Skip to content

Commit

Permalink
Add a convenient method (hasRange) to the interface NodeWithRange
Browse files Browse the repository at this point in the history
  • Loading branch information
jlerbsc committed Nov 17, 2020
1 parent 818946f commit 991202f
Showing 1 changed file with 10 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@

package com.github.javaparser.ast.nodeTypes;

import java.util.Optional;

import com.github.javaparser.Position;
import com.github.javaparser.Range;
import com.github.javaparser.ast.Node;

import java.util.Optional;

/**
* A node that has a Range, which is every Node.
*/
Expand Down Expand Up @@ -71,9 +71,16 @@ default boolean containsWithin(Node other) {
* otherwise.
*/
default boolean containsWithinRange(Node other) {
if (getRange().isPresent() && other.getRange().isPresent()) {
if (hasRange() && other.hasRange()) {
return getRange().get().contains(other.getRange().get());
}
return false;
}

/*
* Returns true if the node has a range
*/
default boolean hasRange() {
return getRange().isPresent();
}
}

0 comments on commit 991202f

Please sign in to comment.