remove ClassHierarchyException from IClass.getAllMethods

git-svn-id: https://wala.svn.sourceforge.net/svnroot/wala/trunk@3557 f5eafffb-2e1d-0410-98e4-8ec43c5233c4
This commit is contained in:
sjfink 2009-05-01 12:50:17 +00:00
parent 9939142eae
commit 948dab4d0d
9 changed files with 59 additions and 73 deletions

View File

@ -23,10 +23,8 @@ import com.ibm.wala.classLoader.IMethod;
import com.ibm.wala.ipa.callgraph.propagation.InstanceKey;
import com.ibm.wala.ipa.callgraph.propagation.InstanceKeyFactory;
import com.ibm.wala.ipa.callgraph.propagation.PropagationCallGraphBuilder;
import com.ibm.wala.ipa.cha.ClassHierarchyException;
import com.ibm.wala.ipa.cha.IClassHierarchy;
import com.ibm.wala.util.collections.HashSetFactory;
import com.ibm.wala.util.debug.Assertions;
public class JavaScopeMappingInstanceKeys extends ScopeMappingInstanceKeys {
@ -38,29 +36,26 @@ public class JavaScopeMappingInstanceKeys extends ScopeMappingInstanceKeys {
protected LexicalParent[] getParents(InstanceKey base) {
IClass cls = base.getConcreteType();
if (isPossiblyLexicalClass(cls)) {
try {
Set<LexicalParent> result = HashSetFactory.make();
Set<LexicalParent> result = HashSetFactory.make();
for (Iterator MS = cls.getAllMethods().iterator(); MS.hasNext();) {
IMethod m = (IMethod) MS.next();
if ((m instanceof AstMethod) && !m.isStatic()) {
AstMethod M = (AstMethod) m;
LexicalParent[] parents = M.getParents();
for (int i = 0; i < parents.length; i++) {
result.add(parents[i]);
}
for (Iterator MS = cls.getAllMethods().iterator(); MS.hasNext();) {
IMethod m = (IMethod) MS.next();
if ((m instanceof AstMethod) && !m.isStatic()) {
AstMethod M = (AstMethod) m;
LexicalParent[] parents = M.getParents();
for (int i = 0; i < parents.length; i++) {
result.add(parents[i]);
}
}
if (!result.isEmpty()) {
if (AstTranslator.DEBUG_LEXICAL)
System.err.println((base + " has parents: " + result));
return (LexicalParent[]) result.toArray(new LexicalParent[result.size()]);
}
} catch (ClassHierarchyException e) {
Assertions.UNREACHABLE();
}
if (!result.isEmpty()) {
if (AstTranslator.DEBUG_LEXICAL)
System.err.println((base + " has parents: " + result));
return (LexicalParent[]) result.toArray(new LexicalParent[result.size()]);
}
}
if (AstTranslator.DEBUG_LEXICAL)

View File

@ -202,7 +202,7 @@ abstract public class AstClass implements IClass, ClassConstants {
return result;
}
public Collection<IMethod> getAllMethods() throws ClassHierarchyException {
public Collection<IMethod> getAllMethods() {
Collection<IMethod> result = HashSetFactory.make();
for (Iterator<IMethod> ms = getDeclaredMethods().iterator(); ms.hasNext();) {
result.add(ms.next());

View File

@ -23,7 +23,6 @@ import com.ibm.wala.classLoader.IMethod;
import com.ibm.wala.classLoader.NewSiteReference;
import com.ibm.wala.ipa.callgraph.CGNode;
import com.ibm.wala.ipa.callgraph.propagation.SSAContextInterpreter;
import com.ibm.wala.ipa.cha.ClassHierarchyException;
import com.ibm.wala.ipa.summaries.SyntheticIR;
import com.ibm.wala.ssa.ConstantValue;
import com.ibm.wala.ssa.DefUse;
@ -45,19 +44,19 @@ import com.ibm.wala.util.collections.NonNullSingletonIterator;
import com.ibm.wala.util.debug.Assertions;
/**
* An {@link SSAContextInterpreter} specialized to interpret methods on java.lang.Class in a {@link JavaTypeContext}
* which represents the point-type of the class object created by the call.
* An {@link SSAContextInterpreter} specialized to interpret methods on java.lang.Class in a {@link JavaTypeContext} which
* represents the point-type of the class object created by the call.
*
* Currently supported methods:
* <ul>
* <li> getConstructor
* <li> getConstructors
* <li> getMethod
* <li> getMethods
* <li> getDeclaredConstructor
* <li> getDeclaredConstructors
* <li> getDeclaredMethod
* <li> getDeclaredMethods
* <li>getConstructor
* <li>getConstructors
* <li>getMethod
* <li>getMethods
* <li>getDeclaredConstructor
* <li>getDeclaredConstructors
* <li>getDeclaredMethod
* <li>getDeclaredMethods
* </ul>
*
* @author pistoia
@ -67,28 +66,28 @@ public class JavaLangClassContextInterpreter implements SSAContextInterpreter {
public final static MethodReference GET_CONSTRUCTOR = MethodReference.findOrCreate(TypeReference.JavaLangClass, "getConstructor",
"([Ljava/lang/Class;)Ljava/lang/reflect/Constructor;");
public final static MethodReference GET_CONSTRUCTORS = MethodReference.findOrCreate(TypeReference.JavaLangClass,
"getConstructors", "()[Ljava/lang/reflect/Constructor;");
public final static MethodReference GET_METHOD = MethodReference.findOrCreate(TypeReference.JavaLangClass, "getMethod",
"(Ljava/lang/String;[Ljava/lang/Class;)Ljava/lang/reflect/Method;");
public final static MethodReference GET_METHODS = MethodReference.findOrCreate(TypeReference.JavaLangClass, "getMethods",
"()[Ljava/lang/reflect/Method;");
public final static MethodReference GET_DECLARED_CONSTRUCTOR = MethodReference.findOrCreate(TypeReference.JavaLangClass,
"getDeclaredConstructor", "([Ljava/lang/Class;)Ljava/lang/reflect/Constructor;");
public final static MethodReference GET_DECLARED_CONSTRUCTORS = MethodReference.findOrCreate(TypeReference.JavaLangClass,
"getDeclaredConstructors", "()[Ljava/lang/reflect/Constructor;");
public final static MethodReference GET_DECLARED_METHOD = MethodReference.findOrCreate(TypeReference.JavaLangClass,
"getDeclaredMethod", "(Ljava/lang/String;[Ljava/lang/Class;)Ljava/lang/reflect/Method;");
public final static MethodReference GET_DECLARED_METHODS = MethodReference.findOrCreate(TypeReference.JavaLangClass,
"getDeclaredMethods", "()[Ljava/lang/reflect/Method;");
private static final boolean DEBUG = false;
/*
@ -172,10 +171,9 @@ public class JavaLangClassContextInterpreter implements SSAContextInterpreter {
return false;
}
MethodReference mRef = node.getMethod().getReference();
return mRef.equals(GET_CONSTRUCTOR) || mRef.equals(GET_CONSTRUCTORS)
|| mRef.equals(GET_METHOD) || mRef.equals(GET_METHODS)
|| mRef.equals(GET_DECLARED_CONSTRUCTOR) || mRef.equals(GET_DECLARED_CONSTRUCTORS)
|| mRef.equals(GET_DECLARED_METHOD) || mRef.equals(GET_DECLARED_METHODS);
return mRef.equals(GET_CONSTRUCTOR) || mRef.equals(GET_CONSTRUCTORS) || mRef.equals(GET_METHOD) || mRef.equals(GET_METHODS)
|| mRef.equals(GET_DECLARED_CONSTRUCTOR) || mRef.equals(GET_DECLARED_CONSTRUCTORS) || mRef.equals(GET_DECLARED_METHOD)
|| mRef.equals(GET_DECLARED_METHODS);
}
public Iterator<NewSiteReference> iterateNewSites(CGNode node) {
@ -212,19 +210,14 @@ public class JavaLangClassContextInterpreter implements SSAContextInterpreter {
}
return result;
}
/**
* Get all non-constructor, non-class-initializer methods declared by a class and all its superclasses
*/
private Collection<IMethod> getAllNormalPublicMethods(IClass cls) {
Collection<IMethod> result = HashSetFactory.make();
Collection<IMethod> allMethods = null;
try {
allMethods = cls.getAllMethods();
} catch (ClassHierarchyException e) {
Assertions.UNREACHABLE();
e.printStackTrace();
}
allMethods = cls.getAllMethods();
for (IMethod m : allMethods) {
if (!m.isInit() && !m.isClinit() && m.isPublic()) {
result.add(m);
@ -232,7 +225,6 @@ public class JavaLangClassContextInterpreter implements SSAContextInterpreter {
}
return result;
}
/**
* Get all the constructors of a class
@ -246,7 +238,7 @@ public class JavaLangClassContextInterpreter implements SSAContextInterpreter {
}
return result;
}
/**
* Get all the public constructors of a class
*/
@ -287,8 +279,8 @@ public class JavaLangClassContextInterpreter implements SSAContextInterpreter {
int index = i++;
int indexVn = nextLocal++;
constants.put(indexVn, new ConstantValue(index));
SSAArrayStoreInstruction store = insts.ArrayStoreInstruction(retValue, indexVn, c,
TypeReference.JavaLangReflectConstructor);
SSAArrayStoreInstruction store = insts
.ArrayStoreInstruction(retValue, indexVn, c, TypeReference.JavaLangReflectConstructor);
statements.add(store);
}
SSAReturnInstruction R = insts.ReturnInstruction(retValue, false);
@ -307,9 +299,8 @@ public class JavaLangClassContextInterpreter implements SSAContextInterpreter {
}
/**
* create statements for methods like getConstructor() and getDeclaredMethod(), which return a single method. This
* creates a return statement for each possible return value, each of which is a {@link ConstantValue} for an
* {@link IMethod}.
* create statements for methods like getConstructor() and getDeclaredMethod(), which return a single method. This creates a
* return statement for each possible return value, each of which is a {@link ConstantValue} for an {@link IMethod}.
*
* @param returnValues the possible return values for this method.
*/
@ -338,7 +329,7 @@ public class JavaLangClassContextInterpreter implements SSAContextInterpreter {
}
return result;
}
/**
* create statements for getConstructor()
*/
@ -350,8 +341,8 @@ public class JavaLangClassContextInterpreter implements SSAContextInterpreter {
return getParticularMethodStatements(GET_CONSTRUCTOR, getPublicConstructors(cls), context, constants);
}
}
//TODO
// TODO
private SSAInstruction[] makeGetCtorsStatements(JavaTypeContext context, Map<Integer, ConstantValue> constants) {
IClass cls = context.getType().getType();
if (cls == null) {
@ -360,7 +351,7 @@ public class JavaLangClassContextInterpreter implements SSAContextInterpreter {
return getMethodArrayStatements(GET_DECLARED_CONSTRUCTORS, getPublicConstructors(cls), context, constants);
}
}
private SSAInstruction[] makeGetMethodStatements(JavaTypeContext context, Map<Integer, ConstantValue> constants) {
IClass cls = context.getType().getType();
if (cls == null) {
@ -369,7 +360,7 @@ public class JavaLangClassContextInterpreter implements SSAContextInterpreter {
return getParticularMethodStatements(GET_METHOD, getAllNormalPublicMethods(cls), context, constants);
}
}
private SSAInstruction[] makeGetMethodsStatments(JavaTypeContext context, Map<Integer, ConstantValue> constants) {
IClass cls = context.getType().getType();
if (cls == null) {
@ -390,7 +381,7 @@ public class JavaLangClassContextInterpreter implements SSAContextInterpreter {
return getParticularMethodStatements(GET_DECLARED_CONSTRUCTOR, getConstructors(cls), context, constants);
}
}
private SSAInstruction[] makeGetDeclCtorsStatements(JavaTypeContext context, Map<Integer, ConstantValue> constants) {
IClass cls = context.getType().getType();
if (cls == null) {
@ -399,7 +390,7 @@ public class JavaLangClassContextInterpreter implements SSAContextInterpreter {
return getMethodArrayStatements(GET_DECLARED_CONSTRUCTORS, getConstructors(cls), context, constants);
}
}
/**
* create statements for getDeclaredMethod()
*/
@ -411,7 +402,7 @@ public class JavaLangClassContextInterpreter implements SSAContextInterpreter {
return getParticularMethodStatements(GET_DECLARED_METHOD, getDeclaredNormalMethods(cls), context, constants);
}
}
/**
* create statements for getDeclaredMethod()
*/
@ -423,7 +414,7 @@ public class JavaLangClassContextInterpreter implements SSAContextInterpreter {
return getMethodArrayStatements(GET_DECLARED_METHODS, getDeclaredNormalMethods(cls), context, constants);
}
}
public boolean recordFactoryType(CGNode node, IClass klass) {
return false;
}

View File

@ -295,7 +295,7 @@ public class ArrayClass implements IClass, Constants {
/*
* @see com.ibm.wala.classLoader.IClass#getAllMethods()
*/
public Collection<IMethod> getAllMethods() throws UnimplementedError, ClassHierarchyException {
public Collection<IMethod> getAllMethods() {
return loader.lookupClass(getClassLoader().getLanguage().getRootType().getName()).getAllMethods();
}

View File

@ -317,7 +317,7 @@ public abstract class BytecodeClass<T extends IClassLoader> implements IClass {
/*
* @see com.ibm.wala.classLoader.IClass#getAllMethods()
*/
public Collection<IMethod> getAllMethods() throws ClassHierarchyException {
public Collection<IMethod> getAllMethods() {
Collection<IMethod> result = new LinkedList<IMethod>();
Iterator<IMethod> declaredMethods = getDeclaredMethods().iterator();
while (declaredMethods.hasNext()) {

View File

@ -134,7 +134,7 @@ public interface IClass extends IClassHierarchyDweller {
/**
* Compute the methods declared by this class or any of its superclasses.
*/
Collection<IMethod> getAllMethods() throws ClassHierarchyException;
Collection<IMethod> getAllMethods();
/**
* Compute the instance fields declared by this class.

View File

@ -219,7 +219,7 @@ public class FakeRootClass extends SyntheticClass {
/*
* @see com.ibm.wala.classLoader.IClass#getAllMethods()
*/
public Collection<IMethod> getAllMethods() throws UnsupportedOperationException, ClassHierarchyException {
public Collection<IMethod> getAllMethods() {
throw new UnsupportedOperationException();
}

View File

@ -221,7 +221,7 @@ public class BypassSyntheticClass extends SyntheticClass {
/*
* @see com.ibm.wala.classLoader.IClass#getAllMethods()
*/
public Collection<IMethod> getAllMethods() throws ClassHierarchyException {
public Collection<IMethod> getAllMethods() {
return realType.getAllMethods();
}

View File

@ -77,7 +77,7 @@ public class ActionFormFactoryMethod extends SummarizedMethod {
return Collections.emptySet();
}
public Collection<IMethod> getAllMethods() throws ClassHierarchyException {
public Collection<IMethod> getAllMethods() {
// TODO Auto-generated method stub
assert false;
return null;