use of com.google.devtools.treeshaker.ElementReferenceMapper.MethodReferenceNode in project j2objc by google.
the class ElementReferenceMapperTest method testMethodInvocation.
public void testMethodInvocation() throws IOException {
String source = "class A {\n" + " private static void foo(String s) {final int bro = 1;}\n" + " private static void bar(String s) {foo(\"boo\");}\n" + " static { bar(\"bro\"); }\n" + "}\n";
CompilationUnit unit = compileType("test", source);
final HashMap<String, ReferenceNode> elementReferenceMap = new HashMap<>();
final HashMap<String, Set<String>> overrideMap = new HashMap<>();
final Set<String> staticSet = new HashSet<>();
ElementReferenceMapper mapper = new ElementReferenceMapper(unit, elementReferenceMap, staticSet, overrideMap);
mapper.run();
Set<String> elementSet = elementReferenceMap.keySet();
assertTrue(elementSet.contains(ElementReferenceMapper.stitchClassIdentifier("A")));
assertTrue(elementSet.contains(ElementReferenceMapper.stitchMethodIdentifier("A", "foo", "(Ljava/lang/String;)V")));
assertTrue(elementSet.contains(ElementReferenceMapper.stitchMethodIdentifier("A", "bar", "(Ljava/lang/String;)V")));
assertTrue(((MethodReferenceNode) elementReferenceMap.get(ElementReferenceMapper.stitchMethodIdentifier("A", "bar", "(Ljava/lang/String;)V"))).invokedMethods.contains(ElementReferenceMapper.stitchMethodIdentifier("A", "foo", "(Ljava/lang/String;)V")));
}
use of com.google.devtools.treeshaker.ElementReferenceMapper.MethodReferenceNode in project j2objc by google.
the class UnusedCodeTracker method traverseMethod.
/**
* Traverses the method invocation graph created by ElementReferenceMapper, and marks all methods
* that are reachable from the inputRootSet. Also covers all methods that possibly override these
* called methods.
* @param methodID
*/
public void traverseMethod(String methodID) {
MethodReferenceNode node = (MethodReferenceNode) elementReferenceMap.get(methodID);
if (node == null) {
//TODO(malvania): This might never be reached, because we create a node for every method,
// both invoked and declared.
ErrorUtil.warning("Encountered .class method while accessing: " + methodID);
return;
}
if (node.reachable) {
return;
}
node.reachable = true;
markParentClasses(ElementUtil.getDeclaringClass(node.methodElement));
for (String invokedMethodID : node.invokedMethods) {
traverseMethod(invokedMethodID);
}
for (String overrideMethodID : node.overridingMethods) {
traverseMethod(overrideMethodID);
}
}
Aggregations