From 6b38c14ff11a3fc1321bfb2b225be8bb3e44598b Mon Sep 17 00:00:00 2001 From: aclement Date: Wed, 27 Aug 2008 00:38:04 +0000 Subject: [PATCH] findbugs/eclipse warnings fixed --- ajde/src/org/aspectj/ajde/Ajde.java | 10 +++--- .../ajde/internal/LstBuildConfigManager.java | 2 +- .../aspectj/ajde/ui/AbstractIconRegistry.java | 4 +-- .../org/aspectj/ajde/ui/BuildConfigModel.java | 8 ++--- .../org/aspectj/ajde/ui/BuildConfigNode.java | 17 ++++++---- .../ajde/ui/StructureSearchManager.java | 8 ++--- .../org/aspectj/ajde/ui/StructureView.java | 2 +- .../aspectj/ajde/ui/StructureViewManager.java | 6 ++-- .../ui/internal/TreeStructureViewBuilder.java | 34 +++++++------------ .../ui/internal/UserPreferencesStore.java | 2 +- .../ajde/ui/swing/BrowserViewPanel.java | 2 +- .../ui/swing/BrowserViewTreeListener.java | 4 +-- .../swing/CompilerMessagesCellRenderer.java | 2 +- .../aspectj/ajde/ui/swing/OptionsFrame.java | 28 +++++++-------- .../ajde/ui/swing/StructureTreeManager.java | 4 +-- .../ajde/ui/swing/StructureViewPanel.java | 6 ++-- .../ui/swing/TreeViewBuildConfigEditor.java | 6 ++-- 17 files changed, 67 insertions(+), 78 deletions(-) diff --git a/ajde/src/org/aspectj/ajde/Ajde.java b/ajde/src/org/aspectj/ajde/Ajde.java index 0ce1fa7ce..6191b60d8 100644 --- a/ajde/src/org/aspectj/ajde/Ajde.java +++ b/ajde/src/org/aspectj/ajde/Ajde.java @@ -225,7 +225,7 @@ public class Ajde { } else if (0 != result) { String m = "Result of running " + context; uiBuildMsgHandler.handleMessage(new Message(m, - IMessage.ERROR, thrown, null)); + IMessage.ERROR, null, null)); } if (null != any.fromInPipe) { String m = "Error processing input pipe for " + context; @@ -245,8 +245,7 @@ public class Ajde { } }; - controller = LangUtil.makeProcess(controller, props.classpath, - props.mainClass, props.args); + controller = LangUtil.makeProcess(controller, props.classpath, props.mainClass, props.args); command.append(Arrays.asList(controller.getCommand()).toString()); @@ -347,7 +346,7 @@ public class Ajde { compilerThread.start(); } - class CompilerThread extends Thread { + static class CompilerThread extends Thread { private AjCompiler compiler; private boolean buildFresh; @@ -505,8 +504,7 @@ public class Ajde { public AjCompiler getCompilerForConfigFile(String configFile) { if (configFile == null) return null; - if ((compiler == null || !compiler.getId().equals(configFile)) - && configFile != null) { + if ((compiler == null || !compiler.getId().equals(configFile))) { if (compiler != null) { // have to remove the incremental state of the previous // compiler - this will remove it from the diff --git a/ajde/src/org/aspectj/ajde/internal/LstBuildConfigManager.java b/ajde/src/org/aspectj/ajde/internal/LstBuildConfigManager.java index d66d40c59..c0ff8b8a9 100644 --- a/ajde/src/org/aspectj/ajde/internal/LstBuildConfigManager.java +++ b/ajde/src/org/aspectj/ajde/internal/LstBuildConfigManager.java @@ -87,7 +87,7 @@ public class LstBuildConfigManager implements BuildConfigManager { addFilesToDirTree(model, relativePaths, badEntries); pruneEmptyDirs(root); - sortModel((BuildConfigNode)model.getRoot(), ALPHABETICAL_COMPARATOR); + sortModel(model.getRoot(), ALPHABETICAL_COMPARATOR); //addImportedFilesToDirTree(model, importedFiles); addProblemEntries(root, badEntries); diff --git a/ajde/src/org/aspectj/ajde/ui/AbstractIconRegistry.java b/ajde/src/org/aspectj/ajde/ui/AbstractIconRegistry.java index 8a0ed8b40..742cc1a6b 100644 --- a/ajde/src/org/aspectj/ajde/ui/AbstractIconRegistry.java +++ b/ajde/src/org/aspectj/ajde/ui/AbstractIconRegistry.java @@ -76,9 +76,7 @@ public abstract class AbstractIconRegistry { /** * @return null if the kind could not be resolved */ - protected AbstractIcon getStructureIcon(IProgramElement.Kind kind, IProgramElement.Accessibility accessibility) { - return getStructureIcon(kind, IProgramElement.Accessibility.PUBLIC); - } + protected abstract AbstractIcon getStructureIcon(IProgramElement.Kind kind, IProgramElement.Accessibility accessibility); /** * Assumes "public" visibility for the icon. diff --git a/ajde/src/org/aspectj/ajde/ui/BuildConfigModel.java b/ajde/src/org/aspectj/ajde/ui/BuildConfigModel.java index e682a6204..01ef07bd3 100644 --- a/ajde/src/org/aspectj/ajde/ui/BuildConfigModel.java +++ b/ajde/src/org/aspectj/ajde/ui/BuildConfigModel.java @@ -42,8 +42,7 @@ public class BuildConfigModel { return upPathMatch; } else { StringTokenizer st = new StringTokenizer(path, "/"); - BuildConfigNode node = (BuildConfigNode)root; - return getNodeForPathHelper(st, node); + return getNodeForPathHelper(st, root); } } @@ -72,7 +71,7 @@ public class BuildConfigModel { public List getActiveNodes(BuildConfigNode.Kind kind) { List nodes = new ArrayList(); - getActiveNodesHelper((BuildConfigNode)getRoot(), kind, nodes); + getActiveNodesHelper(root, kind, nodes); return nodes; } @@ -134,8 +133,7 @@ public class BuildConfigModel { && ((node.getSourceLocation().getLine() <= lineNumber && node.getSourceLocation().getEndLine() >= lineNumber) || - (lineNumber <= 1 - && node instanceof BuildConfigNode) + (lineNumber <= 1) ); } catch (IOException ioe) { return false; diff --git a/ajde/src/org/aspectj/ajde/ui/BuildConfigNode.java b/ajde/src/org/aspectj/ajde/ui/BuildConfigNode.java index 94e92a87f..c80f49b4d 100644 --- a/ajde/src/org/aspectj/ajde/ui/BuildConfigNode.java +++ b/ajde/src/org/aspectj/ajde/ui/BuildConfigNode.java @@ -100,12 +100,11 @@ public class BuildConfigNode { * Comparison is string-name based only. */ public int compareTo(Object o) throws ClassCastException { - if (this == o) { - return 0; - } else { + if (o instanceof BuildConfigNode) { BuildConfigNode sn = (BuildConfigNode)o; return this.getName().compareTo(sn.getName()); } + return -1; } public String getName() { @@ -197,9 +196,15 @@ public class BuildConfigNode { return name; } - public boolean equals(Object o) { - return o.equals(name); - } +// public boolean equals(Object o) { +// return (o instanceof Kind? this==o : false); +//// return o.equals(name); +// } +// +// public int hashCode() { +// return ordinal; +//// return name.hashCode(); +// } public boolean isDeclareKind() { return name.startsWith("declare"); diff --git a/ajde/src/org/aspectj/ajde/ui/StructureSearchManager.java b/ajde/src/org/aspectj/ajde/ui/StructureSearchManager.java index 5ec11e6a4..143c7ae52 100644 --- a/ajde/src/org/aspectj/ajde/ui/StructureSearchManager.java +++ b/ajde/src/org/aspectj/ajde/ui/StructureSearchManager.java @@ -39,10 +39,10 @@ public class StructureSearchManager { List matches = new ArrayList(); IHierarchy model = AsmManager.getDefault().getHierarchy(); - if (model.equals(IHierarchy.NO_STRUCTURE)) { + if (model.getRoot().equals(IHierarchy.NO_STRUCTURE)) { return null; } else { - return findMatchesHelper((IProgramElement)model.getRoot(), pattern, kind, matches); + return findMatchesHelper(model.getRoot(), pattern, kind, matches); } } @@ -61,9 +61,9 @@ public class StructureSearchManager { if (node != null && node.getChildren() != null) { for (Iterator it = node.getChildren().iterator(); it.hasNext(); ) { IProgramElement nextNode = (IProgramElement)it.next(); - if (nextNode instanceof IProgramElement) { + if (nextNode!=null) { findMatchesHelper( - (IProgramElement)nextNode, + nextNode, pattern, kind, matches); diff --git a/ajde/src/org/aspectj/ajde/ui/StructureView.java b/ajde/src/org/aspectj/ajde/ui/StructureView.java index 6535dd2b1..edbae4698 100644 --- a/ajde/src/org/aspectj/ajde/ui/StructureView.java +++ b/ajde/src/org/aspectj/ajde/ui/StructureView.java @@ -57,7 +57,7 @@ public abstract class StructureView { */ public IStructureViewNode getActiveNode() { if (activeNode != null - && activeNode.getStructureNode() instanceof IProgramElement) { + && activeNode.getStructureNode()!=null) { return activeNode; } else { return null; diff --git a/ajde/src/org/aspectj/ajde/ui/StructureViewManager.java b/ajde/src/org/aspectj/ajde/ui/StructureViewManager.java index 1d06d9409..b36d32f6c 100644 --- a/ajde/src/org/aspectj/ajde/ui/StructureViewManager.java +++ b/ajde/src/org/aspectj/ajde/ui/StructureViewManager.java @@ -93,8 +93,8 @@ public class StructureViewManager { newFilePath, lineNumber); - if (currNode instanceof IProgramElement) { - navigationAction((IProgramElement)currNode, true); + if (currNode!=null) { + navigationAction(currNode, true); } } @@ -127,7 +127,7 @@ public class StructureViewManager { StructureView view = (StructureView)it.next(); if (!(view instanceof GlobalStructureView) || !recordHistory || defaultFileView == null) { if (node.getKind().equals(IProgramElement.Kind.CODE)) { - IProgramElement parentNode = (IProgramElement)node.getParent(); + IProgramElement parentNode = node.getParent(); if (parentNode != null) { IStructureViewNode currNode = view.findCorrespondingViewNode(parentNode); int lineOffset = node.getSourceLocation().getLine() - parentNode.getSourceLocation().getLine(); diff --git a/ajde/src/org/aspectj/ajde/ui/internal/TreeStructureViewBuilder.java b/ajde/src/org/aspectj/ajde/ui/internal/TreeStructureViewBuilder.java index 5b312fd25..af1a2477f 100644 --- a/ajde/src/org/aspectj/ajde/ui/internal/TreeStructureViewBuilder.java +++ b/ajde/src/org/aspectj/ajde/ui/internal/TreeStructureViewBuilder.java @@ -163,8 +163,8 @@ public class TreeStructureViewBuilder { } private boolean acceptNode(IProgramElement node, StructureViewProperties properties) { - if (node instanceof IProgramElement) { - IProgramElement pNode = (IProgramElement)node; + if (node!=null) { + IProgramElement pNode = node; if (!acceptGranularity(pNode.getKind(), properties.getGranularity())) { return false; } else if (pNode.getKind().isMember()) { @@ -180,11 +180,6 @@ public class TreeStructureViewBuilder { } } } -// } else if (node instanceof IRelationship) { -// IRelationship relation = (IRelationship)node; -// return properties.getRelations().contains(relation); - } else { - return true; } return true; } @@ -387,15 +382,12 @@ public class TreeStructureViewBuilder { IProgramElement sv1 = ((IStructureViewNode)o1).getStructureNode(); IProgramElement sv2 = ((IStructureViewNode)o2).getStructureNode(); - if (sv1 instanceof IProgramElement && sv2 instanceof IProgramElement) { + if (sv1!=null && sv2!=null) { - IProgramElement p1 = (IProgramElement)sv1; - IProgramElement p2 = (IProgramElement)sv2; + if (sv2.getKind() == IProgramElement.Kind.IMPORT_REFERENCE) return 1; + if (sv1.getKind() == IProgramElement.Kind.IMPORT_REFERENCE) return -1; - if (p2.getKind() == IProgramElement.Kind.IMPORT_REFERENCE) return 1; - if (p1.getKind() == IProgramElement.Kind.IMPORT_REFERENCE) return -1; - - return p1.getName().compareTo(p2.getName()); + return sv1.getName().compareTo(sv2.getName()); } else { return 0; } @@ -405,15 +397,13 @@ public class TreeStructureViewBuilder { private static final Comparator DECLARATIONAL_COMPARATOR = new Comparator() { public int compare(Object o1, Object o2) { IProgramElement sv1 = ((IStructureViewNode)o1).getStructureNode(); - IProgramElement sv2 = ((IStructureViewNode)o2).getStructureNode(); - if (sv1 instanceof IProgramElement && sv2 instanceof IProgramElement) { - IProgramElement p1 = (IProgramElement)sv1; - IProgramElement p2 = (IProgramElement)sv2; - if (p2.getKind() == IProgramElement.Kind.IMPORT_REFERENCE) return 1; - if (p1.getKind() == IProgramElement.Kind.IMPORT_REFERENCE) return -1; - if (p1.getSourceLocation() == null || p2.getSourceLocation() == null) { + IProgramElement sv2 = ((IStructureViewNode)o2).getStructureNode(); + if (sv1!=null && sv2!=null) { + if (sv2.getKind() == IProgramElement.Kind.IMPORT_REFERENCE) return 1; + if (sv1.getKind() == IProgramElement.Kind.IMPORT_REFERENCE) return -1; + if (sv1.getSourceLocation() == null || sv2.getSourceLocation() == null) { return 0; - } else if (p1.getSourceLocation().getLine() < p2.getSourceLocation().getLine()) { + } else if (sv1.getSourceLocation().getLine() < sv2.getSourceLocation().getLine()) { return -1; } else { return 1; diff --git a/ajde/src/org/aspectj/ajde/ui/internal/UserPreferencesStore.java b/ajde/src/org/aspectj/ajde/ui/internal/UserPreferencesStore.java index 7e791cc5c..b1120f0fb 100644 --- a/ajde/src/org/aspectj/ajde/ui/internal/UserPreferencesStore.java +++ b/ajde/src/org/aspectj/ajde/ui/internal/UserPreferencesStore.java @@ -34,7 +34,7 @@ import org.aspectj.util.LangUtil; public class UserPreferencesStore implements UserPreferencesAdapter { public static final String FILE_NAME = "/.ajbrowser"; - private final String VALUE_SEP = ";"; + private static final String VALUE_SEP = ";"; private Properties properties = new Properties(); private boolean persist = true; diff --git a/ajde/src/org/aspectj/ajde/ui/swing/BrowserViewPanel.java b/ajde/src/org/aspectj/ajde/ui/swing/BrowserViewPanel.java index c237cbca1..0b15049b6 100644 --- a/ajde/src/org/aspectj/ajde/ui/swing/BrowserViewPanel.java +++ b/ajde/src/org/aspectj/ajde/ui/swing/BrowserViewPanel.java @@ -107,7 +107,7 @@ public class BrowserViewPanel extends JPanel implements StructureViewRenderer { public void updateView(StructureView structureView) { if (structureView instanceof GlobalStructureView) { - treeManager.updateTree((GlobalStructureView)structureView); + treeManager.updateTree(structureView); } } diff --git a/ajde/src/org/aspectj/ajde/ui/swing/BrowserViewTreeListener.java b/ajde/src/org/aspectj/ajde/ui/swing/BrowserViewTreeListener.java index d7ea37076..8e88a38a4 100644 --- a/ajde/src/org/aspectj/ajde/ui/swing/BrowserViewTreeListener.java +++ b/ajde/src/org/aspectj/ajde/ui/swing/BrowserViewTreeListener.java @@ -61,7 +61,7 @@ class BrowserViewTreeListener implements TreeSelectionListener, MouseListener { SwingTreeViewNode treeNode = (SwingTreeViewNode)tree.getLastSelectedPathComponent(); if (treeNode != null && !e.isControlDown() && !e.isShiftDown() && e.getModifiers() != 4) { IProgramElement currNode = (IProgramElement)treeNode.getUserObject(); - if (currNode instanceof IProgramElement && !e.isControlDown() + if (currNode!=null && !e.isControlDown() && !e.isShiftDown() && e.getModifiers() != 4) { //AjdeUIManager.getDefault().getViewManager().showNodeInMasterView((ProgramElementNode)currNode); //if (AjdeUIManager.getDefault().getViewManager().isSplitViewMode()) { @@ -83,7 +83,7 @@ class BrowserViewTreeListener implements TreeSelectionListener, MouseListener { SwingTreeViewNode treeNode = (SwingTreeViewNode)tree.getLastSelectedPathComponent(); if (treeNode != null) { IProgramElement currNode = (IProgramElement)treeNode.getUserObject(); - if (currNode instanceof IProgramElement && !e.isControlDown() && !e.isShiftDown() + if (currNode!=null && !e.isControlDown() && !e.isShiftDown() && e.getModifiers() != 4) { //AjdeUIManager.getDefault().getViewManager().showNodeInMasterView(((LinkNode)currNode).getProgramElementNode()); //AjdeUIManager.getDefault().getViewManager().showNodeInSlaveView(((LinkNode)currNode).getProgramElementNode()); diff --git a/ajde/src/org/aspectj/ajde/ui/swing/CompilerMessagesCellRenderer.java b/ajde/src/org/aspectj/ajde/ui/swing/CompilerMessagesCellRenderer.java index 77de70d53..ea681475f 100644 --- a/ajde/src/org/aspectj/ajde/ui/swing/CompilerMessagesCellRenderer.java +++ b/ajde/src/org/aspectj/ajde/ui/swing/CompilerMessagesCellRenderer.java @@ -45,7 +45,7 @@ public class CompilerMessagesCellRenderer extends JLabel implements ListCellRend IMessage cm = (IMessage) value; label = cm.getMessage(); if (LangUtil.isEmpty(label)) { - label = cm.getMessage().toString(); + label = cm.getMessage(); } kind = cm.getKind(); Throwable thrown = cm.getThrown(); diff --git a/ajde/src/org/aspectj/ajde/ui/swing/OptionsFrame.java b/ajde/src/org/aspectj/ajde/ui/swing/OptionsFrame.java index f92b19d7f..130183676 100644 --- a/ajde/src/org/aspectj/ajde/ui/swing/OptionsFrame.java +++ b/ajde/src/org/aspectj/ajde/ui/swing/OptionsFrame.java @@ -142,20 +142,20 @@ public class OptionsFrame extends JFrame { setVisible(true); main_tabbedPane.setSelectedComponent(panel); } - - private void loadOptions() { - try { - Component[] components = main_tabbedPane.getComponents(); - for (int i = 0; i < components.length; i++) { - if (components[i] instanceof OptionsPanel) { - ((OptionsPanel)components[i]).loadOptions(); - } - } - } catch (IOException ioe) { - Message msg = new Message("Could not load options.",IMessage.ERROR,ioe,null); - Ajde.getDefault().getMessageHandler().handleMessage(msg); - } - } +// +// private void loadOptions() { +// try { +// Component[] components = main_tabbedPane.getComponents(); +// for (int i = 0; i < components.length; i++) { +// if (components[i] instanceof OptionsPanel) { +// ((OptionsPanel)components[i]).loadOptions(); +// } +// } +// } catch (IOException ioe) { +// Message msg = new Message("Could not load options.",IMessage.ERROR,ioe,null); +// Ajde.getDefault().getMessageHandler().handleMessage(msg); +// } +// } private void saveOptions() { try { diff --git a/ajde/src/org/aspectj/ajde/ui/swing/StructureTreeManager.java b/ajde/src/org/aspectj/ajde/ui/swing/StructureTreeManager.java index 7e1f8123b..7cde2b769 100644 --- a/ajde/src/org/aspectj/ajde/ui/swing/StructureTreeManager.java +++ b/ajde/src/org/aspectj/ajde/ui/swing/StructureTreeManager.java @@ -81,7 +81,7 @@ class StructureTreeManager { private void highlightNode(SwingTreeViewNode parent, IProgramElement node) { for (int i = 0; i < parent.getChildCount(); i++) { SwingTreeViewNode currNode = (SwingTreeViewNode)parent.getChildAt(i); - IProgramElement sNode = (IProgramElement)currNode.getStructureNode(); + IProgramElement sNode = currNode.getStructureNode(); if (sNode != null && sNode.equals(node) && currNode.getKind() != IStructureViewNode.Kind.LINK) { TreePath path = new TreePath(currNode.getPath()); structureTree.setSelectionPath(path); @@ -177,7 +177,7 @@ class StructureTreeManager { structureTree.expandPath(structureTree.getPathForRow(0)); } - private class StructureTreeModel extends DefaultTreeModel implements TreeModel { + private static class StructureTreeModel extends DefaultTreeModel { private static final long serialVersionUID = 1L; diff --git a/ajde/src/org/aspectj/ajde/ui/swing/StructureViewPanel.java b/ajde/src/org/aspectj/ajde/ui/swing/StructureViewPanel.java index 69eb0fd51..c1435051a 100644 --- a/ajde/src/org/aspectj/ajde/ui/swing/StructureViewPanel.java +++ b/ajde/src/org/aspectj/ajde/ui/swing/StructureViewPanel.java @@ -103,7 +103,7 @@ public class StructureViewPanel extends JPanel implements StructureViewRenderer public void setActiveNode(IStructureViewNode node, int lineOffset) { if (node == null) return; // if (!(node.getStructureNode() instanceof IProgramElement)) return; - IProgramElement pNode = (IProgramElement)node.getStructureNode(); + IProgramElement pNode = node.getStructureNode(); treeManager.highlightNode(pNode); if (pNode.getSourceLocation() != null) { Ajde.getDefault().getEditorAdapter().showSourceLine( @@ -117,8 +117,8 @@ public class StructureViewPanel extends JPanel implements StructureViewRenderer public void highlightActiveNode() { if (currentView.getActiveNode() == null) return; IProgramElement node = currentView.getActiveNode().getStructureNode(); - if (node instanceof IProgramElement) { - treeManager.highlightNode((IProgramElement)node); + if (node!=null) { + treeManager.highlightNode(node); } } diff --git a/ajde/src/org/aspectj/ajde/ui/swing/TreeViewBuildConfigEditor.java b/ajde/src/org/aspectj/ajde/ui/swing/TreeViewBuildConfigEditor.java index 64a69998c..3d332c865 100644 --- a/ajde/src/org/aspectj/ajde/ui/swing/TreeViewBuildConfigEditor.java +++ b/ajde/src/org/aspectj/ajde/ui/swing/TreeViewBuildConfigEditor.java @@ -90,7 +90,7 @@ public class TreeViewBuildConfigEditor extends JPanel implements BuildConfigEdit jLabel1.setText(" Build configuration: " + configFile); model = Ajde.getDefault().getBuildConfigManager().buildModel(configFile); - root = buildTree((BuildConfigNode)model.getRoot()); + root = buildTree(model.getRoot()); buildConfig_tree.setModel(new DefaultTreeModel(root)); buildConfig_tree.addMouseListener(new ConfigFileMouseAdapter(buildConfig_tree)); @@ -155,7 +155,7 @@ public class TreeViewBuildConfigEditor extends JPanel implements BuildConfigEdit jScrollPane.getViewport().add(buildConfig_tree, null); } - private class ConfigTreeNode extends DefaultMutableTreeNode { + private static class ConfigTreeNode extends DefaultMutableTreeNode { private static final long serialVersionUID = 1L; public JCheckBox checkBox = null; @@ -176,7 +176,7 @@ public class TreeViewBuildConfigEditor extends JPanel implements BuildConfigEdit } - private class ConfigFileMouseAdapter extends MouseAdapter { + private static class ConfigFileMouseAdapter extends MouseAdapter { private JTree tree = null; final JCheckBox checkBoxProto = new JCheckBox(); final int width = checkBoxProto.getPreferredSize().width; -- 2.39.5