@Override public ClassReaderSource getClassSource() { return agent.getClassSource(); } }
@Override public void started(DependencyAgent agent) { characteristics = new Characteristics(agent.getClassSource()); }
@Override public void classReached(DependencyAgent agent, String className) { ClassReader cls = agent.getClassSource().get(className); if (cls == null || cls.getParent() == null || !cls.getParent().equals("java.lang.Enum")) { return; } allEnums.propagate(agent.getType(className)); }
private String getAnnotationImplementor(DependencyAgent agent, String annotationType) { String implementorName = annotationType + "$$_impl"; if (agent.getClassSource().get(implementorName) == null) { ClassHolder implementor = createImplementor(agent.getClassHierarchy(), annotationType, implementorName); agent.submitClass(implementor); } return implementorName; }
@Override public void started(DependencyAgent agent) { proxyClassLoader = new MetaprogrammingClassLoader(agent.getClassLoader()); describer = new MethodDescriber(agent.getDiagnostics(), agent.getClassSource()); MetaprogrammingImpl.classLoader = proxyClassLoader; MetaprogrammingImpl.classSource = agent.getClassSource(); MetaprogrammingImpl.hierarchy = agent.getClassHierarchy(); MetaprogrammingImpl.incrementalDependencies = agent.getIncrementalCache(); MetaprogrammingImpl.agent = agent; MetaprogrammingImpl.reflectContext = new ReflectContext(agent.getClassHierarchy(), proxyClassLoader); }
@Override public void classReached(DependencyAgent agent, String className) { ClassReader cls = agent.getClassSource().get(className); if (cls != null && !cls.hasModifier(ElementModifier.ABSTRACT) && !cls.hasModifier(ElementModifier.INTERFACE)) { allClassesNode.propagate(agent.getType(className)); } }
@Override public void classReached(DependencyAgent agent, String className) { for (MethodReader reader : agent.getClassSource().get(className).getMethods()) { AnnotationReader annotation = reader.getAnnotations().get(Export.class.getName()); if (annotation != null) { agent.linkMethod(reader.getReference()).use(); } } }
private void reachFunctorMethods(DependencyAgent agent, String type) { ClassReader cls = agent.getClassSource().get(type); if (cls != null) { for (MethodReader method : cls.getMethods()) { if (!method.hasModifier(ElementModifier.STATIC)) { agent.linkMethod(method.getReference()).use(); } } } }
@Override public void classReached(DependencyAgent agent, String className) { ClassReader cls = agent.getClassSource().get(className); if (cls == null) { return; } if (cls.hasModifier(ElementModifier.ABSTRACT) || cls.hasModifier(ElementModifier.INTERFACE)) { return; } MethodReader method = cls.getMethod(INIT_METHOD); if (method != null) { allClassesNode.propagate(agent.getType(className)); } }
private void createAnnotationClass(DependencyAgent agent, String className) { String readerClassName = className + "$$__annotations__$$"; if (agent.getClassSource().get(readerClassName) != null) { return; } ClassHolder cls = new ClassHolder(className + "$$__annotations__$$"); cls.setLevel(AccessLevel.PUBLIC); cls.setOwnerName("java.lang.Object"); cls.getInterfaces().add(PlatformAnnotationProvider.class.getName()); MethodHolder ctor = new MethodHolder("<init>", ValueType.VOID); ctor.setLevel(AccessLevel.PUBLIC); ProgramEmitter pe = ProgramEmitter.create(ctor, agent.getClassHierarchy()); ValueEmitter thisVar = pe.var(0, cls); thisVar.invokeSpecial(Object.class, "<init>").exit(); ClassReader annotatedClass = agent.getClassSource().get(className); cls.addMethod(ctor); cls.addMethod(addReader(agent, annotatedClass)); agent.submitClass(cls); }
@Override public void classReached(DependencyAgent agent, String className) { ClassReader cls = agent.getClassSource().get(className); for (MethodReader method : cls.getMethods()) { AnnotationReader exposeAnnot = method.getAnnotations().get(JSMethodToExpose.class.getName()); if (exposeAnnot != null) { MethodDependency methodDep = agent.linkMethod(method.getReference()); methodDep.getVariable(0).propagate(agent.getType(className)); methodDep.use(); } } } }
@Override public void started(DependencyAgent agent) { allClasses = agent.createNode(); allClasses.addConsumer(c -> { if (agent.getClassSource().isSuperType("java.lang.Throwable", c.getName()).orElse(false)) { MethodDependency methodDep = agent.linkMethod(new MethodReference(c.getName(), GET_MESSAGE)); methodDep.getVariable(0).propagate(c); methodDep.use(); } }); agent.linkClass("java.lang.Throwable"); }
private void reachGetInterfaces(DependencyAgent agent, MethodDependency method) { method.getVariable(0).getClassValueNode().addConsumer(type -> { String className = type.getName(); if (className.startsWith("[")) { return; } ClassReader cls = agent.getClassSource().get(className); if (cls != null) { for (String iface : cls.getInterfaces()) { method.getResult().getClassValueNode().propagate(agent.getType(iface)); } } }); }
private void reachGetSuperclass(DependencyAgent agent, MethodDependency method) { method.getVariable(0).getClassValueNode().addConsumer(type -> { String className = type.getName(); if (className.startsWith("[")) { return; } ClassReader cls = agent.getClassSource().get(className); if (cls != null && cls.getParent() != null) { method.getResult().getClassValueNode().propagate(agent.getType(cls.getParent())); } }); }
private ValueEmitter generateAnnotationInstance(DependencyAgent agent, ProgramEmitter pe, AnnotationReader annotation) { ClassReader annotationClass = agent.getClassSource().get(annotation.getType()); if (annotationClass == null) { return pe.constantNull(ValueType.object(annotation.getType())); } String className = getAnnotationImplementor(agent, annotation.getType()); List<ValueEmitter> params = new ArrayList<>(); for (MethodReader methodDecl : annotationClass.getMethods()) { AnnotationValue value = annotation.getValue(methodDecl.getName()); if (value == null) { value = methodDecl.getAnnotationDefault(); } params.add(generateAnnotationValue(agent, pe, methodDecl.getResultType(), value) .cast(methodDecl.getResultType())); } return pe.construct(className, params.toArray(new ValueEmitter[0])); }
private void reachGetAnnotations(DependencyAgent agent, DependencyNode node) { node.getClassValueNode().addConsumer(type -> { String className = type.getName(); ClassReader cls = agent.getClassSource().get(className); if (cls == null) { return; } for (AnnotationReader annotation : cls.getAnnotations().all()) { agent.linkClass(annotation.getType()); } createAnnotationClass(agent, className); }); }
@Override public void methodReached(DependencyAgent agent, MethodDependency method) { AnnotationReader delegateAnnot = method.getMethod().getAnnotations().get(DelegateTo.class.getName()); if (delegateAnnot != null) { String delegateMethodName = delegateAnnot.getValue("value").getString(); ClassReader cls = agent.getClassSource().get(method.getReference().getClassName()); for (MethodReader delegate : cls.getMethods()) { if (delegate.getName().equals(delegateMethodName)) { if (delegate != method.getMethod()) { MethodDependency dep = agent.linkMethod(delegate.getReference()); dep.use(); method.addLocationListener(dep::addLocation); } } } } }
@Override public void methodReached(DependencyAgent agent, MethodDependency method) { AnnotationReader delegateAnnot = method.getMethod().getAnnotations().get(DelegateTo.class.getName()); if (delegateAnnot != null) { String delegateMethodName = delegateAnnot.getValue("value").getString(); ClassReader cls = agent.getClassSource().get(method.getReference().getClassName()); for (MethodReader delegate : cls.getMethods()) { if (delegate.getName().equals(delegateMethodName)) { if (delegate != method.getMethod()) { MethodDependency delegateDep = agent.linkMethod(delegate.getReference()); method.addLocationListener(delegateDep::addLocation); delegateDep.use(); } } } } }
@Override public void methodReached(DependencyAgent agent, MethodDependency methodDep) { MethodModel proxy = describer.getMethod(methodDep.getReference()); if (proxy != null && installedProxies.add(proxy)) { agent.getIncrementalCache().setNoCache(methodDep.getReference()); ClassReader cls = agent.getClassSource().get(methodDep.getMethod().getOwnerName()); int index = 0; for (MethodReader method : cls.getMethods()) { if (method.getDescriptor().equals(methodDep.getMethod().getDescriptor())) { break; } ++index; } new UsageGenerator(agent, proxy, methodDep, proxyClassLoader, index).installProxyEmitter(); } }
@Override public void consume(DependencyType type) { if (!agent.getClassHierarchy().isSuperType(superMethod.getClassName(), type.getName(), false)) { return; } MethodReader method = agent.getClassSource().resolveImplementation(new MethodReference( type.getName(), superMethod.getDescriptor())); if (method == null) { return; } virtualMethods.add(method.getReference()); MethodDependency methodDep = agent.linkMethod(method.getReference()); methodDep.use(); for (int i = 0; i < methodDep.getParameterCount(); ++i) { allClassesNode.connect(methodDep.getVariable(i)); allClassesNode.connect(methodDep.getVariable(i).getArrayItem()); } } }