Example usage for org.eclipse.jdt.internal.compiler.ast ASTNode sourceEnd

List of usage examples for org.eclipse.jdt.internal.compiler.ast ASTNode sourceEnd

Introduction

In this page you can find the example usage for org.eclipse.jdt.internal.compiler.ast ASTNode sourceEnd.

Prototype

public int sourceEnd() 

Source Link

Usage

From source file:ch.uzh.ifi.seal.changedistiller.ast.java.JavaASTHelper.java

License:Apache License

private SourceRange createSourceRange(ASTNode astNode) {
    if (astNode instanceof TypeDeclaration) {
        TypeDeclaration type = (TypeDeclaration) astNode;
        return new SourceRange(type.declarationSourceStart, type.declarationSourceEnd);
    }/*from   w w  w  .  j  a  va 2 s  .c  om*/
    if (astNode instanceof AbstractMethodDeclaration) {
        AbstractMethodDeclaration method = (AbstractMethodDeclaration) astNode;
        return new SourceRange(method.declarationSourceStart, method.declarationSourceEnd);
    }
    if (astNode instanceof FieldDeclaration) {
        FieldDeclaration field = (FieldDeclaration) astNode;
        return new SourceRange(field.declarationSourceStart, field.declarationSourceEnd);
    }
    return new SourceRange(astNode.sourceStart(), astNode.sourceEnd());
}

From source file:ch.uzh.ifi.seal.changedistiller.ast.java.JavaDeclarationConverter.java

License:Apache License

private String getSource(ASTNode node) {
    return getSource(node.sourceStart(), node.sourceEnd());
}

From source file:ch.uzh.ifi.seal.changedistiller.ast.java.JavaDeclarationConverter.java

License:Apache License

private void pushValuedNode(ASTNode node, String value) {
    push(fASTHelper.convertNode(node), value, node.sourceStart(), node.sourceEnd());
}

From source file:ch.uzh.ifi.seal.changedistiller.ast.java.JavaMethodBodyConverter.java

License:Apache License

/**
 * Calculates the proximity between the two given {@link ASTNode}. Usually one of the nodes is a comment.
 * /*  w ww  .j  a va 2 s.  c o m*/
 * @param nodeOne
 *            to calculate the proximity
 * @param nodeTwo
 *            to calculate the proximity
 * @return <code>2</code> if the comment node is on the same line as the other node, <code>1</code> if they are on
 *         adjacent line, <code>0</code> otherwise (times two)
 */
private int proximityRating(ASTNode left, ASTNode right) {
    int result = 0;
    ASTNode nodeOne = left;
    ASTNode nodeTwo = right;
    // swap code, if nodeOne is not before nodeTwo
    if ((nodeTwo.sourceStart() - nodeOne.sourceStart()) < 0) {
        ASTNode tmpNode = nodeOne;
        nodeOne = nodeTwo;
        nodeTwo = tmpNode;
    }

    int endOfNodePosition = nodeOne.sourceEnd();

    // comment (nodeTwo) inside nodeOne
    if (endOfNodePosition > nodeTwo.sourceStart()) {

        // find position before comment start
        String findNodeEndTemp = fSource.substring(nodeOne.sourceStart(), nodeTwo.sourceStart());

        // remove white space between nodeOne and comment (nodeTwo)
        int lastNonSpaceChar = findNodeEndTemp.lastIndexOf("[^\\s]");
        if (lastNonSpaceChar > -1) {
            findNodeEndTemp = findNodeEndTemp.substring(lastNonSpaceChar);
        }

        // end position of nodeOne before comment without succeeding white space
        endOfNodePosition = nodeTwo.sourceStart() - findNodeEndTemp.length();
    }
    String betweenOneAndComment = fSource.substring(endOfNodePosition, nodeTwo.sourceStart());

    // Comment is on the same line as code, but node in code
    int positionAfterBracket = betweenOneAndComment.lastIndexOf('}');
    int positionAfterSemicolon = betweenOneAndComment.lastIndexOf(';');
    int sameLinePosition = Math.max(positionAfterBracket, positionAfterSemicolon);
    if (sameLinePosition > -1) {
        betweenOneAndComment = betweenOneAndComment.substring(sameLinePosition + 1,
                betweenOneAndComment.length());
    }

    // 2 points if on the same line as well as inside the code,
    // i.e. there is no line break between the code and the comment
    String newLine = System.getProperty("line.separator");
    if (betweenOneAndComment.indexOf(newLine) == -1) {
        result += 2;

        // 1 point if on the succeeding line,
        // i.e. only one line break between the code and the comment
    } else if (betweenOneAndComment.replaceFirst(newLine, "").indexOf(newLine) == -1) {
        result++;
    }

    return result * 2;
}

From source file:ch.uzh.ifi.seal.changedistiller.ast.java.JavaMethodBodyConverter.java

License:Apache License

private void pushEmptyNode(ASTNode node) {
    push(fASTHelper.convertNode(node), "", node.sourceStart(), node.sourceEnd());
}

From source file:com.google.gwt.dev.javac.GWTProblem.java

License:Open Source License

public static void recordProblem(ASTNode node, CompilationResult compResult, String message, HelpInfo helpInfo,
        int problemSeverity) {
    int[] lineEnds = compResult.getLineSeparatorPositions();
    int startLine = Util.getLineNumber(node.sourceStart(), lineEnds, 0, lineEnds.length - 1);
    int startColumn = Util.searchColumnNumber(lineEnds, startLine, node.sourceStart());
    recordProblem(node.sourceStart(), node.sourceEnd(), startLine, startColumn, compResult, message, helpInfo,
            problemSeverity);/*from ww w.  j ava2  s  . c  o m*/
}