public AarTypeSolver(File aarFile) throws IOException { JarFile jarFile = new JarFile(aarFile); ZipEntry classesJarEntry = jarFile.getEntry("classes.jar"); if (classesJarEntry == null) { throw new IllegalArgumentException(String.format("The given file (%s) is malformed: entry classes.jar was not found", aarFile.getAbsolutePath())); } delegate = new JarTypeSolver(jarFile.getInputStream(classesJarEntry)); }
@Override public SymbolReference<ResolvedReferenceTypeDeclaration> tryToSolveType(String name) { return delegate.tryToSolveType(name); } }
public static JarTypeSolver getJarTypeSolver(String pathToJar) throws IOException { if (instance == null) { instance = new JarTypeSolver(pathToJar); } else { instance.addPathToJar(pathToJar); } return instance; }
private void addPathToJar(InputStream jarInputStream) throws IOException { addPathToJar(dumpToTempFile(jarInputStream).getAbsolutePath()); }
@Test public void initial() throws IOException { String pathToJar = adaptPath("src/test/resources/javaparser-core-2.1.0.jar"); JarTypeSolver jarTypeSolver = new JarTypeSolver(pathToJar); assertEquals(true, jarTypeSolver.tryToSolveType("com.github.javaparser.SourcesHelper").isSolved()); assertEquals(true, jarTypeSolver.tryToSolveType("com.github.javaparser.Token").isSolved()); assertEquals(true, jarTypeSolver.tryToSolveType("com.github.javaparser.ASTParser.JJCalls").isSolved()); assertEquals(false, jarTypeSolver.tryToSolveType("com.github.javaparser.ASTParser.Foo").isSolved()); assertEquals(false, jarTypeSolver.tryToSolveType("com.github.javaparser.Foo").isSolved()); assertEquals(false, jarTypeSolver.tryToSolveType("Foo").isSolved()); }
public JarTypeSolver(String pathToJar) throws IOException { addPathToJar(pathToJar); }
@Override public SymbolReference<ResolvedReferenceTypeDeclaration> tryToSolveType(String name) { try { if (classpathElements.containsKey(name)) { return SymbolReference.solved( JavassistFactory.toTypeDeclaration(classpathElements.get(name).toCtClass(), getRoot())); } else { return SymbolReference.unsolved(ResolvedReferenceTypeDeclaration.class); } } catch (IOException e) { throw new RuntimeException(e); } }
private void addPathToJar(String pathToJar) throws IOException { try { classPool.appendClassPath(pathToJar); classPool.appendSystemPath(); } catch (NotFoundException e) { throw new RuntimeException(e); } JarFile jarFile = new JarFile(pathToJar); JarEntry entry; Enumeration<JarEntry> e = jarFile.entries(); while (e.hasMoreElements()) { entry = e.nextElement(); if (entry != null && !entry.isDirectory() && entry.getName().endsWith(".class")) { String name = entryPathToClassName(entry.getName()); classpathElements.put(name, new ClasspathElement(jarFile, entry)); } } }
@Override public TypeSolver getParent() { return delegate.getParent(); }
private void addPathToJar(InputStream jarInputStream) throws IOException { addPathToJar(dumpToTempFile(jarInputStream).getAbsolutePath()); }
public JarTypeSolver(InputStream jarInputStream) throws IOException { addPathToJar(jarInputStream); }
@Override public SymbolReference<ResolvedReferenceTypeDeclaration> tryToSolveType(String name) { try { if (classpathElements.containsKey(name)) { return SymbolReference.solved( JavassistFactory.toTypeDeclaration(classpathElements.get(name).toCtClass(), getRoot())); } else { return SymbolReference.unsolved(ResolvedReferenceTypeDeclaration.class); } } catch (IOException e) { throw new RuntimeException(e); } }
private void addPathToJar(String pathToJar) throws IOException { try { classPool.appendClassPath(pathToJar); classPool.appendSystemPath(); } catch (NotFoundException e) { throw new RuntimeException(e); } JarFile jarFile = new JarFile(pathToJar); JarEntry entry = null; Enumeration<JarEntry> e = jarFile.entries(); while (e.hasMoreElements()) { entry = e.nextElement(); if (entry != null && !entry.isDirectory() && entry.getName().endsWith(".class")) { String name = entryPathToClassName(entry.getName()); classpathElements.put(name, new ClasspathElement(jarFile, entry, name)); } } }
public AarTypeSolver(File aarFile) throws IOException { this.aarFile = aarFile; JarFile jarFile = new JarFile(aarFile); ZipEntry classesJarEntry = jarFile.getEntry("classes.jar"); if (classesJarEntry == null) { throw new IllegalArgumentException(String.format("The given file (%s) is malformed: entry classes.jar was not found", aarFile.getAbsolutePath())); } delegate = new JarTypeSolver(jarFile.getInputStream(classesJarEntry)); }
public static JarTypeSolver getJarTypeSolver(String pathToJar) throws IOException { if (instance == null) { instance = new JarTypeSolver(pathToJar); } else { instance.addPathToJar(pathToJar); } return instance; }
private void addPathToJar(InputStream jarInputStream) throws IOException { addPathToJar(dumpToTempFile(jarInputStream).getAbsolutePath()); }
@Override public SymbolReference<ResolvedReferenceTypeDeclaration> tryToSolveType(String name) { return delegate.tryToSolveType(name); } }
public JarTypeSolver(InputStream jarInputStream) throws IOException { addPathToJar(jarInputStream); }
@Override public SymbolReference<ResolvedReferenceTypeDeclaration> tryToSolveType(String name) { try { if (classpathElements.containsKey(name)) { return SymbolReference.solved( JavassistFactory.toTypeDeclaration(classpathElements.get(name).toCtClass(), getRoot())); } else { return SymbolReference.unsolved(ResolvedReferenceTypeDeclaration.class); } } catch (IOException e) { throw new RuntimeException(e); } }
private void addPathToJar(String pathToJar) throws IOException { try { classPool.appendClassPath(pathToJar); classPool.appendSystemPath(); } catch (NotFoundException e) { throw new RuntimeException(e); } JarFile jarFile = new JarFile(pathToJar); JarEntry entry = null; Enumeration<JarEntry> e = jarFile.entries(); while (e.hasMoreElements()) { entry = e.nextElement(); if (entry != null && !entry.isDirectory() && entry.getName().endsWith(".class")) { String name = entryPathToClassName(entry.getName()); classpathElements.put(name, new ClasspathElement(jarFile, entry, name)); } } }