Search in sources :

Example 1 with ClassReferenceNode

use of com.google.devtools.treeshaker.ElementReferenceMapper.ClassReferenceNode in project j2objc by google.

the class UnusedCodeTracker method markUsedElements.

/**
   * Add to root set, methods from CodeReferenceMap and also all public methods in input classes.
   * Then, do tree shaker traversal starting from this root set.
   * @param publicRootSet: CodeReferenceMap with public root methods and classes.
   */
//TODO(malvania): Current paradigm: All methods in input CodeReferenceMap are assumed to be 
//  public roots to traverse from.
//Classes in input CodeReferenceMap here allow user to add Dynamically Loaded Classes and keep
//  their public methods in the public root set.
//In the future, when we add support for libraries, we will want to include protected methods
//  of those library classes as well, so we should add "|| ElementUtil.isProtected(method)" after
//  the isPublic check.
public void markUsedElements(CodeReferenceMap publicRootSet) {
    if (publicRootSet == null) {
        markUsedElements();
        return;
    }
    //Add all public methods in publicRootClasses to root set
    for (String clazz : publicRootSet.getReferencedClasses()) {
        ClassReferenceNode classNode = (ClassReferenceNode) elementReferenceMap.get(ElementReferenceMapper.stitchClassIdentifier(clazz));
        assert (classNode != null);
        Iterable<ExecutableElement> methods = ElementUtil.getMethods(classNode.classElement);
        for (ExecutableElement method : methods) {
            if (ElementUtil.isPublic(method)) {
                rootSet.add(ElementReferenceMapper.stitchMethodIdentifier(method, env.typeUtil(), env.elementUtil()));
            }
        }
    }
    //Add input root methods to static set
    for (Table.Cell<String, String, ImmutableSet<String>> cell : publicRootSet.getReferencedMethods().cellSet()) {
        String clazzName = cell.getRowKey();
        String methodName = cell.getColumnKey();
        for (String signature : cell.getValue()) {
            rootSet.add(ElementReferenceMapper.stitchMethodIdentifier(clazzName, methodName, signature));
        }
    }
    markUsedElements(staticSet);
    markUsedElements(rootSet);
}
Also used : Table(com.google.common.collect.Table) ImmutableSet(com.google.common.collect.ImmutableSet) ExecutableElement(javax.lang.model.element.ExecutableElement) ClassReferenceNode(com.google.devtools.treeshaker.ElementReferenceMapper.ClassReferenceNode)

Aggregations

ImmutableSet (com.google.common.collect.ImmutableSet)1 Table (com.google.common.collect.Table)1 ClassReferenceNode (com.google.devtools.treeshaker.ElementReferenceMapper.ClassReferenceNode)1 ExecutableElement (javax.lang.model.element.ExecutableElement)1