JavaId extends ConstructId { public URL getJarUrl() { ConstructId cid = this; if (cid instanceof JavaConstructorId || cid instanceof JavaMethodId || cid instanceof JavaClassInit) { cid = cid.getDefinitionContext(); } else if (cid instanceof JavaPackageId) return null; URL url = ClassPoolUpdater.getInstance().getJarResourcePath(cid); if (url == null || !url.toString().startsWith("jar:")) { try { url = Class.forName(this.getQualifiedName()) .getResource('/' + this.getQualifiedName().replace('.', '/') + ".class"); } catch (ClassNotFoundException e) { JavaId.log.error("Class [" + this.getQualifiedName() + "] not found: " + e.getMessage()); } catch (NoClassDefFoundError ex) { JavaId.log.error("No class definition found for [" + this.getQualifiedName() + "]"); } catch (UnsatisfiedLinkError e) { JavaId.log.error("UnsatisfiedLinkError for [" + this.getQualifiedName() + "]"); } } if (url != null && url.toString().startsWith("jar:")) { try { return JavaId.getJarUrl(url); } catch (MalformedURLException e) { JavaId.log.error("Cannot create URL from [" + url.toString() + "]: " + e.getMessage()); } } return null; } protected  JavaId(Type _t); Type getType(); String toString(); Set<String> getAnnotations(); void addAnnotation(String _a); boolean hasAnnotation(String _a); abstract JavaPackageId getJavaPackageId(); abstract ConstructId getDefinitionContext(); ConstructType getSharedType(); final String toJSON(); @Override JsonObject toGSON(); @Override final int hashCode(); @Override final boolean equals(Object obj); static String typeToString(Type _t); static Type typeFromString(String _t); static org.eclipse.steady.shared.enums.ConstructType toSharedType(JavaId.Type _core_type); static org.eclipse.steady.ConstructId toCoreType(
      org.eclipse.steady.shared.json.model.ConstructId _cid); static Set<org.eclipse.steady.ConstructId> toCoreType(
      Collection<org.eclipse.steady.shared.json.model.ConstructId> _cids); static JavaClassId getClassId(@NotNull Class _c); static JavaEnumId parseEnumQName(@NotNull String _s); static JavaClassId parseClassQName(@NotNull String _s); static JavaMethodId parseMethodQName(String _s); static JavaMethodId parseMethodQName(JavaId.Type _ctx_type, String _s); static JavaConstructorId parseConstructorQName(String _s); static JavaConstructorId parseConstructorQName(
      JavaId.Type _ctx_type, String _s, String _param_to_skip); static JavaClassInit parseClassInitQName(String _s); static String removePackageContext(String _qname); static Set<ConstructId> filter(Set<ConstructId> _set, String[] _filter); static Set<ConstructId> filter(Set<ConstructId> _set, String _filter); static Set<ConstructId> filter(Set<ConstructId> _set, JavaId.Type[] _filter); static Set<ConstructId> filterWithContext(Set<ConstructId> _set, JavaId _context); URL getJarUrl(); static final URL getJarUrl(URL _url); JavaId getCompilationUnit(); static JavaId getCompilationUnit(JavaId _jid); static JavaId getJavaId(String _type, String _qname);  }
@Test public void testGetJarUrl() { try { URL u = Class.forName("org.junit.Assert") .getResource( '/' + "org.junit.Assert".replace('.', '/') + ".class"); URL uj = JavaId.getJarUrl(u); assertTrue( uj.toString().matches("^file:/.*/\\.m2/repository/junit/junit/.*/junit-.*\\.jar$")); u = new URL( "jar", "", "file:/org.eclipse.equinox.p2.jarprocessor_1.0.300.v20130327-2119.jar"); uj = JavaId.getJarUrl(u); assertEquals( "file:/org.eclipse.equinox.p2.jarprocessor_1.0.300.v20130327-2119.jar", uj.toString()); u = new URL( "jar", "", "file:/org.eclipse.equinox.p2.jarprocessor_1.0.300.v20130327-2119.jar!bar.class"); uj = JavaId.getJarUrl(u); assertEquals( "file:/org.eclipse.equinox.p2.jarprocessor_1.0.300.v20130327-2119.jar", uj.toString()); } catch (Exception e) { e.printStackTrace(); assertTrue(false); } }