Extracted code from computeClassPath() that finds the innermost class loader to a method so that it can be overridden (for languages that derive from Java and use additional ClassLoaderImpls). Added some type parms. computeClassPath() now skips FileModules, in case any "leak" into the module set. Added overridable method skipSourceFile() so that generated source that's in the source path can be skipped (e.g. Java source generated from X10 source files).

git-svn-id: https://wala.svn.sourceforge.net/svnroot/wala/trunk@2515 f5eafffb-2e1d-0410-98e4-8ec43c5233c4
This commit is contained in:
rmfuhrer 2008-01-31 15:54:05 +00:00
parent 601e90eed2
commit ddd7456fc0
1 changed files with 33 additions and 4 deletions

View File

@ -30,6 +30,7 @@ import polyglot.util.Position;
import com.ibm.wala.cast.java.translator.SourceModuleTranslator;
import com.ibm.wala.classLoader.DirectoryTreeModule;
import com.ibm.wala.classLoader.FileModule;
import com.ibm.wala.classLoader.JarFileModule;
import com.ibm.wala.classLoader.Module;
import com.ibm.wala.classLoader.SourceFileModule;
@ -56,12 +57,12 @@ public class PolyglotSourceModuleTranslator implements SourceModuleTranslator {
private void computeClassPath(AnalysisScope scope) {
StringBuffer buf= new StringBuffer();
ClassLoaderReference cl= scope.getApplicationLoader();
ClassLoaderReference cl= findInnermostClassLoader(scope);
while (cl != null) {
Set/* <Module> */modules= scope.getModules(cl);
Set<Module> modules= scope.getModules(cl);
for(Iterator iter= modules.iterator(); iter.hasNext();) {
for(Iterator<Module> iter= modules.iterator(); iter.hasNext(); ) {
Module m= (Module) iter.next();
if (buf.length() > 0)
@ -74,6 +75,8 @@ public class PolyglotSourceModuleTranslator implements SourceModuleTranslator {
DirectoryTreeModule directoryTreeModule= (DirectoryTreeModule) m;
buf.append(directoryTreeModule.getPath());
} else if (m instanceof FileModule) {
// do nothing
} else
Assertions.UNREACHABLE("Module entry is neither jar file nor directory");
}
@ -82,6 +85,20 @@ public class PolyglotSourceModuleTranslator implements SourceModuleTranslator {
fClassPath= buf.toString();
}
private ClassLoaderReference findInnermostClassLoader(AnalysisScope scope) {
Set<ClassLoaderReference> parentLoaders= new HashSet<ClassLoaderReference>();
for(ClassLoaderReference loader: scope.getLoaders()) {
parentLoaders.add(loader.getParent());
}
for (ClassLoaderReference child : scope.getLoaders()) {
if (!parentLoaders.contains(child)) {
return child;
}
}
throw new IllegalStateException("No innermost class loader???");
}
public void loadAllSources(Set modules) {
Options opts= fExtInfo.getOptions();
opts.assertions = true;
@ -101,7 +118,11 @@ public class PolyglotSourceModuleTranslator implements SourceModuleTranslator {
Assertions._assert(entry.isSourceFile());
String filePath= entry.getAbsolutePath();
if (skipSourceFile(entry)) {
continue;
}
String filePath= entry.getAbsolutePath();
try {
StreamSource srcStream= new StreamSource(entry.getInputStream(), filePath);
@ -114,4 +135,12 @@ public class PolyglotSourceModuleTranslator implements SourceModuleTranslator {
compiler.compile(streams);
// At this point, DOMO now "knows" about all the source-originated stuff
}
/**
* @return true if the given source file module should not be processed,
* e.g. because it is generated on behalf of some upstream source.
*/
protected boolean skipSourceFile(SourceFileModule entry) {
return false;
}
}