Package org.eclipse.jdt.core.dom

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


            ICompilationUnit ic = a.getCompilationUnit();
            CompilationUnit cu = (CompilationUnit) ic;

            ASTParser astParser = ASTParser.newParser(AST.JLS3);
            astParser.setSource(cu.getContents());
            ASTNode node = astParser
                .createAST(new NullProgressMonitor());

            ASTNode aNode = a
                .findNode((org.eclipse.jdt.core.dom.CompilationUnit) node);
            if (aNode instanceof NormalAnnotation) {
              NormalAnnotation na = (NormalAnnotation) aNode;
              Expression exp = getAnnotationElement(na, "members");
              parseAnnotationListElement(elems, annotationName,
                  nameProp, colProp, exp);
            }
          }
        }
      } catch (JavaModelException e) {
        e.printStackTrace();
      }
    } else {
      try {
        ias = f.getAnnotations();
        String annotationSetName = "AttributeOverrides";
        String annotationName = "AttributeOverride";
        String nameProp = "name";
        String colProp = "column";

        for (IAnnotation ia : ias) {
          if (ia.getElementName().equals(annotationSetName)) {
            if (ia instanceof Annotation) {
              Annotation a = (Annotation) ia;

              ICompilationUnit ic = a.getCompilationUnit();
              CompilationUnit cu = (CompilationUnit) ic;

              ASTParser astParser = ASTParser.newParser(AST.JLS3);
              astParser.setSource(cu.getContents());
              ASTNode node = astParser
                  .createAST(new NullProgressMonitor());

              ASTNode aNode = a
                  .findNode((org.eclipse.jdt.core.dom.CompilationUnit) node);

              if (aNode instanceof SingleMemberAnnotation) {
                SingleMemberAnnotation sma = (SingleMemberAnnotation) aNode;
                Expression val = sma.getValue();
                parseAnnotationListElement(elems,
                    annotationName, nameProp, colProp, val);
              }
            }
          } else if (ia.getElementName().equals(annotationName)) {
            Annotation a = (Annotation) ia;

            ICompilationUnit ic = a.getCompilationUnit();
            CompilationUnit cu = (CompilationUnit) ic;

            ASTParser astParser = ASTParser.newParser(AST.JLS3);
            astParser.setSource(cu.getContents());
            ASTNode node = astParser
                .createAST(new NullProgressMonitor());

            ASTNode aNode = a
                .findNode((org.eclipse.jdt.core.dom.CompilationUnit) node);
            if (aNode instanceof NormalAnnotation) {
              parseAnnotationElement(elems, annotationName,
                  nameProp, colProp, aNode);
            }
View Full Code Here


            if (list != null) {
                Iterator<ASTNode> nodesIter = list.iterator();

                while (nodesIter.hasNext()) {
                    ASTNode node = nodesIter.next();

                    if (node instanceof ClassInstanceCreation) {
                        _refactor((ClassInstanceCreation) node, state);
                    }
View Full Code Here

        _output(_indent);
        _output("/** ");
        _output(_indent);

        for (Iterator it = node.tags().iterator(); it.hasNext();) {
            ASTNode e = (ASTNode) it.next();
            e.accept(this);
        }

        _output("\n");
        _output(_indent);
        _output(" */\n");
 
View Full Code Here

        }

        boolean previousRequiresNewLine = false;

        for (Iterator it = node.fragments().iterator(); it.hasNext();) {
            ASTNode e = (ASTNode) it.next();

            // assume text elements include necessary leading and trailing
            // whitespace but Name, MemberRef, MethodRef, and nested
            // TagElement do not include white space
            boolean currentIncludesWhiteSpace = (e instanceof TextElement);

            if (previousRequiresNewLine && currentIncludesWhiteSpace) {
                _output("\n");
                _output(_indent);
                _output(" * ");
            }

            previousRequiresNewLine = currentIncludesWhiteSpace;

            // add space if required to separate
            if (previousRequiresWhiteSpace && !currentIncludesWhiteSpace) {
                _output(" ");
            }

            e.accept(this);
            previousRequiresWhiteSpace = !currentIncludesWhiteSpace
                    && !(e instanceof TagElement);
        }

        if (node.isNested()) {
View Full Code Here

     * @param ext the list of modifier and annotation nodes
     * (element type: <code>IExtendedModifiers</code>)
     */
    private void _outputModifiers(List ext) {
        for (Iterator it = ext.iterator(); it.hasNext();) {
            ASTNode p = (ASTNode) it.next();
            p.accept(this);
            _output(" ");
        }
    }
View Full Code Here

    /** Remove an AST node from the its parent.
     *
     *  @param node The node to be removed.
     */
    public static void removeNode(ASTNode node) {
        ASTNode parent = node.getParent();
        StructuralPropertyDescriptor location = node.getLocationInParent();

        if (location.isChildProperty()) {
            parent.setStructuralProperty(location, null);
        } else {
            List<ASTNode> properties = (List<ASTNode>) parent
                    .getStructuralProperty(location);
            int position = properties.indexOf(node);
            properties.remove(position);
        }
    }
View Full Code Here

     *
     *  @param node The node to be replace.
     *  @param newNode The new node.
     */
    public static void replaceNode(ASTNode node, ASTNode newNode) {
        ASTNode parent = node.getParent();
        StructuralPropertyDescriptor location = node.getLocationInParent();

        if (location.isChildProperty()) {
            parent.setStructuralProperty(location, newNode);
        } else {
            List<ASTNode> properties = (List<ASTNode>) parent
                    .getStructuralProperty(location);
            int position = properties.indexOf(node);
            properties.set(position, newNode);
        }
    }
View Full Code Here

     *
     *  @param node The node to be visited.
     */
    public void endVisit(SimpleName node) {
        if (_state.getCurrentClass() != null) {
            ASTNode parent = node.getParent();
            Type owner = null;
            boolean handle = true;

            // Do not type check some simple names.
            if (parent instanceof QualifiedName) {
                handle = false;
            } else if (parent instanceof TypeDeclaration) {
                TypeDeclaration type = (TypeDeclaration) parent;

                if (type.getName() == node) {
                    handle = false;
                }
            } else if (parent instanceof BodyDeclaration) {
                handle = false;
            } else if (parent instanceof BreakStatement
                    && (((BreakStatement) parent).getLabel() == node)) {
                handle = false;
            } else if (parent instanceof SimpleType
                    && parent.getParent() instanceof ClassInstanceCreation) {
                Expression expression = ((ClassInstanceCreation) parent
                        .getParent()).getExpression();

                if (expression != null) {
                    owner = Type.getType(expression);
                }
View Full Code Here

     *
     *  @param node The node to be visited.
     */
    public void endVisit(VariableDeclarationFragment node) {
        Type type = null;
        ASTNode parent = node.getParent();

        if (parent instanceof VariableDeclarationStatement) {
            type = Type.getType(((VariableDeclarationStatement) parent)
                    .getType());
        } else if (parent instanceof FieldDeclaration) {
View Full Code Here

                    RehandleDeclarationRecord record = recordsIter.next();
                    Iterator<ASTNode> extendedIter = record
                            ._getExtendedDeclarations().iterator();

                    while (extendedIter.hasNext()) {
                        ASTNode declaration = extendedIter.next();

                        if (declaration != null) {
                            removeNode(declaration);
                        }
                    }

                    Iterator<ASTNode> fixedIter = record
                            ._getFixedDeclarations().iterator();

                    while (fixedIter.hasNext()) {
                        ASTNode declaration = fixedIter.next();

                        if (declaration != null) {
                            record._getBodyDeclarations().add(declaration);
                        }
                    }
View Full Code Here

TOP

Related Classes of org.eclipse.jdt.core.dom.ASTNode

Copyright © 2018 www.massapicom. 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.