Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use most common suffix for IDL inline IO #2397

Merged
merged 1 commit into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -243,8 +243,8 @@ private Pair<String, String> determineInlineSuffixes(Model fullModel, Collection
return Pair.of(inlineInputSuffix, inlineOutputSuffix);
}

Set<String> inputSuffixes = new HashSet<>();
Set<String> outputSuffixes = new HashSet<>();
Map<String, Integer> inputSuffixes = new LinkedHashMap<>();
Map<String, Integer> outputSuffixes = new LinkedHashMap<>();
for (Shape shape : shapes) {
if (!shape.isOperationShape()) {
continue;
Expand All @@ -255,15 +255,28 @@ private Pair<String, String> determineInlineSuffixes(Model fullModel, Collection
StructureShape output = fullModel.expectShape(operation.getOutputShape(), StructureShape.class);

if (shapes.contains(input) && input.getId().getName().startsWith(operation.getId().getName())) {
inputSuffixes.add(input.getId().getName().substring(operation.getId().getName().length()));
String inputSuffix = input.getId().getName().substring(operation.getId().getName().length());
int inputCount = inputSuffixes.getOrDefault(inputSuffix, 0);
inputSuffixes.put(inputSuffix, ++inputCount);
}

if (shapes.contains(output) && output.getId().getName().startsWith(operation.getId().getName())) {
outputSuffixes.add(output.getId().getName().substring(operation.getId().getName().length()));
String outputSuffix = output.getId().getName().substring(operation.getId().getName().length());
int outputCount = outputSuffixes.getOrDefault(outputSuffix, 0);
outputSuffixes.put(outputSuffix, ++outputCount);
}
}
String inputSuffix = inputSuffixes.size() == 1 ? inputSuffixes.iterator().next() : inlineInputSuffix;
String outputSuffix = outputSuffixes.size() == 1 ? outputSuffixes.iterator().next() : inlineOutputSuffix;

String inputSuffix = inputSuffixes.entrySet()
.stream()
.max(Map.Entry.comparingByValue())
.map(Map.Entry::getKey)
.orElse(inlineInputSuffix);
String outputSuffix = outputSuffixes.entrySet()
.stream()
.max(Map.Entry.comparingByValue())
.map(Map.Entry::getKey)
.orElse(inlineOutputSuffix);
return Pair.of(inputSuffix, outputSuffix);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ $operationOutputSuffix: "Response"

namespace com.example

operation NotShared {
input: NotSharedInput
output: NotSharedOutput
}

operation SharedCustomA {
input := {}
output := {}
Expand All @@ -13,3 +18,9 @@ operation SharedCustomB {
input := {}
output := {}
}

@input
structure NotSharedInput {}

@output
structure NotSharedOutput {}
Loading