From ddd7456fc04359277a12c0d952da8aa491e19630 Mon Sep 17 00:00:00 2001 From: rmfuhrer Date: Thu, 31 Jan 2008 15:54:05 +0000 Subject: [PATCH] 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 --- .../PolyglotSourceModuleTranslator.java | 37 +++++++++++++++++-- 1 file changed, 33 insertions(+), 4 deletions(-) diff --git a/com.ibm.wala.cast.java/src/com/ibm/wala/cast/java/translator/polyglot/PolyglotSourceModuleTranslator.java b/com.ibm.wala.cast.java/src/com/ibm/wala/cast/java/translator/polyglot/PolyglotSourceModuleTranslator.java index 502a2ba80..88e6b45b4 100644 --- a/com.ibm.wala.cast.java/src/com/ibm/wala/cast/java/translator/polyglot/PolyglotSourceModuleTranslator.java +++ b/com.ibm.wala.cast.java/src/com/ibm/wala/cast/java/translator/polyglot/PolyglotSourceModuleTranslator.java @@ -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/* */modules= scope.getModules(cl); + Set modules= scope.getModules(cl); - for(Iterator iter= modules.iterator(); iter.hasNext();) { + for(Iterator 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 parentLoaders= new HashSet(); + + 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; + } }