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>tags/V1_9_7M1
@@ -225,8 +225,7 @@ public class AjdeCoreBuildManager { | |||
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) { |
@@ -367,8 +367,7 @@ public class ShowWeaveMessagesTest extends AjdeCoreTestCase { | |||
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; |
@@ -170,8 +170,7 @@ public class InstructionHandle implements java.io.Serializable { | |||
} | |||
public Set<InstructionTargeter> getTargetersCopy() { | |||
Set<InstructionTargeter> copy = new HashSet<>(); | |||
copy.addAll(targeters); | |||
Set<InstructionTargeter> copy = new HashSet<>(targeters); | |||
return copy; | |||
} | |||
@@ -469,8 +469,7 @@ class HeaderInfo { | |||
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()) { |
@@ -419,8 +419,7 @@ class Samples { | |||
} | |||
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; | |||
} |
@@ -152,8 +152,7 @@ public class BuildArgParser extends Main { | |||
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(); |
@@ -250,8 +250,7 @@ public class AjLookupEnvironment extends LookupEnvironment implements AnonymousC | |||
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 |
@@ -377,8 +377,7 @@ public class AjBuildConfig implements CompilerConfigurationChangeFlags { | |||
* 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()); | |||
} |
@@ -121,8 +121,7 @@ public class IncrementalCase { // XXX NOT bound to junit - bridge tests? | |||
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( |
@@ -293,8 +293,7 @@ public class CrosscuttingMembers { | |||
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) { |
@@ -700,8 +700,7 @@ public class ParserTestCase extends PatternsTestCase { | |||
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();) { |
@@ -1159,7 +1159,6 @@ public class AjcTask extends MatchingTask { | |||
// package-private for testing | |||
String[] makeCommand() { | |||
ArrayList result = new ArrayList(); | |||
if (0 < ignored.size()) { | |||
for (Object o : ignored) { | |||
logVerbose("ignored: " + o); | |||
@@ -1182,7 +1181,7 @@ public class AjcTask extends MatchingTask { | |||
outjarFixedup = true; | |||
} | |||
result.addAll(cmd.extractArguments()); | |||
ArrayList result = new ArrayList(cmd.extractArguments()); | |||
addListArgs(result); | |||
String[] command = (String[]) result.toArray(new String[0]); |
@@ -53,8 +53,7 @@ public class Ajc extends DefaultCompilerAdapter { | |||
"-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); | |||
} | |||
@@ -213,8 +213,7 @@ public class Harness { | |||
// 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); |
@@ -87,10 +87,8 @@ public class OutputSpec { | |||
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)) { |
@@ -167,8 +167,7 @@ public class JavaRun implements IAjcRun { | |||
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)); |
@@ -185,9 +185,8 @@ public class FileUtil { | |||
// 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); |
@@ -402,8 +402,7 @@ public class LangUtil { | |||
* @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) { | |||
@@ -938,13 +937,11 @@ public class LangUtil { | |||
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; |
@@ -269,8 +269,7 @@ public class LangUtilTest extends TestCase { | |||
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; | |||
} | |||
} | |||
@@ -317,8 +316,7 @@ public class LangUtilTest extends TestCase { | |||
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); |
@@ -71,9 +71,8 @@ public class MessageUtilTest extends TestCase { | |||
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; |
@@ -141,8 +141,7 @@ public class TestDiffs { // XXX pretty dumb implementation | |||
* @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(); | |||
@@ -281,8 +280,7 @@ public class TestDiffs { // XXX pretty dumb implementation | |||
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(); | |||
@@ -291,8 +289,7 @@ public class TestDiffs { // XXX pretty dumb implementation | |||
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); |
@@ -143,8 +143,7 @@ public abstract class ModelTestCase extends XMLBasedAjcTestCase { | |||
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))); |
@@ -1000,8 +1000,7 @@ public class LangUtil { | |||
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; | |||
} | |||
@@ -508,8 +508,7 @@ public class FileUtilTest extends TestCase { | |||
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); |
@@ -923,8 +923,7 @@ class BcelClassWeaver implements IClassWeaver { | |||
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 | |||
@@ -1413,8 +1412,7 @@ class BcelClassWeaver implements IClassWeaver { | |||
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 |
@@ -599,8 +599,7 @@ public class ReferenceTypeTestCase extends TestCase { | |||
// 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(); |
@@ -80,12 +80,10 @@ public class AroundWeaveTestCase extends WeaveTestCase { | |||
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)); |
@@ -286,8 +286,7 @@ public class Java15PointcutExpressionTest extends TestCase { | |||
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()) { | |||
@@ -305,8 +304,7 @@ public class Java15PointcutExpressionTest extends TestCase { | |||
} | |||
// parameter annotation checking | |||
expected = new HashSet<>(); | |||
expected.addAll(mpnv.getParameterAnnotations()); | |||
expected = new HashSet<>(mpnv.getParameterAnnotations()); | |||
st = new StringTokenizer(expectedParameterAnnotations==null?"":expectedParameterAnnotations); | |||
while (st.hasMoreTokens()) { |