diff --git a/org.eclipse.jdt.core.javac/META-INF/MANIFEST.MF b/org.eclipse.jdt.core.javac/META-INF/MANIFEST.MF index e4223227ebd..0506988a04c 100644 --- a/org.eclipse.jdt.core.javac/META-INF/MANIFEST.MF +++ b/org.eclipse.jdt.core.javac/META-INF/MANIFEST.MF @@ -1,11 +1,12 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: Javac +Bundle-RequiredExecutionEnvironment: JavaSE-21 Bundle-SymbolicName: org.eclipse.jdt.core.javac Bundle-Version: 1.0.0.qualifier Fragment-Host: org.eclipse.jdt.core Automatic-Module-Name: org.eclipse.jdt.core.javac -Require-Capability: osgi.ee; filter:="(&(osgi.ee=JavaSE)(version=22))" +Require-Capability: osgi.ee; filter:="(&(osgi.ee=JavaSE)(version=21))" Import-Package: org.eclipse.jdt.core.dom Export-Package: org.eclipse.jdt.internal.javac;x-friends:="org.eclipse.jdt.core.tests.javac", org.eclipse.jdt.internal.javac.dom;x-friends:="org.eclipse.jdt.core.tests.javac" diff --git a/org.eclipse.jdt.core.javac/src/org/eclipse/jdt/core/dom/CompilationUnitComparator.java b/org.eclipse.jdt.core.javac/src/org/eclipse/jdt/core/dom/CompilationUnitComparator.java new file mode 100644 index 00000000000..acf61e5ea2e --- /dev/null +++ b/org.eclipse.jdt.core.javac/src/org/eclipse/jdt/core/dom/CompilationUnitComparator.java @@ -0,0 +1,778 @@ +package org.eclipse.jdt.core.dom; + +import java.util.Comparator; +import java.util.List; + +public class CompilationUnitComparator implements Comparator { + private int version; + + public CompilationUnitComparator(int version) { + this.version = version; + } + @Override + public int compare(CompilationUnit res, CompilationUnit res2) { + compareStandard(res, res2); + if( res.imports().size() != res2.imports().size()) { + handleError("imports are a different size"); + } + for( int i = 0; i < res.imports().size(); i++ ) { + ImportDeclaration id1 = (ImportDeclaration)res.imports().get(i); + ImportDeclaration id2 = (ImportDeclaration)res2.imports().get(i); + compareImportDeclarations(id1, id2); + } + compare(res.getPackage(), res2.getPackage()); + + + if( res.getProblems().length != res2.getProblems().length) { + //handleError("problem lengths differ"); + } + + if( res.types().size() != res2.types().size()) { + handleError("list of types are a different size"); + } + for( int i = 0; i < res.types().size(); i++ ) { + compareTypes((AbstractTypeDeclaration)res.types().get(i), (AbstractTypeDeclaration)res2.types().get(i)); + } + + if( version >= AST.JLS9_INTERNAL) { + if( res.getModule() != null && res2.getModule() != null) { + compareModuleDeclaration(res.getModule(), res2.getModule()); + } + } + + // Everything looks ok, but, there might be errors lurking. + nullSafeStringCompare(res, res2, "Comparator incomplete; CUs are different."); + return 0; + } + + private void compareModuleDeclaration(ModuleDeclaration id1, ModuleDeclaration id2) { + compareStandard(id1, id2); + nullSafeStringCompare(id1.getName(), id2.getName()); + List l1 = id1.moduleStatements(); + List l2 = id2.moduleStatements(); + if( (l1 == null && l2 != null) || (l2 == null && l1 != null)) { + handleError("Module statements does not match null"); + } + if( l1.size() != l2.size() ) { + handleError("Module statements does not match size"); + } + for( int i = 0; i < l1.size(); i++ ) { + compareModuleDirective((ModuleDirective)l1.get(i), (ModuleDirective)l2.get(i)); + } + nullSafeStringCompare(id1, id2, "Comparator incomplete; ModuleDeclaration are different."); + } + private void compareModuleDirective(ModuleDirective id1, ModuleDirective id2) { + compareStandard(id1, id2); + if( id1 instanceof RequiresDirective rd1 && id2 instanceof RequiresDirective rd2) { + compareModuleModifiers(rd1.modifiers(), rd2.modifiers()); + } + nullSafeStringCompare(id1, id2, "Comparator incomplete; ModuleDirective are different."); + } + private void compareModuleModifiers(List l1, List l2) { + + if( (l1 == null && l2 != null) || (l2 == null && l1 != null)) { + handleError("Module Modifiers does not match null"); + } + if( l1.size() != l2.size() ) { + handleError("Module Modifiers does not match size"); + } + for( int i = 0; i < l1.size(); i++ ) { + compareModuleModifier((ModuleModifier)l1.get(i), (ModuleModifier)l2.get(i)); + } + } + private void compareModuleModifier(ModuleModifier id1, ModuleModifier id2) { + compareStandard(id1, id2); + } + private void compareImportDeclarations(ImportDeclaration id1, ImportDeclaration id2) { + compareStandard(id1, id2); + if( !id1.getName().toString().equals(id2.getName().toString())) { + handleError("ImportDeclaration names do not match"); + } + if( version != AST.JLS2_INTERNAL) { + if( id1.isStatic() != id2.isStatic()) { + handleError("ImportDeclaration static do not match"); + } + } + nullSafeStringCompare(id1, id2, "Comparator incomplete; imports are different."); + } + private void compareStandard(ASTNode res, ASTNode res2) { + if( res == null && res2 == null ) + return; + if( res == null || res2 == null ) + handleError("difference: null"); + + if( res.getStartPosition() != res2.getStartPosition()) { + handleError("startPosition differ "); + } + if( res.getLength() != res2.getLength()) { + if( Math.abs(res.getLength() - res2.getLength()) == 1) { + handleWarning("Length differ: off by 1 - warning"); + } else { + handleError("length differ "); + } + } + if( res.typeAndFlags != res2.typeAndFlags) { + int flagDiff = Math.abs(res2.typeAndFlags - res.typeAndFlags); + flagDiff &= ~ASTNode.ORIGINAL; + flagDiff &= ~ASTNode.RECOVERED; + flagDiff &= ~ASTNode.PROTECT; + flagDiff &= ~ASTNode.MALFORMED; + if( flagDiff != 0 ) { + handleError("flags are wrong for node "); + } + } + } + + private void compareStandardBodyDecl(BodyDeclaration o1, BodyDeclaration o2) { + compareJavadoc(o1.getJavadoc(), o2.getJavadoc()); + if( o1.getModifiers() != o2.getModifiers()) { + handleError("type modifier flags does not match"); + } + if( version != AST.JLS2_INTERNAL) { + compareModifiers(o1.modifiers(), o2.modifiers()); + } + + } + + private void compareModifiers(List l1, List l2) { + if( (l1 == null && l2 != null) || (l2 == null && l1 != null)) { + handleError("Modifiers does not match null"); + } + if( l1.size() != l2.size() ) { + handleError("Modifiers does not match size"); + } + for( int i = 0; i < l1.size(); i++ ) { + compareModifier((IExtendedModifier)l1.get(i), (IExtendedModifier)l2.get(i)); + } + } + private void compareTypes(AbstractTypeDeclaration object, AbstractTypeDeclaration object2) { + if( object instanceof TypeDeclaration && object2 instanceof TypeDeclaration) { + compareTypeDeclaration((TypeDeclaration)object, (TypeDeclaration)object2); + } else if( object instanceof RecordDeclaration && object2 instanceof RecordDeclaration) { + compareRecord((RecordDeclaration)object, (RecordDeclaration)object2); + } else if( object instanceof AnnotationTypeDeclaration && object2 instanceof AnnotationTypeDeclaration) { + compareAnnotationType((AnnotationTypeDeclaration)object, (AnnotationTypeDeclaration)object2); + } else if( object instanceof EnumDeclaration && object2 instanceof EnumDeclaration) { + compareEnumType((EnumDeclaration)object, (EnumDeclaration)object2); + } else { + handleError("Types not comparable"); + } + } + + private void compareEnumType(EnumDeclaration o1, EnumDeclaration o2) { + compareStandard(o1, o2); + nullSafeStringCompare(o1, o2, "Comparator incomplete; enum decls are different."); + } + + private void compareAnnotationType(AnnotationTypeDeclaration o1, AnnotationTypeDeclaration o2) { + compareStandard(o1, o2); + nullSafeStringCompare(o1, o2, "Comparator incomplete; annot types are different."); + } + + private void compareRecord(RecordDeclaration o1, RecordDeclaration o2) { + compareStandard(o1, o2); + nullSafeStringCompare(o1, o2, "Comparator incomplete; records are different."); + } + + private void compareTypeDeclaration(TypeDeclaration o1, TypeDeclaration o2) { + compareStandard(o1, o2); + compareStandardBodyDecl(o1, o2); + if( !o1.getName().toString().equals(o2.getName().toString())) { + handleError("type names do not match"); + } + if( o1.isInterface() != o2.isInterface()) { + handleError("type interface flag does not match"); + } + if( version == AST.JLS2_INTERNAL) { + nullSafeStringCompare(o1.internalGetSuperclass(), o2.internalGetSuperclass(), "internalGetSuperclass does not match"); + } else { + compareTypeObj(o1.getSuperclassType(), o2.getSuperclassType()); + } + if( version >= AST.JLS17_INTERNAL) { + comparePermittedTypes(o1.permittedTypes(), o2.permittedTypes()); + } + if( version == AST.JLS2_INTERNAL) { + if( o1.internalSuperInterfaces().size() != o2.internalSuperInterfaces().size()) { + handleError("superInterfaceNames does not match size"); + } + for( int i = 0; i < o1.internalSuperInterfaces().size(); i++ ) { + compareSuperInterfaceNames(o1.internalSuperInterfaces().get(i), o2.internalSuperInterfaces().get(i)); + } + } else { + if( o1.superInterfaceTypes().size() != o2.superInterfaceTypes().size()) { + handleError("superInterfaceTypes does not match size"); + } + for( int i = 0; i < o1.superInterfaceTypes().size(); i++ ) { + compareSuperInterfaceTypes(o1.superInterfaceTypes().get(i), o2.superInterfaceTypes().get(i)); + } + } + if( version != AST.JLS2_INTERNAL) { + List l1 = o1.typeParameters(); + List l2 = o2.typeParameters(); + + if( (l1 == null && l2 != null) || (l2 == null && l1 != null)) { + handleError("Type params does not match null"); + } + if( l1.size() != l2.size() ) { + handleError("Type params does not match size"); + } + for( int i = 0; i < l1.size(); i++ ) { + compareTypeParameter((TypeParameter)l1.get(i), (TypeParameter)l2.get(i)); + } + } + + if( o1.bodyDeclarations().size() != o2.bodyDeclarations().size()) { + handleError("Body declarations does not match size"); + } + for( int i = 0; i < o1.bodyDeclarations().size(); i++ ) { + compareBodyDeclaration(o1.bodyDeclarations().get(i), o2.bodyDeclarations().get(i)); + } + + nullSafeStringCompare(o1, o2, "Comparator incomplete; types are different."); + } + + private void compareModifier(IExtendedModifier o1, IExtendedModifier o2) { + compareStandard((ASTNode)o1, (ASTNode)o2); + if( o1 instanceof NormalAnnotation na1 && o2 instanceof NormalAnnotation na2) { + compareNormalAnnotation(na1, na2); + } + nullSafeStringCompare(o1, o2, "Comparator incomplete; modifiers are different."); + } + private void compareNormalAnnotation(NormalAnnotation na1, NormalAnnotation na2) { + // TODO Auto-generated method stub + int z = 5; + } + private void compareBodyDeclaration(Object object, Object object2) { + if( object instanceof MethodDeclaration && object2 instanceof MethodDeclaration) { + compareMethodDeclaration((MethodDeclaration)object, (MethodDeclaration)object2); + } else if( object instanceof FieldDeclaration && object2 instanceof FieldDeclaration) { + compareFieldDeclaration((FieldDeclaration)object, (FieldDeclaration)object2); + } else if( object instanceof TypeDeclaration && object2 instanceof TypeDeclaration) { + compareTypeDeclaration((TypeDeclaration)object, (TypeDeclaration)object2); + } else if( object instanceof Initializer && object2 instanceof Initializer) { + compareInitializer((Initializer)object, (Initializer)object2); + } else if( object instanceof EnumDeclaration && object2 instanceof EnumDeclaration) { + compareEnumDeclaration((EnumDeclaration)object, (EnumDeclaration)object2); + } else if( object instanceof AnnotationTypeDeclaration && object2 instanceof AnnotationTypeDeclaration) { + compareAnnotTypeDeclaration((AnnotationTypeDeclaration)object, (AnnotationTypeDeclaration)object2); + } else if( object instanceof AnnotationTypeMemberDeclaration && object2 instanceof AnnotationTypeMemberDeclaration) { + compareAnnotTypeMemberDeclaration((AnnotationTypeMemberDeclaration)object, (AnnotationTypeMemberDeclaration)object2); + } else { + handleError("Body declaration not comparable"); + } + } + + private void compareAnnotTypeMemberDeclaration(AnnotationTypeMemberDeclaration o1, + AnnotationTypeMemberDeclaration o2) { + compareStandard(o1, o2); + compareStandardBodyDecl(o1, o2); + if( !o1.getName().toString().equals(o2.getName().toString())) { + handleError("type names do not match"); + } + compareTypeObj(o1.getType(), o2.getType()); + nullSafeStringCompare(o1, o2, "Comparator incomplete; annot types are different."); + } + private void compareAnnotTypeDeclaration(AnnotationTypeDeclaration o1, AnnotationTypeDeclaration o2) { + compareStandard(o1, o2); + compareStandardBodyDecl(o1, o2); + if( !o1.getName().toString().equals(o2.getName().toString())) { + handleError("type names do not match"); + } + if( o1.bodyDeclarations().size() != o2.bodyDeclarations().size()) { + handleError("Body declarations does not match size"); + } + for( int i = 0; i < o1.bodyDeclarations().size(); i++ ) { + compareBodyDeclaration(o1.bodyDeclarations().get(i), o2.bodyDeclarations().get(i)); + } + nullSafeStringCompare(o1, o2, "Comparator incomplete; annot type decls are different."); + } + private void compareEnumDeclaration(EnumDeclaration o1, EnumDeclaration o2) { + compareStandard(o1, o2); + compareStandardBodyDecl(o1, o2); + if( !o1.getName().toString().equals(o2.getName().toString())) { + handleError("type names do not match"); + } + if( version == AST.JLS2_INTERNAL) { + // DO nothing + } else { + if( o1.superInterfaceTypes().size() != o2.superInterfaceTypes().size()) { + handleError("superInterfaceTypes does not match size"); + } + for( int i = 0; i < o1.superInterfaceTypes().size(); i++ ) { + compareSuperInterfaceTypes(o1.superInterfaceTypes().get(i), o2.superInterfaceTypes().get(i)); + } + } + if( o1.bodyDeclarations().size() != o2.bodyDeclarations().size()) { + handleError("Body declarations does not match size"); + } + for( int i = 0; i < o1.bodyDeclarations().size(); i++ ) { + compareBodyDeclaration(o1.bodyDeclarations().get(i), o2.bodyDeclarations().get(i)); + } + + nullSafeStringCompare(o1, o2, "Comparator incomplete; enum decl are different."); + } + private void compareInitializer(Initializer o1, Initializer o2) { + compareStandard(o1, o2); + compareStandardBodyDecl(o1, o2); + compareBlock(o1.getBody(), o2.getBody()); + nullSafeStringCompare(o1, o2, "Comparator incomplete; initializers are different."); + } + + private void compareBlock(Block o1, Block o2) { + boolean e1Null = o1 == null; + boolean e2Null = o2 == null; + + if( (e1Null && e2Null)) + return; + if( e1Null || e2Null ) { + handleError("Block not comparable: null"); + } + + compareStandard(o1, o2); + + List s1 = o1.statements(); + List s2 = o2.statements(); + if( s1.size() != s2.size()) { + handleError("Block statements wrong sizes"); + } + for( int i = 0; i < s1.size(); i++ ) { + compareStatement((Statement)s1.get(i), (Statement)s2.get(i)); + } + + nullSafeStringCompare(o1, o2, "Comparator incomplete; blocks are different."); + } + + private void compareStatement(Statement o1, Statement o2) { + compareStandard(o1, o2); + if( o1 instanceof VariableDeclarationStatement vds1 && o2 instanceof VariableDeclarationStatement vds2) { + compareVarDeclStmt(vds1, vds2); + } + if( o1 instanceof ExpressionStatement vds1 && o2 instanceof ExpressionStatement vds2) { + compareExpression(vds1.getExpression(), vds2.getExpression()); + } + nullSafeStringCompare(o1, o2, "Comparator incomplete; Statement are different."); + } + + private void compareVarDeclStmt(VariableDeclarationStatement vds1, VariableDeclarationStatement vds2) { + compareStandard(vds1, vds2); + if( version != AST.JLS2_INTERNAL) { + compareModifiers(vds1.modifiers(), vds2.modifiers()); + } + List frag1 = vds1.fragments(); + List frag2 = vds2.fragments(); + if( frag1.size() != frag2.size()) { + handleError("VariableDeclarationStatement fragments wrong sizes"); + } + for( int i = 0; i < frag1.size(); i++ ) { + compareVariableDeclaration((VariableDeclarationFragment)frag1.get(i), (VariableDeclarationFragment)frag2.get(i)); + } + nullSafeStringCompare(vds1, vds2, "Comparator incomplete; VariableDeclarationStatement are different."); + } + private void compareExpression(Expression e1, Expression e2) { + boolean e1Null = e1 == null; + boolean e2Null = e2 == null; + + if( (e1Null && e2Null)) + return; + if( e1Null || e2Null ) { + handleError("Expression not comparable: null"); + } + if( e1 instanceof LambdaExpression le1 && e2 instanceof LambdaExpression le2) { + compareLambdaExpression(le1, le2); + } else if( e1 instanceof NumberLiteral le1 && e2 instanceof NumberLiteral le2) { + compareStandard(le1, le2); + nullSafeStringCompare(le1.getToken(), le2.getToken()); + } else if( e1 instanceof NullLiteral le1 && e2 instanceof NullLiteral le2) { + compareStandard(le1, le2); // TODO + } else if( e1 instanceof MethodInvocation le1 && e2 instanceof MethodInvocation le2) { + compareStandard(le1, le2); // TODO + } else if( e1 instanceof ClassInstanceCreation le1 && e2 instanceof ClassInstanceCreation le2) { + compareStandard(le1, le2); + compareExpression(le1.getExpression(), le2.getExpression()); + compareAnonymousClassDecl(le1.getAnonymousClassDeclaration(), le2.getAnonymousClassDeclaration()); + compareExpressionList(le1.arguments(), le2.arguments()); + if( version != AST.JLS2_INTERNAL) { + compareTypeList(le1.typeArguments(), le2.typeArguments()); + } + } else if( (e1 instanceof FieldAccess && e2 instanceof QualifiedName) || (e1 instanceof QualifiedName && e2 instanceof FieldAccess)) { + if( e1.getStartPosition() != e2.getStartPosition()) { + handleError("startPosition differ "); + } + if( e1.getLength() != e2.getLength()) { + handleError("length differ "); + } + FieldAccess fa = (e1 instanceof FieldAccess e1a ? e1a : (FieldAccess)e2); + QualifiedName qn = (e1 instanceof QualifiedName e1a ? e1a : (QualifiedName)e2); + nullSafeStringCompare(fa.getName(), qn.getName()); + nullSafeStringCompare(fa.getExpression(), qn.getQualifier()); + } else if( e1 instanceof ArrayCreation ac1 && e2 instanceof ArrayCreation ac2) { + compareStandard(e1, e2); + compareDimensionList(ac1.dimensions(), ac2.dimensions()); + compareExpression(ac1.getInitializer(), ac2.getInitializer()); + nullSafeStringCompare(e1, e2); + } else if( e1 instanceof ArrayInitializer ac1 && e2 instanceof ArrayInitializer ac2) { + compareStandard(e1, e2); + compareExpressionList(ac1.expressions(), ac2.expressions()); + nullSafeStringCompare(e1, e2); + } else if( e1 instanceof Assignment ac1 && e2 instanceof Assignment ac2) { + compareStandard(e1, e2); + compareExpression(ac1.getLeftHandSide(), ac2.getLeftHandSide()); + compareExpression(ac1.getRightHandSide(), ac2.getRightHandSide()); + nullSafeStringCompare(e1, e2); + } else if( e1 instanceof Name ac1 && e2 instanceof Name ac2) { + compareStandard(e1, e2); + nullSafeStringCompare(e1, e2); + } else if( e1 instanceof BooleanLiteral ac1 && e2 instanceof BooleanLiteral ac2) { + compareStandard(e1, e2); + nullSafeStringCompare(e1, e2); + } else if( e1 instanceof CharacterLiteral ac1 && e2 instanceof CharacterLiteral ac2) { + compareStandard(e1, e2); + nullSafeStringCompare(e1, e2); + } else if( e1 instanceof StringLiteral ac1 && e2 instanceof StringLiteral ac2) { + compareStandard(e1, e2); + nullSafeStringCompare(e1, e2); + } else if( e1 instanceof SuperMethodInvocation ac1 && e2 instanceof SuperMethodInvocation ac2) { + compareStandard(e1, e2); + nullSafeStringCompare(e1, e2); + } else if( e1 instanceof PrefixExpression ac1 && e2 instanceof PrefixExpression ac2) { + compareStandard(e1, e2); + nullSafeStringCompare(e1, e2); + } else if( e1 instanceof PostfixExpression ac1 && e2 instanceof PostfixExpression ac2) { + compareStandard(e1, e2); + nullSafeStringCompare(e1, e2); + } else if( e1 instanceof CastExpression ac1 && e2 instanceof CastExpression ac2) { + compareStandard(e1, e2); + nullSafeStringCompare(e1, e2); + } else { + handleError("Expression not comparable"); + } + nullSafeStringCompare(e1, e2); + } + + private void compareExpressionList(List nl1, List nl2) { + boolean nl1Null = nl1 == null; + boolean nl2Null = nl2 == null; + if( (nl1Null && nl2Null)) + return; + if( nl1Null || nl2Null ) { + handleError("Expression list not comparable: null"); + } + for( int i = 0; i < nl1.size(); i++ ) { + compareExpression((Expression)nl1.get(i), (Expression)nl2.get(i)); + } + } + + + private void compareTypeList(List nl1, List nl2) { + boolean nl1Null = nl1 == null; + boolean nl2Null = nl2 == null; + if( (nl1Null && nl2Null)) + return; + if( nl1Null || nl2Null ) { + handleError("Expression list not comparable: null"); + } + for( int i = 0; i < nl1.size(); i++ ) { + compareTypeObj((Type)nl1.get(i), (Type)nl2.get(i)); + } + } + + private void compareAnonymousClassDecl(AnonymousClassDeclaration o1, + AnonymousClassDeclaration o2) { + boolean nl1Null = o1 == null; + boolean nl2Null = o2 == null; + if( (nl1Null && nl2Null)) + return; + if( nl1Null || nl2Null ) { + handleError("Expression list not comparable: null"); + } + + compareStandard(o1, o2); + + if( o1.bodyDeclarations().size() != o2.bodyDeclarations().size()) { + handleError("Body declarations does not match size"); + } + for( int i = 0; i < o1.bodyDeclarations().size(); i++ ) { + compareBodyDeclaration(o1.bodyDeclarations().get(i), o2.bodyDeclarations().get(i)); + } + + } + private void compareLambdaExpression(LambdaExpression le1, LambdaExpression le2) { + compareStandard(le1, le2); + List params1 = le1.parameters(); + List params2 = le2.parameters(); + if( params1.size() != params2.size()) { + handleError("VariableDeclarationStatement fragments wrong sizes"); + } + for( int i = 0; i < params1.size(); i++ ) { + Object o1FragI = params1.get(i); + Object o2FragI = params2.get(i); + if( o1FragI instanceof SingleVariableDeclaration z1 && o2FragI instanceof SingleVariableDeclaration z2) { + compareVariableDeclaration(z1, z2); + } else if( o1FragI instanceof VariableDeclarationFragment w1 && o2FragI instanceof VariableDeclarationFragment w2) { + compareVariableDeclaration(w1, w2); + } else { + handleError("LambdaExpression params wrong types"); + } + } + ASTNode body1 = le1.getBody(); + ASTNode body2 = le2.getBody(); + if( body1 instanceof Expression z1 && body2 instanceof Expression z2) { + compareExpression(z1, z2); + } else if( body1 instanceof Block w1 && body2 instanceof Block w2) { + compareBlock(w1, w2); + } else { + handleError("LambdaExpression body wrong types"); + } + } + private void compareFieldDeclaration(FieldDeclaration object, FieldDeclaration object2) { + compareStandard(object, object2); + compareStandardBodyDecl(object, object2); + List l1 = object.fragments(); + List l2 = object2.fragments(); + if( (l1 == null && l2 != null) || (l2 == null && l1 != null)) { + handleError("fragments does not match null"); + } + if( l1 != null ) { + if( l1.size() != l2.size() ) { + handleError("fragments does not match size"); + } + for( int i = 0; i < l1.size(); i++ ) { + compareVariableDeclaration((VariableDeclarationFragment)l1.get(i), (VariableDeclarationFragment)l2.get(i)); + } + } + nullSafeStringCompare(object, object2, "Comparator incomplete; field decls are different."); + } + + private void compareDimensionList(List l1, List l2) { + if( (l1 == null && l2 != null) || (l2 == null && l1 != null)) { + handleError("dimensions does not match null"); + } + if( l1 != null ) { + if( l1.size() != l2.size() ) { + handleError("dimensions does not match size"); + } + for( int i = 0; i < l1.size(); i++ ) { + compareDimension((Dimension)l1.get(i), (Dimension)l2.get(i)); + } + } + } + + private void compareVariableDeclaration(VariableDeclaration object1, + VariableDeclaration object2) { + compareStandard(object1, object2); + if( object1.getExtraDimensions() != object2.getExtraDimensions()) { + handleError("getExtraDimensions does not match"); + } + if( version > AST.JLS4_INTERNAL) { + compareDimensionList(object1.extraDimensions(), object2.extraDimensions()); + } + + nullSafeStringCompare(object1.getName(), object2.getName()); + compareExpression(object1.getInitializer(), object2.getInitializer()); + nullSafeStringCompare(object1, object2, "Comparator incomplete; var decl fragments are different."); + } + + private void compareMethodDeclaration(MethodDeclaration object, MethodDeclaration object2) { + compareStandard(object, object2); + compareStandardBodyDecl(object, object2); + + if( !object.getName().toString().equals(object2.getName().toString())) { + handleError("getName does not match"); + } + if( object.getExtraDimensions() != object2.getExtraDimensions()) { + handleError("getExtraDimensions does not match"); + } + if( version > AST.JLS4_INTERNAL) { + List l1 = object.extraDimensions(); + List l2 = object2.extraDimensions(); + if( (l1 == null && l2 != null) || (l2 == null && l1 != null)) { + handleError("extraDimensions does not match null"); + } + if( l1 != null ) { + if( l1.size() != l2.size() ) { + handleError("extraDimensions does not match size"); + } + for( int i = 0; i < l1.size(); i++ ) { + compareDimension((Dimension)l1.get(i), (Dimension)l2.get(i)); + } + } + } + if( version > AST.JLS15_INTERNAL) { + if( object.isCompactConstructor() != object2.isCompactConstructor()) { + handleError("isCompactConstructor does not match"); + } + } + if( object.isConstructor() != object2.isConstructor()) { + handleError("isConstructor does not match"); + } + if( version == AST.JLS2_INTERNAL) { + compareTypeObj(object.getReturnType(), object2.getReturnType()); + } else { + compareTypeObj(object.getReturnType2(), object2.getReturnType2()); + } + if( version > AST.JLS4_INTERNAL) { + nullSafeStringCompare(object.getReceiverQualifier(), object2.getReceiverQualifier()); + compareTypeObj(object.getReceiverType(), object2.getReceiverType()); + } + if( version <= AST.JLS4_INTERNAL) { + List l1 = object.thrownExceptions(); + List l2 = object2.thrownExceptions(); + if( (l1 == null && l2 != null) || (l1 != null && l2 == null)) { + handleError("thrownExceptions does not match, nullity"); + } + if( l1 != null ) { + if( l1.size() != l2.size() ) { + handleError("thrownExceptions does not match size"); + } + for( int i = 0; i < l1.size(); i++ ) { + nullSafeStringCompare(l1.get(i), l2.get(i)); + } + } + } else { + List l1 = object.thrownExceptionTypes(); + List l2 = object2.thrownExceptionTypes(); + if( (l1 == null && l2 != null) || (l1 != null && l2 == null)) { + handleError("thrownExceptionTypes does not match, nullity"); + } + if( l1 != null ) { + if( l1.size() != l2.size() ) { + handleError("thrownExceptionTypes does not match size"); + } + for( int i = 0; i < l1.size(); i++ ) { + compareTypeObj((Type)l1.get(i), (Type)l2.get(i)); + } + } + } + if( version != AST.JLS2_INTERNAL) { + // TODO typeParameters + List l1 = object.typeParameters(); + List l2 = object2.typeParameters(); + + if( (l1 == null && l2 != null) || (l2 == null && l1 != null)) { + handleError("methoddecl type params does not match null"); + } + if( l1.size() != l2.size() ) { + handleError("methoddecl type params does not match size"); + } + for( int i = 0; i < l1.size(); i++ ) { + compareTypeParameter((TypeParameter)l1.get(i), (TypeParameter)l2.get(i)); + } + } + + List l1 = object.parameters(); + List l2 = object2.parameters(); + + if( (l1 == null && l2 != null) || (l2 == null && l1 != null)) { + handleError("methoddecl params does not match null"); + } + if( l1 != null && l2 != null ) { + if( l1.size() != l2.size() ) { + handleError("methoddecl params does not match size"); + } + for( int i = 0; i < l1.size(); i++ ) { + compareVariableDeclaration((SingleVariableDeclaration)l1.get(i), (SingleVariableDeclaration)l2.get(i)); + } + } + + compareBlock(object.getBody(), object2.getBody()); + nullSafeStringCompare(object, object2, "Comparator incomplete; method decls are different."); + } + private void compareDimension(Dimension d1, Dimension d2) { + compareStandard(d1, d2); + // TODO more + nullSafeStringCompare(d1, d2, "Comparator incomplete; dimensions are different."); + } + + private void nullSafeStringCompare(Object o1, Object o2) { + nullSafeStringCompare(o1, o2, ""); + } + private void nullSafeStringCompare(Object o1, Object o2, String prefix) { + + if( o1 == null ) { + if( o2 == null ) { + return; + } + handleError(prefix + ": not equal nullity"); + } + if( !o1.toString().equals(o2.toString())) { + handleError(prefix + ": not equal"); + } + } + + private void compareTypeParameter(TypeParameter typeParameter, TypeParameter typeParameter2) { + compareStandard(typeParameter, typeParameter2); + compareStandard(typeParameter.getName(), typeParameter2.getName()); + // TODO compare type bounds + nullSafeStringCompare(typeParameter, typeParameter2, "Comparator incomplete; type param are different."); + } + private void compareSuperInterfaceTypes(Object object, Object object2) { + nullSafeStringCompare(object, object, "Comparator incomplete; super interface types are different."); + } + private void compareSuperInterfaceNames(Object object, Object object2) { + nullSafeStringCompare(object, object, "Comparator incomplete; super interface names are different."); + } + private void comparePermittedTypes(List permittedTypes, List permittedTypes2) { + int x = 1; + nullSafeStringCompare(permittedTypes, permittedTypes2, "Comparator incomplete; permitted types are different."); + } + private void compareTypeObj(Type superclassType, Type superclassType2) { + compareStandard(superclassType, superclassType2); + nullSafeStringCompare(superclassType, superclassType2, "Comparator incomplete; type objs are different."); + } + private void compareJavadoc(Javadoc javadoc, Javadoc javadoc2) { + if( javadoc == null && javadoc2 == null ) + return; + if( (javadoc == null && javadoc2 != null) || (javadoc2 == null && javadoc != null)) { + handleError("javadoc not comparable: null"); + } + compareStandard(javadoc, javadoc2); + if( version == AST.JLS2_INTERNAL) { + nullSafeStringCompare(javadoc.getComment(), javadoc2.getComment()); + } + + List l1 = javadoc.tags(); + List l2 = javadoc2.tags(); + if( (l1 == null && l2 != null) || (l1 != null && l2 == null)) { + handleError("javadoc tags does not match, nullity"); + } + if( l1 != null ) { + if( l1.size() != l2.size() ) { + handleError("javadoc tags does not match size"); + } + for( int i = 0; i < l1.size(); i++ ) { + compareTagElement((TagElement)l1.get(i), (TagElement)l2.get(i)); + } + } + } + + private void compareTagElement(TagElement tagElement, TagElement tagElement2) { + compareStandard(tagElement, tagElement2); + //nullSafeStringCompare(tagElement, tagElement2, "Comparator incomplete; tag elements are different."); + } + public void compare(PackageDeclaration p1, PackageDeclaration p2) { + compareStandard(p1, p2); + if( p1 == null ) + return; + + if( p1.getLength() != p2.getLength()) { + handleError("package lengths differ"); + } + if( p1.typeAndFlags != p2.typeAndFlags) { + handleError("flags are wrong for package declaration "); + } + if( p1.getName().equals(p2.getName())) { + handleError("package names differ"); + } + nullSafeStringCompare(p1, p2, "Comparator incomplete; package decls are different."); + } + + private void handleError(String msg) { + System.out.println("*** " + msg); + throw new RuntimeException(msg); + } + + private void handleWarning(String msg) { + System.out.println("*** " + msg); + //throw new RuntimeException(msg); + } +} diff --git a/org.eclipse.jdt.core.javac/src/org/eclipse/jdt/core/dom/CustomASTMatcher.java b/org.eclipse.jdt.core.javac/src/org/eclipse/jdt/core/dom/CustomASTMatcher.java new file mode 100644 index 00000000000..d6f1afec478 --- /dev/null +++ b/org.eclipse.jdt.core.javac/src/org/eclipse/jdt/core/dom/CustomASTMatcher.java @@ -0,0 +1,108 @@ +package org.eclipse.jdt.core.dom; + +import org.eclipse.jdt.core.dom.InfixExpression.Operator; + +public class CustomASTMatcher extends ASTMatcher { + private boolean nullSafeStringCompare(Object o1, Object o2) { + if( o1 == null ) { + if( o2 == null ) { + return true; + } + return false; + } + return o1.toString().equals(o2.toString()); + } + public boolean match(NumberLiteral node, Object other) { + if( other instanceof PrefixExpression pe) { + return nullSafeStringCompare(node, pe); + } + return super.match(node, other); + } + + public boolean match(PrefixExpression node, Object other) { + if( other instanceof NumberLiteral pe) { + return nullSafeStringCompare(node, pe); + } + return super.match(node, other); + } + public boolean match(InfixExpression node, Object other) { + if( other instanceof StringLiteral sa && node.getOperator() == Operator.PLUS && node.getLeftOperand() instanceof StringLiteral && node.getRightOperand() instanceof StringLiteral) { + String v = sa.toString(); + String nodeString = node.toString(); + String replaced1 = nodeString.replaceAll("\" *\\+ *\"", ""); + if( replaced1.equals(v)) { + return true; + } + } + if( other instanceof InfixExpression sa ) { + String v = sa.toString(); + String nodeString = node.toString(); + String replaced1 = nodeString.replaceAll("\" *\\+ *\"", ""); + if( replaced1.replaceAll(" ", "").equals(v.replaceAll(" ", ""))) { + return true; + } + } + return super.match(node, other); + } + public boolean match(StringLiteral node, Object other) { + if( other instanceof InfixExpression ia && ia.getOperator() == Operator.PLUS && ia.getLeftOperand() instanceof StringLiteral && ia.getRightOperand() instanceof StringLiteral) { + String v = ia.toString(); + String nodeString = node.toString(); + String replaced1 = v.replaceAll("\" \\+ \"", ""); + if( replaced1.equals(nodeString)) { + return true; + } + } + return super.match(node, other); + } + + public boolean match(SimpleName node, Object other) { + if( other instanceof QualifiedName fa) { + return node.toString().equals(other.toString()); + } else { + return super.match(node, other); + } + } + public boolean match(QualifiedName node, Object other) { + if( other instanceof FieldAccess fa) { + return matchQualifiedNameToFieldAccess(node, fa); + } else if( other instanceof SimpleName fa) { + return node.toString().equals(other.toString()); + } else { + return super.match(node, other); + } + } + public boolean match(FieldAccess node, Object other) { + if( other instanceof QualifiedName qn) { + return matchQualifiedNameToFieldAccess(qn, node); + } else { + return super.match(node, other); + } + } + + public boolean match(SimpleType node, Object other) { + if( other instanceof QualifiedType && node.toString().equals(other.toString())) { + return true; + } + return super.match(node, other); + } + + public boolean match(QualifiedType node, Object other) { + if( other instanceof SimpleType && node.toString().equals(other.toString())) { + return true; + } + return super.match(node, other); + } + + public boolean matchQualifiedNameToFieldAccess(QualifiedName node, FieldAccess fa) { + String qualifier1 = fa == null ? null : fa.getExpression() == null ? null : fa.getExpression().toString(); + String qualifier2 = node == null ? null : node.getQualifier() == null ? null : node.getQualifier().toString(); + boolean match1 = nullSafeStringCompare(qualifier1, qualifier2); + + String name1 = fa == null ? null : fa.getName() == null ? null : fa.getName().toString(); + String name2 = node == null ? null : node.getName() == null ? null : node.getName().toString(); + boolean match2 = nullSafeStringCompare(name1, name2); + return match1 && match2; + } + +} \ No newline at end of file diff --git a/org.eclipse.jdt.core.javac/src/org/eclipse/jdt/core/dom/JavacCompilationUnitResolver.java b/org.eclipse.jdt.core.javac/src/org/eclipse/jdt/core/dom/JavacCompilationUnitResolver.java index 45cf2d45b11..0ab92cecbe9 100644 --- a/org.eclipse.jdt.core.javac/src/org/eclipse/jdt/core/dom/JavacCompilationUnitResolver.java +++ b/org.eclipse.jdt.core.javac/src/org/eclipse/jdt/core/dom/JavacCompilationUnitResolver.java @@ -20,6 +20,7 @@ import java.util.Collections; import java.util.Comparator; import java.util.HashMap; +import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Objects; @@ -39,10 +40,13 @@ import org.eclipse.jdt.core.IJavaElement; import org.eclipse.jdt.core.IJavaProject; import org.eclipse.jdt.core.JavaCore; +import org.eclipse.jdt.core.JavaModelException; import org.eclipse.jdt.core.Signature; import org.eclipse.jdt.core.WorkingCopyOwner; +import org.eclipse.jdt.core.compiler.CharOperation; import org.eclipse.jdt.core.compiler.IProblem; import org.eclipse.jdt.core.compiler.InvalidInputException; +import org.eclipse.jdt.core.dom.CompilationUnitResolver.IntArrayList; import org.eclipse.jdt.internal.compiler.batch.FileSystem.Classpath; import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; import org.eclipse.jdt.internal.compiler.env.AccessRestriction; @@ -54,7 +58,14 @@ import org.eclipse.jdt.internal.compiler.lookup.BinaryTypeBinding; import org.eclipse.jdt.internal.compiler.lookup.LookupEnvironment; import org.eclipse.jdt.internal.compiler.lookup.PackageBinding; +import org.eclipse.jdt.internal.compiler.util.HashtableOfObjectToInt; import org.eclipse.jdt.internal.compiler.util.Util; +import org.eclipse.jdt.internal.core.BinaryMember; +import org.eclipse.jdt.internal.core.BinaryModule; +import org.eclipse.jdt.internal.core.LocalVariable; +import org.eclipse.jdt.internal.core.SourceRefElement; +import org.eclipse.jdt.internal.core.util.BindingKeyParser; +import org.eclipse.jdt.internal.core.util.DOMFinder; import org.eclipse.jdt.internal.javac.JavacProblemConverter; import org.eclipse.jdt.internal.javac.JavacUtils; @@ -175,6 +186,105 @@ public void accept(ISourceType[] sourceType, PackageBinding packageBinding, } + private static class CustomBindingKeyParser extends BindingKeyParser { + + private char[] secondarySimpleName; + private char[][] compoundName; + + public CustomBindingKeyParser(String key) { + super(key); + } + + @Override + public void consumeSecondaryType(char[] simpleTypeName) { + this.secondarySimpleName = simpleTypeName; + } + + @Override + public void consumeFullyQualifiedName(char[] fullyQualifiedName) { + this.compoundName = CharOperation.splitOn('/', fullyQualifiedName); + } + } + + @Override + public IBinding[] resolve(IJavaElement[] elements, int apiLevel, Map compilerOptions, + IJavaProject javaProject, WorkingCopyOwner owner, int flags, IProgressMonitor monitor) { + // Logic copied entirely from ECJCompilationUnitResolver + final int length = elements.length; + final HashMap sourceElementPositions = new HashMap(); // a map from ICompilationUnit to int[] (positions in elements) + int cuNumber = 0; + final HashtableOfObjectToInt binaryElementPositions = new HashtableOfObjectToInt(); // a map from String (binding key) to int (position in elements) + for (int i = 0; i < length; i++) { + IJavaElement element = elements[i]; + if (!(element instanceof SourceRefElement)) + throw new IllegalStateException(element + " is not part of a compilation unit or class file"); //$NON-NLS-1$ + Object cu = element.getAncestor(IJavaElement.COMPILATION_UNIT); + if (cu != null) { + // source member + IntArrayList intList = (IntArrayList) sourceElementPositions.get(cu); + if (intList == null) { + sourceElementPositions.put(cu, intList = new IntArrayList()); + cuNumber++; + } + intList.add(i); + } else { + // binary member or method argument + try { + String key; + if (element instanceof BinaryMember) + key = ((BinaryMember) element).getKey(true/*open to get resolved info*/); + else if (element instanceof LocalVariable) + key = ((LocalVariable) element).getKey(true/*open to get resolved info*/); + else if (element instanceof org.eclipse.jdt.internal.core.TypeParameter) + key = ((org.eclipse.jdt.internal.core.TypeParameter) element).getKey(true/*open to get resolved info*/); + else if (element instanceof BinaryModule) + key = ((BinaryModule) element).getKey(true); + else + throw new IllegalArgumentException(element + " has an unexpected type"); //$NON-NLS-1$ + binaryElementPositions.put(key, i); + } catch (JavaModelException e) { + throw new IllegalArgumentException(element + " does not exist", e); //$NON-NLS-1$ + } + } + } + ICompilationUnit[] cus = new ICompilationUnit[cuNumber]; + sourceElementPositions.keySet().toArray(cus); + + int bindingKeyNumber = binaryElementPositions.size(); + String[] bindingKeys = new String[bindingKeyNumber]; + binaryElementPositions.keysToArray(bindingKeys); + + class Requestor extends ASTRequestor { + IBinding[] bindings = new IBinding[length]; + Map map = new HashMap<>(); + @Override + public void acceptAST(ICompilationUnit source, CompilationUnit ast) { + map.put(source, ast); + // TODO (jerome) optimize to visit the AST only once + IntArrayList intList = (IntArrayList) sourceElementPositions.get(source); + for (int i = 0; i < intList.length; i++) { + final int index = intList.list[i]; + SourceRefElement element = (SourceRefElement) elements[index]; + DOMFinder finder = new DOMFinder(ast, element, true/*resolve binding*/); + try { + finder.search(); + } catch (JavaModelException e) { + throw new IllegalArgumentException(element + " does not exist", e); //$NON-NLS-1$ + } + this.bindings[index] = finder.foundBinding; + } + } + @Override + public void acceptBinding(String bindingKey, IBinding binding) { + int index = binaryElementPositions.get(bindingKey); + this.bindings[index] = binding; + } + } + Requestor requestor = new Requestor(); + resolve(cus, bindingKeys, requestor, apiLevel, compilerOptions, javaProject, owner, flags, monitor); + return requestor.bindings; + } + @Override public void parse(ICompilationUnit[] compilationUnits, ASTRequestor requestor, int apiLevel, Map compilerOptions, int flags, IProgressMonitor monitor) { @@ -192,10 +302,26 @@ private Map parse(ICompilationUnit[] compilat && Arrays.stream(compilationUnits).map(ICompilationUnit::getJavaProject).distinct().count() == 1 && Arrays.stream(compilationUnits).allMatch(org.eclipse.jdt.internal.compiler.env.ICompilationUnit.class::isInstance)) { // all in same project, build together - return + Map map = new HashMap<>(); + ASTRequestor r = new ASTRequestor() { + @Override + public void acceptAST(ICompilationUnit source, CompilationUnit ast) { + map.put(source, ast); + } + }; + CompilationUnitResolver.FACADE.parse(compilationUnits, r, apiLevel, compilerOptions, flags, monitor); + + Map ret = parse(Arrays.stream(compilationUnits).map(org.eclipse.jdt.internal.compiler.env.ICompilationUnit.class::cast).toArray(org.eclipse.jdt.internal.compiler.env.ICompilationUnit[]::new), apiLevel, compilerOptions, flags, compilationUnits[0].getJavaProject(), monitor) .entrySet().stream().collect(Collectors.toMap(entry -> (ICompilationUnit)entry.getKey(), entry -> entry.getValue())); + + Iterator it = map.keySet().iterator(); + while(it.hasNext()) { + ICompilationUnit u = it.next(); + map.get(u).subtreeMatch(new CustomASTMatcher(), ret.get(u)); + } + return ret; } // build individually Map res = new HashMap<>(compilationUnits.length, 1.f); @@ -237,38 +363,24 @@ private void resolveBindings(CompilationUnit unit) { } } - @Override - public IBinding[] resolve(IJavaElement[] elements, int apiLevel, Map compilerOptions, - IJavaProject project, WorkingCopyOwner workingCopyOwner, int flags, IProgressMonitor monitor) { - // TODO Auto-generated method stub - throw new UnsupportedOperationException("Unimplemented method 'resolve'"); - } - @Override public CompilationUnit toCompilationUnit(org.eclipse.jdt.internal.compiler.env.ICompilationUnit sourceUnit, boolean initialNeedsToResolveBinding, IJavaProject project, List classpaths, NodeSearcher nodeSearcher, int apiLevel, Map compilerOptions, WorkingCopyOwner workingCopyOwner, WorkingCopyOwner typeRootWorkingCopyOwner, int flags, IProgressMonitor monitor) { - // TODO currently only parse + CompilationUnit res2 = CompilationUnitResolver.FACADE.toCompilationUnit(sourceUnit, initialNeedsToResolveBinding, project, classpaths, nodeSearcher, apiLevel, compilerOptions, typeRootWorkingCopyOwner, typeRootWorkingCopyOwner, flags, monitor); CompilationUnit res = parse(new org.eclipse.jdt.internal.compiler.env.ICompilationUnit[] { sourceUnit}, apiLevel, compilerOptions, flags, project, monitor).get(sourceUnit); if (initialNeedsToResolveBinding) { ((JavacBindingResolver)res.ast.getBindingResolver()).isRecoveringBindings = (flags & ICompilationUnit.ENABLE_BINDINGS_RECOVERY) != 0; resolveBindings(res); } - // For comparison -// CompilationUnit res2 = CompilationUnitResolver.FACADE.toCompilationUnit(sourceUnit, initialNeedsToResolveBinding, project, classpaths, nodeSearcher, apiLevel, compilerOptions, typeRootWorkingCopyOwner, typeRootWorkingCopyOwner, flags, monitor); -// //res.typeAndFlags=res2.typeAndFlags; -// String res1a = res.toString(); -// String res2a = res2.toString(); -// -// AnnotationTypeDeclaration l1 = (AnnotationTypeDeclaration)res.types().get(0); -// AnnotationTypeDeclaration l2 = (AnnotationTypeDeclaration)res2.types().get(0); -// Object o1 = l1.bodyDeclarations().get(0); -// Object o2 = l2.bodyDeclarations().get(0); + + res2.subtreeMatch(new CustomASTMatcher(), res); return res; } + private Map parse(org.eclipse.jdt.internal.compiler.env.ICompilationUnit[] sourceUnits, int apiLevel, Map compilerOptions, int flags, IJavaProject javaProject, IProgressMonitor monitor) { if (sourceUnits.length == 0) { @@ -383,6 +495,8 @@ public boolean visit(Javadoc javadoc) { } } catch (IOException ex) { ILog.get().error(ex.getMessage(), ex); + } catch( IllegalStateException ise) { + ILog.get().error(ise.getMessage(), ise); } return result; diff --git a/org.eclipse.jdt.core.javac/src/org/eclipse/jdt/core/dom/JavacConverter.java b/org.eclipse.jdt.core.javac/src/org/eclipse/jdt/core/dom/JavacConverter.java index 9eb8b689e80..952905cdec8 100644 --- a/org.eclipse.jdt.core.javac/src/org/eclipse/jdt/core/dom/JavacConverter.java +++ b/org.eclipse.jdt.core.javac/src/org/eclipse/jdt/core/dom/JavacConverter.java @@ -253,7 +253,7 @@ private ExportsDirective convert(JCExports javac) { Iterator it = mods.iterator(); while(it.hasNext()) { JCExpression jcpe = it.next(); - Expression e = convertExpression(jcpe); + Expression e = convertExpression(jcpe, res); if( e != null ) res.modules().add(e); } @@ -269,7 +269,7 @@ private OpensDirective convert(JCOpens javac) { Iterator it = mods.iterator(); while(it.hasNext()) { JCExpression jcpe = it.next(); - Expression e = convertExpression(jcpe); + Expression e = convertExpression(jcpe, res); if( e != null ) res.modules().add(e); } @@ -646,7 +646,7 @@ private ASTNode convertMethodInAnnotationTypeDecl(JCMethodDecl javac, ASTNode pa res.modifiers().addAll(convert(javac.getModifiers(), res)); res.setType(convertToType(javac.getReturnType())); if( javac.defaultValue != null) { - res.setDefault(convertExpression(javac.defaultValue)); + res.setDefault(convertExpression(javac.defaultValue, res)); } if (convertName(javac.getName()) instanceof SimpleName simpleName) { res.setName(simpleName); @@ -892,7 +892,7 @@ private VariableDeclaration convertVariableDeclaration(JCVariableDecl javac) { } } if (javac.getInitializer() != null) { - res.setInitializer(convertExpression(javac.getInitializer())); + res.setInitializer(convertExpression(javac.getInitializer(), res)); } return res; } @@ -937,7 +937,7 @@ private VariableDeclarationFragment createVariableDeclarationFragment(JCVariable } } if (javac.getInitializer() != null) { - fragment.setInitializer(convertExpression(javac.getInitializer())); + fragment.setInitializer(convertExpression(javac.getInitializer(), fragment)); } return fragment; } @@ -1024,7 +1024,7 @@ private void setJavadocForNode(JCTree javac, ASTNode node) { } } - private Expression convertExpressionImpl(JCExpression javac) { + private Expression convertExpressionImpl(JCExpression javac, ASTNode parent) { if (javac instanceof JCIdent ident) { if (Objects.equals(ident.name, Names.instance(this.context)._this)) { ThisExpression res = this.ast.newThisExpression(); @@ -1034,7 +1034,7 @@ private Expression convertExpressionImpl(JCExpression javac) { return toName(ident); } if (javac instanceof JCLiteral literal) { - return convertLiteral(literal); + return convertLiteral(literal, parent); } if (javac instanceof JCFieldAccess fieldAccess) { if (Objects.equals(Names.instance(this.context)._class, fieldAccess.getIdentifier())) { @@ -1065,7 +1065,7 @@ private Expression convertExpressionImpl(JCExpression javac) { if (fieldAccess.getExpression() instanceof JCIdent parentFieldAccess && Objects.equals(Names.instance(this.context)._this, parentFieldAccess.getName())) { FieldAccess res = this.ast.newFieldAccess(); commonSettings(res, javac); - res.setExpression(convertExpression(parentFieldAccess)); + res.setExpression(convertExpression(parentFieldAccess, res)); if (convertName(fieldAccess.getIdentifier()) instanceof SimpleName name) { res.setName(name); } @@ -1080,7 +1080,7 @@ private Expression convertExpressionImpl(JCExpression javac) { } FieldAccess res = this.ast.newFieldAccess(); commonSettings(res, javac); - res.setExpression(convertExpression(fieldAccess.getExpression())); + res.setExpression(convertExpression(fieldAccess.getExpression(), res)); if (convertName(fieldAccess.getIdentifier()) instanceof SimpleName name) { res.setName(name); } @@ -1096,7 +1096,12 @@ private Expression convertExpressionImpl(JCExpression javac) { JCFieldAccess fa = superCall1 ? ((JCFieldAccess)access.getExpression()) : access; SuperMethodInvocation res2 = this.ast.newSuperMethodInvocation(); commonSettings(res2, javac); - methodInvocation.getArguments().stream().map(this::convertExpression).forEach(res2.arguments()::add); + for( JCExpression jce : methodInvocation.getArguments() ) { + Expression e = convertExpression(jce, res2); + if( e != null ) { + res2.arguments().add(e); + } + } if( this.ast.apiLevel != AST.JLS2_INTERNAL) { methodInvocation.getTypeArguments().stream() .map(this::convertToType) @@ -1127,7 +1132,12 @@ private Expression convertExpressionImpl(JCExpression javac) { JCFieldAccess fa = superCall1 ? ((JCFieldAccess)access.getExpression()) : access; SuperMethodInvocation res2 = this.ast.newSuperMethodInvocation(); commonSettings(res2, javac); - methodInvocation.getArguments().stream().map(this::convertExpression).forEach(res.arguments()::add); + for( JCExpression jce : methodInvocation.getArguments() ) { + Expression e = convertExpression(jce, res2); + if( e != null ) { + res2.arguments().add(e); + } + } if( this.ast.apiLevel != AST.JLS2_INTERNAL) { methodInvocation.getTypeArguments().stream() .map(this::convertToType) @@ -1143,12 +1153,15 @@ private Expression convertExpressionImpl(JCExpression javac) { if (convertName(access.getIdentifier()) instanceof SimpleName simpleName) { res.setName(simpleName); } - res.setExpression(convertExpression(access.getExpression())); + res.setExpression(convertExpression(access.getExpression(), res)); } if (methodInvocation.getArguments() != null) { - methodInvocation.getArguments().stream() - .map(this::convertExpression) - .forEach(res.arguments()::add); + for( JCExpression jce : methodInvocation.getArguments() ) { + Expression e = convertExpression(jce, res); + if( e != null ) { + res.arguments().add(e); + } + } } if (methodInvocation.getTypeArguments() != null) { if( this.ast.apiLevel != AST.JLS2_INTERNAL) { @@ -1175,12 +1188,15 @@ private Expression convertExpressionImpl(JCExpression javac) { res.setAnonymousClassDeclaration(anon); } if (newClass.getArguments() != null) { - newClass.getArguments().stream() - .map(this::convertExpression) - .forEach(res.arguments()::add); + for( JCExpression jce : newClass.getArguments() ) { + Expression e = convertExpression(jce, res); + if( e != null ) { + res.arguments().add(e); + } + } } if (newClass.encl != null) { - res.setExpression(convertExpression(newClass.encl)); + res.setExpression(convertExpression(newClass.encl, res)); } if( newClass.getTypeArguments() != null && this.ast.apiLevel != AST.JLS2_INTERNAL) { Iterator it = newClass.getTypeArguments().iterator(); @@ -1196,11 +1212,11 @@ private Expression convertExpressionImpl(JCExpression javac) { if (javac instanceof JCBinary binary) { InfixExpression res = this.ast.newInfixExpression(); commonSettings(res, javac); - Expression left = convertExpression(binary.getLeftOperand()); + Expression left = convertExpression(binary.getLeftOperand(), res); if (left != null) { res.setLeftOperand(left); } - Expression right = convertExpression(binary.getRightOperand()); + Expression right = convertExpression(binary.getRightOperand(), res); if (right != null) { res.setRightOperand(right); } @@ -1232,7 +1248,7 @@ private Expression convertExpressionImpl(JCExpression javac) { if (unary.getTag() != Tag.POSTINC && unary.getTag() != Tag.POSTDEC) { PrefixExpression res = this.ast.newPrefixExpression(); commonSettings(res, javac); - res.setOperand(convertExpression(unary.getExpression())); + res.setOperand(convertExpression(unary.getExpression(), res)); res.setOperator(switch (unary.getTag()) { case POS -> PrefixExpression.Operator.PLUS; case NEG -> PrefixExpression.Operator.MINUS; @@ -1246,7 +1262,7 @@ private Expression convertExpressionImpl(JCExpression javac) { } else { PostfixExpression res = this.ast.newPostfixExpression(); commonSettings(res, javac); - res.setOperand(convertExpression(unary.getExpression())); + res.setOperand(convertExpression(unary.getExpression(), res)); res.setOperator(switch (unary.getTag()) { case POSTINC -> PostfixExpression.Operator.INCREMENT; case POSTDEC -> PostfixExpression.Operator.DECREMENT; @@ -1258,21 +1274,21 @@ private Expression convertExpressionImpl(JCExpression javac) { if (javac instanceof JCParens parens) { ParenthesizedExpression res = this.ast.newParenthesizedExpression(); commonSettings(res, javac); - res.setExpression(convertExpression(parens.getExpression())); + res.setExpression(convertExpression(parens.getExpression(), res)); return res; } if (javac instanceof JCAssign assign) { Assignment res = this.ast.newAssignment(); commonSettings(res, javac); - res.setLeftHandSide(convertExpression(assign.getVariable())); - res.setRightHandSide(convertExpression(assign.getExpression())); + res.setLeftHandSide(convertExpression(assign.getVariable(), res)); + res.setRightHandSide(convertExpression(assign.getExpression(), res)); return res; } if (javac instanceof JCAssignOp assignOp) { Assignment res = this.ast.newAssignment(); commonSettings(res, javac); - res.setLeftHandSide(convertExpression(assignOp.getVariable())); - res.setRightHandSide(convertExpression(assignOp.getExpression())); + res.setLeftHandSide(convertExpression(assignOp.getVariable(), res)); + res.setRightHandSide(convertExpression(assignOp.getExpression(), res)); res.setOperator(switch (assignOp.getTag()) { case PLUS_ASG -> Assignment.Operator.PLUS_ASSIGN; case BITOR_ASG -> Assignment.Operator.BIT_OR_ASSIGN; @@ -1293,7 +1309,7 @@ private Expression convertExpressionImpl(JCExpression javac) { if (jcInstanceOf.getType() != null) { InstanceofExpression res = this.ast.newInstanceofExpression(); commonSettings(res, javac); - res.setLeftOperand(convertExpression(jcInstanceOf.getExpression())); + res.setLeftOperand(convertExpression(jcInstanceOf.getExpression(), res)); res.setRightOperand(convertToType(jcInstanceOf.getType())); return res; } @@ -1301,27 +1317,27 @@ private Expression convertExpressionImpl(JCExpression javac) { if (jcPattern instanceof JCAnyPattern) { InstanceofExpression res = this.ast.newInstanceofExpression(); commonSettings(res, javac); - res.setLeftOperand(convertExpression(jcInstanceOf.getExpression())); + res.setLeftOperand(convertExpression(jcInstanceOf.getExpression(), res)); throw new UnsupportedOperationException("Right operand not supported yet"); // return res; } PatternInstanceofExpression res = this.ast.newPatternInstanceofExpression(); commonSettings(res, javac); - res.setLeftOperand(convertExpression(jcInstanceOf.getExpression())); + res.setLeftOperand(convertExpression(jcInstanceOf.getExpression(), res)); res.setPattern(convert(jcPattern)); return res; } if (javac instanceof JCArrayAccess jcArrayAccess) { ArrayAccess res = this.ast.newArrayAccess(); commonSettings(res, javac); - res.setArray(convertExpression(jcArrayAccess.getExpression())); - res.setIndex(convertExpression(jcArrayAccess.getIndex())); + res.setArray(convertExpression(jcArrayAccess.getExpression(), res)); + res.setIndex(convertExpression(jcArrayAccess.getIndex(), res)); return res; } if (javac instanceof JCTypeCast jcCast) { CastExpression res = this.ast.newCastExpression(); commonSettings(res, javac); - res.setExpression(convertExpression(jcCast.getExpression())); + res.setExpression(convertExpression(jcCast.getExpression(), res)); res.setType(convertToType(jcCast.getType())); return res; } @@ -1353,7 +1369,7 @@ private Expression convertExpressionImpl(JCExpression javac) { } else { ExpressionMethodReference res = this.ast.newExpressionMethodReference(); commonSettings(res, javac); - res.setExpression(convertExpression(jcMemberReference.getQualifierExpression())); + res.setExpression(convertExpression(jcMemberReference.getQualifierExpression(), res)); res.setName((SimpleName)convertName(jcMemberReference.getName())); if (jcMemberReference.getTypeArguments() != null) { jcMemberReference.getTypeArguments().stream() @@ -1367,9 +1383,9 @@ private Expression convertExpressionImpl(JCExpression javac) { if (javac instanceof JCConditional jcCondition) { ConditionalExpression res = this.ast.newConditionalExpression(); commonSettings(res, javac); - res.setExpression(convertExpression(jcCondition.getCondition())); - res.setThenExpression(convertExpression(jcCondition.getTrueExpression())); - res.setElseExpression(convertExpression(jcCondition.getFalseExpression())); + res.setExpression(convertExpression(jcCondition.getCondition(), res)); + res.setThenExpression(convertExpression(jcCondition.getTrueExpression(), res)); + res.setElseExpression(convertExpression(jcCondition.getFalseExpression(), res)); return res; } if (javac instanceof JCLambda jcLambda) { @@ -1382,7 +1398,7 @@ private Expression convertExpressionImpl(JCExpression javac) { int arrowIndex = this.rawText.indexOf("->", jcLambda.getStartPosition()); int parenthesisIndex = this.rawText.indexOf(")", jcLambda.getStartPosition()); res.setParentheses(parenthesisIndex >= 0 && parenthesisIndex < arrowIndex); - ASTNode body = jcLambda.getBody() instanceof JCExpression expr ? convertExpression(expr) : + ASTNode body = jcLambda.getBody() instanceof JCExpression expr ? convertExpression(expr, res) : jcLambda.getBody() instanceof JCStatement stmt ? convertStatement(stmt, res) : null; if( body != null ) @@ -1427,7 +1443,12 @@ private Expression convertExpressionImpl(JCExpression javac) { commonSettings(arrayType, jcNewArray.getType()); res.setType(arrayType); } - jcNewArray.getDimensions().map(this::convertExpression).forEach(res.dimensions()::add); + for( JCExpression jce : jcNewArray.getDimensions() ) { + Expression e = convertExpression(jce, res); + if( e != null ) { + res.dimensions().add(e); + } + } if (jcNewArray.getInitializers() != null) { res.setInitializer(createArrayInitializerFromJCNewArray(jcNewArray)); } @@ -1448,7 +1469,7 @@ private Expression convertExpressionImpl(JCExpression javac) { if( switchExpr instanceof JCParens jcp) { switchExpr = jcp.getExpression(); } - res.setExpression(convertExpression(switchExpr)); + res.setExpression(convertExpression(switchExpr, res)); List cases = jcSwitch.getCases(); Iterator it = cases.iterator(); @@ -1474,10 +1495,10 @@ private Expression convertExpressionImpl(JCExpression javac) { res.statements().add(s1); } } else if( next instanceof JCExpression jce) { - Expression s1 = convertExpression(jce); + // make a yield statement out of it?? + YieldStatement r1 = this.ast.newYieldStatement(); + Expression s1 = convertExpression(jce, r1); if( s1 != null ) { - // make a yield statement out of it?? - YieldStatement r1 = this.ast.newYieldStatement(); commonSettings(r1, javac); r1.setExpression(s1); res.statements().add(r1); @@ -1489,8 +1510,8 @@ private Expression convertExpressionImpl(JCExpression javac) { return null; } - private Expression convertExpression(JCExpression javac) { - Expression ret = convertExpressionImpl(javac); + private Expression convertExpression(JCExpression javac, ASTNode parent) { + Expression ret = convertExpressionImpl(javac, parent); if( ret != null ) return ret; @@ -1500,7 +1521,7 @@ private Expression convertExpression(JCExpression javac) { JCTree tree = error.getErrorTrees().get(0); if (tree instanceof JCExpression nestedExpr) { try { - return convertExpression(nestedExpr); + return convertExpression(nestedExpr, parent); } catch (Exception ex) { // pass-through: do not break when attempting such reconcile } @@ -1536,7 +1557,12 @@ private ArrayInitializer createArrayInitializerFromJCNewArray(JCNewArray jcNewAr if( jcNewArray.getInitializers().size() > 0 ) { commonSettings(initializer, jcNewArray.getInitializers().get(0)); } - jcNewArray.getInitializers().stream().map(this::convertExpression).forEach(initializer.expressions()::add); + for( JCExpression jce : jcNewArray.getInitializers() ) { + Expression e = convertExpression(jce, initializer); + if( e != null ) { + initializer.expressions().add(e); + } + } return initializer; } @@ -1582,8 +1608,12 @@ private JCTree unwrapDimensions(JCArrayTypeTree tree, int count) { private SuperMethodInvocation convertSuperMethodInvocation(JCMethodInvocation javac) { SuperMethodInvocation res = this.ast.newSuperMethodInvocation(); commonSettings(res, javac); - javac.getArguments().stream().map(this::convertExpression).forEach(res.arguments()::add); - + for( JCExpression jce : javac.getArguments() ) { + Expression e = convertExpression(jce, res); + if( e != null ) { + res.arguments().add(e); + } + } //res.setFlags(javac.getFlags() | ASTNode.MALFORMED); if( this.ast.apiLevel > AST.JLS2_INTERNAL) { javac.getTypeArguments().stream().map(this::convertToType).forEach(res.typeArguments()::add); @@ -1599,7 +1629,12 @@ private SuperConstructorInvocation convertSuperConstructorInvocation(JCMethodInv // jdt expects semicolon to be part of the range res.setSourceRange(res.getStartPosition(), res.getLength() + 1); } - javac.getArguments().stream().map(this::convertExpression).forEach(res.arguments()::add); + for( JCExpression jce : javac.getArguments() ) { + Expression e = convertExpression(jce, res); + if( e != null ) { + res.arguments().add(e); + } + } //res.setFlags(javac.getFlags() | ASTNode.MALFORMED); if( this.ast.apiLevel > AST.JLS2_INTERNAL) { @@ -1609,7 +1644,7 @@ private SuperConstructorInvocation convertSuperConstructorInvocation(JCMethodInv .forEach(res.typeArguments()::add); } if( javac.getMethodSelect() instanceof JCFieldAccess jcfa && jcfa.selected != null ) { - res.setExpression(convertExpression(jcfa.selected)); + res.setExpression(convertExpression(jcfa.selected, res)); } return res; } @@ -1618,7 +1653,12 @@ private SuperConstructorInvocation convertSuperConstructorInvocation(JCMethodInv private ConstructorInvocation convertThisConstructorInvocation(JCMethodInvocation javac) { ConstructorInvocation res = this.ast.newConstructorInvocation(); commonSettings(res, javac); - javac.getArguments().stream().map(this::convertExpression).forEach(res.arguments()::add); + for( JCExpression jce : javac.getArguments() ) { + Expression e = convertExpression(jce, res); + if( e != null ) { + res.arguments().add(e); + } + } if( this.ast.apiLevel > AST.JLS2_INTERNAL) { javac.getTypeArguments().stream() .map(this::convertToType) @@ -1628,21 +1668,27 @@ private ConstructorInvocation convertThisConstructorInvocation(JCMethodInvocatio return res; } - private Expression convertLiteral(JCLiteral literal) { + private Expression convertLiteral(JCLiteral literal, ASTNode parent) { Object value = literal.getValue(); if (value instanceof Number number) { char firstChar = number.toString().charAt(0); - if( firstChar != '-' ) { + boolean firstCharMinus = firstChar == '-'; + int startPos = literal.getStartPosition(); + int startPosPostSign = startPos; + if( firstCharMinus ) { + startPosPostSign++; + } + boolean useNumberLiteral = !firstCharMinus || (parent instanceof MethodInvocation); + if( useNumberLiteral ) { NumberLiteral res = this.ast.newNumberLiteral(); commonSettings(res, literal); - String fromSrc = this.rawText.substring(res.getStartPosition(), res.getStartPosition() + res.getLength()); + String fromSrc = this.rawText.substring(startPos, startPos + res.getLength()); res.setToken(fromSrc); return res; } else { PrefixExpression res = this.ast.newPrefixExpression(); commonSettings(res, literal); - - String fromSrc = this.rawText.substring(res.getStartPosition()+1, res.getStartPosition() + res.getLength()); + String fromSrc = this.rawText.substring(startPosPostSign, startPos + res.getLength()); NumberLiteral operand = this.ast.newNumberLiteral(); commonSettings(operand, literal); operand.setToken(fromSrc); @@ -1692,7 +1738,7 @@ private Statement convertStatement(JCStatement javac, ASTNode parent) { ReturnStatement res = this.ast.newReturnStatement(); commonSettings(res, javac); if (returnStatement.getExpression() != null) { - res.setExpression(convertExpression(returnStatement.getExpression())); + res.setExpression(convertExpression(returnStatement.getExpression(), res)); } return res; } @@ -1723,8 +1769,9 @@ private Statement convertStatement(JCStatement javac, ASTNode parent) { } } if (tree instanceof JCExpression expr) { - Expression expression = convertExpression(expr); - ExpressionStatement res = this.ast.newExpressionStatement(expression); + ExpressionStatement res = new ExpressionStatement(this.ast); + Expression expression = convertExpression(expr, res); + res.setExpression(expression); commonSettings(res, javac); return res; } @@ -1751,7 +1798,7 @@ private Statement convertStatement(JCStatement javac, ASTNode parent) { if( uniqueCaseFound ) { return convertSuperConstructorInvocation((JCMethodInvocation)jcExpressionStatement.getExpression()); } - ExpressionStatement res = this.ast.newExpressionStatement(convertExpression(jcExpressionStatement.getExpression())); + ExpressionStatement res = this.ast.newExpressionStatement(convertExpression(jcExpressionStatement.getExpression(), parent)); commonSettings(res, javac); return res; } @@ -1792,7 +1839,7 @@ private Statement convertStatement(JCStatement javac, ASTNode parent) { if (javac instanceof JCThrow throwStatement) { ThrowStatement res = this.ast.newThrowStatement(); commonSettings(res, javac); - res.setExpression(convertExpression(throwStatement.getExpression())); + res.setExpression(convertExpression(throwStatement.getExpression(), res)); return res; } if (javac instanceof JCTry tryStatement) { @@ -1805,7 +1852,7 @@ private Statement convertStatement(JCStatement javac, ASTNode parent) { if( syncExpr instanceof JCParens jcp) { syncExpr = jcp.getExpression(); } - res.setExpression(convertExpression(syncExpr)); + res.setExpression(convertExpression(syncExpr, res)); res.setBody(convertBlock(jcSynchronized.getBlock())); return res; } @@ -1822,7 +1869,7 @@ private Statement convertStatement(JCStatement javac, ASTNode parent) { res.initializers().add(expr); } if (jcForLoop.getCondition() != null) { - Expression expr = convertExpression(jcForLoop.getCondition()); + Expression expr = convertExpression(jcForLoop.getCondition(), res); if( expr != null ) res.setExpression(expr); } @@ -1840,7 +1887,7 @@ private Statement convertStatement(JCStatement javac, ASTNode parent) { EnhancedForStatement res = this.ast.newEnhancedForStatement(); commonSettings(res, javac); res.setParameter((SingleVariableDeclaration)convertVariableDeclaration(jcEnhancedForLoop.getVariable())); - Expression expr = convertExpression(jcEnhancedForLoop.getExpression()); + Expression expr = convertExpression(jcEnhancedForLoop.getExpression(), res); if( expr != null ) res.setExpression(expr); Statement stmt = convertStatement(jcEnhancedForLoop.getStatement(), res); @@ -1868,7 +1915,7 @@ private Statement convertStatement(JCStatement javac, ASTNode parent) { if( switchExpr instanceof JCParens jcp) { switchExpr = jcp.getExpression(); } - res.setExpression(convertExpression(switchExpr)); + res.setExpression(convertExpression(switchExpr, res)); jcSwitch.getCases().stream() .flatMap(switchCase -> { int numStatements = switchCase.getStatements() != null ? switchCase.getStatements().size() : 0; @@ -1889,7 +1936,7 @@ private Statement convertStatement(JCStatement javac, ASTNode parent) { if( this.ast.apiLevel >= AST.JLS14_INTERNAL) { if (jcCase.getGuard() != null && (jcCase.getLabels().size() > 1 || jcCase.getLabels().get(0) instanceof JCPatternCaseLabel)) { GuardedPattern guardedPattern = this.ast.newGuardedPattern(); - guardedPattern.setExpression(convertExpression(jcCase.getGuard())); + guardedPattern.setExpression(convertExpression(jcCase.getGuard(), guardedPattern)); if (jcCase.getLabels().length() > 1) { int start = Integer.MAX_VALUE; int end = Integer.MIN_VALUE; @@ -1921,13 +1968,18 @@ private Statement convertStatement(JCStatement javac, ASTNode parent) { guardedPattern.setSourceRange(start, end - start); res.expressions().add(guardedPattern); } else { - jcCase.getExpressions().stream().map(this::convertExpression).forEach(res.expressions()::add); + for (JCExpression jce : jcCase.getExpressions()) { + Expression e = convertExpression(jce, res); + if( e != null ) { + res.expressions().add(e); + } + } } res.setSwitchLabeledRule(jcCase.getCaseKind() == CaseKind.RULE); } else { List l = jcCase.getExpressions(); if( l.size() == 1 ) { - res.setExpression(convertExpression(l.get(0))); + res.setExpression(convertExpression(l.get(0), res)); } else if( l.size() == 0 ) { res.setExpression(null); } @@ -1942,7 +1994,7 @@ private Statement convertStatement(JCStatement javac, ASTNode parent) { if( expr instanceof JCParens jcp) { expr = jcp.getExpression(); } - res.setExpression(convertExpression(expr)); + res.setExpression(convertExpression(expr, res)); Statement body = convertStatement(jcWhile.getStatement(), res); if( body != null ) res.setBody(body); @@ -1955,7 +2007,7 @@ private Statement convertStatement(JCStatement javac, ASTNode parent) { if( expr instanceof JCParens jcp) { expr = jcp.getExpression(); } - Expression expr1 = convertExpression(expr); + Expression expr1 = convertExpression(expr, res); if( expr != null ) res.setExpression(expr1); @@ -1967,7 +2019,7 @@ private Statement convertStatement(JCStatement javac, ASTNode parent) { if (javac instanceof JCYield jcYield) { YieldStatement res = this.ast.newYieldStatement(); commonSettings(res, javac); - res.setExpression(convertExpression(jcYield.getValue())); + res.setExpression(convertExpression(jcYield.getValue(), res)); return res; } if (javac instanceof JCContinue jcContinue) { @@ -1990,11 +2042,11 @@ private Statement convertStatement(JCStatement javac, ASTNode parent) { if (javac instanceof JCAssert jcAssert) { AssertStatement res =this.ast.newAssertStatement(); commonSettings(res, javac); - Expression expr = convertExpression(jcAssert.getCondition()); + Expression expr = convertExpression(jcAssert.getCondition(), res); if( expr != null ) res.setExpression(expr); if( jcAssert.getDetail() != null ) { - Expression det = convertExpression(jcAssert.getDetail()); + Expression det = convertExpression(jcAssert.getDetail(), res); if( det != null ) res.setMessage(det); } @@ -2015,7 +2067,7 @@ private Statement convertStatement(JCStatement javac, ASTNode parent) { private Expression convertStatementToExpression(JCStatement javac, ASTNode parent) { if (javac instanceof JCExpressionStatement jcExpressionStatement) { - return convertExpression(jcExpressionStatement.getExpression()); + return convertExpression(jcExpressionStatement.getExpression(), parent); } Statement javacStatement = convertStatement(javac, parent); if (javacStatement instanceof VariableDeclarationStatement decl && decl.fragments().size() == 1) { @@ -2147,9 +2199,9 @@ private IfStatement convertIfStatement(JCIf javac) { if (javac.getCondition() != null) { JCExpression expr = javac.getCondition(); if( expr instanceof JCParens jpc) { - res.setExpression(convertExpression(jpc.getExpression())); + res.setExpression(convertExpression(jpc.getExpression(), res)); } else { - res.setExpression(convertExpression(expr)); + res.setExpression(convertExpression(expr, res)); } } if (javac.getThenStatement() != null) { @@ -2338,7 +2390,7 @@ private Annotation convert(JCAnnotation javac) { JCTree value = javac.getArguments().get(0); if (value != null) { if( value instanceof JCExpression jce) { - result.setValue(convertExpression(jce)); + result.setValue(convertExpression(jce, result)); } else { result.setValue(toName(value)); } @@ -2367,10 +2419,15 @@ private Annotation convert(JCAnnotation javac) { if (jcass.rhs instanceof JCNewArray jcNewArray) { ArrayInitializer initializer = this.ast.newArrayInitializer(); commonSettings(initializer, javac); - jcNewArray.getInitializers().stream().map(this::convertExpression).forEach(initializer.expressions()::add); + for( JCExpression jce : jcNewArray.getInitializers()) { + Expression e = convertExpression(jce, initializer); + if( e != null ) { + initializer.expressions().add(e); + } + } value = initializer; } else { - value = convertExpression(jcass.rhs); + value = convertExpression(jcass.rhs, pair); } commonSettings(value, jcass.rhs); pair.setValue(value); @@ -2736,7 +2793,7 @@ private EnumConstantDeclaration convertEnumConstantDeclaration(JCTree var, ASTNo if( jcnc.getArguments() != null ) { Iterator it = jcnc.getArguments().iterator(); while(it.hasNext()) { - Expression e = convertExpression(it.next()); + Expression e = convertExpression(it.next(), enumConstantDeclaration); if( e != null ) { enumConstantDeclaration.arguments().add(e); } diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverter9Test.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverter9Test.java index e53b8dbc720..6bc8a326c96 100644 --- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverter9Test.java +++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverter9Test.java @@ -20,9 +20,47 @@ import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.core.runtime.Path; -import org.eclipse.jdt.core.*; +import org.eclipse.jdt.core.IClasspathAttribute; +import org.eclipse.jdt.core.ICompilationUnit; +import org.eclipse.jdt.core.IJavaElement; +import org.eclipse.jdt.core.IJavaProject; +import org.eclipse.jdt.core.IModularClassFile; +import org.eclipse.jdt.core.IModuleDescription; +import org.eclipse.jdt.core.IPackageFragmentRoot; +import org.eclipse.jdt.core.IType; +import org.eclipse.jdt.core.JavaCore; +import org.eclipse.jdt.core.JavaModelException; import org.eclipse.jdt.core.compiler.IProblem; -import org.eclipse.jdt.core.dom.*; +import org.eclipse.jdt.core.dom.AST; +import org.eclipse.jdt.core.dom.ASTNode; +import org.eclipse.jdt.core.dom.ASTParser; +import org.eclipse.jdt.core.dom.ASTRequestor; +import org.eclipse.jdt.core.dom.AbstractTypeDeclaration; +import org.eclipse.jdt.core.dom.CompilationUnit; +import org.eclipse.jdt.core.dom.ExportsDirective; +import org.eclipse.jdt.core.dom.Expression; +import org.eclipse.jdt.core.dom.FieldAccess; +import org.eclipse.jdt.core.dom.IAnnotationBinding; +import org.eclipse.jdt.core.dom.IBinding; +import org.eclipse.jdt.core.dom.IModuleBinding; +import org.eclipse.jdt.core.dom.IPackageBinding; +import org.eclipse.jdt.core.dom.ITypeBinding; +import org.eclipse.jdt.core.dom.ImportDeclaration; +import org.eclipse.jdt.core.dom.MethodDeclaration; +import org.eclipse.jdt.core.dom.ModuleDeclaration; +import org.eclipse.jdt.core.dom.ModuleDirective; +import org.eclipse.jdt.core.dom.Name; +import org.eclipse.jdt.core.dom.PackageDeclaration; +import org.eclipse.jdt.core.dom.ProvidesDirective; +import org.eclipse.jdt.core.dom.QualifiedName; +import org.eclipse.jdt.core.dom.RequiresDirective; +import org.eclipse.jdt.core.dom.SimpleName; +import org.eclipse.jdt.core.dom.SuperFieldAccess; +import org.eclipse.jdt.core.dom.TryStatement; +import org.eclipse.jdt.core.dom.TypeDeclaration; +import org.eclipse.jdt.core.dom.TypeParameter; +import org.eclipse.jdt.core.dom.UsesDirective; +import org.eclipse.jdt.core.dom.VariableDeclarationExpression; import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; import org.eclipse.jdt.internal.core.JrtPackageFragmentRoot; @@ -832,6 +870,7 @@ public void testBug526534_0002() throws JavaModelException { ModuleDeclaration moduleDecl = unit.getModule(); assertTrue(moduleDecl.isOpen()); } catch (ClassCastException e) { + e.printStackTrace(); assertFalse(true); } } @@ -1366,6 +1405,7 @@ public void testBug530803_1() throws Exception { ModuleDeclaration moduleDeclaration2 = cu2.getModule(); ModuleDirective stat = (ModuleDirective) moduleDeclaration2.moduleStatements().get(0); IBinding requiredModule = ((RequiresDirective) stat).getName().resolveBinding(); + String s = requiredModule.getKey(); validateBinding.accept(requiredModule); } finally { diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverterTest.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverterTest.java index 84291dfa06c..4f82b2fc5f2 100644 --- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverterTest.java +++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverterTest.java @@ -14,17 +14,102 @@ package org.eclipse.jdt.core.tests.dom; -import java.util.*; - -import junit.framework.Test; +import java.util.Enumeration; +import java.util.List; import org.eclipse.core.runtime.preferences.IEclipsePreferences; import org.eclipse.core.runtime.preferences.InstanceScope; -import org.eclipse.jdt.core.*; -import org.eclipse.jdt.core.dom.*; -import org.eclipse.jdt.core.jdom.*; +import org.eclipse.jdt.core.ICompilationUnit; +import org.eclipse.jdt.core.IField; +import org.eclipse.jdt.core.IJavaProject; +import org.eclipse.jdt.core.IType; +import org.eclipse.jdt.core.JavaCore; +import org.eclipse.jdt.core.JavaModelException; +import org.eclipse.jdt.core.dom.AST; +import org.eclipse.jdt.core.dom.ASTMatcher; +import org.eclipse.jdt.core.dom.ASTNode; +import org.eclipse.jdt.core.dom.AnonymousClassDeclaration; +import org.eclipse.jdt.core.dom.ArrayCreation; +import org.eclipse.jdt.core.dom.ArrayInitializer; +import org.eclipse.jdt.core.dom.ArrayType; +import org.eclipse.jdt.core.dom.Assignment; +import org.eclipse.jdt.core.dom.Block; +import org.eclipse.jdt.core.dom.BodyDeclaration; +import org.eclipse.jdt.core.dom.BooleanLiteral; +import org.eclipse.jdt.core.dom.BreakStatement; +import org.eclipse.jdt.core.dom.CastExpression; +import org.eclipse.jdt.core.dom.CatchClause; +import org.eclipse.jdt.core.dom.CharacterLiteral; +import org.eclipse.jdt.core.dom.ClassInstanceCreation; +import org.eclipse.jdt.core.dom.CompilationUnit; +import org.eclipse.jdt.core.dom.ConditionalExpression; +import org.eclipse.jdt.core.dom.ContinueStatement; +import org.eclipse.jdt.core.dom.CustomASTMatcher; +import org.eclipse.jdt.core.dom.DoStatement; +import org.eclipse.jdt.core.dom.EmptyStatement; +import org.eclipse.jdt.core.dom.EnumConstantDeclaration; +import org.eclipse.jdt.core.dom.EnumDeclaration; +import org.eclipse.jdt.core.dom.Expression; +import org.eclipse.jdt.core.dom.ExpressionStatement; +import org.eclipse.jdt.core.dom.FieldAccess; +import org.eclipse.jdt.core.dom.FieldDeclaration; +import org.eclipse.jdt.core.dom.ForStatement; +import org.eclipse.jdt.core.dom.IBinding; +import org.eclipse.jdt.core.dom.IMethodBinding; +import org.eclipse.jdt.core.dom.IPackageBinding; +import org.eclipse.jdt.core.dom.ITypeBinding; +import org.eclipse.jdt.core.dom.IVariableBinding; +import org.eclipse.jdt.core.dom.IfStatement; +import org.eclipse.jdt.core.dom.ImportDeclaration; +import org.eclipse.jdt.core.dom.InfixExpression; +import org.eclipse.jdt.core.dom.Initializer; +import org.eclipse.jdt.core.dom.InstanceofExpression; +import org.eclipse.jdt.core.dom.Javadoc; +import org.eclipse.jdt.core.dom.LabeledStatement; +import org.eclipse.jdt.core.dom.MethodDeclaration; +import org.eclipse.jdt.core.dom.MethodInvocation; +import org.eclipse.jdt.core.dom.Modifier; +import org.eclipse.jdt.core.dom.Name; +import org.eclipse.jdt.core.dom.NullLiteral; +import org.eclipse.jdt.core.dom.NumberLiteral; +import org.eclipse.jdt.core.dom.PackageDeclaration; +import org.eclipse.jdt.core.dom.ParenthesizedExpression; +import org.eclipse.jdt.core.dom.PostfixExpression; +import org.eclipse.jdt.core.dom.PrefixExpression; +import org.eclipse.jdt.core.dom.PrimitiveType; +import org.eclipse.jdt.core.dom.QualifiedName; +import org.eclipse.jdt.core.dom.ReturnStatement; +import org.eclipse.jdt.core.dom.SimpleName; +import org.eclipse.jdt.core.dom.SimpleType; +import org.eclipse.jdt.core.dom.SingleVariableDeclaration; +import org.eclipse.jdt.core.dom.Statement; +import org.eclipse.jdt.core.dom.StringLiteral; +import org.eclipse.jdt.core.dom.SuperConstructorInvocation; +import org.eclipse.jdt.core.dom.SuperFieldAccess; +import org.eclipse.jdt.core.dom.SuperMethodInvocation; +import org.eclipse.jdt.core.dom.SwitchCase; +import org.eclipse.jdt.core.dom.SwitchStatement; +import org.eclipse.jdt.core.dom.SynchronizedStatement; +import org.eclipse.jdt.core.dom.ThisExpression; +import org.eclipse.jdt.core.dom.ThrowStatement; +import org.eclipse.jdt.core.dom.TryStatement; +import org.eclipse.jdt.core.dom.Type; +import org.eclipse.jdt.core.dom.TypeDeclaration; +import org.eclipse.jdt.core.dom.TypeDeclarationStatement; +import org.eclipse.jdt.core.dom.TypeLiteral; +import org.eclipse.jdt.core.dom.VariableDeclarationExpression; +import org.eclipse.jdt.core.dom.VariableDeclarationFragment; +import org.eclipse.jdt.core.dom.VariableDeclarationStatement; +import org.eclipse.jdt.core.dom.WhileStatement; +import org.eclipse.jdt.core.jdom.DOMFactory; +import org.eclipse.jdt.core.jdom.IDOMCompilationUnit; +import org.eclipse.jdt.core.jdom.IDOMMethod; +import org.eclipse.jdt.core.jdom.IDOMNode; +import org.eclipse.jdt.core.jdom.IDOMType; import org.eclipse.jdt.core.util.IModifierConstants; +import junit.framework.Test; + @SuppressWarnings("rawtypes") public class ASTConverterTest extends ConverterTestSetup { @@ -115,7 +200,7 @@ public void test0001() throws JavaModelException { methodDeclaration.setBody(block); type.bodyDeclarations().add(methodDeclaration); unit.types().add(type); - assertTrue("Both AST trees should be identical", result.subtreeMatch(new ASTMatcher(), unit));//$NON-NLS-1$ + assertTrue("Both AST trees should be identical", result.subtreeMatch(createASTMatcher(), unit));//$NON-NLS-1$ String expected = "package test0001;\n" + "import java.util.*;\n" + @@ -139,7 +224,7 @@ public void test0002() throws JavaModelException { assertNotNull("Expression should not be null", expression); //$NON-NLS-1$ ClassInstanceCreation classInstanceCreation = this.ast.newClassInstanceCreation(); classInstanceCreation.setName(this.ast.newSimpleName("Object")); //$NON-NLS-1$ - assertTrue("Both AST trees should be identical", classInstanceCreation.subtreeMatch(new ASTMatcher(), expression)); //$NON-NLS-1$ + assertTrue("Both AST trees should be identical", classInstanceCreation.subtreeMatch(createASTMatcher(), expression)); //$NON-NLS-1$ checkSourceRange(expression, "new Object()", source); //$NON-NLS-1$ } @@ -161,7 +246,7 @@ public void test0003() throws JavaModelException { this.ast.newSimpleName("lang")), //$NON-NLS-1$ this.ast.newSimpleName("Object"));//$NON-NLS-1$ classInstanceCreation.setName(name); - assertTrue("Both AST trees should be identical", classInstanceCreation.subtreeMatch(new ASTMatcher(), expression)); //$NON-NLS-1$ + assertTrue("Both AST trees should be identical", classInstanceCreation.subtreeMatch(createASTMatcher(), expression)); //$NON-NLS-1$ checkSourceRange(expression, "new java.lang.Object()", source); //$NON-NLS-1$ } @@ -186,7 +271,7 @@ public void test0004() throws JavaModelException { StringLiteral literal = this.ast.newStringLiteral(); literal.setLiteralValue("ERROR"); //$NON-NLS-1$ classInstanceCreation.arguments().add(literal); - assertTrue("Both AST trees should be identical", classInstanceCreation.subtreeMatch(new ASTMatcher(), expression)); //$NON-NLS-1$ + assertTrue("Both AST trees should be identical", classInstanceCreation.subtreeMatch(createASTMatcher(), expression)); //$NON-NLS-1$ checkSourceRange(expression, "new java.lang.Exception(\"ERROR\")", source); //$NON-NLS-1$ } @@ -210,7 +295,7 @@ public void test0005() throws JavaModelException { classInstanceCreation.setName(name); AnonymousClassDeclaration anonymousClassDeclaration = this.ast.newAnonymousClassDeclaration(); classInstanceCreation.setAnonymousClassDeclaration(anonymousClassDeclaration); - assertTrue("Both AST trees should be identical", classInstanceCreation.subtreeMatch(new ASTMatcher(), expression)); //$NON-NLS-1$ + assertTrue("Both AST trees should be identical", classInstanceCreation.subtreeMatch(createASTMatcher(), expression)); //$NON-NLS-1$ checkSourceRange(expression, "new java.lang.Object() {}", source); //$NON-NLS-1$ ClassInstanceCreation classInstanceCreation2 = (ClassInstanceCreation) expression; Name name2 = classInstanceCreation2.getName(); @@ -245,7 +330,7 @@ public void test0006() throws JavaModelException { AnonymousClassDeclaration anonymousClassDeclaration = this.ast.newAnonymousClassDeclaration(); anonymousClassDeclaration.bodyDeclarations().add(methodDeclaration); classInstanceCreation.setAnonymousClassDeclaration(anonymousClassDeclaration); - assertTrue("Both AST trees should be identical", classInstanceCreation.subtreeMatch(new ASTMatcher(), expression)); //$NON-NLS-1$ + assertTrue("Both AST trees should be identical", classInstanceCreation.subtreeMatch(createASTMatcher(), expression)); //$NON-NLS-1$ checkSourceRange(expression, "new java.lang.Runnable() { public void run() {}}", source); //$NON-NLS-1$ } @@ -267,7 +352,7 @@ public void test0007() throws JavaModelException { ClassInstanceCreation classInstanceCreationExpression = this.ast.newClassInstanceCreation(); classInstanceCreationExpression.setName(this.ast.newSimpleName("Test")); //$NON-NLS-1$ classInstanceCreation.setExpression(classInstanceCreationExpression); - assertTrue("Both AST trees should be identical", classInstanceCreation.subtreeMatch(new ASTMatcher(), expression)); //$NON-NLS-1$ + assertTrue("Both AST trees should be identical", classInstanceCreation.subtreeMatch(createASTMatcher(), expression)); //$NON-NLS-1$ checkSourceRange(expression, "new Test().new D()", source); //$NON-NLS-1$ } @@ -288,7 +373,7 @@ public void test0008() throws JavaModelException { arrayInitializer.expressions().add(this.ast.newNumberLiteral("3"));//$NON-NLS-1$ arrayInitializer.expressions().add(this.ast.newNumberLiteral("4"));//$NON-NLS-1$ arrayCreation.setInitializer(arrayInitializer); - assertTrue("Both AST trees should be identical", arrayCreation.subtreeMatch(new ASTMatcher(), expression)); //$NON-NLS-1$ + assertTrue("Both AST trees should be identical", arrayCreation.subtreeMatch(createASTMatcher(), expression)); //$NON-NLS-1$ checkSourceRange(expression, "new int[] {1, 2, 3, 4}", source); //$NON-NLS-1$ } @@ -311,7 +396,7 @@ public void test0009() throws JavaModelException { innerArrayInitializer.expressions().add(this.ast.newNumberLiteral("2"));//$NON-NLS-1$ arrayInitializer.expressions().add(innerArrayInitializer); arrayCreation.setInitializer(arrayInitializer); - assertTrue("Both AST trees should be identical", arrayCreation.subtreeMatch(new ASTMatcher(), expression)); //$NON-NLS-1$ + assertTrue("Both AST trees should be identical", arrayCreation.subtreeMatch(createASTMatcher(), expression)); //$NON-NLS-1$ checkSourceRange(expression, "new int[][] {{1}, {2}}", source); //$NON-NLS-1$ } @@ -327,7 +412,7 @@ public void test0010() throws JavaModelException { ArrayCreation arrayCreation = this.ast.newArrayCreation(); arrayCreation.setType(this.ast.newArrayType(this.ast.newPrimitiveType(PrimitiveType.INT), 1)); arrayCreation.dimensions().add(this.ast.newNumberLiteral("3")); //$NON-NLS-1$ - assertTrue("Both AST trees should be identical", arrayCreation.subtreeMatch(new ASTMatcher(), expression)); //$NON-NLS-1$ + assertTrue("Both AST trees should be identical", arrayCreation.subtreeMatch(createASTMatcher(), expression)); //$NON-NLS-1$ checkSourceRange(expression, "new int[3]", source); //$NON-NLS-1$ } @@ -343,7 +428,7 @@ public void test0011() throws JavaModelException { ArrayCreation arrayCreation = this.ast.newArrayCreation(); arrayCreation.setType(this.ast.newArrayType(this.ast.newPrimitiveType(PrimitiveType.INT), 2)); arrayCreation.dimensions().add(this.ast.newNumberLiteral("3")); //$NON-NLS-1$ - assertTrue("Both AST trees should be identical", arrayCreation.subtreeMatch(new ASTMatcher(), expression)); //$NON-NLS-1$ + assertTrue("Both AST trees should be identical", arrayCreation.subtreeMatch(createASTMatcher(), expression)); //$NON-NLS-1$ checkSourceRange(expression, "new int[3][]", source); //$NON-NLS-1$ } @@ -364,7 +449,7 @@ public void test0012() throws JavaModelException { innerArrayInitializer = this.ast.newArrayInitializer(); arrayInitializer.expressions().add(innerArrayInitializer); arrayCreation.setInitializer(arrayInitializer); - assertTrue("Both AST trees should be identical", arrayCreation.subtreeMatch(new ASTMatcher(), expression)); //$NON-NLS-1$ + assertTrue("Both AST trees should be identical", arrayCreation.subtreeMatch(createASTMatcher(), expression)); //$NON-NLS-1$ checkSourceRange(expression, "new int[][] {{}, {}}", source); //$NON-NLS-1$ } @@ -383,7 +468,7 @@ public void test0013() throws JavaModelException { VariableDeclarationStatement statement = this.ast.newVariableDeclarationStatement(variableDeclarationFragment); statement.setModifiers(Modifier.NONE); statement.setType(this.ast.newPrimitiveType(PrimitiveType.INT)); - assertTrue("Both AST trees should be identical", statement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$ + assertTrue("Both AST trees should be identical", statement.subtreeMatch(createASTMatcher(), node)); //$NON-NLS-1$ checkSourceRange(node, "int i;", source); //$NON-NLS-1$ } @@ -404,7 +489,7 @@ public void test0014() throws JavaModelException { statement.setModifiers(Modifier.NONE); statement.setType(this.ast.newPrimitiveType(PrimitiveType.INT)); - assertTrue("Both AST trees should be identical", statement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$ + assertTrue("Both AST trees should be identical", statement.subtreeMatch(createASTMatcher(), node)); //$NON-NLS-1$ checkSourceRange(node, "int i = 0;", source); //$NON-NLS-1$ } @@ -422,7 +507,7 @@ public void test0015() throws JavaModelException { assignment.setRightHandSide(this.ast.newNumberLiteral("1")); //$NON-NLS-1$ assignment.setOperator(Assignment.Operator.ASSIGN); ExpressionStatement statement = this.ast.newExpressionStatement(assignment); - assertTrue("Both AST trees should be identical", statement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$ + assertTrue("Both AST trees should be identical", statement.subtreeMatch(createASTMatcher(), node)); //$NON-NLS-1$ checkSourceRange(node, "i = 1;", source); //$NON-NLS-1$ } @@ -440,7 +525,7 @@ public void test0016() throws JavaModelException { assignment.setRightHandSide(this.ast.newNumberLiteral("2")); //$NON-NLS-1$ assignment.setOperator(Assignment.Operator.PLUS_ASSIGN); ExpressionStatement statement = this.ast.newExpressionStatement(assignment); - assertTrue("Both AST trees should be identical", statement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$ + assertTrue("Both AST trees should be identical", statement.subtreeMatch(createASTMatcher(), node)); //$NON-NLS-1$ checkSourceRange(node, "i += 2;", source); //$NON-NLS-1$ } @@ -458,7 +543,7 @@ public void test0017() throws JavaModelException { assignment.setRightHandSide(this.ast.newNumberLiteral("2")); //$NON-NLS-1$ assignment.setOperator(Assignment.Operator.MINUS_ASSIGN); ExpressionStatement statement = this.ast.newExpressionStatement(assignment); - assertTrue("Both AST trees should be identical", statement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$ + assertTrue("Both AST trees should be identical", statement.subtreeMatch(createASTMatcher(), node)); //$NON-NLS-1$ checkSourceRange(node, "i -= 2;", source); //$NON-NLS-1$ } @@ -476,7 +561,7 @@ public void test0018() throws JavaModelException { assignment.setRightHandSide(this.ast.newNumberLiteral("2")); //$NON-NLS-1$ assignment.setOperator(Assignment.Operator.TIMES_ASSIGN); ExpressionStatement statement = this.ast.newExpressionStatement(assignment); - assertTrue("Both AST trees should be identical", statement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$ + assertTrue("Both AST trees should be identical", statement.subtreeMatch(createASTMatcher(), node)); //$NON-NLS-1$ checkSourceRange(node, "i *= 2;", source); //$NON-NLS-1$ } @@ -494,7 +579,7 @@ public void test0019() throws JavaModelException { assignment.setRightHandSide(this.ast.newNumberLiteral("2")); //$NON-NLS-1$ assignment.setOperator(Assignment.Operator.DIVIDE_ASSIGN); ExpressionStatement statement = this.ast.newExpressionStatement(assignment); - assertTrue("Both AST trees should be identical", statement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$ + assertTrue("Both AST trees should be identical", statement.subtreeMatch(createASTMatcher(), node)); //$NON-NLS-1$ checkSourceRange(node, "i /= 2;", source); //$NON-NLS-1$ } @@ -512,7 +597,7 @@ public void test0020() throws JavaModelException { assignment.setRightHandSide(this.ast.newNumberLiteral("2")); //$NON-NLS-1$ assignment.setOperator(Assignment.Operator.BIT_AND_ASSIGN); ExpressionStatement statement = this.ast.newExpressionStatement(assignment); - assertTrue("Both AST trees should be identical", statement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$ + assertTrue("Both AST trees should be identical", statement.subtreeMatch(createASTMatcher(), node)); //$NON-NLS-1$ checkSourceRange(node, "i &= 2;", source); //$NON-NLS-1$ } @@ -530,7 +615,7 @@ public void test0021() throws JavaModelException { assignment.setRightHandSide(this.ast.newNumberLiteral("2")); //$NON-NLS-1$ assignment.setOperator(Assignment.Operator.BIT_OR_ASSIGN); ExpressionStatement statement = this.ast.newExpressionStatement(assignment); - assertTrue("Both AST trees should be identical", statement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$ + assertTrue("Both AST trees should be identical", statement.subtreeMatch(createASTMatcher(), node)); //$NON-NLS-1$ checkSourceRange(node, "i |= 2;", source); //$NON-NLS-1$ } @@ -548,7 +633,7 @@ public void test0022() throws JavaModelException { assignment.setRightHandSide(this.ast.newNumberLiteral("2")); //$NON-NLS-1$ assignment.setOperator(Assignment.Operator.BIT_XOR_ASSIGN); ExpressionStatement statement = this.ast.newExpressionStatement(assignment); - assertTrue("Both AST trees should be identical", statement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$ + assertTrue("Both AST trees should be identical", statement.subtreeMatch(createASTMatcher(), node)); //$NON-NLS-1$ checkSourceRange(node, "i ^= 2;", source); //$NON-NLS-1$ } @@ -566,7 +651,7 @@ public void test0023() throws JavaModelException { assignment.setRightHandSide(this.ast.newNumberLiteral("2")); //$NON-NLS-1$ assignment.setOperator(Assignment.Operator.REMAINDER_ASSIGN); ExpressionStatement statement = this.ast.newExpressionStatement(assignment); - assertTrue("Both AST trees should be identical", statement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$ + assertTrue("Both AST trees should be identical", statement.subtreeMatch(createASTMatcher(), node)); //$NON-NLS-1$ checkSourceRange(node, "i %= 2;", source); //$NON-NLS-1$ } @@ -584,7 +669,7 @@ public void test0024() throws JavaModelException { assignment.setRightHandSide(this.ast.newNumberLiteral("2")); //$NON-NLS-1$ assignment.setOperator(Assignment.Operator.LEFT_SHIFT_ASSIGN); ExpressionStatement statement = this.ast.newExpressionStatement(assignment); - assertTrue("Both AST trees should be identical", statement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$ + assertTrue("Both AST trees should be identical", statement.subtreeMatch(createASTMatcher(), node)); //$NON-NLS-1$ checkSourceRange(node, "i <<= 2;", source); //$NON-NLS-1$ } @@ -602,7 +687,7 @@ public void test0025() throws JavaModelException { assignment.setRightHandSide(this.ast.newNumberLiteral("2")); //$NON-NLS-1$ assignment.setOperator(Assignment.Operator.RIGHT_SHIFT_SIGNED_ASSIGN); ExpressionStatement statement = this.ast.newExpressionStatement(assignment); - assertTrue("Both AST trees should be identical", statement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$ + assertTrue("Both AST trees should be identical", statement.subtreeMatch(createASTMatcher(), node)); //$NON-NLS-1$ checkSourceRange(node, "i >>= 2;", source); //$NON-NLS-1$ } @@ -620,7 +705,7 @@ public void test0026() throws JavaModelException { assignment.setRightHandSide(this.ast.newNumberLiteral("2")); //$NON-NLS-1$ assignment.setOperator(Assignment.Operator.RIGHT_SHIFT_UNSIGNED_ASSIGN); ExpressionStatement statement = this.ast.newExpressionStatement(assignment); - assertTrue("Both AST trees should be identical", statement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$ + assertTrue("Both AST trees should be identical", statement.subtreeMatch(createASTMatcher(), node)); //$NON-NLS-1$ checkSourceRange(node, "i >>>= 2;", source); //$NON-NLS-1$ } @@ -637,7 +722,7 @@ public void test0027() throws JavaModelException { prefixExpression.setOperand(this.ast.newSimpleName("i"));//$NON-NLS-1$ prefixExpression.setOperator(PrefixExpression.Operator.DECREMENT);//$NON-NLS-1$ ExpressionStatement statement = this.ast.newExpressionStatement(prefixExpression); - assertTrue("Both AST trees should be identical", statement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$ + assertTrue("Both AST trees should be identical", statement.subtreeMatch(createASTMatcher(), node)); //$NON-NLS-1$ checkSourceRange(node, "--i;", source); //$NON-NLS-1$ } @@ -654,7 +739,7 @@ public void test0028() throws JavaModelException { prefixExpression.setOperand(this.ast.newSimpleName("i"));//$NON-NLS-1$ prefixExpression.setOperator(PrefixExpression.Operator.INCREMENT);//$NON-NLS-1$ ExpressionStatement statement = this.ast.newExpressionStatement(prefixExpression); - assertTrue("Both AST trees should be identical", statement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$ + assertTrue("Both AST trees should be identical", statement.subtreeMatch(createASTMatcher(), node)); //$NON-NLS-1$ checkSourceRange(node, "++i;", source); //$NON-NLS-1$ } @@ -671,7 +756,7 @@ public void test0029() throws JavaModelException { postfixExpression.setOperand(this.ast.newSimpleName("i"));//$NON-NLS-1$ postfixExpression.setOperator(PostfixExpression.Operator.DECREMENT);//$NON-NLS-1$ ExpressionStatement statement = this.ast.newExpressionStatement(postfixExpression); - assertTrue("Both AST trees should be identical", statement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$ + assertTrue("Both AST trees should be identical", statement.subtreeMatch(createASTMatcher(), node)); //$NON-NLS-1$ checkSourceRange(node, "i--;", source); //$NON-NLS-1$ } @@ -688,7 +773,7 @@ public void test0030() throws JavaModelException { postfixExpression.setOperand(this.ast.newSimpleName("i"));//$NON-NLS-1$ postfixExpression.setOperator(PostfixExpression.Operator.INCREMENT);//$NON-NLS-1$ ExpressionStatement statement = this.ast.newExpressionStatement(postfixExpression); - assertTrue("Both AST trees should be identical", statement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$ + assertTrue("Both AST trees should be identical", statement.subtreeMatch(createASTMatcher(), node)); //$NON-NLS-1$ checkSourceRange(node, "i++;", source); //$NON-NLS-1$ } @@ -711,7 +796,7 @@ public void test0031() throws JavaModelException { VariableDeclarationStatement statement = this.ast.newVariableDeclarationStatement(variableDeclarationFragment); statement.setModifiers(Modifier.NONE); statement.setType(this.ast.newSimpleType(this.ast.newSimpleName("String")));//$NON-NLS-1$ - assertTrue("Both AST trees should be identical", statement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$ + assertTrue("Both AST trees should be identical", statement.subtreeMatch(createASTMatcher(), node)); //$NON-NLS-1$ checkSourceRange(node, "String s = (String) o;", source); //$NON-NLS-1$ } @@ -734,7 +819,7 @@ public void test0032() throws JavaModelException { VariableDeclarationStatement statement = this.ast.newVariableDeclarationStatement(variableDeclarationFragment); statement.setModifiers(Modifier.NONE); statement.setType(this.ast.newPrimitiveType(PrimitiveType.INT));//$NON-NLS-1$ - assertTrue("Both AST trees should be identical", statement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$ + assertTrue("Both AST trees should be identical", statement.subtreeMatch(createASTMatcher(), node)); //$NON-NLS-1$ checkSourceRange(node, "int i = (int) d;", source); //$NON-NLS-1$ } @@ -759,7 +844,7 @@ public void test0033() throws JavaModelException { statement.setModifiers(Modifier.NONE); statement.setType(this.ast.newPrimitiveType(PrimitiveType.FLOAT));//$NON-NLS-1$ - assertTrue("Both AST trees should be identical", statement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$ + assertTrue("Both AST trees should be identical", statement.subtreeMatch(createASTMatcher(), node)); //$NON-NLS-1$ checkSourceRange(node, "float f = (float) d;", source); //$NON-NLS-1$ } @@ -784,7 +869,7 @@ public void test0034() throws JavaModelException { statement.setModifiers(Modifier.NONE); statement.setType(this.ast.newPrimitiveType(PrimitiveType.BYTE));//$NON-NLS-1$ - assertTrue("Both AST trees should be identical", statement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$ + assertTrue("Both AST trees should be identical", statement.subtreeMatch(createASTMatcher(), node)); //$NON-NLS-1$ checkSourceRange(node, "byte b = (byte) d;", source); //$NON-NLS-1$ } @@ -809,7 +894,7 @@ public void test0035() throws JavaModelException { statement.setModifiers(Modifier.NONE); statement.setType(this.ast.newPrimitiveType(PrimitiveType.SHORT));//$NON-NLS-1$ - assertTrue("Both AST trees should be identical", statement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$ + assertTrue("Both AST trees should be identical", statement.subtreeMatch(createASTMatcher(), node)); //$NON-NLS-1$ checkSourceRange(node, "short s = (short) d;", source); //$NON-NLS-1$ } @@ -834,7 +919,7 @@ public void test0036() throws JavaModelException { statement.setModifiers(Modifier.NONE); statement.setType(this.ast.newPrimitiveType(PrimitiveType.LONG));//$NON-NLS-1$ - assertTrue("Both AST trees should be identical", statement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$ + assertTrue("Both AST trees should be identical", statement.subtreeMatch(createASTMatcher(), node)); //$NON-NLS-1$ checkSourceRange(node, "long l = (long) d;", source); //$NON-NLS-1$ } @@ -859,7 +944,7 @@ public void test0037() throws JavaModelException { statement.setModifiers(Modifier.NONE); statement.setType(this.ast.newPrimitiveType(PrimitiveType.CHAR));//$NON-NLS-1$ - assertTrue("Both AST trees should be identical", statement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$ + assertTrue("Both AST trees should be identical", statement.subtreeMatch(createASTMatcher(), node)); //$NON-NLS-1$ checkSourceRange(node, "char c = (char) i;", source); //$NON-NLS-1$ } @@ -883,7 +968,7 @@ public void test0038() throws JavaModelException { statement.setModifiers(Modifier.NONE); statement.setType(this.ast.newSimpleType(this.ast.newSimpleName("Class")));//$NON-NLS-1$ - assertTrue("Both AST trees should be identical", statement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$ + assertTrue("Both AST trees should be identical", statement.subtreeMatch(createASTMatcher(), node)); //$NON-NLS-1$ checkSourceRange(((VariableDeclarationFragment)((VariableDeclarationStatement)node).fragments().get(0)).getInitializer(), "int.class", source); //$NON-NLS-1$ } @@ -907,7 +992,7 @@ public void test0039() throws JavaModelException { statement.setModifiers(Modifier.NONE); statement.setType(this.ast.newSimpleType(this.ast.newSimpleName("Class")));//$NON-NLS-1$ - assertTrue("Both AST trees should be identical", statement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$ + assertTrue("Both AST trees should be identical", statement.subtreeMatch(createASTMatcher(), node)); //$NON-NLS-1$ checkSourceRange(((VariableDeclarationFragment)((VariableDeclarationStatement)node).fragments().get(0)).getInitializer(), "void.class", source); //$NON-NLS-1$ } @@ -931,7 +1016,7 @@ public void test0040() throws JavaModelException { statement.setModifiers(Modifier.NONE); statement.setType(this.ast.newSimpleType(this.ast.newSimpleName("Class")));//$NON-NLS-1$ - assertTrue("Both AST trees should be identical", statement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$ + assertTrue("Both AST trees should be identical", statement.subtreeMatch(createASTMatcher(), node)); //$NON-NLS-1$ checkSourceRange(((VariableDeclarationFragment)((VariableDeclarationStatement)node).fragments().get(0)).getInitializer(), "double.class", source); //$NON-NLS-1$ } @@ -955,7 +1040,7 @@ public void test0041() throws JavaModelException { statement.setModifiers(Modifier.NONE); statement.setType(this.ast.newSimpleType(this.ast.newSimpleName("Class")));//$NON-NLS-1$ - assertTrue("Both AST trees should be identical", statement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$ + assertTrue("Both AST trees should be identical", statement.subtreeMatch(createASTMatcher(), node)); //$NON-NLS-1$ checkSourceRange(((VariableDeclarationFragment)((VariableDeclarationStatement)node).fragments().get(0)).getInitializer(), "long.class", source); //$NON-NLS-1$ } @@ -969,7 +1054,7 @@ public void test0042() throws JavaModelException { ASTNode expression = getASTNodeToCompare((CompilationUnit) result); assertNotNull("Expression should not be null", expression); //$NON-NLS-1$ BooleanLiteral literal = this.ast.newBooleanLiteral(false); - assertTrue("Both AST trees should be identical", literal.subtreeMatch(new ASTMatcher(), expression)); //$NON-NLS-1$ + assertTrue("Both AST trees should be identical", literal.subtreeMatch(createASTMatcher(), expression)); //$NON-NLS-1$ checkSourceRange(expression, "false", source); //$NON-NLS-1$ } @@ -983,7 +1068,7 @@ public void test0043() throws JavaModelException { ASTNode expression = getASTNodeToCompare((CompilationUnit) result); assertNotNull("Expression should not be null", expression); //$NON-NLS-1$ BooleanLiteral literal = this.ast.newBooleanLiteral(true); - assertTrue("Both AST trees should be identical", literal.subtreeMatch(new ASTMatcher(), expression)); //$NON-NLS-1$ + assertTrue("Both AST trees should be identical", literal.subtreeMatch(createASTMatcher(), expression)); //$NON-NLS-1$ checkSourceRange(expression, "true", source); //$NON-NLS-1$ } @@ -997,7 +1082,7 @@ public void test0044() throws JavaModelException { ASTNode expression = getASTNodeToCompare((CompilationUnit) result); assertNotNull("Expression should not be null", expression); //$NON-NLS-1$ NullLiteral literal = this.ast.newNullLiteral(); - assertTrue("Both AST trees should be identical", literal.subtreeMatch(new ASTMatcher(), expression)); //$NON-NLS-1$ + assertTrue("Both AST trees should be identical", literal.subtreeMatch(createASTMatcher(), expression)); //$NON-NLS-1$ checkSourceRange(expression, "null", source); //$NON-NLS-1$ } @@ -1012,7 +1097,7 @@ public void test0045() throws JavaModelException { assertNotNull("Expression should not be null", expression); //$NON-NLS-1$ CharacterLiteral literal = this.ast.newCharacterLiteral(); literal.setEscapedValue("'c'"); //$NON-NLS-1$ - assertTrue("Both AST trees should be identical", literal.subtreeMatch(new ASTMatcher(), expression)); //$NON-NLS-1$ + assertTrue("Both AST trees should be identical", literal.subtreeMatch(createASTMatcher(), expression)); //$NON-NLS-1$ checkSourceRange(expression, "'c'", source); //$NON-NLS-1$ } @@ -1026,7 +1111,7 @@ public void test0046() throws JavaModelException { ASTNode expression = getASTNodeToCompare((CompilationUnit) result); assertNotNull("Expression should not be null", expression); //$NON-NLS-1$ NumberLiteral literal = this.ast.newNumberLiteral("1.00001");//$NON-NLS-1$ - assertTrue("Both AST trees should be identical", literal.subtreeMatch(new ASTMatcher(), expression)); //$NON-NLS-1$ + assertTrue("Both AST trees should be identical", literal.subtreeMatch(createASTMatcher(), expression)); //$NON-NLS-1$ checkSourceRange(expression, "1.00001", source); //$NON-NLS-1$ } @@ -1040,7 +1125,7 @@ public void test0047() throws JavaModelException { ASTNode expression = getASTNodeToCompare((CompilationUnit) result); assertNotNull("Expression should not be null", expression); //$NON-NLS-1$ NumberLiteral literal = this.ast.newNumberLiteral("1.00001f");//$NON-NLS-1$ - assertTrue("Both AST trees should be identical", literal.subtreeMatch(new ASTMatcher(), expression)); //$NON-NLS-1$ + assertTrue("Both AST trees should be identical", literal.subtreeMatch(createASTMatcher(), expression)); //$NON-NLS-1$ checkSourceRange(expression, "1.00001f", source); //$NON-NLS-1$ } @@ -1054,7 +1139,7 @@ public void test0048() throws JavaModelException { ASTNode expression = getASTNodeToCompare((CompilationUnit) result); assertNotNull("Expression should not be null", expression); //$NON-NLS-1$ NumberLiteral literal = this.ast.newNumberLiteral("30000");//$NON-NLS-1$ - assertTrue("Both AST trees should be identical", literal.subtreeMatch(new ASTMatcher(), expression)); //$NON-NLS-1$ + assertTrue("Both AST trees should be identical", literal.subtreeMatch(createASTMatcher(), expression)); //$NON-NLS-1$ checkSourceRange(expression, "30000", source); //$NON-NLS-1$ } @@ -1068,7 +1153,7 @@ public void test0049() throws JavaModelException { ASTNode expression = getASTNodeToCompare((CompilationUnit) result); assertNotNull("Expression should not be null", expression); //$NON-NLS-1$ NumberLiteral literal = this.ast.newNumberLiteral("-2147483648");//$NON-NLS-1$ - assertTrue("Both AST trees should be identical", literal.subtreeMatch(new ASTMatcher(), expression)); //$NON-NLS-1$ + assertTrue("Both AST trees should be identical", literal.subtreeMatch(createASTMatcher(), expression)); //$NON-NLS-1$ checkSourceRange(expression, "-2147483648", source); //$NON-NLS-1$ } @@ -1082,7 +1167,7 @@ public void test0050() throws JavaModelException { ASTNode expression = getASTNodeToCompare((CompilationUnit) result); assertNotNull("Expression should not be null", expression); //$NON-NLS-1$ NumberLiteral literal = this.ast.newNumberLiteral("2147483648L");//$NON-NLS-1$ - assertTrue("Both AST trees should be identical", literal.subtreeMatch(new ASTMatcher(), expression)); //$NON-NLS-1$ + assertTrue("Both AST trees should be identical", literal.subtreeMatch(createASTMatcher(), expression)); //$NON-NLS-1$ checkSourceRange(expression, "2147483648L", source); //$NON-NLS-1$ } @@ -1099,7 +1184,7 @@ public void test0051() throws JavaModelException { PrefixExpression prefixExpression = this.ast.newPrefixExpression(); prefixExpression.setOperand(literal); prefixExpression.setOperator(PrefixExpression.Operator.MINUS); - assertTrue("Both AST trees should be identical", prefixExpression.subtreeMatch(new ASTMatcher(), expression)); //$NON-NLS-1$ + assertTrue("Both AST trees should be identical", prefixExpression.subtreeMatch(createASTMatcher(), expression)); //$NON-NLS-1$ checkSourceRange(expression, "-2147483648L", source); //$NON-NLS-1$ } @@ -1113,7 +1198,7 @@ public void test0052() throws JavaModelException { ASTNode expression = getASTNodeToCompare((CompilationUnit) result); assertNotNull("Expression should not be null", expression); //$NON-NLS-1$ NumberLiteral literal = this.ast.newNumberLiteral("-9223372036854775808L");//$NON-NLS-1$ - assertTrue("Both AST trees should be identical", literal.subtreeMatch(new ASTMatcher(), expression)); //$NON-NLS-1$ + assertTrue("Both AST trees should be identical", literal.subtreeMatch(createASTMatcher(), expression)); //$NON-NLS-1$ checkSourceRange(expression, "-9223372036854775808L", source); //$NON-NLS-1$ } @@ -1138,7 +1223,7 @@ public void test0053() throws JavaModelException { literal.setLiteralValue(" World");//$NON-NLS-1$ infixExpression.setRightOperand(literal);//$NON-NLS-1$ - assertTrue("Both AST trees should be identical", infixExpression.subtreeMatch(new ASTMatcher(), expression)); //$NON-NLS-1$ + assertTrue("Both AST trees should be identical", infixExpression.subtreeMatch(createASTMatcher(), expression)); //$NON-NLS-1$ checkSourceRange(expression, "\"Hello\" + \" World\"", source); //$NON-NLS-1$ } @@ -1164,7 +1249,7 @@ public void test0054() throws JavaModelException { statement.setModifiers(Modifier.NONE); statement.setType(this.ast.newPrimitiveType(PrimitiveType.BOOLEAN)); - assertTrue("Both AST trees should be identical", statement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$ + assertTrue("Both AST trees should be identical", statement.subtreeMatch(createASTMatcher(), node)); //$NON-NLS-1$ checkSourceRange(node, "boolean b3 = b && b2;", source); //$NON-NLS-1$ } @@ -1190,7 +1275,7 @@ public void test0055() throws JavaModelException { statement.setModifiers(Modifier.NONE); statement.setType(this.ast.newPrimitiveType(PrimitiveType.BOOLEAN)); - assertTrue("Both AST trees should be identical", statement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$ + assertTrue("Both AST trees should be identical", statement.subtreeMatch(createASTMatcher(), node)); //$NON-NLS-1$ checkSourceRange(node, "boolean b3 = b || b2;", source); //$NON-NLS-1$ } @@ -1216,7 +1301,7 @@ public void test0056() throws JavaModelException { statement.setModifiers(Modifier.NONE); statement.setType(this.ast.newPrimitiveType(PrimitiveType.BOOLEAN)); - assertTrue("Both AST trees should be identical", statement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$ + assertTrue("Both AST trees should be identical", statement.subtreeMatch(createASTMatcher(), node)); //$NON-NLS-1$ checkSourceRange(node, "boolean b3 = b == b2;", source); //$NON-NLS-1$ } @@ -1242,7 +1327,7 @@ public void test0057() throws JavaModelException { statement.setModifiers(Modifier.NONE); statement.setType(this.ast.newPrimitiveType(PrimitiveType.INT)); - assertTrue("Both AST trees should be identical", statement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$ + assertTrue("Both AST trees should be identical", statement.subtreeMatch(createASTMatcher(), node)); //$NON-NLS-1$ checkSourceRange(node, "int n = i + j;", source); //$NON-NLS-1$ } @@ -1268,7 +1353,7 @@ public void test0058() throws JavaModelException { statement.setModifiers(Modifier.NONE); statement.setType(this.ast.newPrimitiveType(PrimitiveType.INT)); - assertTrue("Both AST trees should be identical", statement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$ + assertTrue("Both AST trees should be identical", statement.subtreeMatch(createASTMatcher(), node)); //$NON-NLS-1$ checkSourceRange(node, "int n = i - j;", source); //$NON-NLS-1$ } @@ -1294,7 +1379,7 @@ public void test0059() throws JavaModelException { statement.setModifiers(Modifier.NONE); statement.setType(this.ast.newPrimitiveType(PrimitiveType.INT)); - assertTrue("Both AST trees should be identical", statement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$ + assertTrue("Both AST trees should be identical", statement.subtreeMatch(createASTMatcher(), node)); //$NON-NLS-1$ checkSourceRange(node, "int n = i * j;", source); //$NON-NLS-1$ } @@ -1320,7 +1405,7 @@ public void test0060() throws JavaModelException { statement.setModifiers(Modifier.NONE); statement.setType(this.ast.newPrimitiveType(PrimitiveType.INT)); - assertTrue("Both AST trees should be identical", statement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$ + assertTrue("Both AST trees should be identical", statement.subtreeMatch(createASTMatcher(), node)); //$NON-NLS-1$ checkSourceRange(node, "int n = i / j;", source); //$NON-NLS-1$ } @@ -1346,7 +1431,7 @@ public void test0061() throws JavaModelException { statement.setModifiers(Modifier.NONE); statement.setType(this.ast.newPrimitiveType(PrimitiveType.INT)); - assertTrue("Both AST trees should be identical", statement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$ + assertTrue("Both AST trees should be identical", statement.subtreeMatch(createASTMatcher(), node)); //$NON-NLS-1$ checkSourceRange(node, "int n = i % j;", source); //$NON-NLS-1$ } @@ -1372,7 +1457,7 @@ public void test0062() throws JavaModelException { statement.setModifiers(Modifier.NONE); statement.setType(this.ast.newPrimitiveType(PrimitiveType.INT)); - assertTrue("Both AST trees should be identical", statement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$ + assertTrue("Both AST trees should be identical", statement.subtreeMatch(createASTMatcher(), node)); //$NON-NLS-1$ checkSourceRange(node, "int n = i ^ j;", source); //$NON-NLS-1$ } @@ -1398,7 +1483,7 @@ public void test0063() throws JavaModelException { statement.setModifiers(Modifier.NONE); statement.setType(this.ast.newPrimitiveType(PrimitiveType.INT)); - assertTrue("Both AST trees should be identical", statement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$ + assertTrue("Both AST trees should be identical", statement.subtreeMatch(createASTMatcher(), node)); //$NON-NLS-1$ checkSourceRange(node, "int n = i & j;", source); //$NON-NLS-1$ } @@ -1424,7 +1509,7 @@ public void test0064() throws JavaModelException { statement.setModifiers(Modifier.NONE); statement.setType(this.ast.newPrimitiveType(PrimitiveType.INT)); - assertTrue("Both AST trees should be identical", statement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$ + assertTrue("Both AST trees should be identical", statement.subtreeMatch(createASTMatcher(), node)); //$NON-NLS-1$ checkSourceRange(node, "int n = i | j;", source); //$NON-NLS-1$ } @@ -1450,7 +1535,7 @@ public void test0065() throws JavaModelException { statement.setModifiers(Modifier.NONE); statement.setType(this.ast.newPrimitiveType(PrimitiveType.BOOLEAN)); - assertTrue("Both AST trees should be identical", statement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$ + assertTrue("Both AST trees should be identical", statement.subtreeMatch(createASTMatcher(), node)); //$NON-NLS-1$ checkSourceRange(node, "boolean b2 = b < b1;", source); //$NON-NLS-1$ } @@ -1476,7 +1561,7 @@ public void test0066() throws JavaModelException { statement.setModifiers(Modifier.NONE); statement.setType(this.ast.newPrimitiveType(PrimitiveType.BOOLEAN)); - assertTrue("Both AST trees should be identical", statement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$ + assertTrue("Both AST trees should be identical", statement.subtreeMatch(createASTMatcher(), node)); //$NON-NLS-1$ checkSourceRange(node, "boolean b2 = b <= b1;", source); //$NON-NLS-1$ } @@ -1502,7 +1587,7 @@ public void test0067() throws JavaModelException { statement.setModifiers(Modifier.NONE); statement.setType(this.ast.newPrimitiveType(PrimitiveType.BOOLEAN)); - assertTrue("Both AST trees should be identical", statement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$ + assertTrue("Both AST trees should be identical", statement.subtreeMatch(createASTMatcher(), node)); //$NON-NLS-1$ checkSourceRange(node, "boolean b2 = b > b1;", source); //$NON-NLS-1$ } @@ -1528,7 +1613,7 @@ public void test0068() throws JavaModelException { statement.setModifiers(Modifier.NONE); statement.setType(this.ast.newPrimitiveType(PrimitiveType.BOOLEAN)); - assertTrue("Both AST trees should be identical", statement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$ + assertTrue("Both AST trees should be identical", statement.subtreeMatch(createASTMatcher(), node)); //$NON-NLS-1$ checkSourceRange(node, "boolean b2 = b >= b1;", source); //$NON-NLS-1$ } @@ -1554,7 +1639,7 @@ public void test0069() throws JavaModelException { statement.setModifiers(Modifier.NONE); statement.setType(this.ast.newPrimitiveType(PrimitiveType.BOOLEAN)); - assertTrue("Both AST trees should be identical", statement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$ + assertTrue("Both AST trees should be identical", statement.subtreeMatch(createASTMatcher(), node)); //$NON-NLS-1$ checkSourceRange(node, "boolean b2 = b != b1;", source); //$NON-NLS-1$ } @@ -1579,7 +1664,7 @@ public void test0070() throws JavaModelException { statement.setModifiers(Modifier.NONE); statement.setType(this.ast.newPrimitiveType(PrimitiveType.BOOLEAN)); - assertTrue("Both AST trees should be identical", statement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$ + assertTrue("Both AST trees should be identical", statement.subtreeMatch(createASTMatcher(), node)); //$NON-NLS-1$ checkSourceRange(node, "boolean b = o instanceof Integer;", source); //$NON-NLS-1$ } @@ -1611,7 +1696,7 @@ public void test0071() throws JavaModelException { statement.setModifiers(Modifier.NONE); statement.setType(this.ast.newPrimitiveType(PrimitiveType.BOOLEAN)); - assertTrue("Both AST trees should be identical", statement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$ + assertTrue("Both AST trees should be identical", statement.subtreeMatch(createASTMatcher(), node)); //$NON-NLS-1$ checkSourceRange(node, "boolean b = o instanceof java.lang.Integer;", source); //$NON-NLS-1$ } @@ -1635,7 +1720,7 @@ public void test0072() throws JavaModelException { statement.setModifiers(Modifier.NONE); statement.setType(this.ast.newPrimitiveType(PrimitiveType.BOOLEAN)); - assertTrue("Both AST trees should be identical", statement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$ + assertTrue("Both AST trees should be identical", statement.subtreeMatch(createASTMatcher(), node)); //$NON-NLS-1$ checkSourceRange(node, "boolean b1 = !b;", source); //$NON-NLS-1$ } @@ -1659,7 +1744,7 @@ public void test0073() throws JavaModelException { statement.setModifiers(Modifier.NONE); statement.setType(this.ast.newPrimitiveType(PrimitiveType.INT)); - assertTrue("Both AST trees should be identical", statement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$ + assertTrue("Both AST trees should be identical", statement.subtreeMatch(createASTMatcher(), node)); //$NON-NLS-1$ checkSourceRange(node, "int n = ~i;", source); //$NON-NLS-1$ } @@ -1684,10 +1769,29 @@ public void test0074() throws JavaModelException { statement.setModifiers(Modifier.NONE); statement.setType(this.ast.newPrimitiveType(PrimitiveType.INT)); - assertTrue("Both AST trees should be identical", statement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$ + assertTrue("Both AST trees should be identical", statement.subtreeMatch(createASTMatcher(), node)); //$NON-NLS-1$ checkSourceRange(node, "int i = +2;", source); //$NON-NLS-1$ } + public void test0049_75() throws JavaModelException { + int z = 5; + boolean firstSuccess = false; + try { + test0049(); + firstSuccess = true; + } catch( Throwable t ) { + t.printStackTrace(); + } + boolean secondSuccess = false; + try { + test0075(); + secondSuccess = true; + } catch( Throwable t ) { + t.printStackTrace(); + } + assertTrue(firstSuccess && secondSuccess); + } + /** * UnaryExpression (-) ==> PrefixExpression * @deprecated using deprecated code @@ -1710,7 +1814,7 @@ public void test0075() throws JavaModelException { statement.setType(this.ast.newPrimitiveType(PrimitiveType.INT)); - assertTrue("Both AST trees should be identical", statement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$ + assertTrue("Both AST trees should be identical", statement.subtreeMatch(createASTMatcher(), node)); //$NON-NLS-1$ checkSourceRange(node, "int i = -2;", source); //$NON-NLS-1$ } @@ -1739,7 +1843,7 @@ public void test0076() throws JavaModelException { VariableDeclarationStatement statement = this.ast.newVariableDeclarationStatement(variableDeclarationFragment); statement.setModifiers(Modifier.NONE); statement.setType(this.ast.newPrimitiveType(PrimitiveType.BOOLEAN)); - assertTrue("Both AST trees should be identical", statement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$ + assertTrue("Both AST trees should be identical", statement.subtreeMatch(createASTMatcher(), node)); //$NON-NLS-1$ checkSourceRange(node, "boolean b = args != null ? true : false;", source); //$NON-NLS-1$ } @@ -1768,7 +1872,7 @@ public void test0077() throws JavaModelException { statement.setModifiers(Modifier.NONE); statement.setType(this.ast.newPrimitiveType(PrimitiveType.INT)); - assertTrue("Both AST trees should be identical", statement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$ + assertTrue("Both AST trees should be identical", statement.subtreeMatch(createASTMatcher(), node)); //$NON-NLS-1$ checkSourceRange(node, "int i = true ? args.length: 0;", source); //$NON-NLS-1$ } @@ -1784,7 +1888,7 @@ public void test0078() throws JavaModelException { SuperMethodInvocation superMethodInvocation = this.ast.newSuperMethodInvocation(); superMethodInvocation.setName(this.ast.newSimpleName("bar")); //$NON-NLS-1$ ExpressionStatement statement = this.ast.newExpressionStatement(superMethodInvocation); - assertTrue("Both AST trees should be identical", statement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$ + assertTrue("Both AST trees should be identical", statement.subtreeMatch(createASTMatcher(), node)); //$NON-NLS-1$ checkSourceRange(node, "super.bar();", source); //$NON-NLS-1$ } @@ -1801,7 +1905,7 @@ public void test0079() throws JavaModelException { superMethodInvocation.setName(this.ast.newSimpleName("bar")); //$NON-NLS-1$ superMethodInvocation.arguments().add(this.ast.newNumberLiteral("4"));//$NON-NLS-1$ ExpressionStatement statement = this.ast.newExpressionStatement(superMethodInvocation); - assertTrue("Both AST trees should be identical", statement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$ + assertTrue("Both AST trees should be identical", statement.subtreeMatch(createASTMatcher(), node)); //$NON-NLS-1$ checkSourceRange(node, "super.bar(4);", source); //$NON-NLS-1$ } @@ -1818,7 +1922,7 @@ public void test0080() throws JavaModelException { methodInvocation.setName(this.ast.newSimpleName("bar")); //$NON-NLS-1$ methodInvocation.arguments().add(this.ast.newNumberLiteral("4"));//$NON-NLS-1$ ExpressionStatement statement = this.ast.newExpressionStatement(methodInvocation); - assertTrue("Both AST trees should be identical", statement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$ + assertTrue("Both AST trees should be identical", statement.subtreeMatch(createASTMatcher(), node)); //$NON-NLS-1$ checkSourceRange(node, "bar(4);", source); //$NON-NLS-1$ } @@ -1836,7 +1940,7 @@ public void test0081() throws JavaModelException { methodInvocation.setExpression(this.ast.newThisExpression()); methodInvocation.arguments().add(this.ast.newNumberLiteral("4"));//$NON-NLS-1$ ExpressionStatement statement = this.ast.newExpressionStatement(methodInvocation); - assertTrue("Both AST trees should be identical", statement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$ + assertTrue("Both AST trees should be identical", statement.subtreeMatch(createASTMatcher(), node)); //$NON-NLS-1$ checkSourceRange(node, "this.bar(4);", source); //$NON-NLS-1$ } @@ -1851,7 +1955,7 @@ public void test0082() throws JavaModelException { assertNotNull("Expression should not be null", node); //$NON-NLS-1$ ForStatement forStatement = this.ast.newForStatement(); forStatement.setBody(this.ast.newEmptyStatement()); - assertTrue("Both AST trees should be identical", forStatement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$ + assertTrue("Both AST trees should be identical", forStatement.subtreeMatch(createASTMatcher(), node)); //$NON-NLS-1$ checkSourceRange(node, "for (;;);", source); //$NON-NLS-1$ } @@ -1883,7 +1987,7 @@ public void test0083() throws JavaModelException { infixExpression.setOperator(InfixExpression.Operator.LESS); infixExpression.setRightOperand(this.ast.newNumberLiteral("10")); //$NON-NLS-1$ forStatement.setExpression(infixExpression); - assertTrue("Both AST trees should be identical", forStatement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$ + assertTrue("Both AST trees should be identical", forStatement.subtreeMatch(createASTMatcher(), node)); //$NON-NLS-1$ checkSourceRange(node, "for (int i = 0; i < 10; i++) {}", source); //$NON-NLS-1$ } @@ -1917,7 +2021,7 @@ public void test0084() throws JavaModelException { infixExpression.setRightOperand(this.ast.newNumberLiteral("10")); //$NON-NLS-1$ forStatement.setExpression(infixExpression); forStatement.setBody(this.ast.newEmptyStatement()); - assertTrue("Both AST trees should be identical", forStatement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$ + assertTrue("Both AST trees should be identical", forStatement.subtreeMatch(createASTMatcher(), node)); //$NON-NLS-1$ checkSourceRange(node, "for (int i = 0; i < 10; i++);", source); //$NON-NLS-1$ } @@ -1946,7 +2050,7 @@ public void test0085() throws JavaModelException { postfixExpression.setOperator(PostfixExpression.Operator.INCREMENT); forStatement.updaters().add(postfixExpression); forStatement.setBody(this.ast.newEmptyStatement()); - assertTrue("Both AST trees should be identical", forStatement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$ + assertTrue("Both AST trees should be identical", forStatement.subtreeMatch(createASTMatcher(), node)); //$NON-NLS-1$ checkSourceRange(node, "for (int i = 0;; i++);", source); //$NON-NLS-1$ } @@ -1970,7 +2074,7 @@ public void test0086() throws JavaModelException { infixExpression.setRightOperand(this.ast.newNumberLiteral("10")); //$NON-NLS-1$ forStatement.setExpression(infixExpression); forStatement.setBody(this.ast.newEmptyStatement()); - assertTrue("Both AST trees should be identical", forStatement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$ + assertTrue("Both AST trees should be identical", forStatement.subtreeMatch(createASTMatcher(), node)); //$NON-NLS-1$ checkSourceRange(node, "for (; i < 10; i++);", source); //$NON-NLS-1$ } @@ -1989,7 +2093,7 @@ public void test0087() throws JavaModelException { postfixExpression.setOperator(PostfixExpression.Operator.INCREMENT); forStatement.updaters().add(postfixExpression); forStatement.setBody(this.ast.newEmptyStatement()); - assertTrue("Both AST trees should be identical", forStatement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$ + assertTrue("Both AST trees should be identical", forStatement.subtreeMatch(createASTMatcher(), node)); //$NON-NLS-1$ checkSourceRange(node, "for (;;i++);", source); //$NON-NLS-1$ } @@ -2011,7 +2115,7 @@ public void test0088() throws JavaModelException { statement.setType(this.ast.newPrimitiveType(PrimitiveType.INT)); statement.setModifiers(Modifier.NONE); - assertTrue("Both AST trees should be identical", statement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$ + assertTrue("Both AST trees should be identical", statement.subtreeMatch(createASTMatcher(), node)); //$NON-NLS-1$ checkSourceRange(node, "int i;", source); //$NON-NLS-1$ } @@ -2041,7 +2145,7 @@ public void test0089() throws JavaModelException { statement.setType(this.ast.newSimpleType(name)); statement.setModifiers(Modifier.NONE); - assertTrue("Both AST trees should be identical", statement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$ + assertTrue("Both AST trees should be identical", statement.subtreeMatch(createASTMatcher(), node)); //$NON-NLS-1$ checkSourceRange(node, "java.lang.String s;", source); //$NON-NLS-1$ } @@ -2066,7 +2170,7 @@ public void test0090() throws JavaModelException { VariableDeclarationStatement statement = this.ast.newVariableDeclarationStatement(variableDeclarationFragment); statement.setType(this.ast.newArrayType(this.ast.newPrimitiveType(PrimitiveType.INT), 1)); statement.setModifiers(Modifier.NONE); - assertTrue("Both AST trees should be identical", statement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$ + assertTrue("Both AST trees should be identical", statement.subtreeMatch(createASTMatcher(), node)); //$NON-NLS-1$ checkSourceRange(node, "int[] tab = {1, 2};", source); //$NON-NLS-1$ } @@ -2085,7 +2189,7 @@ public void test0091() throws JavaModelException { variableDeclaration.setModifiers(Modifier.NONE); variableDeclaration.setType(this.ast.newSimpleType(this.ast.newSimpleName("String")));//$NON-NLS-1$ variableDeclaration.setName(this.ast.newSimpleName("s")); //$NON-NLS-1$ - assertTrue("Both AST trees should be identical", variableDeclaration.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$ + assertTrue("Both AST trees should be identical", variableDeclaration.subtreeMatch(createASTMatcher(), node)); //$NON-NLS-1$ checkSourceRange(node, "String s", source); //$NON-NLS-1$ } @@ -2104,7 +2208,7 @@ public void test0092() throws JavaModelException { variableDeclaration.setModifiers(Modifier.FINAL); variableDeclaration.setType(this.ast.newSimpleType(this.ast.newSimpleName("String")));//$NON-NLS-1$ variableDeclaration.setName(this.ast.newSimpleName("s")); //$NON-NLS-1$ - assertTrue("Both AST trees should be identical", variableDeclaration.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$ + assertTrue("Both AST trees should be identical", variableDeclaration.subtreeMatch(createASTMatcher(), node)); //$NON-NLS-1$ checkSourceRange(node, "final String s", source); //$NON-NLS-1$ assertEquals("Wrong dimension", 0, node.getExtraDimensions()); //$NON-NLS-1$ } @@ -2121,7 +2225,7 @@ public void test0093() throws JavaModelException { BreakStatement statement = (BreakStatement) ((Block) forStatement.getBody()).statements().get(0); assertNotNull("Expression should not be null", statement); //$NON-NLS-1$ BreakStatement breakStatement = this.ast.newBreakStatement(); - assertTrue("Both AST trees should be identical", breakStatement.subtreeMatch(new ASTMatcher(), statement)); //$NON-NLS-1$ + assertTrue("Both AST trees should be identical", breakStatement.subtreeMatch(createASTMatcher(), statement)); //$NON-NLS-1$ checkSourceRange(statement, "break;", source); //$NON-NLS-1$ } @@ -2137,7 +2241,7 @@ public void test0094() throws JavaModelException { ContinueStatement statement = (ContinueStatement) ((Block) forStatement.getBody()).statements().get(0); assertNotNull("Expression should not be null", statement); //$NON-NLS-1$ ContinueStatement continueStatement = this.ast.newContinueStatement(); - assertTrue("Both AST trees should be identical", continueStatement.subtreeMatch(new ASTMatcher(), statement)); //$NON-NLS-1$ + assertTrue("Both AST trees should be identical", continueStatement.subtreeMatch(createASTMatcher(), statement)); //$NON-NLS-1$ checkSourceRange(statement, "continue;", source); //$NON-NLS-1$ } @@ -2154,7 +2258,7 @@ public void test0095() throws JavaModelException { assertNotNull("Expression should not be null", statement); //$NON-NLS-1$ ContinueStatement continueStatement = this.ast.newContinueStatement(); continueStatement.setLabel(this.ast.newSimpleName("label")); //$NON-NLS-1$ - assertTrue("Both AST trees should be identical", continueStatement.subtreeMatch(new ASTMatcher(), statement)); //$NON-NLS-1$ + assertTrue("Both AST trees should be identical", continueStatement.subtreeMatch(createASTMatcher(), statement)); //$NON-NLS-1$ checkSourceRange(statement, "continue label;", source); //$NON-NLS-1$ } @@ -2171,7 +2275,7 @@ public void test0096() throws JavaModelException { assertNotNull("Expression should not be null", statement); //$NON-NLS-1$ BreakStatement breakStatement = this.ast.newBreakStatement(); breakStatement.setLabel(this.ast.newSimpleName("label")); //$NON-NLS-1$ - assertTrue("Both AST trees should be identical", breakStatement.subtreeMatch(new ASTMatcher(), statement)); //$NON-NLS-1$ + assertTrue("Both AST trees should be identical", breakStatement.subtreeMatch(createASTMatcher(), statement)); //$NON-NLS-1$ checkSourceRange(statement, "break label;", source); //$NON-NLS-1$ } @@ -2220,7 +2324,7 @@ public void test0097() throws JavaModelException { methodInvocation.arguments().add(literal); expressionStatement = this.ast.newExpressionStatement(methodInvocation); switchStatement.statements().add(expressionStatement); - assertTrue("Both AST trees should be identical", switchStatement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$ + assertTrue("Both AST trees should be identical", switchStatement.subtreeMatch(createASTMatcher(), node)); //$NON-NLS-1$ String expectedSource = "switch(i) {\n" +//$NON-NLS-1$ " case 1: \n" +//$NON-NLS-1$ " break;\n" +//$NON-NLS-1$ @@ -2250,7 +2354,7 @@ public void test0098() throws JavaModelException { ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 0); assertNotNull("Expression should not be null", node); //$NON-NLS-1$ EmptyStatement emptyStatement = this.ast.newEmptyStatement(); - assertTrue("Both AST trees should be identical", emptyStatement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$ + assertTrue("Both AST trees should be identical", emptyStatement.subtreeMatch(createASTMatcher(), node)); //$NON-NLS-1$ checkSourceRange(node, ";", source); //$NON-NLS-1$ } @@ -2268,7 +2372,7 @@ public void test0099() throws JavaModelException { block.statements().add(this.ast.newEmptyStatement()); doStatement.setBody(block); doStatement.setExpression(this.ast.newBooleanLiteral(true)); - assertTrue("Both AST trees should be identical", doStatement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$ + assertTrue("Both AST trees should be identical", doStatement.subtreeMatch(createASTMatcher(), node)); //$NON-NLS-1$ String expectedSource = "do {;\n" +//$NON-NLS-1$ " } while(true);";//$NON-NLS-1$ checkSourceRange(node, expectedSource, source); @@ -2286,7 +2390,7 @@ public void test0100() throws JavaModelException { WhileStatement whileStatement = this.ast.newWhileStatement(); whileStatement.setExpression(this.ast.newBooleanLiteral(true)); whileStatement.setBody(this.ast.newEmptyStatement()); - assertTrue("Both AST trees should be identical", whileStatement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$ + assertTrue("Both AST trees should be identical", whileStatement.subtreeMatch(createASTMatcher(), node)); //$NON-NLS-1$ checkSourceRange(node, "while(true);", source);//$NON-NLS-1$ } @@ -2302,7 +2406,7 @@ public void test0101() throws JavaModelException { WhileStatement whileStatement = this.ast.newWhileStatement(); whileStatement.setExpression(this.ast.newBooleanLiteral(true)); whileStatement.setBody(this.ast.newBlock()); - assertTrue("Both AST trees should be identical", whileStatement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$ + assertTrue("Both AST trees should be identical", whileStatement.subtreeMatch(createASTMatcher(), node)); //$NON-NLS-1$ checkSourceRange(node, "while(true) {}", source);//$NON-NLS-1$ } @@ -2326,7 +2430,7 @@ public void test0102() throws JavaModelException { literal = this.ast.newStringLiteral();//$NON-NLS-1$ literal.setLiteralValue("!"); //$NON-NLS-1$ infixExpression.extendedOperands().add(literal); - assertTrue("Both AST trees should be identical", infixExpression.subtreeMatch(new ASTMatcher(), expression)); //$NON-NLS-1$ + assertTrue("Both AST trees should be identical", infixExpression.subtreeMatch(createASTMatcher(), expression)); //$NON-NLS-1$ checkSourceRange(expression, "\"Hello\" + \" World\" + \"!\"", source);//$NON-NLS-1$ } @@ -2353,7 +2457,7 @@ public void test0103() throws JavaModelException { literal = this.ast.newStringLiteral();//$NON-NLS-1$ literal.setLiteralValue("!"); //$NON-NLS-1$ infixExpression.extendedOperands().add(literal); - assertTrue("Both AST trees should be identical", infixExpression.subtreeMatch(new ASTMatcher(), expression)); //$NON-NLS-1$ + assertTrue("Both AST trees should be identical", infixExpression.subtreeMatch(createASTMatcher(), expression)); //$NON-NLS-1$ checkSourceRange(expression, "\"Hello\" + \" World\" + \"!\" + \"!\"", source);//$NON-NLS-1$ } @@ -2380,7 +2484,7 @@ public void test0104() throws JavaModelException { NumberLiteral numberLiteral = this.ast.newNumberLiteral();//$NON-NLS-1$ numberLiteral.setToken("4"); //$NON-NLS-1$ infixExpression.extendedOperands().add(numberLiteral); - assertTrue("Both AST trees should be identical", infixExpression.subtreeMatch(new ASTMatcher(), expression)); //$NON-NLS-1$ + assertTrue("Both AST trees should be identical", infixExpression.subtreeMatch(createASTMatcher(), expression)); //$NON-NLS-1$ checkSourceRange(expression, "\"Hello\" + \" World\" + \"!\" + 4", source);//$NON-NLS-1$ } @@ -2407,7 +2511,7 @@ public void test0105() throws JavaModelException { literal = this.ast.newNumberLiteral();//$NON-NLS-1$ literal.setToken("4"); //$NON-NLS-1$ infixExpression.extendedOperands().add(literal); - assertTrue("Both AST trees should be identical", infixExpression.subtreeMatch(new ASTMatcher(), expression)); //$NON-NLS-1$ + assertTrue("Both AST trees should be identical", infixExpression.subtreeMatch(createASTMatcher(), expression)); //$NON-NLS-1$ checkSourceRange(expression, "4 + 5 + 6 + 4", source);//$NON-NLS-1$ } @@ -2443,7 +2547,7 @@ public void test0106() throws JavaModelException { literal.setToken("4"); //$NON-NLS-1$ infixExpression3.setRightOperand(literal); - assertTrue("Both AST trees should be identical", infixExpression3.subtreeMatch(new ASTMatcher(), expression)); //$NON-NLS-1$ + assertTrue("Both AST trees should be identical", infixExpression3.subtreeMatch(createASTMatcher(), expression)); //$NON-NLS-1$ checkSourceRange(expression, "4 - 5 + 6 + 4", source);//$NON-NLS-1$ } @@ -2470,7 +2574,7 @@ public void test0107() throws JavaModelException { literal = this.ast.newNumberLiteral();//$NON-NLS-1$ literal.setToken("4"); //$NON-NLS-1$ infixExpression.extendedOperands().add(literal); - assertTrue("Both AST trees should be identical", infixExpression.subtreeMatch(new ASTMatcher(), expression)); //$NON-NLS-1$ + assertTrue("Both AST trees should be identical", infixExpression.subtreeMatch(createASTMatcher(), expression)); //$NON-NLS-1$ checkSourceRange(expression, "4 - 5 - 6 - 4", source);//$NON-NLS-1$ } @@ -2497,7 +2601,7 @@ public void test0108() throws JavaModelException { literal = this.ast.newNumberLiteral();//$NON-NLS-1$ literal.setToken("4"); //$NON-NLS-1$ infixExpression.extendedOperands().add(literal); - assertTrue("Both AST trees should be identical", infixExpression.subtreeMatch(new ASTMatcher(), expression)); //$NON-NLS-1$ + assertTrue("Both AST trees should be identical", infixExpression.subtreeMatch(createASTMatcher(), expression)); //$NON-NLS-1$ checkSourceRange(expression, "\"4\" + 5 + 6 + 4", source);//$NON-NLS-1$ } @@ -2533,7 +2637,7 @@ public void test0109() throws JavaModelException { literal.setToken("4"); //$NON-NLS-1$ infixExpression3.setRightOperand(literal); - assertTrue("Both AST trees should be identical", infixExpression3.subtreeMatch(new ASTMatcher(), expression)); //$NON-NLS-1$ + assertTrue("Both AST trees should be identical", infixExpression3.subtreeMatch(createASTMatcher(), expression)); //$NON-NLS-1$ checkSourceRange(expression, "\"4\" - 5 + 6 + 4", source);//$NON-NLS-1$ } @@ -2550,7 +2654,7 @@ public void test0110() throws JavaModelException { NumberLiteral literal = this.ast.newNumberLiteral(); literal.setToken("2");//$NON-NLS-1$ returnStatement.setExpression(literal); - assertTrue("Both AST trees should be identical", returnStatement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$ + assertTrue("Both AST trees should be identical", returnStatement.subtreeMatch(createASTMatcher(), node)); //$NON-NLS-1$ checkSourceRange(node, "return 2;", source);//$NON-NLS-1$ } @@ -2567,7 +2671,7 @@ public void test0111() throws JavaModelException { NumberLiteral literal = this.ast.newNumberLiteral(); literal.setToken("2");//$NON-NLS-1$ returnStatement.setExpression(literal); - assertTrue("Both AST trees should be identical", returnStatement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$ + assertTrue("Both AST trees should be identical", returnStatement.subtreeMatch(createASTMatcher(), node)); //$NON-NLS-1$ checkSourceRange(node, "return 2\\u003B", source);//$NON-NLS-1$ } @@ -2583,7 +2687,7 @@ public void test0112() throws JavaModelException { SynchronizedStatement synchronizedStatement = this.ast.newSynchronizedStatement(); synchronizedStatement.setExpression(this.ast.newThisExpression()); synchronizedStatement.setBody(this.ast.newBlock()); - assertTrue("Both AST trees should be identical", synchronizedStatement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$ + assertTrue("Both AST trees should be identical", synchronizedStatement.subtreeMatch(createASTMatcher(), node)); //$NON-NLS-1$ String expectedSource = "synchronized(this) {\n" +//$NON-NLS-1$ " }"; //$NON-NLS-1$ checkSourceRange(node, expectedSource, source); @@ -2610,7 +2714,7 @@ public void test0113() throws JavaModelException { exceptionVariable.setType(this.ast.newSimpleType(this.ast.newSimpleName("Exception")));//$NON-NLS-1$ catchBlock.setException(exceptionVariable); tryStatement.catchClauses().add(catchBlock); - assertTrue("Both AST trees should be identical", tryStatement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$ + assertTrue("Both AST trees should be identical", tryStatement.subtreeMatch(createASTMatcher(), node)); //$NON-NLS-1$ String expectedSource = "try {\n" +//$NON-NLS-1$ " } catch(Exception e) {\n" +//$NON-NLS-1$ " } finally {\n" +//$NON-NLS-1$ @@ -2638,7 +2742,7 @@ public void test0114() throws JavaModelException { exceptionVariable.setType(this.ast.newSimpleType(this.ast.newSimpleName("Exception")));//$NON-NLS-1$ catchBlock.setException(exceptionVariable); tryStatement.catchClauses().add(catchBlock); - assertTrue("Both AST trees should be identical", tryStatement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$ + assertTrue("Both AST trees should be identical", tryStatement.subtreeMatch(createASTMatcher(), node)); //$NON-NLS-1$ String expectedSource = "try {\n" +//$NON-NLS-1$ " } catch(Exception e) {\n" +//$NON-NLS-1$ " }"; //$NON-NLS-1$ @@ -2671,7 +2775,7 @@ public void test0115() throws JavaModelException { exceptionVariable.setType(this.ast.newSimpleType(this.ast.newSimpleName("Exception")));//$NON-NLS-1$ catchBlock.setException(exceptionVariable); tryStatement.catchClauses().add(catchBlock); - assertTrue("Both AST trees should be identical", tryStatement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$ + assertTrue("Both AST trees should be identical", tryStatement.subtreeMatch(createASTMatcher(), node)); //$NON-NLS-1$ String expectedSource = "try {\n" +//$NON-NLS-1$ " return 2;\n" +//$NON-NLS-1$ " } catch(Exception e) {\n" +//$NON-NLS-1$ @@ -2690,7 +2794,7 @@ public void test0116() throws JavaModelException { assertNotNull("Expression should not be null", node); //$NON-NLS-1$ ThrowStatement throwStatement = this.ast.newThrowStatement(); throwStatement.setExpression(this.ast.newSimpleName("e")); //$NON-NLS-1$ - assertTrue("Both AST trees should be identical", throwStatement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$ + assertTrue("Both AST trees should be identical", throwStatement.subtreeMatch(createASTMatcher(), node)); //$NON-NLS-1$ checkSourceRange(node, "throw e \\u003B", source);//$NON-NLS-1$ } @@ -2705,7 +2809,7 @@ public void test0117() throws JavaModelException { assertNotNull("Expression should not be null", node); //$NON-NLS-1$ ThrowStatement throwStatement = this.ast.newThrowStatement(); throwStatement.setExpression(this.ast.newSimpleName("e")); //$NON-NLS-1$ - assertTrue("Both AST trees should be identical", throwStatement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$ + assertTrue("Both AST trees should be identical", throwStatement.subtreeMatch(createASTMatcher(), node)); //$NON-NLS-1$ checkSourceRange(node, "throw e /* comment in the middle of a throw */ \\u003B", source);//$NON-NLS-1$ } @@ -2720,7 +2824,7 @@ public void test0118() throws JavaModelException { assertNotNull("Expression should not be null", node); //$NON-NLS-1$ ThrowStatement throwStatement = this.ast.newThrowStatement(); throwStatement.setExpression(this.ast.newSimpleName("e")); //$NON-NLS-1$ - assertTrue("Both AST trees should be identical", throwStatement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$ + assertTrue("Both AST trees should be identical", throwStatement.subtreeMatch(createASTMatcher(), node)); //$NON-NLS-1$ checkSourceRange(node, "throw e /* comment in the middle of a throw */ \\u003B", source);//$NON-NLS-1$ } @@ -2736,7 +2840,7 @@ public void test0119() throws JavaModelException { IfStatement ifStatement = this.ast.newIfStatement(); ifStatement.setExpression(this.ast.newBooleanLiteral(true)); ifStatement.setThenStatement(this.ast.newEmptyStatement()); - assertTrue("Both AST trees should be identical", ifStatement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$ + assertTrue("Both AST trees should be identical", ifStatement.subtreeMatch(createASTMatcher(), node)); //$NON-NLS-1$ checkSourceRange(node, "if (true)\\u003B", source);//$NON-NLS-1$ } @@ -2753,7 +2857,7 @@ public void test0120() throws JavaModelException { ifStatement.setExpression(this.ast.newBooleanLiteral(true)); ifStatement.setThenStatement(this.ast.newEmptyStatement()); ifStatement.setElseStatement(this.ast.newEmptyStatement()); - assertTrue("Both AST trees should be identical", ifStatement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$ + assertTrue("Both AST trees should be identical", ifStatement.subtreeMatch(createASTMatcher(), node)); //$NON-NLS-1$ String expectedSource = "if (true)\\u003B\n" +//$NON-NLS-1$ "\t\telse ;"; //$NON-NLS-1$ checkSourceRange(node, expectedSource, source); @@ -2772,7 +2876,7 @@ public void test0121() throws JavaModelException { ifStatement.setExpression(this.ast.newBooleanLiteral(true)); ifStatement.setThenStatement(this.ast.newBlock()); ifStatement.setElseStatement(this.ast.newEmptyStatement()); - assertTrue("Both AST trees should be identical", ifStatement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$ + assertTrue("Both AST trees should be identical", ifStatement.subtreeMatch(createASTMatcher(), node)); //$NON-NLS-1$ String expectedSource = "if (true) {}\n" +//$NON-NLS-1$ " else ;"; //$NON-NLS-1$ checkSourceRange(node, expectedSource, source); @@ -2794,7 +2898,7 @@ public void test0122() throws JavaModelException { literal.setToken("2");//$NON-NLS-1$ returnStatement.setExpression(literal); ifStatement.setThenStatement(returnStatement); - assertTrue("Both AST trees should be identical", ifStatement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$ + assertTrue("Both AST trees should be identical", ifStatement.subtreeMatch(createASTMatcher(), node)); //$NON-NLS-1$ checkSourceRange(node, "if (true) return 2\\u003B", source);//$NON-NLS-1$ } @@ -2819,7 +2923,7 @@ public void test0123() throws JavaModelException { literal.setToken("3");//$NON-NLS-1$ returnStatement.setExpression(literal); ifStatement.setElseStatement(returnStatement); - assertTrue("Both AST trees should be identical", ifStatement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$ + assertTrue("Both AST trees should be identical", ifStatement.subtreeMatch(createASTMatcher(), node)); //$NON-NLS-1$ String expectedSource = "if (true) return 2;\n" +//$NON-NLS-1$ " else return 3;"; //$NON-NLS-1$ checkSourceRange(node, expectedSource, source); @@ -2857,7 +2961,7 @@ public void test0124() throws JavaModelException { statement.fragments().add(fragment); statement.setType(this.ast.newPrimitiveType(PrimitiveType.INT)); statement.setModifiers(Modifier.NONE); - assertTrue("Both AST trees should be identical", statement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$ + assertTrue("Both AST trees should be identical", statement.subtreeMatch(createASTMatcher(), node)); //$NON-NLS-1$ VariableDeclarationFragment[] fragments = (VariableDeclarationFragment[])((VariableDeclarationStatement) node).fragments().toArray(new VariableDeclarationFragment[4]); assertTrue("fragments.length != 4", fragments.length == 4); //$NON-NLS-1$ checkSourceRange(fragments[0], "x= 10", source);//$NON-NLS-1$ @@ -2899,7 +3003,7 @@ public void test0125() throws JavaModelException { statement.fragments().add(fragment); statement.setType(this.ast.newArrayType(this.ast.newPrimitiveType(PrimitiveType.INT), 1)); statement.setModifiers(Modifier.NONE); - assertTrue("Both AST trees should be identical", statement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$ + assertTrue("Both AST trees should be identical", statement.subtreeMatch(createASTMatcher(), node)); //$NON-NLS-1$ checkSourceRange(node, "int[] x= 10, z[] = null, i, j[][];", source); //$NON-NLS-1$ VariableDeclarationFragment[] fragments = (VariableDeclarationFragment[])((VariableDeclarationStatement) node).fragments().toArray(new VariableDeclarationFragment[4]); assertTrue("fragments.length != 4", fragments.length == 4); //$NON-NLS-1$ @@ -2933,7 +3037,7 @@ public void test0126() throws JavaModelException { prefixExpression.setOperator(PrefixExpression.Operator.INCREMENT); forStatement.updaters().add(prefixExpression); forStatement.setBody(this.ast.newBlock()); - assertTrue("Both AST trees should be identical", forStatement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$ + assertTrue("Both AST trees should be identical", forStatement.subtreeMatch(createASTMatcher(), node)); //$NON-NLS-1$ checkSourceRange(node, "for (String[] tab[] = null;; ++i) {}", source); //$NON-NLS-1$ checkSourceRange((ASTNode) ((ForStatement) node).updaters().get(0), "++i", source); //$NON-NLS-1$ checkSourceRange((ASTNode) ((ForStatement) node).initializers().get(0), "String[] tab[] = null", source); //$NON-NLS-1$ @@ -2963,7 +3067,7 @@ public void test0127() throws JavaModelException { prefixExpression.setOperator(PrefixExpression.Operator.INCREMENT); forStatement.updaters().add(prefixExpression); forStatement.setBody(this.ast.newBlock()); - assertTrue("Both AST trees should be identical", forStatement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$ + assertTrue("Both AST trees should be identical", forStatement.subtreeMatch(createASTMatcher(), node)); //$NON-NLS-1$ checkSourceRange(node, "for (String tab[] = null;; ++i) {}", source); //$NON-NLS-1$ checkSourceRange((ASTNode) ((ForStatement) node).updaters().get(0), "++i", source); //$NON-NLS-1$ checkSourceRange((ASTNode) ((ForStatement) node).initializers().get(0), "String tab[] = null", source); //$NON-NLS-1$ @@ -2993,7 +3097,7 @@ public void test0128() throws JavaModelException { postfixExpression.setOperator(PostfixExpression.Operator.INCREMENT); forStatement.updaters().add(postfixExpression); forStatement.setBody(this.ast.newBlock()); - assertTrue("Both AST trees should be identical", forStatement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$ + assertTrue("Both AST trees should be identical", forStatement.subtreeMatch(createASTMatcher(), node)); //$NON-NLS-1$ checkSourceRange(node, "for (String tab[] = null;; i++/**/) {}", source); //$NON-NLS-1$ checkSourceRange((ASTNode) ((ForStatement) node).updaters().get(0), "i++", source); //$NON-NLS-1$ checkSourceRange((ASTNode) ((ForStatement) node).initializers().get(0), "String tab[] = null", source); //$NON-NLS-1$ @@ -3018,7 +3122,7 @@ public void test0129() throws JavaModelException { FieldDeclaration fieldDeclaration = this.ast.newFieldDeclaration(fragment); fieldDeclaration.setModifiers(Modifier.NONE); fieldDeclaration.setType(this.ast.newPrimitiveType(PrimitiveType.INT)); - assertTrue("Both AST trees should be identical", fieldDeclaration.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$ + assertTrue("Both AST trees should be identical", fieldDeclaration.subtreeMatch(createASTMatcher(), node)); //$NON-NLS-1$ checkSourceRange(node, "int i;", source); //$NON-NLS-1$ } @@ -3055,7 +3159,7 @@ public void test0130() throws JavaModelException { fragment.setName(this.ast.newSimpleName("j"));//$NON-NLS-1$ fragment.setExtraDimensions(2); fieldDeclaration.fragments().add(fragment); - assertTrue("Both AST trees should be identical", fieldDeclaration.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$ + assertTrue("Both AST trees should be identical", fieldDeclaration.subtreeMatch(createASTMatcher(), node)); //$NON-NLS-1$ checkSourceRange(node, "public int x= 10, y[] = null, i, j[][];", source); //$NON-NLS-1$ VariableDeclarationFragment[] fragments = (VariableDeclarationFragment[])((FieldDeclaration) node).fragments().toArray(new VariableDeclarationFragment[4]); assertTrue("fragments.length != 4", fragments.length == 4); //$NON-NLS-1$ @@ -3084,7 +3188,7 @@ public void test0131() throws JavaModelException { singleVariableDeclaration.setModifiers(Modifier.FINAL); singleVariableDeclaration.setName(this.ast.newSimpleName("i")); //$NON-NLS-1$ singleVariableDeclaration.setType(this.ast.newPrimitiveType(PrimitiveType.INT)); - assertTrue("Both AST trees should be identical", singleVariableDeclaration.subtreeMatch(new ASTMatcher(), arg)); //$NON-NLS-1$ + assertTrue("Both AST trees should be identical", singleVariableDeclaration.subtreeMatch(createASTMatcher(), arg)); //$NON-NLS-1$ checkSourceRange(node, "void foo(final int i) {}", source); //$NON-NLS-1$ checkSourceRange(arg, "final int i", source); //$NON-NLS-1$ } @@ -3103,7 +3207,7 @@ public void test0132() throws JavaModelException { Javadoc actualJavadoc = ((MethodDeclaration) node).getJavadoc(); Javadoc javadoc = this.ast.newJavadoc(); javadoc.setComment("/** JavaDoc Comment*/");//$NON-NLS-1$*/ - assertTrue("Both AST trees should be identical", javadoc.subtreeMatch(new ASTMatcher(), actualJavadoc));//$NON-NLS-1$ + assertTrue("Both AST trees should be identical", javadoc.subtreeMatch(createASTMatcher(), actualJavadoc));//$NON-NLS-1$ checkSourceRange(node, "/** JavaDoc Comment*/\n void foo(final int i) {}", source); //$NON-NLS-1$ checkSourceRange(actualJavadoc, "/** JavaDoc Comment*/", source); //$NON-NLS-1$ } @@ -3152,7 +3256,7 @@ public void test0135() throws JavaModelException { Javadoc actualJavadoc = ((FieldDeclaration) node).getJavadoc(); Javadoc javadoc = this.ast.newJavadoc(); javadoc.setComment("/** JavaDoc Comment*/");//$NON-NLS-1$*/ - assertTrue("Both AST trees should be identical", javadoc.subtreeMatch(new ASTMatcher(), actualJavadoc));//$NON-NLS-1$ + assertTrue("Both AST trees should be identical", javadoc.subtreeMatch(createASTMatcher(), actualJavadoc));//$NON-NLS-1$ checkSourceRange(node, "/** JavaDoc Comment*/\n int i;", source); //$NON-NLS-1$ } @@ -3236,7 +3340,7 @@ public void test0140() throws JavaModelException { Javadoc actualJavadoc = ((TypeDeclaration) node).getJavadoc(); Javadoc javadoc = this.ast.newJavadoc(); javadoc.setComment("/** JavaDoc Comment*/");//$NON-NLS-1$*/ - assertTrue("Both AST trees should be identical", javadoc.subtreeMatch(new ASTMatcher(), actualJavadoc));//$NON-NLS-1$ + assertTrue("Both AST trees should be identical", javadoc.subtreeMatch(createASTMatcher(), actualJavadoc));//$NON-NLS-1$ String expectedContents = "/** JavaDoc Comment*/\n" + //$NON-NLS-1$ "public class Test {\n" +//$NON-NLS-1$ @@ -3260,7 +3364,7 @@ public void test0141() throws JavaModelException { Javadoc actualJavadoc = ((TypeDeclaration) node).getJavadoc(); Javadoc javadoc = this.ast.newJavadoc(); javadoc.setComment("/** JavaDoc Comment*/");//$NON-NLS-1$*/ - assertTrue("Both AST trees should be identical", javadoc.subtreeMatch(new ASTMatcher(), actualJavadoc));//$NON-NLS-1$ + assertTrue("Both AST trees should be identical", javadoc.subtreeMatch(createASTMatcher(), actualJavadoc));//$NON-NLS-1$ String expectedContents = "/** JavaDoc Comment*/\n" + //$NON-NLS-1$ " class B {}";//$NON-NLS-1$ @@ -3351,7 +3455,7 @@ public void test0147() throws JavaModelException { assertNotNull("Javadoc comment should no be null", actualJavadoc); //$NON-NLS-1$ Javadoc javadoc = this.ast.newJavadoc(); javadoc.setComment("/** JavaDoc Comment*/");//$NON-NLS-1$*/ - assertTrue("Both AST trees should be identical", javadoc.subtreeMatch(new ASTMatcher(), actualJavadoc));//$NON-NLS-1$ + assertTrue("Both AST trees should be identical", javadoc.subtreeMatch(createASTMatcher(), actualJavadoc));//$NON-NLS-1$ String expectedContents = "/** JavaDoc Comment*/\n" + //$NON-NLS-1$ " static {}";//$NON-NLS-1$ @@ -3374,7 +3478,7 @@ public void test0148() throws JavaModelException { assertNotNull("Javadoc comment should not be null", actualJavadoc); //$NON-NLS-1$ Javadoc javadoc = this.ast.newJavadoc(); javadoc.setComment("/** JavaDoc Comment*/");//$NON-NLS-1$*/ - assertTrue("Both AST trees should be identical", javadoc.subtreeMatch(new ASTMatcher(), actualJavadoc));//$NON-NLS-1$ + assertTrue("Both AST trees should be identical", javadoc.subtreeMatch(createASTMatcher(), actualJavadoc));//$NON-NLS-1$ String expectedContents = "/** JavaDoc Comment*/\n" + //$NON-NLS-1$ " {}";//$NON-NLS-1$ @@ -4991,7 +5095,7 @@ public void test0207() throws JavaModelException { Javadoc actualJavadoc = ((MethodDeclaration) node).getJavadoc(); Javadoc javadoc = this.ast.newJavadoc(); javadoc.setComment("/** JavaDoc Comment*/");//$NON-NLS-1$*/ - assertTrue("Both AST trees should be identical", javadoc.subtreeMatch(new ASTMatcher(), actualJavadoc));//$NON-NLS-1$ + assertTrue("Both AST trees should be identical", javadoc.subtreeMatch(createASTMatcher(), actualJavadoc));//$NON-NLS-1$ checkSourceRange(node, "/** JavaDoc Comment*/\n void foo(final int i) {}", source); //$NON-NLS-1$ checkSourceRange(actualJavadoc, "/** JavaDoc Comment*/", source); //$NON-NLS-1$ } @@ -5040,7 +5144,7 @@ public void test0210() throws JavaModelException { Javadoc actualJavadoc = ((FieldDeclaration) node).getJavadoc(); Javadoc javadoc = this.ast.newJavadoc(); javadoc.setComment("/** JavaDoc Comment*/");//$NON-NLS-1$*/ - assertTrue("Both AST trees should be identical", javadoc.subtreeMatch(new ASTMatcher(), actualJavadoc));//$NON-NLS-1$ + assertTrue("Both AST trees should be identical", javadoc.subtreeMatch(createASTMatcher(), actualJavadoc));//$NON-NLS-1$ checkSourceRange(node, "/** JavaDoc Comment*/\n int i;", source); //$NON-NLS-1$ } @@ -5124,7 +5228,7 @@ public void test0215() throws JavaModelException { Javadoc actualJavadoc = ((TypeDeclaration) node).getJavadoc(); Javadoc javadoc = this.ast.newJavadoc(); javadoc.setComment("/** JavaDoc Comment*/");//$NON-NLS-1$*/ - assertTrue("Both AST trees should be identical", javadoc.subtreeMatch(new ASTMatcher(), actualJavadoc));//$NON-NLS-1$ + assertTrue("Both AST trees should be identical", javadoc.subtreeMatch(createASTMatcher(), actualJavadoc));//$NON-NLS-1$ String expectedContents = "/** JavaDoc Comment*/\n" + //$NON-NLS-1$ "public class Test {\n" +//$NON-NLS-1$ @@ -5148,7 +5252,7 @@ public void test0216() throws JavaModelException { Javadoc actualJavadoc = ((TypeDeclaration) node).getJavadoc(); Javadoc javadoc = this.ast.newJavadoc(); javadoc.setComment("/** JavaDoc Comment*/");//$NON-NLS-1$*/ - assertTrue("Both AST trees should be identical", javadoc.subtreeMatch(new ASTMatcher(), actualJavadoc));//$NON-NLS-1$ + assertTrue("Both AST trees should be identical", javadoc.subtreeMatch(createASTMatcher(), actualJavadoc));//$NON-NLS-1$ String expectedContents = "/** JavaDoc Comment*/\n" + //$NON-NLS-1$ " class B {}";//$NON-NLS-1$ @@ -5239,7 +5343,7 @@ public void test0222() throws JavaModelException { assertNotNull("Javadoc comment should no be null", actualJavadoc); //$NON-NLS-1$ Javadoc javadoc = this.ast.newJavadoc(); javadoc.setComment("/** JavaDoc Comment*/");//$NON-NLS-1$*/ - assertTrue("Both AST trees should be identical", javadoc.subtreeMatch(new ASTMatcher(), actualJavadoc));//$NON-NLS-1$ + assertTrue("Both AST trees should be identical", javadoc.subtreeMatch(createASTMatcher(), actualJavadoc));//$NON-NLS-1$ String expectedContents = "/** JavaDoc Comment*/\n" + //$NON-NLS-1$ " static {}";//$NON-NLS-1$ @@ -5262,7 +5366,7 @@ public void test0223() throws JavaModelException { assertNotNull("Javadoc comment should not be null", actualJavadoc); //$NON-NLS-1$ Javadoc javadoc = this.ast.newJavadoc(); javadoc.setComment("/** JavaDoc Comment*/");//$NON-NLS-1$*/ - assertTrue("Both AST trees should be identical", javadoc.subtreeMatch(new ASTMatcher(), actualJavadoc));//$NON-NLS-1$ + assertTrue("Both AST trees should be identical", javadoc.subtreeMatch(createASTMatcher(), actualJavadoc));//$NON-NLS-1$ String expectedContents = "/** JavaDoc Comment*/\n" + //$NON-NLS-1$ " {}";//$NON-NLS-1$ @@ -5299,7 +5403,7 @@ public void test0225() throws JavaModelException { assertNotNull("Expression should not be null", statement); //$NON-NLS-1$ ContinueStatement continueStatement = this.ast.newContinueStatement(); continueStatement.setLabel(this.ast.newSimpleName("label")); //$NON-NLS-1$ - assertTrue("Both AST trees should be identical", continueStatement.subtreeMatch(new ASTMatcher(), statement)); //$NON-NLS-1$ + assertTrue("Both AST trees should be identical", continueStatement.subtreeMatch(createASTMatcher(), statement)); //$NON-NLS-1$ checkSourceRange(statement, "continue label;", source); //$NON-NLS-1$ checkSourceRange(statement.getLabel(), "label", source); //$NON-NLS-1$ } @@ -5318,7 +5422,7 @@ public void test0226() throws JavaModelException { assertNotNull("Expression should not be null", statement); //$NON-NLS-1$ BreakStatement breakStatement = this.ast.newBreakStatement(); breakStatement.setLabel(this.ast.newSimpleName("label")); //$NON-NLS-1$ - assertTrue("Both AST trees should be identical", breakStatement.subtreeMatch(new ASTMatcher(), statement)); //$NON-NLS-1$ + assertTrue("Both AST trees should be identical", breakStatement.subtreeMatch(createASTMatcher(), statement)); //$NON-NLS-1$ checkSourceRange(statement, "break label;", source); //$NON-NLS-1$ checkSourceRange(statement.getLabel(), "label", source); //$NON-NLS-1$ } @@ -9113,7 +9217,7 @@ public void test0362() throws JavaModelException { infixExpression.setRightOperand(this.ast.newNumberLiteral("10")); //$NON-NLS-1$ forStatement.setExpression(infixExpression); - assertTrue("Both AST trees should be identical", forStatement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$ + assertTrue("Both AST trees should be identical", forStatement.subtreeMatch(createASTMatcher(), node)); //$NON-NLS-1$ checkSourceRange(node, "for (int i=0, j=0, k=0; i<10 ; i++, j++, k++) {}", source); //$NON-NLS-1$ } @@ -9286,7 +9390,7 @@ public void test0370() throws JavaModelException { DoStatement doStatement = this.ast.newDoStatement(); doStatement.setBody(this.ast.newEmptyStatement()); doStatement.setExpression(this.ast.newBooleanLiteral(true)); - assertTrue("Both AST trees should be identical", doStatement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$ + assertTrue("Both AST trees should be identical", doStatement.subtreeMatch(createASTMatcher(), node)); //$NON-NLS-1$ String expectedSource = "do ; while(true);";//$NON-NLS-1$ checkSourceRange(node, expectedSource, source); DoStatement doStatement2 = (DoStatement) node; @@ -9992,5 +10096,10 @@ public void testBug446746_0002() throws JavaModelException { EnumConstantDeclaration constant = (EnumConstantDeclaration) enumDecl.enumConstants().get(0); checkSourceRange(constant, "B(){void c(){} }", contents); } + + private ASTMatcher createASTMatcher() { + //return new ASTMatcher(); + return new CustomASTMatcher(); + } } diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverterTest2.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverterTest2.java index c8bd65994be..bdf176a882b 100644 --- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverterTest2.java +++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverterTest2.java @@ -20,18 +20,81 @@ import java.util.Map; import java.util.Set; -import junit.framework.Test; - import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.OperationCanceledException; -import org.eclipse.jdt.core.*; +import org.eclipse.jdt.core.IClasspathEntry; +import org.eclipse.jdt.core.ICompilationUnit; +import org.eclipse.jdt.core.IInitializer; +import org.eclipse.jdt.core.IJavaElement; +import org.eclipse.jdt.core.IJavaProject; +import org.eclipse.jdt.core.IMethod; +import org.eclipse.jdt.core.IOrdinaryClassFile; +import org.eclipse.jdt.core.ISourceRange; +import org.eclipse.jdt.core.IType; +import org.eclipse.jdt.core.JavaCore; +import org.eclipse.jdt.core.JavaModelException; +import org.eclipse.jdt.core.WorkingCopyOwner; import org.eclipse.jdt.core.compiler.IProblem; -import org.eclipse.jdt.core.dom.*; +import org.eclipse.jdt.core.dom.AST; +import org.eclipse.jdt.core.dom.ASTMatcher; +import org.eclipse.jdt.core.dom.ASTNode; +import org.eclipse.jdt.core.dom.ASTParser; +import org.eclipse.jdt.core.dom.ASTVisitor; +import org.eclipse.jdt.core.dom.AnonymousClassDeclaration; +import org.eclipse.jdt.core.dom.ArrayType; +import org.eclipse.jdt.core.dom.AssertStatement; +import org.eclipse.jdt.core.dom.Assignment; +import org.eclipse.jdt.core.dom.Block; +import org.eclipse.jdt.core.dom.BodyDeclaration; +import org.eclipse.jdt.core.dom.CastExpression; +import org.eclipse.jdt.core.dom.ClassInstanceCreation; +import org.eclipse.jdt.core.dom.CompilationUnit; +import org.eclipse.jdt.core.dom.ConstructorInvocation; +import org.eclipse.jdt.core.dom.Expression; +import org.eclipse.jdt.core.dom.ExpressionStatement; +import org.eclipse.jdt.core.dom.FieldAccess; +import org.eclipse.jdt.core.dom.FieldDeclaration; +import org.eclipse.jdt.core.dom.ForStatement; +import org.eclipse.jdt.core.dom.IBinding; +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.dom.IfStatement; +import org.eclipse.jdt.core.dom.ImportDeclaration; +import org.eclipse.jdt.core.dom.InfixExpression; +import org.eclipse.jdt.core.dom.Initializer; +import org.eclipse.jdt.core.dom.MethodDeclaration; +import org.eclipse.jdt.core.dom.MethodInvocation; +import org.eclipse.jdt.core.dom.Modifier; +import org.eclipse.jdt.core.dom.Name; +import org.eclipse.jdt.core.dom.NullLiteral; +import org.eclipse.jdt.core.dom.PackageDeclaration; +import org.eclipse.jdt.core.dom.ParenthesizedExpression; +import org.eclipse.jdt.core.dom.QualifiedName; +import org.eclipse.jdt.core.dom.ReturnStatement; +import org.eclipse.jdt.core.dom.SimpleName; +import org.eclipse.jdt.core.dom.SimpleType; +import org.eclipse.jdt.core.dom.SingleVariableDeclaration; +import org.eclipse.jdt.core.dom.Statement; +import org.eclipse.jdt.core.dom.StringLiteral; +import org.eclipse.jdt.core.dom.SuperFieldAccess; +import org.eclipse.jdt.core.dom.SuperMethodInvocation; +import org.eclipse.jdt.core.dom.SwitchCase; +import org.eclipse.jdt.core.dom.SwitchStatement; +import org.eclipse.jdt.core.dom.Type; +import org.eclipse.jdt.core.dom.TypeDeclaration; +import org.eclipse.jdt.core.dom.TypeDeclarationStatement; +import org.eclipse.jdt.core.dom.VariableDeclarationExpression; +import org.eclipse.jdt.core.dom.VariableDeclarationFragment; +import org.eclipse.jdt.core.dom.VariableDeclarationStatement; +import org.eclipse.jdt.core.dom.WhileStatement; import org.eclipse.jdt.core.tests.model.CancelCounter; import org.eclipse.jdt.core.tests.model.Canceler; import org.eclipse.jdt.core.tests.model.ReconcilerTests; import org.eclipse.jdt.core.tests.util.Util; +import junit.framework.Test; + @SuppressWarnings({"rawtypes", "unchecked"}) public class ASTConverterTest2 extends ConverterTestSetup { diff --git a/org.eclipse.jdt.core.tests.model/workspace/Converter/src/test0052/Test.java b/org.eclipse.jdt.core.tests.model/workspace/Converter/src/test0052/Test.java index 68c13d01e24..bbc22db8ba2 100644 --- a/org.eclipse.jdt.core.tests.model/workspace/Converter/src/test0052/Test.java +++ b/org.eclipse.jdt.core.tests.model/workspace/Converter/src/test0052/Test.java @@ -5,4 +5,4 @@ public static void main(String[] args) { System.out.println(-9223372036854775808L); } -} \ No newline at end of file +} diff --git a/org.eclipse.jdt.core/.settings/org.eclipse.pde.api.tools.prefs b/org.eclipse.jdt.core/.settings/org.eclipse.pde.api.tools.prefs index 6f7536aee1a..88ee8ac8e3d 100644 --- a/org.eclipse.jdt.core/.settings/org.eclipse.pde.api.tools.prefs +++ b/org.eclipse.jdt.core/.settings/org.eclipse.pde.api.tools.prefs @@ -1,4 +1,4 @@ -#Fri May 21 10:24:07 EDT 2010 +ANNOTATION_ELEMENT_TYPE_ADDED_FIELD=Warning ANNOTATION_ELEMENT_TYPE_ADDED_METHOD_WITHOUT_DEFAULT_VALUE=Error ANNOTATION_ELEMENT_TYPE_CHANGED_TYPE_CONVERSION=Error ANNOTATION_ELEMENT_TYPE_REMOVED_FIELD=Error @@ -8,6 +8,10 @@ API_COMPONENT_ELEMENT_TYPE_REMOVED_API_TYPE=Error API_COMPONENT_ELEMENT_TYPE_REMOVED_REEXPORTED_API_TYPE=Error API_COMPONENT_ELEMENT_TYPE_REMOVED_REEXPORTED_TYPE=Error API_COMPONENT_ELEMENT_TYPE_REMOVED_TYPE=Error +API_USE_SCAN_FIELD_SEVERITY=Error +API_USE_SCAN_METHOD_SEVERITY=Error +API_USE_SCAN_TYPE_SEVERITY=Error +CLASS_ELEMENT_TYPE_ADDED_FIELD=Warning CLASS_ELEMENT_TYPE_ADDED_METHOD=Error CLASS_ELEMENT_TYPE_ADDED_RESTRICTIONS=Error CLASS_ELEMENT_TYPE_ADDED_TYPE_PARAMETER=Error @@ -47,6 +51,7 @@ ILLEGAL_IMPLEMENT=Warning ILLEGAL_INSTANTIATE=Warning ILLEGAL_OVERRIDE=Warning ILLEGAL_REFERENCE=Warning +INTERFACE_ELEMENT_TYPE_ADDED_DEFAULT_METHOD=Warning INTERFACE_ELEMENT_TYPE_ADDED_FIELD=Error INTERFACE_ELEMENT_TYPE_ADDED_METHOD=Error INTERFACE_ELEMENT_TYPE_ADDED_RESTRICTIONS=Error @@ -58,6 +63,7 @@ INTERFACE_ELEMENT_TYPE_REMOVED_FIELD=Error INTERFACE_ELEMENT_TYPE_REMOVED_METHOD=Error INTERFACE_ELEMENT_TYPE_REMOVED_TYPE_MEMBER=Error INTERFACE_ELEMENT_TYPE_REMOVED_TYPE_PARAMETER=Error +INVALID_ANNOTATION=Ignore INVALID_JAVADOC_TAG=Warning INVALID_REFERENCE_IN_SYSTEM_LIBRARIES=Warning LEAK_EXTEND=Warning @@ -83,12 +89,15 @@ TYPE_PARAMETER_ELEMENT_TYPE_REMOVED_CLASS_BOUND=Error TYPE_PARAMETER_ELEMENT_TYPE_REMOVED_INTERFACE_BOUND=Error UNUSED_PROBLEM_FILTERS=Warning automatically_removed_unused_problem_filters=false +changed_execution_env=Error eclipse.preferences.version=1 -incompatible_api_component_version=Error +incompatible_api_component_version=Warning incompatible_api_component_version_include_major_without_breaking_change=Disabled incompatible_api_component_version_include_minor_without_api_change=Disabled -invalid_since_tag_version=Error -malformed_since_tag=Error -missing_since_tag=Error +incompatible_api_component_version_report_major_without_breaking_change=Warning +incompatible_api_component_version_report_minor_without_api_change=Warning +invalid_since_tag_version=Warning +malformed_since_tag=Warning +missing_since_tag=Warning report_api_breakage_when_major_version_incremented=Disabled report_resolution_errors_api_component=Warning diff --git a/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/ASTNode.java b/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/ASTNode.java index a36aae9705a..65cf1f28c79 100644 --- a/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/ASTNode.java +++ b/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/ASTNode.java @@ -3127,7 +3127,8 @@ public final void setFlags(int flags) { * @return one of the node type constants */ public final int getNodeType() { - return this.typeAndFlags >>> 16; + int nt = this.typeAndFlags >>> 16; + return nt; } /** @@ -3186,7 +3187,13 @@ public final int hashCode() { * false if they do not match */ public final boolean subtreeMatch(ASTMatcher matcher, Object other) { - return subtreeMatch0(matcher, other); + boolean ret = subtreeMatch0(matcher, other); + if( !ret ) { + String clazMsg = this.getClass().getName() + ", " + (other == null ? "null" : other.getClass().getName()); + String nodeMsg = "Expected " + this.toString() + "\nBut Was: " + (other == null ? "null" : other.toString()); + throw new RuntimeException("Died Here: " + clazMsg + "\n" + nodeMsg); + } + return ret; } /** diff --git a/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/CompilationUnit.java b/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/CompilationUnit.java index 77a1d729a0d..8b93a3942ba 100644 --- a/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/CompilationUnit.java +++ b/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/CompilationUnit.java @@ -1007,7 +1007,8 @@ void setCommentTable(Comment[] commentTable) { this.optionalCommentTable = null; } else { int nextAvailablePosition = 0; - for (Comment comment : commentTable) { + for (int i = 0; i < commentTable.length; i++) { + Comment comment = commentTable[i]; if (comment == null) { throw new IllegalArgumentException(); } diff --git a/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/CompilationUnitResolver.java b/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/CompilationUnitResolver.java index 93fddff325b..56f94a6528a 100644 --- a/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/CompilationUnitResolver.java +++ b/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/CompilationUnitResolver.java @@ -81,9 +81,9 @@ import org.eclipse.jdt.internal.core.util.DOMFinder; @SuppressWarnings({ "rawtypes", "unchecked" }) -class CompilationUnitResolver extends Compiler { +public class CompilationUnitResolver extends Compiler { - private static final class ECJCompilationUnitResolver implements ICompilationUnitResolver { + public static final class ECJCompilationUnitResolver implements ICompilationUnitResolver { @Override public void resolve(String[] sourceFilePaths, String[] encodings, String[] bindingKeys,