Skip to content

Commit 6f93366

Browse files
committed
Source::functionExplanation
1 parent 2ee3a19 commit 6f93366

File tree

1 file changed

+22
-0
lines changed
  • src/main/java/org/variantsync/diffdetective/util

1 file changed

+22
-0
lines changed

src/main/java/org/variantsync/diffdetective/util/Source.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,28 @@ static String fullExplanation(Source source) {
205205
return result.toString();
206206
}
207207

208+
/**
209+
* The same as {@link #fullExplanation(Source)} but with a different formatting.
210+
* Where fullExplanation renders this tree of sources as using newlines and indentation,
211+
* functionExplanation renders this tree as one large, nested function call of the form:
212+
* {@link #getSourceExplanation()}({@link #getSourceArguments() args}..., {@link #getSources() nested sources}...).
213+
*/
214+
default String functionExplanation() {
215+
String result = getSourceExplanation() + "(";
216+
217+
final List<String> args = new ArrayList<>();
218+
for (Object arg : getSourceArguments()) {
219+
args.add(arg.toString());
220+
}
221+
for (Source child : getSources()) {
222+
args.add(child.functionExplanation());
223+
}
224+
225+
result += args.stream().collect(Collectors.joining(", "));
226+
227+
return result + ")";
228+
}
229+
208230
/**
209231
* Uses a depth first traversal of the {@link Source} {@link getSources hierarchy} to find and
210232
* return all instances of {@code clazz}.

0 commit comments

Comments
 (0)