fixes for work with ECJ
This commit is contained in:
parent
6daceaa0ed
commit
73747cbb86
|
@ -1291,6 +1291,7 @@ public abstract class JDTJava2CAstTranslator<T extends Position> {
|
|||
else
|
||||
modifiers = ((FieldDeclaration) n.getParent()).getModifiers();
|
||||
boolean isFinal = (modifiers & Modifier.FINAL) != 0;
|
||||
assert n.resolveBinding() != null : n;
|
||||
ITypeBinding type = n.resolveBinding().getType();
|
||||
Expression init = n.getInitializer();
|
||||
CAstNode initNode;
|
||||
|
@ -1778,7 +1779,7 @@ public abstract class JDTJava2CAstTranslator<T extends Position> {
|
|||
if (n.resolveBinding() instanceof ITypeBinding)
|
||||
return makeNode(context, fFactory, null, CAstNode.EMPTY);
|
||||
|
||||
assert n.resolveBinding() instanceof IVariableBinding : "SimpleName's binding is not a variable or a type binding!";
|
||||
assert n.resolveBinding() instanceof IVariableBinding : "SimpleName's binding, " + n.resolveBinding() + ", is not a variable or a type binding!";
|
||||
|
||||
IVariableBinding binding = (IVariableBinding) n.resolveBinding();
|
||||
binding = binding.getVariableDeclaration(); // ignore weird generic stuff
|
||||
|
|
|
@ -37,6 +37,8 @@
|
|||
*/
|
||||
package com.ibm.wala.cast.java.translator.jdt.ejc;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.util.Hashtable;
|
||||
|
@ -61,6 +63,7 @@ import com.ibm.wala.cast.tree.CAstSourcePositionMap.Position;
|
|||
import com.ibm.wala.cast.tree.impl.RangePosition;
|
||||
import com.ibm.wala.classLoader.DirectoryTreeModule;
|
||||
import com.ibm.wala.classLoader.JarFileModule;
|
||||
import com.ibm.wala.classLoader.JarStreamModule;
|
||||
import com.ibm.wala.classLoader.Module;
|
||||
import com.ibm.wala.classLoader.ModuleEntry;
|
||||
import com.ibm.wala.classLoader.SourceFileModule;
|
||||
|
@ -69,6 +72,7 @@ import com.ibm.wala.types.ClassLoaderReference;
|
|||
import com.ibm.wala.util.collections.HashMapFactory;
|
||||
import com.ibm.wala.util.collections.Pair;
|
||||
import com.ibm.wala.util.debug.Assertions;
|
||||
import com.ibm.wala.util.io.TemporaryFile;
|
||||
|
||||
/**
|
||||
* A SourceModuleTranslator whose implementation of loadAllSources() uses the PolyglotFrontEnd pseudo-compiler to generate DOMO IR
|
||||
|
@ -128,8 +132,7 @@ public class ECJSourceModuleTranslator implements SourceModuleTranslator {
|
|||
private Pair<String[],String[]> computeClassPath(AnalysisScope scope) {
|
||||
List<String> sources = new LinkedList<String>();
|
||||
List<String> libs = new LinkedList<String>();
|
||||
|
||||
ClassLoaderReference cl = scope.getApplicationLoader();
|
||||
for (ClassLoaderReference cl : scope.getLoaders()) {
|
||||
|
||||
while (cl != null) {
|
||||
List<Module> modules = scope.getModules(cl);
|
||||
|
@ -141,15 +144,26 @@ public class ECJSourceModuleTranslator implements SourceModuleTranslator {
|
|||
JarFileModule jarFileModule = (JarFileModule) m;
|
||||
|
||||
libs.add(jarFileModule.getAbsolutePath());
|
||||
} else if (m instanceof JarStreamModule) {
|
||||
try {
|
||||
File F = File.createTempFile("tmp", "jar");
|
||||
F.deleteOnExit();
|
||||
TemporaryFile.streamToFile(F, ((JarStreamModule)m));
|
||||
libs.add(F.getAbsolutePath());
|
||||
} catch (IOException e) {
|
||||
assert false : e;
|
||||
}
|
||||
} else if (m instanceof DirectoryTreeModule) {
|
||||
DirectoryTreeModule directoryTreeModule = (DirectoryTreeModule) m;
|
||||
|
||||
sources.add(directoryTreeModule.getPath());
|
||||
} else
|
||||
Assertions.UNREACHABLE("Module entry is neither jar file nor directory");
|
||||
} else {
|
||||
//Assertions.UNREACHABLE("Module entry is neither jar file nor directory");
|
||||
}
|
||||
}
|
||||
cl = cl.getParent();
|
||||
}
|
||||
}
|
||||
|
||||
return Pair.make(sources.toArray(new String[ sources.size() ]), libs.toArray(new String[ libs.size() ]));
|
||||
}
|
||||
|
@ -174,7 +188,7 @@ public class ECJSourceModuleTranslator implements SourceModuleTranslator {
|
|||
String[] sourceFiles = sources.toArray(new String[ sources.size() ]);
|
||||
final ASTParser parser = ASTParser.newParser(AST.JLS8);
|
||||
parser.setResolveBindings(true);
|
||||
parser.setEnvironment(libs, null, null, false);
|
||||
parser.setEnvironment(libs, this.sources, null, false);
|
||||
Hashtable options = JavaCore.getOptions();
|
||||
options.put(JavaCore.COMPILER_SOURCE, "1.8");
|
||||
parser.setCompilerOptions(options);
|
||||
|
|
|
@ -450,7 +450,7 @@ public abstract class IRTests {
|
|||
return null;
|
||||
}
|
||||
|
||||
protected void populateScope(JavaSourceAnalysisEngine engine, Collection<String> sources, List<String> libs) {
|
||||
public static void populateScope(JavaSourceAnalysisEngine engine, Collection<String> sources, List<String> libs) {
|
||||
boolean foundLib = false;
|
||||
for (String lib : libs) {
|
||||
File libFile = new File(lib);
|
||||
|
|
|
@ -31,24 +31,18 @@ import com.ibm.wala.util.warnings.Warnings;
|
|||
* and adapted to work with an input stream.
|
||||
* @author Juergen Graf <juergen.graf@gmail.com>
|
||||
*/
|
||||
public class JarStreamModule implements Module {
|
||||
public class JarStreamModule extends JarInputStream implements Module {
|
||||
|
||||
private static final boolean DEBUG = false;
|
||||
|
||||
private final JarInputStream stream;
|
||||
|
||||
/**
|
||||
* For efficiency, we cache the byte[] holding each ZipEntry's contents; this will help avoid multiple unzipping TODO: use a soft
|
||||
* reference?
|
||||
*/
|
||||
private HashMap<String, byte[]> cache = null;
|
||||
|
||||
public JarStreamModule(JarInputStream stream) {
|
||||
if (stream == null) {
|
||||
throw new IllegalArgumentException("null stream");
|
||||
}
|
||||
|
||||
this.stream = stream;
|
||||
public JarStreamModule(JarInputStream stream) throws IOException {
|
||||
super(stream);
|
||||
}
|
||||
|
||||
public InputStream getInputStream(String name) {
|
||||
|
@ -63,7 +57,7 @@ public class JarStreamModule implements Module {
|
|||
}
|
||||
cache = HashMapFactory.make();
|
||||
try {
|
||||
for (ZipEntry z = stream.getNextEntry(); z != null; z = stream.getNextEntry()) {
|
||||
for (ZipEntry z = getNextEntry(); z != null; z = getNextEntry()) {
|
||||
final String name = z.getName();
|
||||
if (DEBUG) {
|
||||
System.err.println(("got entry: " + name));
|
||||
|
@ -71,10 +65,10 @@ public class JarStreamModule implements Module {
|
|||
if (FileSuffixes.isClassFile(name) || FileSuffixes.isSourceFile(name)) {
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
byte[] temp = new byte[1024];
|
||||
int n = stream.read(temp);
|
||||
int n = read(temp);
|
||||
while (n != -1) {
|
||||
out.write(temp, 0, n);
|
||||
n = stream.read(temp);
|
||||
n = read(temp);
|
||||
}
|
||||
byte[] bb = out.toByteArray();
|
||||
cache.put(name, bb);
|
||||
|
@ -242,14 +236,14 @@ public class JarStreamModule implements Module {
|
|||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Jar input stream " + stream.toString();
|
||||
return "Jar input stream " + super.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + (stream.hashCode());
|
||||
result = prime * result + (super.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -262,7 +256,7 @@ public class JarStreamModule implements Module {
|
|||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
JarStreamModule other = (JarStreamModule) obj;
|
||||
return stream.equals(other.stream);
|
||||
return super.equals(other);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue