Search in sources :

Example 1 with Range

use of com.github.javaparser.Range in project javaparser by javaparser.

the class CommentParsingSteps method thenTheBlockCommentsHaveTheFollowingPositions.

@Then("the block comments have the following positions: $table")
public void thenTheBlockCommentsHaveTheFollowingPositions(ExamplesTable examplesTable) {
    int index = 0;
    for (Parameters exampleRow : examplesTable.getRowsAsParameters()) {
        Comment expectedLineComment = toComment(exampleRow, new BlockComment());
        Comment lineCommentUnderTest = getCommentAt(commentsCollection.getBlockComments(), index);
        Range underTestRange = lineCommentUnderTest.getRange().get();
        Range expectedRange = expectedLineComment.getRange().get();
        assertThat(underTestRange.begin.line, is(expectedRange.begin.line));
        assertThat(underTestRange.begin.column, is(expectedRange.begin.column));
        assertThat(underTestRange.end.line, is(expectedRange.end.line));
        assertThat(underTestRange.end.column, is(expectedRange.end.column));
        index++;
    }
}
Also used : Parameters(org.jbehave.core.steps.Parameters) Range(com.github.javaparser.Range) Then(org.jbehave.core.annotations.Then)

Example 2 with Range

use of com.github.javaparser.Range in project javaparser by javaparser.

the class ASTParserTokenManager method CommonTokenAction.

private void CommonTokenAction(Token token) {
    tokens.add(token);
    while (token.specialToken != null) {
        token = token.specialToken;
        String commentText = token.image;
        if (commentText.startsWith("/**")) {
            JavadocComment comment = new JavadocComment(tokenRange(token), commentText.substring(3, commentText.length() - 2));
            commentsCollection.addComment(comment);
        } else if (commentText.startsWith("/*")) {
            BlockComment comment = new BlockComment(tokenRange(token), commentText.substring(2, commentText.length() - 2));
            commentsCollection.addComment(comment);
        } else if (commentText.startsWith("//")) {
            // line comments have their end of line character(s) included, and we don't want that.
            Range range = tokenRange(token);
            while (commentText.endsWith("\r") || commentText.endsWith("\n")) {
                commentText = commentText.substring(0, commentText.length() - 1);
            }
            range = range.withEnd(pos(range.begin.line, range.begin.column + commentText.length()));
            LineComment comment = new LineComment(tokenRange(token), commentText.substring(2));
            commentsCollection.addComment(comment);
        } else {
            throw new AssertionError("Didn't expect to get here. Please file a bug report. [" + commentText + "]");
        }
    }
}
Also used : Range(com.github.javaparser.Range)

Example 3 with Range

use of com.github.javaparser.Range in project javaparser by javaparser.

the class PositionUtils method nodeContains.

public static boolean nodeContains(Node container, Node contained, boolean ignoringAnnotations) {
    final Range containedRange = contained.getRange().get();
    final Range containerRange = container.getRange().get();
    if (!ignoringAnnotations || PositionUtils.getLastAnnotation(container) == null) {
        return container.containsWithin(contained);
    }
    if (!container.containsWithin(contained)) {
        return false;
    }
    // let's not consider it contained
    if (container instanceof NodeWithAnnotations) {
        int bl = beginLineWithoutConsideringAnnotation(container);
        int bc = beginColumnWithoutConsideringAnnotation(container);
        if (bl > containedRange.begin.line)
            return false;
        if (bl == containedRange.begin.line && bc > containedRange.begin.column)
            return false;
        if (containerRange.end.line < containedRange.end.line)
            return false;
        // TODO < or <= ?
        return !(containerRange.end.line == containedRange.end.line && containerRange.end.column < containedRange.end.column);
    }
    return true;
}
Also used : NodeWithAnnotations(com.github.javaparser.ast.nodeTypes.NodeWithAnnotations) Range(com.github.javaparser.Range)

Example 4 with Range

use of com.github.javaparser.Range in project javaparser by javaparser.

the class CommentParsingSteps method thenTheLineCommentsHaveTheFollowingPositions.

@Then("the line comments have the following positions: $table")
public void thenTheLineCommentsHaveTheFollowingPositions(ExamplesTable examplesTable) {
    int index = 0;
    for (Parameters exampleRow : examplesTable.getRowsAsParameters()) {
        Comment expectedLineComment = toComment(exampleRow, new LineComment());
        Comment lineCommentUnderTest = getCommentAt(commentsCollection.getLineComments(), index);
        Range underTestRange = lineCommentUnderTest.getRange().get();
        Range expectedRange = expectedLineComment.getRange().get();
        assertThat(underTestRange.begin.line, is(expectedRange.begin.line));
        assertThat(underTestRange.begin.column, is(expectedRange.begin.column));
        assertThat(underTestRange.end.line, is(expectedRange.end.line));
        assertThat(underTestRange.end.column, is(expectedRange.end.column));
        index++;
    }
}
Also used : Parameters(org.jbehave.core.steps.Parameters) Range(com.github.javaparser.Range) Then(org.jbehave.core.annotations.Then)

Example 5 with Range

use of com.github.javaparser.Range in project javaparser by javaparser.

the class CommentParsingSteps method thenTheJavadocCommentsHaveTheFollowingPositions.

@Then("the Javadoc comments have the following positions: $table")
public void thenTheJavadocCommentsHaveTheFollowingPositions(ExamplesTable examplesTable) {
    int index = 0;
    for (Parameters exampleRow : examplesTable.getRowsAsParameters()) {
        Comment expectedLineComment = toComment(exampleRow, new BlockComment());
        Comment lineCommentUnderTest = getCommentAt(commentsCollection.getJavadocComments(), index);
        Range underTestRange = lineCommentUnderTest.getRange().get();
        Range expectedRange = expectedLineComment.getRange().get();
        assertThat(underTestRange.begin.line, is(expectedRange.begin.line));
        assertThat(underTestRange.begin.column, is(expectedRange.begin.column));
        assertThat(underTestRange.end.line, is(expectedRange.end.line));
        assertThat(underTestRange.end.column, is(expectedRange.end.column));
        index++;
    }
}
Also used : Parameters(org.jbehave.core.steps.Parameters) Range(com.github.javaparser.Range) Then(org.jbehave.core.annotations.Then)

Aggregations

Range (com.github.javaparser.Range)5 Then (org.jbehave.core.annotations.Then)3 Parameters (org.jbehave.core.steps.Parameters)3 NodeWithAnnotations (com.github.javaparser.ast.nodeTypes.NodeWithAnnotations)1