Examples of AbstractTypeDeclaration


Examples of org.aspectj.org.eclipse.jdt.core.dom.AbstractTypeDeclaration

  private ASTRewrite sortCompilationUnit(org.aspectj.org.eclipse.jdt.core.dom.CompilationUnit ast, final TextEditGroup group) {
    ast.accept(new ASTVisitor() {
      public boolean visit(org.aspectj.org.eclipse.jdt.core.dom.CompilationUnit compilationUnit) {
        List types = compilationUnit.types();
        for (Iterator iter = types.iterator(); iter.hasNext();) {
          AbstractTypeDeclaration typeDeclaration = (AbstractTypeDeclaration) iter.next();
          typeDeclaration.setProperty(CompilationUnitSorter.RELATIVE_ORDER, new Integer(typeDeclaration.getStartPosition()));
          compilationUnit.setProperty(CONTAINS_MALFORMED_NODES, Boolean.valueOf(isMalformed(typeDeclaration)));
        }
        return true;
      }
      public boolean visit(AnnotationTypeDeclaration annotationTypeDeclaration) {
        List bodyDeclarations = annotationTypeDeclaration.bodyDeclarations();
        for (Iterator iter = bodyDeclarations.iterator(); iter.hasNext();) {
          BodyDeclaration bodyDeclaration = (BodyDeclaration) iter.next();
          bodyDeclaration.setProperty(CompilationUnitSorter.RELATIVE_ORDER, new Integer(bodyDeclaration.getStartPosition()));
          annotationTypeDeclaration.setProperty(CONTAINS_MALFORMED_NODES, Boolean.valueOf(isMalformed(bodyDeclaration)));
        }
        return true;
      }

      public boolean visit(AnonymousClassDeclaration anonymousClassDeclaration) {
        List bodyDeclarations = anonymousClassDeclaration.bodyDeclarations();
        for (Iterator iter = bodyDeclarations.iterator(); iter.hasNext();) {
          BodyDeclaration bodyDeclaration = (BodyDeclaration) iter.next();
          bodyDeclaration.setProperty(CompilationUnitSorter.RELATIVE_ORDER, new Integer(bodyDeclaration.getStartPosition()));
          anonymousClassDeclaration.setProperty(CONTAINS_MALFORMED_NODES, Boolean.valueOf(isMalformed(bodyDeclaration)));
        }
        return true;
      }
     
      public boolean visit(TypeDeclaration typeDeclaration) {
        List bodyDeclarations = typeDeclaration.bodyDeclarations();
        for (Iterator iter = bodyDeclarations.iterator(); iter.hasNext();) {
          BodyDeclaration bodyDeclaration = (BodyDeclaration) iter.next();
          bodyDeclaration.setProperty(CompilationUnitSorter.RELATIVE_ORDER, new Integer(bodyDeclaration.getStartPosition()));
          typeDeclaration.setProperty(CONTAINS_MALFORMED_NODES, Boolean.valueOf(isMalformed(bodyDeclaration)));
        }
        return true;
      }

      public boolean visit(EnumDeclaration enumDeclaration) {
        List bodyDeclarations = enumDeclaration.bodyDeclarations();
        for (Iterator iter = bodyDeclarations.iterator(); iter.hasNext();) {
          BodyDeclaration bodyDeclaration = (BodyDeclaration) iter.next();
          bodyDeclaration.setProperty(CompilationUnitSorter.RELATIVE_ORDER, new Integer(bodyDeclaration.getStartPosition()));
          enumDeclaration.setProperty(CONTAINS_MALFORMED_NODES, Boolean.valueOf(isMalformed(bodyDeclaration)));
        }
        List enumConstants = enumDeclaration.enumConstants();
        for (Iterator iter = enumConstants.iterator(); iter.hasNext();) {
          EnumConstantDeclaration enumConstantDeclaration = (EnumConstantDeclaration) iter.next();
          enumConstantDeclaration.setProperty(CompilationUnitSorter.RELATIVE_ORDER, new Integer(enumConstantDeclaration.getStartPosition()));
          enumDeclaration.setProperty(CONTAINS_MALFORMED_NODES, Boolean.valueOf(isMalformed(enumConstantDeclaration)));
        }       
        return true;
      }
    });
   
    final ASTRewrite rewriter= ASTRewrite.create(ast.getAST());
    final boolean[] hasChanges= new boolean[] {false};
   
    ast.accept(new ASTVisitor() {
   
      private void sortElements(List elements, ListRewrite listRewrite) {
        if (elements.size() == 0)
          return;
       
        final List myCopy = new ArrayList();
        myCopy.addAll(elements);
        Collections.sort(myCopy, SortElementsOperation.this.comparator);
       
        for (int i = 0; i < elements.size(); i++) {
          ASTNode oldNode= (ASTNode) elements.get(i);
          ASTNode newNode= (ASTNode) myCopy.get(i);
          if (oldNode != newNode) {
            listRewrite.replace(oldNode, rewriter.createMoveTarget(newNode), group);
            hasChanges[0]= true;
          }
        }
      }

      public boolean visit(org.aspectj.org.eclipse.jdt.core.dom.CompilationUnit compilationUnit) {
        if (checkMalformedNodes(compilationUnit)) {
          return true; // abort sorting of current element
        }
       
        sortElements(compilationUnit.types(), rewriter.getListRewrite(compilationUnit, org.aspectj.org.eclipse.jdt.core.dom.CompilationUnit.TYPES_PROPERTY));
        return true;
      }

      public boolean visit(AnnotationTypeDeclaration annotationTypeDeclaration) {
        if (checkMalformedNodes(annotationTypeDeclaration)) {
          return true; // abort sorting of current element
        }
       
        sortElements(annotationTypeDeclaration.bodyDeclarations(), rewriter.getListRewrite(annotationTypeDeclaration, AnnotationTypeDeclaration.BODY_DECLARATIONS_PROPERTY));
        return true;
      }

      public boolean visit(AnonymousClassDeclaration anonymousClassDeclaration) {
        if (checkMalformedNodes(anonymousClassDeclaration)) {
          return true; // abort sorting of current element
        }
       
        sortElements(anonymousClassDeclaration.bodyDeclarations(), rewriter.getListRewrite(anonymousClassDeclaration, AnonymousClassDeclaration.BODY_DECLARATIONS_PROPERTY))
        return true;
      }
     
      public boolean visit(TypeDeclaration typeDeclaration) {
        if (checkMalformedNodes(typeDeclaration)) {
          return true; // abort sorting of current element
        }
       
        sortElements(typeDeclaration.bodyDeclarations(), rewriter.getListRewrite(typeDeclaration, TypeDeclaration.BODY_DECLARATIONS_PROPERTY));
        return true;
      }

      public boolean visit(EnumDeclaration enumDeclaration) {
        if (checkMalformedNodes(enumDeclaration)) {
View Full Code Here

Examples of org.aspectj.org.eclipse.jdt.core.dom.AbstractTypeDeclaration

        // update main type name
        IType[] types = cu.getTypes();
        for (int i = 0, max = types.length; i < max; i++) {
          IType currentType = types[i];
          if (currentType.getElementName().equals(oldTypeName)) {
            AbstractTypeDeclaration typeNode = (AbstractTypeDeclaration) ((JavaElement) currentType).findNode(astCU);
            if (typeNode != null) {
              // rename type
              rewriter.replace(typeNode.getName(), ast.newSimpleName(newTypeName), null);
              // rename constructors
              Iterator bodyDeclarations = typeNode.bodyDeclarations().iterator();
              while (bodyDeclarations.hasNext()) {
                Object bodyDeclaration = bodyDeclarations.next();
                if (bodyDeclaration instanceof MethodDeclaration) {
                  MethodDeclaration methodDeclaration = (MethodDeclaration) bodyDeclaration;
                  if (methodDeclaration.isConstructor()) {
View Full Code Here

Examples of org.aspectj.org.eclipse.jdt.core.dom.AbstractTypeDeclaration

}
private String getASTNodeName() {
  return ((AbstractTypeDeclaration) this.createdNode).getName().getIdentifier();
}
protected SimpleName rename(ASTNode node, SimpleName newName) {
  AbstractTypeDeclaration type = (AbstractTypeDeclaration) node;
  SimpleName oldName = type.getName();
  type.setName(newName);
  return oldName;
}
View Full Code Here

Examples of org.eclipse.jdt.core.dom.AbstractTypeDeclaration

     * @param cname class name
     * @param isenum Java 5 enum class flag
     * @return type declaration
     */
    private AbstractTypeDeclaration createClass(String cname, boolean isenum) {
        AbstractTypeDeclaration abstype;
        if (isenum) {
            abstype = m_ast.newEnumDeclaration();
        } else {
            TypeDeclaration type = m_ast.newTypeDeclaration();
            type.setInterface(false);
            abstype = type;
        }
        abstype.modifiers().add(m_ast.newModifier(Modifier.ModifierKeyword.PUBLIC_KEYWORD));
        abstype.setName(m_ast.newSimpleName(cname));
        return abstype;
    }
View Full Code Here

Examples of org.eclipse.jdt.core.dom.AbstractTypeDeclaration

     * @param cname class name
     * @param isenum Java 5 enum class flag
     * @return builder
     */
    public ClassBuilder newMainClass(String cname, boolean isenum) {
        AbstractTypeDeclaration decl = createClass(cname, isenum);
        m_compilationUnit.types().add(decl);
        ClassBuilder builder = new ClassBuilder(decl, this);
        m_classes.add(builder);
        return builder;
    }
View Full Code Here

Examples of org.eclipse.jdt.core.dom.AbstractTypeDeclaration

     * @param outer containing class builder
     * @param isenum Java 5 enum class flag
     * @return builder
     */
    public ClassBuilder newInnerClass(String cname, ClassBuilder outer, boolean isenum) {
        AbstractTypeDeclaration decl = createClass(cname, isenum);
        decl.modifiers().add(m_ast.newModifier(Modifier.ModifierKeyword.STATIC_KEYWORD));
//        type.superInterfaceTypes().add(createType("java.io.Serializable"));
        return new ClassBuilder(decl, outer);
    }
View Full Code Here

Examples of org.eclipse.jdt.core.dom.AbstractTypeDeclaration

                String typeContent = constructTypeStub(parentCU, imports, lineDelimiter);

                int index = cuContent.lastIndexOf(simpleTypeStub);
                if (index == -1) {
                    AbstractTypeDeclaration typeNode = (AbstractTypeDeclaration) astRoot.types().get(0);
                    int start = ((ASTNode) typeNode.modifiers().get(0)).getStartPosition();
                    int end = typeNode.getStartPosition() + typeNode.getLength();
                    buffer.replace(start, end - start, typeContent);
                } else {
                    buffer.replace(index, simpleTypeStub.length(), typeContent);
                }
View Full Code Here

Examples of org.eclipse.jdt.core.dom.AbstractTypeDeclaration

                String typeContent = constructTypeStub(parentCU, imports, lineDelimiter);

                int index = cuContent.lastIndexOf(simpleTypeStub);
                if (index == -1) {
                    AbstractTypeDeclaration typeNode = (AbstractTypeDeclaration) astRoot.types().get(0);
                    int start = ((ASTNode) typeNode.modifiers().get(0)).getStartPosition();
                    int end = typeNode.getStartPosition() + typeNode.getLength();
                    buffer.replace(start, end - start, typeContent);
                } else {
                    buffer.replace(index, simpleTypeStub.length(), typeContent);
                }
View Full Code Here

Examples of org.eclipse.jdt.core.dom.AbstractTypeDeclaration

      imports.add(visitChild(d));
    }
 
    IValueList typeDeclarations = new IValueList(values);
    for (Iterator it = node.types().iterator(); it.hasNext();) {
      AbstractTypeDeclaration d = (AbstractTypeDeclaration) it.next();
      typeDeclarations.add(visitChild(d));
    }
   
    ownValue = constructDeclarationNode("compilationUnit", packageOfUnit, imports.asList(), typeDeclarations.asList());   
    return false;
View Full Code Here

Examples of org.eclipse.jdt.core.dom.AbstractTypeDeclaration

    for (Iterator it = node.imports().iterator(); it.hasNext(); ) {
      ImportDeclaration d = (ImportDeclaration) it.next();
      d.accept(this);
    }
    for (Iterator it = node.types().iterator(); it.hasNext(); ) {
      AbstractTypeDeclaration d = (AbstractTypeDeclaration) it.next();
      d.accept(this);
    }
    return false;
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.