Reports Collection.addAll() and Map.putAll() calls after instantiation of a collection using a constructor call without arguments. Such constructs can be replaced with a single call to a parametrized constructor which simplifies code. Also for some collections the replacement might be more performant.
Signed-off-by: Lars Grefer <eclipse@larsgrefer.de>
if (projectSourceFiles == null) {
return null;
}
- List<String> l = new ArrayList<>();
- l.addAll(projectSourceFiles);
+ List<String> l = new ArrayList<>(projectSourceFiles);
// If the processor options are specified build the command line options for the JDT compiler to see
String processor = compilerConfig.getProcessor();
if (processor != null && processor.length() != 0) {
String line = null;
while ((line = fr.readLine()) != null)
fileContents.add(line);
- List<String> originalFileContents = new ArrayList<>();
- originalFileContents.addAll(fileContents);
+ List<String> originalFileContents = new ArrayList<>(fileContents);
// See if the messages match
int msgCount = 0;
}
public Set<InstructionTargeter> getTargetersCopy() {
- Set<InstructionTargeter> copy = new HashSet<>();
- copy.addAll(targeters);
+ Set<InstructionTargeter> copy = new HashSet<>(targeters);
return copy;
}
this.lastLine = lastLine;
this.file = file;
this.hasLicense = hasLicense;
- List<String> newYears = new ArrayList<>();
- newYears.addAll(years);
+ List<String> newYears = new ArrayList<>(years);
Collections.sort(newYears);
this.years = Collections.unmodifiableList(newYears);
if ((null == file) || !file.canWrite()) {
}
List<Sample> getSortedSamples(Comparator<Sample> comparer) {
- ArrayList<Sample> result = new ArrayList<>();
- result.addAll(samples);
+ ArrayList<Sample> result = new ArrayList<>(samples);
result.sort(comparer);
return result;
}
boolean incrementalMode = buildConfig.isIncrementalMode() || buildConfig.isIncrementalFileMode();
- List<File> xmlfileList = new ArrayList<>();
- xmlfileList.addAll(parser.getXmlFiles());
+ List<File> xmlfileList = new ArrayList<>(parser.getXmlFiles());
List<File> fileList = new ArrayList<>();
List<File> files = parser.getFiles();
Collections.addAll(typesToProcess, stbs);
}
- List<SourceTypeBinding> stb2 = new ArrayList<>();
- stb2.addAll(typesToProcess);
+ List<SourceTypeBinding> stb2 = new ArrayList<>(typesToProcess);
while (typesToProcess.size() > 0) {
// A side effect of weaveIntertypes() is that the processed type is removed from the collection
* classpath), and output dir or jar
*/
public List<String> getFullClasspath() {
- List<String> full = new ArrayList<>();
- full.addAll(getBootclasspath()); // XXX Is it OK that boot classpath overrides inpath/injars/aspectpath?
+ List<String> full = new ArrayList<>(getBootclasspath()); // XXX Is it OK that boot classpath overrides inpath/injars/aspectpath?
for (File file: inJars) {
full.add(file.getAbsolutePath());
}
List safeFiles = Collections.unmodifiableList(files);
log("Compiling ", safeFiles, handler);
if (1 == i) {
- ArrayList<String> argList = new ArrayList<>();
- argList.addAll(getBaseArgs(targetSrc, targetClasses));
+ ArrayList<String> argList = new ArrayList<>(getBaseArgs(targetSrc, targetClasses));
File[] fra = (File[]) safeFiles.toArray(new File[0]);
// sigh
argList.addAll(
theseShadowMungers.add(munger);
}
}
- Set<ShadowMunger> tempSet = new HashSet<>();
- tempSet.addAll(other.shadowMungers);
+ Set<ShadowMunger> tempSet = new HashSet<>(other.shadowMungers);
Set<ShadowMunger> otherShadowMungers = new HashSet<>();
Set<ShadowMunger> otherInlinedAroundMungers = new HashSet<>();
for (ShadowMunger munger : tempSet) {
WildAnnotationTypePattern watp = (WildAnnotationTypePattern) atp;
Map<String,String> m = watp.annotationValues;
Set<String> keys = m.keySet();
- List<String> orderedKeys = new ArrayList<>();
- orderedKeys.addAll(keys);
+ List<String> orderedKeys = new ArrayList<>(keys);
Collections.sort(orderedKeys);
StringBuffer sb = new StringBuffer();
for (Iterator<String> iterator = orderedKeys.iterator(); iterator.hasNext();) {
// package-private for testing
String[] makeCommand() {
- ArrayList result = new ArrayList();
if (0 < ignored.size()) {
for (Object o : ignored) {
logVerbose("ignored: " + o);
outjarFixedup = true;
}
- result.addAll(cmd.extractArguments());
+ ArrayList result = new ArrayList(cmd.extractArguments());
addListArgs(result);
String[] command = (String[]) result.toArray(new String[0]);
"-encoding", "-target" });
private static List<String> finalList(String[] args) {
- List<String> result = new ArrayList<>();
- result.addAll(Arrays.asList(args));
+ List<String> result = new ArrayList<>(Arrays.asList(args));
return Collections.unmodifiableList(result);
}
// read arguments
final ArrayList<String> globals = new ArrayList<>();
final ArrayList<String> files = new ArrayList<>();
- final LinkedList<String> argList = new LinkedList<>();
- argList.addAll(Arrays.asList(args));
+ final LinkedList<String> argList = new LinkedList<>(Arrays.asList(args));
for (int i = 0; i < argList.size(); i++) {
String arg = argList.get(i);
List<String> aliases = aliasOptions(arg);
createFailureMessage(output, -1, outputFound.size());
return;
}
- List<String> expected = new ArrayList<>();
- expected.addAll(expectedOutputLines);
- List<String> found = new ArrayList<>();
- found.addAll(outputFound);
+ List<String> expected = new ArrayList<>(expectedOutputLines);
+ List<String> found = new ArrayList<>(outputFound);
for (String lineFound : outputFound) {
for (String lineExpected : expectedOutputLines) {
if (lineFound.contains(lineExpected)) {
File[] files = sandbox.findFiles(spec.aspectpath);
aspectURLs = FileUtil.getFileURLs(files);
}
- ArrayList classpath = new ArrayList();
- classpath.addAll(Arrays.asList(aspectURLs));
+ ArrayList classpath = new ArrayList(Arrays.asList(aspectURLs));
final URL[] classURLs;
{
classpath.addAll(Arrays.asList(clAndLibs));
// skip if not file or not right time
return false;
}
- };
- ArrayList unexp = new ArrayList();
- unexp.addAll(Arrays.asList(dir.listFiles(touchedCollector)));
+ };
+ ArrayList unexp = new ArrayList(Arrays.asList(dir.listFiles(touchedCollector)));
// report any unexpected changes
return Diffs.makeDiffs(label, expected, unexp, String.CASE_INSENSITIVE_ORDER);
* @see Util#combine(Object[], Object[])
*/
public static String[] combine(String[] one, String[] two) {
- ArrayList twoList = new ArrayList();
- twoList.addAll(org.aspectj.util.LangUtil.arrayAsList(two));
+ ArrayList twoList = new ArrayList(org.aspectj.util.LangUtil.arrayAsList(two));
ArrayList result = new ArrayList();
if (null != one) {
for (String s : one) {
if ((0 == actualListIn.size()) && (0 == expectedListIn.size()) ) {
return;
}
-
- ArrayList expected = new ArrayList();
- expected.addAll(expectedListIn);
+
+ ArrayList expected = new ArrayList(expectedListIn);
expected.sort(comparator);
-
- ArrayList actual = new ArrayList();
- actual.addAll(actualListIn);
+
+ ArrayList actual = new ArrayList(actualListIn);
actual.sort(comparator);
Iterator actualIter = actual.iterator();
Object act = null;
if (unmodifiable) {
return Collections.unmodifiableList(Arrays.asList(ra));
} else {
- ArrayList list = new ArrayList();
- list.addAll(Arrays.asList(ra));
+ ArrayList list = new ArrayList(Arrays.asList(ra));
return list;
}
}
String label = one + "?=" + two;
assertTrue(label, (null == one) == (null == two));
if (null != one) {
- ArrayList aone = new ArrayList();
- aone.addAll(one);
+ ArrayList aone = new ArrayList(one);
ArrayList atwo = new ArrayList();
aone.addAll(two);
Collections.sort(aone);
List getSampleMessageTexts() {
if (null == messageTexts) {
- ArrayList result = new ArrayList();
- result.addAll(Arrays.asList(new String[]
- { "one", "two", "now is the time for all good men..." }));
+ ArrayList result = new ArrayList(Arrays.asList(new String[]
+ {"one", "two", "now is the time for all good men..."}));
messageTexts = result;
}
return messageTexts;
* @return ArrayList with all input except those in trim (by name)
*/
private static ArrayList trimByName(List input, List trim) {
- ArrayList result = new ArrayList();
- result.addAll(input);
+ ArrayList result = new ArrayList(input);
if (!LangUtil.isEmpty(input) && !LangUtil.isEmpty(trim)) {
for (ListIterator iter = result.listIterator(); iter.hasNext();) {
TestResult inputItem = (TestResult) iter.next();
actualFailed = safeList(failed);
// stillPassing: expected.passed w/o broken, missingPasses
- passed = new ArrayList();
- passed.addAll(expectedPassed);
+ passed = new ArrayList(expectedPassed);
passed = trimByName(passed, this.broken);
ArrayList missingPasses = new ArrayList();
ArrayList missingFails = new ArrayList();
stillPassing = safeList(passed);
// stillFailing: expected.failed w/o fixed, missingFails
- failed = new ArrayList();
- failed.addAll(expectedFailed);
+ failed = new ArrayList(expectedFailed);
failed = trimByName(failed, this.fixed);
failed = trimByName(failed, missingFails);
stillFailing = safeList(failed);
while ((expectedLine = expect.readLine()) != null) {
fileContents.add(expectedLine);
}
- List<String> expectedFileContents = new ArrayList<>();
- expectedFileContents.addAll(fileContents);
+ List<String> expectedFileContents = new ArrayList<>(fileContents);
// Load the file with the output from this test run
BufferedReader found = new BufferedReader(new FileReader(new File(modelOutput)));
if ((null == array) || (1 > array.length)) {
return Collections.emptyList();
}
- ArrayList<T> list = new ArrayList<>();
- list.addAll(Arrays.asList(array));
+ ArrayList<T> list = new ArrayList<>(Arrays.asList(array));
return list;
}
errors.add(error);
}
};
- List<String> sourceList = new ArrayList<>();
- sourceList.addAll(Arrays.asList(sources));
+ List<String> sourceList = new ArrayList<>(Arrays.asList(sources));
sourceList = Collections.unmodifiableList(sourceList);
for (int k = 0; k < sources.length; k++) {
List<String> result = FileUtil.lineSeek("" + k, sourceList, true, errorSink);
return false; // nothing to do
}
- Set<DeclareAnnotation> unusedDecams = new HashSet<>();
- unusedDecams.addAll(decaMs);
+ Set<DeclareAnnotation> unusedDecams = new HashSet<>(decaMs);
// These methods may have been targeted with declare annotation. Example: ITD on an interface
// where the top most implementor gets a real method. The top most implementor method
List<BcelField> fields = clazz.getFieldGens();
if (fields != null) {
- Set<DeclareAnnotation> unusedDecafs = new HashSet<>();
- unusedDecafs.addAll(decafs);
+ Set<DeclareAnnotation> unusedDecafs = new HashSet<>(decafs);
for (BcelField field : fields) {
if (!field.getName().startsWith(NameMangler.PREFIX)) {
// Single first pass
// ReferenceType.r = 0;
long stime = System.nanoTime();
for (int j = 0; j < 10; j++) {
- List objects2 = new ArrayList();
- objects2.addAll(objects);
+ List objects2 = new ArrayList(objects);
PartialOrder.sort(objects2);
}
long etime = System.nanoTime();
private void aroundTestAndOthers(String outName, final boolean matchOnlyPrintln)
throws IOException
{
-
- List<ShadowMunger> l = new ArrayList<>();
- // the afterReturning was taken out to avoid circular advice dependency
+ // the afterReturning was taken out to avoid circular advice dependency
- l.addAll(makeAdviceAll("before", matchOnlyPrintln));
+ List<ShadowMunger> l = new ArrayList<>(makeAdviceAll("before", matchOnlyPrintln));
//l.addAll(makeAdviceAll("afterReturning", matchOnlyPrintln));
l.add(makeAroundMunger(matchOnlyPrintln));
tps[parameterNumber].getAnnotationPattern().toString();
// parameter type annotation checking
- Set<String> expected = new HashSet<>();
- expected.addAll(mpnv.getParameterTypeAnnotations());
+ Set<String> expected = new HashSet<>(mpnv.getParameterTypeAnnotations());
StringTokenizer st = new StringTokenizer(expectedParameterTypeAnnotations==null?"":expectedParameterTypeAnnotations);
while (st.hasMoreTokens()) {
}
// parameter annotation checking
- expected = new HashSet<>();
- expected.addAll(mpnv.getParameterAnnotations());
+ expected = new HashSet<>(mpnv.getParameterAnnotations());
st = new StringTokenizer(expectedParameterAnnotations==null?"":expectedParameterAnnotations);
while (st.hasMoreTokens()) {