Skip to content

Commit

Permalink
Add documentation to findIndexInSubList
Browse files Browse the repository at this point in the history
  • Loading branch information
I-Al-Istannen committed Apr 13, 2023
1 parent 8d7fa86 commit 1669e5a
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/main/java/spoon/support/compiler/jdt/JDTTreeBuilderHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,18 @@ boolean isProblemNameRefProbablyTypeRef(QualifiedNameReference qualifiedNameRefe
return false;
}

/**
* Finds the lowest index where {@code needle} appears in {@code haystack}. This is akin to a
* substring search, but JDT uses a String[] to omit separators and a char[] to represent strings.
* If we want to find out where "String" appears in "java.lang.String", we would call
* {@code indexOfSubList(["java", "lang", "String"], ["lang", "String"])} and receive {@code 1}.
*
* @param haystack the haystack to search in
* @param needle the needle to search
* @return the first index where needle appears in haystack
* @see java.util.Collections#indexOfSubList(List, List) Collections#indexOfSubList for a more
* general version that does not correctly handle array equality
*/
private static int indexOfSubList(char[][] haystack, char[][] needle) {
outer:
for (int i = 0; i < haystack.length - needle.length; i++) {
Expand Down

0 comments on commit 1669e5a

Please sign in to comment.