예제 #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);
  }
예제 #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;
  }
예제 #3
0
 @Override
 public MethodDependency getMethodImplementation(MethodReference methodRef) {
   MethodReader method = methodReaderCache.map(methodRef);
   return method != null ? methodCache.getKnown(method.getReference()) : null;
 }