Skip to content

Commit 2890be7

Browse files
authored
Simplify calls to List.toArray()
1 parent 1cf6f32 commit 2890be7

File tree

15 files changed

+16
-20
lines changed

15 files changed

+16
-20
lines changed

checker-qual/src/main/java/org/checkerframework/checker/formatter/qual/ConversionCategory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ public enum ConversionCategory {
144144
typesWithPrimitives.add(unwrapped);
145145
}
146146
}
147-
this.types = typesWithPrimitives.toArray(new Class<?>[typesWithPrimitives.size()]);
147+
this.types = typesWithPrimitives.toArray(new Class<?>[0]);
148148
}
149149
}
150150

checker-util/src/main/java/org/checkerframework/checker/formatter/util/FormatUtil.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ private static Conversion[] parse(String format) {
257257
cs.add(new Conversion(c, indexFromFormat(m)));
258258
}
259259
}
260-
return cs.toArray(new Conversion[cs.size()]);
260+
return cs.toArray(new Conversion[0]);
261261
}
262262

263263
public static class ExcessiveOrMissingFormatArgumentException

checker/src/main/java/org/checkerframework/checker/calledmethods/CalledMethodsAnnotatedTypeFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,7 @@ private AnnotationMirror ensuresCMAnno(String expression, List<String> calledMet
452452
private AnnotationMirror ensuresCMAnno(String[] expressions, List<String> calledMethods) {
453453
AnnotationBuilder builder = new AnnotationBuilder(processingEnv, EnsuresCalledMethods.class);
454454
builder.setValue("value", expressions);
455-
builder.setValue("methods", calledMethods.toArray(new String[calledMethods.size()]));
455+
builder.setValue("methods", calledMethods.toArray(new String[0]));
456456
AnnotationMirror am = builder.build();
457457
return am;
458458
}

checker/src/main/java/org/checkerframework/checker/index/samelen/SameLenAnnotatedTypeFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ public List<String> getSameLensFromString(
374374
*/
375375
public AnnotationMirror createSameLen(Collection<String> exprs) {
376376
AnnotationBuilder builder = new AnnotationBuilder(processingEnv, SameLen.class);
377-
String[] exprArray = exprs.toArray(new String[exprs.size()]);
377+
String[] exprArray = exprs.toArray(new String[0]);
378378
builder.setValue("value", exprArray);
379379
return builder.build();
380380
}

checker/src/main/java/org/checkerframework/checker/index/searchindex/SearchIndexAnnotatedTypeFactory.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,7 @@ public AnnotationMirror greatestLowerBoundQualifiers(AnnotationMirror a1, Annota
139139
Set<String> combinedSet = new HashSet<>(getValueElement(a1));
140140
combinedSet.addAll(getValueElement(a2));
141141
// The list is backed by the given array.
142-
List<String> combinedList =
143-
Arrays.asList(combinedSet.toArray(new String[combinedSet.size()]));
142+
List<String> combinedList = Arrays.asList(combinedSet.toArray(new String[0]));
144143

145144
// NegativeIndexFor <: SearchIndexFor.
146145
if (areSameByClass(a1, NegativeIndexFor.class)

checker/src/main/java/org/checkerframework/checker/mustcall/MustCallAnnotatedTypeFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ public AnnotationMirror createMustCall(List<String> val) {
431431
*/
432432
private AnnotationMirror createMustCallImpl(List<String> methodList) {
433433
AnnotationBuilder builder = new AnnotationBuilder(processingEnv, MustCall.class);
434-
String[] methodArray = methodList.toArray(new String[methodList.size()]);
434+
String[] methodArray = methodList.toArray(new String[0]);
435435
Arrays.sort(methodArray);
436436
builder.setValue("value", methodArray);
437437
return builder.build();

checker/src/main/java/org/checkerframework/checker/resourceleak/MustCallConsistencyAnalyzer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2482,7 +2482,7 @@ private void incrementMustCallImpl(TypeMirror type) {
24822482
// Create this annotation and use a subtype test because there's no guarantee that
24832483
// cmAnno is actually an instance of CalledMethods: it could be CMBottom or CMPredicate.
24842484
AnnotationMirror cmAnnoForMustCallMethods =
2485-
typeFactory.createCalledMethods(mustCallValues.toArray(new String[mustCallValues.size()]));
2485+
typeFactory.createCalledMethods(mustCallValues.toArray(new String[0]));
24862486
return typeFactory
24872487
.getQualifierHierarchy()
24882488
.isSubtypeQualifiersOnly(cmAnno, cmAnnoForMustCallMethods);

checker/src/main/java/org/checkerframework/checker/resourceleak/MustCallInference.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -564,8 +564,7 @@ private void addEnsuresCalledMethodsForDisposedFields() {
564564
for (String mustCallValue : methodToFields.keySet()) {
565565
Set<String> fields = methodToFields.get(mustCallValue);
566566
AnnotationMirror am =
567-
createEnsuresCalledMethods(
568-
fields.toArray(new String[fields.size()]), new String[] {mustCallValue});
567+
createEnsuresCalledMethods(fields.toArray(new String[0]), new String[] {mustCallValue});
569568
WholeProgramInference wpi = resourceLeakAtf.getWholeProgramInference();
570569
wpi.addMethodDeclarationAnnotation(methodElt, am);
571570
}

framework/src/main/java/org/checkerframework/common/basetype/BaseTypeChecker.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -827,8 +827,7 @@ public Set<String> getSupportedOptions() {
827827
}
828828

829829
options.addAll(
830-
expandCFOptions(
831-
Arrays.asList(this.getClass()), options.toArray(new String[options.size()])));
830+
expandCFOptions(Arrays.asList(this.getClass()), options.toArray(new String[0])));
832831

833832
supportedOptions = Collections.unmodifiableSet(options);
834833
}

framework/src/main/java/org/checkerframework/common/initializedfields/InitializedFieldsAnnotatedTypeFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ private String[] fieldsToInitialize(TypeElement type) {
207207
}
208208
}
209209

210-
return result.toArray(new String[result.size()]);
210+
return result.toArray(new String[0]);
211211
}
212212

213213
/**

framework/src/main/java/org/checkerframework/common/value/ValueAnnotatedTypeFactory.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1205,7 +1205,7 @@ public AnnotationMirror createMatchesRegexAnnotation(@Nullable List<@Regex Strin
12051205
return BOTTOMVAL;
12061206
}
12071207
AnnotationBuilder builder = new AnnotationBuilder(processingEnv, MatchesRegex.class);
1208-
builder.setValue("value", regexes.toArray(new String[regexes.size()]));
1208+
builder.setValue("value", regexes.toArray(new String[0]));
12091209
return builder.build();
12101210
}
12111211

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

framework/src/main/java/org/checkerframework/framework/source/AggregateChecker.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,7 @@ public final Set<String> getSupportedOptions() {
148148
options.addAll(checker.getSupportedOptions());
149149
}
150150
options.addAll(
151-
expandCFOptions(
152-
Arrays.asList(this.getClass()), options.toArray(new String[options.size()])));
151+
expandCFOptions(Arrays.asList(this.getClass()), options.toArray(new String[0])));
153152
this.supportedOptions = options;
154153
}
155154
return this.supportedOptions;

framework/src/main/java/org/checkerframework/framework/type/AnnotatedTypeFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1008,7 +1008,7 @@ public void setRoot(@Nullable CompilationUnitTree root) {
10081008
}
10091009
if (candidateAjavaFiles.size() == 1) {
10101010
currentFileAjavaTypes = new AnnotationFileElementTypes(this);
1011-
String ajavaPath = candidateAjavaFiles.toArray(new String[candidateAjavaFiles.size()])[0];
1011+
String ajavaPath = candidateAjavaFiles.toArray(new String[0])[0];
10121012
try {
10131013
currentFileAjavaTypes.parseAjavaFileWithTree(ajavaPath, root);
10141014
} catch (Throwable e) {

framework/src/main/java/org/checkerframework/framework/util/CheckerMain.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -573,7 +573,7 @@ public int invokeCompiler() {
573573
}
574574

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

579579
private static void outputArgumentsToFile(String outputFilename, List<String> args) {

framework/src/test/java/org/checkerframework/framework/test/junit/RangeTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ public RangeTest() {
105105
}
106106
}
107107
}
108-
ranges = rangesList.toArray(new Range[rangesList.size()]);
108+
ranges = rangesList.toArray(new Range[0]);
109109
}
110110

111111
/** The element is a member of the range. */

0 commit comments

Comments
 (0)