Example usage for org.eclipse.jdt.core.dom ASTNode structuralPropertiesForType

List of usage examples for org.eclipse.jdt.core.dom ASTNode structuralPropertiesForType

Introduction

In this page you can find the example usage for org.eclipse.jdt.core.dom ASTNode structuralPropertiesForType.

Prototype

public final List structuralPropertiesForType() 

Source Link

Document

Returns a list of structural property descriptors for nodes of the same type as this node.

Usage

From source file:ast.AstNodeLocationMapper.java

License:Apache License

private static ASTNode findNearestPreviousChild(ASTNode node, int position) {
    int childAt = -1;
    ASTNode childNode = null;/*from  w  w  w. ja  va2  s  .co m*/
    for (Object o : node.structuralPropertiesForType()) {
        if (o instanceof ChildPropertyDescriptor) {
            ASTNode n = (ASTNode) node.getStructuralProperty((StructuralPropertyDescriptor) o);
            if (n != null) {
                int start = n.getStartPosition();
                if (start >= 0 && childAt < start && start <= position) {
                    childAt = start;
                    childNode = n;
                }
            }
        } else if (o instanceof ChildListPropertyDescriptor) {
            List<?> list = (List<?>) node.getStructuralProperty((StructuralPropertyDescriptor) o);
            for (Object e : list) {
                ASTNode n = (ASTNode) e;
                assert n != null;
                int start = n.getStartPosition();
                if (start >= 0 && childAt < start && start <= position) {
                    childAt = start;
                    childNode = n;
                }
            }
        }
    }
    return childNode;
}

From source file:astview.ASTViewContentProvider.java

License:Open Source License

private Object[] getNodeChildren(ASTNode node) {
    ArrayList<Object> res = new ArrayList<>();

    if (node instanceof Expression) {
        Expression expression = (Expression) node;
        ITypeBinding expressionTypeBinding = expression.resolveTypeBinding();
        res.add(createExpressionTypeBinding(node, expressionTypeBinding));

        // expressions:
        if (expression instanceof Name) {
            IBinding binding = ((Name) expression).resolveBinding();
            if (binding != expressionTypeBinding)
                res.add(createBinding(expression, binding));
        } else if (expression instanceof MethodInvocation) {
            MethodInvocation methodInvocation = (MethodInvocation) expression;
            IMethodBinding binding = methodInvocation.resolveMethodBinding();
            res.add(createBinding(expression, binding));
            String inferred = String.valueOf(methodInvocation.isResolvedTypeInferredFromExpectedType());
            res.add(new GeneralAttribute(expression, "ResolvedTypeInferredFromExpectedType", inferred)); //$NON-NLS-1$
        } else if (expression instanceof SuperMethodInvocation) {
            SuperMethodInvocation superMethodInvocation = (SuperMethodInvocation) expression;
            IMethodBinding binding = superMethodInvocation.resolveMethodBinding();
            res.add(createBinding(expression, binding));
            String inferred = String.valueOf(superMethodInvocation.isResolvedTypeInferredFromExpectedType());
            res.add(new GeneralAttribute(expression, "ResolvedTypeInferredFromExpectedType", inferred)); //$NON-NLS-1$
        } else if (expression instanceof ClassInstanceCreation) {
            ClassInstanceCreation classInstanceCreation = (ClassInstanceCreation) expression;
            IMethodBinding binding = classInstanceCreation.resolveConstructorBinding();
            res.add(createBinding(expression, binding));
            String inferred = String.valueOf(classInstanceCreation.isResolvedTypeInferredFromExpectedType());
            res.add(new GeneralAttribute(expression, "ResolvedTypeInferredFromExpectedType", inferred)); //$NON-NLS-1$
        } else if (expression instanceof FieldAccess) {
            IVariableBinding binding = ((FieldAccess) expression).resolveFieldBinding();
            res.add(createBinding(expression, binding));
        } else if (expression instanceof SuperFieldAccess) {
            IVariableBinding binding = ((SuperFieldAccess) expression).resolveFieldBinding();
            res.add(createBinding(expression, binding));
        } else if (expression instanceof Annotation) {
            IAnnotationBinding binding = ((Annotation) expression).resolveAnnotationBinding();
            res.add(createBinding(expression, binding));
        } else if (expression instanceof LambdaExpression) {
            ASTAttribute bindingAttribute;
            try {
                IMethodBinding binding = ((LambdaExpression) expression).resolveMethodBinding();
                bindingAttribute = createBinding(expression, binding);
            } catch (RuntimeException e) {
                bindingAttribute = new Error(res, ">binding: Error: " + e.getMessage(), e);
            }//from  w  w  w .  j  a v  a  2s. c  o  m
            res.add(bindingAttribute);
        } else if (expression instanceof MethodReference) {
            IMethodBinding binding = ((MethodReference) expression).resolveMethodBinding();
            res.add(createBinding(expression, binding));
        }
        // Expression attributes:
        res.add(new GeneralAttribute(expression,
                "Boxing: " + expression.resolveBoxing() + "; Unboxing: " + expression.resolveUnboxing())); //$NON-NLS-1$ //$NON-NLS-2$
        res.add(new GeneralAttribute(expression, "ConstantExpressionValue", //$NON-NLS-1$
                expression.resolveConstantExpressionValue()));

        // references:
    } else if (node instanceof ConstructorInvocation) {
        IMethodBinding binding = ((ConstructorInvocation) node).resolveConstructorBinding();
        res.add(createBinding(node, binding));
    } else if (node instanceof SuperConstructorInvocation) {
        IMethodBinding binding = ((SuperConstructorInvocation) node).resolveConstructorBinding();
        res.add(createBinding(node, binding));
    } else if (node instanceof MethodRef) {
        IBinding binding = ((MethodRef) node).resolveBinding();
        res.add(createBinding(node, binding));
    } else if (node instanceof MemberRef) {
        IBinding binding = ((MemberRef) node).resolveBinding();
        res.add(createBinding(node, binding));
    } else if (node instanceof Type) {
        IBinding binding = ((Type) node).resolveBinding();
        res.add(createBinding(node, binding));

        // declarations:
    } else if (node instanceof AbstractTypeDeclaration) {
        IBinding binding = ((AbstractTypeDeclaration) node).resolveBinding();
        res.add(createBinding(node, binding));
    } else if (node instanceof AnnotationTypeMemberDeclaration) {
        IBinding binding = ((AnnotationTypeMemberDeclaration) node).resolveBinding();
        res.add(createBinding(node, binding));
    } else if (node instanceof EnumConstantDeclaration) {
        IBinding binding = ((EnumConstantDeclaration) node).resolveVariable();
        res.add(createBinding(node, binding));
        IBinding binding2 = ((EnumConstantDeclaration) node).resolveConstructorBinding();
        res.add(createBinding(node, binding2));
    } else if (node instanceof MethodDeclaration) {
        IBinding binding = ((MethodDeclaration) node).resolveBinding();
        res.add(createBinding(node, binding));
    } else if (node instanceof VariableDeclaration) {
        IBinding binding = ((VariableDeclaration) node).resolveBinding();
        res.add(createBinding(node, binding));
    } else if (node instanceof AnonymousClassDeclaration) {
        IBinding binding = ((AnonymousClassDeclaration) node).resolveBinding();
        res.add(createBinding(node, binding));
    } else if (node instanceof ImportDeclaration) {
        IBinding binding = ((ImportDeclaration) node).resolveBinding();
        res.add(createBinding(node, binding));
    } else if (node instanceof PackageDeclaration) {
        IBinding binding = ((PackageDeclaration) node).resolveBinding();
        res.add(createBinding(node, binding));
    } else if (node instanceof TypeParameter) {
        IBinding binding = ((TypeParameter) node).resolveBinding();
        res.add(createBinding(node, binding));
    } else if (node instanceof MemberValuePair) {
        IBinding binding = ((MemberValuePair) node).resolveMemberValuePairBinding();
        res.add(createBinding(node, binding));
    }

    @SuppressWarnings("unchecked")
    List<StructuralPropertyDescriptor> list = node.structuralPropertiesForType();
    for (int i = 0; i < list.size(); i++) {
        StructuralPropertyDescriptor curr = list.get(i);
        res.add(new NodeProperty(node, curr));
    }

    return res.toArray();
}

From source file:changenodes.matching.BestLeafTreeMatcher.java

License:Apache License

@SuppressWarnings("unchecked")
private void markMatchedNode(ASTNode left, ASTNode right) {
    if (left.getNodeType() != right.getNodeType()) {
        return;/*  w ww .  j a  va  2 s.c o  m*/
    }
    if (!(leftMatching.containsKey(left) || rightMatching.containsKey(right))) {
        leftMatching.put(left, right);
        rightMatching.put(right, left);
        List<StructuralPropertyDescriptor> props = (List<StructuralPropertyDescriptor>) left
                .structuralPropertiesForType();
        for (StructuralPropertyDescriptor prop : props) {
            if (prop.isChildProperty()) {
                ASTNode newLeft, newRight;
                newLeft = (ASTNode) left.getStructuralProperty(prop);
                newRight = (ASTNode) right.getStructuralProperty(prop);
                if (newLeft != null && newRight != null) {
                    markMatchedNode(newLeft, newRight);
                }
            } else if (prop.isChildListProperty()) {
                List<ASTNode> lefts, rights;
                lefts = (List<ASTNode>) left.getStructuralProperty(prop);
                rights = (List<ASTNode>) right.getStructuralProperty(prop);
                int times = lefts.size();
                if (lefts.size() > rights.size()) {
                    times = rights.size();
                }
                Iterator<ASTNode> leftIt = lefts.iterator();
                Iterator<ASTNode> rightIt = rights.iterator();
                for (int i = 0; i < times; ++i) {
                    ASTNode rNode = rightIt.next();
                    ASTNode lNode = leftIt.next();
                    if (lNode != null && rNode != null) {
                        markMatchedNode(lNode, rNode);
                    }
                }
            }
            //we dont handle simple props as they point to objects
        }
    }
}

From source file:cideplus.ui.astview.ASTViewContentProvider.java

License:Open Source License

private Object[] getNodeChildren(ASTNode node) {
    ArrayList res = new ArrayList();

    /*if (node instanceof Expression) {
       Expression expression= (Expression) node;
       ITypeBinding expressionTypeBinding= expression.resolveTypeBinding();
       //res.add(createExpressionTypeBinding(node, expressionTypeBinding));
               /*from   w  ww  . j ava  2  s.c o  m*/
       // expressions:
       if (expression instanceof Name) {
    IBinding binding= ((Name) expression).resolveBinding();
    if (binding != expressionTypeBinding){
       //res.add(createBinding(expression, binding));
    }
       } else if (expression instanceof MethodInvocation) {
    MethodInvocation methodInvocation= (MethodInvocation) expression;
    IMethodBinding binding= methodInvocation.resolveMethodBinding();
    //res.add(createBinding(expression, binding));
    String inferred= String.valueOf(methodInvocation.isResolvedTypeInferredFromExpectedType());
    //res.add(new GeneralAttribute(expression, "ResolvedTypeInferredFromExpectedType", inferred)); //$NON-NLS-1$
       } else if (expression instanceof SuperMethodInvocation) {
    SuperMethodInvocation superMethodInvocation= (SuperMethodInvocation) expression;
    IMethodBinding binding= superMethodInvocation.resolveMethodBinding();
    //res.add(createBinding(expression, binding));
    String inferred= String.valueOf(superMethodInvocation.isResolvedTypeInferredFromExpectedType());
    //res.add(new GeneralAttribute(expression, "ResolvedTypeInferredFromExpectedType", inferred)); //$NON-NLS-1$
       } else if (expression instanceof ClassInstanceCreation) {
    IMethodBinding binding= ((ClassInstanceCreation) expression).resolveConstructorBinding();
    //res.add(createBinding(expression, binding));
       } else if (expression instanceof FieldAccess) {
    IVariableBinding binding= ((FieldAccess) expression).resolveFieldBinding();
    //res.add(createBinding(expression, binding));
       } else if (expression instanceof SuperFieldAccess) {
    IVariableBinding binding= ((SuperFieldAccess) expression).resolveFieldBinding();
    //res.add(createBinding(expression, binding));
       } else if (expression instanceof Annotation) {
    IAnnotationBinding binding= ((Annotation) expression).resolveAnnotationBinding();
    //res.add(createBinding(expression, binding));
       }
       // Expression attributes:
       //res.add(new GeneralAttribute(expression, "Boxing: " + expression.resolveBoxing() + "; Unboxing: " + expression.resolveUnboxing())); //$NON-NLS-1$ //$NON-NLS-2$
       //res.add(new GeneralAttribute(expression, "ConstantExpressionValue", expression.resolveConstantExpressionValue())); //$NON-NLS-1$
            
    // references:
    } else if (node instanceof ConstructorInvocation) {
       IMethodBinding binding= ((ConstructorInvocation) node).resolveConstructorBinding();
       //res.add(createBinding(node, binding));
    } else if (node instanceof SuperConstructorInvocation) {
       IMethodBinding binding= ((SuperConstructorInvocation) node).resolveConstructorBinding();
       //res.add(createBinding(node, binding));
    } else if (node instanceof MethodRef) {
       IBinding binding= ((MethodRef) node).resolveBinding();
       //res.add(createBinding(node, binding));
    } else if (node instanceof MemberRef) {
       IBinding binding= ((MemberRef) node).resolveBinding();
       //res.add(createBinding(node, binding));
    } else if (node instanceof Type) {
       IBinding binding= ((Type) node).resolveBinding();
       //res.add(createBinding(node, binding));
               
    // declarations:
    } else if (node instanceof AbstractTypeDeclaration) {
       IBinding binding= ((AbstractTypeDeclaration) node).resolveBinding();
       //res.add(createBinding(node, binding)); 
    } else if (node instanceof AnnotationTypeMemberDeclaration) {
       IBinding binding= ((AnnotationTypeMemberDeclaration) node).resolveBinding();
       //res.add(createBinding(node, binding));
    } else if (node instanceof EnumConstantDeclaration) {
       IBinding binding= ((EnumConstantDeclaration) node).resolveVariable();
       //res.add(createBinding(node, binding));
       IBinding binding2= ((EnumConstantDeclaration) node).resolveConstructorBinding();
       //res.add(createBinding(node, binding2));
    } else if (node instanceof MethodDeclaration) {
       IBinding binding= ((MethodDeclaration) node).resolveBinding();
       //res.add(createBinding(node, binding));
    } else if (node instanceof VariableDeclaration) {
       IBinding binding= ((VariableDeclaration) node).resolveBinding();
       //res.add(createBinding(node, binding));
    } else if (node instanceof AnonymousClassDeclaration) {
       IBinding binding= ((AnonymousClassDeclaration) node).resolveBinding();
       //res.add(createBinding(node, binding));
    } else if (node instanceof ImportDeclaration) {
       IBinding binding= ((ImportDeclaration) node).resolveBinding();
       //res.add(createBinding(node, binding));
       return new Object[0];//o import declaration
    } else if (node instanceof PackageDeclaration) {
       IBinding binding= ((PackageDeclaration) node).resolveBinding();
       //res.add(createBinding(node, binding));
       return new Object[0];//o package declaration no deve ter filhos
    } else if (node instanceof TypeParameter) {
       IBinding binding= ((TypeParameter) node).resolveBinding();
       //res.add(createBinding(node, binding));
    } else if (node instanceof MemberValuePair) {
       IBinding binding= ((MemberValuePair) node).resolveMemberValuePairBinding();
       //res.add(createBinding(node, binding));
    } else*/

    /*
    if(node instanceof Modifier){
       return new Object[0];
    } else if(node instanceof TextElement){
       return new Object[0];
    } else if(node instanceof SimpleName){
       return new Object[0];
    } else if(node instanceof SimpleType){
       return new Object[0];
    } else if(node instanceof StringLiteral){
       return new Object[0];
    } else if(node instanceof NumberLiteral){
       return new Object[0];
    } else if(node instanceof PrimitiveType){
       return new Object[0];
    } else if(node instanceof PackageDeclaration){
       return new Object[0];
    } else if(node instanceof ImportDeclaration){
       return new Object[0];
    } else if(node instanceof EnumConstantDeclaration){
       return new Object[0];
    }*/

    @SuppressWarnings("unchecked")
    List<Class<? extends ASTNode>> noChildNodes = Arrays.asList(Modifier.class, TextElement.class,
            SimpleName.class, SimpleType.class, StringLiteral.class, NumberLiteral.class, PrimitiveType.class,
            PackageDeclaration.class, ImportDeclaration.class, EnumConstantDeclaration.class);
    for (Class<? extends ASTNode> class1 : noChildNodes) {
        if (class1.isAssignableFrom(node.getClass())) {
            return new Object[0];
        }
    }

    //essas propriedades no tero um parent (o filho ocupar o lugar do parent)
    List<String> childrenProperties = Arrays.asList("TAGS", "FRAGMENTS", "STATEMENTS", "BODY", "PACKAGE",
            "IMPORTS", "TYPES");
    List list = node.structuralPropertiesForType();
    for (int i = 0; i < list.size(); i++) {
        StructuralPropertyDescriptor curr = (StructuralPropertyDescriptor) list.get(i);
        NodeProperty nodeProperty = new NodeProperty(node, curr);
        if (childrenProperties.contains(nodeProperty.getPropertyName())) {
            res.addAll(Arrays.asList(nodeProperty.getChildren()));
        } else {
            if (!(curr.isChildListProperty() && nodeProperty.getChildren().length == 0)
                    && !nodeProperty.getPropertyName().equals("INTERFACE")
                    && !(nodeProperty.getNode() == null)) {
                res.add(nodeProperty);
            }
        }
    }

    if (node instanceof CompilationUnit) {
        CompilationUnit root = (CompilationUnit) node;
        //res.add(new JavaElement(root, root.getJavaElement()));
        //res.add(new CommentsProperty(root));
        //res.add(new ProblemsProperty(root));
        //res.add(new SettingsProperty(root));
        //res.add(new WellKnownTypesProperty(root));
    }

    return res.toArray();
}

From source file:coloredide.astview.ASTViewContentProvider.java

License:Open Source License

private Object[] getNodeChildren(ASTNode node) {
    ArrayList res = new ArrayList();

    if (node instanceof Expression) {
        Expression expression = (Expression) node;
        ITypeBinding expressionTypeBinding = expression.resolveTypeBinding();
        res.add(createExpressionTypeBinding(node, expressionTypeBinding));

        // expressions:
        if (expression instanceof Name) {
            IBinding binding = ((Name) expression).resolveBinding();
            if (binding != expressionTypeBinding)
                res.add(createBinding(expression, binding));
        } else if (expression instanceof MethodInvocation) {
            IMethodBinding binding = ((MethodInvocation) expression).resolveMethodBinding();
            res.add(createBinding(expression, binding));
        } else if (expression instanceof SuperMethodInvocation) {
            IMethodBinding binding = ((SuperMethodInvocation) expression).resolveMethodBinding();
            res.add(createBinding(expression, binding));
        } else if (expression instanceof ClassInstanceCreation) {
            IMethodBinding binding = ((ClassInstanceCreation) expression).resolveConstructorBinding();
            res.add(createBinding(expression, binding));
        } else if (expression instanceof FieldAccess) {
            IVariableBinding binding = ((FieldAccess) expression).resolveFieldBinding();
            res.add(createBinding(expression, binding));
        } else if (expression instanceof SuperFieldAccess) {
            IVariableBinding binding = ((SuperFieldAccess) expression).resolveFieldBinding();
            res.add(createBinding(expression, binding));
        } else if (expression instanceof Annotation) {
            IAnnotationBinding binding = ((Annotation) expression).resolveAnnotationBinding();
            res.add(createBinding(expression, binding));
        }// w w w  .  j  a v  a  2 s.co  m
        // Expression attributes:
        res.add(new GeneralAttribute(expression,
                "Boxing: " + expression.resolveBoxing() + "; Unboxing: " + expression.resolveUnboxing())); //$NON-NLS-1$ //$NON-NLS-2$
        res.add(new GeneralAttribute(expression, "ConstantExpressionValue", //$NON-NLS-1$
                expression.resolveConstantExpressionValue()));

        // references:
    } else if (node instanceof ConstructorInvocation) {
        IMethodBinding binding = ((ConstructorInvocation) node).resolveConstructorBinding();
        res.add(createBinding(node, binding));
    } else if (node instanceof SuperConstructorInvocation) {
        IMethodBinding binding = ((SuperConstructorInvocation) node).resolveConstructorBinding();
        res.add(createBinding(node, binding));
    } else if (node instanceof MethodRef) {
        IBinding binding = ((MethodRef) node).resolveBinding();
        res.add(createBinding(node, binding));
    } else if (node instanceof MemberRef) {
        IBinding binding = ((MemberRef) node).resolveBinding();
        res.add(createBinding(node, binding));
    } else if (node instanceof Type) {
        IBinding binding = ((Type) node).resolveBinding();
        res.add(createBinding(node, binding));

        // declarations:
    } else if (node instanceof AbstractTypeDeclaration) {
        IBinding binding = ((AbstractTypeDeclaration) node).resolveBinding();
        res.add(createBinding(node, binding));
    } else if (node instanceof AnnotationTypeMemberDeclaration) {
        IBinding binding = ((AnnotationTypeMemberDeclaration) node).resolveBinding();
        res.add(createBinding(node, binding));
    } else if (node instanceof EnumConstantDeclaration) {
        IBinding binding = ((EnumConstantDeclaration) node).resolveVariable();
        res.add(createBinding(node, binding));
        IBinding binding2 = ((EnumConstantDeclaration) node).resolveConstructorBinding();
        res.add(createBinding(node, binding2));
    } else if (node instanceof MethodDeclaration) {
        IBinding binding = ((MethodDeclaration) node).resolveBinding();
        res.add(createBinding(node, binding));
    } else if (node instanceof VariableDeclaration) {
        IBinding binding = ((VariableDeclaration) node).resolveBinding();
        res.add(createBinding(node, binding));
    } else if (node instanceof AnonymousClassDeclaration) {
        IBinding binding = ((AnonymousClassDeclaration) node).resolveBinding();
        res.add(createBinding(node, binding));
    } else if (node instanceof ImportDeclaration) {
        IBinding binding = ((ImportDeclaration) node).resolveBinding();
        res.add(createBinding(node, binding));
    } else if (node instanceof PackageDeclaration) {
        IBinding binding = ((PackageDeclaration) node).resolveBinding();
        res.add(createBinding(node, binding));
    } else if (node instanceof TypeParameter) {
        IBinding binding = ((TypeParameter) node).resolveBinding();
        res.add(createBinding(node, binding));
    } else if (node instanceof MemberValuePair) {
        IBinding binding = ((MemberValuePair) node).resolveMemberValuePairBinding();
        res.add(createBinding(node, binding));
    }

    List list = node.structuralPropertiesForType();
    for (int i = 0; i < list.size(); i++) {
        StructuralPropertyDescriptor curr = (StructuralPropertyDescriptor) list.get(i);
        res.add(new NodeProperty(node, curr));
    }

    if (node instanceof CompilationUnit) {
        CompilationUnit root = (CompilationUnit) node;
        res.add(new JavaElement(root, root.getJavaElement()));
        res.add(new CommentsProperty(root));
        res.add(new ProblemsProperty(root));
    }

    return res.toArray();
}

From source file:com.halware.nakedide.eclipse.ext.annot.utils.AstUtils.java

License:Open Source License

/**
 * Returns all the {@link ChildListPropertyDescriptor}s of the supplied
 * {@link ASTNode} (as per {@link ASTNode#structuralPropertiesForType()}.
 * //from  w  w w . j  a  v a  2s.  c  o m
 * @param node
 * @return
 */
public static List<ChildListPropertyDescriptor> getChildListPropertyDescriptors(ASTNode node) {
    List<ChildListPropertyDescriptor> childListPropertyDescriptors = new ArrayList<ChildListPropertyDescriptor>();
    List list = node.structuralPropertiesForType();
    for (int i = 0; i < list.size(); i++) {
        StructuralPropertyDescriptor curr = (StructuralPropertyDescriptor) list.get(i);
        if (!(curr instanceof ChildListPropertyDescriptor)) {
            continue;
        }
        childListPropertyDescriptors.add((ChildListPropertyDescriptor) curr);
    }
    return childListPropertyDescriptors;
}

From source file:de.ovgu.cide.configuration.jdt.DeleteHiddenNodesVisitor.java

License:Open Source License

public void postVisit(ASTNode node) {
    if (shouldHide(node)) {
        // are there children that should not be deleted as well?
        List<ASTNode> replacements = new ArrayList<ASTNode>();
        for (Object prop : node.structuralPropertiesForType()) {
            if (ASTColorInheritance.notInheritedProperties.contains(prop)) {
                Object replace = rewrite.get(node, (StructuralPropertyDescriptor) prop);
                if (replace instanceof ASTNode)
                    replacements.add((ASTNode) replace);
            }/*from  w  w  w  .  ja  v a2s.  c o  m*/
        }
        remove(node, replacements);
    }
}

From source file:edu.buffalo.cse.Sapphire.JavaModelListener.java

License:Open Source License

/**
 * This method traverses the root ASTNode in the parameter and calls
 * printStatement to store the information of the child node.
 * /*from w  w w  . jav  a  2 s  . com*/
 * @author Chern Yee Chua
 */

public static void print(ASTNode node) {

    List properties = node.structuralPropertiesForType();
    for (Iterator iterator = properties.iterator(); iterator.hasNext();) {
        Object descriptor = iterator.next();
        if (descriptor instanceof SimplePropertyDescriptor) {
            SimplePropertyDescriptor simple = (SimplePropertyDescriptor) descriptor;
            Object value = node.getStructuralProperty(simple);
            int lineNumber;
            if (isTempLarger) {
                lineNumber = astRootTemp.getLineNumber(node.getStartPosition());
            } else {
                lineNumber = astRoot.getLineNumber(node.getStartPosition());
            }

            lastLineNumber = lineNumber;
            printStatement(lineNumber, simple, value, node);

        } else if (descriptor instanceof ChildPropertyDescriptor) {
            ChildPropertyDescriptor child = (ChildPropertyDescriptor) descriptor;
            ASTNode childNode = (ASTNode) node.getStructuralProperty(child);
            if (childNode != null) {

                print(childNode);
            }
        } else {
            ChildListPropertyDescriptor list = (ChildListPropertyDescriptor) descriptor;
            print((List) node.getStructuralProperty(list));
        }
    }
}

From source file:edu.buffalo.cse.Sapphire.JavaModelListenerNew.java

License:Open Source License

/**
 * This method traverses the root ASTNode in the parameter and calls
 * printStatement to store the information of the child node.
 * //w w w  .  j a va 2  s  . co  m
 * @author Chern Yee Chua
 */

public static void print(ASTNode node) {

    List properties = node.structuralPropertiesForType();
    for (Iterator iterator = properties.iterator(); iterator.hasNext();) {
        Object descriptor = iterator.next();
        if (descriptor instanceof SimplePropertyDescriptor) {
            SimplePropertyDescriptor simple = (SimplePropertyDescriptor) descriptor;
            Object value = node.getStructuralProperty(simple);
            int lineNumber = astRoot.getLineNumber(node.getStartPosition());

            lastLineNumber = lineNumber;
            printStatement(lineNumber, node);

        } else if (descriptor instanceof ChildPropertyDescriptor) {
            ChildPropertyDescriptor child = (ChildPropertyDescriptor) descriptor;
            ASTNode childNode = (ASTNode) node.getStructuralProperty(child);
            if (childNode != null) {

                print(childNode);
            }
        } else {
            ChildListPropertyDescriptor list = (ChildListPropertyDescriptor) descriptor;
            print((List) node.getStructuralProperty(list));
        }
    }
}

From source file:org.eclipse.jet.internal.xpath.inspectors.jdt.InspectASTNode.java

License:Open Source License

/**
 * Return the property descriptors for the given type.
 * @param node//from w w  w.  j a  va  2s. co  m
 * @return
 */
private List getPropertyDescriptors(final ASTNode node) {
    final Integer nodeType = new Integer(node.getNodeType());

    List propsList = (List) propertyDescriptorByType.get(nodeType);

    if (propsList == null) {
        synchronized (propertyDescriptorByType) {
            propsList = (List) propertyDescriptorByType.get(nodeType);
            if (propsList == null) {
                propsList = node.structuralPropertiesForType();
                propertyDescriptorByType.put(nodeType, propsList);
            }

        }
    }
    return propsList;
}