From 64c97807a20105644f604fe9b5263acdb63bd41d Mon Sep 17 00:00:00 2001 From: Andy Clement Date: Fri, 28 Oct 2016 09:04:08 -0700 Subject: [PATCH] Fixing generics warnings --- .../src/org/aspectj/weaver/World.java | 2 +- .../ReflectionBasedReferenceTypeDelegate.java | 37 ++++------------ .../aspectj/weaver/tools/AbstractTrace.java | 4 +- util/src/org/aspectj/util/LangUtil.java | 4 +- util/src/org/aspectj/util/PartialOrder.java | 42 +++++++++---------- .../org/aspectj/util/FileUtilTest.java | 28 ++++++------- 6 files changed, 46 insertions(+), 71 deletions(-) diff --git a/org.aspectj.matcher/src/org/aspectj/weaver/World.java b/org.aspectj.matcher/src/org/aspectj/weaver/World.java index 31b978028..8af6cc528 100644 --- a/org.aspectj.matcher/src/org/aspectj/weaver/World.java +++ b/org.aspectj.matcher/src/org/aspectj/weaver/World.java @@ -1293,7 +1293,7 @@ public abstract class World implements Dump.INode { if (!memoryProfiling) { return; } - Reference r = null; + Reference r = null; while ((r=rq.poll()) != null) { collectedTypes++; } diff --git a/org.aspectj.matcher/src/org/aspectj/weaver/reflect/ReflectionBasedReferenceTypeDelegate.java b/org.aspectj.matcher/src/org/aspectj/weaver/reflect/ReflectionBasedReferenceTypeDelegate.java index 6110e6ceb..2aa83c957 100644 --- a/org.aspectj.matcher/src/org/aspectj/weaver/reflect/ReflectionBasedReferenceTypeDelegate.java +++ b/org.aspectj.matcher/src/org/aspectj/weaver/reflect/ReflectionBasedReferenceTypeDelegate.java @@ -23,6 +23,7 @@ import java.util.Collections; import org.aspectj.weaver.AjAttribute.WeaverVersionInfo; import org.aspectj.weaver.AnnotationAJ; import org.aspectj.weaver.AnnotationTargetKind; +import org.aspectj.weaver.ConcreteTypeMunger; import org.aspectj.weaver.ISourceContext; import org.aspectj.weaver.ReferenceType; import org.aspectj.weaver.ReferenceTypeDelegate; @@ -34,6 +35,7 @@ import org.aspectj.weaver.UnresolvedType; import org.aspectj.weaver.WeakClassLoaderReference; import org.aspectj.weaver.WeaverStateInfo; import org.aspectj.weaver.World; +import org.aspectj.weaver.patterns.Declare; import org.aspectj.weaver.patterns.PerClause; /** @@ -62,7 +64,7 @@ public class ReflectionBasedReferenceTypeDelegate implements ReferenceTypeDelega public ReflectionBasedReferenceTypeDelegate() { } - public void initialize(ReferenceType aType, Class aClass, ClassLoader aClassLoader, World aWorld) { + public void initialize(ReferenceType aType, Class aClass, ClassLoader aClassLoader, World aWorld) { this.myClass = aClass; this.resolvedType = aType; this.world = aWorld; @@ -302,22 +304,12 @@ public class ReflectionBasedReferenceTypeDelegate implements ReferenceTypeDelega return null; } - /* - * (non-Javadoc) - * - * @see org.aspectj.weaver.ReferenceTypeDelegate#getDeclares() - */ - public Collection getDeclares() { - // no declares - return Collections.EMPTY_SET; + public Collection getDeclares() { + return Collections.emptySet(); } - /* - * @see org.aspectj.weaver.ReferenceTypeDelegate#getTypeMungers() - */ - public Collection getTypeMungers() { - // no type mungers - return Collections.EMPTY_SET; + public Collection getTypeMungers() { + return Collections.emptySet(); } /* @@ -363,29 +355,14 @@ public class ReflectionBasedReferenceTypeDelegate implements ReferenceTypeDelega return null; } - /* - * (non-Javadoc) - * - * @see org.aspectj.weaver.ReferenceTypeDelegate#getResolvedTypeX() - */ public ReferenceType getResolvedTypeX() { return this.resolvedType; } - /* - * (non-Javadoc) - * - * @see org.aspectj.weaver.ReferenceTypeDelegate#doesNotExposeShadowMungers() - */ public boolean doesNotExposeShadowMungers() { return false; } - /* - * (non-Javadoc) - * - * @see org.aspectj.weaver.ReferenceTypeDelegate#getDeclaredGenericSignature() - */ public String getDeclaredGenericSignature() { // no generic sig in 1.4 return null; diff --git a/org.aspectj.matcher/src/org/aspectj/weaver/tools/AbstractTrace.java b/org.aspectj.matcher/src/org/aspectj/weaver/tools/AbstractTrace.java index c736de886..52217f880 100644 --- a/org.aspectj.matcher/src/org/aspectj/weaver/tools/AbstractTrace.java +++ b/org.aspectj.matcher/src/org/aspectj/weaver/tools/AbstractTrace.java @@ -166,11 +166,11 @@ public abstract class AbstractTrace implements Trace { } } - protected String formatArray (Object obj) { + protected String formatArray(Object obj) { return obj.getClass().getComponentType().getName() + "[" + Array.getLength(obj) + "]"; } - protected String formatCollection (Collection c) { + protected String formatCollection(Collection c) { return c.getClass().getName() + "(" + c.size() + ")"; } diff --git a/util/src/org/aspectj/util/LangUtil.java b/util/src/org/aspectj/util/LangUtil.java index cf929b7b5..b0bf14522 100644 --- a/util/src/org/aspectj/util/LangUtil.java +++ b/util/src/org/aspectj/util/LangUtil.java @@ -929,11 +929,11 @@ public class LangUtil { * @param array the Object[] to convert (may be null) * @return the List corresponding to array (never null) */ - public static List arrayAsList(Object[] array) { + public static List arrayAsList(T[] array) { if ((null == array) || (1 > array.length)) { return Collections.emptyList(); } - ArrayList list = new ArrayList(); + ArrayList list = new ArrayList<>(); list.addAll(Arrays.asList(array)); return list; } diff --git a/util/src/org/aspectj/util/PartialOrder.java b/util/src/org/aspectj/util/PartialOrder.java index 5dd870205..8bb9f3b77 100644 --- a/util/src/org/aspectj/util/PartialOrder.java +++ b/util/src/org/aspectj/util/PartialOrder.java @@ -49,12 +49,12 @@ public class PartialOrder { public int fallbackCompareTo(Object other); } - private static class SortObject { - PartialComparable object; - List smallerObjects = new LinkedList(); - List biggerObjects = new LinkedList(); + private static class SortObject { + T object; + List> smallerObjects = new LinkedList>(); + List> biggerObjects = new LinkedList>(); - public SortObject(PartialComparable o) { + public SortObject(T o) { object = o; } @@ -62,12 +62,12 @@ public class PartialOrder { return smallerObjects.size() == 0; } - boolean removeSmallerObject(SortObject o) { + boolean removeSmallerObject(SortObject o) { smallerObjects.remove(o); return hasNoSmallerObjects(); } - void addDirectedLinks(SortObject other) { + void addDirectedLinks(SortObject other) { int cmp = object.compareTo(other.object); if (cmp == 0) { return; @@ -86,18 +86,18 @@ public class PartialOrder { } } - private static void addNewPartialComparable(List graph, PartialComparable o) { - SortObject so = new SortObject(o); - for (Iterator i = graph.iterator(); i.hasNext();) { - SortObject other = i.next(); + private static void addNewPartialComparable(List> graph, T o) { + SortObject so = new SortObject(o); + for (Iterator> i = graph.iterator(); i.hasNext();) { + SortObject other = i.next(); so.addDirectedLinks(other); } graph.add(so); } - private static void removeFromGraph(List graph, SortObject o) { - for (Iterator i = graph.iterator(); i.hasNext();) { - SortObject other = i.next(); + private static void removeFromGraph(List> graph, SortObject o) { + for (Iterator> i = graph.iterator(); i.hasNext();) { + SortObject other = i.next(); if (o == other) { i.remove(); @@ -114,7 +114,7 @@ public class PartialOrder { * @returns the same members as objects, but sorted according to their partial order. returns null if the objects are cyclical * */ - public static List sort(List objects) { + public static List sort(List objects) { // lists of size 0 or 1 don't need any sorting if (objects.size() < 2) { return objects; @@ -124,9 +124,9 @@ public class PartialOrder { // ??? I don't like creating this data structure, but it does give good // ??? separation of concerns. - List sortList = new LinkedList(); // objects.size()); - for (Iterator i = objects.iterator(); i.hasNext();) { - addNewPartialComparable(sortList, (PartialComparable) i.next()); + List> sortList = new LinkedList>(); + for (Iterator i = objects.iterator(); i.hasNext();) { + addNewPartialComparable(sortList, i.next()); } // System.out.println(sortList); @@ -140,11 +140,9 @@ public class PartialOrder { // System.out.println(sortList); // System.out.println("-->" + ret); - SortObject leastWithNoSmallers = null; + SortObject leastWithNoSmallers = null; - for (Iterator i = sortList.iterator(); i.hasNext();) { - SortObject so = (SortObject) i.next(); - // System.out.println(so); + for (SortObject so: sortList) { if (so.hasNoSmallerObjects()) { if (leastWithNoSmallers == null || so.object.fallbackCompareTo(leastWithNoSmallers.object) < 0) { leastWithNoSmallers = so; diff --git a/util/testsrc/org/aspectj/util/FileUtilTest.java b/util/testsrc/org/aspectj/util/FileUtilTest.java index 3f065278b..8ce18c700 100644 --- a/util/testsrc/org/aspectj/util/FileUtilTest.java +++ b/util/testsrc/org/aspectj/util/FileUtilTest.java @@ -62,7 +62,7 @@ public class FileUtilTest extends TestCase { * @throws AssertionFailedError if any names are not in dir */ public static String[] dirContains(File dir, final String[] filenames) { - final ArrayList sought = new ArrayList(LangUtil.arrayAsList(filenames)); + final ArrayList sought = new ArrayList<>(LangUtil.arrayAsList(filenames)); FilenameFilter filter = new FilenameFilter() { public boolean accept(File d, String name) { return !sought.remove(name); @@ -129,11 +129,11 @@ public class FileUtilTest extends TestCase { * @return sorted String[] of all paths to all files under dir ending with one of the listed suffixes but not starting with "." */ public static String[] dirPaths(File dir, String[] suffixes) { - ArrayList result = new ArrayList(); + ArrayList result = new ArrayList(); doDirPaths(dir, result); // if suffixes required, remove those without suffixes if (!LangUtil.isEmpty(suffixes)) { - for (ListIterator iter = result.listIterator(); iter.hasNext();) { + for (ListIterator iter = result.listIterator(); iter.hasNext();) { String path = iter.next().toString(); boolean hasSuffix = false; for (int i = 0; !hasSuffix && (i < suffixes.length); i++) { @@ -161,7 +161,7 @@ public class FileUtilTest extends TestCase { * @param dir the File to read - ignored if null, not a directory, or has "CVS" in its path * @param useSuffix if true, then use dir as suffix to path */ - private static void doDirPaths(File dir, ArrayList paths) { + private static void doDirPaths(File dir, ArrayList paths) { if ((null == dir) || !dir.canRead() || (-1 != dir.getPath().indexOf("CVS"))) { return; } @@ -188,15 +188,15 @@ public class FileUtilTest extends TestCase { } /** List of File files or directories to delete when exiting */ - final ArrayList tempFiles; + final ArrayList tempFiles; public FileUtilTest(String s) { super(s); - tempFiles = new ArrayList(); + tempFiles = new ArrayList(); } public void tearDown() { - for (ListIterator iter = tempFiles.listIterator(); iter.hasNext();) { + for (ListIterator iter = tempFiles.listIterator(); iter.hasNext();) { File dir = (File) iter.next(); log("removing " + dir); FileUtil.deleteContents(dir); @@ -236,7 +236,7 @@ public class FileUtilTest extends TestCase { public void testCopyFiles() { // bad input - Class iaxClass = IllegalArgumentException.class; + Class iaxClass = IllegalArgumentException.class; checkCopyFiles(null, null, iaxClass, false); @@ -388,7 +388,7 @@ public class FileUtilTest extends TestCase { } public void testRandomFileString() { - ArrayList results = new ArrayList(); + ArrayList results = new ArrayList<>(); for (int i = 0; i < 1000; i++) { String s = FileUtil.randomFileString(); if (results.contains(s)) { @@ -469,7 +469,7 @@ public class FileUtilTest extends TestCase { } }; for (int i = 0; i < 10; i++) { - List result = FileUtil.lineSeek("" + i, sourceList, true, errorSink); + List result = FileUtil.lineSeek("" + i, sourceList, true, errorSink); assertEquals(2, result.size()); assertEquals(path + ":1:" + i, result.get(0)); assertEquals(path + ":2:" + i, result.get(1)); @@ -502,19 +502,19 @@ public class FileUtilTest extends TestCase { tempFiles.add(file); } // now test - final ArrayList errors = new ArrayList(); + final ArrayList errors = new ArrayList<>(); final PrintStream errorSink = new PrintStream(System.err, true) { public void println(String error) { errors.add(error); } }; - List sourceList = new ArrayList(); + List sourceList = new ArrayList<>(); sourceList.addAll(Arrays.asList(sources)); sourceList = Collections.unmodifiableList(sourceList); for (int k = 0; k < sources.length; k++) { - List result = FileUtil.lineSeek("" + k, sourceList, true, errorSink); + List result = FileUtil.lineSeek("" + k, sourceList, true, errorSink); // number k found in every other line of every file at index k - Iterator iter = result.iterator(); + Iterator iter = result.iterator(); for (int i = 0; i < MAX; i++) { // for each file for (int j = 1; j < (MAX + 1); j++) { // for every other line assertTrue(iter.hasNext()); -- 2.39.5