Search in sources :

Example 1 with NodeWithAnnotations

use of com.github.javaparser.ast.nodeTypes.NodeWithAnnotations 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)

Aggregations

Range (com.github.javaparser.Range)1 NodeWithAnnotations (com.github.javaparser.ast.nodeTypes.NodeWithAnnotations)1