Index: src/org/eclipse/jdt/core/tests/dom/ASTMatcherTest.java =================================================================== RCS file: /data/cvs/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTMatcherTest.java,v retrieving revision 1.6 diff -u -r1.6 ASTMatcherTest.java --- src/org/eclipse/jdt/core/tests/dom/ASTMatcherTest.java 11 Mar 2003 15:07:11 -0000 1.6 +++ src/org/eclipse/jdt/core/tests/dom/ASTMatcherTest.java 8 Apr 2003 16:49:05 -0000 @@ -259,6 +259,12 @@ public boolean match(EmptyStatement node, Object other) { return standardBody(node, other, superMatch ? super.match(node, other) : false); } + public boolean match(EnhancedForStatement node, Object other) { + return standardBody(node, other, superMatch ? super.match(node, other) : false); + } + public boolean match(EnumConstantDeclaration node, Object other) { + return standardBody(node, other, superMatch ? super.match(node, other) : false); + } public boolean match(ExpressionStatement node, Object other) { return standardBody(node, other, superMatch ? super.match(node, other) : false); } @@ -592,6 +598,24 @@ } public void testEmptyStatement() { EmptyStatement x1 = ast.newEmptyStatement(); + basicMatch(x1); + } + public void testEnhancedForStatement() { + EnhancedForStatement x1 = ast.newEnhancedForStatement(); + x1.setType(T1); + x1.setName(N1); + x1.setExpression(E1); + x1.setBody(S1); + basicMatch(x1); + } + public void testEnumConstantDeclaration() { + EnumConstantDeclaration x1 = ast.newEnumConstantDeclaration(); + x1.setJavadoc(JD1); + x1.setName(N1); + x1.arguments().add(E1); + x1.arguments().add(E2); + x1.bodyDeclarations().add(FD1); + x1.bodyDeclarations().add(FD2); basicMatch(x1); } public void testExpressionStatement() { Index: src/org/eclipse/jdt/core/tests/dom/ASTTest.java =================================================================== RCS file: /data/cvs/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTTest.java,v retrieving revision 1.15 diff -u -r1.15 ASTTest.java --- src/org/eclipse/jdt/core/tests/dom/ASTTest.java 11 Mar 2003 15:07:11 -0000 1.15 +++ src/org/eclipse/jdt/core/tests/dom/ASTTest.java 8 Apr 2003 16:49:09 -0000 @@ -1663,6 +1663,7 @@ assertTrue(x.getAST() == ast); assertTrue(x.getParent() == null); assertTrue(x.isOnDemand() == false); + assertTrue(x.isStatic() == false); assertTrue(x.getName().getParent() == x); assertTrue(x.getNodeType() == ASTNode.IMPORT_DECLARATION); // make sure that reading did not change modification count @@ -1692,6 +1693,9 @@ x.setOnDemand(true); assertTrue(ast.modificationCount() > previousCount); assertTrue(x.isOnDemand() == true); + x.setStatic(true); + assertTrue(ast.modificationCount() > previousCount); + assertTrue(x.isStatic() == true); } public void testCompilationUnit() { @@ -1825,6 +1829,7 @@ assertTrue(x.getParent() == null); assertTrue(x.getModifiers() == Modifier.NONE); assertTrue(x.isInterface() == false); + assertTrue(x.isEnumeration() == false); assertTrue(x.getName().getParent() == x); assertTrue(x.getName().isDeclaration() == true); assertTrue(x.getSuperclass() == null); @@ -1853,6 +1858,12 @@ assertTrue(ast.modificationCount() > previousCount); assertTrue(x.getModifiers() == Modifier.NONE); + previousCount = ast.modificationCount(); + x.setEnumeration(true); + assertTrue(ast.modificationCount() > previousCount); + assertTrue(x.isEnumeration() == true); + x.setEnumeration(false); + tJavadocComment(x); genericPropertyTest(x, new Property("Name", true, SimpleName.class) { //$NON-NLS-1$ @@ -1927,7 +1938,11 @@ MethodDeclaration m2 = ast.newMethodDeclaration(); TypeDeclaration t1 = ast.newTypeDeclaration(); TypeDeclaration t2 = ast.newTypeDeclaration(); + EnumConstantDeclaration c1 = ast.newEnumConstantDeclaration(); + EnumConstantDeclaration c2 = ast.newEnumConstantDeclaration(); + x.bodyDeclarations().add(c1); + x.bodyDeclarations().add(c2); x.bodyDeclarations().add(ast.newInitializer()); x.bodyDeclarations().add(f1); x.bodyDeclarations().add(ast.newInitializer()); @@ -1957,7 +1972,99 @@ assertTrue(ts.contains(t1)); assertTrue(ts.contains(t2)); + List es = Arrays.asList(x.getEnumConstants()); + assertTrue(es.size() == 2); + assertTrue(es.contains(c1)); + assertTrue(es.contains(c2)); + + // check that TypeDeclarations in body are classified correctly + assertTrue(t1.isLocalTypeDeclaration() == false); + assertTrue(t1.isMemberTypeDeclaration() == true); + assertTrue(t1.isPackageMemberTypeDeclaration() == false); + + } + + public void testEnumConstantDeclaration() { + long previousCount = ast.modificationCount(); + final EnumConstantDeclaration x = ast.newEnumConstantDeclaration(); + assertTrue(ast.modificationCount() > previousCount); + previousCount = ast.modificationCount(); + assertTrue(x instanceof BodyDeclaration); + assertTrue(x.getAST() == ast); + assertTrue(x.getParent() == null); + assertTrue(x.getName().getParent() == x); + assertTrue(x.getName().isDeclaration() == true); + assertTrue(x.getJavadoc() == null); + assertTrue(x.arguments().size()== 0); + assertTrue(x.bodyDeclarations().size()== 0); + assertTrue(x.getNodeType() == ASTNode.ENUM_CONSTANT_DECLARATION); + // make sure that reading did not change modification count + assertTrue(ast.modificationCount() == previousCount); + + tJavadocComment(x); + + genericPropertyTest(x, new Property("Name", true, SimpleName.class) { //$NON-NLS-1$ + public ASTNode sample(AST targetAst, boolean parented) { + SimpleName result = targetAst.newSimpleName("foo"); //$NON-NLS-1$ + if (parented) { + targetAst.newExpressionStatement(result); + } + return result; + } + public ASTNode get() { + return x.getName(); + } + public void set(ASTNode value) { + x.setName((SimpleName) value); + } + }); + + genericPropertyListTest(x, x.arguments(), + new Property("Arguments", true, Expression.class) { //$NON-NLS-1$ + public ASTNode sample(AST targetAst, boolean parented) { + SimpleName result = targetAst.newSimpleName("foo"); //$NON-NLS-1$ + if (parented) { + targetAst.newExpressionStatement(result); + } + return result; + } + public ASTNode wrap() { + AnonymousClassDeclaration s1 = x.getAST().newAnonymousClassDeclaration(); + s1.bodyDeclarations().add(x); + return s1; + } + public void unwrap() { + AnonymousClassDeclaration s1 = (AnonymousClassDeclaration) x.getParent(); + s1.bodyDeclarations().remove(x); + } + }); + + genericPropertyListTest(x, x.bodyDeclarations(), + new Property("BodyDeclarations", true, BodyDeclaration.class) { //$NON-NLS-1$ + public ASTNode sample(AST targetAst, boolean parented) { + TypeDeclaration result = targetAst.newTypeDeclaration(); + if (parented) { + CompilationUnit cu = targetAst.newCompilationUnit(); + cu.types().add(result); + } + return result; + } + public ASTNode wrap() { + EnumConstantDeclaration s1 = x.getAST().newEnumConstantDeclaration(); + s1.bodyDeclarations().add(x); + return s1; + } + public void unwrap() { + EnumConstantDeclaration s1 = (EnumConstantDeclaration) x.getParent(); + s1.bodyDeclarations().remove(x); + } + }); + // check that TypeDeclarations in body are classified correctly + x.bodyDeclarations().clear(); + TypeDeclaration t1 = ast.newTypeDeclaration(); + x.bodyDeclarations().add(t1); + assertTrue(t1.isLocalTypeDeclaration() == false); assertTrue(t1.isMemberTypeDeclaration() == true); assertTrue(t1.isPackageMemberTypeDeclaration() == false); @@ -4357,6 +4464,11 @@ VariableDeclarationExpression variableDeclarationExpression = target.newVariableDeclarationExpression(variableDeclarationFragment3); variableDeclarationExpression.setSourceRange(430, 5); z.add(variableDeclarationExpression); + + // new for 2.2 + EnhancedForStatement foreachStatement = target.newEnhancedForStatement(); + foreachStatement.setSourceRange(500, 5); + b.statements().add(foreachStatement); ASTNode clone = ASTNode.copySubtree(ast, cu); assertTrue(cu.subtreeMatch(new CheckPositionsMatcher(), clone)); @@ -4570,6 +4682,124 @@ public void unwrap() { Block s3 = (Block) x.getParent(); s3.statements().remove(x); + } + }); + + genericPropertyTest(x, new Property("Body", true, Statement.class) { //$NON-NLS-1$ + public ASTNode sample(AST targetAst, boolean parented) { + Block result = targetAst.newBlock(); + if (parented) { + Block b2 = targetAst.newBlock(); + b2.statements().add(result); + } + return result; + } + public ASTNode wrap() { + // return a Statement that embeds x + Block s1 = ast.newBlock(); + s1.statements().add(x); + return s1; + } + public void unwrap() { + Block s2 = (Block) x.getParent(); + s2.statements().remove(x); + } + public ASTNode get() { + return x.getBody(); + } + public void set(ASTNode value) { + x.setBody((Statement) value); + } + }); + } + + public void testEnhancedForStatement() { + long previousCount = ast.modificationCount(); + final EnhancedForStatement x = ast.newEnhancedForStatement(); + assertTrue(ast.modificationCount() > previousCount); + previousCount = ast.modificationCount(); + assertTrue(x instanceof Statement); + assertTrue(x.getAST() == ast); + assertTrue(x.getParent() == null); + assertTrue(x.getType() != null); + assertTrue(x.getType().getParent() == x); + assertTrue(x.getName() != null); + assertTrue(x.getName().getParent() == x); + assertTrue(x.getName().isDeclaration() == true); + assertTrue(x.getExpression() != null); + assertTrue(x.getExpression().getParent() == x); + assertTrue(x.getBody().getParent() == x); + assertTrue(x.getBody() instanceof Block); + assertTrue(((Block) x.getBody()).statements().isEmpty()); + assertTrue(x.getLeadingComment() == null); + assertTrue(x.getNodeType() == ASTNode.ENHANCED_FOR_STATEMENT); + // make sure that reading did not change modification count + assertTrue(ast.modificationCount() == previousCount); + + tLeadingComment(x); + + genericPropertyTest(x, new Property("Type", true, Type.class) { //$NON-NLS-1$ + public ASTNode sample(AST targetAst, boolean parented) { + SimpleType result = targetAst.newSimpleType( + targetAst.newSimpleName("a")); //$NON-NLS-1$ + if (parented) { + targetAst.newArrayType(result); + } + return result; + } + public ASTNode get() { + return x.getType(); + } + public void set(ASTNode value) { + x.setType((Type) value); + } + }); + + genericPropertyTest(x, new Property("Name", true, SimpleName.class) { //$NON-NLS-1$ + public ASTNode sample(AST targetAst, boolean parented) { + SimpleName result = targetAst.newSimpleName("foo"); //$NON-NLS-1$ + if (parented) { + targetAst.newExpressionStatement(result); + } + return result; + } + public ASTNode get() { + return x.getName(); + } + public void set(ASTNode value) { + x.setName((SimpleName) value); + } + }); + + genericPropertyTest(x, new Property("Expression", true, Expression.class) { //$NON-NLS-1$ + public ASTNode sample(AST ast, boolean parented) { + Expression result = ast.newSimpleName("foo"); //$NON-NLS-1$ + if (parented) { + ast.newExpressionStatement(result); + } + return result; + } + public ASTNode wrap() { + // return Expression that embeds x + ClassInstanceCreation s1 = ast.newClassInstanceCreation(); + AnonymousClassDeclaration a1 = ast.newAnonymousClassDeclaration(); + s1.setAnonymousClassDeclaration(a1); + MethodDeclaration s2 = ast.newMethodDeclaration(); + a1.bodyDeclarations().add(s2); + Block s3 = ast.newBlock(); + s2.setBody(s3); + s3.statements().add(x); + return s1; + } + public void unwrap() { + Block s3 = (Block) x.getParent(); + s3.statements().remove(x); + } + public ASTNode get() { + return x.getExpression(); + } + public void set(ASTNode value) { + x.setExpression((Expression) value); } }); Index: src/org/eclipse/jdt/core/tests/dom/ASTVisitorTest.java =================================================================== RCS file: /data/cvs/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTVisitorTest.java,v retrieving revision 1.8 diff -u -r1.8 ASTVisitorTest.java --- src/org/eclipse/jdt/core/tests/dom/ASTVisitorTest.java 11 Mar 2003 15:07:11 -0000 1.8 +++ src/org/eclipse/jdt/core/tests/dom/ASTVisitorTest.java 8 Apr 2003 16:49:10 -0000 @@ -383,6 +383,22 @@ b.append("sEM)"); //$NON-NLS-1$ } + public boolean visit(EnhancedForStatement node) { + b.append("(sEFR"); //$NON-NLS-1$ + return isVisitingChildren(); + } + public void endVisit(EnhancedForStatement node) { + b.append("sEFR)"); //$NON-NLS-1$ + } + + public boolean visit(EnumConstantDeclaration node) { + b.append("(ECD"); //$NON-NLS-1$ + return isVisitingChildren(); + } + public void endVisit(EnumConstantDeclaration node) { + b.append("ECD)"); //$NON-NLS-1$ + } + public boolean visit(ExpressionStatement node) { b.append("(sEX"); //$NON-NLS-1$ return isVisitingChildren(); @@ -964,6 +980,20 @@ String result = b.toString(); assertTrue(result.equals("[(sEMsEM)]")); //$NON-NLS-1$ } + public void testEnumConstantDeclaration() { + EnumConstantDeclaration x1 = ast.newEnumConstantDeclaration(); + x1.setJavadoc(JD1); + x1.setName(N1); + x1.arguments().add(E1); + x1.arguments().add(E2); + x1.bodyDeclarations().add(FD1); + x1.bodyDeclarations().add(FD2); + TestVisitor v1 = new TestVisitor(); + b.setLength(0); + x1.accept(v1); + String result = b.toString(); + assertTrue(result.equals("[(ECD"+JD1S+N1S+E1S+E2S+FD1S+FD2S+"ECD)]")); //$NON-NLS-1$ //$NON-NLS-2$ + } public void testExpressionStatement() { ExpressionStatement x1 = ast.newExpressionStatement(E1); TestVisitor v1 = new TestVisitor(); @@ -1006,6 +1036,18 @@ x1.accept(v1); String result = b.toString(); assertTrue(result.equals("[(sFR"+E1S+E2S+N1S+N2S+N3S+S1S+"sFR)]")); //$NON-NLS-1$ //$NON-NLS-2$ + } + public void testEnhancedForStatement() { + EnhancedForStatement x1 = ast.newEnhancedForStatement(); + x1.setType(T1); + x1.setName(N1); + x1.setExpression(E1); + x1.setBody(S1); + TestVisitor v1 = new TestVisitor(); + b.setLength(0); + x1.accept(v1); + String result = b.toString(); + assertTrue(result.equals("[(sEFR"+T1S+N1S+E1S+S1S+"sEFR)]")); //$NON-NLS-1$ //$NON-NLS-2$ } public void testIfStatement() { IfStatement x1 = ast.newIfStatement();