From 639f5030e0391e831138f9786cf831c3374449e7 Mon Sep 17 00:00:00 2001 From: Lars Grefer Date: Sat, 15 Aug 2020 17:01:46 +0200 Subject: Weaken Collection declarations Reports on declarations of Collection variables made by using the collection class as the type, rather than an appropriate interface. Signed-off-by: Lars Grefer --- .../aspectj/apache/bcel/generic/FieldGenOrMethodGen.java | 4 ++-- .../org/aspectj/apache/bcel/generic/InstructionList.java | 9 +++------ .../java/org/aspectj/apache/bcel/generic/MethodGen.java | 14 +++++--------- .../main/java/org/aspectj/apache/bcel/util/ClassPath.java | 10 +++------- 4 files changed, 13 insertions(+), 24 deletions(-) (limited to 'bcel-builder/src/main/java') diff --git a/bcel-builder/src/main/java/org/aspectj/apache/bcel/generic/FieldGenOrMethodGen.java b/bcel-builder/src/main/java/org/aspectj/apache/bcel/generic/FieldGenOrMethodGen.java index c8e1fe2fb..5b4256685 100644 --- a/bcel-builder/src/main/java/org/aspectj/apache/bcel/generic/FieldGenOrMethodGen.java +++ b/bcel-builder/src/main/java/org/aspectj/apache/bcel/generic/FieldGenOrMethodGen.java @@ -76,8 +76,8 @@ public abstract class FieldGenOrMethodGen extends Modifiers { protected String name; protected Type type; protected ConstantPool cp; - private ArrayList attributeList = new ArrayList<>(); - protected ArrayList annotationList = new ArrayList<>(); + private List attributeList = new ArrayList<>(); + protected List annotationList = new ArrayList<>(); protected FieldGenOrMethodGen() { } diff --git a/bcel-builder/src/main/java/org/aspectj/apache/bcel/generic/InstructionList.java b/bcel-builder/src/main/java/org/aspectj/apache/bcel/generic/InstructionList.java index 156adf0ad..7938218bc 100644 --- a/bcel-builder/src/main/java/org/aspectj/apache/bcel/generic/InstructionList.java +++ b/bcel-builder/src/main/java/org/aspectj/apache/bcel/generic/InstructionList.java @@ -58,10 +58,7 @@ import java.io.ByteArrayOutputStream; import java.io.DataOutputStream; import java.io.IOException; import java.io.Serializable; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Iterator; -import java.util.Set; +import java.util.*; import org.aspectj.apache.bcel.Constants; import org.aspectj.apache.bcel.classfile.Constant; @@ -690,7 +687,7 @@ public class InstructionList implements Serializable { return; } - ArrayList target_vec = new ArrayList<>(); + List target_vec = new ArrayList<>(); for (InstructionHandle ih = first; ih != null; ih = ih.next) { ih.getInstruction().dispose(); // e.g. BranchInstructions release their targets @@ -1003,7 +1000,7 @@ public class InstructionList implements Serializable { */ public Instruction[] getInstructions() { ByteSequence bytes = new ByteSequence(getByteCode()); - ArrayList instructions = new ArrayList<>(); + List instructions = new ArrayList<>(); try { while (bytes.available() > 0) { diff --git a/bcel-builder/src/main/java/org/aspectj/apache/bcel/generic/MethodGen.java b/bcel-builder/src/main/java/org/aspectj/apache/bcel/generic/MethodGen.java index cf8c06834..453fe7c1f 100644 --- a/bcel-builder/src/main/java/org/aspectj/apache/bcel/generic/MethodGen.java +++ b/bcel-builder/src/main/java/org/aspectj/apache/bcel/generic/MethodGen.java @@ -54,11 +54,7 @@ package org.aspectj.apache.bcel.generic; * . */ -import java.util.ArrayList; -import java.util.Hashtable; -import java.util.Iterator; -import java.util.List; -import java.util.Stack; +import java.util.*; import org.aspectj.apache.bcel.Constants; import org.aspectj.apache.bcel.classfile.Attribute; @@ -103,11 +99,11 @@ public class MethodGen extends FieldGenOrMethodGen { private int highestLineNumber = 0; - private ArrayList localVariablesList = new ArrayList<>(); - private ArrayList lineNumbersList = new ArrayList<>(); + private List localVariablesList = new ArrayList<>(); + private List lineNumbersList = new ArrayList<>(); private ArrayList exceptionsList = new ArrayList<>(); private ArrayList exceptionsThrown = new ArrayList<>(); - private ArrayList codeAttributesList = new ArrayList<>(); + private List codeAttributesList = new ArrayList<>(); private List[] param_annotations; // Array of lists containing AnnotationGen objects private boolean hasParameterAnnotations = false; private boolean haveUnpackedParameterAnnotations = false; @@ -934,7 +930,7 @@ public class MethodGen extends FieldGenOrMethodGen { static final class BranchStack { Stack branchTargets = new Stack<>(); - Hashtable visitedTargets = new Hashtable<>(); + Map visitedTargets = new Hashtable<>(); public void push(InstructionHandle target, int stackDepth) { if (visited(target)) { diff --git a/bcel-builder/src/main/java/org/aspectj/apache/bcel/util/ClassPath.java b/bcel-builder/src/main/java/org/aspectj/apache/bcel/util/ClassPath.java index 179800540..678abb1dc 100644 --- a/bcel-builder/src/main/java/org/aspectj/apache/bcel/util/ClassPath.java +++ b/bcel-builder/src/main/java/org/aspectj/apache/bcel/util/ClassPath.java @@ -69,11 +69,7 @@ import java.nio.file.Path; import java.nio.file.SimpleFileVisitor; import java.nio.file.attribute.BasicFileAttributeView; import java.nio.file.attribute.BasicFileAttributes; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Iterator; -import java.util.Map; -import java.util.StringTokenizer; +import java.util.*; import java.util.zip.ZipEntry; import java.util.zip.ZipFile; @@ -106,7 +102,7 @@ public class ClassPath implements Serializable { public ClassPath(String class_path) { this.class_path = class_path; - ArrayList vec = new ArrayList<>(); + List vec = new ArrayList<>(); for (StringTokenizer tok = new StringTokenizer(class_path, System.getProperty("path.separator")); tok .hasMoreTokens();) { @@ -167,7 +163,7 @@ public class ClassPath implements Serializable { return false; } - private static final void getPathComponents(String path, ArrayList list) { + private static final void getPathComponents(String path, List list) { if (path != null) { StringTokenizer tok = new StringTokenizer(path, File.pathSeparator); -- cgit v1.2.3