Merge branch 'java-7'
This commit is contained in:
@@ -22,9 +22,9 @@ import net.sourceforge.pmd.util.CollectionUtil;
|
||||
public abstract class AbstractPropertySource implements PropertySource {
|
||||
|
||||
/** The list of known properties that can be configured. */
|
||||
protected List<PropertyDescriptor<?>> propertyDescriptors = new ArrayList<PropertyDescriptor<?>>();
|
||||
protected List<PropertyDescriptor<?>> propertyDescriptors = new ArrayList<>();
|
||||
/** The values for each property. */
|
||||
protected Map<PropertyDescriptor<?>, Object> propertyValuesByDescriptor = new HashMap<PropertyDescriptor<?>, Object>();
|
||||
protected Map<PropertyDescriptor<?>, Object> propertyValuesByDescriptor = new HashMap<>();
|
||||
|
||||
/**
|
||||
* Creates a copied list of the property descriptors and returns it.
|
||||
@@ -32,7 +32,7 @@ public abstract class AbstractPropertySource implements PropertySource {
|
||||
* @return a copy of the property descriptors.
|
||||
*/
|
||||
protected List<PropertyDescriptor<?>> copyPropertyDescriptors() {
|
||||
List<PropertyDescriptor<?>> copy = new ArrayList<PropertyDescriptor<?>>(propertyDescriptors.size());
|
||||
List<PropertyDescriptor<?>> copy = new ArrayList<>(propertyDescriptors.size());
|
||||
copy.addAll(propertyDescriptors);
|
||||
return copy;
|
||||
}
|
||||
@@ -43,7 +43,7 @@ public abstract class AbstractPropertySource implements PropertySource {
|
||||
* @return a copy of the values
|
||||
*/
|
||||
protected Map<PropertyDescriptor<?>, Object> copyPropertyValues() {
|
||||
Map<PropertyDescriptor<?>, Object> copy = new HashMap<PropertyDescriptor<?>, Object>(
|
||||
Map<PropertyDescriptor<?>, Object> copy = new HashMap<>(
|
||||
propertyValuesByDescriptor.size());
|
||||
copy.putAll(propertyValuesByDescriptor);
|
||||
return copy;
|
||||
@@ -152,7 +152,7 @@ public abstract class AbstractPropertySource implements PropertySource {
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
|
||||
Map<PropertyDescriptor<?>, Object> propertiesByPropertyDescriptor = new HashMap<PropertyDescriptor<?>, Object>(
|
||||
Map<PropertyDescriptor<?>, Object> propertiesByPropertyDescriptor = new HashMap<>(
|
||||
propertyDescriptors.size());
|
||||
// Fill with existing explicitly values
|
||||
propertiesByPropertyDescriptor.putAll(this.propertyValuesByDescriptor);
|
||||
|
||||
@@ -67,7 +67,7 @@ public class PMD {
|
||||
* @see DBURI
|
||||
*/
|
||||
public static List<DataSource> getURIDataSources(String uriString) throws PMDException {
|
||||
List<DataSource> dataSources = new ArrayList<DataSource>();
|
||||
List<DataSource> dataSources = new ArrayList<>();
|
||||
|
||||
try {
|
||||
DBURI dbUri = new DBURI(uriString);
|
||||
@@ -156,7 +156,7 @@ public class PMD {
|
||||
*/
|
||||
private static Set<Rule> removeBrokenRules(RuleSets ruleSets) {
|
||||
|
||||
Set<Rule> brokenRules = new HashSet<Rule>();
|
||||
Set<Rule> brokenRules = new HashSet<>();
|
||||
ruleSets.removeDysfunctionalRules(brokenRules);
|
||||
|
||||
for (Rule rule : brokenRules) {
|
||||
@@ -229,7 +229,7 @@ public class PMD {
|
||||
long reportStart = System.nanoTime();
|
||||
try {
|
||||
Renderer renderer = configuration.createRenderer();
|
||||
List<Renderer> renderers = new LinkedList<Renderer>();
|
||||
List<Renderer> renderers = new LinkedList<>();
|
||||
renderers.add(renderer);
|
||||
|
||||
renderer.setWriter(IOUtil.createWriter(configuration.getReportFile()));
|
||||
@@ -389,7 +389,7 @@ public class PMD {
|
||||
|
||||
private static List<DataSource> internalGetApplicableFiles(PMDConfiguration configuration, Set<Language> languages) {
|
||||
LanguageFilenameFilter fileSelector = new LanguageFilenameFilter(languages);
|
||||
List<DataSource> files = new ArrayList<DataSource>();
|
||||
List<DataSource> files = new ArrayList<>();
|
||||
|
||||
if (null != configuration.getInputPaths()) {
|
||||
files.addAll(FileUtil.collectFiles(configuration.getInputPaths(), fileSelector));
|
||||
@@ -410,7 +410,7 @@ public class PMD {
|
||||
}
|
||||
|
||||
private static Set<Language> getApplicableLanguages(PMDConfiguration configuration, RuleSets ruleSets) {
|
||||
Set<Language> languages = new HashSet<Language>();
|
||||
Set<Language> languages = new HashSet<>();
|
||||
LanguageVersionDiscoverer discoverer = configuration.getLanguageVersionDiscoverer();
|
||||
|
||||
for (Rule rule : ruleSets.getAllRules()) {
|
||||
|
||||
@@ -201,16 +201,16 @@ public class Report implements Iterable<RuleViolation> {
|
||||
|
||||
// Note that this and the above data structure are both being maintained for
|
||||
// a bit
|
||||
private final List<RuleViolation> violations = new ArrayList<RuleViolation>();
|
||||
private final Set<Metric> metrics = new HashSet<Metric>();
|
||||
private final List<SynchronizedReportListener> listeners = new ArrayList<SynchronizedReportListener>();
|
||||
private final List<RuleViolation> violations = new ArrayList<>();
|
||||
private final Set<Metric> metrics = new HashSet<>();
|
||||
private final List<SynchronizedReportListener> listeners = new ArrayList<>();
|
||||
private List<ProcessingError> errors;
|
||||
private List<RuleConfigurationError> configErrors;
|
||||
private Map<Integer, String> linesToSuppress = new HashMap<Integer, String>();
|
||||
private Map<Integer, String> linesToSuppress = new HashMap<>();
|
||||
private long start;
|
||||
private long end;
|
||||
|
||||
private List<SuppressedViolation> suppressedRuleViolations = new ArrayList<SuppressedViolation>();
|
||||
private List<SuppressedViolation> suppressedRuleViolations = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* Configure the lines, that are suppressed via a NOPMD comment.
|
||||
@@ -232,7 +232,7 @@ public class Report implements Iterable<RuleViolation> {
|
||||
* @return violations per class name
|
||||
*/
|
||||
public Map<String, Integer> getCountSummary() {
|
||||
Map<String, Integer> summary = new HashMap<String, Integer>();
|
||||
Map<String, Integer> summary = new HashMap<>();
|
||||
for (RuleViolation rv : violationTree) {
|
||||
String key = keyFor(rv);
|
||||
Integer o = summary.get(key);
|
||||
@@ -252,7 +252,7 @@ public class Report implements Iterable<RuleViolation> {
|
||||
* of violations)
|
||||
*/
|
||||
public Map<String, Integer> getSummary() {
|
||||
Map<String, Integer> summary = new HashMap<String, Integer>();
|
||||
Map<String, Integer> summary = new HashMap<>();
|
||||
for (RuleViolation rv : violations) {
|
||||
String name = rv.getRule().getName();
|
||||
if (!summary.containsKey(name)) {
|
||||
@@ -323,7 +323,7 @@ public class Report implements Iterable<RuleViolation> {
|
||||
*/
|
||||
public void addConfigError(RuleConfigurationError error) {
|
||||
if (configErrors == null) {
|
||||
configErrors = new ArrayList<RuleConfigurationError>();
|
||||
configErrors = new ArrayList<>();
|
||||
}
|
||||
configErrors.add(error);
|
||||
}
|
||||
@@ -335,7 +335,7 @@ public class Report implements Iterable<RuleViolation> {
|
||||
*/
|
||||
public void addError(ProcessingError error) {
|
||||
if (errors == null) {
|
||||
errors = new ArrayList<ProcessingError>();
|
||||
errors = new ArrayList<>();
|
||||
}
|
||||
errors.add(error);
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ import net.sourceforge.pmd.lang.rule.RuleChainVisitor;
|
||||
*/
|
||||
public class RuleChain {
|
||||
// Mapping from Language to RuleChainVisitor
|
||||
private final Map<Language, RuleChainVisitor> languageToRuleChainVisitor = new HashMap<Language, RuleChainVisitor>();
|
||||
private final Map<Language, RuleChainVisitor> languageToRuleChainVisitor = new HashMap<>();
|
||||
|
||||
/**
|
||||
* Add all Rules from the given RuleSet which want to participate in the
|
||||
|
||||
@@ -39,7 +39,7 @@ public class RuleContext {
|
||||
* Default constructor.
|
||||
*/
|
||||
public RuleContext() {
|
||||
attributes = new ConcurrentHashMap<String, Object>();
|
||||
attributes = new ConcurrentHashMap<>();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -35,14 +35,14 @@ public class RuleSet {
|
||||
|
||||
private static final Logger LOG = Logger.getLogger(RuleSet.class.getName());
|
||||
|
||||
private List<Rule> rules = new ArrayList<Rule>();
|
||||
private List<Rule> rules = new ArrayList<>();
|
||||
private String fileName;
|
||||
private String name = "";
|
||||
private String description = "";
|
||||
|
||||
// TODO should these not be Sets or is their order important?
|
||||
private List<String> excludePatterns = new ArrayList<String>(0);
|
||||
private List<String> includePatterns = new ArrayList<String>(0);
|
||||
private List<String> excludePatterns = new ArrayList<>(0);
|
||||
private List<String> includePatterns = new ArrayList<>(0);
|
||||
|
||||
private Filter<File> filter;
|
||||
|
||||
@@ -251,7 +251,7 @@ public class RuleSet {
|
||||
RuleSetReference ruleSetReference = new RuleSetReference(ruleSet.getFileName());
|
||||
ruleSetReference.setAllRules(allRules);
|
||||
if (excludes != null) {
|
||||
ruleSetReference.setExcludes(new HashSet<String>(Arrays.asList(excludes)));
|
||||
ruleSetReference.setExcludes(new HashSet<>(Arrays.asList(excludes)));
|
||||
}
|
||||
for (Rule rule : ruleSet.getRules()) {
|
||||
RuleReference ruleReference = new RuleReference(rule, ruleSetReference);
|
||||
|
||||
@@ -88,7 +88,7 @@ public class RuleSetFactory {
|
||||
public Iterator<RuleSet> getRegisteredRuleSets() throws RuleSetNotFoundException {
|
||||
String rulesetsProperties = null;
|
||||
try {
|
||||
List<RuleSetReferenceId> ruleSetReferenceIds = new ArrayList<RuleSetReferenceId>();
|
||||
List<RuleSetReferenceId> ruleSetReferenceIds = new ArrayList<>();
|
||||
for (Language language : LanguageRegistry.findWithRuleSupport()) {
|
||||
Properties props = new Properties();
|
||||
rulesetsProperties = "rulesets/" + language.getTerseName() + "/rulesets.properties";
|
||||
@@ -332,7 +332,7 @@ public class RuleSetFactory {
|
||||
ruleSetReference.setRuleSetFileName(ref);
|
||||
String priority = null;
|
||||
NodeList childNodes = ruleElement.getChildNodes();
|
||||
Set<String> excludedRulesCheck = new HashSet<String>();
|
||||
Set<String> excludedRulesCheck = new HashSet<>();
|
||||
for (int i = 0; i < childNodes.getLength(); i++) {
|
||||
Node child = childNodes.item(i);
|
||||
if (isElementNode(child, "exclude")) {
|
||||
@@ -676,7 +676,6 @@ public class RuleSetFactory {
|
||||
* @param rule The Rule to which the property should be added. //@param
|
||||
* propertyNode Must be a property element node.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
// private static void parsePropertyNode(Rule rule, Node propertyNode) {
|
||||
// Element propertyElement = (Element) propertyNode;
|
||||
// String name = propertyElement.getAttribute("name");
|
||||
@@ -715,12 +714,11 @@ public class RuleSetFactory {
|
||||
// rule.definePropertyDescriptor(propertyDescriptor);
|
||||
// }
|
||||
// }
|
||||
private static void setValue(Rule rule, PropertyDescriptor desc, String strValue) {
|
||||
Object realValue = desc.valueFrom(strValue);
|
||||
private static <T> void setValue(Rule rule, PropertyDescriptor<T> desc, String strValue) {
|
||||
T realValue = desc.valueFrom(strValue);
|
||||
rule.setProperty(desc, realValue);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private static void parsePropertyNodeBR(Rule rule, Node propertyNode) {
|
||||
|
||||
Element propertyElement = (Element) propertyNode;
|
||||
@@ -750,7 +748,7 @@ public class RuleSetFactory {
|
||||
}
|
||||
|
||||
Map<String, Boolean> valueKeys = pdFactory.expectedFields();
|
||||
Map<String, String> values = new HashMap<String, String>(valueKeys.size());
|
||||
Map<String, String> values = new HashMap<>(valueKeys.size());
|
||||
|
||||
// populate a map of values for an individual descriptor
|
||||
for (Map.Entry<String, Boolean> entry : valueKeys.entrySet()) {
|
||||
@@ -764,7 +762,7 @@ public class RuleSetFactory {
|
||||
}
|
||||
|
||||
PropertyDescriptor<?> desc = pdFactory.createWith(values);
|
||||
PropertyDescriptorWrapper<?> wrapper = new PropertyDescriptorWrapper(desc);
|
||||
PropertyDescriptorWrapper<?> wrapper = new PropertyDescriptorWrapper<>(desc);
|
||||
|
||||
rule.definePropertyDescriptor(wrapper);
|
||||
setValue(rule, desc, strValue);
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
package net.sourceforge.pmd;
|
||||
|
||||
public class RuleSetNotFoundException extends Exception {
|
||||
private static final long serialVersionUID = -4617033110919250810L;
|
||||
|
||||
public RuleSetNotFoundException(String msg) {
|
||||
super(msg);
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ import java.util.Set;
|
||||
public class RuleSetReference {
|
||||
private String ruleSetFileName;
|
||||
private boolean allRules;
|
||||
private Set<String> excludes = new LinkedHashSet<String>(0);
|
||||
private Set<String> excludes = new LinkedHashSet<>(0);
|
||||
|
||||
public RuleSetReference() { }
|
||||
|
||||
|
||||
@@ -288,13 +288,12 @@ public class RuleSetReferenceId {
|
||||
}
|
||||
|
||||
private static boolean isHttpUrl(String name) {
|
||||
|
||||
if (name == null) {
|
||||
String stripped = StringUtils.strip(name);
|
||||
if (stripped == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
name = StringUtils.strip(name);
|
||||
if (name.startsWith("http://") || name.startsWith("https://")) {
|
||||
if (stripped.startsWith("http://") || stripped.startsWith("https://")) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -333,7 +332,7 @@ public class RuleSetReferenceId {
|
||||
* @return The corresponding List of RuleSetReferenceId instances.
|
||||
*/
|
||||
public static List<RuleSetReferenceId> parse(String referenceString) {
|
||||
List<RuleSetReferenceId> references = new ArrayList<RuleSetReferenceId>();
|
||||
List<RuleSetReferenceId> references = new ArrayList<>();
|
||||
if (referenceString != null && referenceString.trim().length() > 0) {
|
||||
|
||||
if (referenceString.indexOf(',') == -1) {
|
||||
|
||||
@@ -60,7 +60,7 @@ public class RuleSetWriter {
|
||||
documentBuilderFactory.setNamespaceAware(true);
|
||||
DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
|
||||
document = documentBuilder.newDocument();
|
||||
ruleSetFileNames = new HashSet<String>();
|
||||
ruleSetFileNames = new HashSet<>();
|
||||
|
||||
Element ruleSetElement = createRuleSetElement(ruleSet);
|
||||
document.appendChild(ruleSetElement);
|
||||
|
||||
@@ -23,7 +23,7 @@ public class RuleSets {
|
||||
/**
|
||||
* Map of RuleLanguage on RuleSet.
|
||||
*/
|
||||
private Collection<RuleSet> ruleSets = new ArrayList<RuleSet>();
|
||||
private Collection<RuleSet> ruleSets = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* RuleChain for efficient AST visitation.
|
||||
@@ -77,7 +77,7 @@ public class RuleSets {
|
||||
* @return Set
|
||||
*/
|
||||
public Set<Rule> getAllRules() {
|
||||
Set<Rule> result = new HashSet<Rule>();
|
||||
Set<Rule> result = new HashSet<>();
|
||||
for (RuleSet r : ruleSets) {
|
||||
result.addAll(r.getRules());
|
||||
}
|
||||
|
||||
@@ -141,7 +141,7 @@ public class SourceCodeProcessor {
|
||||
usesDFA(languageVersion, rootNode, ruleSets, language);
|
||||
usesTypeResolution(languageVersion, rootNode, ruleSets,language);
|
||||
|
||||
List<Node> acus = new ArrayList<Node>();
|
||||
List<Node> acus = new ArrayList<>();
|
||||
acus.add(rootNode);
|
||||
ruleSets.apply(acus, ctx, language);
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ public class Formatter {
|
||||
private String type;
|
||||
private boolean toConsole;
|
||||
private boolean showSuppressed;
|
||||
private final List<Parameter> parameters = new ArrayList<Parameter>();
|
||||
private final List<Parameter> parameters = new ArrayList<>();
|
||||
|
||||
public void setShowSuppressed(boolean value) {
|
||||
this.showSuppressed = value;
|
||||
|
||||
@@ -20,8 +20,8 @@ public class PMDTask extends Task {
|
||||
|
||||
private Path classpath;
|
||||
private Path auxClasspath;
|
||||
private final List<Formatter> formatters = new ArrayList<Formatter>();
|
||||
private final List<FileSet> filesets = new ArrayList<FileSet>();
|
||||
private final List<Formatter> formatters = new ArrayList<>();
|
||||
private final List<FileSet> filesets = new ArrayList<>();
|
||||
private boolean failOnError;
|
||||
private boolean failOnRuleViolation;
|
||||
private boolean shortFilenames;
|
||||
@@ -33,7 +33,7 @@ public class PMDTask extends Task {
|
||||
private int maxRuleViolations = 0;
|
||||
private String failuresPropertyName;
|
||||
private SourceLanguage sourceLanguage;
|
||||
private final Collection<RuleSetWrapper> nestedRules = new ArrayList<RuleSetWrapper>();
|
||||
private final Collection<RuleSetWrapper> nestedRules = new ArrayList<>();
|
||||
|
||||
@Override
|
||||
public void execute() throws BuildException {
|
||||
|
||||
@@ -49,8 +49,8 @@ public class PMDTaskImpl {
|
||||
|
||||
private Path classpath;
|
||||
private Path auxClasspath;
|
||||
private final List<Formatter> formatters = new ArrayList<Formatter>();
|
||||
private final List<FileSet> filesets = new ArrayList<FileSet>();
|
||||
private final List<Formatter> formatters = new ArrayList<>();
|
||||
private final List<FileSet> filesets = new ArrayList<>();
|
||||
private final PMDConfiguration configuration = new PMDConfiguration();
|
||||
private boolean failOnError;
|
||||
private boolean failOnRuleViolation;
|
||||
@@ -138,7 +138,7 @@ public class PMDTaskImpl {
|
||||
final String separator = System.getProperty("file.separator");
|
||||
|
||||
for (FileSet fs : filesets) {
|
||||
List<DataSource> files = new LinkedList<DataSource>();
|
||||
List<DataSource> files = new LinkedList<>();
|
||||
DirectoryScanner ds = fs.getDirectoryScanner(project);
|
||||
String[] srcFiles = ds.getIncludedFiles();
|
||||
for (String srcFile : srcFiles) {
|
||||
@@ -173,7 +173,7 @@ public class PMDTaskImpl {
|
||||
return null;
|
||||
} // not relevant
|
||||
};
|
||||
List<Renderer> renderers = new LinkedList<Renderer>();
|
||||
List<Renderer> renderers = new LinkedList<>();
|
||||
renderers.add(logRenderer);
|
||||
for (Formatter formatter : formatters) {
|
||||
renderers.add(formatter.getRenderer());
|
||||
|
||||
@@ -103,7 +103,7 @@ public class Benchmarker {
|
||||
if (debug) {
|
||||
System.out.println("Checking directory " + srcDir);
|
||||
}
|
||||
Set<RuleDuration> results = new TreeSet<RuleDuration>();
|
||||
Set<RuleDuration> results = new TreeSet<>();
|
||||
RuleSetFactory factory = new RuleSetFactory();
|
||||
if (StringUtil.isNotEmpty(ruleset)) {
|
||||
stress(languageVersion, factory.createRuleSet(ruleset), dataSources, results, debug);
|
||||
@@ -185,7 +185,7 @@ public class Benchmarker {
|
||||
}
|
||||
}
|
||||
|
||||
private static final Map<String, BenchmarkResult> BENCHMARKS_BY_NAME = new HashMap<String, BenchmarkResult>();
|
||||
private static final Map<String, BenchmarkResult> BENCHMARKS_BY_NAME = new HashMap<>();
|
||||
|
||||
/**
|
||||
* @param type Benchmark
|
||||
|
||||
@@ -65,7 +65,7 @@ public class TextReport implements BenchmarkReport {
|
||||
*/
|
||||
public void generate(Map<String, BenchmarkResult> benchmarksByName, PrintStream out) {
|
||||
|
||||
List<BenchmarkResult> results = new ArrayList<BenchmarkResult>(benchmarksByName.values());
|
||||
List<BenchmarkResult> results = new ArrayList<>(benchmarksByName.values());
|
||||
|
||||
long[] totalTime = new long[Benchmark.TotalPMD.index + 1];
|
||||
long[] totalCount = new long[Benchmark.TotalPMD.index + 1];
|
||||
|
||||
@@ -64,7 +64,7 @@ public class PMDParameters {
|
||||
|
||||
@Parameter(names = { "-property", "-P" }, description = "{name}={value}: Define a property for the report format.",
|
||||
converter = PropertyConverter.class)
|
||||
private List<Properties> properties = new ArrayList<Properties>();
|
||||
private List<Properties> properties = new ArrayList<>();
|
||||
|
||||
@Parameter(names = { "-reportfile", "-r" }, description = "Sends report output to a file; default to System.out.")
|
||||
private String reportfile = null;
|
||||
|
||||
@@ -29,7 +29,7 @@ public class CPD {
|
||||
|
||||
private CPDConfiguration configuration;
|
||||
|
||||
private Map<String, SourceCode> source = new TreeMap<String, SourceCode>();
|
||||
private Map<String, SourceCode> source = new TreeMap<>();
|
||||
private CPDListener listener = new CPDNullListener();
|
||||
private Tokens tokens = new Tokens();
|
||||
private MatchAlgorithm matchAlgorithm;
|
||||
@@ -76,7 +76,7 @@ public class CPD {
|
||||
add(finder.findFilesFrom(dir, configuration.filenameFilter(), recurse));
|
||||
}
|
||||
|
||||
private Set<String> current = new HashSet<String>();
|
||||
private Set<String> current = new HashSet<>();
|
||||
|
||||
public void add(File file) throws IOException {
|
||||
|
||||
@@ -163,7 +163,7 @@ public class CPD {
|
||||
* @return names of sources to be processed
|
||||
*/
|
||||
public List<String> getSourcePaths() {
|
||||
return new ArrayList<String>(source.keySet());
|
||||
return new ArrayList<>(source.keySet());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -172,7 +172,7 @@ public class CPD {
|
||||
* @return all Sources to be processed
|
||||
*/
|
||||
public List<SourceCode> getSources() {
|
||||
return new ArrayList<SourceCode>(source.values());
|
||||
return new ArrayList<>(source.values());
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -157,7 +157,7 @@ public class CPDConfiguration extends AbstractConfiguration {
|
||||
return getRendererFromString(name, System.getProperty("file.encoding"));
|
||||
}
|
||||
|
||||
private static final Map<String, Class<? extends Renderer>> RENDERERS = new HashMap<String, Class<? extends Renderer>>();
|
||||
private static final Map<String, Class<? extends Renderer>> RENDERERS = new HashMap<>();
|
||||
static {
|
||||
RENDERERS.put(DEFAULT_RENDERER, SimpleRenderer.class);
|
||||
RENDERERS.put("xml", XMLRenderer.class);
|
||||
@@ -289,7 +289,7 @@ public class CPDConfiguration extends AbstractConfiguration {
|
||||
}
|
||||
|
||||
final FilenameFilter languageFilter = language.getFileFilter();
|
||||
final Set<String> exclusions = new HashSet<String>();
|
||||
final Set<String> exclusions = new HashSet<>();
|
||||
|
||||
if (excludes != null) {
|
||||
FileFinder finder = new FileFinder();
|
||||
|
||||
@@ -54,7 +54,7 @@ public class CPDTask extends Task {
|
||||
private String skipBlocksPattern = Tokenizer.DEFAULT_SKIP_BLOCKS_PATTERN;
|
||||
private File outputFile;
|
||||
private String encoding = System.getProperty("file.encoding");
|
||||
private List<FileSet> filesets = new ArrayList<FileSet>();
|
||||
private List<FileSet> filesets = new ArrayList<>();
|
||||
|
||||
public void execute() throws BuildException {
|
||||
ClassLoader oldClassloader = Thread.currentThread().getContextClassLoader();
|
||||
|
||||
@@ -142,7 +142,7 @@ public class GUI implements CPDListener {
|
||||
}
|
||||
|
||||
private static final int DEFAULT_CPD_MINIMUM_LENGTH = 75;
|
||||
private static final Map<String, LanguageConfig> LANGUAGE_CONFIGS_BY_LABEL = new HashMap<String, LanguageConfig>(LANGUAGE_SETS.length);
|
||||
private static final Map<String, LanguageConfig> LANGUAGE_CONFIGS_BY_LABEL = new HashMap<>(LANGUAGE_SETS.length);
|
||||
private static final KeyStroke COPY_KEY_STROKE = KeyStroke.getKeyStroke(KeyEvent.VK_C,ActionEvent.CTRL_MASK,false);
|
||||
private static final KeyStroke DELETE_KEY_STROKE = KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0);
|
||||
|
||||
@@ -158,10 +158,10 @@ public class GUI implements CPDListener {
|
||||
width = aWidth;
|
||||
sorter = aSorter;
|
||||
}
|
||||
public String label() { return label; };
|
||||
public int alignment() { return alignment; };
|
||||
public int width() { return width; };
|
||||
public Comparator<Match> sorter() { return sorter; };
|
||||
public String label() { return label; }
|
||||
public int alignment() { return alignment; }
|
||||
public int width() { return width; }
|
||||
public Comparator<Match> sorter() { return sorter; }
|
||||
}
|
||||
|
||||
private final ColumnSpec[] matchColumns = new ColumnSpec[] {
|
||||
@@ -255,12 +255,12 @@ public class GUI implements CPDListener {
|
||||
}
|
||||
|
||||
private class AlignmentRenderer extends DefaultTableCellRenderer {
|
||||
|
||||
private static final long serialVersionUID = -2190382865483285032L;
|
||||
private int[] alignments;
|
||||
|
||||
public AlignmentRenderer(int[] theAlignments) {
|
||||
alignments = theAlignments;
|
||||
};
|
||||
}
|
||||
|
||||
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
|
||||
super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
|
||||
@@ -283,7 +283,7 @@ public class GUI implements CPDListener {
|
||||
private JCheckBox ignoreLiteralsCheckbox = new JCheckBox("", false);
|
||||
private JCheckBox ignoreAnnotationsCheckbox = new JCheckBox("", false);
|
||||
private JCheckBox ignoreUsingsCheckbox = new JCheckBox("", false);
|
||||
private JComboBox languageBox = new JComboBox();
|
||||
private JComboBox<String> languageBox = new JComboBox<>();
|
||||
private JTextField extensionField = new JTextField();
|
||||
private JLabel extensionLabel = new JLabel("Extension:", SwingConstants.RIGHT);
|
||||
private JTable resultsTable = new JTable();
|
||||
@@ -293,7 +293,7 @@ public class GUI implements CPDListener {
|
||||
private JFrame frame;
|
||||
private boolean trimLeadingWhitespace;
|
||||
|
||||
private List<Match> matches = new ArrayList<Match>();
|
||||
private List<Match> matches = new ArrayList<>();
|
||||
|
||||
private void addSaveOptionsTo(JMenu menu) {
|
||||
|
||||
@@ -387,7 +387,7 @@ public class GUI implements CPDListener {
|
||||
helper.add(minimumLengthField);
|
||||
helper.addLabel("Language:");
|
||||
for (int i=0; i<LANGUAGE_SETS.length; i++) {
|
||||
languageBox.addItem(LANGUAGE_SETS[i][0]);
|
||||
languageBox.addItem(String.valueOf(LANGUAGE_SETS[i][0]));
|
||||
}
|
||||
languageBox.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
@@ -474,7 +474,7 @@ public class GUI implements CPDListener {
|
||||
private void populateResultArea() {
|
||||
int[] selectionIndices = resultsTable.getSelectedRows();
|
||||
TableModel model = resultsTable.getModel();
|
||||
List<Match> selections = new ArrayList<Match>(selectionIndices.length);
|
||||
List<Match> selections = new ArrayList<>(selectionIndices.length);
|
||||
for (int i=0; i<selectionIndices.length; i++) {
|
||||
selections.add((Match)model.getValueAt(selectionIndices[i], 99));
|
||||
}
|
||||
@@ -561,7 +561,7 @@ public class GUI implements CPDListener {
|
||||
|
||||
private String setLabelFor(Match match) {
|
||||
|
||||
Set<String> sourceIDs = new HashSet<String>(match.getMarkCount());
|
||||
Set<String> sourceIDs = new HashSet<>(match.getMarkCount());
|
||||
for (Iterator<Mark> occurrences = match.iterator(); occurrences.hasNext();) {
|
||||
sourceIDs.add(occurrences.next().getFilename());
|
||||
}
|
||||
@@ -631,14 +631,14 @@ public class GUI implements CPDListener {
|
||||
cpd.go();
|
||||
t.stop();
|
||||
|
||||
matches = new ArrayList<Match>();
|
||||
matches = new ArrayList<>();
|
||||
for (Iterator<Match> i = cpd.getMatches(); i.hasNext();) {
|
||||
Match match = i.next();
|
||||
setLabelFor(match);
|
||||
matches.add(match);
|
||||
}
|
||||
|
||||
setListDataFrom(cpd.getMatches());
|
||||
setListDataFrom(matches);
|
||||
String report = new SimpleRenderer().render(cpd.getMatches());
|
||||
if (report.length() == 0) {
|
||||
JOptionPane.showMessageDialog(frame,
|
||||
@@ -716,10 +716,10 @@ public class GUI implements CPDListener {
|
||||
public String getColumnName(int i) { return matchColumns[i].label(); }
|
||||
public void addTableModelListener(TableModelListener l) { }
|
||||
public void removeTableModelListener(TableModelListener l) { }
|
||||
public int sortColumn() { return sortColumn; };
|
||||
public void sortColumn(int column) { sortColumn = column; };
|
||||
public boolean sortDescending() { return sortDescending; };
|
||||
public void sortDescending(boolean flag) { sortDescending = flag; };
|
||||
public int sortColumn() { return sortColumn; }
|
||||
public void sortColumn(int column) { sortColumn = column; }
|
||||
public boolean sortDescending() { return sortDescending; }
|
||||
public void sortDescending(boolean flag) { sortDescending = flag; }
|
||||
public void sort(Comparator<Match> comparator) {
|
||||
Collections.sort(items, comparator);
|
||||
if (sortDescending) {
|
||||
@@ -744,7 +744,7 @@ public class GUI implements CPDListener {
|
||||
resultsTable.repaint();
|
||||
}
|
||||
|
||||
private void setListDataFrom(Iterator iter) {
|
||||
private void setListDataFrom(List<Match> matches) {
|
||||
|
||||
resultsTable.setModel(tableModelFrom(matches));
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ public final class LanguageFactory {
|
||||
supportedLanguages = instance.languages.keySet().toArray(new String[instance.languages.size()]);
|
||||
}
|
||||
|
||||
private Map<String, Language> languages = new HashMap<String, Language>();
|
||||
private Map<String, Language> languages = new HashMap<>();
|
||||
|
||||
private LanguageFactory() {
|
||||
ServiceLoader<Language> languageLoader = ServiceLoader.load(Language.class);
|
||||
|
||||
@@ -13,7 +13,7 @@ import java.util.TreeSet;
|
||||
public class Match implements Comparable<Match> {
|
||||
|
||||
private int tokenCount;
|
||||
private Set<Mark> markSet = new TreeSet<Mark>();
|
||||
private Set<Mark> markSet = new TreeSet<>();
|
||||
private String label;
|
||||
|
||||
public static final Comparator<Match> MATCHES_COMPARATOR = new Comparator<Match>() {
|
||||
|
||||
@@ -90,7 +90,7 @@ public class MatchAlgorithm {
|
||||
|
||||
@SuppressWarnings("PMD.JumbledIncrementer")
|
||||
private Map<TokenEntry, Object> hash() {
|
||||
Map<TokenEntry, Object> markGroups = new HashMap<TokenEntry, Object>(tokens.size());
|
||||
Map<TokenEntry, Object> markGroups = new HashMap<>(tokens.size());
|
||||
for (int i = code.size() - 1; i >= 0; i--) {
|
||||
TokenEntry token = code.get(i);
|
||||
if (token != TokenEntry.EOF) {
|
||||
@@ -104,7 +104,7 @@ public class MatchAlgorithm {
|
||||
if (o == null) {
|
||||
markGroups.put(token, token);
|
||||
} else if (o instanceof TokenEntry) {
|
||||
List<TokenEntry> l = new ArrayList<TokenEntry>();
|
||||
List<TokenEntry> l = new ArrayList<>();
|
||||
l.add((TokenEntry) o);
|
||||
l.add(token);
|
||||
markGroups.put(token, l);
|
||||
|
||||
@@ -10,8 +10,8 @@ import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class MatchCollector {
|
||||
private List<Match> matchList = new ArrayList<Match>();
|
||||
private Map<Integer, Map<Integer, Match>> matchTree = new TreeMap<Integer, Map<Integer, Match>>();
|
||||
private List<Match> matchList = new ArrayList<>();
|
||||
private Map<Integer, Map<Integer, Match>> matchTree = new TreeMap<>();
|
||||
private MatchAlgorithm ma;
|
||||
|
||||
public MatchCollector(MatchAlgorithm ma) {
|
||||
@@ -49,7 +49,7 @@ public class MatchCollector {
|
||||
private void reportMatch(TokenEntry mark1, TokenEntry mark2, int dupes) {
|
||||
Map<Integer, Match> matches = matchTree.get(dupes);
|
||||
if (matches == null) {
|
||||
matches = new TreeMap<Integer, Match>();
|
||||
matches = new TreeMap<>();
|
||||
matchTree.put(dupes, matches);
|
||||
addNewMatch(mark1, mark2, dupes, matches);
|
||||
} else {
|
||||
|
||||
@@ -7,8 +7,9 @@ package net.sourceforge.pmd.cpd;
|
||||
* @author Philippe T'Seyen
|
||||
*/
|
||||
public class ReportException extends Exception {
|
||||
private static final long serialVersionUID = 6043174086675858209L;
|
||||
|
||||
public ReportException(Throwable cause) {
|
||||
super();
|
||||
super(cause);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ public class SourceCode {
|
||||
if (c != null) {
|
||||
return c;
|
||||
}
|
||||
this.code = new SoftReference<List<String>>(load());
|
||||
this.code = new SoftReference<>(load());
|
||||
return code.get();
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ public class SourceCode {
|
||||
LineNumberReader lnr = null;
|
||||
try {
|
||||
lnr = new LineNumberReader(getReader());
|
||||
List<String> lines = new ArrayList<String>();
|
||||
List<String> lines = new ArrayList<>();
|
||||
String currentLine;
|
||||
while ((currentLine = lnr.readLine()) != null) {
|
||||
lines.add(currentLine);
|
||||
|
||||
@@ -22,7 +22,7 @@ public class TokenEntry implements Comparable<TokenEntry> {
|
||||
private static final ThreadLocal<Map<String, Integer>> TOKENS = new ThreadLocal<Map<String, Integer>>(){
|
||||
@Override
|
||||
protected Map<String, Integer> initialValue() {
|
||||
return new HashMap<String, Integer>();
|
||||
return new HashMap<>();
|
||||
}
|
||||
};
|
||||
private static final ThreadLocal<AtomicInteger> TOKEN_COUNT = new ThreadLocal<AtomicInteger>(){
|
||||
@@ -69,8 +69,8 @@ public class TokenEntry implements Comparable<TokenEntry> {
|
||||
private List<TokenEntry> entries;
|
||||
public State(List<TokenEntry> entries) {
|
||||
this.tokenCount = TokenEntry.TOKEN_COUNT.get().intValue();
|
||||
this.tokens = new HashMap<String, Integer>(TokenEntry.TOKENS.get());
|
||||
this.entries = new ArrayList<TokenEntry>(entries);
|
||||
this.tokens = new HashMap<>(TokenEntry.TOKENS.get());
|
||||
this.entries = new ArrayList<>(entries);
|
||||
}
|
||||
public List<TokenEntry> restore() {
|
||||
TokenEntry.TOKEN_COUNT.get().set(tokenCount);
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user