Added support for additional reflective methods

git-svn-id: https://wala.svn.sourceforge.net/svnroot/wala/trunk@2746 f5eafffb-2e1d-0410-98e4-8ec43c5233c4
This commit is contained in:
pistoia 2008-04-04 19:45:56 +00:00
parent cbcee6624f
commit 2197b8237a
2 changed files with 75 additions and 1 deletions

View File

@ -497,10 +497,76 @@ public class ReflectionTest extends WalaTestCase {
TestConstants.REFLECT19_MAIN);
AnalysisOptions options = CallGraphTestUtil.makeAnalysisOptions(scope, entrypoints);
CallGraph cg = CallGraphTestUtil.buildZeroOneCFA(options, new AnalysisCache(), cha, scope, false);
System.err.println(cg);
TypeReference tr = TypeReference.findOrCreate(ClassLoaderReference.Primordial, "Ljava/lang/Integer");
MethodReference mr = MethodReference.findOrCreate(tr, "toString", "()Ljava/lang/String;");
Set<CGNode> nodes = cg.getNodes(mr);
assertFalse(nodes.isEmpty());
}
/**
* Test that when analyzing Reflect20, the call graph includes a node for Helper.o.
*/
public void testReflect20() throws WalaException, IllegalArgumentException, CancelException, IOException {
AnalysisScope scope = CallGraphTestUtil.makeJ2SEAnalysisScope(TestConstants.WALA_TESTDATA, "Java60RegressionExclusions.txt");
ClassHierarchy cha = ClassHierarchy.make(scope);
Iterable<Entrypoint> entrypoints = com.ibm.wala.ipa.callgraph.impl.Util.makeMainEntrypoints(scope, cha,
TestConstants.REFLECT20_MAIN);
AnalysisOptions options = CallGraphTestUtil.makeAnalysisOptions(scope, entrypoints);
CallGraph cg = CallGraphTestUtil.buildZeroOneCFA(options, new AnalysisCache(), cha, scope, false);
TypeReference tr = TypeReference.findOrCreate(ClassLoaderReference.Application, "Lreflection/Helper");
MethodReference mr = MethodReference.findOrCreate(tr, "o", "(Ljava/lang/Object;Ljava/lang/Object;)V");
Set<CGNode> nodes = cg.getNodes(mr);
assertFalse(nodes.isEmpty());
}
/**
* Test that when analyzing Reflect21, the call graph includes a node for the constructor of {@link Helper} that takes
* two {@link Object} parameters. This is to test the support for Class.getDeclaredConstructor.
*/
public void testReflect21() throws WalaException, IllegalArgumentException, CancelException, IOException {
AnalysisScope scope = CallGraphTestUtil.makeJ2SEAnalysisScope(TestConstants.WALA_TESTDATA, "Java60RegressionExclusions.txt");
ClassHierarchy cha = ClassHierarchy.make(scope);
Iterable<Entrypoint> entrypoints = com.ibm.wala.ipa.callgraph.impl.Util.makeMainEntrypoints(scope, cha,
TestConstants.REFLECT21_MAIN);
AnalysisOptions options = CallGraphTestUtil.makeAnalysisOptions(scope, entrypoints);
CallGraph cg = CallGraphTestUtil.buildZeroOneCFA(options, new AnalysisCache(), cha, scope, false);
TypeReference tr = TypeReference.findOrCreate(ClassLoaderReference.Application, "Lreflection/Helper");
MethodReference mr = MethodReference.findOrCreate(tr, "<init>", "(Ljava/lang/Object;Ljava/lang/Object;)V");
Set<CGNode> nodes = cg.getNodes(mr);
assertFalse(nodes.isEmpty());
}
/**
* Test that when analyzing Reflect22, the call graph includes a node for the constructor of {@link Helper} that takes
* one {@link Integer} parameters. This is to test the support for Class.getDeclaredConstructors.
*/
public void testReflect22() throws WalaException, IllegalArgumentException, CancelException, IOException {
AnalysisScope scope = CallGraphTestUtil.makeJ2SEAnalysisScope(TestConstants.WALA_TESTDATA, "Java60RegressionExclusions.txt");
ClassHierarchy cha = ClassHierarchy.make(scope);
Iterable<Entrypoint> entrypoints = com.ibm.wala.ipa.callgraph.impl.Util.makeMainEntrypoints(scope, cha,
TestConstants.REFLECT22_MAIN);
AnalysisOptions options = CallGraphTestUtil.makeAnalysisOptions(scope, entrypoints);
CallGraph cg = CallGraphTestUtil.buildZeroOneCFA(options, new AnalysisCache(), cha, scope, false);
TypeReference tr = TypeReference.findOrCreate(ClassLoaderReference.Application, "Lreflection/Helper");
MethodReference mr = MethodReference.findOrCreate(tr, "<init>", "(Ljava/lang/Integer;)V");
Set<CGNode> nodes = cg.getNodes(mr);
assertFalse(nodes.isEmpty());
}
/**
* Test that when analyzing Reflect22, the call graph includes a node for the constructor of {@link Helper} that takes
* one {@link Integer} parameters. This is to test the support for Class.getDeclaredConstructors.
*/
public void testReflect23() throws WalaException, IllegalArgumentException, CancelException, IOException {
AnalysisScope scope = CallGraphTestUtil.makeJ2SEAnalysisScope(TestConstants.WALA_TESTDATA, "Java60RegressionExclusions.txt");
ClassHierarchy cha = ClassHierarchy.make(scope);
Iterable<Entrypoint> entrypoints = com.ibm.wala.ipa.callgraph.impl.Util.makeMainEntrypoints(scope, cha,
TestConstants.REFLECT23_MAIN);
AnalysisOptions options = CallGraphTestUtil.makeAnalysisOptions(scope, entrypoints);
CallGraph cg = CallGraphTestUtil.buildZeroOneCFA(options, new AnalysisCache(), cha, scope, false);
TypeReference tr = TypeReference.findOrCreate(ClassLoaderReference.Application, "Lreflection/Helper");
MethodReference mr = MethodReference.findOrCreate(tr, "u", "(Ljava/lang/Integer;)V");
Set<CGNode> nodes = cg.getNodes(mr);
assertFalse(nodes.isEmpty());
}
}

View File

@ -77,6 +77,14 @@ public interface TestConstants {
public final static String REFLECT18_MAIN = "Lreflection/Reflect18";
public final static String REFLECT19_MAIN = "Lreflection/Reflect19";
public final static String REFLECT20_MAIN = "Lreflection/Reflect20";
public final static String REFLECT21_MAIN = "Lreflection/Reflect21";
public final static String REFLECT22_MAIN = "Lreflection/Reflect22";
public final static String REFLECT23_MAIN = "Lreflection/Reflect23";
public final static String SLICE1_MAIN = "Lslice/Slice1";