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

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

Introduction

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

Prototype

public final int getFlags() 

Source Link

Document

Returns the flags associated with this node.

Usage

From source file:boa.datagen.util.JavaErrorCheckVisitor.java

License:Apache License

public boolean preVisit2(ASTNode node) {
    if ((node.getFlags() & ASTNode.MALFORMED) != 0)
        hasError = true;//from w w w.  j  a  v a  2  s. c o m
    return !hasError;
}

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

License:Open Source License

private void getNodeType(ASTNode node, StringBuffer buf) {
    if (node instanceof PackageDeclaration || node instanceof ImportDeclaration || node instanceof Modifier
            || node instanceof TagElement || node instanceof TextElement || node instanceof SimpleName
            || node instanceof SimpleType || node instanceof StringLiteral || node instanceof NumberLiteral
            || node instanceof PrimitiveType || node instanceof EnumConstantDeclaration) {
        buf.append(node.toString().replace('\n', ' ') + "  [" + node.getClass().getSimpleName() + "]");
    } else if (node instanceof TypeDeclaration) {
        buf.append(((TypeDeclaration) node).getName());
    } else if (node instanceof EnumDeclaration) {
        buf.append(((EnumDeclaration) node).getName());
    } else {// w w w .j a v a  2 s  . c  o m
        buf.append(Signature.getSimpleName(node.getClass().getName()));
        if (node instanceof Expression) {
            buf.append("  -> " + node.toString().replace('\n', ' '));
        }
    }
    buf.append(" ["); //$NON-NLS-1$
    buf.append(node.getStartPosition());
    buf.append(", "); //$NON-NLS-1$
    buf.append(node.getLength());
    buf.append(']');
    if ((node.getFlags() & ASTNode.MALFORMED) != 0) {
        buf.append(" (malformed)"); //$NON-NLS-1$
    }
    if ((node.getFlags() & ASTNode.RECOVERED) != 0) {
        buf.append(" (recovered)"); //$NON-NLS-1$
    }
}

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

License:Open Source License

public Color getForeground(Object element) {
    if ((element instanceof Error))
        return fRed;
    if ((element instanceof ExceptionAttribute) && ((ExceptionAttribute) element).getException() != null)
        return fRed;

    if (element instanceof ASTNode) {
        ASTNode node = (ASTNode) element;
        if ((node.getFlags() & ASTNode.MALFORMED) != 0) {
            return fRed;
        }//ww  w. jav a2  s.com
        return fDarkGray;
    } else if (element instanceof Binding) {
        Binding binding = (Binding) element;
        if (!binding.isRelevant())
            return fDarkGray;
        return fBlue;
    } else if (element instanceof NodeProperty) {
        return null; // normal color
    } else if (element instanceof BindingProperty) {
        BindingProperty binding = (BindingProperty) element;
        if (!binding.isRelevant())
            return fDarkGray;
        return fBlue;
    } else if (element instanceof JavaElement) {
        JavaElement javaElement = (JavaElement) element;
        if (javaElement.getJavaElement() == null || !javaElement.getJavaElement().exists()) {
            return fRed;
        }
        return fDarkGreen;
    }
    return fDarkRed; // all extra properties
}

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

License:Open Source License

public Font getFont(Object element) {
    if (element instanceof ASTNode) {
        ASTNode node = (ASTNode) element;
        if ((node.getFlags() & ASTNode.RECOVERED) != 0)
            return fAllocatedBoldItalic;
        else/*from w w w  . j av a  2 s  .  c om*/
            return fBold;
    }
    return null;
}

From source file:coloredide.astview.ASTViewLabelProvider.java

License:Open Source License

private void getNodeType(ASTNode node, StringBuffer buf) {
    buf.append(Signature.getSimpleName(node.getClass().getName()));
    buf.append(" ["); //$NON-NLS-1$
    buf.append(node.getStartPosition());
    buf.append(", "); //$NON-NLS-1$
    buf.append(node.getLength());//w  w w.j a  v a 2  s. c o m
    buf.append(']');
    if ((node.getFlags() & ASTNode.MALFORMED) != 0) {
        buf.append(" (malformed)"); //$NON-NLS-1$
    }
    if ((node.getFlags() & ASTNode.RECOVERED) != 0) {
        buf.append(" (recovered)"); //$NON-NLS-1$
    }
}

From source file:com.bsiag.eclipse.jdt.java.formatter.CommentsPreparator.java

License:Open Source License

@Override
public boolean preVisit2(ASTNode node) {
    boolean isMalformed = (node.getFlags() & ASTNode.MALFORMED) != 0;
    return !isMalformed;
}

From source file:com.bsiag.eclipse.jdt.java.formatter.linewrap.WrapPreparator.java

License:Open Source License

@Override
public boolean preVisit2(ASTNode node) {
    this.currentDepth++;

    assert this.wrapIndexes.isEmpty() && this.wrapPenalties.isEmpty();
    assert this.wrapParentIndex == -1 && this.wrapGroupEnd == -1;

    boolean isMalformed = (node.getFlags() & ASTNode.MALFORMED) != 0;
    if (isMalformed) {
        this.tm.addDisableFormatTokenPair(this.tm.firstTokenIn(node, -1), this.tm.lastTokenIn(node, -1));
    }//from  ww  w. j a  v a2 s  . c o m
    return !isMalformed;
}

From source file:com.github.parzonka.ccms.engine.SortElementsOperation.java

License:Open Source License

protected boolean isMalformed(ASTNode node) {
    return (node.getFlags() & ASTNode.MALFORMED) != 0;
}

From source file:org.eclipse.che.jdt.dom.ASTNodes.java

License:Open Source License

/**
 * Adds flags to the given node and all its descendants.
 *
 * @param root// ww  w .  j  ava  2  s . c  om
 *         The root node
 * @param flags
 *         The flags to set
 */
public static void setFlagsToAST(ASTNode root, final int flags) {
    root.accept(new GenericVisitor(true) {
        @Override
        protected boolean visitNode(ASTNode node) {
            node.setFlags(node.getFlags() | flags);
            return true;
        }
    });
}

From source file:org.eclipselabs.javainterpreter.JavaInterpreter.java

License:Open Source License

public Object evaluateMethodInvocation(String expression) {
    ASTParser parser = ASTParser.newParser(AST.JLS4);
    parser.setKind(ASTParser.K_EXPRESSION);
    parser.setResolveBindings(true);/*www.ja  v  a2  s  . c om*/
    parser.setStatementsRecovery(false);
    parser.setSource(expression.toCharArray());
    ASTNode node = parser.createAST(null);

    if ((node.getFlags() & ASTNode.MALFORMED) == ASTNode.MALFORMED)
        throw new IllegalArgumentException("Parse error");

    if (node.getNodeType() == ASTNode.METHOD_INVOCATION || node.getNodeType() == ASTNode.ASSIGNMENT
            || node.getNodeType() == ASTNode.CLASS_INSTANCE_CREATION
            || node.getNodeType() == ASTNode.ARRAY_CREATION || node.getNodeType() == ASTNode.STRING_LITERAL) {

        try {
            node.accept(visitor);
        } catch (RuntimeException ex) {
            if (ex.getCause() != null)
                ex.printStackTrace();

            throw new IllegalArgumentException(ex.getMessage());
        }

        return visitor.resolve();
    }
    //      else if(node.getNodeType() == ASTNode.ASSIGNMENT) {
    //         AssignmentVisitor visitor = new AssignmentVisitor();
    //         try {
    //            node.accept(visitor);
    //         }
    //         catch(RuntimeException ex) {
    //            throw ex;
    //         }
    //         variables.put(visitor.variable, visitor.result);
    //         return visitor.result;
    //      }
    throw new IllegalArgumentException("Parse error");
}