/**
   * 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);
  }
Ejemplo n.º 2
0
 public boolean visit(ClassDeclaration s) throws Exception {
   Map<String, String> parameters = createInitialParameters(s);
   parameters.put("name", s.getName());
   xmlWriter.startTag("ClassDeclaration", parameters);
   return true;
 }
Ejemplo n.º 3
0
 @Test(result = {"m1()", "m2()", "m2(int)"})
 Collection<MethodDeclaration> getMethods() {
   return nested.getMethods();
 }
Ejemplo n.º 4
0
 @Test(result = {"null"})
 ClassType objectHasNoSuperclass() {
   return object.getSuperclass();
 }
Ejemplo n.º 5
0
 @Test(result = "java.io.Serializable")
 Collection<InterfaceType> getSuperinterfaces() {
   return nested.getSuperinterfaces();
 }
Ejemplo n.º 6
0
 // Check for default constructor.
 // 4997614: visitConstructionDeclaration reports info when there is no ctor
 @Test(result = {"NestedClass()"})
 Collection<ConstructorDeclaration> getConstructors2() {
   return nested.getConstructors();
 }
Ejemplo n.º 7
0
 @Test(result = "ClassDecl.NestedClass")
 String getQualifiedName2() {
   return nested.getQualifiedName();
 }
Ejemplo n.º 8
0
 @Test(result = "java.lang.Object")
 String getQualifiedName3() {
   return object.getQualifiedName();
 }
Ejemplo n.º 9
0
 @Test(result = "T")
 Collection<TypeParameterDeclaration> getFormalTypeParameters2() {
   return nested.getFormalTypeParameters();
 }
Ejemplo n.º 10
0
 @Test(result = "java.lang")
 PackageDeclaration getPackage2() {
   return object.getPackage();
 }
Ejemplo n.º 11
0
 @Test(result = "ClassDecl")
 TypeDeclaration getDeclaringType2() {
   return nested.getDeclaringType();
 }
Ejemplo n.º 12
0
 @Test(result = "NestedClass")
 String getSimpleName2() {
   return nested.getSimpleName();
 }
Ejemplo n.º 13
0
 // 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();
 }
Ejemplo n.º 14
0
 /**
  *
  *
  * <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());
    }
  }