Skip to content

Commit

Permalink
Add getAsStringsWithSimpleNames() method.
Browse files Browse the repository at this point in the history
  • Loading branch information
lukehutch committed Dec 20, 2020
1 parent 4a97779 commit 4b155fa
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/main/java/io/github/classgraph/InfoList.java
Original file line number Diff line number Diff line change
Expand Up @@ -121,4 +121,26 @@ public List<String> getAsStrings() {
return toStringVals;
}
}

/**
* Get the String representations of all items in this list, using only the simple name of any named class, by
* calling {@code ScanResultObject#toStringWithSimpleNames()} if the object is a {@code ScanResultObject} (e.g.
* {@link ClassInfo}, {@link MethodInfo} or {@link FieldInfo} object), otherwise calling {@code toString()}, for
* each item in the list.
*
* @return The String representations of all items in this list, using only the simple name of any named class.
*/
public List<String> getAsStringsWithSimpleNames() {
if (this.isEmpty()) {
return Collections.emptyList();
} else {
final List<String> toStringVals = new ArrayList<>(this.size());
for (final T i : this) {
toStringVals.add(i == null ? "null"
: i instanceof ScanResultObject ? ((ScanResultObject) i).toStringWithSimpleNames()
: i.toString());
}
return toStringVals;
}
}
}

0 comments on commit 4b155fa

Please sign in to comment.