Skip to content

Commit

Permalink
[GR-51099] Generate List.of() instead of Arrays.asList().
Browse files Browse the repository at this point in the history
PullRequest: graal/16458
  • Loading branch information
fniephaus committed Jan 4, 2024
2 parents bbcdfde + 9939955 commit c069de7
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@ private static CodeTypeElement generateDescriptors(ProcessorContext context, Ele
if (model.options.isEmpty()) {
builder.startStaticCall(context.getType(Collections.class), "<OptionDescriptor> emptyList().iterator").end();
} else {
builder.startStaticCall(context.getType(Arrays.class), "asList");
builder.startStaticCall(context.getType(List.class), "of");
for (OptionInfo info : model.options) {
builder.startGroup();
builder.startIndention();
Expand All @@ -514,7 +514,7 @@ private static CodeTypeElement generateDescriptors(ProcessorContext context, Ele
builder.end();
builder.end();
}
builder.end(); /// asList call
builder.end(); /// of call
builder.newLine();
builder.startCall("", "iterator").end();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1803,7 +1803,7 @@ private void generateIntrospectionInfo(CodeTypeElement clazz, boolean inlined) {
}

builder.startStatement().startCall("cached", "add");
builder.startStaticCall(context.getType(Arrays.class), "<Object>asList");
builder.startStaticCall(context.getType(List.class), "of");
for (CacheExpression cache : specialization.getCaches()) {
if (cache.isAlwaysInitialized()) {
continue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -367,11 +367,7 @@ private static ExecutableElement createGetFactories(ProcessorContext context, No
CodeTreeBuilder builder = method.createBuilder();
builder.startReturn();

if (factoryList.size() > 1) {
builder.startStaticCall(context.getType(Arrays.class), "asList");
} else {
builder.startStaticCall(context.getType(Collections.class), "singletonList");
}
builder.startStaticCall(context.getType(List.class), "of");

for (NodeData child : factoryList) {
builder.startGroup();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
import static javax.lang.model.element.Modifier.STATIC;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import javax.lang.model.element.Element;
Expand Down Expand Up @@ -143,11 +142,11 @@ private CodeExecutableElement createCreateGetNodeSignatures() {
builder.startReturn();

builder.startGroup();
builder.startStaticCall(context.getType(Arrays.class), "asList");
builder.startStaticCall(context.getType(List.class), "of");
List<ExecutableElement> constructors = GeneratorUtils.findUserConstructors(createdFactoryElement.asType());
for (ExecutableElement constructor : constructors) {
builder.startGroup();
builder.startStaticCall(context.getType(Arrays.class), "asList");
builder.startStaticCall(context.getType(List.class), "of");
for (VariableElement var : constructor.getParameters()) {
builder.typeLiteral(var.asType());
}
Expand All @@ -167,7 +166,7 @@ private CodeExecutableElement createCreateGetExecutionSignature() {
CodeTreeBuilder builder = method.createBuilder();
builder.startReturn();

builder.startStaticCall(context.getType(Arrays.class), "asList");
builder.startStaticCall(context.getType(List.class), "of");
for (NodeExecutionData execution : node.getChildExecutions()) {
TypeMirror nodeType = execution.getNodeType();
if (nodeType != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -779,14 +779,13 @@ public List<CodeTypeElement> create(ProcessorContext context1, AnnotationProcess
builder = implConstructor.createBuilder();
builder.startStatement();
builder.startSuperCall().staticReference(libraryClassLiteral);
builder.startStaticCall(context.getType(Collections.class), "unmodifiableList");
builder.startStaticCall(context.getType(Arrays.class), "asList");
builder.startStaticCall(context.getType(List.class), "of");
for (MessageObjects message : methods) {
if (message.messageField != null) {
builder.field(null, message.messageField);
}
}
builder.end().end(); // unmodfiiableList, asList
builder.end(); // of
builder.end(); // superCall
builder.end(); // statement

Expand Down

0 comments on commit c069de7

Please sign in to comment.