Author: dgolovin
Date: 2007-12-19 19:12:22 -0500 (Wed, 19 Dec 2007)
New Revision: 5389
Modified:
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/XJob.java
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/engines/impl/XProcessStorage.java
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/filesystems/impl/FileSystemPeer.java
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/filesystems/impl/JarAccess.java
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/handlers/RemoveModelNatureHandler.java
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/options/SwitchPreference.java
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/util/EclipseResourceUtil.java
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/util/extension/ExtensionPointUtil.java
Log:
Cleanup the code:
1. new Long(value) replaced for Long.valueOf(value)
2. new String() removed
3. new Boolean(true/false) replaced to Boolean.TRUE/FALSE
4. Unused packages were removed from seam.plugins
5. Throwing of NullPointerException replaced to IllegalArgument Exception
6. catch Exception replaced to particular Exception types in several places
Modified:
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/XJob.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/XJob.java 2007-12-20
00:12:12 UTC (rev 5388)
+++
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/XJob.java 2007-12-20
00:12:22 UTC (rev 5389)
@@ -76,7 +76,6 @@
continue;
}
//TODO keep watching
- System.out.println(js[i].getName());
return js[i];
}
}
Modified:
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/engines/impl/XProcessStorage.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/engines/impl/XProcessStorage.java 2007-12-20
00:12:12 UTC (rev 5388)
+++
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/engines/impl/XProcessStorage.java 2007-12-20
00:12:22 UTC (rev 5389)
@@ -25,7 +25,7 @@
public void addInstance(String path, XProcess p) {
if(p == null || !p.isRunning()) return;
- getInstances(path).put(new Long(System.currentTimeMillis()), p);
+ getInstances(path).put(Long.valueOf(System.currentTimeMillis()), p);
}
private HashMap<Long,XProcess> getInstances(String path) {
@@ -56,7 +56,7 @@
public void stopInstance(String path, long time) {
HashMap<Long,XProcess> is = getRunningInstances(path);
if(is == null) return;
- Long l = new Long(time);
+ Long l = Long.valueOf(time);
XProcess p = is.get(l);
if(p == null) return;
p.stop();
Modified:
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/filesystems/impl/FileSystemPeer.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/filesystems/impl/FileSystemPeer.java 2007-12-20
00:12:12 UTC (rev 5388)
+++
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/filesystems/impl/FileSystemPeer.java 2007-12-20
00:12:22 UTC (rev 5389)
@@ -58,7 +58,7 @@
}
private Long toLastModified(File f) {
- return !f.exists() ? new Long(0) : new Long(f.lastModified());
+ return !f.exists() ? Long.valueOf(0) : Long.valueOf(f.lastModified());
}
}
Modified:
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/filesystems/impl/JarAccess.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/filesystems/impl/JarAccess.java 2007-12-20
00:12:12 UTC (rev 5388)
+++
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/filesystems/impl/JarAccess.java 2007-12-20
00:12:22 UTC (rev 5389)
@@ -107,7 +107,7 @@
ZipEntry entry = (ZipEntry)en.nextElement();
String name = entry.getName();
if(name != null && !name.endsWith("/") && entry.getSize()
> 0) {
- fileEntries.put(name, new Long(entry.getSize()));
+ fileEntries.put(name, Long.valueOf(entry.getSize()));
}
register(name);
} catch (Exception e) {
Modified:
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/handlers/RemoveModelNatureHandler.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/handlers/RemoveModelNatureHandler.java 2007-12-20
00:12:12 UTC (rev 5388)
+++
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/handlers/RemoveModelNatureHandler.java 2007-12-20
00:12:22 UTC (rev 5389)
@@ -64,7 +64,7 @@
pd.setProperty(ServiceDialog.DIALOG_MESSAGE, message);
String checkBoxMessage = "Remove Dynamic Web Project Capabilities";
pd.setProperty(ServiceDialog.CHECKBOX_MESSAGE, checkBoxMessage);
- pd.put(ServiceDialog.CHECKED, new Boolean(false));
+ pd.put(ServiceDialog.CHECKED, Boolean.FALSE);
if(!dialog.openConfirm(pd)) return;
Boolean b = (Boolean)pd.get(ServiceDialog.CHECKED);
unregisterWTP = b.booleanValue();
Modified:
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/options/SwitchPreference.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/options/SwitchPreference.java 2007-12-20
00:12:12 UTC (rev 5388)
+++
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/options/SwitchPreference.java 2007-12-20
00:12:22 UTC (rev 5389)
@@ -38,7 +38,7 @@
}
public String getValue() {
- if(switchPreference==null) throw new NullPointerException("switchPreference cannot
be null, call setSwitchPreferenceFirst.");
+ if(switchPreference==null) throw new IllegalStateException("switchPreference
cannot be null, call setSwitchPreferenceFirst.");
Preference preference = (Preference)preferencesMap.get(switchPreference.getValue());
if(preference==null) throw new IllegalStateException("Preference in't added
for switch value '" + switchPreference.getValue() + "'");
return preference.getValue();
Modified:
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/util/EclipseResourceUtil.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/util/EclipseResourceUtil.java 2007-12-20
00:12:12 UTC (rev 5388)
+++
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/util/EclipseResourceUtil.java 2007-12-20
00:12:22 UTC (rev 5389)
@@ -72,13 +72,8 @@
}
public static String getIconPath(XModelObject o) {
- try {
- String s = o.getMainIconName();
- return o.getModelEntity().getMetaModel().getIconList().getIconPath(s,
"default.unknown");
- } catch (Exception ex) {
- ModelPlugin.getPluginLog().logError(ex);
- return null;
- }
+ String s = o.getMainIconName();
+ return o.getModelEntity().getMetaModel().getIconList().getIconPath(s,
"default.unknown");
}
public static Image getImage(String path) {
@@ -125,13 +120,8 @@
public static XModelObject getObjectByPath(IProject p, String path) {
if(p == null) return null;
- try {
- IModelNature sp = getModelNature(p);
- return (sp == null) ? null : sp.getModel().getByPath(path);
- } catch (Exception e) {
- ModelPlugin.getPluginLog().logError(e);
- return null;
- }
+ IModelNature sp = getModelNature(p);
+ return (sp == null) ? null : sp.getModel().getByPath(path);
}
public static XModelObject findFileSystem(IResource resource, XModel model) {
@@ -201,7 +191,7 @@
if(p == null || !p.isOpen()) return false;
try {
if(p.hasNature(nature)) return true;
- } catch (Exception e) {
+ } catch (CoreException e) {
ModelPlugin.getPluginLog().logError(e);
}
return false;
@@ -216,7 +206,7 @@
IModelNature n = (IModelNature)p.getNature(natures[i]);
return n == null || n.getModel() == null ? null : n;
}
- } catch (Exception e) {
+ } catch (CoreException e) {
ModelPlugin.getPluginLog().logError(e);
}
}
@@ -227,7 +217,7 @@
if(p == null || !p.isOpen()) return null;
try {
if(p.hasNature(id)) return (IModelNature)p.getNature(id);
- } catch (Exception e) {
+ } catch (CoreException e) {
ModelPlugin.getPluginLog().logError(e);
}
return null;
@@ -247,23 +237,20 @@
if(resource == null || !resource.exists()) return null;
IProject project = resource.getProject();
if(project == null || !project.isOpen()) return null;
- try {
- IModelNature sp = getModelNature(project);
- if(sp != null) {
- XModelObject result = getObjectByResource(resource);
- if(result == null) {
- XModelObject fs = findFileSystem(resource.getProject(), sp.getModel());
- if(fs == null) {
- fs = addFileSystem(resource.getProject(), sp.getModel());
- if(fs != null) result = getObjectByResource(resource);
- }
+
+ IModelNature sp = getModelNature(project);
+ if(sp != null) {
+ XModelObject result = getObjectByResource(resource);
+ if(result == null) {
+ XModelObject fs = findFileSystem(resource.getProject(), sp.getModel());
+ if(fs == null) {
+ fs = addFileSystem(resource.getProject(), sp.getModel());
+ if(fs != null) result = getObjectByResource(resource);
}
- return result;
}
- } catch (Exception e) {
- ModelPlugin.getPluginLog().logError(e);
- return null;
+ return result;
}
+
XModel model = models.get(project);
if(model != null) {
validateJarSystem(model.getByPath("FileSystems"), resource);
@@ -311,7 +298,7 @@
IResource[] cs = null;
try {
cs = project.members();
- } catch (Exception e) {
+ } catch (CoreException e) {
ModelPlugin.getPluginLog().logError(e);
}
if(cs != null) for (int i = 0; i < cs.length; i++) {
@@ -412,7 +399,7 @@
if(project == null || !project.isOpen()) return null;
if(!project.hasNature(JavaCore.NATURE_ID)) return null;
return JavaCore.create(project);
- } catch (Exception e) {
+ } catch (CoreException e) {
ModelPlugin.getPluginLog().logError(e);
return null;
}
@@ -425,32 +412,17 @@
IPath p = javaProject.getOutputLocation();
IResource r = project.getWorkspace().getRoot().findMember(p);
return (r == null || r.getLocation() == null) ? null : r.getLocation().toString();
- } catch (Exception e) {
+ } catch (CoreException e) {
ModelPlugin.getPluginLog().logError(e);
return null;
}
}
-
- public static URLClassLoader getClassLoader(IProject project, ClassLoader parent) throws
Exception {
- if(!project.hasNature(JavaCore.NATURE_ID)) return null;
- List paths = getClassPath(project);
- ArrayList<URL> l = new ArrayList<URL>();
- for (int i = 0; i < paths.size(); i++) {
- try {
- l.add(new File(paths.get(i).toString()).toURL());
- } catch (Exception e) {
- //ignore - we do not care about malformed URLs in classpath here.
- }
- }
- URL[] urls = l.toArray(new URL[0]);
- return new URLClassLoader(urls, parent);
- }
-
/**
* Returns list of canonical paths to resources included in class path.
+ * @throws IOException
*/
- public static List<String> getClassPath(IProject project) throws Exception {
+ public static List<String> getClassPath(IProject project) throws CoreException,
IOException {
if(!project.hasNature(JavaCore.NATURE_ID)) return null;
ArrayList<String> l = new ArrayList<String>();
IJavaProject javaProject = JavaCore.create(project);
@@ -472,7 +444,7 @@
l.add(new java.io.File(s).getCanonicalPath());
}
}
- } catch (Exception e) {
+ } catch (IOException e) {
//ignore - we do not care about non-existent files here.
}
}
@@ -520,7 +492,7 @@
path = new Path(p.replace('.', '/') + ".java");
}
return javaProject.findElement(path);
- } catch (Exception ex) {
+ } catch (CoreException ex) {
ModelPlugin.getPluginLog().logError(ex);
}
return null;
@@ -530,22 +502,25 @@
if (className == null && className.length() == 0) return null;
IJavaProject javaProject = getJavaProject(project);
if(javaProject == null) return null;
+ IFile f = null;
try {
IType t = javaProject.findType(className);
if(t == null || t.isBinary()) return t;
if(t.getParent() instanceof ICompilationUnit) {
ICompilationUnit u = (ICompilationUnit)t.getParent();
- IFile f = (IFile)u.getCorrespondingResource();
+ f = (IFile)u.getCorrespondingResource();
IMarker[] ms = f.findMarkers(IJavaModelMarker.JAVA_MODEL_PROBLEM_MARKER, true,
IResource.DEPTH_ZERO);
for (int i = 0; i < ms.length; i++) {
if(ms[i].getAttribute(IMarker.SEVERITY, IMarker.SEVERITY_INFO) ==
IMarker.SEVERITY_ERROR) return null;
}
}
return t;
- } catch (Exception t) {
+ } catch (JavaModelException t) {
ModelPlugin.getPluginLog().logError("Error while obtaining type " +
className, t);
- return null;
+ } catch (CoreException t) {
+ ModelPlugin.getPluginLog().logError("Error occured while obtaining Java Problem
markers for " + f.getLocation() , t);
}
+ return null;
}
/**
@@ -581,7 +556,7 @@
String output = r.getLocation().toString();
String f = output + "/" + className.replace('.', '/') +
".class";
return new java.io.File(f).isFile();
- } catch (Exception t) {
+ } catch (JavaModelException t) {
ModelPlugin.getPluginLog().logError("Error checking class " + className,
t);
return false;
}
@@ -628,7 +603,7 @@
}
}
}
- } catch (Exception ex) {
+ } catch (JavaModelException ex) {
ModelPlugin.getPluginLog().logError(ex);
}
return null;
@@ -671,7 +646,7 @@
proj.setDescription(description, null);
}
- public static void openResource(IResource resource) throws Exception {
+ public static void openResource(IResource resource) {
XModelObject o = getObjectByResource(resource);
if(o == null) o = createObjectForResource(resource);
if(o != null) XActionInvoker.invoke("Open", o, null);
@@ -694,7 +669,7 @@
public static URL getInstallURL(Bundle bundle) {
try {
return bundle == null ? null : FileLocator.resolve(bundle.getEntry("/"));
- } catch (Exception e) {
+ } catch (IOException e) {
//ignore and try to execute it in the other way
return bundle.getEntry("/");
}
@@ -719,7 +694,7 @@
IResource[] ms = null;
try {
ms = projects[i].members(true);
- } catch (Exception e) {
+ } catch (CoreException e) {
//ignore - we do not care if project can give its members here.
}
if(ms != null) for (int j = 0; j < ms.length; j++) {
@@ -753,7 +728,7 @@
String relative = location.substring(l.length()).replace('\\',
'/');
return (relative.length() == 0) ? (IResource)c : c.getFolder(new Path(relative));
}
- } catch (Exception e) {
+ } catch (CoreException e) {
ModelPlugin.getPluginLog().logError(e);
}
continue;
@@ -795,31 +770,30 @@
ArrayList<IResource> l = new ArrayList<IResource>();
IClasspathEntry[] es = null;
+
try {
es = javaProject.getResolvedClasspath(true);
} catch (JavaModelException e) {
//ignore - if project cannot respond, it may not have resources of interest.
return new IProject[0];
}
+
if(es != null) for (int i = 0; i < es.length; i++) {
- try {
- if(es[i].getEntryKind() == IClasspathEntry.CPE_PROJECT) {
- IPath path = es[i].getPath();
- IProject p = (IProject)project.getWorkspace().getRoot().findMember(path);
- l.add(p);
- } else if(es[i].getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
- IPath path = es[i].getPath();
- IResource r = project.getWorkspace().getRoot().findMember(path);
- if(r != null && (r instanceof IContainer)) {
- l.add(r);
- } else if(r != null && !project.getFullPath().isPrefixOf(r.getFullPath()))
{
- l.add(r); //probably it is jar
- }
+ if(es[i].getEntryKind() == IClasspathEntry.CPE_PROJECT) {
+ IPath path = es[i].getPath();
+ IProject p = (IProject)project.getWorkspace().getRoot().findMember(path);
+ l.add(p);
+ } else if(es[i].getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
+ IPath path = es[i].getPath();
+ IResource r = project.getWorkspace().getRoot().findMember(path);
+ if(r != null && (r instanceof IContainer)) {
+ l.add(r);
+ } else if(r != null && !project.getFullPath().isPrefixOf(r.getFullPath())) {
+ l.add(r); //probably it is jar
}
- } catch (Exception e) {
- ModelPlugin.getPluginLog().logError(e);
}
}
+
return l.toArray(new IResource[0]);
}
Modified:
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/util/extension/ExtensionPointUtil.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/util/extension/ExtensionPointUtil.java 2007-12-20
00:12:12 UTC (rev 5388)
+++
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/util/extension/ExtensionPointUtil.java 2007-12-20
00:12:22 UTC (rev 5389)
@@ -22,10 +22,10 @@
public static Object findClassByElementId(IExtensionPoint point, String id) throws
Exception {
IConfigurationElement element = getElementById(point, id);
if(element == null)
- throw new NullPointerException("Configuration element with id=" + id +
" is not found");
+ throw new IllegalArgumentException("Configuration element with id=" + id +
" is not found");
String className = element.getAttribute("class");
if(className == null || className.length() == 0)
- throw new NullPointerException("Configuration element with id=" + id +
" does not define 'class' attribute");
+ throw new IllegalArgumentException("Configuration element with id=" + id +
" does not define 'class' attribute");
return element.createExecutableExtension("class");
}