Skip to content

Commit

Permalink
[NETBEANS-5074] - cleanup ArrayList warnings..
Browse files Browse the repository at this point in the history
This work cleans up a bunch of warnings surrounding the use of ArrayList..

For example:

   [repeat] /home/bwalker/src/netbeans/platform/core.multitabs/src/org/netbeans/core/multitabs/impl/TabLayoutManager.java:245: warning: [unchecked] unchecked conversion
   [repeat]             List<Integer>[] rowIndexes = new ArrayList[rowCount];
   [repeat]                                          ^
   [repeat]   required: List<Integer>[]
   [repeat]   found:    ArrayList[]

ActionsManager.java was especially involved since one change would require another. And keeping track of
that, so as not to break things, was hard.
  • Loading branch information
BradWalker committed Nov 28, 2020
1 parent b9a3bfb commit 9f7f605
Show file tree
Hide file tree
Showing 36 changed files with 92 additions and 78 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ private void init (FileObject fo,EarDataLoader loader) {
}

private void refreshSourceFolders () {
ArrayList srcRootList = new ArrayList ();
List<FileObject> srcRootList = new ArrayList<>();

Project project = FileOwnerQuery.getOwner (getPrimaryFile ());
if (project != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ private void init(FileObject fo, ClientDataLoader loader) {
}

private void refreshSourceFolders() {
ArrayList srcRootList = new ArrayList();
List<FileObject> srcRootList = new ArrayList<>();

Project project = FileOwnerQuery.getOwner(getPrimaryFile());
if (project != null) {
Expand Down
2 changes: 1 addition & 1 deletion enterprise/web.core.syntax/nbproject/project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ release.external/generated-jstl11-doc-1.1.2.zip=docs/jstl11-doc.zip
release.external/generated-jsf12-tlddoc-1.2-20.zip=docs/jsf12-tlddoc.zip
release.external/generated-struts-tags-1.3.10.zip=docs/struts-tags.zip

javac.source=1.6
javac.source=1.8
requires.nb.javac=true
javadoc.arch=${basedir}/arch.xml

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import javax.swing.text.BadLocationException;
import javax.swing.text.JTextComponent;
import javax.swing.text.StyledDocument;
Expand Down Expand Up @@ -59,12 +60,12 @@ public class ErrorAnnotationImpl implements ErrorAnnotation {
/** Jsp file, for which is the ErrorAnnotation */
private FileObject jspFo;

private ArrayList annotations;
private List annotations;

/** Creates a new instance of ErrorAnnotation */
public ErrorAnnotationImpl(FileObject jspFo) {
this.jspFo = jspFo;
annotations = new ArrayList();
annotations = new ArrayList<>();
}

/** Adds annotation for the errors. If the error is already annotated, does nothing. If there are
Expand All @@ -74,7 +75,7 @@ public ErrorAnnotationImpl(FileObject jspFo) {
*/
@Override
public void annotate(ErrorInfo[] errors){
ArrayList added, removed, unchanged;
List added, removed, unchanged;
Collection newAnnotations;

// obtain data object
Expand Down Expand Up @@ -113,10 +114,10 @@ public void annotate(ErrorInfo[] errors){
// create annotations from errors
newAnnotations = getAnnotations(errors, document);
// which annotations are really new
added=new ArrayList(newAnnotations);
added=new ArrayList<>(newAnnotations);
added.removeAll(annotations);
// which annotations were here before
unchanged=new ArrayList(annotations);
unchanged=new ArrayList<>(annotations);
unchanged.retainAll(newAnnotations);
// which annotations are obsolete
removed = annotations;
Expand All @@ -125,7 +126,7 @@ public void annotate(ErrorInfo[] errors){

// are there new annotations?
if (!added.isEmpty()) {
final ArrayList finalAdded = added;
final List finalAdded = added;
final DataObject doJsp2 = doJsp;
Runnable docRenderer = new Runnable() {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public NewWebFreeformProjectWizardIterator() {
}

private WizardDescriptor.Panel[] createPanels () {
List<WizardDescriptor.Panel> l = new ArrayList<WizardDescriptor.Panel>();
List<WizardDescriptor.Panel> l = new ArrayList<>();
List<TargetDescriptor> extraTargets = new ArrayList<TargetDescriptor>();
extraTargets.add(WebProjectNature.getExtraTarget());
l.add(NewFreeformProjectSupport.createBasicProjectInfoWizardPanel());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ public static Object makeCollection(String className, ClassLoader loader)
} else {
Class<?> cls = Class.forName(className, true, loader);
if (cls.isInterface()) {
return new ArrayList();
return new ArrayList<Object>();
} else {
savedLoader = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(loader);
Expand Down
52 changes: 31 additions & 21 deletions ide/api.debugger/src/org/netbeans/api/debugger/ActionsManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,14 @@

import java.beans.*;
import java.lang.reflect.Field;
import java.util.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Vector;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.logging.Level;
import java.util.logging.Logger;
Expand Down Expand Up @@ -105,7 +112,7 @@ public final class ActionsManager {

private final Vector<ActionsManagerListener> listener = new Vector<ActionsManagerListener>();
private final HashMap<String, List<ActionsManagerListener>> listeners = new HashMap<String, List<ActionsManagerListener>>();
private HashMap<Object, ArrayList<ActionsProvider>> actionProviders;
private HashMap<Object, List<ActionsProvider>> actionProviders;
private final Object actionProvidersLock = new Object();
private final AtomicBoolean actionProvidersInitialized = new AtomicBoolean(false);
private MyActionListener actionListener = new MyActionListener ();
Expand Down Expand Up @@ -137,7 +144,7 @@ public final class ActionsManager {
*/
public final void doAction (final Object action) {
doiingDo = true;
ArrayList<ActionsProvider> l = getActionProvidersForActionWithInit(action);
List<ActionsProvider> l = getActionProvidersForActionWithInit(action);
boolean done = false;
if (l != null) {
int i, k = l.size ();
Expand Down Expand Up @@ -185,15 +192,17 @@ public final Task postAction(final Object action) {
if (!inited && Mutex.EVENT.isReadAccess()) { // is EDT
return postActionWithLazyInit(action);
}
ArrayList<ActionsProvider> l = getActionProvidersForActionWithInit(action);

List<ActionsProvider> l = getActionProvidersForActionWithInit(action);
boolean posted = false;
int k;
if (l != null) {
k = l.size ();
} else {
k = 0;
}
List<ActionsProvider> postedActions = new ArrayList<ActionsProvider>(k);

List<ActionsProvider> postedActions = new ArrayList<>(k);
final AsynchActionTask task = new AsynchActionTask(postedActions);
if (l != null) {
int i;
Expand Down Expand Up @@ -356,7 +365,7 @@ public final boolean isEnabled (final Object action) {
boolean doInit = false;
synchronized (actionProvidersLock) {
if (actionProviders == null) {
actionProviders = new HashMap<Object, ArrayList<ActionsProvider>>();
actionProviders = new HashMap<>();
doInit = true;
}
}
Expand All @@ -374,7 +383,8 @@ public void run() {
initActionImpls();
}
}
ArrayList<ActionsProvider> l = getActionProvidersForAction(action);

List<ActionsProvider> l = getActionProvidersForAction(action);
if (l != null) {
int i, k = l.size ();
for (i = 0; i < k; i++) {
Expand Down Expand Up @@ -431,7 +441,7 @@ public void addActionsManagerListener (
synchronized (listeners) {
List<ActionsManagerListener> ls = listeners.get (propertyName);
if (ls == null) {
ls = new ArrayList<ActionsManagerListener>();
ls = new ArrayList<>();
listeners.put (propertyName, ls);
}
ls.add(l);
Expand Down Expand Up @@ -498,12 +508,12 @@ private void fireActionDone (
final Object action
) {
initListeners ();
List<ActionsManagerListener> l = new ArrayList<ActionsManagerListener>(listener);
List<ActionsManagerListener> l = new ArrayList<>(listener);
List<ActionsManagerListener> l1;
synchronized (listeners) {
l1 = listeners.get(ActionsManagerListener.PROP_ACTION_PERFORMED);
if (l1 != null) {
l1 = new ArrayList<ActionsManagerListener>(l1);
l1 = new ArrayList<>(l1);
}
}
int i, k = l.size ();
Expand Down Expand Up @@ -533,12 +543,12 @@ private void fireActionStateChanged (
) {
boolean enabled = isEnabled (action);
initListeners ();
List<ActionsManagerListener> l = new ArrayList<ActionsManagerListener>(listener);
List<ActionsManagerListener> l = new ArrayList<>(listener);
List<ActionsManagerListener> l1;
synchronized (listeners) {
l1 = listeners.get(ActionsManagerListener.PROP_ACTION_STATE_CHANGED);
if (l1 != null) {
l1 = new ArrayList<ActionsManagerListener>(l1);
l1 = new ArrayList<>(l1);
}
}
int i, k = l.size ();
Expand All @@ -556,22 +566,22 @@ private void fireActionStateChanged (

// private support .........................................................

private ArrayList<ActionsProvider> getActionProvidersForAction(Object action) {
ArrayList<ActionsProvider> l;
private List<ActionsProvider> getActionProvidersForAction(Object action) {
List<ActionsProvider> l;
synchronized (actionProvidersLock) {
l = actionProviders.get(action);
if (l != null) {
l = (ArrayList<ActionsProvider>) l.clone ();
l = new ArrayList<>(l);
}
}
return l;
}

private ArrayList<ActionsProvider> getActionProvidersForActionWithInit(Object action) {
private List<ActionsProvider> getActionProvidersForActionWithInit(Object action) {
boolean doInit = false;
synchronized (actionProvidersLock) {
if (actionProviders == null) {
actionProviders = new HashMap<Object, ArrayList<ActionsProvider>>();
actionProviders = new HashMap<>();
doInit = true;
}
}
Expand All @@ -593,9 +603,9 @@ private ArrayList<ActionsProvider> getActionProvidersForActionWithInit(Object ac

private void registerActionsProvider (Object action, ActionsProvider p) {
synchronized (actionProvidersLock) {
ArrayList<ActionsProvider> l = actionProviders.get (action);
List<ActionsProvider> l = actionProviders.get(action);
if (l == null) {
l = new ArrayList<ActionsProvider>();
l = new ArrayList<>();
actionProviders.put (action, l);
}
l.add (p);
Expand Down Expand Up @@ -721,8 +731,8 @@ private void destroyIn () {
}
}
synchronized (actionProvidersLock) {
Collection<ArrayList<ActionsProvider>> apsc = actionProviders.values();
for (ArrayList<ActionsProvider> aps : apsc) {
Collection<List<ActionsProvider>> apsc = actionProviders.values();
for (List<ActionsProvider> aps : apsc) {
for (ActionsProvider ap : aps) {
ap.removeActionsProviderListener(actionListener);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ int getRecentChangesColumnIdx() {
}

private void setFilterIntern(Filter filter) {
final List<IssueNode> filteredNodes = new ArrayList<IssueNode>(nodes.size());
final List<IssueNode> filteredNodes = new ArrayList<>(nodes.size());
for (IssueNode node : nodes) {
if (filter == null || filter.accept(node)) {
filteredNodes.add(node);
Expand Down Expand Up @@ -669,7 +669,7 @@ public void ancestorMoved(AncestorEvent event) { }
public void ancestorRemoved(AncestorEvent event) { }

private void setModelProperties() {
List<ColumnDescriptor> properties = new ArrayList<ColumnDescriptor>(descriptors.length + (isSaved ? 2 : 0));
List<ColumnDescriptor> properties = new ArrayList<>(descriptors.length + (isSaved ? 2 : 0));
int i = 0;
for (; i < descriptors.length; i++) {
ColumnDescriptor desc = descriptors[i];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public void propertyChange(PropertyChangeEvent evt) {
if(LOG.isLoggable(Level.FINE)) {
LOG.log(Level.FINE, "firing query list change {0} - rImpl: {1} - r: {2}", new Object[]{getDisplayName(), this, r}); // NOI18N
}
Collection<QueryImpl> queries = new ArrayList<QueryImpl>(getQueries());
Collection<QueryImpl> queries = new ArrayList<>(getQueries());
synchronized(queryMap) {
List<Q> toRemove = new LinkedList<Q>();
for(Entry<Q, WeakReference<QueryImpl>> e : queryMap.entrySet()) {
Expand Down Expand Up @@ -218,7 +218,7 @@ public Collection<IssueImpl> getIssueImpls(String... ids) {
if(is == null || is.isEmpty()) {
return Collections.emptyList();
}
List<IssueImpl> ret = new ArrayList<IssueImpl>(is.size());
List<IssueImpl> ret = new ArrayList<>(is.size());
for (I i : is) {
IssueImpl impl = getIssue(i);
if(impl != null) {
Expand Down Expand Up @@ -255,7 +255,7 @@ public RepositoryProvider<R, Q, I> getProvider() {

public Collection<IssueImpl> simpleSearch(String criteria) {
Collection<I> issues = repositoryProvider.simpleSearch(r, criteria);
List<IssueImpl> ret = new ArrayList<IssueImpl>(issues.size());
List<IssueImpl> ret = new ArrayList<>(issues.size());
for (I i : issues) {
ret.add(getIssue(i));
}
Expand Down Expand Up @@ -428,7 +428,7 @@ public Collection<IssueImpl> getUnsubmittedIssues () {
if (issues == null || issues.isEmpty()) {
return Collections.<IssueImpl>emptyList();
}
List<IssueImpl> ret = new ArrayList<IssueImpl>(issues.size());
List<IssueImpl> ret = new ArrayList<>(issues.size());
for (I i : issues) {
IssueImpl impl = getIssue(i);
if(impl != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ private void fireChanged() {
abbreviation,
getDescription(idx),
getText(idx),
new ArrayList(getContexts(idx)),
new ArrayList<String>(getContexts(idx)),
getUniqueId(idx),
mimeType
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ public void run() {
if (fold == null) {
return;
}
List<Fold> allFolds = new ArrayList<>(FoldUtilities.findRecursive(fold));
List<Fold> allFolds = new ArrayList<Fold>(FoldUtilities.findRecursive(fold));
Collections.reverse(allFolds);
allFolds.add(0, fold);
hierarchy.expand(allFolds);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ public void resultChanged(LookupEvent ev) {
private static boolean rebuilding = false;

private final String storageDescriptionId;
private final List<StorageFilter> filtersForId = new ArrayList<StorageFilter>();
private final List<StorageFilter> filtersForId = new ArrayList<>();

private static Set<String> rebuild() {
filters.clear();
Expand Down
2 changes: 1 addition & 1 deletion ide/html/nbproject/project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@
# under the License.

javac.compilerargs=-Xlint:unchecked
javac.source=1.6
javac.source=1.8
javadoc.arch=${basedir}/arch.xml
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ private synchronized void updateModelLazily() {
if (View.LOCALS_VIEW_NAME.equals(viewType) && (VariablesViewButtons.isResultsViewNested() ||
VariablesViewButtons.isWatchesViewNested())) {

hyperModels = new ArrayList();
hyperModels = new ArrayList<>();
if (VariablesViewButtons.isResultsViewNested()) {
hyperModels.add(createCompound(View.RESULTS_VIEW_NAME));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public final class Turbo {

private static WeakReference defaultInstance;

private List listeners = new ArrayList(100);
private List<TurboListener> listeners = new ArrayList<>(100);

/** memory layer */
private final Memory memory;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.List;
import org.openide.ErrorManager;
import org.openide.util.Lookup;
import org.openide.util.lookup.Lookups;
Expand Down Expand Up @@ -147,7 +148,7 @@ public GrammarQuery getGrammar(GrammarEnvironment ctx) {
public Enumeration enabled(GrammarEnvironment ctx) {
Iterator<GrammarQueryManager> it = getRegistrations();
transaction.set(null);
ArrayList list = new ArrayList(5);
List list = new ArrayList<>(5);
{
Enumeration en = ctx.getDocumentChildren();
while (en.hasMoreElements()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ public SyntaxElement createElement( TokenItem item ) throws BadLocationException
}
} else { // starttag
String name = text.substring( 1 );
ArrayList attrs = new ArrayList();
List<String> attrs = new ArrayList<>();

// skip attributes

Expand Down
Loading

0 comments on commit 9f7f605

Please sign in to comment.