Simplify collection expressions

This commit is contained in:
Juan Martín Sotuyo Dodero
2016-10-13 17:17:17 -03:00
parent 61b55bd7e5
commit 42277d7b8d
3 changed files with 13 additions and 21 deletions

View File

@@ -32,9 +32,7 @@ public abstract class AbstractPropertySource implements PropertySource {
* @return a copy of the property descriptors.
*/
protected List<PropertyDescriptor<?>> copyPropertyDescriptors() {
List<PropertyDescriptor<?>> copy = new ArrayList<>(propertyDescriptors.size());
copy.addAll(propertyDescriptors);
return copy;
return new ArrayList<>(propertyDescriptors);
}
/**
@@ -43,10 +41,7 @@ public abstract class AbstractPropertySource implements PropertySource {
* @return a copy of the values
*/
protected Map<PropertyDescriptor<?>, Object> copyPropertyValues() {
Map<PropertyDescriptor<?>, Object> copy = new HashMap<>(
propertyValuesByDescriptor.size());
copy.putAll(propertyValuesByDescriptor);
return copy;
return new HashMap<>(propertyValuesByDescriptor);
}
/**

View File

@@ -7,18 +7,22 @@ import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.apache.commons.io.IOUtils;
import net.sourceforge.pmd.benchmark.Benchmark;
import net.sourceforge.pmd.benchmark.Benchmarker;
import net.sourceforge.pmd.lang.*;
import net.sourceforge.pmd.lang.Language;
import net.sourceforge.pmd.lang.LanguageVersion;
import net.sourceforge.pmd.lang.LanguageVersionHandler;
import net.sourceforge.pmd.lang.Parser;
import net.sourceforge.pmd.lang.VisitorStarter;
import net.sourceforge.pmd.lang.ast.Node;
import net.sourceforge.pmd.lang.ast.ParseException;
import net.sourceforge.pmd.lang.xpath.Initializer;
import org.apache.commons.io.IOUtils;
public class SourceCodeProcessor {
private final PMDConfiguration configuration;
@@ -141,13 +145,10 @@ public class SourceCodeProcessor {
usesDFA(languageVersion, rootNode, ruleSets, language);
usesTypeResolution(languageVersion, rootNode, ruleSets,language);
List<Node> acus = new ArrayList<>();
acus.add(rootNode);
List<Node> acus = Collections.singletonList(rootNode);
ruleSets.apply(acus, ctx, language);
}
private void determineLanguage(RuleContext ctx) {
// If LanguageVersion of the source file is not known, make a determination
if (ctx.getLanguageVersion() == null) {

View File

@@ -68,15 +68,11 @@ public abstract class AbstractRule extends AbstractPropertySource implements Rul
}
private List<String> copyExamples() {
List<String> copy = new ArrayList<>(examples.size());
copy.addAll(examples);
return copy;
return new ArrayList<>(examples);
}
private List<String> copyRuleChainVisits() {
List<String> copy = new ArrayList<>(ruleChainVisits.size());
copy.addAll(ruleChainVisits);
return copy;
return new ArrayList<>(ruleChainVisits);
}
/**