Index: openide/util/nbproject/project.properties =================================================================== RCS file: /cvs/openide/util/nbproject/project.properties,v retrieving revision 1.9 retrieving revision 1.9.2.1 diff -u -r1.9 -r1.9.2.1 --- openide/util/nbproject/project.properties 18 Jan 2006 05:18:08 -0000 1.9 +++ openide/util/nbproject/project.properties 17 Mar 2006 19:51:10 -0000 1.9.2.1 @@ -9,6 +9,8 @@ # Code is Sun Microsystems, Inc. Portions Copyright 1997-2005 Sun # Microsystems, Inc. All Rights Reserved. +javac.compilerargs=-Xlint:unchecked +javac.source=1.5 module.jar.dir=lib spec.version.base=6.9.0 Index: openide/util/src/org/openide/ErrorManager.java =================================================================== RCS file: /cvs/openide/util/src/org/openide/ErrorManager.java,v retrieving revision 1.3 retrieving revision 1.3.2.1 diff -u -r1.3 -r1.3.2.1 --- openide/util/src/org/openide/ErrorManager.java 14 Feb 2006 12:10:19 -0000 1.3 +++ openide/util/src/org/openide/ErrorManager.java 17 Mar 2006 19:51:10 -0000 1.3.2.1 @@ -502,15 +502,14 @@ /** * A set that has to be updated when the list of delegates * changes. All instances created by getInstance are held here. - * It is a set of DelagatingErrorManager. */ - private WeakSet createdByMe = new WeakSet(); + private WeakSet createdByMe = new WeakSet(); /** If we are the "central" delagate this is not null and * we listen on the result. On newly created delegates this * is null. */ - Lookup.Result r; + Lookup.Result r; public DelegatingErrorManager(String name) { this.name = name; @@ -674,8 +673,9 @@ * Updates the list of delegates. Also updates all instances created * by ourselves. */ - public synchronized void setDelegates(Collection newDelegates) { - java.util.LinkedHashSet d = new java.util.LinkedHashSet(newDelegates); + public synchronized void setDelegates(Collection newDelegates) { + java.util.LinkedHashSet d; + d = new java.util.LinkedHashSet(newDelegates); delegates = d; for (Iterator i = createdByMe.iterator(); i.hasNext();) { @@ -695,7 +695,7 @@ * @param DelagatingErrorManager d the instance to which we will attach */ private void attachNewDelegates(DelegatingErrorManager dem, String name) { - Set newDelegatesForDem = new HashSet(); + Set newDelegatesForDem = new HashSet(); for (Iterator j = delegates.iterator(); j.hasNext();) { ErrorManager e = (ErrorManager) j.next(); @@ -709,17 +709,14 @@ * delegates and adds a listener. */ public void initialize() { - r = Lookup.getDefault().lookup(new Lookup.Template(ErrorManager.class)); - - Collection instances = r.allInstances(); - setDelegates(instances); + r = Lookup.getDefault().lookup(new Lookup.Template(ErrorManager.class)); + setDelegates(r.allInstances()); } /** Updates the delegates.*/ public void resultChanged(LookupEvent ev) { if (r != null) { - Collection instances = r.allInstances(); - setDelegates(instances); + setDelegates(r.allInstances()); } } } Index: openide/util/src/org/openide/ServiceType.java =================================================================== RCS file: /cvs/openide/util/src/org/openide/ServiceType.java,v retrieving revision 1.3 retrieving revision 1.3.48.1 diff -u -r1.3 -r1.3.48.1 --- openide/util/src/org/openide/ServiceType.java 29 Apr 2005 14:11:09 -0000 1.3 +++ openide/util/src/org/openide/ServiceType.java 17 Mar 2006 19:51:10 -0000 1.3.48.1 @@ -197,16 +197,16 @@ /** Get all available services managed by the engine. * @return an enumeration of {@link ServiceType}s */ - public abstract Enumeration services(); + public abstract Enumeration services(); /** Get all available services that are assignable to the given superclass. * @param clazz the class that all services should be subclass of * @return an enumeration of all matching {@link ServiceType}s */ - public Enumeration services(final Class clazz) { - class IsInstance implements org.openide.util.Enumerations.Processor { - public Object process(Object obj, java.util.Collection ignore) { - return clazz.isInstance(obj) ? obj : null; + public Enumeration services(final Class clazz) { + class IsInstance implements org.openide.util.Enumerations.Processor { + public T process(ServiceType obj, java.util.Collection ignore) { + return clazz.isInstance(obj) ? clazz.cast(obj) : null; } } @@ -311,16 +311,15 @@ public ServiceType getServiceType() { if (serviceType == null) { // the class to search for - Class clazz; + Class clazz; // the first subclass of ServiceType to search for - Class serviceTypeClass; + Class serviceTypeClass; // try to find it by class try { - clazz = Class.forName(className, true, (ClassLoader) Lookup.getDefault().lookup(ClassLoader.class)); - - serviceTypeClass = clazz; + serviceTypeClass = Class.forName(className, true, (ClassLoader) Lookup.getDefault().lookup(ClassLoader.class)); + clazz = serviceTypeClass.asSubclass(ServiceType.class); while (serviceTypeClass.getSuperclass() != ServiceType.class) { serviceTypeClass = serviceTypeClass.getSuperclass(); Index: openide/util/src/org/openide/util/Enumerations.java =================================================================== RCS file: /cvs/openide/util/src/org/openide/util/Enumerations.java,v retrieving revision 1.1 retrieving revision 1.1.48.1 diff -u -r1.1 -r1.1.48.1 --- openide/util/src/org/openide/util/Enumerations.java 21 Apr 2005 20:16:09 -0000 1.1 +++ openide/util/src/org/openide/util/Enumerations.java 17 Mar 2006 19:51:05 -0000 1.1.48.1 @@ -37,8 +37,9 @@ * from empty().nextElement(). * @return the enumeration */ - public static final Enumeration empty() { - return Collections.enumeration(Collections.EMPTY_LIST); + public static final Enumeration empty() { + Collection emptyL = Collections.emptyList(); + return Collections.enumeration(emptyL); } /** @@ -46,7 +47,7 @@ * @param obj the element to be present in the enumeration. * @return enumeration */ - public static Enumeration singleton(Object obj) { + public static Enumeration singleton(T obj) { return Collections.enumeration(Collections.singleton(obj)); } @@ -61,8 +62,11 @@ * @param en2 second enumeration * @return enumeration */ - public static Enumeration concat(Enumeration en1, Enumeration en2) { - return new SeqEn(en1, en2); + public static Enumeration concat(Enumeration en1, Enumeration en2) { + ArrayList> two = new ArrayList>(); + two.add(en1); + two.add(en2); + return new SeqEn(Collections.enumeration(two)); } /** @@ -76,8 +80,8 @@ * @param enumOfEnums Enumeration of Enumeration elements * @return enumeration */ - public static Enumeration concat(Enumeration enumOfEnums) { - return new SeqEn(enumOfEnums); + public static Enumeration concat(Enumeration> enumOfEnums) { + return new SeqEn(enumOfEnums); } /** @@ -89,11 +93,11 @@ * @param en enumeration to filter * @return enumeration without duplicated items */ - public static Enumeration removeDuplicates(Enumeration en) { - class RDupls implements Processor { - private Set set = new HashSet(); + public static Enumeration removeDuplicates(Enumeration en) { + class RDupls implements Processor { + private Set set = new HashSet(); - public Object process(Object o, Collection nothing) { + public T process(T o, Collection nothing) { return set.add(o) ? o : null; } } @@ -106,7 +110,7 @@ * @param arr the array of object * @return enumeration of those objects */ - public static Enumeration array(Object[] arr) { + public static Enumeration array(T... arr) { return Collections.enumeration(Arrays.asList(arr)); } @@ -115,8 +119,8 @@ * @param en enumeration that can contain nulls * @return new enumeration without null values */ - public static Enumeration removeNulls(Enumeration en) { - return filter(en, new RNulls()); + public static Enumeration removeNulls(Enumeration en) { + return filter(en, new RNulls()); } /** @@ -138,8 +142,8 @@ * @param processor a callback processor for the elements (its toAdd arguments is always null) * @return new enumeration where all elements has been processed */ - public static Enumeration convert(Enumeration en, Processor processor) { - return new AltEn(en, processor); + public static Enumeration convert(Enumeration en, Processor processor) { + return new AltEn(en, processor); } /** @@ -166,8 +170,8 @@ * @param filter a callback processor for the elements (its toAdd arguments is always null) * @return new enumeration which does not include non-processed (returned null from processor) elements */ - public static Enumeration filter(Enumeration en, Processor filter) { - return new FilEn(en, filter); + public static Enumeration filter(Enumeration en, Processor filter) { + return new FilEn(en, filter); } /** @@ -199,8 +203,8 @@ * null if the filter returned null from its * {@link Processor#process} method. */ - public static Enumeration queue(Enumeration en, Processor filter) { - QEn q = new QEn(filter); + public static Enumeration queue(Enumeration en, Processor filter) { + QEn q = new QEn(filter); while (en.hasMoreElements()) { q.put(en.nextElement()); @@ -213,26 +217,26 @@ * Processor interface that can filter out objects from the enumeration, * change them or add aditional objects to the end of the current enumeration. */ - public static interface Processor { + public static interface Processor { /** @param original the object that is going to be returned from the enumeration right now * @return a replacement for this object * @param toAdd can be non-null if one can add new objects at the end of the enumeration */ - public Object process(Object original, Collection toAdd); + public R process(T original, Collection toAdd); } /** Altering enumeration implementation */ - private static final class AltEn extends Object implements Enumeration { + private static final class AltEn extends Object implements Enumeration { /** enumeration to filter */ - private Enumeration en; + private Enumeration en; /** map to alter */ - private Processor process; + private Processor process; /** * @param en enumeration to filter */ - public AltEn(Enumeration en, Processor process) { + public AltEn(Enumeration en, Processor process) { this.en = en; this.process = process; } @@ -247,19 +251,19 @@ * @exception NoSuchElementException can be thrown if there is no next object * in the enumeration */ - public Object nextElement() { + public R nextElement() { return process.process(en.nextElement(), null); } } // end of AltEn /** Sequence of enumerations */ - private static final class SeqEn extends Object implements Enumeration { + private static final class SeqEn extends Object implements Enumeration { /** enumeration of Enumerations */ - private Enumeration en; + private Enumeration> en; /** current enumeration */ - private Enumeration current; + private Enumeration current; /** is {@link #current} up-to-date and has more elements? * The combination current == null and @@ -274,25 +278,17 @@ * * @param en enumeration of Enumerations that should be sequenced */ - public SeqEn(Enumeration en) { + public SeqEn(Enumeration> en) { this.en = en; } - /** Composes two enumerations into one. - * @param first first enumeration - * @param second second enumeration - */ - public SeqEn(Enumeration first, Enumeration second) { - this(array(new Enumeration[] { first, second })); - } - /** Ensures that current enumeration is set. If there aren't more * elements in the Enumerations, sets the field current to null. */ private void ensureCurrent() { while ((current == null) || !current.hasMoreElements()) { if (en.hasMoreElements()) { - current = (Enumeration) en.nextElement(); + current = en.nextElement(); } else { // no next valid enumeration current = null; @@ -315,7 +311,7 @@ /** @return next element * @exception NoSuchElementException if there is no next element */ - public Object nextElement() { + public T nextElement() { if (!checked) { ensureCurrent(); } @@ -334,39 +330,39 @@ /** QueueEnumeration */ - private static class QEn extends Object implements Enumeration { + private static class QEn extends Object implements Enumeration { /** next object to be returned */ - private ListItem next = null; + private ListItem next = null; /** last object in the queue */ - private ListItem last = null; + private ListItem last = null; /** processor to use */ - private Processor processor; + private Processor processor; - public QEn(Processor p) { + public QEn(Processor p) { this.processor = p; } /** Put adds new object to the end of queue. * @param o the object to add */ - public void put(Object o) { + public void put(T o) { if (last != null) { - ListItem li = new ListItem(o); + ListItem li = new ListItem(o); last.next = li; last = li; } else { - next = last = new ListItem(o); + next = last = new ListItem(o); } } /** Adds array of objects into the queue. * @param arr array of objects to put into the queue */ - public void put(Object[] arr) { - for (int i = 0; i < arr.length; i++) { - put(arr[i]); + public void put(Collection arr) { + for (T e : arr) { + put(e); } } @@ -380,12 +376,12 @@ /** @return next object in enumeration * @exception NoSuchElementException if there is no next object */ - public Object nextElement() { + public R nextElement() { if (next == null) { throw new NoSuchElementException(); } - Object res = next.object; + T res = next.object; if ((next = next.next) == null) { last = null; @@ -393,29 +389,29 @@ ; - ToAdd toAdd = new ToAdd(this); - res = processor.process(res, toAdd); + ToAdd toAdd = new ToAdd(this); + R out = processor.process(res, toAdd); toAdd.finish(); - return res; + return out; } /** item in linked list of Objects */ - private static final class ListItem { - Object object; - ListItem next; + private static final class ListItem { + T object; + ListItem next; /** @param o the object for this item */ - ListItem(Object o) { + ListItem(T o) { object = o; } } /** Temporary collection that supports only add and addAll operations*/ - private static final class ToAdd extends Object implements Collection { - private QEn q; + private static final class ToAdd extends Object implements Collection { + private QEn q; - public ToAdd(QEn q) { + public ToAdd(QEn q) { this.q = q; } @@ -423,14 +419,14 @@ this.q = null; } - public boolean add(Object o) { + public boolean add(T o) { q.put(o); return true; } - public boolean addAll(Collection c) { - q.put(c.toArray()); + public boolean addAll(Collection c) { + q.put(c); return true; } @@ -455,7 +451,7 @@ throw new UnsupportedOperationException(msg()); } - public Iterator iterator() { + public Iterator iterator() { throw new UnsupportedOperationException(msg()); } @@ -479,7 +475,7 @@ throw new UnsupportedOperationException(msg()); } - public Object[] toArray(Object[] a) { + public X[] toArray(X[] a) { throw new UnsupportedOperationException(msg()); } } @@ -488,24 +484,24 @@ // end of QEn /** Filtering enumeration */ - private static final class FilEn extends Object implements Enumeration { + private static final class FilEn extends Object implements Enumeration { /** marker object stating there is no nexte element prepared */ private static final Object EMPTY = new Object(); /** enumeration to filter */ - private Enumeration en; + private Enumeration en; /** element to be returned next time or {@link #EMPTY} if there is * no such element prepared */ - private Object next = EMPTY; + private R next = empty(); /** the set to use as filter */ - private Processor filter; + private Processor filter; /** * @param en enumeration to filter */ - public FilEn(Enumeration en, Processor filter) { + public FilEn(Enumeration en, Processor filter) { this.en = en; this.filter = filter; } @@ -513,7 +509,7 @@ /** @return true if there is more elements in the enumeration */ public boolean hasMoreElements() { - if (next != EMPTY) { + if (next != empty()) { // there is a object already prepared return true; } @@ -530,7 +526,7 @@ ; } - next = EMPTY; + next = empty(); return false; } @@ -539,22 +535,27 @@ * @exception NoSuchElementException can be thrown if there is no next object * in the enumeration */ - public Object nextElement() { + public R nextElement() { if ((next == EMPTY) && !hasMoreElements()) { throw new NoSuchElementException(); } - Object res = next; - next = EMPTY; + R res = next; + next = empty(); return res; } + + @SuppressWarnings("unchecked") + private R empty() { + return (R)EMPTY; + } } // end of FilEn /** Returns true from contains if object is not null */ - private static class RNulls implements Processor { - public Object process(Object original, Collection toAdd) { + private static class RNulls implements Processor { + public T process(T original, Collection toAdd) { return original; } } Index: openide/util/src/org/openide/util/IconManager.java =================================================================== RCS file: /cvs/openide/util/src/org/openide/util/IconManager.java,v retrieving revision 1.2 retrieving revision 1.2.20.1 diff -u -r1.2 -r1.2.20.1 --- openide/util/src/org/openide/util/IconManager.java 4 Nov 2005 10:54:11 -0000 1.2 +++ openide/util/src/org/openide/util/IconManager.java 17 Mar 2006 19:51:03 -0000 1.2.20.1 @@ -35,15 +35,15 @@ private static final Object NO_ICON = new Object(); /** map of resource name to loaded icon (String, SoftRefrence (Image)) or (String, NO_ICON) */ - private static final HashMap map = new HashMap(128); - private static final HashMap localizedMap = new HashMap(128); + private static final HashMap map = new HashMap(128); + private static final HashMap localizedMap = new HashMap(128); /** Resource paths for which we have had to strip initial slash. * @see "#20072" */ - private static final Set extraInitialSlashes = new HashSet(); // Set + private static final Set extraInitialSlashes = new HashSet(); // Set private static volatile Object currentLoader; - private static Lookup.Result loaderQuery = null; + private static Lookup.Result loaderQuery = null; private static boolean noLoaderWarned = false; private static final Component component = new Component() { }; @@ -67,7 +67,7 @@ currentLoader = Thread.currentThread(); if (loaderQuery == null) { - loaderQuery = Lookup.getDefault().lookup(new Lookup.Template(ClassLoader.class)); + loaderQuery = Lookup.getDefault().lookup(new Lookup.Template(ClassLoader.class)); loaderQuery.addLookupListener( new LookupListener() { public void resultChanged(LookupEvent ev) { @@ -424,11 +424,11 @@ } /** Cleaning reference. */ - private static final class ActiveRef extends SoftReference implements Runnable { + private static final class ActiveRef extends SoftReference implements Runnable { private Map holder; private Object key; - public ActiveRef(Object o, Map holder, Object key) { + public ActiveRef(Image o, Map holder, Object key) { super(o, Utilities.activeReferenceQueue()); this.holder = holder; this.key = key; Index: openide/util/src/org/openide/util/Lookup.java =================================================================== RCS file: /cvs/openide/util/src/org/openide/util/Lookup.java,v retrieving revision 1.5 retrieving revision 1.5.2.1 diff -u -r1.5 -r1.5.2.1 --- openide/util/src/org/openide/util/Lookup.java 9 Jan 2006 21:13:33 -0000 1.5 +++ openide/util/src/org/openide/util/Lookup.java 17 Mar 2006 19:51:05 -0000 1.5.2.1 @@ -134,7 +134,7 @@ * @return an object implementing the given class or null if no such * implementation is found */ - public abstract Object lookup(Class clazz); + public abstract T lookup(Class clazz); /** The general lookup method. Callers can get list of all instances and classes * that match the given template, request more info about @@ -147,7 +147,7 @@ * @param template a template describing the services to look for * @return an object containing the results */ - public abstract Result lookup(Template template); + public abstract Result lookup(Template template); /** Look up the first item matching a given template. * Includes not only the instance but other associated information. @@ -156,11 +156,10 @@ * * @since 1.8 */ - public Item lookupItem(Template template) { - Result res = lookup(template); - Iterator it = res.allItems().iterator(); - - return it.hasNext() ? (Item) it.next() : null; + public Item lookupItem(Template template) { + Result res = lookup(template); + Iterator> it = res.allItems().iterator(); + return it.hasNext() ? it.next() : null; } /** @@ -183,18 +182,18 @@ /** Template defining a pattern to filter instances by. */ - public static final class Template extends Object { + public static final class Template extends Object { /** cached hash code */ private int hashCode; /** type of the service */ - private Class type; + private Class type; /** identity to search for */ private String id; /** instance to search for */ - private Object instance; + private T instance; /** General template to find all possible instances. * @deprecated Use new Template (Object.class) which @@ -208,7 +207,7 @@ /** Create a simple template matching by class. * @param type the class of service we are looking for (subclasses will match) */ - public Template(Class type) { + public Template(Class type) { this(type, null, null); } @@ -217,18 +216,23 @@ * @param id the ID of the item/service we are looking for or null to leave unspecified * @param instance a specific known instance to look for or null to leave unspecified */ - public Template(Class type, String id, Object instance) { - this.type = (type == null) ? Object.class : type; + public Template(Class type, String id, T instance) { + this.type = extractType(type); this.id = id; this.instance = instance; } + @SuppressWarnings("unchecked") + private Class extractType(Class type) { + return (type == null) ? (Class)Object.class : type; + } + /** Get the class (or superclass or interface) to search for. * If it was not specified in the constructor, Object is used as * this will match any instance. * @return the class to search for */ - public Class getType() { + public Class getType() { return type; } @@ -250,7 +254,7 @@ * * @since 1.8 */ - public Object getInstance() { + public T getInstance() { return instance; } @@ -317,7 +321,7 @@ * Also permits listening to changes in the result. * Result can contain duplicate items. */ - public static abstract class Result extends Object { + public static abstract class Result extends Object { /** Registers a listener that is invoked when there is a possible * change in this result. * @@ -334,7 +338,7 @@ * should be List instead of Collection, but it is too late to change it. * @return unmodifiable collection of all instances that will never change its content */ - public abstract java.util.Collection allInstances(); + public abstract java.util.Collection allInstances(); /** Get all classes represented in the result. * That is, the set of concrete classes @@ -344,8 +348,8 @@ * * @since 1.8 */ - public java.util.Set allClasses() { - return java.util.Collections.EMPTY_SET; + public java.util.Set> allClasses() { + return java.util.Collections.emptySet(); } /** Get all registered items. @@ -356,8 +360,8 @@ * * @since 1.8 */ - public java.util.Collection allItems() { - return java.util.Collections.EMPTY_SET; + public java.util.Collection> allItems() { + return java.util.Collections.emptyList(); } } @@ -367,16 +371,16 @@ * * @since 1.25 */ - public static abstract class Item extends Object { + public static abstract class Item extends Object { /** Get the instance itself. * @return the instance or null if the instance cannot be created */ - public abstract Object getInstance(); + public abstract T getInstance(); /** Get the implementing class of the instance. * @return the class of the item */ - public abstract Class getType(); + public abstract Class getType(); // XXX can it be null?? @@ -425,11 +429,12 @@ Empty() { } - public Object lookup(Class clazz) { + public T lookup(Class clazz) { return null; } - public Result lookup(Template template) { + @SuppressWarnings("unchecked") + public Result lookup(Template template) { return NO_RESULT; } } Index: openide/util/src/org/openide/util/Mutex.java =================================================================== RCS file: /cvs/openide/util/src/org/openide/util/Mutex.java,v retrieving revision 1.6 retrieving revision 1.6.2.1 diff -u -r1.6 -r1.6.2.1 --- openide/util/src/org/openide/util/Mutex.java 2 Mar 2006 20:54:08 -0000 1.6 +++ openide/util/src/org/openide/util/Mutex.java 17 Mar 2006 19:51:05 -0000 1.6.2.1 @@ -138,7 +138,7 @@ private /*final*/ Object LOCK; /** threads that - owns or waits for this mutex */ - private /*final*/ Map registeredThreads; + private /*final*/ Map registeredThreads; /** number of threads that holds S mode (readersNo == "count of threads in registeredThreads that holds S") */ @@ -146,7 +146,7 @@ private int readersNo = 0; /** a queue of waiting threads for this mutex */ - private List waiters; + private List waiters; /** Enhanced constructor that permits specifying an object to use as a lock. * The lock is used on entry and exit to {@link #readAccess} and during the @@ -190,8 +190,8 @@ /** Initiates this Mutex */ private void init(Object lock) { this.LOCK = lock; - this.registeredThreads = new HashMap(7); - this.waiters = new LinkedList(); + this.registeredThreads = new HashMap(7); + this.waiters = new LinkedList(); } /** Run an action only with read access. @@ -1307,7 +1307,7 @@ /** queue of runnable rquests that are to be executed (in X mode) right after S mode is left * deadlock avoidance technique */ - List[] queues; + List[] queues; /** value of counts[S] when the mode was upgraded * rsnapshot works as follows: @@ -1323,11 +1323,12 @@ */ int rsnapshot; + @SuppressWarnings("unchecked") public ThreadInfo(Thread t, int mode) { this.t = t; this.mode = mode; this.counts = new int[MODE_COUNT]; - this.queues = new List[MODE_COUNT]; + this.queues = (List[])new List[MODE_COUNT]; counts[mode] = 1; } @@ -1338,7 +1339,7 @@ /** Adds the Runnable into the queue of waiting requests */ public void enqueue(int mode, Runnable run) { if (queues[mode] == null) { - queues[mode] = new ArrayList(13); + queues[mode] = new ArrayList(13); } queues[mode].add(run); Index: openide/util/src/org/openide/util/NbBundle.java =================================================================== RCS file: /cvs/openide/util/src/org/openide/util/NbBundle.java,v retrieving revision 1.6 retrieving revision 1.6.14.1 diff -u -r1.6 -r1.6.14.1 --- openide/util/src/org/openide/util/NbBundle.java 1 Dec 2005 12:05:09 -0000 1.6 +++ openide/util/src/org/openide/util/NbBundle.java 17 Mar 2006 19:51:05 -0000 1.6.14.1 @@ -62,12 +62,12 @@ * Keeps only weak references to the class loaders. * @see "#9275" */ - private static final Map localizedFileCache = new WeakHashMap(); // Map> + private static final Map> localizedFileCache = new WeakHashMap>(); /** * Cache of resource bundles. */ - private static final Map bundleCache = new WeakHashMap(); // Map>> + private static final Map>> bundleCache = new WeakHashMap>>(); /** * Do not call. @@ -154,14 +154,14 @@ // [PENDING] in the future, could maybe do something neat if // USE_DEBUG_LOADER and ext is "html" or "txt" etc... URL lookup = null; - Iterator it = new LocaleIterator(locale); + Iterator it = new LocaleIterator(locale); String cachePrefix = "[" + Integer.toString(loader.hashCode()) + "]"; // NOI18N - List cacheCandidates = new ArrayList(10); // List + List cacheCandidates = new ArrayList(10); String baseNameSlashes = baseName.replace('.', '/'); - Map perLoaderCache = (Map) localizedFileCache.get(loader); + Map perLoaderCache = localizedFileCache.get(loader); if (perLoaderCache == null) { - localizedFileCache.put(loader, perLoaderCache = new HashMap()); + localizedFileCache.put(loader, perLoaderCache = new HashMap()); } // #31008: better use of domain cache priming. @@ -441,13 +441,13 @@ * @return a resource bundle (locale- and branding-merged), or null if not found */ private static ResourceBundle getBundleFast(String name, Locale locale, ClassLoader loader) { - Map m; + Map> m; synchronized (bundleCache) { - m = (Map) bundleCache.get(loader); // Map> + m = bundleCache.get(loader); if (m == null) { - bundleCache.put(loader, m = new HashMap()); + bundleCache.put(loader, m = new HashMap>()); } } @@ -480,8 +480,8 @@ String key = name + '/' + (brandingToken != null ? brandingToken : "-") + '/' + locale; // NOI18N */ synchronized (m) { - Object o = m.get(key); - ResourceBundle b = (o != null) ? (ResourceBundle) ((Reference) o).get() : null; + Reference o = m.get(key); + ResourceBundle b = o != null ? o.get() : null; if (b != null) { return b; @@ -489,7 +489,7 @@ b = loadBundle(name, locale, loader); if (b != null) { - m.put(key, new TimedSoftReference(b, m, key)); + m.put(key, new TimedSoftReference(b, m, key)); } else { // Used to cache misses as well, to make the negative test faster. // However this caused problems: see #31578. @@ -509,8 +509,8 @@ */ private static ResourceBundle loadBundle(String name, Locale locale, ClassLoader loader) { String sname = name.replace('.', '/'); - Iterator it = new LocaleIterator(locale); - LinkedList l = new LinkedList(); + Iterator it = new LocaleIterator(locale); + LinkedList l = new LinkedList(); while (it.hasNext()) { l.addFirst(it.next()); @@ -555,7 +555,15 @@ first = false; } - return new PBundle(p, locale); + return new PBundle(propsToStringMap(p), locale); + } + + /** Just converts the Properties to Map assuming the + * content is correct. + */ + @SuppressWarnings("unchecked") + private static Map propsToStringMap(Properties p) { + return (Map)p; } /** @@ -769,7 +777,7 @@ * A resource bundle based on .properties files (or any map). */ private static final class PBundle extends ResourceBundle { - private final Map m; // Map + private final Map m; private final Locale locale; /** @@ -777,12 +785,12 @@ * @param m a map from resources keys to values (typically both strings) * @param locale the locale it represents (informational) */ - public PBundle(Map m, Locale locale) { + public PBundle(Map m, Locale locale) { this.m = m; this.locale = locale; } - public Enumeration getKeys() { + public Enumeration getKeys() { return Collections.enumeration(m.keySet()); } @@ -819,7 +827,7 @@ return loc; } - public Enumeration getKeys() { + public Enumeration getKeys() { return Enumerations.removeDuplicates(Enumerations.concat(sub1.getKeys(), sub2.getKeys())); } @@ -853,7 +861,7 @@ * Branding tokens with underscores are broken apart naturally: so e.g. * branding "f4j_ce" looks first for "f4j_ce" branding, then "f4j" branding, then none. */ - private static class LocaleIterator extends Object implements Iterator { + private static class LocaleIterator extends Object implements Iterator { /** this flag means, if default locale is in progress */ private boolean defaultInProgress = false; @@ -896,7 +904,7 @@ /** @return next sufix. * @exception NoSuchElementException if there is no more locale sufix. */ - public Object next() throws NoSuchElementException { + public String next() throws NoSuchElementException { if (current == null) { throw new NoSuchElementException(); } @@ -981,10 +989,10 @@ /** indices of known bundles; needed since DebugLoader's can be collected * when softly reachable, but this should be transparent to the user */ - private static final Map knownIDs = new HashMap(); // Map + private static final Map knownIDs = new HashMap(); /** cache of existing debug loaders for regular loaders */ - private static final Map existing = new WeakHashMap(); // Map> + private static final Map> existing = new WeakHashMap>(); private DebugLoader(ClassLoader cl) { super(cl); @@ -1025,7 +1033,7 @@ } ClassLoader dl = new DebugLoader(normal); - existing.put(normal, new WeakReference(dl)); + existing.put(normal, new WeakReference(dl)); return dl; } Index: openide/util/src/org/openide/util/Queue.java =================================================================== RCS file: /cvs/openide/util/src/org/openide/util/Queue.java,v retrieving revision 1.1 retrieving revision 1.1.48.1 diff -u -r1.1 -r1.1.48.1 --- openide/util/src/org/openide/util/Queue.java 21 Apr 2005 20:16:11 -0000 1.1 +++ openide/util/src/org/openide/util/Queue.java 17 Mar 2006 19:51:05 -0000 1.1.48.1 @@ -21,7 +21,7 @@ */ public class Queue extends Object { /** Queue enumeration */ - private java.util.LinkedList queue = new java.util.LinkedList(); + private java.util.LinkedList queue = new java.util.LinkedList(); /** Adds new item. * @param o object to add Index: openide/util/src/org/openide/util/RE13.java =================================================================== RCS file: /cvs/openide/util/src/org/openide/util/RE13.java,v retrieving revision 1.1 retrieving revision 1.1.48.1 diff -u -r1.1 -r1.1.48.1 --- openide/util/src/org/openide/util/RE13.java 21 Apr 2005 20:16:12 -0000 1.1 +++ openide/util/src/org/openide/util/RE13.java 17 Mar 2006 19:51:04 -0000 1.1.48.1 @@ -116,7 +116,7 @@ /** Data structure to needed to store the */ public void init(String[] original, String[] newversion) { - ArrayList root = new ArrayList(); + ArrayList root = new ArrayList(); for (int i = 0; i < original.length; i++) { placeString(root, original[i], i); @@ -131,7 +131,7 @@ * @param s string to place there * @param indx index to put at the end node */ - private static void placeString(List item, String s, int indx) { + private static void placeString(List item, String s, int indx) { if (s.length() == 0) { item.add(new Integer(indx)); @@ -140,7 +140,7 @@ char f = s.charAt(0); - ListIterator it = item.listIterator(); + ListIterator it = item.listIterator(); while (it.hasNext()) { Object o = it.next(); @@ -159,7 +159,7 @@ // next is the list or null List listForPref = (List) it.next(); - ArrayList switchList = new ArrayList(); + ArrayList switchList = new ArrayList(); it.set(switchList); switchList.add(pref.substring(i)); @@ -168,7 +168,7 @@ if (i >= s.length()) { switchList.add(new Integer(indx)); } else { - ArrayList terminalList = new ArrayList(); + ArrayList terminalList = new ArrayList(); terminalList.add(new Integer(indx)); switchList.add(s.substring(i)); @@ -182,7 +182,7 @@ // // the new string is longer than the existing recursive add // - List switchList = (List) it.next(); + List switchList = nextList(it); placeString(switchList, s.substring(pref.length()), indx); return; @@ -193,11 +193,17 @@ // // ok new prefix in this item // - ArrayList id = new ArrayList(); + ArrayList id = new ArrayList(); id.add(new Integer(indx)); item.add(s); item.add(id); + } + + @SuppressWarnings("unchecked") + private static List nextList(final ListIterator it) { + List switchList = (List) it.next(); + return switchList; } /** Compress tree of Lists into tree of Objects. Index: openide/util/src/org/openide/util/RequestProcessor.java =================================================================== RCS file: /cvs/openide/util/src/org/openide/util/RequestProcessor.java,v retrieving revision 1.12 retrieving revision 1.12.2.1 diff -u -r1.12 -r1.12.2.1 --- openide/util/src/org/openide/util/RequestProcessor.java 12 Jan 2006 08:50:46 -0000 1.12 +++ openide/util/src/org/openide/util/RequestProcessor.java 17 Mar 2006 19:51:05 -0000 1.12.2.1 @@ -119,12 +119,12 @@ private Object processorLock = new Object(); /** The set holding all the Processors assigned to this RequestProcessor */ - private HashSet processors = new HashSet(); + private HashSet processors = new HashSet(); /** Actualy the first item is pending to be processed. * Can be accessed/trusted only under the above processorLock lock. * If null, nothing is scheduled and the processor is not running. */ - private List queue = new LinkedList(); + private List queue = new LinkedList(); /** Number of currently running processors. If there is a new request * and this number is lower that the throughput, new Processor is asked @@ -442,7 +442,7 @@ queue.add(item); item.enqueued = true; } else { - for (ListIterator it = queue.listIterator(); it.hasNext();) { + for (ListIterator it = queue.listIterator(); it.hasNext();) { Item next = (Item) it.next(); if (iprio > next.getPriority()) { @@ -805,7 +805,7 @@ */ private static class Processor extends Thread { /** A stack containing all the inactive Processors */ - private static Stack pool = new Stack(); + private static Stack pool = new Stack(); /* One minute of inactivity and the Thread will die if not assigned */ private static final int INACTIVE_TIMEOUT = 60000; @@ -1033,8 +1033,8 @@ * end of the task. */ static ThreadGroup getTopLevelThreadGroup() { - java.security.PrivilegedAction run = new java.security.PrivilegedAction() { - public Object run() { + java.security.PrivilegedAction run = new java.security.PrivilegedAction() { + public ThreadGroup run() { ThreadGroup current = Thread.currentThread().getThreadGroup(); while (current.getParent() != null) { @@ -1045,7 +1045,7 @@ } }; - return (ThreadGroup) java.security.AccessController.doPrivileged(run); + return java.security.AccessController.doPrivileged(run); } } } Index: openide/util/src/org/openide/util/SharedClassObject.java =================================================================== RCS file: /cvs/openide/util/src/org/openide/util/SharedClassObject.java,v retrieving revision 1.4 retrieving revision 1.4.2.1 diff -u -r1.4 -r1.4.2.1 --- openide/util/src/org/openide/util/SharedClassObject.java 18 Jan 2006 05:23:05 -0000 1.4 +++ openide/util/src/org/openide/util/SharedClassObject.java 17 Mar 2006 19:51:06 -0000 1.4.2.1 @@ -50,7 +50,7 @@ private static final Object PROP_SUPPORT = new Object(); /** Map (Class, DataEntry) that maps Classes to maps of any objects */ - private static final Map values = new WeakHashMap(4); + private static final Map values = new WeakHashMap(37); /** A set of all classes for which we are currently inside createInstancePrivileged. * If a SCO constructor is called when an instance of that class already exists, normally @@ -60,12 +60,12 @@ * second instance (because it is nobody's fault and it will be handled OK). * Map from class name to nesting count. */ - private static final Map instancesBeingCreated = new HashMap(3); // Map + private static final Map instancesBeingCreated = new HashMap(7); /** Set of classes to not warn about any more. * Names only. */ - private static final Set alreadyWarnedAboutDupes = new HashSet(); // Set + private static final Set alreadyWarnedAboutDupes = new HashSet(); // private static final ErrorManager err = ErrorManager.getDefault().getInstance("org.openide.util.SharedClassObject"); // NOI18N /** data entry for this class */ @@ -456,7 +456,7 @@ * @param clazz the shared class to look for * @return the instance, or null if such does not exists */ - public static SharedClassObject findObject(Class clazz) { + public static T findObject(Class clazz) { return findObject(clazz, false); } @@ -469,7 +469,7 @@ * @return an instance, or null if there was none and create was false * @exception IllegalArgumentException if a new instance could not be created for some reason */ - public static SharedClassObject findObject(Class clazz, boolean create) { + public static T findObject(Class clazz, boolean create) { // synchronizing on the same object as returned from getLock() synchronized (clazz.getName().intern()) { DataEntry de = (DataEntry) values.get(clazz); @@ -480,10 +480,10 @@ if ((obj == null) && create) { // try to create new instance - PrivilegedExceptionAction action = new SetAccessibleAction(clazz); + SetAccessibleAction action = new SetAccessibleAction(clazz); try { - obj = (SharedClassObject) AccessController.doPrivileged(action); + obj = AccessController.doPrivileged(action); } catch (PrivilegedActionException e) { Exception ex = e.getException(); IllegalArgumentException newEx = new IllegalArgumentException(ex.toString()); @@ -509,7 +509,7 @@ throw new IllegalStateException("Inconsistent state: " + clazz); // NOI18N } - return obj2; + return clazz.cast(obj2); } } @@ -523,7 +523,7 @@ // if such state exists it is deserialized before the object is returned from lookup. if (obj.isSystemOption()) { // Lookup will find serialized version of searched object and deserialize it - final Lookup.Result r = Lookup.getDefault().lookup(new Lookup.Template(clazz)); + final Lookup.Result r = Lookup.getDefault().lookup(new Lookup.Template(clazz)); if (r.allInstances().isEmpty()) { // #17711: folder lookup not yet initialized. Try to load the option later. @@ -570,7 +570,7 @@ throw new IllegalStateException("Inconsistent state: " + clazz); // NOI18N } - return obj; + return clazz.cast(obj); } } @@ -595,9 +595,9 @@ err.notify(ErrorManager.INFORMATIONAL, t); } - static Object createInstancePrivileged(Class clazz) + static SharedClassObject createInstancePrivileged(Class clazz) throws Exception { - java.lang.reflect.Constructor c = clazz.getDeclaredConstructor(new Class[0]); + java.lang.reflect.Constructor c = clazz.getDeclaredConstructor(new Class[0]); c.setAccessible(true); String name = clazz.getName(); @@ -646,7 +646,7 @@ static final long serialVersionUID = 1327893248974327640L; /** the class */ - private Class clazz; + private Class clazz; /** class name, in case clazz could not be reloaded */ private String name; @@ -714,7 +714,7 @@ // make readResolve accessible (it can have any access modifier) resolveMethod.setAccessible(true); - return resolveMethod.invoke(object, null); + return resolveMethod.invoke(object); } catch (Exception ex) { // checked or runtime does not matter - we must survive String banner = "Skipping " + object.getClass() + " resolution:"; //NOI18N @@ -777,13 +777,13 @@ */ static final class DataEntry extends Object { /** The data */ - private HashMap map; + private HashMap map; /** The reference counter */ private int count = 0; /** weak reference to an object of this class */ - private WeakReference ref = new WeakReference(null); + private WeakReference ref = new WeakReference(null); /** inited? */ private boolean initialized = false; @@ -807,12 +807,12 @@ * @param obj the requestor object * @return the data */ - Map getMap(SharedClassObject obj) { + Map getMap(SharedClassObject obj) { ensureValid(obj); if (map == null) { // to signal invalid state - map = new HashMap(); + map = new HashMap(); } if (!initialized) { @@ -836,7 +836,7 @@ if (map == null) { // to signal invalid state - map = new HashMap(); + map = new HashMap(); ret = null; } else { ret = map.get(key); @@ -865,7 +865,7 @@ if (map == null) { // to signal invalid state - map = new HashMap(); + map = new HashMap(); } return map; @@ -932,7 +932,7 @@ SharedClassObject s = (SharedClassObject) ref.get(); if (s == null) { - ref = new WeakReference(obj); + ref = new WeakReference(obj); return obj; } else { @@ -962,14 +962,14 @@ } } - static final class SetAccessibleAction implements PrivilegedExceptionAction { - Class klass; + static final class SetAccessibleAction implements PrivilegedExceptionAction { + Class klass; - SetAccessibleAction(Class klass) { + SetAccessibleAction(Class klass) { this.klass = klass; } - public Object run() throws Exception { + public SharedClassObject run() throws Exception { return createInstancePrivileged(klass); } } Index: openide/util/src/org/openide/util/Task.java =================================================================== RCS file: /cvs/openide/util/src/org/openide/util/Task.java,v retrieving revision 1.2 retrieving revision 1.2.24.1 diff -u -r1.2 -r1.2.24.1 --- openide/util/src/org/openide/util/Task.java 4 Oct 2005 09:18:56 -0000 1.2 +++ openide/util/src/org/openide/util/Task.java 17 Mar 2006 19:51:04 -0000 1.2.24.1 @@ -44,9 +44,8 @@ } /** map of subclasses to booleans whether they override waitFinished() or not - * */ - private static java.util.WeakHashMap overrides; + private static java.util.WeakHashMap overrides; /** request processor for workarounding compatibility problem with * classes that do not override waitFinished (long) @@ -60,7 +59,7 @@ private boolean finished; /** listeners for the finish of task (TaskListener) */ - private HashSet list; + private HashSet list; /** Create a new task. * The runnable should provide its own error-handling, as @@ -225,7 +224,7 @@ */ public synchronized void addTaskListener(TaskListener l) { if (list == null) { - list = new HashSet(); + list = new HashSet(); } list.add(l); @@ -263,18 +262,18 @@ return true; } - java.util.WeakHashMap m; + java.util.WeakHashMap m; Boolean does; synchronized (Task.class) { if (overrides == null) { - overrides = new java.util.WeakHashMap(); + overrides = new java.util.WeakHashMap(); RP = new RequestProcessor("Timeout waitFinished compatibility processor", 255); // NOI18N } m = overrides; - does = (Boolean) m.get(getClass()); + does = m.get(getClass()); if (does != null) { return does.booleanValue(); Index: openide/util/src/org/openide/util/TimedSoftReference.java =================================================================== RCS file: /cvs/openide/util/src/org/openide/util/TimedSoftReference.java,v retrieving revision 1.1 retrieving revision 1.1.48.1 diff -u -r1.1 -r1.1.48.1 --- openide/util/src/org/openide/util/TimedSoftReference.java 21 Apr 2005 20:16:13 -0000 1.1 +++ openide/util/src/org/openide/util/TimedSoftReference.java 17 Mar 2006 19:51:04 -0000 1.1.48.1 @@ -37,11 +37,11 @@ * * @author Jesse Glick */ -final class TimedSoftReference extends SoftReference implements Runnable { +final class TimedSoftReference extends SoftReference implements Runnable { private static final int TIMEOUT = 30000; private static final RequestProcessor RP = new RequestProcessor("TimedSoftReference"); // NOI18N private RequestProcessor.Task task; - private Object o; + private T o; private final Map m; private final Object k; @@ -56,7 +56,7 @@ * @param m a map in which this reference may serve as a value * @param k the key whose value in m may be this reference */ - public TimedSoftReference(Object o, Map m, Object k) { + public TimedSoftReference(T o, Map m, Object k) { super(o, Utilities.activeReferenceQueue()); this.o = o; this.m = m; @@ -86,7 +86,7 @@ } } - public Object get() { + public T get() { synchronized (m) { if (o == null) { o = super.get(); Index: openide/util/src/org/openide/util/TopologicalSortException.java =================================================================== RCS file: /cvs/openide/util/src/org/openide/util/TopologicalSortException.java,v retrieving revision 1.1 retrieving revision 1.1.48.1 diff -u -r1.1 -r1.1.48.1 --- openide/util/src/org/openide/util/TopologicalSortException.java 21 Apr 2005 20:16:13 -0000 1.1 +++ openide/util/src/org/openide/util/TopologicalSortException.java 17 Mar 2006 19:51:05 -0000 1.1.48.1 @@ -37,7 +37,7 @@ private int counter; /** vertexes sorted by increasing value of y */ - private Stack dualGraph = new Stack(); + private Stack dualGraph = new Stack(); TopologicalSortException(Collection vertexes, Map edges) { this.vertexes = vertexes; @@ -52,10 +52,12 @@ public final List partialSort() { Set[] all = topologicalSets(); - ArrayList res = new ArrayList(vertexes.size()); + ArrayList res = new ArrayList(vertexes.size()); for (int i = 0; i < all.length; i++) { - res.addAll(all[i]); + for (Object e : all[i]) { + res.add(e); + } } return res; @@ -75,7 +77,7 @@ public final Set[] unsortableSets() { Set[] all = topologicalSets(); - ArrayList unsort = new ArrayList(); + ArrayList unsort = new ArrayList(); for (int i = 0; i < all.length; i++) { if ((all[i].size() > 1) || !(all[i] instanceof HashSet)) { @@ -83,7 +85,7 @@ } } - return (Set[]) unsort.toArray(new Set[0]); + return unsort.toArray(new Set[0]); } /** Adds description why the graph cannot be sorted. @@ -137,7 +139,7 @@ return result; } - HashMap vertexInfo = new HashMap(); + HashMap vertexInfo = new HashMap(); // computes value X and Y for each vertex counter = 0; @@ -151,15 +153,15 @@ // now connect vertexes that cannot be sorted into own // sets // map from the original objects to - Map objectsToSets = new HashMap(); + Map objectsToSets = new HashMap(); - ArrayList sets = new ArrayList(); + ArrayList sets = new ArrayList(); while (!dualGraph.isEmpty()) { Vertex v = (Vertex) dualGraph.pop(); if (!v.visited) { - Set set = new HashSet(); + Set set = new HashSet(); visitDualGraph(v, set); if ((set.size() == 1) && v.edgesFrom.contains(v)) { @@ -185,7 +187,7 @@ // now topologically sort the sets // 1. prepare the map - HashMap edgesBetweenSets = new HashMap(); + HashMap> edgesBetweenSets = new HashMap>(); it = edges.entrySet().iterator(); while (it.hasNext()) { @@ -196,19 +198,19 @@ continue; } - Set from = (Set) objectsToSets.get(entry.getKey()); + Set from = objectsToSets.get(entry.getKey()); - Collection setsTo = (Collection) edgesBetweenSets.get(from); + Collection setsTo = edgesBetweenSets.get(from); if (setsTo == null) { - setsTo = new ArrayList(); + setsTo = new ArrayList(); edgesBetweenSets.put(from, setsTo); } Iterator convert = leadsTo.iterator(); while (convert.hasNext()) { - Set to = (Set) objectsToSets.get(convert.next()); + Set to = objectsToSets.get(convert.next()); if (from != to) { // avoid self cycles @@ -219,7 +221,8 @@ // 2. do the sort try { - result = (Set[]) Utilities.topologicalSort(sets, edgesBetweenSets).toArray(new Set[0]); + List listResult = Utilities.topologicalSort(sets, edgesBetweenSets); + result = listResult.toArray(new Set[0]); } catch (TopologicalSortException ex) { throw new IllegalStateException("Cannot happen"); // NOI18N } @@ -232,7 +235,7 @@ * @param vertex current vertex * @param vertexInfo the info */ - private Vertex constructDualGraph(int counter, Object vertex, HashMap vertexInfo) { + private Vertex constructDualGraph(int counter, Object vertex, HashMap vertexInfo) { Vertex info = (Vertex) vertexInfo.get(vertex); if (info == null) { @@ -269,7 +272,7 @@ * @param vertex vertex to start from * @param visited list of all objects that we've been to */ - private void visitDualGraph(Vertex vertex, Collection visited) { + private void visitDualGraph(Vertex vertex, Collection visited) { if (vertex.visited) { return; } @@ -289,12 +292,12 @@ * comparable by the value of Y, but only after the value is set, * so the sort has to be done latelly. */ - private static final class Vertex implements Comparable { + private static final class Vertex implements Comparable { /** the found object */ public Object object; /** list of vertexes that point to this one */ - public List edgesFrom = new ArrayList(); + public List edgesFrom = new ArrayList(); /** the counter state when we entered the vertex */ public final int x; @@ -331,10 +334,8 @@ * @return a negative integer, zero, or a positive integer as this object * is less than, equal to, or greater than the specified object. */ - public int compareTo(Object o) { - Vertex v = (Vertex) o; - - return v.y - y; + public int compareTo(Vertex o) { + return o.y - y; } } } Index: openide/util/src/org/openide/util/Utilities.java =================================================================== RCS file: /cvs/openide/util/src/org/openide/util/Utilities.java,v retrieving revision 1.10 retrieving revision 1.10.2.1 diff -u -r1.10 -r1.10.2.1 --- openide/util/src/org/openide/util/Utilities.java 28 Feb 2006 18:11:25 -0000 1.10 +++ openide/util/src/org/openide/util/Utilities.java 17 Mar 2006 19:51:04 -0000 1.10.2.1 @@ -154,11 +154,11 @@ private static final int TYPICAL_MACOSX_MENU_HEIGHT = 24; /** variable holding the activeReferenceQueue */ - private static ReferenceQueue activeReferenceQueue; + private static ReferenceQueue activeReferenceQueue; /** reference to map that maps allowed key names to their values (String, Integer) and reference to map for mapping of values to their names */ - private static Reference namesAndValues; + private static Reference namesAndValues; /** The operating system on which NetBeans runs*/ private static int operatingSystem = -1; @@ -242,7 +242,7 @@ * * @since 3.11 */ - public static synchronized ReferenceQueue activeReferenceQueue() { + public static synchronized ReferenceQueue activeReferenceQueue() { if (activeReferenceQueue == null) { activeReferenceQueue = new ActiveQueue(false); } @@ -492,7 +492,7 @@ return workingSet; } - java.util.ArrayList lines = new java.util.ArrayList(); + java.util.ArrayList lines = new java.util.ArrayList(); int lineStart = 0; // the position of start of currently processed line in the original string @@ -616,7 +616,7 @@ return original; } - java.util.Vector lines = new java.util.Vector(); + java.util.Vector lines = new java.util.Vector(); int lineStart = 0; // the position of start of currently processed line in the original string int lastSpacePos = -1; @@ -1323,7 +1323,7 @@ int INPARAMPENDING = 0x2; // INPARAM + \ int STICK = 0x4; // INPARAM + " or STICK + non_" // NOI18N int STICKPENDING = 0x8; // STICK + \ - Vector params = new Vector(5, 5); + Vector params = new Vector(5, 5); char c; int state = NULL; @@ -1532,8 +1532,8 @@ Field[] fields = KeyEvent.class.getDeclaredFields(); - HashMap names = new HashMap(((fields.length * 4) / 3) + 5, 0.75f); - HashMap values = new HashMap(((fields.length * 4) / 3) + 5, 0.75f); + HashMap names = new HashMap(((fields.length * 4) / 3) + 5, 0.75f); + HashMap values = new HashMap(((fields.length * 4) / 3) + 5, 0.75f); for (int i = 0; i < fields.length; i++) { if (Modifier.isStatic(fields[i].getModifiers())) { @@ -1569,7 +1569,7 @@ HashMap[] arr = { names, values }; - namesAndValues = new SoftReference(arr); + namesAndValues = new SoftReference(arr); return arr; } @@ -1741,7 +1741,7 @@ */ public static KeyStroke[] stringToKeys(String s) { StringTokenizer st = new StringTokenizer(s.toUpperCase(Locale.ENGLISH), " "); // NOI18N - ArrayList arr = new ArrayList(); + ArrayList arr = new ArrayList(); while (st.hasMoreElements()) { s = st.nextToken(); @@ -1755,7 +1755,7 @@ arr.add(k); } - return (KeyStroke[]) arr.toArray(new KeyStroke[arr.size()]); + return arr.toArray(new KeyStroke[arr.size()]); } /** Adds characters for modifiers to the buffer. @@ -2079,6 +2079,7 @@ * @throws UnorderableException if the specified partial order is inconsistent on this list * @deprecated Deprecated in favor of the potentially much faster (and possibly more correct) {@link #topologicalSort}. */ + @SuppressWarnings("unchecked") // do not bother, it is deprecated anyway public static List partialSort(List l, Comparator c, boolean stable) throws UnorderableException { // map from objects in the list to null or sets of objects they are greater than @@ -2200,17 +2201,17 @@ * @since 3.30 * @see Issue #27286 */ - public static List topologicalSort(Collection c, Map edges) + public static List topologicalSort(Collection c, Map> edges) throws TopologicalSortException { - Map finished = new HashMap(); - List r = new ArrayList(Math.max(c.size(), 1)); - List cRev = new ArrayList(c); + Map finished = new HashMap(); + List r = new ArrayList(Math.max(c.size(), 1)); + List cRev = new ArrayList(c); Collections.reverse(cRev); - Iterator it = cRev.iterator(); + Iterator it = cRev.iterator(); while (it.hasNext()) { - List cycle = visit(it.next(), edges, finished, r); + List cycle = visit(it.next(), edges, finished, r); if (cycle != null) { throw new TopologicalSortException(cRev, edges); @@ -2232,7 +2233,12 @@ * @param r the order in progress * @return list with detected cycle */ - static List visit(Object node, Map edges, Map finished, List r) { + static List visit( + T node, + Map> edges, + Map finished, + List r + ) { Boolean b = (Boolean) finished.get(node); //System.err.println("node=" + node + " color=" + b); @@ -2241,22 +2247,22 @@ return null; } - ArrayList cycle = new ArrayList(); + ArrayList cycle = new ArrayList(); cycle.add(node); finished.put(node, null); return cycle; } - Collection e = (Collection) edges.get(node); + Collection e = edges.get(node); if (e != null) { finished.put(node, Boolean.FALSE); - Iterator it = e.iterator(); + Iterator it = e.iterator(); while (it.hasNext()) { - List cycle = visit(it.next(), edges, finished, r); + List cycle = visit(it.next(), edges, finished, r); if (cycle != null) { if (cycle instanceof ArrayList) { @@ -2430,11 +2436,11 @@ re = new RE13(); // } - TreeSet list = new TreeSet( - new Comparator() { - public int compare(Object o1, Object o2) { - String s1 = ((String[]) o1)[0]; - String s2 = ((String[]) o2)[0]; + TreeSet list = new TreeSet( + new Comparator() { + public int compare(String[] o1, String[] o2) { + String s1 = o1[0]; + String s2 = o2[0]; int i1 = s1.length(); int i2 = s2.length(); @@ -2500,7 +2506,7 @@ * @param resource URL identifiing transaction table * @param results will be filled with String[2] */ - private static void loadTranslationFile(RE re, BufferedReader reader, Set results) + private static void loadTranslationFile(RE re, BufferedReader reader, Set results) throws IOException { for (;;) { String line = reader.readLine(); @@ -2575,7 +2581,7 @@ JPopupMenu menu = org.netbeans.modules.openide.util.AWTBridge.getDefault().createEmptyPopup(); // keeps actions for which was menu item created already - HashSet counted = new HashSet(); + HashSet counted = new HashSet(); boolean haveHadNonSep = false; boolean needSep = false; @@ -2957,7 +2963,7 @@ /** Implementation of the active queue. */ - private static final class ActiveQueue extends ReferenceQueue implements Runnable { + private static final class ActiveQueue extends ReferenceQueue implements Runnable { private boolean running; private boolean deprecated; @@ -2970,15 +2976,15 @@ t.start(); } - public Reference poll() { + public Reference poll() { throw new java.lang.UnsupportedOperationException(); } - public Reference remove(long timeout) throws IllegalArgumentException, InterruptedException { + public Reference remove(long timeout) throws IllegalArgumentException, InterruptedException { throw new java.lang.InterruptedException(); } - public Reference remove() throws InterruptedException { + public Reference remove() throws InterruptedException { throw new java.lang.InterruptedException(); } Index: openide/util/src/org/openide/util/UtilitiesCompositeActionMap.java =================================================================== RCS file: /cvs/openide/util/src/org/openide/util/UtilitiesCompositeActionMap.java,v retrieving revision 1.1 retrieving revision 1.1.48.1 diff -u -r1.1 -r1.1.48.1 --- openide/util/src/org/openide/util/UtilitiesCompositeActionMap.java 21 Apr 2005 20:16:13 -0000 1.1 +++ openide/util/src/org/openide/util/UtilitiesCompositeActionMap.java 17 Mar 2006 19:51:04 -0000 1.1.48.1 @@ -76,7 +76,7 @@ } private Object[] keys(boolean all) { - java.util.HashSet keys = new java.util.HashSet(); + java.util.HashSet keys = new java.util.HashSet(); Component c = component; @@ -85,7 +85,7 @@ javax.swing.ActionMap m = ((JComponent) c).getActionMap(); if (m != null) { - java.util.List l; + java.util.List l; if (all) { l = java.util.Arrays.asList(m.allKeys()); Index: openide/util/src/org/openide/util/WeakListenerImpl.java =================================================================== RCS file: /cvs/openide/util/src/org/openide/util/WeakListenerImpl.java,v retrieving revision 1.4 retrieving revision 1.4.2.1 diff -u -r1.4 -r1.4.2.1 --- openide/util/src/org/openide/util/WeakListenerImpl.java 5 Mar 2006 21:08:57 -0000 1.4 +++ openide/util/src/org/openide/util/WeakListenerImpl.java 17 Mar 2006 19:51:04 -0000 1.4.2.1 @@ -29,6 +29,8 @@ import java.lang.reflect.Proxy; import java.util.EventListener; import java.util.EventObject; +import java.util.Map; +import java.util.WeakHashMap; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; import javax.swing.event.DocumentEvent; @@ -49,7 +51,7 @@ Class listenerClass; /** weak reference to source */ - private Reference source; + private Reference source; /** * @param listenerClass class/interface of the listener @@ -81,7 +83,7 @@ if (source == null) { this.source = null; } else { - this.source = new WeakReference(source); + this.source = new WeakReference(source); } } @@ -116,11 +118,11 @@ return getClass().getName() + "[" + ((listener == null) ? "null" : (listener.getClass().getName() + "]")); } - public static EventListener create(Class lType, Class apiType, EventListener l, Object source) { + public static T create(Class lType, Class apiType, T l, Object source) { ProxyListener pl = new ProxyListener(lType, apiType, l); pl.setSource(source); - return (EventListener) pl.proxy; + return lType.cast(pl.proxy); } /** Weak property change listener @@ -343,7 +345,7 @@ private static Method equalsMth; /** Class -> Reference(Constructor) */ - private static final java.util.WeakHashMap constructors = new java.util.WeakHashMap(); + private static final Map> constructors = new WeakHashMap>(); /** proxy generated for this listener */ public final Object proxy; @@ -360,7 +362,7 @@ if (proxyConstructor == null) { Class proxyClass = Proxy.getProxyClass(c.getClassLoader(), new Class[] { c }); proxyConstructor = proxyClass.getConstructor(new Class[] { InvocationHandler.class }); - constructors.put(c, new SoftReference(proxyConstructor)); + constructors.put(c, new SoftReference(proxyConstructor)); } Object p; @@ -457,7 +459,7 @@ /** Reference that also holds ref to WeakListenerImpl. */ - private static final class ListenerReference extends WeakReference implements Runnable { + private static final class ListenerReference extends WeakReference implements Runnable { private static Class lastClass; private static String lastMethodName; private static Method lastRemove; @@ -481,7 +483,7 @@ if (weakListener.source != source) { // plan new cleanup into the activeReferenceQueue with this listener and // provided source - weakListener.source = new WeakReference(source) { + weakListener.source = new WeakReference (source) { ListenerReference doNotGCRef = new ListenerReference(new Object(), weakListener); }; } Index: openide/util/src/org/openide/util/WeakListeners.java =================================================================== RCS file: /cvs/openide/util/src/org/openide/util/WeakListeners.java,v retrieving revision 1.1 retrieving revision 1.1.48.1 diff -u -r1.1 -r1.1.48.1 --- openide/util/src/org/openide/util/WeakListeners.java 21 Apr 2005 20:16:14 -0000 1.1 +++ openide/util/src/org/openide/util/WeakListeners.java 17 Mar 2006 19:51:06 -0000 1.1.48.1 @@ -185,7 +185,7 @@ * @return an instance of lType delegating all the interface * calls to l. */ - public static EventListener create(Class lType, EventListener l, Object source) { + public static T create(Class lType, T l, Object source) { if (!lType.isInterface()) { throw new IllegalArgumentException("Not interface: " + lType); } @@ -228,7 +228,7 @@ * calls to l. * @since 4.12 */ - public static EventListener create(Class lType, Class apiType, EventListener l, Object source) { + public static T create(Class lType, Class apiType, T l, Object source) { if (!lType.isInterface()) { throw new IllegalArgumentException("Not interface: " + lType); } Index: openide/util/src/org/openide/util/WeakSet.java =================================================================== RCS file: /cvs/openide/util/src/org/openide/util/WeakSet.java,v retrieving revision 1.2 retrieving revision 1.2.30.1 diff -u -r1.2 -r1.2.30.1 --- openide/util/src/org/openide/util/WeakSet.java 12 Sep 2005 21:13:07 -0000 1.2 +++ openide/util/src/org/openide/util/WeakSet.java 17 Mar 2006 19:51:05 -0000 1.2.30.1 @@ -34,7 +34,7 @@ * * @author Ales Novak */ -public class WeakSet extends AbstractSet implements Cloneable, Serializable { +public class WeakSet extends AbstractSet implements Cloneable, Serializable { static final long serialVersionUID = 3062376055928236721L; /** load factor */ @@ -47,14 +47,14 @@ private long modcount; /** Reference queue of collected weak refs */ - private transient ReferenceQueue refq; + private transient ReferenceQueue refq; /** Count of null in this set */ long nullCount; /** An array of Entries */ - private transient Entry[] entries; - transient Entry iterChain; + private transient Entry[] entries; + transient Entry iterChain; /** Constructs a new set. */ public WeakSet() { @@ -64,7 +64,7 @@ /** Constructs a new set containing the elements in the specified collection. * @param c a collection to add */ - public WeakSet(Collection c) { + public WeakSet(Collection c) { this(); addAll(c); } @@ -90,8 +90,8 @@ modcount = 0; this.loadFactor = loadFactor; nullCount = 0; - refq = new ReferenceQueue(); - entries = new Entry[initialCapacity]; + refq = new ReferenceQueue(); + entries = Entry.createArray(initialCapacity); iterChain = null; } @@ -99,7 +99,7 @@ * * @param o an Object to add */ - public boolean add(Object o) { + public boolean add(E o) { if (o == null) { size++; nullCount++; @@ -118,8 +118,8 @@ size++; int hash = hashIt(o); - Entry next = entries[hash]; - iterChain = entries[hash] = new Entry(o, refq, next, iterChain); + Entry next = entries[hash]; + iterChain = entries[hash] = new Entry(this, o, refq, next, iterChain); rehash(); return true; @@ -139,11 +139,11 @@ /** Returns a shallow copy of this WeakSet instance: the elements themselves are not cloned. */ public Object clone() { - WeakSet nws = new WeakSet(1, loadFactor); + WeakSet nws = new WeakSet(1, loadFactor); nws.size = size; nws.nullCount = nullCount; - Entry[] cloned = new Entry[entries.length]; + Entry[] cloned = Entry.createArray(entries.length); nws.entries = cloned; for (int i = 0; i < cloned.length; i++) { @@ -157,7 +157,7 @@ } // chains into nws iterator chain - Entry entry = cloned[i]; + Entry entry = cloned[i]; while (entry != null) { entry.chainIntoIter(nws.iterChain); @@ -188,7 +188,7 @@ } /** Returns an iterator over the elements in this set. */ - public Iterator iterator() { + public Iterator iterator() { return new WeakSetIterator(); } @@ -229,9 +229,9 @@ return size; } - public Object[] toArray(Object[] array) { - ArrayList list = new ArrayList(array.length); - Iterator it = iterator(); + public T[] toArray(T[] array) { + ArrayList list = new ArrayList(array.length); + Iterator it = iterator(); while (it.hasNext()) { list.add(it.next()); @@ -241,8 +241,8 @@ } public Object[] toArray() { - ArrayList list = new ArrayList(); - Iterator it = iterator(); + ArrayList list = new ArrayList(); + Iterator it = iterator(); while (it.hasNext()) { list.add(it.next()); @@ -273,7 +273,7 @@ /** Checks if the queue is empty if not pending weak refs are removed. */ void checkRefQueue() { for (;;) { - Entry entry = (Entry) refq.poll(); + Entry entry = Entry.class.cast(refq.poll()); if (entry == null) { break; @@ -328,23 +328,24 @@ obtos.writeObject(toArray()); } + @SuppressWarnings("unchecked") private void readObject(ObjectInputStream obtis) throws IOException, ClassNotFoundException { obtis.defaultReadObject(); Object[] arr = (Object[]) obtis.readObject(); entries = new Entry[(int) (size * 1.5)]; - refq = new ReferenceQueue(); + refq = new ReferenceQueue(); for (int i = 0; i < arr.length; i++) { - add(arr[i]); + add((E)arr[i]); } } - class WeakSetIterator implements Iterator { - Entry current; - Entry next; - Object currentObj; - Object nextObj; + class WeakSetIterator implements Iterator { + Entry current; + Entry next; + E currentObj; + E nextObj; final long myModcount; long myNullCount; @@ -354,13 +355,13 @@ current = null; next = null; - Entry ee = iterChain; + Entry ee = iterChain; if (ee == null) { return; } - Object o = ee.get(); + E o = ee.get(); while (ee.isEnqueued()) { ee = ee.iterChainNext; @@ -382,7 +383,7 @@ return ((myNullCount > 0) || (next != null)); } - public Object next() { + public E next() { checkModcount(); checkRefQueue(); @@ -432,16 +433,21 @@ } /** Entries of this set */ - class Entry extends WeakReference { + static class Entry extends WeakReference { + /** reference to outer WeakSet */ + private WeakSet set; + // double linked list - Entry prev; - Entry next; + Entry prev; + Entry next; private final int hashcode; - Entry iterChainNext; - Entry iterChainPrev; + Entry iterChainNext; + Entry iterChainPrev; - Entry(Object referenced, ReferenceQueue q, Entry next, Entry nextInIter) { + Entry(WeakSet set, E referenced, ReferenceQueue q, Entry next, Entry nextInIter) { super(referenced, q); + this.set = set; + this.next = next; this.prev = null; @@ -450,7 +456,7 @@ } if (referenced != null) { - hashcode = hashIt(referenced); + hashcode = set.hashIt(referenced); } else { hashcode = 0; } @@ -458,7 +464,12 @@ chainIntoIter(nextInIter); } - void chainIntoIter(Entry nextInIter) { + @SuppressWarnings("unchecked") + static final Entry[] createArray(int size) { + return new Entry[size]; + } + + void chainIntoIter(Entry nextInIter) { iterChainNext = nextInIter; if (nextInIter != null) { @@ -489,11 +500,11 @@ if (iterChainPrev != null) { iterChainPrev.iterChainNext = iterChainNext; } else { // root - iterChain = iterChainNext; + set.iterChain = iterChainNext; } - if (entries[hashcode] == this) { - entries[hashcode] = next; + if (set.entries[hashcode] == this) { + set.entries[hashcode] = next; } prev = null; @@ -516,8 +527,8 @@ } } - public Entry clone(ReferenceQueue q) { - return new Entry(get(), q, ((next != null) ? (Entry) next.clone(q) : null), null); + public Entry clone(ReferenceQueue q) { + return new Entry(set, get(), q, next != null ? next.clone(q) : null, null); } } } Index: openide/util/src/org/openide/util/actions/CallableSystemAction.java =================================================================== RCS file: /cvs/openide/util/src/org/openide/util/actions/CallableSystemAction.java,v retrieving revision 1.4 retrieving revision 1.4.14.1 diff -u -r1.4 -r1.4.14.1 --- openide/util/src/org/openide/util/actions/CallableSystemAction.java 1 Dec 2005 12:05:09 -0000 1.4 +++ openide/util/src/org/openide/util/actions/CallableSystemAction.java 17 Mar 2006 19:51:06 -0000 1.4.14.1 @@ -42,7 +42,7 @@ * Set of action classes for which we have already issued a warning that * {@link #asynchronous} was not overridden to return false. */ - private static final Set warnedAsynchronousActions = new WeakSet(); // Set + private static final Set warnedAsynchronousActions = new WeakSet(); private static final boolean DEFAULT_ASYNCH = !Boolean.getBoolean( "org.openide.util.actions.CallableSystemAction.synchronousByDefault" ); Index: openide/util/src/org/openide/util/actions/CallbackSystemAction.java =================================================================== RCS file: /cvs/openide/util/src/org/openide/util/actions/CallbackSystemAction.java,v retrieving revision 1.6 retrieving revision 1.6.2.1 diff -u -r1.6 -r1.6.2.1 --- openide/util/src/org/openide/util/actions/CallbackSystemAction.java 28 Feb 2006 15:44:05 -0000 1.6 +++ openide/util/src/org/openide/util/actions/CallbackSystemAction.java 17 Mar 2006 19:51:06 -0000 1.6.2.1 @@ -44,10 +44,10 @@ private static final String PROP_ACTION_PERFORMER = "actionPerformer"; // NOI18N /** a list of all actions that has survive focus change set to false */ - private static final WeakSet notSurviving = new WeakSet(37); + private static final WeakSet> notSurviving = new WeakSet>(37); /** a list of CallableSystemAction actions surviving focus change */ - private static final WeakSet surviving = new WeakSet(37); + private static final WeakSet> surviving = new WeakSet>(37); /** key to access listener */ private static final Object LISTENER = new Object(); @@ -254,18 +254,18 @@ /** Array of actions from a set of classes. */ - private static ArrayList toInstances(java.util.Set s) { - ArrayList actions; + private static ArrayList toInstances(java.util.Set> s) { + ArrayList actions; synchronized (notSurviving) { - actions = new ArrayList(s.size()); + actions = new ArrayList(s.size()); - Iterator it = s.iterator(); + Iterator> it = s.iterator(); while (it.hasNext()) { - Class c = (Class) it.next(); + Class c = it.next(); - Object a = SystemAction.findObject(c, false); + SystemAction a = SystemAction.findObject(c, false); if (a != null) { actions.add(a); @@ -310,12 +310,12 @@ */ private static final class GlobalManager implements LookupListener { private static GlobalManager instance; - private Lookup.Result result; - private Reference actionMap = new WeakReference(null); + private Lookup.Result result; + private Reference actionMap = new WeakReference(null); private final ActionMap survive = new ActionMap(); private GlobalManager() { - result = Utilities.actionsGlobalContext().lookup(new Lookup.Template(ActionMap.class)); + result = Utilities.actionsGlobalContext().lookup(new Lookup.Template(ActionMap.class)); result.addLookupListener(this); resultChanged(null); } @@ -331,7 +331,7 @@ } public Action findGlobalAction(Object key, boolean surviveFocusChange) { - ActionMap map = (ActionMap) actionMap.get(); + ActionMap map = actionMap.get(); Action a = (map == null) ? null : map.get(key); if (surviveFocusChange) { @@ -363,7 +363,7 @@ /** Change all that do not survive ActionMap change */ public void resultChanged(org.openide.util.LookupEvent ev) { - ActionMap a = (ActionMap) Utilities.actionsGlobalContext().lookup(ActionMap.class); + ActionMap a = Utilities.actionsGlobalContext().lookup(ActionMap.class); if (errLog) { err.log("changed map : " + a); // NOI18N @@ -374,7 +374,7 @@ return; } - actionMap = new WeakReference(a); + actionMap = new WeakReference(a); if (errLog) { err.log("clearActionPerformers"); // NOI18N @@ -387,7 +387,7 @@ /** An action that holds a weak reference to other action. */ - private static final class WeakAction extends WeakReference implements Action { + private static final class WeakAction extends WeakReference implements Action { public WeakAction(Action delegate) { super(delegate); } @@ -428,12 +428,12 @@ /** A class that listens on changes in enabled state of an action * and updates the state of the action according to it. */ - private static final class ActionDelegateListener extends WeakReference implements PropertyChangeListener { + private static final class ActionDelegateListener extends WeakReference implements PropertyChangeListener { private WeakReference delegate; - public ActionDelegateListener(CallbackSystemAction c, javax.swing.Action delegate) { + public ActionDelegateListener(CallbackSystemAction c, Action delegate) { super(c); - this.delegate = new WeakReference(delegate); + this.delegate = new WeakReference(delegate); delegate.addPropertyChangeListener(this); } @@ -466,7 +466,7 @@ prev.removePropertyChangeListener(this); } - this.delegate = new WeakReference(action); + this.delegate = new WeakReference(action); action.addPropertyChangeListener(this); } @@ -497,7 +497,7 @@ private CallbackSystemAction delegate; /** lookup we are associated with (or null) */ - private org.openide.util.Lookup.Result result; + private Lookup.Result result; /** previous state of enabled */ private boolean enabled; @@ -516,7 +516,7 @@ this.weakL = org.openide.util.WeakListeners.propertyChange(this, null); this.enabled = a.getActionPerformer() != null; - this.result = actionContext.lookup(new org.openide.util.Lookup.Template(javax.swing.ActionMap.class)); + this.result = actionContext.lookup(new Lookup.Template(ActionMap.class)); this.result.addLookupListener( (LookupListener) org.openide.util.WeakListeners.create(LookupListener.class, this, this.result) ); @@ -579,7 +579,7 @@ last.removePropertyChangeListener(weakL); } - lastRef = new WeakReference(a); + lastRef = new WeakReference(a); a.addPropertyChangeListener(weakL); } Index: openide/util/src/org/openide/util/actions/SystemAction.java =================================================================== RCS file: /cvs/openide/util/src/org/openide/util/actions/SystemAction.java,v retrieving revision 1.4 retrieving revision 1.4.14.1 diff -u -r1.4 -r1.4.14.1 --- openide/util/src/org/openide/util/actions/SystemAction.java 1 Dec 2005 12:05:10 -0000 1.4 +++ openide/util/src/org/openide/util/actions/SystemAction.java 17 Mar 2006 19:51:06 -0000 1.4.14.1 @@ -52,7 +52,7 @@ /** Name of property for the action's display icon, if textual. */ private static final String PROP_ICON_TEXTUAL = "iconTextual"; // NOI18N private static ImageIcon BLANK_ICON = null; - private static final Set relativeIconResourceClasses = new HashSet(200); // Set + private static final Set relativeIconResourceClasses = new HashSet(200); // Matches NB 3.4 w/ openide-compat.jar; see #26491 private static final long serialVersionUID = -8361232596876856810L; @@ -74,8 +74,8 @@ * @exception ClassCastException if the class is not SystemAction * @exception IllegalArgumentException if the instance cannot be created */ - public static SystemAction get(Class actionClass) { - return (SystemAction) findObject(actionClass, true); + public static T get(Class actionClass) { + return findObject(actionClass, true); } /** Get a human presentable name of the action. @@ -332,7 +332,7 @@ * @return an array of both sets of actions in the same order */ public static SystemAction[] linkActions(SystemAction[] actions1, SystemAction[] actions2) { - List l = new Vector(Arrays.asList(actions1)); + List l = new Vector(Arrays.asList(actions1)); l.addAll(Arrays.asList(actions2)); return (SystemAction[]) l.toArray(actions1); Index: openide/util/src/org/openide/util/datatransfer/ExTransferable.java =================================================================== RCS file: /cvs/openide/util/src/org/openide/util/datatransfer/ExTransferable.java,v retrieving revision 1.2 retrieving revision 1.2.16.1 diff -u -r1.2 -r1.2.16.1 --- openide/util/src/org/openide/util/datatransfer/ExTransferable.java 16 Nov 2005 21:44:50 -0000 1.2 +++ openide/util/src/org/openide/util/datatransfer/ExTransferable.java 17 Mar 2006 19:51:09 -0000 1.2.16.1 @@ -46,7 +46,7 @@ } /** hash map that assigns objects to dataflavors (DataFlavor, Single) */ - private LinkedHashMap map; + private LinkedHashMap map; /** listeners */ private EventListenerList listeners; @@ -56,7 +56,7 @@ * @param o clipobard owner (or null) */ private ExTransferable(final Transferable t) { - map = new LinkedHashMap(); + map = new LinkedHashMap(); final DataFlavor[] df = t.getTransferDataFlavors(); @@ -356,7 +356,7 @@ * @param array array of flavors */ public boolean areDataFlavorsSupported(DataFlavor[] array) { - HashSet flav = new HashSet(); + HashSet flav = new HashSet(); for (int i = 0; i < array.length; i++) { flav.add(array[i]); Index: openide/util/src/org/openide/util/io/NbObjectOutputStream.java =================================================================== RCS file: /cvs/openide/util/src/org/openide/util/io/NbObjectOutputStream.java,v retrieving revision 1.3 retrieving revision 1.3.2.1 diff -u -r1.3 -r1.3.2.1 --- openide/util/src/org/openide/util/io/NbObjectOutputStream.java 18 Jan 2006 05:23:05 -0000 1.3 +++ openide/util/src/org/openide/util/io/NbObjectOutputStream.java 17 Mar 2006 19:51:09 -0000 1.3.2.1 @@ -37,7 +37,7 @@ */ public class NbObjectOutputStream extends ObjectOutputStream { private static final String SVUID = "serialVersionUID"; // NOI18N - private static final Set alreadyReported = new WeakSet(); // Set + private static final Set alreadyReported = new WeakSet(); static { // See below. @@ -47,8 +47,8 @@ alreadyReported.add("java.awt.geom.AffineTransform"); // NOI18N } - private static Map examinedClasses = new WeakHashMap(250); // Map - private final List serializing = new ArrayList(50); // List + private static Map examinedClasses = new WeakHashMap(250); + private final List serializing = new ArrayList(50); /** Create a new object output. * @param os the underlying output stream @@ -134,7 +134,7 @@ String classname = cl.getName(); if (alreadyReported.add(classname)) { - Set serializingUniq = new HashSet(); // Set + Set serializingUniq = new HashSet(); StringBuffer b = new StringBuffer("Serializable class "); // NOI18N b.append(classname); b.append(" does not declare serialVersionUID field. Encountered while storing: ["); // NOI18N Index: openide/util/src/org/openide/util/lookup/ALPairComparator.java =================================================================== RCS file: /cvs/openide/util/src/org/openide/util/lookup/ALPairComparator.java,v retrieving revision 1.1 retrieving revision 1.1.48.1 diff -u -r1.1 -r1.1.48.1 --- openide/util/src/org/openide/util/lookup/ALPairComparator.java 21 Apr 2005 20:16:19 -0000 1.1 +++ openide/util/src/org/openide/util/lookup/ALPairComparator.java 17 Mar 2006 19:51:08 -0000 1.1.48.1 @@ -13,14 +13,15 @@ package org.openide.util.lookup; import java.util.Comparator; +import org.openide.util.lookup.AbstractLookup.Pair; /** Implementation of comparator for AbstractLookup.Pair * * @author Jaroslav Tulach */ -final class ALPairComparator implements Comparator { - public static final Comparator DEFAULT = new ALPairComparator(); +final class ALPairComparator implements Comparator> { + public static final Comparator> DEFAULT = new ALPairComparator(); /** Creates a new instance of ALPairComparator */ private ALPairComparator() { @@ -28,10 +29,7 @@ /** Compares two items. */ - public int compare(Object obj, Object obj1) { - AbstractLookup.Pair i1 = (AbstractLookup.Pair) obj; - AbstractLookup.Pair i2 = (AbstractLookup.Pair) obj1; - + public int compare(Pair i1, Pair i2) { int result = i1.getIndex() - i2.getIndex(); if (result == 0) { Index: openide/util/src/org/openide/util/lookup/AbstractLookup.java =================================================================== RCS file: /cvs/openide/util/src/org/openide/util/lookup/AbstractLookup.java,v retrieving revision 1.6 retrieving revision 1.6.2.1 diff -u -r1.6 -r1.6.2.1 --- openide/util/src/org/openide/util/lookup/AbstractLookup.java 12 Jan 2006 16:29:54 -0000 1.6 +++ openide/util/src/org/openide/util/lookup/AbstractLookup.java 17 Mar 2006 19:51:08 -0000 1.6.2.1 @@ -24,6 +24,7 @@ import java.lang.ref.ReferenceQueue; import java.util.*; +import org.openide.util.Utilities; /** Implementation of the lookup from OpenAPIs that is based on the @@ -40,13 +41,6 @@ /** lock for initialization of the maps of lookups */ private static Object treeLock = new Object(); - /** This is a workaround for bug 35366 that probably has to be here until - * we end producing separate openide-lookup.jar. The activeReferenceQueue - * has to be obtained using reflection to prevent the openide-lookup.jar - * to be as large as openide-util.jar. - */ - private static Object activeQueue; - /** the tree that registers all items (or Integer as a treshold size) */ private Object tree; @@ -68,7 +62,7 @@ /** Constructor for testing purposes that allows specification of storage * as mechanism as well. */ - AbstractLookup(Content content, Storage storage) { + AbstractLookup(Content content, Storage storage) { this(content); this.tree = storage; initialize(); @@ -90,7 +84,7 @@ public String toString() { if (tree instanceof Storage) { - return "AbstractLookup" + lookup(new Lookup.Template(Object.class)).allItems(); // NOI18N + return "AbstractLookup" + lookup(new Lookup.Template(Object.class)).allItems(); // NOI18N } else { return super.toString(); } @@ -98,7 +92,8 @@ /** Entres the storage management system. */ - private AbstractLookup.Storage enterStorage() { + @SuppressWarnings("unchecked") + private AbstractLookup.Storage enterStorage() { for (;;) { synchronized (treeLock) { if (tree instanceof AbstractLookup.Storage) { @@ -119,9 +114,9 @@ continue; } else { // ok, tree is initialized and nobody is using it yet - tree = new DelegatingStorage((Storage) tree); + tree = new DelegatingStorage((Storage) tree); - return (Storage) tree; + return (Storage) tree; } } @@ -158,17 +153,21 @@ /** Notifies subclasses that a query is about to be processed. * @param template the template */ - protected void beforeLookup(Template template) { + protected void beforeLookup(Template template) { } /** The method to add instance to the lookup with. * @param pair class/instance pair */ - protected final void addPair(Pair pair) { - HashSet toNotify = new HashSet(); + protected final void addPair(Pair pair) { + addPairImpl(pair); + } + + private final void addPairImpl(Pair pair) { + HashSet toNotify = new HashSet(); - Object transaction = null; - AbstractLookup.Storage t = enterStorage(); + AbstractLookup.Storage t = enterStorage(); + Transaction transaction = null; try { transaction = t.beginTransaction(-2); @@ -188,7 +187,7 @@ t.endTransaction(transaction, toNotify); } else { // just finish the process by calling endTransaction - t.endTransaction(transaction, new HashSet()); + t.endTransaction(transaction, new HashSet()); } } finally { exitStorage(); @@ -200,11 +199,15 @@ /** Remove instance. * @param pair class/instance pair */ - protected final void removePair(Pair pair) { - HashSet toNotify = new HashSet(); + protected final void removePair(Pair pair) { + removePairImpl(pair); + } + + private void removePairImpl(Pair pair) { + HashSet toNotify = new HashSet(); - Object transaction = null; - AbstractLookup.Storage t = enterStorage(); + AbstractLookup.Storage t = enterStorage(); + Transaction transaction = null; try { transaction = t.beginTransaction(-1); @@ -220,24 +223,24 @@ /** Changes all pairs in the lookup to new values. * @param collection the collection of (Pair) objects */ - protected final void setPairs(Collection collection) { + protected final void setPairs(Collection collection) { notifyCollectedListeners(setPairsAndCollectListeners(collection)); } /** Getter for set of pairs. Package private contract with MetaInfServicesLookup. * @return a LinkedHashSet that can be modified */ - final LinkedHashSet getPairsAsLHS() { - AbstractLookup.Storage t = enterStorage(); + final LinkedHashSet> getPairsAsLHS() { + AbstractLookup.Storage t = enterStorage(); try { - Enumeration en = t.lookup(Object.class); - LinkedHashSet arr = new LinkedHashSet(); + Enumeration> en = t.lookup(Object.class); + LinkedHashSet> arr = new LinkedHashSet>(); while (en.hasMoreElements()) { - Pair item = (Pair) en.nextElement(); - arr.add(item); + Pair item = en.nextElement(); + arr.add(item); } - return arr; + return arr; } finally { exitStorage(); } @@ -246,15 +249,15 @@ /** Collects listeners without notification. Needed in MetaInfServicesLookup * right now, but maybe will become an API later. */ - final HashSet setPairsAndCollectListeners(Collection collection) { - HashSet toNotify = new HashSet(27); + final HashSet setPairsAndCollectListeners(Collection collection) { + HashSet toNotify = new HashSet(27); - Object transaction = null; - AbstractLookup.Storage t = enterStorage(); + AbstractLookup.Storage t = enterStorage(); + Transaction transaction = null; try { // map between the Items and their indexes (Integer) - HashMap shouldBeThere = new HashMap(collection.size() * 2); + HashMap,Info> shouldBeThere = new HashMap,Info>(collection.size() * 2); count = 0; @@ -311,8 +314,8 @@ /** Notifies all collected listeners. Needed by MetaInfServicesLookup, * maybe it will be an API later. */ - final void notifyCollectedListeners(Object listeners) { - notifyListeners((HashSet) listeners); + final void notifyCollectedListeners(Set listeners) { + notifyListeners(listeners); } private final void writeObject(ObjectOutputStream oos) @@ -330,20 +333,19 @@ } } - public final Object lookup(Class clazz) { - Lookup.Item item = lookupItem(new Lookup.Template(clazz)); - + public final T lookup(Class clazz) { + Lookup.Item item = lookupItem(new Lookup.Template(clazz)); return (item == null) ? null : item.getInstance(); } - public final Lookup.Item lookupItem(Lookup.Template template) { + public final Lookup.Item lookupItem(Lookup.Template template) { AbstractLookup.this.beforeLookup(template); - ArrayList list = null; - AbstractLookup.Storage t = enterStorage(); + ArrayList> list = null; + AbstractLookup.Storage t = enterStorage(); try { - Enumeration en; + Enumeration> en; try { en = t.lookup(template.getType()); @@ -352,7 +354,7 @@ } catch (AbstractLookup.ISE ex) { // not possible to enumerate the exception, ok, copy it // to create new - list = new ArrayList(); + list = new ArrayList>(); en = t.lookup(null); // this should get all the items without any checks // the checks will be done out side of the storage @@ -367,12 +369,12 @@ return findSmallest(Collections.enumeration(list), template, true); } - private static Pair findSmallest(Enumeration en, Lookup.Template template, boolean deepCheck) { + private static Pair findSmallest(Enumeration> en, Lookup.Template template, boolean deepCheck) { int smallest = InheritanceTree.unsorted(en) ? Integer.MAX_VALUE : Integer.MIN_VALUE; - Pair res = null; + Pair res = null; while (en.hasMoreElements()) { - Pair item = (Pair) en.nextElement(); + Pair item = en.nextElement(); if (matches(template, item, deepCheck)) { if (smallest == Integer.MIN_VALUE) { @@ -391,15 +393,15 @@ return res; } - public final Lookup.Result lookup(Lookup.Template template) { + public final Lookup.Result lookup(Lookup.Template template) { for (;;) { AbstractLookup.ISE toRun = null; - AbstractLookup.Storage t = enterStorage(); + AbstractLookup.Storage t = enterStorage(); try { - R r = new R(); - ReferenceToResult newRef = new ReferenceToResult(r, this, template); + R r = new R(); + ReferenceToResult newRef = new ReferenceToResult(r, this, template); newRef.next = t.registerReferenceToResult(newRef); return r; @@ -418,16 +420,14 @@ /** Notifies listeners. * @param allAffectedResults set of R */ - private static void notifyListeners(Set allAffectedResults) { + private static void notifyListeners(Set allAffectedResults) { if (allAffectedResults.isEmpty()) { return; } - ArrayList evAndListeners = new ArrayList(); + ArrayList evAndListeners = new ArrayList(); { - Iterator it = allAffectedResults.iterator(); - while(it.hasNext()) { - AbstractLookup.R result = (AbstractLookup.R) it.next(); + for (R result : allAffectedResults) { result.collectFires(evAndListeners); } } @@ -449,14 +449,14 @@ * objects on even positions and the listeners on odd positions * @param ev the event to fire */ - static void notifyListeners(Object[] listeners, LookupEvent ev, Collection evAndListeners) { + static void notifyListeners(Object[] listeners, LookupEvent ev, Collection evAndListeners) { for (int i = listeners.length - 1; i >= 0; i -= 2) { LookupListener ll = (LookupListener) listeners[i]; try { if (evAndListeners != null) { if (ll instanceof WaitableResult) { - WaitableResult wr = (WaitableResult)ll; + WaitableResult wr = (WaitableResult)ll; wr.collectFires(evAndListeners); } else { evAndListeners.add(ev); @@ -478,7 +478,7 @@ * @param deepCheck true if type of the pair should be tested, false if it is already has been tested * @return true if item matches the template requirements, false if not */ - static boolean matches(Template t, Pair item, boolean deepCheck) { + static boolean matches(Template t, Pair item, boolean deepCheck) { String id = t.getId(); if ((id != null) && !item.getId().equals(id)) { @@ -546,8 +546,8 @@ * @param template the template the result was for * @return true if the hash map with all items has been cleared */ - boolean cleanUpResult(Lookup.Template template) { - AbstractLookup.Storage t = enterStorage(); + boolean cleanUpResult(Lookup.Template template) { + AbstractLookup.Storage t = enterStorage(); try { return t.cleanUpResult(template) == null; @@ -563,6 +563,7 @@ * @param ref the value of the reference to listener or listener list * @return new value to the reference to listener or list */ + @SuppressWarnings("unchecked") static Object modifyListenerList(boolean add, LookupListener l, Object ref) { if (add) { if (ref == null) { @@ -599,25 +600,14 @@ } } - private static ReferenceQueue activeQueue() { - if (activeQueue == null) { - try { - Class c = Class.forName("org.openide.util.Utilities"); // NOI18N - Class[] noArgs = new Class[0]; - java.lang.reflect.Method m = c.getDeclaredMethod("activeReferenceQueue", noArgs); // NOI18N - activeQueue = m.invoke(null, noArgs); - } catch (Exception ex) { - activeQueue = ex; - } - } - - return (activeQueue instanceof ReferenceQueue) ? (ReferenceQueue) activeQueue : null; + private static ReferenceQueue activeQueue() { + return Utilities.activeReferenceQueue(); } /** Storage to keep the internal structure of Pairs and to answer * different queries. */ - interface Storage { + interface Storage { /** Initializes a modification operation by creating an object * that will be passsed to all add, remove, retainAll methods * and should collect enough information about the change to @@ -628,7 +618,7 @@ * the amount of objects at the end * @return a token to identify the transaction */ - public Object beginTransaction(int ensure); + public Transaction beginTransaction(int ensure); /** Collects all affected results R that were modified in the * given transaction. @@ -636,7 +626,7 @@ * @param modified place to add results R to * @param transaction the transaction indentification */ - public void endTransaction(Object transaction, Set modifiedResults); + public void endTransaction(Transaction transaction, Set modifiedResults); /** Adds an item into the storage. * @param item to add @@ -644,24 +634,24 @@ * @return true if the Item has been added for the first time or false if some other * item equal to this one already existed in the lookup */ - public boolean add(AbstractLookup.Pair item, Object transaction); + public boolean add(AbstractLookup.Pair item, Transaction transaction); /** Removes an item. */ - public void remove(AbstractLookup.Pair item, Object transaction); + public void remove(AbstractLookup.Pair item, Transaction transaction); /** Removes all items that are not present in the provided collection. * @param retain collection of Pairs to keep them in * @param transaction the transaction context */ - public void retainAll(Map retain, Object transaction); + public void retainAll(Map retain, Transaction transaction); /** Queries for instances of given class. * @param clazz the class to check * @return enumeration of Item * @see #unsorted */ - public Enumeration lookup(Class clazz); + public Enumeration> lookup(Class clazz); /** Registers another reference to a result with the storage. This method * has also a special meaning. @@ -671,19 +661,19 @@ * the applications is expected to link from newRef to this returned * value to form a linked list */ - public ReferenceToResult registerReferenceToResult(ReferenceToResult newRef); + public ReferenceToResult registerReferenceToResult(ReferenceToResult newRef); /** Given the provided template, Do cleanup the results. * @param templ template of a result(s) that should be checked * @return null if all references for this template were cleared or one of them */ - public ReferenceToResult cleanUpResult(Lookup.Template templ); + public ReferenceToResult cleanUpResult(Lookup.Template templ); } /** Extension to the default lookup item that offers additional information * for the data structures use in AbstractLookup */ - public static abstract class Pair extends Lookup.Item implements Serializable { + public static abstract class Pair extends Lookup.Item implements Serializable { private static final long serialVersionUID = 1L; /** possition of this item in the lookup, manipulated in addPair, removePair, setPairs methods */ @@ -697,7 +687,7 @@ return index; } - final void setIndex(AbstractLookup.Storage tree, int x) { + final void setIndex(AbstractLookup.Storage tree, int x) { if (tree == null) { this.index = x; @@ -714,7 +704,7 @@ /** Tests whether this item can produce object * of class c. */ - protected abstract boolean instanceOf(Class c); + protected abstract boolean instanceOf(Class c); /** Method that can test whether an instance of a class has been created * by this item. @@ -728,9 +718,9 @@ /** Result based on one instance returned. */ - static final class R extends WaitableResult { + static final class R extends WaitableResult { /** reference our result is attached to (do not modify) */ - public ReferenceToResult reference; + public ReferenceToResult reference; /** listeners on the results or pointer to one listener */ private Object listeners; @@ -766,8 +756,9 @@ return null; } - private Set getClassesCache() { - return (Set) getFromCache(0); + @SuppressWarnings("unchecked") + private Set> getClassesCache() { + return (Set>) getFromCache(0); } private void setClassesCache(Set s) { @@ -785,8 +776,9 @@ ((Object[]) reference.caches)[0] = s; } - private Collection getInstancesCache() { - return (Collection) getFromCache(1); + @SuppressWarnings("unchecked") + private Collection getInstancesCache() { + return (Collection) getFromCache(1); } private void setInstancesCache(Collection c) { @@ -804,11 +796,12 @@ ((Object[]) reference.caches)[1] = c; } - private Object[] getItemsCache() { - return (Object[]) getFromCache(2); + @SuppressWarnings("unchecked") + private Pair[] getItemsCache() { + return (Pair[]) getFromCache(2); } - private void setItemsCache(Collection c) { + private void setItemsCache(Collection c) { if (isSimple()) { // mark it as being used reference.caches = reference; @@ -820,7 +813,7 @@ reference.caches = new Object[3]; } - ((Object[]) reference.caches)[2] = c.toArray(); + ((Object[]) reference.caches)[2] = c.toArray(new Pair[0]); } private void clearCaches() { @@ -843,7 +836,7 @@ /** Delete all cached values, the template changed. */ - protected void collectFires(Collection evAndListeners) { + protected void collectFires(Collection evAndListeners) { Object[] previousItems = getItemsCache(); clearCaches(); @@ -866,8 +859,8 @@ if (listeners instanceof LookupListener) { arr = new LookupListener[] { (LookupListener) listeners }; } else { - ArrayList l = (ArrayList) listeners; - arr = (LookupListener[]) l.toArray(new LookupListener[l.size()]); + ArrayList l = (ArrayList) listeners; + arr = l.toArray(new LookupListener[l.size()]); } } @@ -876,30 +869,30 @@ notifyListeners(ll, ev, evAndListeners); } - public Collection allInstances() { + public Collection allInstances() { reference.lookup.beforeLookup(reference.template); - Collection s = getInstancesCache(); + Collection s = getInstancesCache(); if (s != null) { return s; } - Collection items = allItemsWithoutBeforeLookup(); - s = new ArrayList(items.size()); + Collection> items = allItemsWithoutBeforeLookup(); + ArrayList list = new ArrayList(items.size()); - Iterator it = items.iterator(); + Iterator> it = items.iterator(); while (it.hasNext()) { - Pair item = (Pair) it.next(); - Object obj = item.getInstance(); + Pair item = it.next(); + T obj = item.getInstance(); if (reference.template.getType().isInstance(obj)) { - s.add(obj); + list.add(obj); } } - s = Collections.unmodifiableList((ArrayList)s); + s = Collections.unmodifiableList(list); setInstancesCache(s); return s; @@ -908,22 +901,19 @@ /** Set of all classes. * */ - public Set allClasses() { + public Set> allClasses() { reference.lookup.beforeLookup(reference.template); - Set s = getClassesCache(); + Set> s = getClassesCache(); if (s != null) { return s; } - s = new HashSet(); + s = new HashSet>(); - Iterator it = allItemsWithoutBeforeLookup().iterator(); - - while (it.hasNext()) { - Item item = (Item) it.next(); - Class clazz = item.getType(); + for (Pair item : allItemsWithoutBeforeLookup()) { + Class clazz = item.getType(); if (clazz != null) { s.add(clazz); @@ -938,22 +928,22 @@ /** Items are stored directly in the allItems. */ - public Collection allItems() { + public Collection> allItems() { reference.lookup.beforeLookup(reference.template); return allItemsWithoutBeforeLookup(); } /** Implements the search for allItems, but without asking for before lookup */ - private Collection allItemsWithoutBeforeLookup() { - Object[] c = getItemsCache(); + private Collection> allItemsWithoutBeforeLookup() { + Pair[] c = getItemsCache(); if (c != null) { return Collections.unmodifiableList(Arrays.asList(c)); } - ArrayList saferCheck = null; - AbstractLookup.Storage t = reference.lookup.enterStorage(); + ArrayList> saferCheck = null; + AbstractLookup.Storage t = reference.lookup.enterStorage(); try { try { @@ -961,47 +951,43 @@ } catch (AbstractLookup.ISE ex) { // do less effective evaluation of items outside of the // locked storage - saferCheck = new ArrayList(); + saferCheck = new ArrayList>(); - Enumeration en = t.lookup(null); // get all Pairs + Enumeration> en = t.lookup(null); // get all Pairs while (en.hasMoreElements()) { - Pair i = (Pair) en.nextElement(); - ; + Pair i = en.nextElement(); saferCheck.add(i); } } } finally { reference.lookup.exitStorage(); } + return extractPairs(saferCheck); + } - Iterator it = saferCheck.iterator(); - - // InheritanceTree is comparator for AbstractLookup.Pairs - TreeSet items = new TreeSet(ALPairComparator.DEFAULT); - - while (it.hasNext()) { - Pair i = (Pair) it.next(); - + @SuppressWarnings("unchecked") + private Collection> extractPairs(final ArrayList> saferCheck) { + TreeSet> items = new TreeSet>(ALPairComparator.DEFAULT); + for (Pair i : saferCheck) { if (matches(reference.template, i, false)) { - items.add(i); + items.add((Pair)i); } } - return Collections.unmodifiableCollection(items); } /** Initializes items. */ - private Collection initItems(Storage t) { + private Collection> initItems(Storage t) { // manipulation with the tree must be synchronized - Enumeration en = t.lookup(reference.template.getType()); + Enumeration> en = t.lookup(reference.template.getType()); // InheritanceTree is comparator for AbstractLookup.Pairs - TreeSet items = new TreeSet(ALPairComparator.DEFAULT); + TreeSet> items = new TreeSet>(ALPairComparator.DEFAULT); while (en.hasMoreElements()) { - Pair i = (Pair) en.nextElement(); + Pair i = en.nextElement(); if (matches(reference.template, i, false)) { items.add(i); @@ -1046,7 +1032,7 @@ /** abstract lookup we are connected to */ private AbstractLookup al = null; - private transient ArrayList earlyPairs; + private transient ArrayList earlyPairs; /** A lookup attaches to this object. */ @@ -1056,10 +1042,8 @@ if (earlyPairs != null) { // we must just add no override! - Pair[] p = (Pair[]) earlyPairs.toArray(new Pair[earlyPairs.size()]); - - for (int i = 0; i < p.length; i++) { - addPair(p[i]); + for (Pair p : earlyPairs) { + addPair(p); } } @@ -1074,14 +1058,14 @@ /** The method to add instance to the lookup with. * @param pair class/instance pair */ - public final void addPair(Pair pair) { + public final void addPair(Pair pair) { AbstractLookup a = al; if (a != null) { a.addPair(pair); } else { if (earlyPairs == null) { - earlyPairs = new ArrayList(3); + earlyPairs = new ArrayList(3); } earlyPairs.add(pair); @@ -1091,14 +1075,14 @@ /** Remove instance. * @param pair class/instance pair */ - public final void removePair(Pair pair) { + public final void removePair(Pair pair) { AbstractLookup a = al; if (a != null) { a.removePair(pair); } else { if (earlyPairs == null) { - earlyPairs = new ArrayList(3); + earlyPairs = new ArrayList(3); } earlyPairs.remove(pair); @@ -1108,13 +1092,13 @@ /** Changes all pairs in the lookup to new values. * @param c the collection of (Pair) objects */ - public final void setPairs(Collection c) { + public final void setPairs(Collection c) { AbstractLookup a = al; if (a != null) { a.setPairs(c); } else { - earlyPairs = new ArrayList(c); + earlyPairs = new ArrayList(c); } } } @@ -1134,12 +1118,12 @@ /** Reference to a result R */ - static final class ReferenceToResult extends WeakReference implements Runnable { + static final class ReferenceToResult extends WeakReference> implements Runnable { /** next refernece in chain, modified only from AbstractLookup or this */ - private ReferenceToResult next; + private ReferenceToResult next; /** the template for the result */ - public final Template template; + public final Template template; /** the lookup we are attached to */ public final AbstractLookup lookup; @@ -1150,7 +1134,7 @@ /** Creates a weak refernece to a new result R in context of lookup * for given template */ - private ReferenceToResult(R result, AbstractLookup lookup, Template template) { + private ReferenceToResult(R result, AbstractLookup lookup, Template template) { super(result, activeQueue()); this.template = template; this.lookup = lookup; @@ -1159,8 +1143,8 @@ /** Returns the result or null */ - R getResult() { - return (R) get(); + R getResult() { + return get(); } /** Cleans the reference. Implements Runnable interface, do not call @@ -1173,12 +1157,12 @@ /** Clones the reference list to given Storage. * @param storage storage to clone to */ - public void cloneList(AbstractLookup.Storage storage) { + public void cloneList(AbstractLookup.Storage storage) { ReferenceIterator it = new ReferenceIterator(this); while (it.next()) { - ReferenceToResult current = it.current(); - ReferenceToResult newRef = new ReferenceToResult(current.getResult(), current.lookup, current.template); + ReferenceToResult current = it.current(); + ReferenceToResult newRef = current.cloneRef(); newRef.next = storage.registerReferenceToResult(newRef); newRef.caches = current.caches; @@ -1187,6 +1171,10 @@ } } } + + private ReferenceToResult cloneRef() { + return new ReferenceToResult(getResult(), lookup, template); + } } // end of ReferenceToResult @@ -1200,22 +1188,22 @@ * this.ref = it.first (); // remember the first one */ static final class ReferenceIterator extends Object { - private ReferenceToResult first; - private ReferenceToResult current; + private ReferenceToResult first; + private ReferenceToResult current; /** hard reference to current result, so it is not GCed meanwhile */ - private R currentResult; + private R currentResult; /** Initializes the iterator with first reference. */ - public ReferenceIterator(ReferenceToResult first) { + public ReferenceIterator(ReferenceToResult first) { this.first = first; } /** Moves the current to next possition */ public boolean next() { - ReferenceToResult prev; - ReferenceToResult ref; + ReferenceToResult prev; + ReferenceToResult ref; if (current == null) { ref = first; @@ -1226,7 +1214,7 @@ } while (ref != null) { - R result = (R) ref.get(); + R result = ref.get(); if (result == null) { if (prev == null) { @@ -1256,13 +1244,13 @@ /** Access to current reference. */ - public ReferenceToResult current() { + public ReferenceToResult current() { return current; } /** Access to reference that is supposed to be the first one. */ - public ReferenceToResult first() { + public ReferenceToResult first() { return first; } } @@ -1273,7 +1261,7 @@ */ static final class ISE extends IllegalStateException { /** list of jobs to execute. */ - private java.util.List jobs; + private java.util.List jobs; /** @param msg message */ @@ -1286,7 +1274,7 @@ */ public void registerJob(Job job) { if (jobs == null) { - jobs = new java.util.ArrayList(); + jobs = new java.util.ArrayList(); } jobs.add(job); @@ -1300,16 +1288,14 @@ throw this; } - for (java.util.Iterator it = jobs.iterator(); it.hasNext();) { - Job j = (Job) it.next(); + for (Job j : jobs) { j.before(); } AbstractLookup.Storage s = lookup.enterStorage(); try { - for (java.util.Iterator it = jobs.iterator(); it.hasNext();) { - Job j = (Job) it.next(); + for (Job j : jobs) { j.inside(); } } finally { Index: openide/util/src/org/openide/util/lookup/ArrayStorage.java =================================================================== RCS file: /cvs/openide/util/src/org/openide/util/lookup/ArrayStorage.java,v retrieving revision 1.2 retrieving revision 1.2.2.1 diff -u -r1.2 -r1.2.2.1 --- openide/util/src/org/openide/util/lookup/ArrayStorage.java 26 Dec 2005 16:32:04 -0000 1.2 +++ openide/util/src/org/openide/util/lookup/ArrayStorage.java 17 Mar 2006 19:51:08 -0000 1.2.2.1 @@ -19,12 +19,14 @@ import java.lang.ref.WeakReference; import java.util.*; +import org.openide.util.lookup.AbstractLookup.Pair; /** ArrayStorage of Pairs from AbstractLookup. * @author Jaroslav Tulach */ -final class ArrayStorage extends Object implements AbstractLookup.Storage { +final class ArrayStorage extends Object +implements AbstractLookup.Storage { /** default trashold */ static final Integer DEFAULT_TRASH = new Integer(11); @@ -32,7 +34,7 @@ private Object content; /** linked list of refernces to results */ - private transient AbstractLookup.ReferenceToResult results; + private transient AbstractLookup.ReferenceToResult results; /** Constructor */ @@ -50,8 +52,7 @@ * @return true if the Item has been added for the first time or false if some other * item equal to this one already existed in the lookup */ - public boolean add(AbstractLookup.Pair item, Object transaction) { - Transaction changed = (Transaction) transaction; + public boolean add(AbstractLookup.Pair item, Transaction changed) { Object[] arr = changed.current; if (changed.arr == null) { @@ -112,8 +113,7 @@ /** Removes an item. */ - public void remove(AbstractLookup.Pair item, Object transaction) { - Transaction changed = (Transaction) transaction; + public void remove(AbstractLookup.Pair item, Transaction changed) { Object[] arr = changed.current; int found = -1; @@ -126,8 +126,9 @@ if ((found == -1) && arr[i].equals(item)) { // already there - ((AbstractLookup.Pair) arr[i]).setIndex(null, -1); - changed.add(arr[i]); + Pair p = (Pair)arr[i]; + p.setIndex(null, -1); + changed.add(p); found = i; } @@ -148,8 +149,7 @@ * @param retain Pair -> AbstractLookup.Info map * @param notify set of Classes that has possibly changed */ - public void retainAll(Map retain, Object transaction) { - Transaction changed = (Transaction) transaction; + public void retainAll(Map retain, Transaction changed) { Object[] arr = changed.current; for (int from = 0; from < arr.length; from++) { @@ -188,9 +188,10 @@ * @return enumeration of Item * @see #unsorted */ - public Enumeration lookup(final Class clazz) { - class CheckEn implements org.openide.util.Enumerations.Processor { - public Object process(Object o, Collection ignore) { + public Enumeration> lookup(final Class clazz) { + class CheckEn implements org.openide.util.Enumerations.Processor> { + @SuppressWarnings("unchecked") + public Pair process(Object o, Collection ignore) { boolean ok; if (o instanceof AbstractLookup.Pair) { @@ -199,13 +200,12 @@ ok = false; } - return ok ? o : null; + return ok ? (Pair)o : null; } } if (content instanceof Object[]) { - Enumeration all = org.openide.util.Enumerations.array((Object[]) content); - + Enumeration all = org.openide.util.Enumerations.array((Object[]) content); return org.openide.util.Enumerations.filter(all, new CheckEn()); } else { return org.openide.util.Enumerations.empty(); @@ -214,7 +214,7 @@ /** Associates another result with this storage. */ - public AbstractLookup.ReferenceToResult registerReferenceToResult(AbstractLookup.ReferenceToResult newRef) { + public AbstractLookup.ReferenceToResult registerReferenceToResult(AbstractLookup.ReferenceToResult newRef) { AbstractLookup.ReferenceToResult prev = this.results; this.results = newRef; @@ -223,7 +223,7 @@ /** Cleanup the references */ - public AbstractLookup.ReferenceToResult cleanUpResult(Lookup.Template templ) { + public AbstractLookup.ReferenceToResult cleanUpResult(Lookup.Template templ) { AbstractLookup.ReferenceIterator it = new AbstractLookup.ReferenceIterator(this.results); while (it.next()) @@ -233,22 +233,20 @@ } /** We use a hash set of all modified Pair to handle the transaction */ - public Object beginTransaction(int ensure) { + public Transaction beginTransaction(int ensure) { return new Transaction(ensure, content); } /** Extract all results. */ - public void endTransaction(Object transaction, Set modified) { - Transaction changed = (Transaction) transaction; - + public void endTransaction(Transaction changed, Set modified) { AbstractLookup.ReferenceIterator it = new AbstractLookup.ReferenceIterator(this.results); if (changed.arr == null) { // either add or remove, only check the content of check HashSet while (it.next()) { AbstractLookup.ReferenceToResult ref = it.current(); - Iterator pairs = changed.iterator(); + Iterator> pairs = changed.iterator(); while (pairs.hasNext()) { AbstractLookup.Pair p = (AbstractLookup.Pair) pairs.next(); @@ -305,7 +303,7 @@ /** HashSet with additional field for new array which is callocated * in case we are doing replace to hold all new items. */ - private static final class Transaction extends HashSet { + static final class Transaction extends HashSet> { /** array with current objects */ public final Object[] current; @@ -404,7 +402,7 @@ } } - public int addPair(AbstractLookup.Pair p) { + public int addPair(AbstractLookup.Pair p) { p.setIndex(null, cnt); arr[cnt++] = p; Index: openide/util/src/org/openide/util/lookup/DelegatingStorage.java =================================================================== RCS file: /cvs/openide/util/src/org/openide/util/lookup/DelegatingStorage.java,v retrieving revision 1.1 retrieving revision 1.1.48.1 diff -u -r1.1 -r1.1.48.1 --- openide/util/src/org/openide/util/lookup/DelegatingStorage.java 21 Apr 2005 20:16:20 -0000 1.1 +++ openide/util/src/org/openide/util/lookup/DelegatingStorage.java 17 Mar 2006 19:51:07 -0000 1.1.48.1 @@ -19,19 +19,21 @@ import java.lang.ref.WeakReference; import java.util.*; +import org.openide.util.lookup.AbstractLookup.Pair; /** Storages that can switch between another storages. * @author Jaroslav Tulach */ -final class DelegatingStorage extends Object implements Serializable, AbstractLookup.Storage { +final class DelegatingStorage extends Object +implements Serializable, AbstractLookup.Storage { /** object to delegate to */ - private AbstractLookup.Storage delegate; + private AbstractLookup.Storage delegate; /** thread just accessing the storage */ private Thread owner; - public DelegatingStorage(AbstractLookup.Storage d) { + public DelegatingStorage(AbstractLookup.Storage d) { this.delegate = d; this.owner = Thread.currentThread(); } @@ -61,44 +63,55 @@ /** Exits from the owners ship of the storage. */ - public AbstractLookup.Storage exitDelegate() { + public AbstractLookup.Storage exitDelegate() { if (Thread.currentThread() != owner) { throw new IllegalStateException("Onwer: " + owner + " caller: " + Thread.currentThread()); // NOI18N } - AbstractLookup.Storage d = delegate; + AbstractLookup.Storage d = delegate; delegate = null; return d; } - public boolean add(org.openide.util.lookup.AbstractLookup.Pair item, Object transaction) { + public boolean add(AbstractLookup.Pair item, Transaction transaction) { return delegate.add(item, transaction); } - public void remove(org.openide.util.lookup.AbstractLookup.Pair item, Object transaction) { + public void remove(org.openide.util.lookup.AbstractLookup.Pair item, Transaction transaction) { delegate.remove(item, transaction); } - public void retainAll(Map retain, Object transaction) { + public void retainAll(Map retain, Transaction transaction) { delegate.retainAll(retain, transaction); } - public Object beginTransaction(int ensure) { + /** A special method to change the backing storage. + * In fact it is not much typesafe as it changes the + * type of Transaction but we know that nobody is currently + * holding a transaction object, so there cannot be inconsitencies. + */ + @SuppressWarnings("unchecked") + private void changeDelegate(InheritanceTree st) { + delegate = (AbstractLookup.Storage)st; + } + + public Transaction beginTransaction(int ensure) { try { return delegate.beginTransaction(ensure); } catch (UnsupportedOperationException ex) { // let's convert to InheritanceTree ArrayStorage arr = (ArrayStorage) delegate; - delegate = new InheritanceTree(); + InheritanceTree inh = new InheritanceTree(); + changeDelegate(inh); // // Copy content // - Enumeration en = arr.lookup(Object.class); + Enumeration> en = arr.lookup(Object.class); while (en.hasMoreElements()) { - if (!delegate.add((AbstractLookup.Pair) en.nextElement(), new ArrayList())) { + if (!inh.add(en.nextElement(), new ArrayList())) { throw new IllegalStateException("All objects have to be accepted"); // NOI18N } } @@ -106,10 +119,10 @@ // // Copy listeners // - AbstractLookup.ReferenceToResult ref = arr.cleanUpResult(null); + AbstractLookup.ReferenceToResult ref = arr.cleanUpResult(null); if (ref != null) { - ref.cloneList(delegate); + ref.cloneList(inh); } // we have added the current content and now we can start transaction @@ -123,11 +136,11 @@ return delegate.cleanUpResult(templ); } - public void endTransaction(Object transaction, Set modified) { + public void endTransaction(Transaction transaction, Set modified) { delegate.endTransaction(transaction, modified); } - public Enumeration lookup(Class clazz) { + public Enumeration> lookup(Class clazz) { return delegate.lookup(clazz); } Index: openide/util/src/org/openide/util/lookup/ExcludingLookup.java =================================================================== RCS file: /cvs/openide/util/src/org/openide/util/lookup/ExcludingLookup.java,v retrieving revision 1.2 retrieving revision 1.2.14.1 diff -u -r1.2 -r1.2.14.1 --- openide/util/src/org/openide/util/lookup/ExcludingLookup.java 2 Dec 2005 10:45:41 -0000 1.2 +++ openide/util/src/org/openide/util/lookup/ExcludingLookup.java 17 Mar 2006 19:51:07 -0000 1.2.14.1 @@ -47,7 +47,7 @@ return "ExcludingLookup: " + delegate + " excludes: " + Arrays.asList(classes()); // NOI18N } - public Result lookup(Template template) { + public Result lookup(Template template) { if (template == null) { throw new NullPointerException(); } @@ -57,15 +57,15 @@ return Lookup.EMPTY.lookup(template); } - return new R(template.getType(), delegate.lookup(template)); + return new R(template.getType(), delegate.lookup(template)); } - public Object lookup(Class clazz) { + public T lookup(Class clazz) { if (areSubclassesOfThisClassAlwaysExcluded(clazz)) { return null; } - Object res = delegate.lookup(clazz); + T res = delegate.lookup(clazz); if (isObjectAccessible(clazz, res, 0)) { return res; @@ -74,12 +74,12 @@ } } - public org.openide.util.Lookup.Item lookupItem(org.openide.util.Lookup.Template template) { + public Lookup.Item lookupItem(Lookup.Template template) { if (areSubclassesOfThisClassAlwaysExcluded(template.getType())) { return null; } - org.openide.util.Lookup.Item retValue = delegate.lookupItem(template); + Lookup.Item retValue = delegate.lookupItem(template); if (isObjectAccessible(template.getType(), retValue, 2)) { return retValue; @@ -90,8 +90,8 @@ /** @return true if the instance of class c shall never be returned from this lookup */ - private boolean areSubclassesOfThisClassAlwaysExcluded(Class c) { - Class[] arr = classes(); + private boolean areSubclassesOfThisClassAlwaysExcluded(Class c) { + Class[] arr = classes(); for (int i = 0; i < arr.length; i++) { if (arr[i].isAssignableFrom(c)) { @@ -104,7 +104,7 @@ /** Returns the array of classes this lookup filters. */ - final Class[] classes() { + final Class[] classes() { if (classes instanceof Class[]) { return (Class[]) classes; } else { @@ -116,7 +116,7 @@ * releation ship without walking thru any of the classes mentioned in the * barrier. */ - private static boolean isAccessible(Class[] barriers, Class from, Class to) { + private static boolean isAccessible(Class[] barriers, Class from, Class to) { if ((to == null) || !from.isAssignableFrom(to)) { // no way to reach each other by walking up return false; @@ -196,28 +196,25 @@ /** Filters collection accroding to set of given filters. */ - final java.util.Collection filter(Class[] arr, Class from, java.util.Collection c, int type) { - java.util.Collection ret = null; + final > T filter( + Class[] arr, Class from, T c, int type, T prototype + ) { + T ret = null; // optimistic strategy expecting we will not need to filter TWICE: for (;;) { - Iterator it = c.iterator(); + Iterator it = c.iterator(); BIG: while (it.hasNext()) { - Object res = it.next(); + E res = it.next(); if (!isObjectAccessible(arr, from, res, type)) { if (ret == null) { // we need to restart the scanning again // as there is an active filter - if (type == 1) { - ret = new java.util.HashSet(); - } else { - ret = new ArrayList(c.size()); - } - + ret = prototype; continue TWICE; } @@ -239,12 +236,12 @@ /** Delegating result that filters unwanted items and instances. */ - private final class R extends WaitableResult implements LookupListener { - private Result result; + private final class R extends WaitableResult implements LookupListener { + private Result result; private Object listeners; - private Class from; + private Class from; - R(Class from, Result delegate) { + R(Class from, Result delegate) { this.from = from; this.result = delegate; } @@ -281,16 +278,20 @@ } } - public java.util.Collection allInstances() { - return filter(classes(), from, result.allInstances(), 0); + public Collection allInstances() { + return openCol(result.allInstances(), 0); + } + + private Collection openCol(Collection c, int type) { + return filter(classes(), from, c, type, new ArrayList(c.size())); } - public Set allClasses() { - return (Set) filter(classes(), from, result.allClasses(), 1); + public Set> allClasses() { + return filter(classes(), from, result.allClasses(), 1, new HashSet>()); } - public Collection allItems() { - return filter(classes(), from, result.allItems(), 2); + public Collection> allItems() { + return openCol(result.allItems(), 2); } public void resultChanged(org.openide.util.LookupEvent ev) { @@ -299,7 +300,7 @@ } } - protected void collectFires(Collection evAndListeners) { + protected void collectFires(Collection evAndListeners) { LookupListener[] arr; synchronized (this) { @@ -310,8 +311,8 @@ if (listeners instanceof LookupListener) { arr = new LookupListener[] { (LookupListener) listeners }; } else { - ArrayList l = (ArrayList) listeners; - arr = (LookupListener[]) l.toArray(new LookupListener[l.size()]); + ArrayList l = (ArrayList) listeners; + arr = l.toArray(new LookupListener[l.size()]); } } Index: openide/util/src/org/openide/util/lookup/InheritanceTree.java =================================================================== RCS file: /cvs/openide/util/src/org/openide/util/lookup/InheritanceTree.java,v retrieving revision 1.2 retrieving revision 1.2.2.1 diff -u -r1.2 -r1.2.2.1 --- openide/util/src/org/openide/util/lookup/InheritanceTree.java 9 Mar 2006 07:20:47 -0000 1.2 +++ openide/util/src/org/openide/util/lookup/InheritanceTree.java 17 Mar 2006 19:51:07 -0000 1.2.2.1 @@ -12,7 +12,9 @@ */ package org.openide.util.lookup; +import org.openide.util.Enumerations; import org.openide.util.Lookup; +import org.openide.util.lookup.AbstractLookup.Pair; import org.openide.util.lookup.AbstractLookup.ReferenceIterator; import org.openide.util.lookup.AbstractLookup.ReferenceToResult; @@ -87,7 +89,8 @@ * * @author Jaroslav Tulach */ -final class InheritanceTree extends Object implements Serializable, AbstractLookup.Storage { +final class InheritanceTree extends Object +implements Serializable, AbstractLookup.Storage> { private static final long serialVersionUID = 1L; /** the root item (represents Object) */ @@ -96,12 +99,12 @@ /** Map of queried interfaces. *

Type: Map<Class, (Collection<AbstractLookup.Pair> | AbstractLookup.Pair)> */ - private transient Map interfaces; + private transient Map interfaces; /** Map (Class, ReferenceToResult) of all listeners that are waiting in * changes in class Class */ - private transient Map reg; + private transient Map reg; /** Constructor */ @@ -135,7 +138,7 @@ private void readObject(ObjectInputStream ois) throws IOException, ClassNotFoundException { object = (Node) ois.readObject(); - interfaces = new WeakHashMap(); + interfaces = new WeakHashMap(); String clazz; ClassLoader l = (ClassLoader) Lookup.getDefault().lookup(ClassLoader.class); @@ -157,9 +160,7 @@ * @return true if the Item has been added for the first time or false if some other * item equal to this one already existed in the lookup */ - public boolean add(AbstractLookup.Pair item, Object transaction) { - ArrayList affected = (ArrayList) transaction; - + public boolean add(AbstractLookup.Pair item, ArrayList affected) { Node node = registerClass(object, item); affected.add(node.getType()); @@ -179,9 +180,7 @@ /** Removes an item. */ - public void remove(AbstractLookup.Pair item, Object transaction) { - ArrayList affected = (ArrayList) transaction; - + public void remove(AbstractLookup.Pair item, ArrayList affected) { Node n = removeClass(object, item); if (n != null) { @@ -195,9 +194,7 @@ * @param retain collection of Pairs to keep them in * @param notify set of Classes that has possibly changed */ - public void retainAll(Map retain, Object transaction) { - ArrayList notify = (ArrayList) transaction; - + public void retainAll(Map retain, ArrayList notify) { retainAllInterface(retain, notify); retainAllClasses(object, retain, notify); } @@ -207,11 +204,12 @@ * @return enumeration of Item * @see #unsorted */ - public Enumeration lookup(Class clazz) { + @SuppressWarnings("unchecked") + public Enumeration> lookup(Class clazz) { if ((clazz != null) && clazz.isInterface()) { - return searchInterface(clazz); + return (Enumeration)searchInterface(clazz); } else { - return searchClass(object, clazz); + return (Enumeration)searchClass(object, clazz); } } @@ -317,7 +315,7 @@ * @return node that represents clazz in the tree or null if the clazz is not * represented under the node n */ - private Node classToNode(final Node n, final Class clazz) { + private Node classToNode(final Node n, final Class clazz) { if (!n.accepts(clazz)) { // nothing from us return null; @@ -343,12 +341,12 @@ if ((found != null) && ch.deserialized()) { class VerifyJob implements AbstractLookup.ISE.Job { - private AbstractLookup.Pair[] pairs; + private AbstractLookup.Pair[] pairs; private boolean[] answers; - public VerifyJob(Collection items) { + public VerifyJob(Collection items) { if (items != null) { - pairs = (AbstractLookup.Pair[]) items.toArray(new AbstractLookup.Pair[0]); + pairs = items.toArray(new AbstractLookup.Pair[0]); } } @@ -377,13 +375,13 @@ if (n.children != null) { // consolidate all nodes that represent the same class - HashMap nodes = new HashMap(n.children.size() * 3); + HashMap nodes = new HashMap(n.children.size() * 3); Iterator child = n.children.iterator(); while (child.hasNext()) { Node node = extractNode(child); - Node prev = (Node) nodes.put(node.getType(), node); + Node prev = nodes.put(node.getType(), node); if (prev != null) { child.remove(); @@ -455,10 +453,10 @@ boolArr = new boolean[n.items.size()]; int i = 0; - Iterator it = n.items.iterator(); + Iterator it = n.items.iterator(); while (it.hasNext()) { - AbstractLookup.Pair item = (AbstractLookup.Pair) it.next(); + AbstractLookup.Pair item = it.next(); arr[i] = item; boolArr[i] = item.instanceOf(clazz); i++; @@ -482,10 +480,10 @@ } public void internal() { - ArrayList reparent = null; + ArrayList reparent = null; if (n.children == null) { - n.children = new ArrayList(); + n.children = new ArrayList(); } else { // scan thru all my nodes if some of them are not a subclass // of clazz => then they would need to become child of newNode @@ -500,7 +498,7 @@ if (clazz.isAssignableFrom(r.getType())) { if (reparent == null) { - reparent = new ArrayList(); + reparent = new ArrayList(); } reparent.add(r); @@ -558,7 +556,7 @@ /** Search for a requested class. * @return enumeration of Pair */ - private Enumeration searchClass(Node n, Class clazz) { + private Enumeration searchClass(Node n, Class clazz) { if (clazz != null) { n = classToNode(n, clazz); } @@ -579,14 +577,14 @@ * @param notify collection of classes will be changed * @return true if some items were changed and node items and children are emptied, * those nodes, excluding root, will be removed from tree */ - private boolean retainAllClasses(Node node, Map retain, Collection notify) { + private boolean retainAllClasses(Node node, Map retain, Collection notify) { boolean retained = false; if ((node.items != null) && (retain != null)) { - Iterator it = node.items.iterator(); + Iterator it = node.items.iterator(); while (it.hasNext()) { - AbstractLookup.Pair item = (AbstractLookup.Pair) it.next(); + AbstractLookup.Pair item = it.next(); AbstractLookup.Info n = (AbstractLookup.Info) retain.remove(item); if (n == null) { @@ -634,38 +632,41 @@ * @param n node to create enumeration for * @return enumeration of Pairs */ - private static Enumeration nodeToEnum(Node n) { + private static Enumeration nodeToEnum(Node n) { if (n.children == null) { // create a simple enumeration because we do not have children - return (n.items == null) ? org.openide.util.Enumerations.empty() : Collections.enumeration(n.items); + Enumeration e; + if (n.items == null) { + e = Enumerations.empty(); + } else { + e = Collections.enumeration(n.items); + } + return e; } // we have found what we need // now we have to just build the enumeration - class DeepAndItems implements org.openide.util.Enumerations.Processor { - public Object process(Object obj, Collection toAdd) { - Node n2 = (Node) obj; - + class DeepAndItems implements Enumerations.Processor> { + public Enumeration process(Node n2, Collection toAdd) { if (n2.children != null) { toAdd.addAll(n2.children); } if ((n2.items == null) || n2.items.isEmpty()) { - return org.openide.util.Enumerations.empty(); + return Enumerations.empty(); } else { return Collections.enumeration(n2.items); } } } - Enumeration en = org.openide.util.Enumerations.queue( - + Enumeration> en = Enumerations.queue( // initial node is our current one - org.openide.util.Enumerations.singleton(n), new DeepAndItems() - ); - + Enumerations.singleton(n), new DeepAndItems() + ); + Enumeration all = Enumerations.concat(en); // create enumeration of Items - return new NeedsSortEnum(org.openide.util.Enumerations.concat(en)); + return new NeedsSortEnum(all); } // @@ -677,22 +678,23 @@ * @param affected list of classes that were affected * @return false if similar item has already been registered */ - private boolean registerInterface(AbstractLookup.Pair item, Collection affected) { + @SuppressWarnings("unchecked") + private boolean registerInterface(AbstractLookup.Pair item, Collection affected) { if (interfaces == null) { return true; } - Iterator it = interfaces.entrySet().iterator(); + Iterator> it = interfaces.entrySet().iterator(); while (it.hasNext()) { - Map.Entry entry = (Map.Entry) it.next(); - Class iface = (Class) entry.getKey(); + Map.Entry entry = it.next(); + Class iface = entry.getKey(); if (item.instanceOf(iface)) { Object value = entry.getValue(); if (value instanceof Collection) { - Collection set = (Collection) value; + Collection set = (Collection) value; if (!set.add(item)) { // item is already there, probably (if everything is correct) is registered in @@ -707,7 +709,7 @@ } // otherwise replace the single item with ArrayList - ArrayList ll = new ArrayList(3); + ArrayList ll = new ArrayList(3); ll.add(value); ll.add(item); entry.setValue(ll); @@ -724,6 +726,7 @@ * @param item item to register * @param affected list of classes that were affected */ + @SuppressWarnings("unchecked") private void removeInterface(AbstractLookup.Pair item, Collection affected) { if (interfaces == null) { return; @@ -764,6 +767,7 @@ * (AbstractLookup.Pair -> AbstractLookup.Info) * @param affected list of classes that were affected */ + @SuppressWarnings("unchecked") private void retainAllInterface(Map retainItems, Collection affected) { if (interfaces == null) { return; @@ -775,7 +779,7 @@ Map.Entry entry = (Map.Entry) it.next(); Object value = entry.getValue(); - HashMap retain = new HashMap(retainItems); + HashMap retain = new HashMap(retainItems); Iterator elems; boolean multi = value instanceof Collection; @@ -843,7 +847,8 @@ * @param clazz class to search for * @return enumeration of Items */ - private Enumeration searchInterface(final Class clazz) { + @SuppressWarnings("unchecked") + private Enumeration searchInterface(final Class clazz) { if (interfaces == null) { // first call for interface, only initialize interfaces = new WeakHashMap(); @@ -895,7 +900,7 @@ return Collections.enumeration((Collection) obj); } else { // single item mode - return org.openide.util.Enumerations.singleton(obj); + return org.openide.util.Enumerations.singleton((Pair)obj); } } } @@ -933,7 +938,7 @@ if (n.items != null) { i = 0; - it = new ArrayList(n.items).iterator(); + it = new ArrayList(n.items).iterator(); while (it.hasNext()) { AbstractLookup.Pair p = (AbstractLookup.Pair) it.next(); @@ -963,12 +968,12 @@ } } - public ReferenceToResult registerReferenceToResult(ReferenceToResult newRef) { + public ReferenceToResult registerReferenceToResult(ReferenceToResult newRef) { if (reg == null) { - reg = new HashMap(); + reg = new HashMap(); } - Class clazz = newRef.template.getType(); + Class clazz = newRef.template.getType(); // initialize the data structures if not yet lookup(clazz); @@ -983,13 +988,11 @@ return (reg == null) ? null : (ReferenceToResult) reg.get(templ.getType()); } - public Object beginTransaction(int ensure) { - return new ArrayList(); + public ArrayList beginTransaction(int ensure) { + return new ArrayList(); } - public void endTransaction(Object transaction, Set allAffectedResults) { - ArrayList list = (ArrayList) transaction; - + public void endTransaction(ArrayList list, Set allAffectedResults) { if (list.size() == 1) { // probably the most common case collectListeners(allAffectedResults, (Class) list.get(0)); @@ -1007,7 +1010,7 @@ * @param allAffectedResults adds Results into this set * @param c the class that has changed */ - private void collectListeners(Set allAffectedResults, Class c) { + private void collectListeners(Set allAffectedResults, Class c) { if (reg == null) { return; } @@ -1017,7 +1020,7 @@ ReferenceIterator it = new ReferenceIterator(first); while (it.next()) { - Object result = it.current().getResult(); + AbstractLookup.R result = it.current().getResult(); if (allAffectedResults != null) { // add result @@ -1046,14 +1049,14 @@ /** Node in the tree. */ - static final class Node extends WeakReference implements Serializable { + static final class Node extends WeakReference implements Serializable { static final long serialVersionUID = 3L; /** children nodes */ - public ArrayList children; // List + public ArrayList children; /** list of items assigned to this node (suspect to be subclasses) */ - public List items; // List + public List items; /** Constructor. */ @@ -1072,7 +1075,7 @@ if (items.isEmpty()) { items = null; } else { - items = new ArrayList(items); + items = new ArrayList(items); } return true; @@ -1082,7 +1085,7 @@ */ public void markDeserialized() { if (items == null || items == Collections.EMPTY_LIST) { - items = Collections.EMPTY_LIST; + items = Collections.emptyList(); } else { items = Collections.synchronizedList(items); } @@ -1090,8 +1093,8 @@ /** Getter for the type associated with this node. */ - public Class getType() { - Class c = (Class) get(); + public Class getType() { + Class c = get(); // if garbage collected, then return a garbage return (c == null) ? Void.TYPE : c; @@ -1099,7 +1102,7 @@ /** Checks whether a node can represent an class. */ - public boolean accepts(Class clazz) { + public boolean accepts(Class clazz) { if (getType() == Object.class) { return true; } @@ -1109,7 +1112,7 @@ /** Checks whether item is instance of this node. */ - public boolean accepts(AbstractLookup.Pair item) { + public boolean accepts(AbstractLookup.Pair item) { if (getType() == Object.class) { // Object.class return true; @@ -1122,9 +1125,9 @@ * @param item the item * @return true if item has been added as new */ - public boolean assignItem(InheritanceTree tree, AbstractLookup.Pair item) { + public boolean assignItem(InheritanceTree tree, AbstractLookup.Pair item) { if ((items == null) || (items == Collections.EMPTY_LIST)) { - items = new ArrayList(); + items = new ArrayList(); items.add(item); return true; @@ -1164,18 +1167,18 @@ static final long serialVersionUID = 1L; private static ClassLoader l; private String clazzName; - private transient Class clazz; - private ArrayList children; - private ArrayList items; + private transient Class clazz; + private ArrayList children; + private ArrayList items; public R(Node n) { this.clazzName = n.getType().getName(); this.children = n.children; if (n.items instanceof ArrayList || (n.items == null)) { - this.items = (ArrayList) n.items; + this.items = (ArrayList) n.items; } else { - this.items = new ArrayList(n.items); + this.items = new ArrayList(n.items); } } @@ -1204,10 +1207,10 @@ /** Just a marker class to be able to do instanceof and find out * that this enumeration is not sorted */ - private static final class NeedsSortEnum implements Enumeration { - private Enumeration en; + private static final class NeedsSortEnum implements Enumeration { + private Enumeration en; - public NeedsSortEnum(Enumeration en) { + public NeedsSortEnum(Enumeration en) { this.en = en; } @@ -1215,7 +1218,7 @@ return en.hasMoreElements(); } - public Object nextElement() { + public T nextElement() { return en.nextElement(); } } Index: openide/util/src/org/openide/util/lookup/InstanceContent.java =================================================================== RCS file: /cvs/openide/util/src/org/openide/util/lookup/InstanceContent.java,v retrieving revision 1.1 retrieving revision 1.1.48.1 diff -u -r1.1 -r1.1.48.1 --- openide/util/src/org/openide/util/lookup/InstanceContent.java 21 Apr 2005 20:16:20 -0000 1.1 +++ openide/util/src/org/openide/util/lookup/InstanceContent.java 17 Mar 2006 19:51:07 -0000 1.1.48.1 @@ -47,7 +47,7 @@ * @param inst instance */ public final void add(Object inst) { - addPair(new SimpleItem(inst)); + addPair(new SimpleItem(inst)); } /** The method to add instance to the lookup with. @@ -55,15 +55,15 @@ * @param conv convertor which postponing an instantiation, * if conv==null then the instance is registered directly. */ - public final void add(Object inst, Convertor conv) { - addPair(new ConvertingItem(inst, conv)); + public final void add(T inst, Convertor conv) { + addPair(new ConvertingItem(inst, conv)); } /** Remove instance. * @param inst instance */ public final void remove(Object inst) { - removePair(new SimpleItem(inst)); + removePair(new SimpleItem(inst)); } /** Remove instance added with a convertor. @@ -71,8 +71,8 @@ * @param conv convertor, if conv==null it is same like * remove(Object) */ - public final void remove(Object inst, Convertor conv) { - removePair(new ConvertingItem(inst, conv)); + public final void remove(T inst, Convertor conv) { + removePair(new ConvertingItem(inst, conv)); } /** Changes all pairs in the lookup to new values. Converts collection of @@ -80,17 +80,17 @@ * @param col the collection of (Item) objects * @param conv the convertor to use or null */ - public final void set(Collection col, Convertor conv) { - ArrayList l = new ArrayList(col.size()); - Iterator it = col.iterator(); + public final void set(Collection col, Convertor conv) { + ArrayList> l = new ArrayList>(col.size()); + Iterator it = col.iterator(); if (conv == null) { while (it.hasNext()) { - l.add(new SimpleItem(it.next())); + l.add(new SimpleItem(it.next())); } } else { while (it.hasNext()) { - l.add(new ConvertingItem(it.next(), conv)); + l.add(new ConvertingItem(it.next(), conv)); } } @@ -100,7 +100,7 @@ /** Convertor postpones an instantiation of an object. * @since 1.25 */ - public static interface Convertor { + public static interface Convertor { /** Convert obj to other object. There is no need to implement * cache mechanism. It is provided by InstanceLookup.Item.getInstance(). * Method should be called more than once because Lookup holds @@ -109,48 +109,47 @@ * @param obj the registered object * @return the object converted from this object */ - public Object convert(Object obj); + public R convert(T obj); /** Return type of converted object. * @param obj the registered object * @return the class that will be produced from this object (class or * superclass of convert (obj)) */ - public Class type(Object obj); + public Class type(T obj); /** Computes the ID of the resulted object. * @param obj the registered object * @return the ID for the object */ - public String id(Object obj); + public String id(T obj); /** The human presentable name for the object. * @param obj the registered object * @return the name representing the object for the user */ - public String displayName(Object obj); + public String displayName(T obj); } /** Instance of one item representing an object. */ - final static class SimpleItem extends Pair { - private Object obj; + final static class SimpleItem extends Pair { + private T obj; /** Create an item. * @obj object to register */ - public SimpleItem(Object obj) { + public SimpleItem(T obj) { if (obj == null) { throw new NullPointerException(); } - this.obj = obj; } /** Tests whether this item can produce object * of class c. */ - public boolean instanceOf(Class c) { + public boolean instanceOf(Class c) { return c.isInstance(obj); } @@ -159,7 +158,7 @@ * to converted object is saved. * @return the instance of the object. */ - public Object getInstance() { + public T getInstance() { return obj; } @@ -203,29 +202,30 @@ /** The class of this item. * @return the correct class */ - public Class getType() { - return obj.getClass(); + @SuppressWarnings("unchecked") + public Class getType() { + return (Class)obj.getClass(); } } // end of SimpleItem /** Instance of one item registered in the map. */ - final static class ConvertingItem extends Pair { + final static class ConvertingItem extends Pair { /** registered object */ - private Object obj; + private T obj; /** Reference to converted object. */ - private WeakReference ref; + private WeakReference ref; /** convertor to use */ - private Convertor conv; + private Convertor conv; /** Create an item. * @obj object to register * @conv a convertor, can be null. */ - public ConvertingItem(Object obj, Convertor conv) { + public ConvertingItem(T obj, Convertor conv) { this.obj = obj; this.conv = conv; } @@ -233,14 +233,14 @@ /** Tests whether this item can produce object * of class c. */ - public boolean instanceOf(Class c) { + public boolean instanceOf(Class c) { return c.isAssignableFrom(getType()); } /** Returns converted object or null if obj has not been converted yet * or reference was cleared by garbage collector. */ - private Object getConverted() { + private R getConverted() { if (ref == null) { return null; } @@ -253,12 +253,12 @@ * to converted object is saved. * @return the instance of the object. */ - public synchronized Object getInstance() { - Object converted = getConverted(); + public synchronized R getInstance() { + R converted = getConverted(); if (converted == null) { converted = conv.convert(obj); - ref = new WeakReference(converted); + ref = new WeakReference(converted); } return converted; @@ -308,18 +308,15 @@ /** The class of this item. * @return the correct class */ - public Class getType() { - if (conv == null) { - return obj.getClass(); - } - - Object converted = getConverted(); + @SuppressWarnings("unchecked") + public Class getType() { + R converted = getConverted(); if (converted == null) { return conv.type(obj); } - return converted.getClass(); + return (Class)converted.getClass(); } } // end of ConvertingItem Index: openide/util/src/org/openide/util/lookup/Lookups.java =================================================================== RCS file: /cvs/openide/util/src/org/openide/util/lookup/Lookups.java,v retrieving revision 1.2 retrieving revision 1.2.24.1 diff -u -r1.2 -r1.2.24.1 --- openide/util/src/org/openide/util/lookup/Lookups.java 29 Sep 2005 23:03:35 -0000 1.2 +++ openide/util/src/org/openide/util/lookup/Lookups.java 17 Mar 2006 19:51:07 -0000 1.2.24.1 @@ -83,7 +83,7 @@ * @since 2.21 * */ - public static Lookup fixed(Object[] keys, InstanceContent.Convertor convertor) { + public static Lookup fixed(T[] keys, InstanceContent.Convertor convertor) { if (keys == null) { throw new NullPointerException(); } Index: openide/util/src/org/openide/util/lookup/MetaInfServicesLookup.java =================================================================== RCS file: /cvs/openide/util/src/org/openide/util/lookup/MetaInfServicesLookup.java,v retrieving revision 1.3 retrieving revision 1.3.2.1 diff -u -r1.3 -r1.3.2.1 --- openide/util/src/org/openide/util/lookup/MetaInfServicesLookup.java 3 Mar 2006 23:44:58 -0000 1.3 +++ openide/util/src/org/openide/util/lookup/MetaInfServicesLookup.java 17 Mar 2006 19:51:08 -0000 1.3.2.1 @@ -21,7 +21,9 @@ import java.util.ArrayList; import java.util.Collection; import java.util.Enumeration; +import java.util.HashSet; import java.util.Iterator; +import java.util.LinkedHashSet; import java.util.List; import java.util.Map; import java.util.Set; @@ -46,7 +48,7 @@ final class MetaInfServicesLookup extends AbstractLookup { // Better not to use ErrorManager here - EM.gD will use this class, might cause cycles etc. private static final boolean DEBUG = Boolean.getBoolean("org.openide.util.lookup.MetaInfServicesLookup.DEBUG"); // NOI18N - private static final Map knownInstances = new WeakHashMap(); // Map + private static final Map knownInstances = new WeakHashMap(); /** A set of all requested classes. * Note that classes that we actually succeeded on can never be removed @@ -54,7 +56,7 @@ * However we also hold classes which are definitely not loadable by * our loader. */ - private final Set classes = new WeakSet(); // Set + private final Set classes = new WeakSet(); // Set /** class loader to use */ private final ClassLoader loader; @@ -85,12 +87,12 @@ protected final void beforeLookup(Lookup.Template t) { Class c = t.getType(); - Object listeners; + HashSet listeners; synchronized (this) { if (classes.add(c)) { // Added new class, search for it. - Collection arr = getPairsAsLHS(); + LinkedHashSet> arr = getPairsAsLHS(); search(c, arr); // listeners are notified under while holding lock on class c, @@ -110,7 +112,7 @@ * @param clazz class to find * @param result collection to add Pair to */ - private void search(Class clazz, Collection result) { + private void search(Class clazz, Collection> result) { if (DEBUG) { System.err.println("Searching for " + clazz.getName() + " in " + clazz.getClassLoader() + " from " + this); // NOI18N } @@ -132,8 +134,8 @@ // has the same entry in it (and they load to the same class). // Probably would not happen, assuming JARs only list classes // they own, but just in case... - List /**/ foundClasses = new ArrayList(); - Collection removeClasses = new ArrayList(); // Collection + List foundClasses = new ArrayList(); + Collection removeClasses = new ArrayList(); boolean foundOne = false; @@ -310,7 +312,7 @@ /** * Insert item to the list according to item.position value. */ - private void insertItem(Item item, List list) { + private void insertItem(Item item, List list) { // no position? -> add it to the end if (item.position == -1) { list.add(item); @@ -349,7 +351,7 @@ /** Pair that holds name of a class and maybe the instance. */ - private static final class P extends AbstractLookup.Pair { + private static final class P extends AbstractLookup.Pair { /** May be one of three things: * 1. The implementation class which was named in the services file. * 2. An instance of it. @@ -357,17 +359,17 @@ */ private Object object; - public P(Class clazz) { + public P(Class clazz) { this.object = clazz; } /** Finds the class. */ - private Class clazz() { + private Class clazz() { Object o = object; if (o instanceof Class) { - return (Class) o; + return (Class) o; } else if (o != null) { return o.getClass(); } else { @@ -388,11 +390,11 @@ return clazz().hashCode(); } - protected boolean instanceOf(Class c) { + protected boolean instanceOf(Class c) { return c.isAssignableFrom(clazz()); } - public Class getType() { + public Class getType() { return clazz(); } @@ -405,7 +407,7 @@ // 2 instances of the same class try { - Class c = ((Class) o); + Class c = ((Class) o); synchronized (knownInstances) { // guards only the static cache o = knownInstances.get(c); @@ -413,7 +415,7 @@ if (o == null) { if (SharedClassObject.class.isAssignableFrom(c)) { - o = SharedClassObject.findObject(c, true); + o = SharedClassObject.findObject(c.asSubclass(SharedClassObject.class), true); } else { o = c.newInstance(); } Index: openide/util/src/org/openide/util/lookup/ProxyLookup.java =================================================================== RCS file: /cvs/openide/util/src/org/openide/util/lookup/ProxyLookup.java,v retrieving revision 1.6 retrieving revision 1.6.2.2 diff -u -r1.6 -r1.6.2.2 --- openide/util/src/org/openide/util/lookup/ProxyLookup.java 7 Mar 2006 06:12:43 -0000 1.6 +++ openide/util/src/org/openide/util/lookup/ProxyLookup.java 17 Mar 2006 20:09:55 -0000 1.6.2.2 @@ -37,7 +37,7 @@ private Object lookups; /** map of templates to currently active results */ - private HashMap results; + private HashMap,Reference> results; /** Create a proxy to some other lookups. * @param lookups the initial delegates @@ -106,15 +106,15 @@ * @since 1.19 protected */ protected final void setLookups(Lookup[] lookups) { - Reference[] arr; - HashSet newL; - HashSet current; + Collection> arr; + HashSet newL; + HashSet current; Lookup[] old; synchronized (this) { old = getLookups(false); - current = new HashSet(Arrays.asList(old)); - newL = new HashSet(Arrays.asList(lookups)); + current = new HashSet(Arrays.asList(old)); + newL = new HashSet(Arrays.asList(lookups)); setLookupsNoFire(lookups); @@ -123,9 +123,9 @@ return; } - arr = (Reference[]) results.values().toArray(new Reference[0]); + arr = new ArrayList>(results.values()); - HashSet removed = new HashSet(current); + HashSet removed = new HashSet(current); removed.removeAll(newL); // current contains just those lookups that have disappeared newL.removeAll(current); // really new lookups @@ -134,9 +134,8 @@ return; } - for (int i = 0; i < arr.length; i++) { - R r = (R) arr[i].get(); - + for (Reference ref : arr) { + R r = ref.get(); if (r != null) { r.lookupChange(newL, removed, old, lookups); } @@ -144,10 +143,9 @@ } // this cannot be done from the synchronized block - ArrayList evAndListeners = new ArrayList(); - for (int i = 0; i < arr.length; i++) { - R r = (R) arr[i].get(); - + ArrayList evAndListeners = new ArrayList(); + for (Reference ref : arr) { + R r = ref.get(); if (r != null) { r.collectFires(evAndListeners); } @@ -171,16 +169,16 @@ * @param template the template of the query * @since 1.31 */ - protected void beforeLookup(Template template) { + protected void beforeLookup(Template template) { } - public final Object lookup(Class clazz) { - beforeLookup(new Template(clazz)); + public final T lookup(Class clazz) { + beforeLookup(new Template(clazz)); Lookup[] lookups = this.getLookups(false); for (int i = 0; i < lookups.length; i++) { - Object o = lookups[i].lookup(clazz); + T o = lookups[i].lookup(clazz); if (o != null) { return o; @@ -190,13 +188,13 @@ return null; } - public final Item lookupItem(Template template) { + public final Item lookupItem(Template template) { beforeLookup(template); Lookup[] lookups = this.getLookups(false); for (int i = 0; i < lookups.length; i++) { - Item o = lookups[i].lookupItem(template); + Item o = lookups[i].lookupItem(template); if (o != null) { return o; @@ -206,34 +204,37 @@ return null; } - public final synchronized Result lookup(Lookup.Template template) { - R r; + @SuppressWarnings("unchecked") + private static R convertResult(R r) { + return (R)r; + } + public final synchronized Result lookup(Lookup.Template template) { if (results != null) { - Reference ref = (Reference) results.get(template); - r = (ref == null) ? null : (R) ref.get(); + Reference ref = results.get(template); + R r = (ref == null) ? null : ref.get(); if (r != null) { - return r; + return convertResult(r); } } else { - results = new HashMap(); + results = new HashMap,Reference>(); } - r = new R(template); - results.put(template, new java.lang.ref.SoftReference(r)); + R newR = new R(template); + results.put(template, new java.lang.ref.SoftReference(newR)); - return r; + return newR; } /** Unregisters a template from the has map. */ - private final synchronized void unregisterTemplate(Template template) { + private final synchronized void unregisterTemplate(Template template) { if (results == null) { return; } - Reference ref = (Reference) results.remove(template); + Reference ref = results.remove(template); if ((ref != null) && (ref.get() != null)) { // seems like there is a reference to a result for this template @@ -246,24 +247,24 @@ * that was found (not too useful) and also to all objects found * (more useful). */ - private final class R extends WaitableResult { + private final class R extends WaitableResult { /** list of listeners added */ private javax.swing.event.EventListenerList listeners; /** template for this result */ - private Lookup.Template template; + private Lookup.Template template; /** collection of Objects */ private Collection[] cache; /** weak listener & result */ - private WeakResult weakL; + private WeakResult weakL; /** Constructor. */ - public R(Lookup.Template t) { + public R(Lookup.Template t) { template = t; - weakL = new WeakResult(this); + weakL = new WeakResult(this); } /** When garbage collected, remove the template from the has map. @@ -272,9 +273,14 @@ unregisterTemplate(template); } + @SuppressWarnings("unchecked") + private Result[] newResults(int len) { + return new Result[len]; + } + /** initializes the results */ - private Result[] initResults() { + private Result[] initResults() { synchronized (this) { if (weakL.results != null) { return weakL.results; @@ -282,7 +288,7 @@ } Lookup[] myLkps = getLookups(false); - Result[] arr = new Result[myLkps.length]; + Result[] arr = newResults(myLkps.length); for (int i = 0; i < arr.length; i++) { arr[i] = myLkps[i].lookup(template); @@ -318,7 +324,7 @@ } // map (Lookup, Lookup.Result) - HashMap map = new HashMap(old.length * 2); + HashMap> map = new HashMap>(old.length * 2); for (int i = 0; i < old.length; i++) { if (removed.contains(old[i])) { @@ -330,7 +336,7 @@ } } - Lookup.Result[] arr = new Lookup.Result[current.length]; + Lookup.Result[] arr = newResults(current.length); for (int i = 0; i < current.length; i++) { if (added.contains(current[i])) { @@ -339,7 +345,7 @@ arr[i].addLookupListener(weakL); } else { // old lookup - arr[i] = (Lookup.Result) map.get(current[i]); + arr[i] = map.get(current[i]); if (arr[i] == null) { // assert @@ -378,7 +384,8 @@ /** Access to all instances in the result. * @return collection of all instances */ - public java.util.Collection allInstances() { + @SuppressWarnings("unchecked") + public java.util.Collection allInstances() { return computeResult(0); } @@ -386,15 +393,17 @@ * that are registered in the system. * @return set of Class objects */ - public java.util.Set allClasses() { - return (java.util.Set) computeResult(1); + @SuppressWarnings("unchecked") + public java.util.Set> allClasses() { + return (java.util.Set>) computeResult(1); } /** All registered items. The collection of all pairs of * ii and their classes. * @return collection of Lookup.Item */ - public java.util.Collection allItems() { + @SuppressWarnings("unchecked") + public java.util.Collection> allItems() { return computeResult(2); } @@ -404,7 +413,7 @@ */ private java.util.Collection computeResult(int indexToCache) { // results to use - Lookup.Result[] arr = myBeforeLookup(); + Lookup.Result[] arr = myBeforeLookup(); // if the call to beforeLookup resulted in deletion of caches synchronized (this) { @@ -417,15 +426,17 @@ } // initialize the collection to hold result - Collection compute; - Collection ret; + Collection compute; + Collection ret; if (indexToCache == 1) { - compute = new HashSet(); - ret = Collections.unmodifiableSet((Set)compute); + HashSet s = new HashSet(); + compute = s; + ret = Collections.unmodifiableSet(s); } else { - compute = new ArrayList(arr.length * 2); - ret = Collections.unmodifiableList((List)compute); + List l = new ArrayList(arr.length * 2); + compute = l; + ret = Collections.unmodifiableList(l); } // fill the collection @@ -469,7 +480,7 @@ collectFires(null); } - protected void collectFires(Collection evAndListeners) { + protected void collectFires(Collection evAndListeners) { // clear cached instances Collection oldItems; Collection oldInstances; @@ -528,10 +539,10 @@ /** Implementation of my before lookup. * @return results to work on. */ - private Lookup.Result[] myBeforeLookup() { + private Lookup.Result[] myBeforeLookup() { ProxyLookup.this.beforeLookup(template); - Lookup.Result[] arr = initResults(); + Lookup.Result[] arr = initResults(); // invoke update on the results for (int i = 0; i < arr.length; i++) { @@ -552,18 +563,18 @@ } } } - private static final class WeakResult extends WaitableResult implements LookupListener { + private static final class WeakResult extends WaitableResult implements LookupListener { /** all results */ - private Lookup.Result[] results; + private Lookup.Result[] results; - private Reference result; + private Reference result; public WeakResult(R r) { - this.result = new WeakReference(r); + this.result = new WeakReference(r); } protected void beforeLookup(Lookup.Template t) { - R r = (R)result.get(); + R r = result.get(); if (r != null) { r.beforeLookup(t); } else { @@ -572,7 +583,7 @@ } private void removeListeners() { - Lookup.Result[] arr = this.results; + Lookup.Result[] arr = this.results; if (arr == null) { return; } @@ -582,8 +593,8 @@ } } - protected void collectFires(Collection evAndListeners) { - R r = (R)result.get(); + protected void collectFires(Collection evAndListeners) { + R r = result.get(); if (r != null) { r.collectFires(evAndListeners); } else { @@ -599,13 +610,13 @@ assert false; } - public Collection allInstances() { + public Collection allInstances() { assert false; return null; } public void resultChanged(LookupEvent ev) { - R r = (R)result.get(); + R r = result.get(); if (r != null) { r.resultChanged(ev); } else { @@ -613,12 +624,12 @@ } } - public Collection allItems() { + public Collection> allItems() { assert false; return null; } - public Set allClasses() { + public Set> allClasses() { assert false; return null; } Index: openide/util/src/org/openide/util/lookup/SimpleLookup.java =================================================================== RCS file: /cvs/openide/util/src/org/openide/util/lookup/SimpleLookup.java,v retrieving revision 1.4 retrieving revision 1.4.2.1 diff -u -r1.4 -r1.4.2.1 --- openide/util/src/org/openide/util/lookup/SimpleLookup.java 20 Dec 2005 16:59:46 -0000 1.4 +++ openide/util/src/org/openide/util/lookup/SimpleLookup.java 17 Mar 2006 19:51:08 -0000 1.4.2.1 @@ -28,50 +28,50 @@ class SimpleLookup extends org.openide.util.Lookup { /** This variable is initialized in constructor and thus null * value is not allowed as its value. */ - private Collection allItems; + private Collection> allItems; /** * Creates new Result object with supplied instances parameter. * @param instances to be used to return from the lookup */ - SimpleLookup(Collection instances) { - allItems = new ArrayList(instances.size()); + SimpleLookup(Collection instances) { + allItems = new ArrayList>(instances.size()); for (Iterator i = instances.iterator(); i.hasNext();) { - allItems.add(new InstanceContent.SimpleItem(i.next())); + allItems.add(new InstanceContent.SimpleItem(i.next())); } } - SimpleLookup(Collection keys, InstanceContent.Convertor conv) { - allItems = new ArrayList(keys.size()); + SimpleLookup(Collection keys, InstanceContent.Convertor conv) { + allItems = new ArrayList>(keys.size()); - for (Iterator i = keys.iterator(); i.hasNext();) { - allItems.add(new InstanceContent.ConvertingItem(i.next(), conv)); + for (T item : keys) { + allItems.add(new InstanceContent.ConvertingItem(item, conv)); } } public String toString() { - return "SimpleLookup" + lookup(new Template(Object.class)).allInstances(); + return "SimpleLookup" + lookup(new Template(Object.class)).allInstances(); } - public Result lookup(Template template) { + public Result lookup(Template template) { if (template == null) { throw new NullPointerException(); } - return new SimpleResult(template); + return new SimpleResult(template); } - public Object lookup(Class clazz) { + public T lookup(Class clazz) { for (Iterator i = allItems.iterator(); i.hasNext();) { Object o = i.next(); if (o instanceof AbstractLookup.Pair) { - AbstractLookup.Pair p = (AbstractLookup.Pair)o; + AbstractLookup.Pair p = (AbstractLookup.Pair)o; if (p.instanceOf(clazz)) { Object ret = p.getInstance(); if (clazz.isInstance(ret)) { - return ret; + return clazz.cast(ret); } } } @@ -83,12 +83,12 @@ * @param item the item to match * @return true if item matches the template requirements, false if not */ - private static boolean matches(Template t, AbstractLookup.Pair item) { + private static boolean matches(Template t, AbstractLookup.Pair item) { if (!AbstractLookup.matches(t, item, true)) { return false; } - Class type = t.getType(); + Class type = t.getType(); if ((type != null) && !type.isAssignableFrom(item.getType())) { return false; @@ -102,21 +102,21 @@ * passed in constructor. As the contents of this lookup result never * changes the addLookupListener and removeLookupListener are empty. */ - private class SimpleResult extends Lookup.Result { + private class SimpleResult extends Lookup.Result { /** can be null and is initialized lazily */ - private Set classes; + private Set> classes; /** can be null and is initialized lazily */ - private Collection items; + private Collection> items; /** Template used for this result. It is never null.*/ - private Template template; + private Template template; /** can be null and is initialized lazily */ - private Collection results; + private Collection results; /** Just remembers the supplied argument in variable template.*/ - SimpleResult(Template template) { + SimpleResult(Template template) { this.template = template; } @@ -138,17 +138,18 @@ * Lazy initializes the results collection. Uses a call to allItems * to obtain the instances. */ - public java.util.Collection allInstances() { + public java.util.Collection allInstances() { synchronized (this) { if (results != null) { return results; } } - Collection res = new ArrayList(allItems.size()); - for (Iterator i = allItems().iterator(); i.hasNext();) { - res.add(((Lookup.Item) i.next()).getInstance()); + Collection res = new ArrayList(allItems.size()); + + for (Item item : allItems()) { + res.add(item.getInstance()); } synchronized (this) { @@ -162,17 +163,17 @@ * Lazy initializes variable classes. Uses a call to allItems to * compute the result. */ - public Set allClasses() { + public Set> allClasses() { synchronized (this) { if (classes != null) { return classes; } } - Set res = new HashSet(); + Set> res = new HashSet>(); - for (Iterator i = allItems().iterator(); i.hasNext();) { - res.add(((Lookup.Item) i.next()).getType()); + for (Item item : allItems()) { + res.add(item.getType()); } synchronized (this) { @@ -187,21 +188,21 @@ * element in the instances collection. It puts either SimpleItem * or ConvertingItem to the collection. */ - public Collection allItems() { + public Collection> allItems() { synchronized (this) { if (items != null) { return items; } } - Collection res = new ArrayList(allItems.size()); + Collection> res = new ArrayList>(allItems.size()); - for (Iterator i = allItems.iterator(); i.hasNext();) { - Object o = i.next(); + for (Iterator> i = allItems.iterator(); i.hasNext();) { + Item o = i.next(); if (o instanceof AbstractLookup.Pair) { if (matches(template, (AbstractLookup.Pair) o)) { - res.add(o); + res.add(cast(o)); } } } @@ -211,6 +212,11 @@ } return items; + } + + @SuppressWarnings("unchecked") + private Item cast(Item i) { + return (Item)i; } } } Index: openide/util/src/org/openide/util/lookup/SimpleProxyLookup.java =================================================================== RCS file: /cvs/openide/util/src/org/openide/util/lookup/SimpleProxyLookup.java,v retrieving revision 1.4 retrieving revision 1.4.2.1 diff -u -r1.4 -r1.4.2.1 --- openide/util/src/org/openide/util/lookup/SimpleProxyLookup.java 20 Dec 2005 16:59:46 -0000 1.4 +++ openide/util/src/org/openide/util/lookup/SimpleProxyLookup.java 17 Mar 2006 19:51:07 -0000 1.4.2.1 @@ -35,7 +35,7 @@ private Lookup delegate; /** map of all templates to Reference (results) associated to this lookup */ - private WeakHashMap results; + private WeakHashMap,Reference>> results; /** * @param provider provider to delegate to @@ -49,24 +49,24 @@ Lookup l = provider.getLookup(); // iterator over Reference (ProxyResult) - Iterator toCheck = null; + Iterator>> toCheck = null; synchronized (this) { if (l != delegate) { this.delegate = l; if (results != null) { - toCheck = Arrays.asList(results.values().toArray()).iterator(); + toCheck = new ArrayList>>(results.values()).iterator(); } } } if (toCheck != null) { // update - ArrayList evAndListeners = new ArrayList(); - for (Iterator it = toCheck; it.hasNext(); ) { - java.lang.ref.Reference ref = (java.lang.ref.Reference) it.next(); - ProxyResult p = (ProxyResult) ref.get(); + ArrayList evAndListeners = new ArrayList(); + for (Iterator>> it = toCheck; it.hasNext(); ) { + java.lang.ref.Reference> ref = it.next(); + ProxyResult p = ref.get(); if (p != null && p.updateLookup(l)) { p.collectFires(evAndListeners); @@ -83,30 +83,36 @@ return delegate; } - public Result lookup(Template template) { + @SuppressWarnings("unchecked") + private static ProxyResult cast(ProxyResult p) { + return (ProxyResult)p; + } + + public Result lookup(Template template) { synchronized (this) { if (results == null) { - results = new WeakHashMap(); + results = new WeakHashMap,Reference>>(); } else { - java.lang.ref.Reference ref = (java.lang.ref.Reference) results.get(template); + Reference> ref = results.get(template); if (ref != null) { - ProxyResult p = (ProxyResult) ref.get(); + ProxyResult p = ref.get(); if (p != null) { - return p; + return cast(p); } } } - ProxyResult p = new ProxyResult(template); - results.put(template, new java.lang.ref.WeakReference(p)); + ProxyResult p = new ProxyResult(template); + Reference> ref = new WeakReference>(p); + results.put(template, ref); return p; } } - public Object lookup(Class clazz) { + public T lookup(Class clazz) { if (clazz == null) { checkLookup(); return null; @@ -114,7 +120,7 @@ return checkLookup().lookup(clazz); } - public Item lookupItem(Template template) { + public Item lookupItem(Template template) { return checkLookup().lookupItem(template); } @@ -123,25 +129,25 @@ * passed in constructor. As the contents of this lookup result never * changes the addLookupListener and removeLookupListener are empty. */ - private final class ProxyResult extends WaitableResult implements LookupListener { + private final class ProxyResult extends WaitableResult implements LookupListener { /** Template used for this result. It is never null.*/ - private Template template; + private Template template; /** result to delegate to */ - private Lookup.Result delegate; + private Lookup.Result delegate; /** listeners set */ private javax.swing.event.EventListenerList listeners; private LookupListener lastListener; /** Just remembers the supplied argument in variable template.*/ - ProxyResult(Template template) { + ProxyResult(Template template) { this.template = template; } /** Checks state of the result */ - private Result checkResult() { + private Result checkResult() { updateLookup(checkLookup()); return this.delegate; @@ -151,7 +157,7 @@ * @return true if the lookup really changed */ public boolean updateLookup(Lookup l) { - Collection oldPairs = (delegate != null) ? delegate.allItems() : null; + Collection> oldPairs = (delegate != null) ? delegate.allItems() : null; LookupListener removedListener; @@ -165,12 +171,12 @@ } // cannot call to foreign code - Lookup.Result res = l.lookup(template); + Lookup.Result res = l.lookup(template); synchronized (this) { if (removedListener == lastListener) { delegate = res; - lastListener = new WeakResult(this, delegate); + lastListener = new WeakResult(this, delegate); delegate.addLookupListener(lastListener); } } @@ -180,20 +186,20 @@ return false; } - Collection newPairs = delegate.allItems(); + Collection> newPairs = delegate.allItems(); // See #34961 for explanation. if (!(oldPairs instanceof List)) { if (oldPairs == Collections.EMPTY_SET) { // avoid allocation - oldPairs = Collections.EMPTY_LIST; + oldPairs = Collections.emptyList(); } else { - oldPairs = new ArrayList(oldPairs); + oldPairs = new ArrayList>(oldPairs); } } if (!(newPairs instanceof List)) { - newPairs = new ArrayList(newPairs); + newPairs = new ArrayList>(newPairs); } return !oldPairs.equals(newPairs); @@ -213,15 +219,15 @@ } } - public java.util.Collection allInstances() { + public java.util.Collection allInstances() { return checkResult().allInstances(); } - public Set allClasses() { + public Set> allClasses() { return checkResult().allClasses(); } - public Collection allItems() { + public Collection> allItems() { return checkResult().allItems(); } @@ -241,7 +247,7 @@ collectFires(null); } - protected void collectFires(Collection evAndListeners) { + protected void collectFires(Collection evAndListeners) { javax.swing.event.EventListenerList l = this.listeners; if (l == null) { @@ -259,12 +265,12 @@ } } // end of ProxyResult - private final class WeakResult extends WaitableResult implements LookupListener { + private final class WeakResult extends WaitableResult implements LookupListener { private Lookup.Result source; - private Reference result; + private Reference> result; - public WeakResult(ProxyResult r, Lookup.Result s) { - this.result = new WeakReference(r); + public WeakResult(ProxyResult r, Lookup.Result s) { + this.result = new WeakReference>(r); this.source = s; } @@ -277,8 +283,8 @@ } } - protected void collectFires(Collection evAndListeners) { - ProxyResult r = (ProxyResult)result.get(); + protected void collectFires(Collection evAndListeners) { + ProxyResult r = result.get(); if (r != null) { r.collectFires(evAndListeners); } else { @@ -294,7 +300,7 @@ assert false; } - public Collection allInstances() { + public Collection allInstances() { assert false; return null; } @@ -308,12 +314,12 @@ } } - public Collection allItems() { + public Collection> allItems() { assert false; return null; } - public Set allClasses() { + public Set> allClasses() { assert false; return null; } Index: openide/util/src/org/openide/util/lookup/WaitableResult.java =================================================================== RCS file: /cvs/openide/util/src/org/openide/util/lookup/WaitableResult.java,v retrieving revision 1.2 retrieving revision 1.2.14.1 diff -u -r1.2 -r1.2.14.1 --- openide/util/src/org/openide/util/lookup/WaitableResult.java 2 Dec 2005 10:45:42 -0000 1.2 +++ openide/util/src/org/openide/util/lookup/WaitableResult.java 17 Mar 2006 19:51:07 -0000 1.2.14.1 @@ -20,7 +20,7 @@ * * @author Jaroslav Tulach */ -abstract class WaitableResult extends Lookup.Result { +abstract class WaitableResult extends Lookup.Result { /** Used by proxy results to synchronize before lookup. */ protected abstract void beforeLookup(Lookup.Template t); @@ -29,6 +29,6 @@ * after all AbstractLookup and ProxyLookups have been updated. * @param evAndListeners LookupEvent, LookupListener, LookupEvent, LookupListener, etc. */ - protected abstract void collectFires(Collection evAndListeners); + protected abstract void collectFires(Collection evAndListeners); } Index: openide/util/src/org/openide/xml/EntityCatalog.java =================================================================== RCS file: /cvs/openide/util/src/org/openide/xml/EntityCatalog.java,v retrieving revision 1.1 retrieving revision 1.1.48.1 diff -u -r1.1 -r1.1.48.1 --- openide/util/src/org/openide/xml/EntityCatalog.java 21 Apr 2005 20:16:22 -0000 1.1 +++ openide/util/src/org/openide/xml/EntityCatalog.java 17 Mar 2006 19:51:10 -0000 1.1.48.1 @@ -68,7 +68,7 @@ * This catalog is forwarding implementation. */ private static class Forwarder extends EntityCatalog { - private Lookup.Result result; + private Lookup.Result result; Forwarder() { } @@ -76,15 +76,12 @@ public InputSource resolveEntity(String publicID, String systemID) throws IOException, SAXException { if (result == null) { - Lookup.Template temp = new Lookup.Template(EntityCatalog.class); + Lookup.Template temp = new Lookup.Template(EntityCatalog.class); result = Lookup.getDefault().lookup(temp); } - Iterator it = result.allInstances().iterator(); - - while (it.hasNext()) { + for (EntityCatalog res : result.allInstances()) { // using resolver's method because EntityCatalog extends EntityResolver - EntityCatalog res = (EntityCatalog) it.next(); InputSource is = res.resolveEntity(publicID, systemID); if (is != null) { Index: openide/util/src/org/openide/xml/XMLUtil.java =================================================================== RCS file: /cvs/openide/util/src/org/openide/xml/XMLUtil.java,v retrieving revision 1.8 retrieving revision 1.8.14.1 diff -u -r1.8 -r1.8.14.1 --- openide/util/src/org/openide/xml/XMLUtil.java 6 Dec 2005 15:40:08 -0000 1.8 +++ openide/util/src/org/openide/xml/XMLUtil.java 17 Mar 2006 19:51:11 -0000 1.8.14.1 @@ -275,10 +275,11 @@ * Cache of DocumentBuilder instances per thread. * They are relatively expensive to create, so don't do it more than necessary. */ - private static final ThreadLocal/**/[] builderTL = new ThreadLocal[4]; + @SuppressWarnings("unchecked") + private static final ThreadLocal[] builderTL = new ThreadLocal[4]; static { for (int i = 0; i < 4; i++) { - builderTL[i] = new ThreadLocal(); + builderTL[i] = new ThreadLocal(); } } /** @@ -431,7 +432,7 @@ Method setLineWidth = outputFormatClazz.getMethod("setLineWidth", new Class[] {Integer.TYPE}); // NOI18N setLineWidth.invoke(outputFormat, new Object[] {new Integer(0)}); Method setLineSeparator = outputFormatClazz.getMethod("setLineSeparator", new Class[] {String.class}); // NOI18N - setLineSeparator.invoke(outputFormat, new String[] {System.getProperty("line.separator")}); // NOI18N + setLineSeparator.invoke(outputFormat, System.getProperty("line.separator")); // NOI18N Method setOutputByteStream = xmlSerializerClazz.getMethod("setOutputByteStream", new Class[] {OutputStream.class}); // NOI18N setOutputByteStream.invoke(xmlSerializer, new Object[] {out}); Method setEncoding = outputFormatClazz.getMethod("setEncoding", new Class[] {String.class}); // NOI18N @@ -441,7 +442,7 @@ Method setNamespaces = xmlSerializerClazz.getMethod("setNamespaces", new Class[] {Boolean.TYPE}); // NOI18N setNamespaces.invoke(xmlSerializer, new Object[] {Boolean.TRUE}); Method asDOMSerializer = xmlSerializerClazz.getMethod("asDOMSerializer", new Class[0]); // NOI18N - Object impl = asDOMSerializer.invoke(xmlSerializer, null); + Object impl = asDOMSerializer.invoke(xmlSerializer); Method serialize = impl.getClass().getMethod("serialize", new Class[] {Document.class}); // NOI18N serialize.invoke(impl, new Object[] {doc}); } Index: openide/util/test/unit/src/org/openide/util/UtilitiesTopologicalSortTest.java =================================================================== RCS file: /cvs/openide/util/test/unit/src/org/openide/util/UtilitiesTopologicalSortTest.java,v retrieving revision 1.1 retrieving revision 1.1.48.1 diff -u -r1.1 -r1.1.48.1 --- openide/util/test/unit/src/org/openide/util/UtilitiesTopologicalSortTest.java 22 Apr 2005 06:03:06 -0000 1.1 +++ openide/util/test/unit/src/org/openide/util/UtilitiesTopologicalSortTest.java 17 Mar 2006 19:51:09 -0000 1.1.48.1 @@ -250,7 +250,25 @@ assertEquals(Arrays.asList(new String[] {"d", "e"}), l.subList(5, 7)); */ } + public void testTopologicalSortCompile() throws Exception { + Collection c = new ArrayList(); + Map> edges = new HashMap>(); + + List result = Utilities.topologicalSort(c, edges); + } + public void testTopologicalSortCompile2() throws Exception { + Collection c = new ArrayList(); + Map> edges = new HashMap>(); + + List result = Utilities.topologicalSort(c, edges); + } + public void testTopologicalSortCompile3() throws Exception { + Collection c = new ArrayList(); + Map> edges = new HashMap>(); + + List result = Utilities.topologicalSort(c, edges); + } public void testErrorReporting () throws Exception { Collection c = Arrays.asList(new String[] {"a", "b", "c", "d", "e", "f"}); Map m = new HashMap (); Index: openide/util/test/unit/src/org/openide/util/WeakListenersTest.java =================================================================== RCS file: /cvs/openide/util/test/unit/src/org/openide/util/WeakListenersTest.java,v retrieving revision 1.4 retrieving revision 1.4.2.1 diff -u -r1.4 -r1.4.2.1 --- openide/util/test/unit/src/org/openide/util/WeakListenersTest.java 5 Mar 2006 21:08:57 -0000 1.4 +++ openide/util/test/unit/src/org/openide/util/WeakListenersTest.java 17 Mar 2006 19:51:09 -0000 1.4.2.1 @@ -265,21 +265,21 @@ public void testExceptionIllegalState () { Listener l = new Listener (); try { - WeakListeners.create (PropertyChangeListener.class, javax.naming.event.NamingListener.class, l, null); + WeakListeners.create ((Class)PropertyChangeListener.class, (Class)javax.naming.event.NamingListener.class, l, null); fail ("This shall not be allowed as NamingListener is not superclass of PropertyChangeListener"); } catch (IllegalArgumentException ex) { // ok } try { - WeakListeners.create (Object.class, l, null); + WeakListeners.create ((Class)Object.class, l, null); fail ("Not interface, it should fail"); } catch (IllegalArgumentException ex) { // ok } try { - WeakListeners.create (Object.class, Object.class, l, null); + WeakListeners.create ((Class)Object.class, (Class)Object.class, l, null); fail ("Not interface, it should fail"); } catch (IllegalArgumentException ex) { // ok @@ -361,8 +361,8 @@ } } - private static final class Listener - implements java.beans.PropertyChangeListener, javax.naming.event.ObjectChangeListener { + private static final class Listener + implements PCL, java.beans.PropertyChangeListener, javax.naming.event.ObjectChangeListener { public int cnt; public void propertyChange (java.beans.PropertyChangeEvent ev) { Index: openide/util/test/unit/src/org/openide/util/lookup/AbstractLookupMemoryTest.java =================================================================== RCS file: /cvs/openide/util/test/unit/src/org/openide/util/lookup/AbstractLookupMemoryTest.java,v retrieving revision 1.1 retrieving revision 1.1.48.1 diff -u -r1.1 -r1.1.48.1 --- openide/util/test/unit/src/org/openide/util/lookup/AbstractLookupMemoryTest.java 22 Apr 2005 06:03:14 -0000 1.1 +++ openide/util/test/unit/src/org/openide/util/lookup/AbstractLookupMemoryTest.java 17 Mar 2006 19:51:09 -0000 1.1.48.1 @@ -83,10 +83,10 @@ c.addPair ((EmptyPair)ignore[1]); assertSize ("Is bigger I guess (not counting the pair sizes)", Collections.singleton (l), 56, ignore); - c.setPairs(Arrays.asList (ignore).subList (0, 3)); + c.setPairs((Collection)Arrays.asList (ignore).subList (0, 3)); assertSize ("Even bigger (not counting the pair sizes)", Collections.singleton (l), 64, ignore); - c.setPairs(Arrays.asList (ignore).subList (0, 4)); + c.setPairs((Collection)Arrays.asList (ignore).subList (0, 4)); assertSize ("Now not that much(not counting the pair sizes)", Collections.singleton (l), 64, ignore); Lookup.Result res = l.lookup (t);