/** * Visits a class declaration. * * @param d the declaration to visit */ public void visitClassDeclaration(ClassDeclaration d) { d.accept(pre); SortedSet<Declaration> decls = new TreeSet<Declaration>(SourceOrderDeclScanner.comparator); for (TypeParameterDeclaration tpDecl : d.getFormalTypeParameters()) { decls.add(tpDecl); } for (FieldDeclaration fieldDecl : d.getFields()) { decls.add(fieldDecl); } for (MethodDeclaration methodDecl : d.getMethods()) { decls.add(methodDecl); } for (TypeDeclaration typeDecl : d.getNestedTypes()) { decls.add(typeDecl); } for (ConstructorDeclaration ctorDecl : d.getConstructors()) { decls.add(ctorDecl); } for (Declaration decl : decls) decl.accept(this); d.accept(post); }
public boolean visit(ClassDeclaration s) throws Exception { Map<String, String> parameters = createInitialParameters(s); parameters.put("name", s.getName()); xmlWriter.startTag("ClassDeclaration", parameters); return true; }
@Test(result = {"m1()", "m2()", "m2(int)"}) Collection<MethodDeclaration> getMethods() { return nested.getMethods(); }
@Test(result = {"null"}) ClassType objectHasNoSuperclass() { return object.getSuperclass(); }
@Test(result = "java.io.Serializable") Collection<InterfaceType> getSuperinterfaces() { return nested.getSuperinterfaces(); }
// Check for default constructor. // 4997614: visitConstructionDeclaration reports info when there is no ctor @Test(result = {"NestedClass()"}) Collection<ConstructorDeclaration> getConstructors2() { return nested.getConstructors(); }
@Test(result = "ClassDecl.NestedClass") String getQualifiedName2() { return nested.getQualifiedName(); }
@Test(result = "java.lang.Object") String getQualifiedName3() { return object.getQualifiedName(); }
@Test(result = "T") Collection<TypeParameterDeclaration> getFormalTypeParameters2() { return nested.getFormalTypeParameters(); }
@Test(result = "java.lang") PackageDeclaration getPackage2() { return object.getPackage(); }
@Test(result = "ClassDecl") TypeDeclaration getDeclaringType2() { return nested.getDeclaringType(); }
@Test(result = "NestedClass") String getSimpleName2() { return nested.getSimpleName(); }
// Check that static nested class has "static" modifier, even though // the VM doesn't set that bit. @Test(result = {"private", "static", "strictfp"}) Collection<Modifier> getModifiers2() { return nested.getModifiers(); }
/** * * * <pre> * ClassDeclaration : class BindingIdentifier ClassTail * ClassDeclaration : class ClassTail * </pre> */ @Override public List<Name> visit(ClassDeclaration node, List<Name> names) { names.add(node.getName()); return names; }
@Test public void testStatements() { String expected1 = literal( "[B ClassDeclaration X (20-80)]", " [I Modifiers (20-20)]", " typeName: [I Identifier X (20-20)]", " PROPERTY: name = X", " [B NormalTypeBody (20-80)]", " [B InstanceInitializer (20-80)]", " [B Block (20-80)]", " [B Synchronized (60-80)]", " lock: [I This (60-80)]", " [B Block (60-80)]"); ClassDeclaration classDecl = (ClassDeclaration) Template.parseMember("class X {{foo:;}}"); { Template<ClassDeclaration> template = Template.of(classDecl); Statement x = new Synchronized().astBody(new Block()).astLock(new This()); Ast.setAllPositions(x, new Position(60, 80)); template.setStartPosition(20); template.replaceStatement("foo", x); ClassDeclaration finish = template.finish(); StructureFormatter sf = StructureFormatter.formatterWithPositions(); finish.accept(new SourcePrinter(sf)); assertEquals(expected1, sf.finish()); } { Template<ClassDeclaration> template = Template.of(classDecl); Statement x = new Synchronized().astBody(new Block()).astLock(new This()); template.setStartPosition(20); template.replaceStatement("foo", x, new Position(60, 80)); ClassDeclaration finish = template.finish(); StructureFormatter sf = StructureFormatter.formatterWithPositions(); finish.accept(new SourcePrinter(sf)); assertEquals(expected1, sf.finish()); } String expected2 = literal( "[B ClassDeclaration X (20-200)]", " [I Modifiers (20-20)]", " typeName: [I Identifier X (20-20)]", " PROPERTY: name = X", " [B NormalTypeBody (20-200)]", " [B InstanceInitializer (20-200)]", " [B Block (20-200)]", " [B Synchronized (40-50)]", " lock: [I This (40-50)]", " [B Block (40-50)]", " [B While (100-200)]", " condition: [I BooleanLiteral (100-200)]", " PROPERTY: value = true", " [B EmptyStatement (100-200)]"); { Template<ClassDeclaration> template = Template.of(classDecl); Statement x = new Synchronized().astBody(new Block()).astLock(new This()); Statement y = new While() .astCondition(new BooleanLiteral().astValue(true)) .astStatement(new EmptyStatement()); Ast.setAllPositions(x, new Position(40, 50)); Ast.setAllPositions(y, new Position(100, 200)); template.setStartPosition(20); template.replaceStatement("foo", Arrays.asList(x, y)); ClassDeclaration finish = template.finish(); StructureFormatter sf = StructureFormatter.formatterWithPositions(); finish.accept(new SourcePrinter(sf)); assertEquals(expected2, sf.finish()); } }