Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 33235 Details for
Bug 124388
[DOM AST] Method defaults not resolved
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
JUnit test that demonstrate the problem
ParticipantBuildTests.newTest.patch (text/plain), 7.93 KB, created by
Theodora Yeung
on 2006-01-18 17:51:37 EST
(
hide
)
Description:
JUnit test that demonstrate the problem
Filename:
MIME Type:
Creator:
Theodora Yeung
Created:
2006-01-18 17:51:37 EST
Size:
7.93 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.jdt.core.tests.builder >Index: src/org/eclipse/jdt/core/tests/builder/ParticipantBuildTests.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.builder/src/org/eclipse/jdt/core/tests/builder/ParticipantBuildTests.java,v >retrieving revision 1.7 >diff -u -r1.7 ParticipantBuildTests.java >--- src/org/eclipse/jdt/core/tests/builder/ParticipantBuildTests.java 17 Jan 2006 19:09:50 -0000 1.7 >+++ src/org/eclipse/jdt/core/tests/builder/ParticipantBuildTests.java 18 Jan 2006 01:18:04 -0000 >@@ -11,11 +11,23 @@ > package org.eclipse.jdt.core.tests.builder; > > import java.io.*; >+import java.util.ArrayList; >+import java.util.List; >+ > import junit.framework.*; > > import org.eclipse.core.runtime.*; > import org.eclipse.core.resources.*; > import org.eclipse.jdt.core.compiler.*; >+import org.eclipse.jdt.core.dom.AST; >+import org.eclipse.jdt.core.dom.ASTParser; >+import org.eclipse.jdt.core.dom.AbstractTypeDeclaration; >+import org.eclipse.jdt.core.dom.CompilationUnit; >+import org.eclipse.jdt.core.dom.IMethodBinding; >+import org.eclipse.jdt.core.dom.ITypeBinding; >+import org.eclipse.jdt.core.dom.IVariableBinding; >+import org.eclipse.jdt.core.IJavaProject; >+import org.eclipse.jdt.core.JavaCore; > import org.eclipse.jdt.core.JavaModelException; > import org.eclipse.jdt.core.tests.util.Util; > >@@ -75,6 +87,158 @@ > fullBuild(projectPath); > expectingNoProblems(); > } >+ >+ public void testDefaultValue() throws JavaModelException { >+ IPath projectPath = env.addProject("Project", "1.5"); //$NON-NLS-1$ //$NON-NLS-2$ >+ env.addExternalJars(projectPath, Util.getJavaClassLibs()); >+ env.removePackageFragmentRoot(projectPath, ""); //$NON-NLS-1$ >+ IPath root = env.addPackageFragmentRoot(projectPath, "src"); //$NON-NLS-1$ >+ env.setOutputFolder(projectPath, "bin"); //$NON-NLS-1$ >+ >+ String codeEntryPoint = "package test;\n" + >+ "public class EntryPoint {\n" + >+ " ClassWithNestedAnnotation nestedAnno;\n}"; >+ >+ env.addClass(root, "test", "EntryPoint", codeEntryPoint); >+ >+ String codeClassWithNestedAnnotation = >+ "package test; \n" + >+ "public class ClassWithNestedAnnotation {\n" + >+ " public final int FOUR = 4; \n " + >+ " public @interface NestedAnnotation{\n" + >+ " public enum Character{ \n" + >+ " Winnie, Tiger, Piglet, Eore; \n" + >+ " }\n"+ >+ " Character value() default Character.Eore; \n" + >+ " }\n" + >+ "}"; >+ >+ env.addClass(root, "test", "ClassWithNestedAnnotation", codeClassWithNestedAnnotation); >+ >+ // install compilationParticipant >+ new BuildTestParticipant() { >+ public boolean isAnnotationProcessor() { >+ return true; >+ } >+ public void processAnnotations(ICompilationParticipantResult[] files) { >+ final class ParticipantProblem extends CategorizedProblem implements IProblem { >+ >+ int counter = 0; >+ final String message; >+ final int id; >+ final char[] filename; >+ ParticipantProblem(String message, String filename){ >+ this.message = message; >+ id = counter ++; >+ this.filename = filename.toCharArray(); >+ } >+ public String[] getArguments() { return new String[0];} >+ public int getID() {return id; } >+ public String getMessage() { return message; } >+ public char[] getOriginatingFileName() { return filename; } >+ public int getSourceStart() { return 0; } >+ public int getSourceEnd() { return 0; } >+ public int getSourceLineNumber() { return 1; } >+ public boolean isError() { return true; } >+ public boolean isWarning() { return false; } >+ public void setSourceEnd(int sourceEnd) {/* not needed */} >+ public void setSourceLineNumber(int lineNumber) {/* not needed */} >+ public void setSourceStart(int sourceStart) {/* not needed */} >+ public int getCategoryID() { return 0; } >+ public String getMarkerType() { return "Test_Marker"; } >+ } >+ >+ final int total = files.length; >+ for( int i=0; i<total; i++ ){ >+ final IFile file = files[i].getFile(); >+ final List problems = new ArrayList(); >+ // Traversing the members of test.ClassWithNestedAnnotation through a reference >+ // in EntryPoint.java >+ >+ if( "EntryPoint.java".equals(file.getName()) ){ //$NON-NLS-1$ >+ final CompilationUnit unit = buildCompilationUnit(files[i]); >+ final List types = unit.types(); >+ for( int t=0, tLen=types.size(); t<tLen; t++ ){ >+ final AbstractTypeDeclaration typeDecl = (AbstractTypeDeclaration)types.get(t); >+ final ITypeBinding typeBinding = typeDecl.resolveBinding(); >+ if(typeBinding == null ) continue; >+ final IVariableBinding[] fieldBindings = typeBinding.getDeclaredFields(); >+ >+ for( int f=0, fLen=fieldBindings.length; f<fLen; f++ ){ >+ final IVariableBinding field = fieldBindings[f]; >+ final String name = field.getName(); >+ if( "nestedAnno".equals(name)){ >+ final ITypeBinding fieldType = field.getType(); >+ final ITypeBinding[] declaredTypes = fieldType.getDeclaredTypes(); >+ for(int d=0, dLen=declaredTypes.length; d<dLen; d++ ){ >+ >+ if( "NestedAnnotation".equals(declaredTypes[d].getName()) ){ >+ final IMethodBinding[] annotationMethods = declaredTypes[d].getDeclaredMethods(); >+ for( int m=0, mLen=annotationMethods.length; m<mLen; m++ ){ >+ if( "value".equals(annotationMethods[m].getName()) ){ >+ String defaultString = (String)annotationMethods[m].getDefaultValue(); >+ final String expected = "Eore"; >+ if(!expected.equals(defaultString) ){ >+ final IProblem problem = new ParticipantProblem( >+ "expecting default=" + expected + " but got " + defaultString, >+ file.getName()); >+ problems.add(problem); >+ } >+ } >+ } >+ break; >+ } >+ } >+ >+ final IVariableBinding[] nestedAnnoFields = fieldType.getDeclaredFields(); >+ for( int nf=0, nfLen=nestedAnnoFields.length; nf<nfLen; nf ++ ){ >+ if(nestedAnnoFields[nf].getName().equals("FOUR")){ >+ final Object constant = nestedAnnoFields[nf].getConstantValue(); >+ final String expected = "4"; >+ final String constantStr = constant == null ? "" : constant.toString(); >+ if(!constantStr.equals(expected) ){ >+ final IProblem problem = new ParticipantProblem( >+ "expecting constant=" + expected + " but got " + constantStr, >+ file.getName()); >+ problems.add(problem); >+ } >+ } >+ break; >+ } >+ } >+ else{ >+ final IProblem problem = new ParticipantProblem( >+ "found unexpected field " + field, >+ file.getName()); >+ problems.add(problem); >+ } >+ } >+ } >+ } >+ // post problems, if any >+ if(!problems.isEmpty() ){ >+ IProblem[] problemArray = new IProblem[problems.size()]; >+ problemArray = (IProblem[])problems.toArray(problemArray); >+ files[i].recordNewProblems(problemArray); >+ } >+ } >+ } >+ }; >+ >+ fullBuild(projectPath); >+ expectingNoProblems(); >+ } >+ >+ CompilationUnit buildCompilationUnit(final ICompilationParticipantResult file){ >+ final IJavaProject javaProject = JavaCore.create(file.getFile().getProject()); >+ ASTParser p = ASTParser.newParser( AST.JLS3 ); >+ p.setProject( javaProject ); >+ p.setSource(file.getContents()); >+ p.setResolveBindings( true ); >+ p.setKind( ASTParser.K_COMPILATION_UNIT ); >+ p.setUnitName(file.getFile().getName()); >+ return (CompilationUnit) p.createAST(null); >+ } > > public void testProcessAnnotationDeclarations() throws JavaModelException { > IPath projectPath = env.addProject("Project", "1.5"); //$NON-NLS-1$ //$NON-NLS-2$
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 124388
:
33235
|
33661
|
33662