2007-02-02 17:20:09 +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
|
|
|
|
*****************************************************************************/
|
|
|
|
package com.ibm.wala.cast.java.ipa.callgraph;
|
|
|
|
|
2012-07-12 17:27:24 +00:00
|
|
|
import java.util.Collection;
|
|
|
|
import java.util.Collections;
|
2007-02-02 17:20:09 +00:00
|
|
|
import java.util.Iterator;
|
|
|
|
import java.util.Set;
|
2007-07-06 22:08:34 +00:00
|
|
|
|
2007-02-02 17:20:09 +00:00
|
|
|
import com.ibm.wala.cast.ipa.callgraph.ScopeMappingInstanceKeys;
|
|
|
|
import com.ibm.wala.cast.ir.translator.AstTranslator;
|
|
|
|
import com.ibm.wala.cast.java.loader.JavaSourceLoaderImpl.JavaClass;
|
|
|
|
import com.ibm.wala.cast.loader.AstMethod;
|
|
|
|
import com.ibm.wala.cast.loader.AstMethod.LexicalParent;
|
2007-07-06 22:08:34 +00:00
|
|
|
import com.ibm.wala.classLoader.IClass;
|
|
|
|
import com.ibm.wala.classLoader.IMethod;
|
2012-07-12 17:27:24 +00:00
|
|
|
import com.ibm.wala.ipa.callgraph.CGNode;
|
2007-02-02 17:20:09 +00:00
|
|
|
import com.ibm.wala.ipa.callgraph.propagation.InstanceKey;
|
|
|
|
import com.ibm.wala.ipa.callgraph.propagation.InstanceKeyFactory;
|
|
|
|
import com.ibm.wala.ipa.callgraph.propagation.PropagationCallGraphBuilder;
|
2007-07-06 22:08:34 +00:00
|
|
|
import com.ibm.wala.ipa.cha.IClassHierarchy;
|
2007-07-11 21:07:19 +00:00
|
|
|
import com.ibm.wala.util.collections.HashSetFactory;
|
2012-07-12 17:27:24 +00:00
|
|
|
import com.ibm.wala.util.collections.Pair;
|
2007-02-02 17:20:09 +00:00
|
|
|
|
|
|
|
public class JavaScopeMappingInstanceKeys extends ScopeMappingInstanceKeys {
|
|
|
|
|
2007-06-01 03:37:03 +00:00
|
|
|
public JavaScopeMappingInstanceKeys(IClassHierarchy cha, PropagationCallGraphBuilder builder, InstanceKeyFactory basic) {
|
2007-02-02 17:20:09 +00:00
|
|
|
super(builder, basic);
|
2007-02-09 15:33:10 +00:00
|
|
|
|
2007-02-02 17:20:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
protected LexicalParent[] getParents(InstanceKey base) {
|
|
|
|
IClass cls = base.getConcreteType();
|
2007-02-14 16:20:33 +00:00
|
|
|
if (isPossiblyLexicalClass(cls)) {
|
2009-05-01 12:50:17 +00:00
|
|
|
Set<LexicalParent> result = HashSetFactory.make();
|
2007-02-02 17:20:09 +00:00
|
|
|
|
2009-05-01 12:50:17 +00:00
|
|
|
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]);
|
2007-02-09 15:33:10 +00:00
|
|
|
}
|
|
|
|
}
|
2009-05-01 12:50:17 +00:00
|
|
|
}
|
2007-02-02 17:20:09 +00:00
|
|
|
|
2009-05-01 12:50:17 +00:00
|
|
|
if (!result.isEmpty()) {
|
|
|
|
if (AstTranslator.DEBUG_LEXICAL)
|
|
|
|
System.err.println((base + " has parents: " + result));
|
2007-02-09 15:33:10 +00:00
|
|
|
|
2009-05-01 12:50:17 +00:00
|
|
|
return (LexicalParent[]) result.toArray(new LexicalParent[result.size()]);
|
2007-02-02 17:20:09 +00:00
|
|
|
}
|
2009-05-01 12:50:17 +00:00
|
|
|
|
2007-02-02 17:20:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (AstTranslator.DEBUG_LEXICAL)
|
2009-04-09 20:31:14 +00:00
|
|
|
System.err.println((base + " has no parents"));
|
2007-02-02 17:20:09 +00:00
|
|
|
|
|
|
|
return new LexicalParent[0];
|
|
|
|
}
|
|
|
|
|
2007-02-14 16:20:33 +00:00
|
|
|
protected boolean isPossiblyLexicalClass(IClass cls) {
|
|
|
|
return cls instanceof JavaClass;
|
|
|
|
}
|
|
|
|
|
2007-02-02 17:20:09 +00:00
|
|
|
protected boolean needsScopeMappingKey(InstanceKey base) {
|
|
|
|
boolean result = getParents(base).length > 0;
|
2007-02-09 15:33:10 +00:00
|
|
|
if (AstTranslator.DEBUG_LEXICAL)
|
2009-04-09 20:31:14 +00:00
|
|
|
System.err.println(("does " + base + " need scope mapping? " + result));
|
2007-02-02 17:20:09 +00:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
2012-07-12 17:27:24 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
protected Collection<CGNode> getConstructorCallers(ScopeMappingInstanceKey smik, Pair<String, String> name) {
|
|
|
|
// for Java, the creator node is exactly what we want
|
|
|
|
return Collections.singleton(smik.getCreator());
|
|
|
|
}
|
|
|
|
|
2007-02-02 17:20:09 +00:00
|
|
|
}
|