Exemplo n.º 1
0
  public DependencyChecker(
      ClassReaderSource classSource,
      ClassLoader classLoader,
      ServiceRepository services,
      Diagnostics diagnostics) {
    this.diagnostics = diagnostics;
    this.classSource = new DependencyClassSource(classSource, diagnostics);
    this.classLoader = classLoader;
    this.services = services;
    methodReaderCache = new CachedMapper<>(preimage -> this.classSource.resolveMutable(preimage));
    fieldReaderCache = new CachedMapper<>(preimage -> this.classSource.resolveMutable(preimage));
    methodCache =
        new CachedMapper<>(
            preimage -> {
              MethodHolder method = methodReaderCache.map(preimage);
              if (method != null && !method.getReference().equals(preimage)) {
                return methodCache.map(method.getReference());
              }
              return createMethodDep(preimage, method);
            });
    fieldCache =
        new CachedMapper<>(
            preimage -> {
              FieldReader field = fieldReaderCache.map(preimage);
              if (field != null && !field.getReference().equals(preimage)) {
                return fieldCache.map(field.getReference());
              }
              return createFieldNode(preimage, field);
            });

    classCache = new CachedMapper<>(this::createClassDependency);

    agent = new DependencyAgent(this);
  }
Exemplo n.º 2
0
  public MethodDependency linkMethod(MethodReference methodRef, CallLocation callLocation) {
    if (methodRef == null) {
      throw new IllegalArgumentException();
    }
    MethodReader methodReader = methodReaderCache.map(methodRef);
    if (methodReader != null) {
      methodRef = methodReader.getReference();
    }

    if (completing && getMethod(methodRef) == null) {
      throw new IllegalStateException("Can't submit class during completion phase");
    }
    callGraph.getNode(methodRef);
    boolean added = true;
    if (callLocation != null && callLocation.getMethod() != null) {
      added =
          callGraph
              .getNode(callLocation.getMethod())
              .addCallSite(methodRef, callLocation.getSourceLocation());
    } else {
      added = methodsAddedByRoot.add(methodRef);
    }
    MethodDependency graph = methodCache.map(methodRef);
    if (!graph.isMissing() && added) {
      for (DependencyListener listener : listeners) {
        listener.methodReached(agent, graph, callLocation);
      }
      activateDependencyPlugin(graph, callLocation);
    }
    return graph;
  }
Exemplo n.º 3
0
 public FieldDependency linkField(FieldReference fieldRef, CallLocation location) {
   if (completing) {
     throw new IllegalStateException("Can't submit class during completion phase");
   }
   boolean added = true;
   if (location != null) {
     added =
         callGraph
             .getNode(location.getMethod())
             .addFieldAccess(fieldRef, location.getSourceLocation());
   } else {
     added = fieldsAddedByRoot.add(fieldRef);
   }
   FieldDependency dep = fieldCache.map(fieldRef);
   if (!dep.isMissing()) {
     tasks.add(() -> linkClass(fieldRef.getClassName(), location).initClass(location));
   }
   if (!dep.isMissing() && added) {
     for (DependencyListener listener : listeners) {
       listener.fieldReached(agent, dep, location);
     }
   }
   return dep;
 }
Exemplo n.º 4
0
 public ClassDependency linkClass(String className, CallLocation callLocation) {
   if (completing && getClass(className) == null) {
     throw new IllegalStateException("Can't link class during completion phase");
   }
   ClassDependency dep = classCache.map(className);
   boolean added = true;
   if (callLocation != null && callLocation.getMethod() != null) {
     DefaultCallGraphNode callGraphNode = callGraph.getNode(callLocation.getMethod());
     if (!addClassAccess(callGraphNode, className, callLocation.getSourceLocation())) {
       added = false;
     }
   } else {
     added = classesAddedByRoot.add(className);
   }
   if (!dep.isMissing() && added) {
     tasks.add(
         () -> {
           for (DependencyListener listener : listeners) {
             listener.classReached(agent, className, callLocation);
           }
         });
   }
   return dep;
 }
Exemplo n.º 5
0
 @Override
 public MethodDependency getMethodImplementation(MethodReference methodRef) {
   MethodReader method = methodReaderCache.map(methodRef);
   return method != null ? methodCache.getKnown(method.getReference()) : null;
 }
Exemplo n.º 6
0
 @Override
 public MethodDependency getMethod(MethodReference methodRef) {
   return methodCache.getKnown(methodRef);
 }
Exemplo n.º 7
0
 @Override
 public ClassDependency getClass(String className) {
   return classCache.getKnown(className);
 }
Exemplo n.º 8
0
 @Override
 public FieldDependency getField(FieldReference fieldRef) {
   return fieldCache.getKnown(fieldRef);
 }
Exemplo n.º 9
0
 @Override
 public Collection<String> getReachableClasses() {
   return classCache.getCachedPreimages();
 }
Exemplo n.º 10
0
 @Override
 public Collection<FieldReference> getReachableFields() {
   return fieldCache.getCachedPreimages();
 }
Exemplo n.º 11
0
 @Override
 public Collection<MethodReference> getReachableMethods() {
   return methodCache.getCachedPreimages();
 }