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

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

Introduction

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

Prototype

@Override
public final String toString() 

Source Link

Document

Returns a string representation of this node suitable for debugging purposes only.

Usage

From source file:at.bestsolution.fxide.jdt.corext.dom.ASTFlattener.java

License:Open Source License

@Override
protected boolean visitNode(ASTNode node) {
    Assert.isTrue(false, "No implementation to flatten node: " + node.toString()); //$NON-NLS-1$
    return false;
}

From source file:at.bestsolution.fxide.jdt.editor.JDTJavaDocSupport.java

License:Open Source License

private static void handleContents(StringBuilder b, TagElement e) {
    List<ASTNode> l = e.fragments();
    for (ASTNode child : l) {
        if (child instanceof TextElement) {
            b.append(((TextElement) child).getText() + "\n");
        } else {//w  w  w  . j av a2s .co  m
            b.append(child.toString() + "\n");
        }

    }
}

From source file:ca.mcgill.cs.swevo.ppa.ui.NameBindingVisitor.java

License:Open Source License

@Override
public void postVisit(ASTNode node) {
    super.postVisit(node);

    if (node instanceof Expression) {
        Expression exp = (Expression) node;

        IBinding binding = null;// w w  w .  ja  v a  2s  .  c  om
        if (exp instanceof Name) {
            Name name = (Name) exp;
            binding = name.resolveBinding();
        } else if (exp instanceof MethodInvocation) {
            MethodInvocation mi = (MethodInvocation) exp;
            binding = mi.resolveMethodBinding();
        } else if (exp instanceof ClassInstanceCreation) {
            ClassInstanceCreation cic = (ClassInstanceCreation) exp;
            binding = cic.resolveConstructorBinding();
        } else {
            return;
        }

        printer.println("Node: " + node.toString());
        ITypeBinding tBinding = exp.resolveTypeBinding();
        if (tBinding != null) {
            printer.println("  Type Binding: " + tBinding.getQualifiedName());
            printer.println("  isAnnotation?: " + tBinding.isAnnotation());
        }

        if (binding != null) {
            printer.println("  " + PPABindingsUtil.getBindingText(binding));
        }
        printer.flush();
    }
    monitor.worked(1);
}

From source file:changenodes.matching.BestLeafTreeMatcher.java

License:Apache License

private List<LeafPair> matchLeaves(ASTNode left, ASTNode right) {
    List<LeafPair> matchedLeafs = new ArrayList<LeafPair>();
    for (Iterator<ASTNode> iterator = new BreadthFirstNodeIterator(left); iterator.hasNext();) {
        ASTNode x = iterator.next();
        if (NodeClassifier.isLeafStatement(x)) {
            for (Iterator<ASTNode> rightIterator = new BreadthFirstNodeIterator(right); rightIterator
                    .hasNext();) {//from  w  w w. jav a  2s.co  m
                ASTNode y = rightIterator.next();
                if (NodeClassifier.isLeafStatement(y) && x.getNodeType() == y.getNodeType()) {
                    double similarity = 0;

                    if (NodeClassifier.isComment(x)) {
                        //ignore comments as they are not easily available
                    } else { // ...other statements.
                        similarity = fLeafGenericStringSimilarityCalculator.calculateSimilarity(x.toString(),
                                y.toString());

                        // Important! Otherwise nodes that match poorly will make it into final matching set,
                        // if no better matches are found!
                        if (similarity >= fLeafGenericStringSimilarityThreshold) {
                            matchedLeafs.add(new LeafPair(x, y, similarity));
                        }
                    }
                }
            }
        }
    }
    return matchedLeafs;
}

From source file:changenodes.matching.BestLeafTreeMatcher.java

License:Apache License

private double equal(ASTNode x, ASTNode y) {
    // inner nodes
    if (areInnerOrRootNodes(x, y) && x.getNodeType() == y.getNodeType()) {
        // little heuristic
        if (NodeClassifier.isRoot(x)) {
            return 1.0;
        } else {/*from  w  ww.  j  a v a  2 s.  com*/
            double t = fNodeSimilarityThreshold;

            double simNode = fNodeSimilarityCalculator.calculateSimilarity(x, y);
            double simString = fNodeStringSimilarityCalculator.calculateSimilarity(x.toString(), y.toString());
            if ((simString < fNodeStringSimilarityThreshold) && (simNode >= WEIGHTING_THRESHOLD)) {
                return simString;
            } else {
                if ((simNode >= t) && (simString >= fNodeStringSimilarityThreshold)) {
                    return simString;
                }
            }
        }
    }
    return 0;
}

From source file:chibi.gumtreediff.gen.jdt.JdtVisitor.java

License:Open Source License

protected String getLabel(ASTNode n) {
    if (n instanceof Name)
        return ((Name) n).getFullyQualifiedName();
    if (n instanceof Type)
        return n.toString();
    if (n instanceof Modifier)
        return n.toString();
    if (n instanceof StringLiteral)
        return ((StringLiteral) n).getEscapedValue();
    if (n instanceof NumberLiteral)
        return ((NumberLiteral) n).getToken();
    if (n instanceof CharacterLiteral)
        return ((CharacterLiteral) n).getEscapedValue();
    if (n instanceof BooleanLiteral)
        return ((BooleanLiteral) n).toString();
    if (n instanceof InfixExpression)
        return ((InfixExpression) n).getOperator().toString();
    if (n instanceof PrefixExpression)
        return ((PrefixExpression) n).getOperator().toString();
    if (n instanceof PostfixExpression)
        return ((PostfixExpression) n).getOperator().toString();
    if (n instanceof Assignment)
        return ((Assignment) n).getOperator().toString();
    if (n instanceof TextElement)
        return n.toString();
    if (n instanceof TagElement)
        return ((TagElement) n).getTagName();

    return "";
}

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:com.drgarbage.ast.ASTGraphUtil.java

License:Apache License

/**
 * Returns nodes description.//from w w  w  .  ja va 2 s. com
 * 
 * @param node the AST-node
 * @return description string
 */
public static String getNodeDescr(ASTNode node) {
    StringBuffer elementDescr = new StringBuffer(node.getClass().getSimpleName());
    elementDescr.append(": ");

    int nodeType = node.getNodeType();
    switch (nodeType) {
    case ASTNode.COMPILATION_UNIT:
        CompilationUnit cu = (CompilationUnit) node;
        elementDescr.append(cu.getJavaElement().getElementName());
        break;

    case ASTNode.PACKAGE_DECLARATION:
        PackageDeclaration pd = (PackageDeclaration) node;
        elementDescr.append(pd.getName());
        break;

    case ASTNode.TYPE_DECLARATION:
        TypeDeclaration td = (TypeDeclaration) node;
        appendModifiers(td.getModifiers(), elementDescr);
        elementDescr.append(" class ");
        elementDescr.append(td.getName());
        break;

    case ASTNode.METHOD_DECLARATION:
        MethodDeclaration md = (MethodDeclaration) node;
        appendModifiers(md.getModifiers(), elementDescr);
        elementDescr.append(md.getReturnType2() == null ? "" : md.getReturnType2().toString());
        elementDescr.append(' ');
        elementDescr.append(md.getName());
        elementDescr.append("()");
        break;

    case ASTNode.BLOCK:
        elementDescr.append("{...}");
        break;

    case ASTNode.IF_STATEMENT:
        IfStatement is = (IfStatement) node;
        elementDescr.append("if( ");
        elementDescr.append(is.getExpression().toString());
        elementDescr.append(")");
        break;

    case ASTNode.FOR_STATEMENT:
        ForStatement fs = (ForStatement) node;
        elementDescr.append("for (...; ");
        elementDescr.append(fs.getExpression().toString());
        elementDescr.append("; ...){...}");
        break;

    case ASTNode.WHILE_STATEMENT:
        WhileStatement ws = (WhileStatement) node;
        elementDescr.append("while ( ");
        elementDescr.append(ws.getExpression().toString());
        elementDescr.append("){...}");
        break;

    case ASTNode.DO_STATEMENT:
        DoStatement ds = (DoStatement) node;
        elementDescr.append("do {...} while (");
        elementDescr.append(ds.getExpression().toString());
        elementDescr.append(")");
        break;

    case ASTNode.LABELED_STATEMENT:
        LabeledStatement ls = (LabeledStatement) node;
        elementDescr.append(ls.getLabel().toString());
        elementDescr.append(":");
        break;

    case ASTNode.CATCH_CLAUSE:
        CatchClause cs = (CatchClause) node;
        elementDescr.append("catch (");
        elementDescr.append(cs.getException().toString());
        elementDescr.append("){...}");
        break;

    case ASTNode.SWITCH_STATEMENT:
        SwitchStatement ss = (SwitchStatement) node;
        elementDescr.append("switch (");
        elementDescr.append(ss.getExpression().toString());
        elementDescr.append("){...}");
        break;

    case ASTNode.SWITCH_CASE:
        SwitchCase sc = (SwitchCase) node;
        elementDescr.append("case ");
        elementDescr.append(sc.getExpression() == null ? "default" : sc.getExpression().toString());
        elementDescr.append(":");
        break;
    case ASTNode.JAVADOC:
    case ASTNode.BLOCK_COMMENT:
    case ASTNode.LINE_COMMENT:
    case ASTNode.TRY_STATEMENT:
        /* nothing to do */
        break;

    default:
        elementDescr.append(node.toString());
    }

    /* cut the string if it is too long */
    String str = elementDescr.toString();
    if (str.length() > 128) {
        str = str.substring(0, 128) + " ... ";
    }
    str = str.replaceAll("\n", "");
    return str;
}

From source file:com.github.gumtreediff.gen.jdt.JdtVisitor.java

License:Open Source License

protected String getLabel(ASTNode n) {
    if (n instanceof Name)
        return ((Name) n).getFullyQualifiedName();
    if (n instanceof Type)
        return n.toString();
    if (n instanceof Modifier)
        return n.toString();
    if (n instanceof StringLiteral)
        return ((StringLiteral) n).getEscapedValue();
    if (n instanceof NumberLiteral)
        return ((NumberLiteral) n).getToken();
    if (n instanceof CharacterLiteral)
        return ((CharacterLiteral) n).getEscapedValue();
    if (n instanceof BooleanLiteral)
        return ((BooleanLiteral) n).toString();
    if (n instanceof InfixExpression)
        return ((InfixExpression) n).getOperator().toString();
    if (n instanceof PrefixExpression)
        return ((PrefixExpression) n).getOperator().toString();
    if (n instanceof PostfixExpression)
        return ((PostfixExpression) n).getOperator().toString();
    if (n instanceof Assignment)
        return ((Assignment) n).getOperator().toString();

    return "";
}

From source file:com.google.devtools.j2objc.ast.TextElement.java

License:Apache License

public TextElement(ASTNode jdtNode) {
    super(jdtNode);
    text = jdtNode.toString();
}