@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 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 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); }
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; }
private void linkType(DependencyAgent agent, ValueType type) { while (type instanceof ValueType.Array) { type = ((ValueType.Array) type).getItemType(); } if (type instanceof ValueType.Object) { String className = ((ValueType.Object) type).getClassName(); agent.linkClass(className); typesInReflectableSignaturesNode.propagate(agent.getType(className)); } }
private void includeDefaultDependencies(DependencyAgent agent) { agent.linkMethod(JavaScriptConvGenerator.fromJsMethod).use(); agent.linkMethod(JavaScriptConvGenerator.toJsMethod).use(); agent.linkMethod(JavaScriptConvGenerator.intValueMethod).propagate(0, Integer.class).use(); agent.linkMethod(JavaScriptConvGenerator.valueOfIntMethod).use(); agent.linkMethod(JavaScriptConvGenerator.booleanValueMethod).propagate(0, Boolean.class).use(); agent.linkMethod(JavaScriptConvGenerator.valueOfBooleanMethod).use(); agent.linkMethod(JavaScriptConvGenerator.doubleValueMethod).propagate(0, Double.class).use(); agent.linkMethod(JavaScriptConvGenerator.valueOfDoubleMethod).use(); agent.linkMethod(JavaScriptConvGenerator.charValueMethod).propagate(0, Character.class).use(); agent.linkMethod(JavaScriptConvGenerator.valueOfCharMethod).use(); agent.linkMethod(JavaScriptConvGenerator.byteValueMethod).propagate(0, Byte.class).use(); agent.linkMethod(JavaScriptConvGenerator.valueOfByteMethod).use(); agent.linkMethod(JavaScriptConvGenerator.shortValueMethod).propagate(0, Short.class).use(); agent.linkMethod(JavaScriptConvGenerator.valueOfShortMethod).use(); agent.linkMethod(JavaScriptConvGenerator.valueOfLongMethod).use(); allClassesNode.propagate(agent.getType("java.lang.Integer")); allClassesNode.propagate(agent.getType("java.lang.Float")); allClassesNode.propagate(agent.getType("java.lang.Double")); allClassesNode.propagate(agent.getType("java.lang.String")); }
@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"); }
@Override public void classReached(DependencyAgent agent, String className) { allClasses.propagate(agent.getType(className)); } }
@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 methodReached(DependencyAgent agent, MethodDependency method) { if (method.getReference().getClassName().equals(Platform.class.getName()) && method.getReference().getName().equals("getEnumConstants")) { allEnums.connect(method.getResult().getArrayItem()); final MethodReference ref = method.getReference(); allEnums.addConsumer(type -> { ClassReader cls = agent.getClassSource().get(type.getName()); MethodReader valuesMethod = cls.getMethod(new MethodDescriptor("values", ValueType.arrayOf(ValueType.object(cls.getName())))); if (valuesMethod != null) { MethodDependency valuesDep = agent.linkMethod(valuesMethod.getReference()); valuesDep.addLocation(new CallLocation(ref)); valuesDep.use(); } }); method.getResult().propagate(agent.getType("[Ljava/lang/Enum;")); for (String cls : agent.getReachableClasses()) { classReached(agent, cls); } } } }
@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()); } } }
@Override public void methodReached(DependencyAgent agent, MethodDependency method) { MethodReference ref = method.getReference(); MethodReference asyncRef = getAsyncReference(ref); MethodDependency asyncMethod = agent.linkMethod(asyncRef); method.addLocationListener(asyncMethod::addLocation); int paramCount = ref.parameterCount(); for (int i = 0; i <= paramCount; ++i) { method.getVariable(i).connect(asyncMethod.getVariable(i)); } asyncMethod.getVariable(paramCount + 1).propagate(agent.getType(AsyncCallbackWrapper.class.getName())); MethodDependency completeMethod = agent.linkMethod( new MethodReference(AsyncCallbackWrapper.class, "complete", Object.class, void.class)); if (method.getResult() != null) { completeMethod.getVariable(1).connect(method.getResult(), type -> agent.getClassHierarchy() .isSuperType(ref.getReturnType(), ValueType.object(type.getName()), false)); } completeMethod.use(); MethodDependency errorMethod = agent.linkMethod(new MethodReference(AsyncCallbackWrapper.class, "error", Throwable.class, void.class)); errorMethod.getVariable(1).connect(method.getThrown()); errorMethod.use(); agent.linkMethod(new MethodReference(AsyncCallbackWrapper.class, "create", AsyncCallback.class, AsyncCallbackWrapper.class)).use(); asyncMethod.use(); }
private void handleFieldSet(DependencyAgent agent, MethodDependency method) { CallLocation location = new CallLocation(method.getReference()); DependencyNode classValueNode = agent.linkMethod(getFields) .addLocation(location) .getVariable(0).getClassValueNode(); classValueNode.addConsumer(reflectedType -> { if (reflectedType.getName().startsWith("[")) { return; } Set<String> accessibleFields = getAccessibleFields(agent, reflectedType.getName()); ClassReader cls = agent.getClassSource().get(reflectedType.getName()); for (String fieldName : accessibleFields) { FieldReader field = cls.getField(fieldName); FieldDependency fieldDep = agent.linkField(field.getReference()).addLocation(location); propagateSet(agent, field.getType(), method.getVariable(2), fieldDep.getValue(), location); linkClassIfNecessary(agent, field, location); } }); }
@Override protected CharSequence callMethod(String ident, String fqn, String method, String params) { MethodDescriptor desc = MethodDescriptor.parse(method + params + "V"); MethodReference methodRef = new MethodReference(fqn, desc); MethodReader reader = findMethod(agent.getClassSource(), fqn, desc); if (reader == null) { agent.getDiagnostics().error(new CallLocation(caller.getReference()), "Can't resolve method {{m0}}", methodRef); } methodRef = reader.getReference(); MethodDependency methodDep = agent.linkMethod(methodRef); if (ident == null) { reachedMethods.get(caller.getReference()).add(methodRef); methodDep.use(); for (int i = 0; i < methodDep.getParameterCount(); ++i) { allClassesNode.connect(methodDep.getVariable(i)); } } else { allClassesNode.addConsumer(new VirtualCallbackConsumer(agent, methodRef)); } return ""; } }
@Override public void started(DependencyAgent agent) { allClasses = agent.createNode(); }
@Override public void methodReached(DependencyAgent agent, MethodDependency method) { MethodReference ref = method.getReference(); Set<MethodReference> callbackMethods = repository.callbackMethods.get(ref); if (callbackMethods != null) { for (MethodReference callbackMethod : callbackMethods) { agent.linkMethod(callbackMethod).addLocation(new CallLocation(ref)).use(); } } }
private void processInvocation(DependencyAgent agent, CallLocation location, String functionClassName, String targetClassName, String methodName) { Diagnostics diagnostics = agent.getDiagnostics(); ClassHierarchy hierarchy = agent.getClassHierarchy(); boolean valid = true; resolvedMethods.put(new ExportedMethodKey(functionClassName, targetClassName, methodName), reference); exportedMethods.add(reference); MethodDependency dep = agent.linkMethod(reference); dep.addLocation(location); dep.use();
ClassHierarchy hierarchy = callSite.getAgent().getClassHierarchy(); ClassReader samClass = hierarchy.getClassSource().get(samName); ClassReaderSource classSource = callSite.getAgent().getClassSource(); ClassReader callerClass = classSource.get(callSite.getCaller().getClassName()); int id = 0; ProgramEmitter pe = ProgramEmitter.create(worker, callSite.getAgent().getClassHierarchy()); pe.setCurrentLocation(callerPe.getCurrentLocation()); ValueEmitter thisVar = pe.var(0, implementor); callSite.getAgent().submitClass(implementor); callSite.getAgent().getIncrementalCache().addDependencies(implementor.getName(), dependencies.toArray(new String[0]));
cls.addMethod(method); agent.submitClass(cls); agent.getIncrementalCache().setNoCache(cls.getName()); MethodDependency implMethod = agent.linkMethod(implRef); implMethod.addLocation(location); for (int i = 0; i < implRef.parameterCount(); ++i) { implMethod.use(); agent.linkClass(implRef.getClassName());
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); }); }