Skip to content

Commit

Permalink
Simplify calls to List.toArray()
Browse files Browse the repository at this point in the history
  • Loading branch information
mernst committed Apr 28, 2024
1 parent 1cf6f32 commit 2890be7
Show file tree
Hide file tree
Showing 15 changed files with 16 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ public enum ConversionCategory {
typesWithPrimitives.add(unwrapped);
}
}
this.types = typesWithPrimitives.toArray(new Class<?>[typesWithPrimitives.size()]);
this.types = typesWithPrimitives.toArray(new Class<?>[0]);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ private static Conversion[] parse(String format) {
cs.add(new Conversion(c, indexFromFormat(m)));
}
}
return cs.toArray(new Conversion[cs.size()]);
return cs.toArray(new Conversion[0]);
}

public static class ExcessiveOrMissingFormatArgumentException
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ private AnnotationMirror ensuresCMAnno(String expression, List<String> calledMet
private AnnotationMirror ensuresCMAnno(String[] expressions, List<String> calledMethods) {
AnnotationBuilder builder = new AnnotationBuilder(processingEnv, EnsuresCalledMethods.class);
builder.setValue("value", expressions);
builder.setValue("methods", calledMethods.toArray(new String[calledMethods.size()]));
builder.setValue("methods", calledMethods.toArray(new String[0]));
AnnotationMirror am = builder.build();
return am;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ public List<String> getSameLensFromString(
*/
public AnnotationMirror createSameLen(Collection<String> exprs) {
AnnotationBuilder builder = new AnnotationBuilder(processingEnv, SameLen.class);
String[] exprArray = exprs.toArray(new String[exprs.size()]);
String[] exprArray = exprs.toArray(new String[0]);
builder.setValue("value", exprArray);
return builder.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,7 @@ public AnnotationMirror greatestLowerBoundQualifiers(AnnotationMirror a1, Annota
Set<String> combinedSet = new HashSet<>(getValueElement(a1));
combinedSet.addAll(getValueElement(a2));
// The list is backed by the given array.
List<String> combinedList =
Arrays.asList(combinedSet.toArray(new String[combinedSet.size()]));
List<String> combinedList = Arrays.asList(combinedSet.toArray(new String[0]));

// NegativeIndexFor <: SearchIndexFor.
if (areSameByClass(a1, NegativeIndexFor.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ public AnnotationMirror createMustCall(List<String> val) {
*/
private AnnotationMirror createMustCallImpl(List<String> methodList) {
AnnotationBuilder builder = new AnnotationBuilder(processingEnv, MustCall.class);
String[] methodArray = methodList.toArray(new String[methodList.size()]);
String[] methodArray = methodList.toArray(new String[0]);
Arrays.sort(methodArray);
builder.setValue("value", methodArray);
return builder.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2482,7 +2482,7 @@ private void incrementMustCallImpl(TypeMirror type) {
// Create this annotation and use a subtype test because there's no guarantee that
// cmAnno is actually an instance of CalledMethods: it could be CMBottom or CMPredicate.
AnnotationMirror cmAnnoForMustCallMethods =
typeFactory.createCalledMethods(mustCallValues.toArray(new String[mustCallValues.size()]));
typeFactory.createCalledMethods(mustCallValues.toArray(new String[0]));
return typeFactory
.getQualifierHierarchy()
.isSubtypeQualifiersOnly(cmAnno, cmAnnoForMustCallMethods);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -564,8 +564,7 @@ private void addEnsuresCalledMethodsForDisposedFields() {
for (String mustCallValue : methodToFields.keySet()) {
Set<String> fields = methodToFields.get(mustCallValue);
AnnotationMirror am =
createEnsuresCalledMethods(
fields.toArray(new String[fields.size()]), new String[] {mustCallValue});
createEnsuresCalledMethods(fields.toArray(new String[0]), new String[] {mustCallValue});
WholeProgramInference wpi = resourceLeakAtf.getWholeProgramInference();
wpi.addMethodDeclarationAnnotation(methodElt, am);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -827,8 +827,7 @@ public Set<String> getSupportedOptions() {
}

options.addAll(
expandCFOptions(
Arrays.asList(this.getClass()), options.toArray(new String[options.size()])));
expandCFOptions(Arrays.asList(this.getClass()), options.toArray(new String[0])));

supportedOptions = Collections.unmodifiableSet(options);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ private String[] fieldsToInitialize(TypeElement type) {
}
}

return result.toArray(new String[result.size()]);
return result.toArray(new String[0]);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1205,7 +1205,7 @@ public AnnotationMirror createMatchesRegexAnnotation(@Nullable List<@Regex Strin
return BOTTOMVAL;
}
AnnotationBuilder builder = new AnnotationBuilder(processingEnv, MatchesRegex.class);
builder.setValue("value", regexes.toArray(new String[regexes.size()]));
builder.setValue("value", regexes.toArray(new String[0]));
return builder.build();
}

Expand All @@ -1223,7 +1223,7 @@ public AnnotationMirror createDoesNotMatchRegexAnnotation(@Nullable List<@Regex
return UNKNOWNVAL;
}
AnnotationBuilder builder = new AnnotationBuilder(processingEnv, DoesNotMatchRegex.class);
builder.setValue("value", regexes.toArray(new String[regexes.size()]));
builder.setValue("value", regexes.toArray(new String[0]));
return builder.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,7 @@ public final Set<String> getSupportedOptions() {
options.addAll(checker.getSupportedOptions());
}
options.addAll(
expandCFOptions(
Arrays.asList(this.getClass()), options.toArray(new String[options.size()])));
expandCFOptions(Arrays.asList(this.getClass()), options.toArray(new String[0])));
this.supportedOptions = options;
}
return this.supportedOptions;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1008,7 +1008,7 @@ public void setRoot(@Nullable CompilationUnitTree root) {
}
if (candidateAjavaFiles.size() == 1) {
currentFileAjavaTypes = new AnnotationFileElementTypes(this);
String ajavaPath = candidateAjavaFiles.toArray(new String[candidateAjavaFiles.size()])[0];
String ajavaPath = candidateAjavaFiles.toArray(new String[0])[0];
try {
currentFileAjavaTypes.parseAjavaFileWithTree(ajavaPath, root);
} catch (Throwable e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,7 @@ public int invokeCompiler() {
}

// Actually invoke the compiler
return ExecUtil.execute(args.toArray(new String[args.size()]), System.out, System.err);
return ExecUtil.execute(args.toArray(new String[0]), System.out, System.err);
}

private static void outputArgumentsToFile(String outputFilename, List<String> args) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public RangeTest() {
}
}
}
ranges = rangesList.toArray(new Range[rangesList.size()]);
ranges = rangesList.toArray(new Range[0]);
}

/** The element is a member of the range. */
Expand Down

0 comments on commit 2890be7

Please sign in to comment.