Example usage for org.eclipse.jdt.core.dom StructuralPropertyDescriptor isSimpleProperty

List of usage examples for org.eclipse.jdt.core.dom StructuralPropertyDescriptor isSimpleProperty

Introduction

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

Prototype

public final boolean isSimpleProperty() 

Source Link

Document

Returns whether this property is a simple property (instance of SimplePropertyDescriptor .

Usage

From source file:de.ovgu.cide.export.physical.ahead.JakFeatureRefactorer.java

License:Open Source License

static void replaceStatement(Statement target, Statement replacement) {
    ASTNode p = target.getParent();/*  w  ww .  j  a  v a 2 s .co m*/

    if (target instanceof Block && !(replacement instanceof Block)) {
        Block b = replacement.getAST().newBlock();
        b.statements().add(replacement);
        replacement = b;
    }

    StructuralPropertyDescriptor prop = target.getLocationInParent();
    if (prop.isSimpleProperty() || prop.isChildProperty()) {
        p.setStructuralProperty(prop, replacement);
    } else if (prop.isChildListProperty()) {
        assert false;
    }

}

From source file:de.ovgu.cide.export.physical.ahead.JakHookMethodHelper.java

License:Open Source License

private void replaceSubtreeRuleExceptionByPlaceholder() {
    ASTNode parent = subtreeRuleException.getParent();
    StructuralPropertyDescriptor prop = subtreeRuleException.getLocationInParent();
    if (prop.isSimpleProperty() || prop.isChildProperty()) {
        parent.setStructuralProperty(prop, exceptionPlaceholder);
    } else if (prop.isChildListProperty()) {
        assert false;
    }/*from   ww  w.  j  a  v a2 s . c  om*/
}

From source file:de.ovgu.cide.export.physical.ahead.JakHookMethodHelper.java

License:Open Source License

private void createRefinement() {
    refinement = createHookMethodSkeleton();
    List<Statement> statementList = refinement.getBody().statements();

    for (Statement stmt : statements) {
        Statement copyStmt = copyStatement(stmt);
        if (hasSubtreeRuleException && subtreeRuleExceptionParent == stmt) {
            assert returnValues.size() <= 1;
            Formal formal = null;//from w  ww .  ja va2s  .  co m
            if (returnValues.size() == 1)
                formal = returnValues.get(0);
            Statement replacement = JakFeatureRefactorer.createSuperCall(refinement, ast, false, formal);
            /*
             * we place the supercall at the old position where currently
             * the placeholder is located
             */
            if (subtreeRuleExceptionIsBlock) {
                Block b = ast.newBlock();
                b.statements().add(replacement);
                replacement = b;
            }

            StructuralPropertyDescriptor prop = exceptionPlaceholder.getLocationInParent();
            if (prop.isSimpleProperty() || prop.isChildProperty()) {
                copyStmt.setStructuralProperty(prop, replacement);
            } else if (prop.isChildListProperty()) {
                assert false;
            }

        }

        statementList.add(copyStmt);
    }
    if (subtreeRuleException == null)
        statementList.add(JakFeatureRefactorer.createSuperCall(refinement, ast, true, null));
    else
        appendReturnStatement(refinement.getBody());

}

From source file:de.ovgu.cide.language.jdt.ASTBridge.java

License:Open Source License

private ASTNode bridgeASTNode(org.eclipse.jdt.core.dom.ASTNode e_node) {
    ASTNode result = bridgeCache.get(e_node);
    if (result != null)
        return result;

    IToken c_firstToken = new PosToken(e_node.getStartPosition());
    IToken c_lastToken = new PosToken(e_node.getStartPosition() + e_node.getLength());

    IASTNode[] wrappee = null;/*from   ww  w  .  ja v  a 2s .co m*/
    List<StructuralPropertyDescriptor> e_props = e_node.structuralPropertiesForType();
    List<Property> c_props = new ArrayList<Property>();
    for (StructuralPropertyDescriptor e_prop : e_props) {
        if (e_prop.isSimpleProperty()) {
            Property prop = bridgeSimpleProperty(e_node, (SimplePropertyDescriptor) e_prop);
            if (prop != null) {
                if (ASTColorInheritance.notInheritedProperties.contains(e_prop))
                    wrappee = join(wrappee, prop.getChildren());
                c_props.add(prop);
            }
        } else if (e_prop.isChildListProperty()) {
            Property prop = bridgeChildListProperty(e_node, (ChildListPropertyDescriptor) e_prop);
            if (ASTColorInheritance.notInheritedProperties.contains(e_prop))
                wrappee = join(wrappee, prop.getChildren());
            c_props.add(prop);
        } else if (e_prop.isChildProperty()) {
            Property prop = bridgeChildProperty(e_node, (ChildPropertyDescriptor) e_prop);
            if (prop != null) {
                if (ASTColorInheritance.notInheritedProperties.contains(e_prop))
                    wrappee = join(wrappee, prop.getChildren());
                c_props.add(prop);
            }
        }

    }
    result = new UnifiedASTNode(getDisplayName(e_node), ASTID.id(e_node), c_props, c_firstToken, c_lastToken,
            wrappee, getKind(e_node));
    bridgeCache.put(e_node, result);
    return result;
}

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

License:Open Source License

/**
 * @param node/*from   w w  w  . j av a 2s  . c o m*/
 * @return
 */
private List getAttributePropertyDescriptors(final ASTNode node) {
    final Integer nodeType = new Integer(node.getNodeType());

    List propsList = (List) attributePropertyDescriptorByType.get(nodeType);
    if (propsList == null) {
        synchronized (attributePropertyDescriptorByType) {
            propsList = (List) attributePropertyDescriptorByType.get(nodeType);
            if (propsList == null) {
                final List allPropsList = node.structuralPropertiesForType();
                propsList = new ArrayList(allPropsList.size());
                for (final Iterator i = allPropsList.iterator(); i.hasNext();) {
                    final StructuralPropertyDescriptor spd = (StructuralPropertyDescriptor) i.next();
                    if (spd.isSimpleProperty()) {
                        propsList.add(spd);
                    }

                }
                attributePropertyDescriptorByType.put(nodeType, propsList);
            }

        }
    }
    return propsList;
}

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

License:Open Source License

/**
 * @param node/*ww  w.ja  v  a  2  s.  c o m*/
 * @return
 */
private List getElementPropertyDescriptors(final ASTNode node) {
    final Integer nodeType = new Integer(node.getNodeType());

    List propsList = (List) childPropertyDescriptorByType.get(nodeType);
    if (propsList == null) {
        synchronized (childPropertyDescriptorByType) {
            propsList = (List) childPropertyDescriptorByType.get(nodeType);
            if (propsList == null) {
                final List allPropsList = node.structuralPropertiesForType();
                propsList = new ArrayList(allPropsList.size());
                for (final Iterator i = allPropsList.iterator(); i.hasNext();) {
                    final StructuralPropertyDescriptor spd = (StructuralPropertyDescriptor) i.next();
                    if (!spd.isSimpleProperty()) {
                        propsList.add(spd);
                    }

                }
                childPropertyDescriptorByType.put(nodeType, propsList);
            }

        }
    }
    return propsList;
}

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

License:Open Source License

public Object getNamedAttribute(final Object node, final ExpandedName nameTestExpandedName) {
    final ASTNode astNode = (ASTNode) node;

    final String propertyName = nameTestExpandedName.getLocalPart();

    final NonDescriptorAttribute attribute = NonDescriptorAttribute.getAttribute(astNode, propertyName);
    if (attribute != null) {
        return attribute;
    }//  w w  w  .j  a v  a 2s. co m

    final StructuralPropertyDescriptor spd = getPropertyDescriptor(astNode, propertyName);

    if (spd != null && spd.isSimpleProperty() && astNode.getStructuralProperty(spd) != null) {
        return new SimplePropertyDescriptorAttribute(astNode, (SimplePropertyDescriptor) spd);
    }

    return null;
}

From source file:processing.mode.java.pdex.ASTGenerator.java

License:Open Source License

protected static ASTNode findClosestParentNode(int lineNumber, ASTNode node) {
    Iterator<StructuralPropertyDescriptor> it = node.structuralPropertiesForType().iterator();
    // Base.loge("Props of " + node.getClass().getName());
    while (it.hasNext()) {
        StructuralPropertyDescriptor prop = it.next();

        if (prop.isChildProperty() || prop.isSimpleProperty()) {
            if (node.getStructuralProperty(prop) != null) {
                //          System.out
                //              .println(node.getStructuralProperty(prop) + " -> " + (prop));
                if (node.getStructuralProperty(prop) instanceof ASTNode) {
                    ASTNode cnode = (ASTNode) node.getStructuralProperty(prop);
                    //            log("Looking at " + getNodeAsString(cnode)+ " for line num " + lineNumber);
                    int cLineNum = ((CompilationUnit) cnode.getRoot())
                            .getLineNumber(cnode.getStartPosition() + cnode.getLength());
                    if (getLineNumber(cnode) <= lineNumber && lineNumber <= cLineNum) {
                        return findClosestParentNode(lineNumber, cnode);
                    }//from w ww .  j av a 2  s . c  om
                }
            }
        }

        else if (prop.isChildListProperty()) {
            List<ASTNode> nodelist = (List<ASTNode>) node.getStructuralProperty(prop);
            for (ASTNode cnode : nodelist) {
                int cLineNum = ((CompilationUnit) cnode.getRoot())
                        .getLineNumber(cnode.getStartPosition() + cnode.getLength());
                //          log("Looking at " + getNodeAsString(cnode)+ " for line num " + lineNumber);
                if (getLineNumber(cnode) <= lineNumber && lineNumber <= cLineNum) {
                    return findClosestParentNode(lineNumber, cnode);
                }
            }
        }
    }
    return node;
}

From source file:processing.mode.java.pdex.ASTGenerator.java

License:Open Source License

/**
 * Generates AST Swing component/*from w w w  .j  av  a 2  s  .  c om*/
 * @param node
 * @param tnode
 */
public static void visitRecur(ASTNode node, DefaultMutableTreeNode tnode) {
    Iterator<StructuralPropertyDescriptor> it = node.structuralPropertiesForType().iterator();
    //Base.loge("Props of " + node.getClass().getName());
    DefaultMutableTreeNode ctnode = null;
    while (it.hasNext()) {
        StructuralPropertyDescriptor prop = it.next();

        if (prop.isChildProperty() || prop.isSimpleProperty()) {
            if (node.getStructuralProperty(prop) != null) {
                //          System.out
                //              .println(node.getStructuralProperty(prop) + " -> " + (prop));
                if (node.getStructuralProperty(prop) instanceof ASTNode) {
                    ASTNode cnode = (ASTNode) node.getStructuralProperty(prop);
                    if (isAddableASTNode(cnode)) {
                        ctnode = new DefaultMutableTreeNode(
                                new ASTNodeWrapper((ASTNode) node.getStructuralProperty(prop)));
                        tnode.add(ctnode);
                        visitRecur(cnode, ctnode);
                    }
                } else {
                    tnode.add(new DefaultMutableTreeNode(node.getStructuralProperty(prop)));
                }
            }
        } else if (prop.isChildListProperty()) {
            List<ASTNode> nodelist = (List<ASTNode>) node.getStructuralProperty(prop);
            for (ASTNode cnode : nodelist) {
                if (isAddableASTNode(cnode)) {
                    ctnode = new DefaultMutableTreeNode(new ASTNodeWrapper(cnode));
                    tnode.add(ctnode);
                    visitRecur(cnode, ctnode);
                } else {
                    visitRecur(cnode, tnode);
                }
            }
        }
    }
}

From source file:processing.mode.java.pdex.ASTGenerator.java

License:Open Source License

public ASTNode dfsLookForASTNode(ASTNode root, String name, int startOffset, int endOffset) {
    //    log("dfsLookForASTNode() lookin for " + name + " Offsets: " + startOffset
    //        + "," + endOffset);
    Stack<ASTNode> stack = new Stack<ASTNode>();
    stack.push(root);//from w w w  . j a  v a2  s . c o m

    while (!stack.isEmpty()) {
        ASTNode node = stack.pop();
        //log("Popped from stack: " + getNodeAsString(node));
        Iterator<StructuralPropertyDescriptor> it = node.structuralPropertiesForType().iterator();
        while (it.hasNext()) {
            StructuralPropertyDescriptor prop = it.next();

            if (prop.isChildProperty() || prop.isSimpleProperty()) {
                if (node.getStructuralProperty(prop) instanceof ASTNode) {
                    ASTNode temp = (ASTNode) node.getStructuralProperty(prop);
                    if (temp.getStartPosition() <= startOffset
                            && (temp.getStartPosition() + temp.getLength()) >= endOffset) {
                        if (temp instanceof SimpleName) {
                            if (name.equals(temp.toString())) {
                                //                  log("Found simplename: " + getNodeAsString(temp));
                                return temp;
                            }
                            //                log("Bummer, didn't match");
                        } else
                            stack.push(temp);
                        //log("Pushed onto stack: " + getNodeAsString(temp));
                    }
                }
            } else if (prop.isChildListProperty()) {
                List<ASTNode> nodelist = (List<ASTNode>) node.getStructuralProperty(prop);
                for (ASTNode temp : nodelist) {
                    if (temp.getStartPosition() <= startOffset
                            && (temp.getStartPosition() + temp.getLength()) >= endOffset) {
                        stack.push(temp);
                        //                log("Pushed onto stack: " + getNodeAsString(temp));
                        if (temp instanceof SimpleName) {
                            if (name.equals(temp.toString())) {
                                //                    log("Found simplename: " + getNodeAsString(temp));
                                return temp;
                            }
                            //                  log("Bummer, didn't match");
                        } else
                            stack.push(temp);
                        //log("Pushed onto stack: " + getNodeAsString(temp));
                    }
                }
            }
        }
    }
    //    log("dfsLookForASTNode() not found " + name);
    return null;
}