2007-02-02 17:22:28 +00:00
|
|
|
/******************************************************************************
|
|
|
|
* Copyright (c) 2002 - 2006 IBM Corporation.
|
|
|
|
* All rights reserved. This program and the accompanying materials
|
|
|
|
* are made available under the terms of the Eclipse Public License v1.0
|
|
|
|
* which accompanies this distribution, and is available at
|
|
|
|
* http://www.eclipse.org/legal/epl-v10.html
|
|
|
|
*
|
|
|
|
* Contributors:
|
|
|
|
* IBM Corporation - initial API and implementation
|
|
|
|
*****************************************************************************/
|
|
|
|
/*
|
|
|
|
* Created on Oct 3, 2005
|
|
|
|
*/
|
|
|
|
package com.ibm.wala.cast.java.test;
|
|
|
|
|
|
|
|
import java.io.File;
|
|
|
|
import java.io.IOException;
|
2007-02-08 19:06:52 +00:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Collection;
|
|
|
|
import java.util.Collections;
|
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.HashSet;
|
|
|
|
import java.util.Iterator;
|
|
|
|
import java.util.LinkedList;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Map;
|
|
|
|
import java.util.Set;
|
2007-02-02 17:22:28 +00:00
|
|
|
import java.util.jar.JarFile;
|
|
|
|
|
2007-02-08 19:06:52 +00:00
|
|
|
import junit.framework.Assert;
|
|
|
|
|
2007-04-18 15:51:08 +00:00
|
|
|
import com.ibm.wala.cast.java.client.JavaSourceAnalysisEngine;
|
2007-02-02 17:22:28 +00:00
|
|
|
import com.ibm.wala.cast.java.ipa.callgraph.JavaSourceAnalysisScope;
|
2007-04-17 14:04:50 +00:00
|
|
|
import com.ibm.wala.classLoader.IClass;
|
|
|
|
import com.ibm.wala.classLoader.IClassLoader;
|
|
|
|
import com.ibm.wala.classLoader.IMethod;
|
|
|
|
import com.ibm.wala.classLoader.JarFileModule;
|
|
|
|
import com.ibm.wala.classLoader.SourceDirectoryTreeModule;
|
|
|
|
import com.ibm.wala.classLoader.SourceFileModule;
|
2007-02-02 17:22:28 +00:00
|
|
|
import com.ibm.wala.core.tests.util.WalaTestCase;
|
|
|
|
import com.ibm.wala.ipa.callgraph.CGNode;
|
|
|
|
import com.ibm.wala.ipa.callgraph.CallGraph;
|
|
|
|
import com.ibm.wala.ipa.cha.ClassHierarchy;
|
2007-03-22 15:48:58 +00:00
|
|
|
import com.ibm.wala.shrikeCT.InvalidClassFileException;
|
2007-02-08 19:06:52 +00:00
|
|
|
import com.ibm.wala.ssa.IR;
|
|
|
|
import com.ibm.wala.ssa.SSAInstruction;
|
2007-02-02 17:22:28 +00:00
|
|
|
import com.ibm.wala.types.ClassLoaderReference;
|
|
|
|
import com.ibm.wala.types.MethodReference;
|
|
|
|
import com.ibm.wala.types.TypeName;
|
|
|
|
import com.ibm.wala.types.TypeReference;
|
|
|
|
import com.ibm.wala.util.Atom;
|
2007-04-17 14:04:50 +00:00
|
|
|
import com.ibm.wala.util.collections.HashSetFactory;
|
2007-02-08 19:06:52 +00:00
|
|
|
import com.ibm.wala.util.collections.MapUtil;
|
|
|
|
import com.ibm.wala.util.debug.Assertions;
|
|
|
|
import com.ibm.wala.util.debug.Trace;
|
2007-02-02 17:22:28 +00:00
|
|
|
import com.ibm.wala.util.warnings.WarningSet;
|
|
|
|
|
|
|
|
public abstract class IRTests extends WalaTestCase {
|
2007-02-09 15:33:22 +00:00
|
|
|
public IRTests(String name) {
|
|
|
|
super(name);
|
|
|
|
}
|
2007-02-02 17:22:28 +00:00
|
|
|
|
2007-02-09 15:33:22 +00:00
|
|
|
protected static String javaHomePath = System.getProperty("java.home");
|
2007-02-02 17:22:28 +00:00
|
|
|
|
2007-02-09 15:33:22 +00:00
|
|
|
protected static String testSrcPath = "." + File.separator + "testSrc";
|
2007-02-02 17:22:28 +00:00
|
|
|
|
2007-03-12 16:09:57 +00:00
|
|
|
protected static List<String> rtJar;
|
2007-02-02 17:22:28 +00:00
|
|
|
|
2007-02-09 15:33:22 +00:00
|
|
|
static {
|
|
|
|
rtJar = new LinkedList<String>();
|
|
|
|
rtJar.add(javaHomePath + File.separator + "lib" + File.separator + "rt.jar");
|
|
|
|
rtJar.add(javaHomePath + File.separator + "lib" + File.separator + "core.jar");
|
2007-03-12 02:41:23 +00:00
|
|
|
rtJar.add(javaHomePath + File.separator + "lib" + File.separator + "vm.jar");
|
2007-02-09 15:33:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
protected static class EdgeAssertions {
|
|
|
|
public final String srcDescriptor;
|
2007-02-02 17:22:28 +00:00
|
|
|
|
2007-03-12 16:09:57 +00:00
|
|
|
public final List/* <String> */<String> tgtDescriptors = new ArrayList<String>();
|
2007-02-09 15:33:22 +00:00
|
|
|
|
|
|
|
public EdgeAssertions(String srcDescriptor) {
|
|
|
|
this.srcDescriptor = srcDescriptor;
|
2007-02-02 17:22:28 +00:00
|
|
|
}
|
|
|
|
|
2007-02-09 15:33:22 +00:00
|
|
|
public static EdgeAssertions make(String srcDescriptor, String tgtDescriptor) {
|
|
|
|
EdgeAssertions ea = new EdgeAssertions(srcDescriptor);
|
|
|
|
ea.tgtDescriptors.add(tgtDescriptor);
|
|
|
|
return ea;
|
2007-02-02 17:22:28 +00:00
|
|
|
}
|
|
|
|
|
2007-02-09 15:33:22 +00:00
|
|
|
public static EdgeAssertions make(String srcDescriptor, String tgtDescriptor1, String tgtDescriptor2) {
|
|
|
|
EdgeAssertions ea = new EdgeAssertions(srcDescriptor);
|
|
|
|
ea.tgtDescriptors.add(tgtDescriptor1);
|
|
|
|
ea.tgtDescriptors.add(tgtDescriptor2);
|
|
|
|
return ea;
|
|
|
|
}
|
2007-02-02 17:22:28 +00:00
|
|
|
|
2007-02-09 15:33:22 +00:00
|
|
|
public static EdgeAssertions make(String srcDescriptor, String tgtDescriptor1, String tgtDescriptor2, String tgtDescriptor3) {
|
|
|
|
EdgeAssertions ea = new EdgeAssertions(srcDescriptor);
|
|
|
|
ea.tgtDescriptors.add(tgtDescriptor1);
|
|
|
|
ea.tgtDescriptors.add(tgtDescriptor2);
|
|
|
|
ea.tgtDescriptors.add(tgtDescriptor3);
|
|
|
|
return ea;
|
2007-02-02 17:22:28 +00:00
|
|
|
}
|
|
|
|
|
2007-02-09 15:33:22 +00:00
|
|
|
public static EdgeAssertions make(String srcDescriptor, String tgtDescriptor1, String tgtDescriptor2, String tgtDescriptor3,
|
|
|
|
String tgtDescriptor4) {
|
|
|
|
EdgeAssertions ea = new EdgeAssertions(srcDescriptor);
|
|
|
|
ea.tgtDescriptors.add(tgtDescriptor1);
|
|
|
|
ea.tgtDescriptors.add(tgtDescriptor2);
|
|
|
|
ea.tgtDescriptors.add(tgtDescriptor3);
|
|
|
|
ea.tgtDescriptors.add(tgtDescriptor4);
|
|
|
|
return ea;
|
|
|
|
}
|
|
|
|
}
|
2007-02-02 17:22:28 +00:00
|
|
|
|
2007-02-09 15:33:22 +00:00
|
|
|
protected static class GraphAssertions {
|
2007-03-12 16:09:57 +00:00
|
|
|
public final Set/* <EdgeAssertions> */<EdgeAssertions> nodeAssertions = new HashSet<EdgeAssertions>();
|
2007-02-02 17:22:28 +00:00
|
|
|
|
2007-02-09 15:33:22 +00:00
|
|
|
public GraphAssertions() {
|
|
|
|
}
|
2007-02-02 17:22:28 +00:00
|
|
|
|
2007-02-09 15:33:22 +00:00
|
|
|
public GraphAssertions(EdgeAssertions ea1) {
|
|
|
|
nodeAssertions.add(ea1);
|
2007-02-02 17:22:28 +00:00
|
|
|
}
|
|
|
|
|
2007-02-09 15:33:22 +00:00
|
|
|
public GraphAssertions(EdgeAssertions ea1, EdgeAssertions ea2) {
|
|
|
|
nodeAssertions.add(ea1);
|
|
|
|
nodeAssertions.add(ea2);
|
|
|
|
}
|
2007-02-02 17:22:28 +00:00
|
|
|
|
2007-02-09 15:33:22 +00:00
|
|
|
public GraphAssertions(EdgeAssertions ea1, EdgeAssertions ea2, EdgeAssertions ea3) {
|
|
|
|
nodeAssertions.add(ea1);
|
|
|
|
nodeAssertions.add(ea2);
|
|
|
|
nodeAssertions.add(ea3);
|
|
|
|
}
|
2007-02-02 17:22:28 +00:00
|
|
|
|
2007-02-09 15:33:22 +00:00
|
|
|
public GraphAssertions(EdgeAssertions ea1, EdgeAssertions ea2, EdgeAssertions ea3, EdgeAssertions ea4) {
|
|
|
|
nodeAssertions.add(ea1);
|
|
|
|
nodeAssertions.add(ea2);
|
|
|
|
nodeAssertions.add(ea3);
|
|
|
|
nodeAssertions.add(ea4);
|
2007-02-02 17:22:28 +00:00
|
|
|
}
|
2007-02-09 15:33:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
protected static class SourceMapAssertion {
|
|
|
|
private final String variableName;
|
|
|
|
|
|
|
|
private final int definingLineNumber;
|
2007-02-02 17:22:28 +00:00
|
|
|
|
2007-02-09 15:33:22 +00:00
|
|
|
protected SourceMapAssertion(String variableName, int definingLineNumber) {
|
|
|
|
this.variableName = variableName;
|
|
|
|
this.definingLineNumber = definingLineNumber;
|
2007-02-02 17:22:28 +00:00
|
|
|
}
|
|
|
|
|
2007-02-09 15:33:22 +00:00
|
|
|
boolean check(IMethod m, IR ir) {
|
|
|
|
Trace.println("check for " + variableName + " defined at " + definingLineNumber);
|
|
|
|
SSAInstruction[] insts = ir.getInstructions();
|
|
|
|
for (int i = 0; i < insts.length; i++) {
|
|
|
|
if (insts[i] != null) {
|
2007-03-22 15:48:58 +00:00
|
|
|
int ln = -1;
|
|
|
|
try {
|
|
|
|
ln = m.getLineNumber(i);
|
|
|
|
} catch (InvalidClassFileException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
Assertions.UNREACHABLE();
|
|
|
|
}
|
2007-02-09 15:33:22 +00:00
|
|
|
if (ln == definingLineNumber) {
|
|
|
|
Trace.println(" found " + insts[i] + " at " + ln);
|
|
|
|
for (int j = 0; j < insts[i].getNumberOfDefs(); j++) {
|
|
|
|
int def = insts[i].getDef(j);
|
|
|
|
Trace.println(" looking at def " + j + ": " + def);
|
|
|
|
String[] names = ir.getLocalNames(i, def);
|
|
|
|
if (names != null) {
|
|
|
|
for (int n = 0; n < names.length; n++) {
|
|
|
|
Trace.println(" looking at name " + names[n]);
|
|
|
|
if (names[n].equals(variableName)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2007-02-02 17:22:28 +00:00
|
|
|
}
|
2007-02-09 15:33:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
protected static class SourceMapAssertions {
|
2007-02-02 17:22:28 +00:00
|
|
|
|
2007-02-09 15:33:22 +00:00
|
|
|
private final Map<String, Set<SourceMapAssertion>> methodAssertions = new HashMap<String, Set<SourceMapAssertion>>();
|
|
|
|
|
|
|
|
protected void addAssertion(String method, SourceMapAssertion a) {
|
|
|
|
Set<SourceMapAssertion> x = MapUtil.findOrCreateSet(methodAssertions, method);
|
|
|
|
x.add(a);
|
2007-02-02 17:22:28 +00:00
|
|
|
}
|
|
|
|
|
2007-02-09 15:33:22 +00:00
|
|
|
void check(CallGraph CG) {
|
|
|
|
WarningSet ws = new WarningSet();
|
|
|
|
for (Iterator ms = methodAssertions.entrySet().iterator(); ms.hasNext();) {
|
|
|
|
Map.Entry entry = (Map.Entry) ms.next();
|
|
|
|
|
|
|
|
Set s = (Set) entry.getValue();
|
|
|
|
|
|
|
|
String method = (String) entry.getKey();
|
|
|
|
MethodReference mref = descriptorToMethodRef(method, CG.getClassHierarchy());
|
|
|
|
|
|
|
|
for (Iterator ns = CG.getNodes(mref).iterator(); ns.hasNext();) {
|
|
|
|
CGNode n = (CGNode) ns.next();
|
|
|
|
for (Iterator as = s.iterator(); as.hasNext();) {
|
|
|
|
SourceMapAssertion a = (SourceMapAssertion) as.next();
|
|
|
|
Assert.assertTrue("failed for " + a.variableName + " in " + n, a
|
|
|
|
.check(n.getMethod(), CG.getInterpreter(n).getIR(n, ws)));
|
|
|
|
}
|
|
|
|
}
|
2007-02-02 17:22:28 +00:00
|
|
|
}
|
|
|
|
}
|
2007-02-09 15:33:22 +00:00
|
|
|
}
|
2007-02-02 17:22:28 +00:00
|
|
|
|
2007-02-09 15:33:22 +00:00
|
|
|
protected abstract String singleInputForTest();
|
2007-02-02 17:22:28 +00:00
|
|
|
|
2007-02-09 15:33:22 +00:00
|
|
|
protected abstract String singlePkgInputForTest(String pkgName);
|
|
|
|
|
|
|
|
protected Collection singleTestSrc() {
|
|
|
|
return Collections.singletonList(testSrcPath + File.separator + singleInputForTest());
|
|
|
|
}
|
|
|
|
|
|
|
|
protected Collection singlePkgTestSrc(String pkgName) {
|
|
|
|
return Collections.singletonList(testSrcPath + File.separator + singlePkgInputForTest(pkgName));
|
|
|
|
}
|
|
|
|
|
|
|
|
protected String[] simpleTestEntryPoint() {
|
|
|
|
return new String[] { "L" + getName().substring(4) };
|
|
|
|
}
|
|
|
|
|
|
|
|
protected String[] simplePkgTestEntryPoint(String pkgName) {
|
|
|
|
return new String[] { "L" + pkgName + "/" + getName().substring(4) };
|
|
|
|
}
|
|
|
|
|
2007-04-18 15:51:08 +00:00
|
|
|
protected abstract JavaSourceAnalysisEngine getAnalysisEngine(String[] mainClassDescriptors);
|
2007-02-09 15:33:22 +00:00
|
|
|
|
2007-03-12 16:09:57 +00:00
|
|
|
public void runTest(Collection/* <String> */sources, List/* <String> */libs, String[] mainClassDescriptors, GraphAssertions ga,
|
|
|
|
SourceMapAssertions sa, boolean assertReachable) {
|
2007-02-09 15:33:22 +00:00
|
|
|
try {
|
2007-04-18 15:51:08 +00:00
|
|
|
JavaSourceAnalysisEngine engine = getAnalysisEngine(mainClassDescriptors);
|
2007-02-09 15:33:22 +00:00
|
|
|
|
|
|
|
populateScope(engine, sources, libs);
|
|
|
|
|
|
|
|
CallGraph callGraph = engine.buildDefaultCallGraph();
|
2007-02-09 18:20:17 +00:00
|
|
|
Trace.println(callGraph.toString());
|
2007-02-09 15:33:22 +00:00
|
|
|
|
|
|
|
// If we've gotten this far, IR has been produced.
|
2007-02-09 18:20:17 +00:00
|
|
|
dumpIR(callGraph, assertReachable);
|
2007-02-09 15:33:22 +00:00
|
|
|
|
|
|
|
// Now check any assertions as to source mapping
|
|
|
|
if (sa != null) {
|
|
|
|
sa.check(callGraph);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Now check any assertions as to call-graph shape.
|
|
|
|
checkCallGraphShape(callGraph, ga);
|
|
|
|
} catch (IOException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-12 16:09:57 +00:00
|
|
|
private static void dumpIR(CallGraph cg, boolean assertReachable) throws IOException {
|
2007-04-17 14:04:50 +00:00
|
|
|
Set<IMethod> unreachable = HashSetFactory.make();
|
2007-02-09 15:33:22 +00:00
|
|
|
WarningSet warnings = new WarningSet();
|
|
|
|
ClassHierarchy cha = cg.getClassHierarchy();
|
|
|
|
IClassLoader sourceLoader = cha.getLoader(JavaSourceAnalysisScope.SOURCE_REF);
|
|
|
|
for (Iterator iter = sourceLoader.iterateAllClasses(); iter.hasNext();) {
|
|
|
|
IClass clazz = (IClass) iter.next();
|
|
|
|
|
2007-02-09 18:20:17 +00:00
|
|
|
Trace.println(clazz);
|
2007-02-09 15:33:22 +00:00
|
|
|
if (clazz.isInterface())
|
|
|
|
continue;
|
|
|
|
|
|
|
|
for (Iterator iterator = clazz.getDeclaredMethods().iterator(); iterator.hasNext();) {
|
|
|
|
IMethod m = (IMethod) iterator.next();
|
|
|
|
if (m.isAbstract())
|
2007-02-09 18:20:17 +00:00
|
|
|
Trace.println(m);
|
2007-02-09 15:33:22 +00:00
|
|
|
else {
|
|
|
|
Iterator nodeIter = cg.getNodes(m.getReference()).iterator();
|
|
|
|
if (!nodeIter.hasNext()) {
|
2007-04-17 14:04:50 +00:00
|
|
|
Trace.println("Method " + m.getReference() + " not reachable?");
|
|
|
|
unreachable.add(m);
|
2007-02-09 15:33:22 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
CGNode node = (CGNode) nodeIter.next();
|
2007-02-09 18:20:17 +00:00
|
|
|
Trace.println(cg.getInterpreter(node).getIR(node, warnings));
|
2007-02-09 15:33:22 +00:00
|
|
|
}
|
|
|
|
}
|
2007-02-02 17:22:28 +00:00
|
|
|
}
|
2007-04-04 13:04:29 +00:00
|
|
|
|
|
|
|
if (assertReachable) {
|
|
|
|
Assert.assertTrue(unreachable.toString(), unreachable.isEmpty());
|
|
|
|
}
|
2007-02-09 15:33:22 +00:00
|
|
|
}
|
2007-02-02 17:22:28 +00:00
|
|
|
|
2007-02-09 15:33:22 +00:00
|
|
|
private static void checkCallGraphShape(CallGraph callGraph, GraphAssertions ga) throws IOException {
|
|
|
|
for (Iterator<EdgeAssertions> nodeIter = ga.nodeAssertions.iterator(); nodeIter.hasNext();) {
|
|
|
|
EdgeAssertions ea = nodeIter.next();
|
2007-02-02 17:22:28 +00:00
|
|
|
|
2007-02-09 15:33:22 +00:00
|
|
|
MethodReference srcMethod = descriptorToMethodRef(ea.srcDescriptor, callGraph.getClassHierarchy());
|
|
|
|
Set/* <CGNode> */srcNodes = callGraph.getNodes(srcMethod);
|
2007-02-02 17:22:28 +00:00
|
|
|
|
2007-02-09 15:33:22 +00:00
|
|
|
if (srcNodes.size() == 0) {
|
2007-02-09 18:20:17 +00:00
|
|
|
Trace.println("Unreachable/non-existent method: " + srcMethod);
|
2007-02-09 15:33:22 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (srcNodes.size() > 1) {
|
2007-02-09 18:20:17 +00:00
|
|
|
Trace.println("Context-sensitive call graph?");
|
2007-02-09 15:33:22 +00:00
|
|
|
}
|
2007-02-02 17:22:28 +00:00
|
|
|
|
2007-02-09 15:33:22 +00:00
|
|
|
// Assume only one node for src method
|
|
|
|
CGNode srcNode = (CGNode) srcNodes.iterator().next();
|
|
|
|
|
|
|
|
for (Iterator<String> edgeIter = ea.tgtDescriptors.iterator(); edgeIter.hasNext();) {
|
|
|
|
String target = edgeIter.next();
|
|
|
|
MethodReference tgtMethod = descriptorToMethodRef(target, callGraph.getClassHierarchy());
|
|
|
|
// Assume only one node for target method
|
|
|
|
Set tgtNodes = callGraph.getNodes(tgtMethod);
|
|
|
|
if (tgtNodes.size() == 0) {
|
2007-02-09 18:20:17 +00:00
|
|
|
Trace.println("Unreachable/non-existent method: " + tgtMethod);
|
2007-02-09 15:33:22 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
CGNode tgtNode = (CGNode) tgtNodes.iterator().next();
|
|
|
|
|
|
|
|
boolean found = false;
|
|
|
|
for (Iterator succIter = callGraph.getSuccNodes(srcNode); succIter.hasNext();) {
|
|
|
|
CGNode succ = (CGNode) succIter.next();
|
|
|
|
|
|
|
|
if (tgtNode == succ) {
|
|
|
|
found = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!found)
|
2007-02-09 18:20:17 +00:00
|
|
|
Trace.println("Missing edge: " + srcMethod + " -> " + tgtMethod);
|
2007-02-09 15:33:22 +00:00
|
|
|
}
|
2007-02-02 17:22:28 +00:00
|
|
|
}
|
2007-02-09 15:33:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private static MethodReference descriptorToMethodRef(String descrip, ClassHierarchy cha) {
|
|
|
|
String srcDescriptor = descrip; // ldr#type#methName#methSig
|
|
|
|
String[] ldrTypeMeth = srcDescriptor.split("\\#");
|
|
|
|
|
|
|
|
String loaderName = ldrTypeMeth[0];
|
|
|
|
String typeStr = ldrTypeMeth[1];
|
|
|
|
String methName = ldrTypeMeth[2];
|
|
|
|
String methSig = ldrTypeMeth[3];
|
|
|
|
|
|
|
|
ClassLoaderReference clr = findLoader(loaderName, cha);
|
|
|
|
TypeName typeName = TypeName.string2TypeName("L" + typeStr);
|
|
|
|
TypeReference typeRef = TypeReference.findOrCreate(clr, typeName);
|
|
|
|
MethodReference methodRef = MethodReference.findOrCreate(typeRef, methName, methSig);
|
|
|
|
|
|
|
|
return methodRef;
|
|
|
|
}
|
|
|
|
|
|
|
|
private static ClassLoaderReference findLoader(String loaderName, ClassHierarchy cha) {
|
|
|
|
Atom loaderAtom = Atom.findOrCreateUnicodeAtom(loaderName);
|
|
|
|
IClassLoader[] loaders = cha.getLoaders();
|
|
|
|
for (int i = 0; i < loaders.length; i++) {
|
|
|
|
if (loaders[i].getName() == loaderAtom)
|
|
|
|
return loaders[i].getReference();
|
|
|
|
}
|
|
|
|
Assertions.UNREACHABLE();
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2007-04-18 15:51:08 +00:00
|
|
|
private static void populateScope(JavaSourceAnalysisEngine engine, Collection/* <String> */sources,
|
2007-02-09 15:33:22 +00:00
|
|
|
List/* <String> */libs) throws IOException {
|
|
|
|
|
|
|
|
boolean foundLib = false;
|
|
|
|
for (Iterator iter = libs.iterator(); iter.hasNext();) {
|
|
|
|
String lib = (String) iter.next();
|
2007-02-02 17:22:28 +00:00
|
|
|
|
2007-02-09 15:33:22 +00:00
|
|
|
File libFile = new File(lib);
|
|
|
|
if (libFile.exists()) {
|
|
|
|
foundLib = true;
|
|
|
|
engine.addSystemModule(new JarFileModule(new JarFile(libFile)));
|
|
|
|
}
|
2007-02-02 17:22:28 +00:00
|
|
|
}
|
2007-02-09 15:33:22 +00:00
|
|
|
Assertions._assert(foundLib);
|
|
|
|
|
|
|
|
for (Iterator iter = sources.iterator(); iter.hasNext();) {
|
|
|
|
String srcFilePath = (String) iter.next();
|
|
|
|
String srcFileName = srcFilePath.substring(srcFilePath.lastIndexOf(File.separator) + 1);
|
2007-03-12 02:08:45 +00:00
|
|
|
File f = new File(srcFilePath);
|
|
|
|
Assert.assertTrue(f.exists());
|
|
|
|
if (f.isDirectory()) {
|
2007-03-12 16:09:57 +00:00
|
|
|
engine.addSourceModule(new SourceDirectoryTreeModule(f));
|
2007-03-12 02:08:45 +00:00
|
|
|
} else {
|
2007-03-12 16:09:57 +00:00
|
|
|
engine.addSourceModule(new SourceFileModule(f, srcFileName));
|
2007-03-12 02:08:45 +00:00
|
|
|
}
|
2007-02-02 17:22:28 +00:00
|
|
|
}
|
2007-02-09 15:33:22 +00:00
|
|
|
}
|
2007-02-02 17:22:28 +00:00
|
|
|
}
|