Lines 1663-1668
Link Here
|
1663 |
assertTrue(x.getAST() == ast); |
1663 |
assertTrue(x.getAST() == ast); |
1664 |
assertTrue(x.getParent() == null); |
1664 |
assertTrue(x.getParent() == null); |
1665 |
assertTrue(x.isOnDemand() == false); |
1665 |
assertTrue(x.isOnDemand() == false); |
|
|
1666 |
assertTrue(x.isStatic() == false); |
1666 |
assertTrue(x.getName().getParent() == x); |
1667 |
assertTrue(x.getName().getParent() == x); |
1667 |
assertTrue(x.getNodeType() == ASTNode.IMPORT_DECLARATION); |
1668 |
assertTrue(x.getNodeType() == ASTNode.IMPORT_DECLARATION); |
1668 |
// make sure that reading did not change modification count |
1669 |
// make sure that reading did not change modification count |
Lines 1692-1697
Link Here
|
1692 |
x.setOnDemand(true); |
1693 |
x.setOnDemand(true); |
1693 |
assertTrue(ast.modificationCount() > previousCount); |
1694 |
assertTrue(ast.modificationCount() > previousCount); |
1694 |
assertTrue(x.isOnDemand() == true); |
1695 |
assertTrue(x.isOnDemand() == true); |
|
|
1696 |
x.setStatic(true); |
1697 |
assertTrue(ast.modificationCount() > previousCount); |
1698 |
assertTrue(x.isStatic() == true); |
1695 |
} |
1699 |
} |
1696 |
|
1700 |
|
1697 |
public void testCompilationUnit() { |
1701 |
public void testCompilationUnit() { |
Lines 1825-1830
Link Here
|
1825 |
assertTrue(x.getParent() == null); |
1829 |
assertTrue(x.getParent() == null); |
1826 |
assertTrue(x.getModifiers() == Modifier.NONE); |
1830 |
assertTrue(x.getModifiers() == Modifier.NONE); |
1827 |
assertTrue(x.isInterface() == false); |
1831 |
assertTrue(x.isInterface() == false); |
|
|
1832 |
assertTrue(x.isEnumeration() == false); |
1828 |
assertTrue(x.getName().getParent() == x); |
1833 |
assertTrue(x.getName().getParent() == x); |
1829 |
assertTrue(x.getName().isDeclaration() == true); |
1834 |
assertTrue(x.getName().isDeclaration() == true); |
1830 |
assertTrue(x.getSuperclass() == null); |
1835 |
assertTrue(x.getSuperclass() == null); |
Lines 1853-1858
Link Here
|
1853 |
assertTrue(ast.modificationCount() > previousCount); |
1858 |
assertTrue(ast.modificationCount() > previousCount); |
1854 |
assertTrue(x.getModifiers() == Modifier.NONE); |
1859 |
assertTrue(x.getModifiers() == Modifier.NONE); |
1855 |
|
1860 |
|
|
|
1861 |
previousCount = ast.modificationCount(); |
1862 |
x.setEnumeration(true); |
1863 |
assertTrue(ast.modificationCount() > previousCount); |
1864 |
assertTrue(x.isEnumeration() == true); |
1865 |
x.setEnumeration(false); |
1866 |
|
1856 |
tJavadocComment(x); |
1867 |
tJavadocComment(x); |
1857 |
|
1868 |
|
1858 |
genericPropertyTest(x, new Property("Name", true, SimpleName.class) { //$NON-NLS-1$ |
1869 |
genericPropertyTest(x, new Property("Name", true, SimpleName.class) { //$NON-NLS-1$ |
Lines 1927-1933
Link Here
|
1927 |
MethodDeclaration m2 = ast.newMethodDeclaration(); |
1938 |
MethodDeclaration m2 = ast.newMethodDeclaration(); |
1928 |
TypeDeclaration t1 = ast.newTypeDeclaration(); |
1939 |
TypeDeclaration t1 = ast.newTypeDeclaration(); |
1929 |
TypeDeclaration t2 = ast.newTypeDeclaration(); |
1940 |
TypeDeclaration t2 = ast.newTypeDeclaration(); |
|
|
1941 |
EnumConstantDeclaration c1 = ast.newEnumConstantDeclaration(); |
1942 |
EnumConstantDeclaration c2 = ast.newEnumConstantDeclaration(); |
1930 |
|
1943 |
|
|
|
1944 |
x.bodyDeclarations().add(c1); |
1945 |
x.bodyDeclarations().add(c2); |
1931 |
x.bodyDeclarations().add(ast.newInitializer()); |
1946 |
x.bodyDeclarations().add(ast.newInitializer()); |
1932 |
x.bodyDeclarations().add(f1); |
1947 |
x.bodyDeclarations().add(f1); |
1933 |
x.bodyDeclarations().add(ast.newInitializer()); |
1948 |
x.bodyDeclarations().add(ast.newInitializer()); |
Lines 1957-1963
Link Here
|
1957 |
assertTrue(ts.contains(t1)); |
1972 |
assertTrue(ts.contains(t1)); |
1958 |
assertTrue(ts.contains(t2)); |
1973 |
assertTrue(ts.contains(t2)); |
1959 |
|
1974 |
|
|
|
1975 |
List es = Arrays.asList(x.getEnumConstants()); |
1976 |
assertTrue(es.size() == 2); |
1977 |
assertTrue(es.contains(c1)); |
1978 |
assertTrue(es.contains(c2)); |
1979 |
|
1980 |
// check that TypeDeclarations in body are classified correctly |
1981 |
assertTrue(t1.isLocalTypeDeclaration() == false); |
1982 |
assertTrue(t1.isMemberTypeDeclaration() == true); |
1983 |
assertTrue(t1.isPackageMemberTypeDeclaration() == false); |
1984 |
|
1985 |
} |
1986 |
|
1987 |
public void testEnumConstantDeclaration() { |
1988 |
long previousCount = ast.modificationCount(); |
1989 |
final EnumConstantDeclaration x = ast.newEnumConstantDeclaration(); |
1990 |
assertTrue(ast.modificationCount() > previousCount); |
1991 |
previousCount = ast.modificationCount(); |
1992 |
assertTrue(x instanceof BodyDeclaration); |
1993 |
assertTrue(x.getAST() == ast); |
1994 |
assertTrue(x.getParent() == null); |
1995 |
assertTrue(x.getName().getParent() == x); |
1996 |
assertTrue(x.getName().isDeclaration() == true); |
1997 |
assertTrue(x.getJavadoc() == null); |
1998 |
assertTrue(x.arguments().size()== 0); |
1999 |
assertTrue(x.bodyDeclarations().size()== 0); |
2000 |
assertTrue(x.getNodeType() == ASTNode.ENUM_CONSTANT_DECLARATION); |
2001 |
// make sure that reading did not change modification count |
2002 |
assertTrue(ast.modificationCount() == previousCount); |
2003 |
|
2004 |
tJavadocComment(x); |
2005 |
|
2006 |
genericPropertyTest(x, new Property("Name", true, SimpleName.class) { //$NON-NLS-1$ |
2007 |
public ASTNode sample(AST targetAst, boolean parented) { |
2008 |
SimpleName result = targetAst.newSimpleName("foo"); //$NON-NLS-1$ |
2009 |
if (parented) { |
2010 |
targetAst.newExpressionStatement(result); |
2011 |
} |
2012 |
return result; |
2013 |
} |
2014 |
public ASTNode get() { |
2015 |
return x.getName(); |
2016 |
} |
2017 |
public void set(ASTNode value) { |
2018 |
x.setName((SimpleName) value); |
2019 |
} |
2020 |
}); |
2021 |
|
2022 |
genericPropertyListTest(x, x.arguments(), |
2023 |
new Property("Arguments", true, Expression.class) { //$NON-NLS-1$ |
2024 |
public ASTNode sample(AST targetAst, boolean parented) { |
2025 |
SimpleName result = targetAst.newSimpleName("foo"); //$NON-NLS-1$ |
2026 |
if (parented) { |
2027 |
targetAst.newExpressionStatement(result); |
2028 |
} |
2029 |
return result; |
2030 |
} |
2031 |
public ASTNode wrap() { |
2032 |
AnonymousClassDeclaration s1 = x.getAST().newAnonymousClassDeclaration(); |
2033 |
s1.bodyDeclarations().add(x); |
2034 |
return s1; |
2035 |
} |
2036 |
public void unwrap() { |
2037 |
AnonymousClassDeclaration s1 = (AnonymousClassDeclaration) x.getParent(); |
2038 |
s1.bodyDeclarations().remove(x); |
2039 |
} |
2040 |
}); |
2041 |
|
2042 |
genericPropertyListTest(x, x.bodyDeclarations(), |
2043 |
new Property("BodyDeclarations", true, BodyDeclaration.class) { //$NON-NLS-1$ |
2044 |
public ASTNode sample(AST targetAst, boolean parented) { |
2045 |
TypeDeclaration result = targetAst.newTypeDeclaration(); |
2046 |
if (parented) { |
2047 |
CompilationUnit cu = targetAst.newCompilationUnit(); |
2048 |
cu.types().add(result); |
2049 |
} |
2050 |
return result; |
2051 |
} |
2052 |
public ASTNode wrap() { |
2053 |
EnumConstantDeclaration s1 = x.getAST().newEnumConstantDeclaration(); |
2054 |
s1.bodyDeclarations().add(x); |
2055 |
return s1; |
2056 |
} |
2057 |
public void unwrap() { |
2058 |
EnumConstantDeclaration s1 = (EnumConstantDeclaration) x.getParent(); |
2059 |
s1.bodyDeclarations().remove(x); |
2060 |
} |
2061 |
}); |
2062 |
|
1960 |
// check that TypeDeclarations in body are classified correctly |
2063 |
// check that TypeDeclarations in body are classified correctly |
|
|
2064 |
x.bodyDeclarations().clear(); |
2065 |
TypeDeclaration t1 = ast.newTypeDeclaration(); |
2066 |
x.bodyDeclarations().add(t1); |
2067 |
|
1961 |
assertTrue(t1.isLocalTypeDeclaration() == false); |
2068 |
assertTrue(t1.isLocalTypeDeclaration() == false); |
1962 |
assertTrue(t1.isMemberTypeDeclaration() == true); |
2069 |
assertTrue(t1.isMemberTypeDeclaration() == true); |
1963 |
assertTrue(t1.isPackageMemberTypeDeclaration() == false); |
2070 |
assertTrue(t1.isPackageMemberTypeDeclaration() == false); |
Lines 4357-4362
Link Here
|
4357 |
VariableDeclarationExpression variableDeclarationExpression = target.newVariableDeclarationExpression(variableDeclarationFragment3); |
4464 |
VariableDeclarationExpression variableDeclarationExpression = target.newVariableDeclarationExpression(variableDeclarationFragment3); |
4358 |
variableDeclarationExpression.setSourceRange(430, 5); |
4465 |
variableDeclarationExpression.setSourceRange(430, 5); |
4359 |
z.add(variableDeclarationExpression); |
4466 |
z.add(variableDeclarationExpression); |
|
|
4467 |
|
4468 |
// new for 2.2 |
4469 |
EnhancedForStatement foreachStatement = target.newEnhancedForStatement(); |
4470 |
foreachStatement.setSourceRange(500, 5); |
4471 |
b.statements().add(foreachStatement); |
4360 |
|
4472 |
|
4361 |
ASTNode clone = ASTNode.copySubtree(ast, cu); |
4473 |
ASTNode clone = ASTNode.copySubtree(ast, cu); |
4362 |
assertTrue(cu.subtreeMatch(new CheckPositionsMatcher(), clone)); |
4474 |
assertTrue(cu.subtreeMatch(new CheckPositionsMatcher(), clone)); |
Lines 4570-4575
Link Here
|
4570 |
public void unwrap() { |
4682 |
public void unwrap() { |
4571 |
Block s3 = (Block) x.getParent(); |
4683 |
Block s3 = (Block) x.getParent(); |
4572 |
s3.statements().remove(x); |
4684 |
s3.statements().remove(x); |
|
|
4685 |
} |
4686 |
}); |
4687 |
|
4688 |
genericPropertyTest(x, new Property("Body", true, Statement.class) { //$NON-NLS-1$ |
4689 |
public ASTNode sample(AST targetAst, boolean parented) { |
4690 |
Block result = targetAst.newBlock(); |
4691 |
if (parented) { |
4692 |
Block b2 = targetAst.newBlock(); |
4693 |
b2.statements().add(result); |
4694 |
} |
4695 |
return result; |
4696 |
} |
4697 |
public ASTNode wrap() { |
4698 |
// return a Statement that embeds x |
4699 |
Block s1 = ast.newBlock(); |
4700 |
s1.statements().add(x); |
4701 |
return s1; |
4702 |
} |
4703 |
public void unwrap() { |
4704 |
Block s2 = (Block) x.getParent(); |
4705 |
s2.statements().remove(x); |
4706 |
} |
4707 |
public ASTNode get() { |
4708 |
return x.getBody(); |
4709 |
} |
4710 |
public void set(ASTNode value) { |
4711 |
x.setBody((Statement) value); |
4712 |
} |
4713 |
}); |
4714 |
} |
4715 |
|
4716 |
public void testEnhancedForStatement() { |
4717 |
long previousCount = ast.modificationCount(); |
4718 |
final EnhancedForStatement x = ast.newEnhancedForStatement(); |
4719 |
assertTrue(ast.modificationCount() > previousCount); |
4720 |
previousCount = ast.modificationCount(); |
4721 |
assertTrue(x instanceof Statement); |
4722 |
assertTrue(x.getAST() == ast); |
4723 |
assertTrue(x.getParent() == null); |
4724 |
assertTrue(x.getType() != null); |
4725 |
assertTrue(x.getType().getParent() == x); |
4726 |
assertTrue(x.getName() != null); |
4727 |
assertTrue(x.getName().getParent() == x); |
4728 |
assertTrue(x.getName().isDeclaration() == true); |
4729 |
assertTrue(x.getExpression() != null); |
4730 |
assertTrue(x.getExpression().getParent() == x); |
4731 |
assertTrue(x.getBody().getParent() == x); |
4732 |
assertTrue(x.getBody() instanceof Block); |
4733 |
assertTrue(((Block) x.getBody()).statements().isEmpty()); |
4734 |
assertTrue(x.getLeadingComment() == null); |
4735 |
assertTrue(x.getNodeType() == ASTNode.ENHANCED_FOR_STATEMENT); |
4736 |
// make sure that reading did not change modification count |
4737 |
assertTrue(ast.modificationCount() == previousCount); |
4738 |
|
4739 |
tLeadingComment(x); |
4740 |
|
4741 |
genericPropertyTest(x, new Property("Type", true, Type.class) { //$NON-NLS-1$ |
4742 |
public ASTNode sample(AST targetAst, boolean parented) { |
4743 |
SimpleType result = targetAst.newSimpleType( |
4744 |
targetAst.newSimpleName("a")); //$NON-NLS-1$ |
4745 |
if (parented) { |
4746 |
targetAst.newArrayType(result); |
4747 |
} |
4748 |
return result; |
4749 |
} |
4750 |
public ASTNode get() { |
4751 |
return x.getType(); |
4752 |
} |
4753 |
public void set(ASTNode value) { |
4754 |
x.setType((Type) value); |
4755 |
} |
4756 |
}); |
4757 |
|
4758 |
genericPropertyTest(x, new Property("Name", true, SimpleName.class) { //$NON-NLS-1$ |
4759 |
public ASTNode sample(AST targetAst, boolean parented) { |
4760 |
SimpleName result = targetAst.newSimpleName("foo"); //$NON-NLS-1$ |
4761 |
if (parented) { |
4762 |
targetAst.newExpressionStatement(result); |
4763 |
} |
4764 |
return result; |
4765 |
} |
4766 |
public ASTNode get() { |
4767 |
return x.getName(); |
4768 |
} |
4769 |
public void set(ASTNode value) { |
4770 |
x.setName((SimpleName) value); |
4771 |
} |
4772 |
}); |
4773 |
|
4774 |
genericPropertyTest(x, new Property("Expression", true, Expression.class) { //$NON-NLS-1$ |
4775 |
public ASTNode sample(AST ast, boolean parented) { |
4776 |
Expression result = ast.newSimpleName("foo"); //$NON-NLS-1$ |
4777 |
if (parented) { |
4778 |
ast.newExpressionStatement(result); |
4779 |
} |
4780 |
return result; |
4781 |
} |
4782 |
public ASTNode wrap() { |
4783 |
// return Expression that embeds x |
4784 |
ClassInstanceCreation s1 = ast.newClassInstanceCreation(); |
4785 |
AnonymousClassDeclaration a1 = ast.newAnonymousClassDeclaration(); |
4786 |
s1.setAnonymousClassDeclaration(a1); |
4787 |
MethodDeclaration s2 = ast.newMethodDeclaration(); |
4788 |
a1.bodyDeclarations().add(s2); |
4789 |
Block s3 = ast.newBlock(); |
4790 |
s2.setBody(s3); |
4791 |
s3.statements().add(x); |
4792 |
return s1; |
4793 |
} |
4794 |
public void unwrap() { |
4795 |
Block s3 = (Block) x.getParent(); |
4796 |
s3.statements().remove(x); |
4797 |
} |
4798 |
public ASTNode get() { |
4799 |
return x.getExpression(); |
4800 |
} |
4801 |
public void set(ASTNode value) { |
4802 |
x.setExpression((Expression) value); |
4573 |
} |
4803 |
} |
4574 |
}); |
4804 |
}); |
4575 |
|
4805 |
|