refactor polyglot-based java code in its own projects

git-svn-id: https://wala.svn.sourceforge.net/svnroot/wala/trunk@3168 f5eafffb-2e1d-0410-98e4-8ec43c5233c4
This commit is contained in:
dolby-oss 2009-01-09 14:12:19 +00:00
parent 1135a37fb5
commit 624fb4c5ae
7 changed files with 35 additions and 157 deletions

View File

@ -1,16 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<launchConfiguration type="org.eclipse.jdt.junit.launchconfig">
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS">
<listEntry value="/com.ibm.wala.cast.java.test/src/com/ibm/wala/cast/java/test/PolyglotJavaIRTests.java"/>
</listAttribute>
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES">
<listEntry value="1"/>
</listAttribute>
<stringAttribute key="org.eclipse.jdt.junit.CONTAINER" value=""/>
<booleanAttribute key="org.eclipse.jdt.junit.KEEPRUNNING_ATTR" value="false"/>
<stringAttribute key="org.eclipse.jdt.junit.TESTNAME" value=""/>
<stringAttribute key="org.eclipse.jdt.junit.TEST_KIND" value="org.eclipse.jdt.junit.loader.junit3"/>
<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="com.ibm.wala.cast.java.test.PolyglotJavaIRTests"/>
<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="com.ibm.wala.cast.java.test"/>
<stringAttribute key="org.eclipse.jdt.launching.WORKING_DIRECTORY" value="${workspace_loc:com.ibm.wala.cast.java.test.data}"/>
</launchConfiguration>

View File

@ -1,16 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<launchConfiguration type="org.eclipse.jdt.junit.launchconfig">
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS">
<listEntry value="/com.ibm.wala.cast.java.test/src/com/ibm/wala/cast/java/test/SyncDuplicatorTest.java"/>
</listAttribute>
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES">
<listEntry value="1"/>
</listAttribute>
<stringAttribute key="org.eclipse.jdt.junit.CONTAINER" value=""/>
<booleanAttribute key="org.eclipse.jdt.junit.KEEPRUNNING_ATTR" value="false"/>
<stringAttribute key="org.eclipse.jdt.junit.TESTNAME" value=""/>
<stringAttribute key="org.eclipse.jdt.junit.TEST_KIND" value="org.eclipse.jdt.junit.loader.junit3"/>
<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="com.ibm.wala.cast.java.test.SyncDuplicatorTest"/>
<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="com.ibm.wala.cast.java.test"/>
<stringAttribute key="org.eclipse.jdt.launching.WORKING_DIRECTORY" value="${workspace_loc:com.ibm.wala.cast.java.test.data}"/>
</launchConfiguration>

View File

@ -261,16 +261,12 @@ public abstract class IRTests extends WalaTestCase {
}
}
protected abstract String singleInputForTest();
protected abstract String singlePkgInputForTest(String pkgName);
protected Collection<String> singleTestSrc() {
return Collections.singletonList(getTestSrcPath() + File.separator + singleInputForTest());
return Collections.singletonList(getTestSrcPath() + File.separator + singleJavaInputForTest());
}
protected Collection<String> singlePkgTestSrc(String pkgName) {
return Collections.singletonList(getTestSrcPath() + File.separator + singlePkgInputForTest(pkgName));
return Collections.singletonList(getTestSrcPath() + File.separator + singleJavaPkgInputForTest(pkgName));
}
protected String[] simpleTestEntryPoint() {
@ -337,7 +333,7 @@ public abstract class IRTests extends WalaTestCase {
}
if (assertReachable) {
Assert.assertTrue(unreachable.toString(), unreachable.isEmpty());
Assert.assertTrue("unreachable methods: " + unreachable.toString(), unreachable.isEmpty());
}
}
@ -411,7 +407,11 @@ public abstract class IRTests extends WalaTestCase {
if (w != null) {
IFile file = project.getProject().getFile(srcFilePath);
engine.addSourceModule(new EclipseSourceFileModule(file));
try {
engine.addSourceModule(new EclipseSourceFileModule(file));
} catch (IllegalArgumentException e) {
assertTrue(e.getMessage(), false);
}
} else {
String srcFileName = srcFilePath.substring(srcFilePath.lastIndexOf(File.separator) + 1);
@ -433,4 +433,17 @@ public abstract class IRTests extends WalaTestCase {
protected String getTestSrcPath() {
return testSrcPath;
}
protected String singleJavaInputForTest() {
return getName().substring(4) + ".java";
}
protected String singleInputForTest() {
return getName().substring(4);
}
protected String singleJavaPkgInputForTest(String pkgName) {
return pkgName + File.separator + getName().substring(4) + ".java";
}
}

View File

@ -10,32 +10,13 @@
*****************************************************************************/
package com.ibm.wala.cast.java.test;
import com.ibm.wala.cast.java.client.JavaSourceAnalysisEngine;
import com.ibm.wala.cast.java.translator.polyglot.PolyglotJavaSourceAnalysisEngine;
import com.ibm.wala.core.tests.callGraph.CallGraphTestUtil;
import com.ibm.wala.eclipse.util.EclipseProjectPath;
import com.ibm.wala.ipa.callgraph.AnalysisScope;
import com.ibm.wala.ipa.callgraph.Entrypoint;
import com.ibm.wala.ipa.callgraph.impl.Util;
import com.ibm.wala.ipa.cha.IClassHierarchy;
public abstract class JLexTest extends IRTests {
public class JLexTest extends IRTests {
public JLexTest() {
super("JLexTest", null);
public JLexTest(String name) {
super(name, null);
}
protected JavaSourceAnalysisEngine getAnalysisEngine(final String[] mainClassDescriptors) {
JavaSourceAnalysisEngine engine = new PolyglotJavaSourceAnalysisEngine() {
protected Iterable<Entrypoint> makeDefaultEntrypoints(AnalysisScope scope, IClassHierarchy cha) {
return Util.makeMainEntrypoints(EclipseProjectPath.SOURCE_REF, cha, new String[] { "LJLex/Main" });
}
};
engine.setExclusionsFile(CallGraphTestUtil.REGRESSION_EXCLUSIONS);
return engine;
}
protected String singleInputForTest() {
protected String singleJavaInputForTest() {
return "JLex";
}
@ -43,7 +24,7 @@ public class JLexTest extends IRTests {
runTest(singleTestSrc(), rtJar, new String[] { "LJLex/Main" }, emptyList, false);
}
protected String singlePkgInputForTest(String pkgName) {
protected String singleJavaPkgInputForTest(String pkgName) {
return "";
}
}

View File

@ -13,7 +13,6 @@
*/
package com.ibm.wala.cast.java.test;
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
@ -62,18 +61,6 @@ public abstract class JavaIRTests extends IRTests {
this(name, null);
}
protected String singleInputForTest() {
return getName().substring(4) + ".java";
}
protected String singleInputForTestNoExt() {
return getName().substring(4);
}
protected String singlePkgInputForTest(String pkgName) {
return pkgName + File.separator + getName().substring(4) + ".java";
}
public void testSimple1() {
List<? extends IRAssertion> assertions = Arrays.asList(new SourceMapAssertion("Source#Simple1#doStuff#(I)V", "prod", 14),
@ -94,7 +81,7 @@ public abstract class JavaIRTests extends IRTests {
new IRAssertion() {
public void check(CallGraph cg) throws Exception {
final String typeStr = singleInputForTestNoExt();
final String typeStr = singleInputForTest();
final TypeReference type = findOrCreateTypeReference("Source", typeStr, cg.getClassHierarchy());
@ -327,7 +314,7 @@ public abstract class JavaIRTests extends IRTests {
new IRAssertion() {
public void check(CallGraph cg) throws Exception {
final String typeStr = singleInputForTestNoExt() + "$WhatsIt";
final String typeStr = singleInputForTest() + "$WhatsIt";
final TypeReference type = findOrCreateTypeReference("Source", typeStr, cg.getClassHierarchy());
@ -357,7 +344,7 @@ public abstract class JavaIRTests extends IRTests {
new IRAssertion() {
public void check(CallGraph cg) throws Exception {
final String typeStr = singleInputForTestNoExt();
final String typeStr = singleInputForTest();
final TypeReference type = findOrCreateTypeReference("Source", typeStr + "$WhatsIt", cg.getClassHierarchy());
@ -473,7 +460,7 @@ public abstract class JavaIRTests extends IRTests {
* to.
*/
public void check(CallGraph cg) throws Exception {
final String typeStr = singleInputForTestNoExt();
final String typeStr = singleInputForTest();
final String localClassStr = "Foo";
// Observe the descriptor for a class local to a method.
@ -509,7 +496,7 @@ public abstract class JavaIRTests extends IRTests {
new IRAssertion() {
public void check(CallGraph cg) throws Exception {
final String typeStr = singleInputForTestNoExt();
final String typeStr = singleInputForTest();
final TypeReference type = findOrCreateTypeReference("Source", typeStr, cg.getClassHierarchy());

View File

@ -1,29 +0,0 @@
package com.ibm.wala.cast.java.test;
import com.ibm.wala.cast.java.client.JavaSourceAnalysisEngine;
import com.ibm.wala.cast.java.translator.polyglot.PolyglotJavaSourceAnalysisEngine;
import com.ibm.wala.core.tests.callGraph.CallGraphTestUtil;
import com.ibm.wala.eclipse.util.EclipseProjectPath;
import com.ibm.wala.ipa.callgraph.AnalysisScope;
import com.ibm.wala.ipa.callgraph.Entrypoint;
import com.ibm.wala.ipa.callgraph.impl.Util;
import com.ibm.wala.ipa.cha.IClassHierarchy;
public class PolyglotJavaIRTests extends JavaIRTests {
public PolyglotJavaIRTests(String name) {
super(name);
}
@Override
protected JavaSourceAnalysisEngine getAnalysisEngine(final String[] mainClassDescriptors) {
JavaSourceAnalysisEngine engine = new PolyglotJavaSourceAnalysisEngine() {
protected Iterable<Entrypoint> makeDefaultEntrypoints(AnalysisScope scope, IClassHierarchy cha) {
return Util.makeMainEntrypoints(EclipseProjectPath.SOURCE_REF, cha, mainClassDescriptors);
}
};
engine.setExclusionsFile(CallGraphTestUtil.REGRESSION_EXCLUSIONS);
return engine;
}
}

View File

@ -12,21 +12,8 @@ package com.ibm.wala.cast.java.test;
import java.io.File;
import com.ibm.wala.cast.java.client.JavaSourceAnalysisEngine;
import com.ibm.wala.cast.java.examples.ast.SynchronizedBlockDuplicator;
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.PolyglotJavaSourceAnalysisEngine;
import com.ibm.wala.cast.tree.CAst;
import com.ibm.wala.cast.tree.impl.CAstRewriter;
import com.ibm.wala.cast.tree.impl.CAstRewriterFactory;
import com.ibm.wala.classLoader.CallSiteReference;
import com.ibm.wala.core.tests.callGraph.CallGraphTestUtil;
import com.ibm.wala.eclipse.util.EclipseProjectPath;
import com.ibm.wala.ipa.callgraph.AnalysisScope;
import com.ibm.wala.ipa.callgraph.Entrypoint;
import com.ibm.wala.ipa.callgraph.impl.Util;
import com.ibm.wala.ipa.cha.IClassHierarchy;
import com.ibm.wala.shrikeBT.IInvokeInstruction;
import com.ibm.wala.types.Descriptor;
import com.ibm.wala.types.MethodReference;
@ -34,45 +21,16 @@ import com.ibm.wala.types.TypeName;
import com.ibm.wala.types.TypeReference;
import com.ibm.wala.util.strings.Atom;
public class SyncDuplicatorTest extends IRTests {
public abstract class SyncDuplicatorTest extends IRTests {
public SyncDuplicatorTest() {
super("SyncDuplicatorTest", null);
public SyncDuplicatorTest(String name) {
super(name, null);
}
private final static CallSiteReference testMethod = CallSiteReference.make(0, MethodReference.findOrCreate(TypeReference
protected final static CallSiteReference testMethod = CallSiteReference.make(0, MethodReference.findOrCreate(TypeReference
.findOrCreate(EclipseProjectPath.SOURCE_REF, TypeName.string2TypeName("LMonitor2")), Atom.findOrCreateUnicodeAtom("test"),
Descriptor.findOrCreateUTF8("(Ljava/lang/Object;)Z")), IInvokeInstruction.Dispatch.STATIC);
protected JavaSourceAnalysisEngine getAnalysisEngine(final String[] mainClassDescriptors) {
JavaSourceAnalysisEngine engine = new PolyglotJavaSourceAnalysisEngine() {
protected Iterable<Entrypoint> makeDefaultEntrypoints(AnalysisScope scope, IClassHierarchy cha) {
return Util.makeMainEntrypoints(EclipseProjectPath.SOURCE_REF, cha, mainClassDescriptors);
}
public IRTranslatorExtension getTranslatorExtension() {
JavaIRTranslatorExtension ext = new JavaIRTranslatorExtension();
ext.setCAstRewriterFactory(new CAstRewriterFactory() {
public CAstRewriter createCAstRewriter(CAst ast) {
return new SynchronizedBlockDuplicator(ast, true, testMethod);
}
});
return ext;
}
};
engine.setExclusionsFile(CallGraphTestUtil.REGRESSION_EXCLUSIONS);
return engine;
}
protected String singleInputForTest() {
return getName().substring(4) + ".java";
}
protected String singlePkgInputForTest(String pkgName) {
return pkgName + File.separator + getName().substring(4) + ".java";
}
public void testMonitor2() {
runTest(singleTestSrc(), rtJar, simpleTestEntryPoint(), emptyList, true);
}