cleanup and refactoring of Eclipse analysis scope management

git-svn-id: https://wala.svn.sourceforge.net/svnroot/wala/trunk@974 f5eafffb-2e1d-0410-98e4-8ec43c5233c4
This commit is contained in:
sjfink 2007-04-17 16:12:50 +00:00
parent 6cf79ac1b3
commit b82f1cec16
6 changed files with 310 additions and 176 deletions

View File

@ -1,7 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="output" path="bin"/>
</classpath>
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="lib" path="/com.ibm.wala.cast.java/lib/java_cup.jar"/>
<classpathentry kind="lib" path="/com.ibm.wala.cast.java/lib/polyglot.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>

View File

@ -11,7 +11,6 @@ Require-Bundle: com.ibm.wala.core.tests,
com.ibm.wala.cast,
com.ibm.wala.core,
org.eclipse.core.runtime,
org.junit,
com.ibm.wala.eclipse
org.junit
Eclipse-LazyStart: true
Export-Package: com.ibm.wala.cast.java.test

View File

@ -37,7 +37,6 @@ import com.ibm.wala.classLoader.JarFileModule;
import com.ibm.wala.classLoader.SourceDirectoryTreeModule;
import com.ibm.wala.classLoader.SourceFileModule;
import com.ibm.wala.core.tests.util.WalaTestCase;
import com.ibm.wala.eclipse.util.EclipseProjectSourceAnalysisEngine;
import com.ibm.wala.ipa.callgraph.CGNode;
import com.ibm.wala.ipa.callgraph.CallGraph;
import com.ibm.wala.ipa.cha.ClassHierarchy;
@ -239,12 +238,12 @@ public abstract class IRTests extends WalaTestCase {
return new String[] { "L" + pkgName + "/" + getName().substring(4) };
}
protected abstract EclipseProjectSourceAnalysisEngine getAnalysisEngine(String[] mainClassDescriptors);
protected abstract TestSourceAnalysisEngine getAnalysisEngine(String[] mainClassDescriptors);
public void runTest(Collection/* <String> */sources, List/* <String> */libs, String[] mainClassDescriptors, GraphAssertions ga,
SourceMapAssertions sa, boolean assertReachable) {
try {
EclipseProjectSourceAnalysisEngine engine = getAnalysisEngine(mainClassDescriptors);
TestSourceAnalysisEngine engine = getAnalysisEngine(mainClassDescriptors);
populateScope(engine, sources, libs);
@ -372,7 +371,7 @@ public abstract class IRTests extends WalaTestCase {
return null;
}
private static void populateScope(EclipseProjectSourceAnalysisEngine engine, Collection/* <String> */sources,
private static void populateScope(TestSourceAnalysisEngine engine, Collection/* <String> */sources,
List/* <String> */libs) throws IOException {
boolean foundLib = false;

View File

@ -10,41 +10,35 @@
*****************************************************************************/
package com.ibm.wala.cast.java.test;
import com.ibm.wala.cast.java.ipa.callgraph.*;
import com.ibm.wala.eclipse.util.EclipseProjectSourceAnalysisEngine;
import com.ibm.wala.ipa.callgraph.*;
import com.ibm.wala.ipa.callgraph.impl.*;
import com.ibm.wala.cast.java.ipa.callgraph.JavaSourceAnalysisScope;
import com.ibm.wala.ipa.callgraph.AnalysisScope;
import com.ibm.wala.ipa.callgraph.Entrypoints;
import com.ibm.wala.ipa.callgraph.impl.Util;
import com.ibm.wala.ipa.cha.ClassHierarchy;
public class JLexTest extends IRTests {
public JLexTest() {
super("JLexTest");
}
public JLexTest() {
super("JLexTest");
}
protected EclipseProjectSourceAnalysisEngine getAnalysisEngine(final String[] mainClassDescriptors) {
return new EclipseProjectSourceAnalysisEngine() {
protected Entrypoints
makeDefaultEntrypoints(AnalysisScope scope, ClassHierarchy cha)
{
return Util.makeMainEntrypoints(JavaSourceAnalysisScope.SOURCE_REF, cha, new String[]{ "LJLex/Main" });
}
};
}
protected TestSourceAnalysisEngine getAnalysisEngine(final String[] mainClassDescriptors) {
return new TestSourceAnalysisEngine() {
protected Entrypoints makeDefaultEntrypoints(AnalysisScope scope, ClassHierarchy cha) {
return Util.makeMainEntrypoints(JavaSourceAnalysisScope.SOURCE_REF, cha, new String[] { "LJLex/Main" });
}
};
}
protected String singleInputForTest() {
return "JLex";
}
protected String singleInputForTest() {
return "JLex";
}
public void testJLex() {
runTest(singleTestSrc(), rtJar,
new String[]{ "LJLex/Main" },
new GraphAssertions(),
new SourceMapAssertions(),
false);
}
public void testJLex() {
runTest(singleTestSrc(), rtJar, new String[] { "LJLex/Main" }, new GraphAssertions(), new SourceMapAssertions(), false);
}
protected String singlePkgInputForTest(String pkgName) {
return "";
}
protected String singlePkgInputForTest(String pkgName) {
return "";
}
}

View File

@ -16,174 +16,143 @@ package com.ibm.wala.cast.java.test;
import java.io.File;
import com.ibm.wala.cast.java.ipa.callgraph.JavaSourceAnalysisScope;
import com.ibm.wala.eclipse.util.EclipseProjectSourceAnalysisEngine;
import com.ibm.wala.ipa.callgraph.AnalysisScope;
import com.ibm.wala.ipa.callgraph.Entrypoints;
import com.ibm.wala.ipa.callgraph.impl.Util;
import com.ibm.wala.ipa.cha.ClassHierarchy;
public class JavaIRTests extends IRTests {
public JavaIRTests(String name) {
super(name);
}
public JavaIRTests(String name) {
super(name);
}
protected EclipseProjectSourceAnalysisEngine getAnalysisEngine(final String[] mainClassDescriptors) {
return new EclipseProjectSourceAnalysisEngine() {
protected Entrypoints
makeDefaultEntrypoints(AnalysisScope scope, ClassHierarchy cha)
{
return Util.makeMainEntrypoints(JavaSourceAnalysisScope.SOURCE_REF, cha, mainClassDescriptors);
}
};
}
protected TestSourceAnalysisEngine getAnalysisEngine(final String[] mainClassDescriptors) {
return new TestSourceAnalysisEngine() {
protected Entrypoints makeDefaultEntrypoints(AnalysisScope scope, ClassHierarchy cha) {
return Util.makeMainEntrypoints(JavaSourceAnalysisScope.SOURCE_REF, cha, mainClassDescriptors);
}
};
}
protected String singleInputForTest() {
return getName().substring(4) + ".java";
}
protected String singleInputForTest() {
return getName().substring(4) + ".java";
}
protected String singlePkgInputForTest(String pkgName) {
return pkgName + File.separator + getName().substring(4) + ".java";
}
protected String singlePkgInputForTest(String pkgName) {
return pkgName + File.separator + getName().substring(4) + ".java";
}
public void testSimple1() {
SourceMapAssertions sa = new SourceMapAssertions();
sa.addAssertion("Source#Simple1#doStuff#(I)V", new SourceMapAssertion("prod", 14));
sa.addAssertion("Source#Simple1#doStuff#(I)V", new SourceMapAssertion("j", 13));
sa.addAssertion("Source#Simple1#main#([Ljava/lang/String;)V", new SourceMapAssertion("s", 22));
sa.addAssertion("Source#Simple1#main#([Ljava/lang/String;)V", new SourceMapAssertion("i", 18));
sa.addAssertion("Source#Simple1#main#([Ljava/lang/String;)V", new SourceMapAssertion("sum", 19));
public void testSimple1() {
SourceMapAssertions sa = new SourceMapAssertions();
sa.addAssertion("Source#Simple1#doStuff#(I)V", new SourceMapAssertion("prod", 14));
sa.addAssertion("Source#Simple1#doStuff#(I)V", new SourceMapAssertion("j", 13));
sa.addAssertion("Source#Simple1#main#([Ljava/lang/String;)V", new SourceMapAssertion("s", 22));
sa.addAssertion("Source#Simple1#main#([Ljava/lang/String;)V", new SourceMapAssertion("i", 18));
sa.addAssertion("Source#Simple1#main#([Ljava/lang/String;)V", new SourceMapAssertion("sum", 19));
runTest(singleTestSrc(), rtJar, simpleTestEntryPoint(),
new GraphAssertions(
EdgeAssertions.make("Source#Simple1#main#([Ljava/lang/String;)V", "Source#Simple1#doStuff#(I)V"),
EdgeAssertions.make("Source#Simple1#instanceMethod1#()V", "Source#Simple1#instanceMethod2#()V")
),
// this needs soure positions to work too
sa,
true);
}
runTest(singleTestSrc(), rtJar, simpleTestEntryPoint(), new GraphAssertions(EdgeAssertions.make(
"Source#Simple1#main#([Ljava/lang/String;)V", "Source#Simple1#doStuff#(I)V"), EdgeAssertions.make(
"Source#Simple1#instanceMethod1#()V", "Source#Simple1#instanceMethod2#()V")),
// this needs soure positions to work too
sa, true);
}
public void testTwoClasses() {
runTest(singleTestSrc(), rtJar, simpleTestEntryPoint(),
new GraphAssertions(), null, true);
}
public void testTwoClasses() {
runTest(singleTestSrc(), rtJar, simpleTestEntryPoint(), new GraphAssertions(), null, true);
}
public void testInterfaceTest1() {
runTest(singleTestSrc(), rtJar, simpleTestEntryPoint(),
new GraphAssertions(), null, true);
}
public void testInterfaceTest1() {
runTest(singleTestSrc(), rtJar, simpleTestEntryPoint(), new GraphAssertions(), null, true);
}
public void testInheritance1() {
runTest(singleTestSrc(), rtJar, simpleTestEntryPoint(),
new GraphAssertions(), null, true);
}
public void testInheritance1() {
runTest(singleTestSrc(), rtJar, simpleTestEntryPoint(), new GraphAssertions(), null, true);
}
public void testArray1() {
runTest(singleTestSrc(), rtJar, simpleTestEntryPoint(),
new GraphAssertions(), null, true);
}
public void testArray1() {
runTest(singleTestSrc(), rtJar, simpleTestEntryPoint(), new GraphAssertions(), null, true);
}
public void testArrayLiteral1() {
runTest(singleTestSrc(), rtJar, simpleTestEntryPoint(),
new GraphAssertions(), null, true);
}
public void testArrayLiteral1() {
runTest(singleTestSrc(), rtJar, simpleTestEntryPoint(), new GraphAssertions(), null, true);
}
public void testArrayLiteral2() {
runTest(singleTestSrc(), rtJar, simpleTestEntryPoint(),
new GraphAssertions(), null, true);
}
public void testArrayLiteral2() {
runTest(singleTestSrc(), rtJar, simpleTestEntryPoint(), new GraphAssertions(), null, true);
}
public void testInheritedField() {
runTest(singleTestSrc(), rtJar, simpleTestEntryPoint(),
new GraphAssertions(
EdgeAssertions.make("Source#InheritedField#main#([Ljava/lang/String;)V", "Source#B#foo#()V"),
EdgeAssertions.make("Source#InheritedField#main#([Ljava/lang/String;)V", "Source#B#bar#()V")
), null, true);
}
public void testInheritedField() {
runTest(singleTestSrc(), rtJar, simpleTestEntryPoint(), new GraphAssertions(EdgeAssertions.make(
"Source#InheritedField#main#([Ljava/lang/String;)V", "Source#B#foo#()V"), EdgeAssertions.make(
"Source#InheritedField#main#([Ljava/lang/String;)V", "Source#B#bar#()V")), null, true);
}
public void testQualifiedStatic() {
runTest(singleTestSrc(), rtJar, simpleTestEntryPoint(),
new GraphAssertions(), null, true);
}
public void testQualifiedStatic() {
runTest(singleTestSrc(), rtJar, simpleTestEntryPoint(), new GraphAssertions(), null, true);
}
public void testStaticNesting() {
runTest(singleTestSrc(), rtJar, simpleTestEntryPoint(),
new GraphAssertions(), null, true);
}
public void testStaticNesting() {
runTest(singleTestSrc(), rtJar, simpleTestEntryPoint(), new GraphAssertions(), null, true);
}
public void testInnerClass() {
runTest(singleTestSrc(), rtJar, simpleTestEntryPoint(),
new GraphAssertions(), null, true);
}
public void testInnerClass() {
runTest(singleTestSrc(), rtJar, simpleTestEntryPoint(), new GraphAssertions(), null, true);
}
public void testLocalClass() {
runTest(singleTestSrc(), rtJar, simpleTestEntryPoint(),
new GraphAssertions(), null, true);
}
public void testLocalClass() {
runTest(singleTestSrc(), rtJar, simpleTestEntryPoint(), new GraphAssertions(), null, true);
}
public void testAnonymousClass() {
runTest(singleTestSrc(), rtJar, simpleTestEntryPoint(),
new GraphAssertions(), null, true);
}
public void testAnonymousClass() {
runTest(singleTestSrc(), rtJar, simpleTestEntryPoint(), new GraphAssertions(), null, true);
}
public void testWhileTest1() {
runTest(singleTestSrc(), rtJar, simpleTestEntryPoint(),
new GraphAssertions(), null, true);
}
public void testWhileTest1() {
runTest(singleTestSrc(), rtJar, simpleTestEntryPoint(), new GraphAssertions(), null, true);
}
public void testSwitch1() {
runTest(singleTestSrc(), rtJar, simpleTestEntryPoint(),
new GraphAssertions(), null, true);
}
public void testSwitch1() {
runTest(singleTestSrc(), rtJar, simpleTestEntryPoint(), new GraphAssertions(), null, true);
}
public void testException1() {
runTest(singleTestSrc(), rtJar, simpleTestEntryPoint(),
new GraphAssertions(), null, true);
}
public void testException1() {
runTest(singleTestSrc(), rtJar, simpleTestEntryPoint(), new GraphAssertions(), null, true);
}
public void testException2() {
runTest(singleTestSrc(), rtJar, simpleTestEntryPoint(),
new GraphAssertions(), null, true);
}
public void testException2() {
runTest(singleTestSrc(), rtJar, simpleTestEntryPoint(), new GraphAssertions(), null, true);
}
public void testFinally1() {
runTest(singleTestSrc(), rtJar, simpleTestEntryPoint(),
new GraphAssertions(), null, true);
}
public void testFinally1() {
runTest(singleTestSrc(), rtJar, simpleTestEntryPoint(), new GraphAssertions(), null, true);
}
public void testScoping1() {
runTest(singleTestSrc(), rtJar, simpleTestEntryPoint(),
new GraphAssertions(), null, true);
}
public void testScoping1() {
runTest(singleTestSrc(), rtJar, simpleTestEntryPoint(), new GraphAssertions(), null, true);
}
public void testScoping2() {
runTest(singleTestSrc(), rtJar, simpleTestEntryPoint(),
new GraphAssertions(), null, true);
}
public void testScoping2() {
runTest(singleTestSrc(), rtJar, simpleTestEntryPoint(), new GraphAssertions(), null, true);
}
public void testNonPrimaryTopLevel() {
runTest(singlePkgTestSrc("p"), rtJar, simplePkgTestEntryPoint("p"),
new GraphAssertions(), null, true);
}
public void testNonPrimaryTopLevel() {
runTest(singlePkgTestSrc("p"), rtJar, simplePkgTestEntryPoint("p"), new GraphAssertions(), null, true);
}
public void testMiniaturList() {
runTest(singleTestSrc(), rtJar, simpleTestEntryPoint(),
new GraphAssertions(), null, true);
}
public void testMiniaturList() {
runTest(singleTestSrc(), rtJar, simpleTestEntryPoint(), new GraphAssertions(), null, true);
}
public void testMonitor() {
runTest(singleTestSrc(), rtJar, simpleTestEntryPoint(),
new GraphAssertions(), null, true);
}
public void testMonitor() {
runTest(singleTestSrc(), rtJar, simpleTestEntryPoint(), new GraphAssertions(), null, true);
}
public void testStaticInit() {
runTest(singleTestSrc(), rtJar, simpleTestEntryPoint(),
new GraphAssertions(), null, true);
}
public void testStaticInit() {
runTest(singleTestSrc(), rtJar, simpleTestEntryPoint(), new GraphAssertions(), null, true);
}
public void testThread1() {
runTest(singleTestSrc(), rtJar, simpleTestEntryPoint(),
new GraphAssertions(), null, true);
}
public void testThread1() {
runTest(singleTestSrc(), rtJar, simpleTestEntryPoint(), new GraphAssertions(), null, true);
}
}

View File

@ -0,0 +1,171 @@
/******************************************************************************
* 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
*****************************************************************************/
package com.ibm.wala.cast.java.test;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
import com.ibm.wala.cast.ir.ssa.AstIRFactory;
import com.ibm.wala.cast.java.client.impl.ZeroCFABuilderFactory;
import com.ibm.wala.cast.java.ipa.callgraph.JavaSourceAnalysisScope;
import com.ibm.wala.cast.java.translator.polyglot.IRTranslatorExtension;
import com.ibm.wala.cast.java.translator.polyglot.JavaIRTranslatorExtension;
import com.ibm.wala.cast.java.translator.polyglot.PolyglotClassLoaderFactory;
import com.ibm.wala.classLoader.ClassLoaderFactory;
import com.ibm.wala.classLoader.Module;
import com.ibm.wala.client.impl.AbstractAnalysisEngine;
import com.ibm.wala.ipa.callgraph.AnalysisOptions;
import com.ibm.wala.ipa.callgraph.AnalysisScope;
import com.ibm.wala.ipa.callgraph.Entrypoints;
import com.ibm.wala.ipa.callgraph.impl.SetOfClasses;
import com.ibm.wala.ipa.callgraph.impl.Util;
import com.ibm.wala.ipa.cha.ClassHierarchy;
import com.ibm.wala.ipa.cha.ClassHierarchyException;
import com.ibm.wala.ssa.SSAOptions;
import com.ibm.wala.ssa.SymbolTable;
import com.ibm.wala.ssa.Value;
import com.ibm.wala.types.ClassLoaderReference;
import com.ibm.wala.util.config.XMLSetOfClasses;
import com.ibm.wala.util.debug.Assertions;
import com.ibm.wala.util.warnings.WarningSet;
/**
*
* @author julian dolby?
* @author sfink. refactored to clean up eclipse utilities.
*
*/
public class TestSourceAnalysisEngine extends AbstractAnalysisEngine {
/**
* Modules which are user-space code
*/
private final Set<Module> userEntries = new HashSet<Module>();
/**
* Modules which are source code
*/
private final Set<Module> sourceEntries = new HashSet<Module>();
/**
* Modules which are system or library code TODO: what about extension loader?
*/
private final Set<Module> systemEntries = new HashSet<Module>();
public TestSourceAnalysisEngine() {
super();
setCallGraphBuilderFactory(new ZeroCFABuilderFactory());
}
/**
* Adds the given source module to the source loader's module list. Clients
* should/may call this method if they don't supply an IJavaProject to the
* constructor.
*/
public void addSourceModule(Module M) {
sourceEntries.add(M);
}
/**
* Adds the given compiled module to the application loader's module list.
* Clients should/may call this method if they don't supply an IJavaProject to
* the constructor.
*/
public void addCompiledModule(Module M) {
userEntries.add(M);
}
/**
* Adds the given module to the primordial loader's module list. Clients
* should/may call this method if they don't supply an IJavaProject to the
* constructor.
*/
public void addSystemModule(Module M) {
systemEntries.add(M);
}
protected void addApplicationModulesToScope() {
ClassLoaderReference app = scope.getApplicationLoader();
for (Iterator it = userEntries.iterator(); it.hasNext();) {
Module M = (Module) it.next();
scope.addToScope(app, M);
}
ClassLoaderReference src = ((JavaSourceAnalysisScope) scope).getSourceLoader();
for (Iterator it = sourceEntries.iterator(); it.hasNext();) {
Module M = (Module) it.next();
scope.addToScope(src, M);
}
}
protected void buildAnalysisScope() {
scope = new JavaSourceAnalysisScope();
if (getExclusionsFile() != null) {
ClassLoader loader = getClass().getClassLoader();
scope.setExclusions(new XMLSetOfClasses(getExclusionsFile(), loader));
}
for (Iterator modules = systemEntries.iterator(); modules.hasNext();) {
scope.addToScope(scope.getPrimordialLoader(), (Module) modules.next());
}
// add user stuff
addApplicationModulesToScope();
}
public IRTranslatorExtension getTranslatorExtension() {
return new JavaIRTranslatorExtension();
}
protected ClassLoaderFactory getClassLoaderFactory(SetOfClasses exclusions, WarningSet warnings, IRTranslatorExtension extInfo) {
return new PolyglotClassLoaderFactory(exclusions, warnings, extInfo);
}
protected ClassHierarchy buildClassHierarchy() {
ClassHierarchy cha = null;
ClassLoaderFactory factory = getClassLoaderFactory(scope.getExclusions(), getWarnings(), getTranslatorExtension());
try {
cha = ClassHierarchy.make(getScope(), factory, getWarnings());
} catch (ClassHierarchyException e) {
System.err.println("Class Hierarchy construction failed");
System.err.println(e.toString());
e.printStackTrace();
}
return cha;
}
protected Entrypoints makeDefaultEntrypoints(AnalysisScope scope, ClassHierarchy cha) {
return Util.makeMainEntrypoints(JavaSourceAnalysisScope.SOURCE_REF, cha);
}
public AnalysisOptions getDefaultOptions(Entrypoints entrypoints) {
AnalysisOptions options = new AnalysisOptions(getScope(), AstIRFactory.makeDefaultFactory(true), entrypoints);
SSAOptions ssaOptions = new SSAOptions();
ssaOptions.setDefaultValues(new SSAOptions.DefaultValues() {
public int getDefaultValue(SymbolTable symtab, int valueNumber) {
Value v = symtab.getValue(valueNumber);
if (v == null) {
Assertions._assert(v != null, "no default for " + valueNumber);
}
return v.getDefaultValue(symtab);
}
});
options.setSSAOptions(ssaOptions);
return options;
}
}