@Override public boolean isApplicable(MethodReference methodReference) { MethodReader method = classSource.resolve(methodReference); if (method == null) { return false; } return method.getAnnotations().get(MetadataProvider.class.getName()) != null; }
private MethodHolder addReader(DependencyAgent agent, ClassReader cls) { MethodHolder readerMethod = new MethodHolder("getAnnotations", ValueType.parse(Annotation[].class)); readerMethod.setLevel(AccessLevel.PUBLIC); ProgramEmitter pe = ProgramEmitter.create(readerMethod, agent.getClassHierarchy()); List<AnnotationReader> annotations = new ArrayList<>(); for (AnnotationReader annot : cls.getAnnotations().all()) { ClassReader annotType = agent.getClassSource().get(annot.getType()); if (annotType == null) { continue; } AnnotationReader retention = annotType.getAnnotations().get(Retention.class.getName()); if (retention != null) { String retentionPolicy = retention.getValue("value").getEnumValue().getFieldName(); if (retentionPolicy.equals("RUNTIME")) { annotations.add(annot); } } } ValueEmitter array = pe.constructArray(Annotation.class, annotations.size()); for (int i = 0; i < annotations.size(); ++i) { array.setElement(i, generateAnnotationInstance(agent, pe, annotations.get(i))); } array.returnValue(); return readerMethod; }
public static void copyAnnotations(AnnotationContainerReader src, AnnotationContainer dst) { for (AnnotationReader annot : src.all()) { dst.add(copyAnnotation(annot)); } }
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 boolean canHandle(MethodReference methodReference) { MethodReader method = classSource.resolve(methodReference); if (method == null) { return false; } return method.getAnnotations().get(MetadataProvider.class.getName()) != null; }
@Override public void methodReached(DependencyAgent agent, MethodDependency method) { if (!reachedMethods.add(method.getReference())) { return; } ValueType type = method.getMethod().getResultType(); while (type instanceof ValueType.Array) { type = ((ValueType.Array) type).getItemType(); } if (type instanceof ValueType.Object) { String className = ((ValueType.Object) type).getClassName(); ClassReader cls = agent.getClassSource().get(className); if (cls != null && cls.hasModifier(ElementModifier.ANNOTATION)) { agent.linkClass(className); } } if (method.getMethod().hasModifier(ElementModifier.STATIC) && method.getMethod().getName().equals("$$__readAnnotations__$$")) { ClassReader cls = agent.getClassSource().get(method.getReference().getClassName()); if (cls != null) { for (AnnotationReader annotation : cls.getAnnotations().all()) { agent.linkClass(annotation.getType()); } } } MethodReference methodRef = method.getMethod().getReference(); if (methodRef.getClassName().equals("java.lang.Class") && methodRef.getName().equals("getAnnotations")) { reachGetAnnotations(agent, method.getVariable(0)); } }
private boolean isStaticInit(String className) { ClassReader cls = unprocessedClassSource.get(className); if (cls == null) { return false; } return cls.getAnnotations().get(StaticInit.class.getName()) != null; }
public static void copyAnnotations(AnnotationContainerReader src, AnnotationContainer dst) { for (AnnotationReader annot : src.all()) { dst.add(copyAnnotation(annot)); } }
private boolean computeIsManaged(MethodReference methodReference) { MethodReader method = classSource.resolve(methodReference); if (method == null) { return true; } ClassReader cls = classSource.get(method.getOwnerName()); if (cls.getAnnotations().get(Unmanaged.class.getName()) != null) { return false; } return method == null || method.getAnnotations().get(Unmanaged.class.getName()) == null; } }
private String extractSuggestedPropertyName(MethodReader method) { AnnotationReader annot = method.getAnnotations().get(JSProperty.class.getName()); AnnotationValue value = annot.getValue("value"); return value != null ? value.getString() : null; }
private String getPublicAlias(MethodReader method) { AnnotationReader annot = method.getAnnotations().get(JSMethodToExpose.class.getName()); return annot != null ? annot.getValue("name").getString() : null; }
private MarkerKind isMarker(MemberReader member) { AnnotationReader annot = member.getAnnotations().get(PlatformMarker.class.getName()); if (annot == null) { return null; } AnnotationValue value = annot.getValue("value"); if (value == null) { return MarkerKind.TRUE; } String tagToMatch = value.getString(); for (String tag : tags) { if (tag.equals(tagToMatch)) { return MarkerKind.TRUE; } } return MarkerKind.FALSE; }
private void getFunctorMethods(String className, Map<MethodDescriptor, MethodReference> methods) { classSource.getAncestors(className).forEach(cls -> { if (cls.getAnnotations().get(JSFunctor.class.getName()) != null && marshaller.isProperFunctor(cls)) { MethodReference method = cls.getMethods().iterator().next().getReference(); if (!methods.containsKey(method.getDescriptor())) { methods.put(method.getDescriptor(), method); } } }); }
private void processInclude(AnnotationContainerReader container) { AnnotationReader annot = container.get(Include.class.getName()); if (annot == null) { return; } String includeString = annot.getValue("value").getString(); AnnotationValue systemValue = annot.getValue("isSystem"); if (systemValue == null || systemValue.getBoolean()) { includeString = "<" + includeString + ">"; } else { includeString = "\"" + includeString + "\""; } includes.add(includeString); }
@Override public <S extends Annotation> S getAnnotation(Class<S> type) { @SuppressWarnings("unchecked") S result = (S) annotations.computeIfAbsent(type, t -> { if (annotationContainer == null) { return null; } AnnotationReader annot = annotationContainer.get(t.getName()); if (annot == null) { return null; } AnnotationProxy handler = new AnnotationProxy(context.getClassLoader(), context.getHierarchy(), annot, t); return (Annotation) Proxy.newProxyInstance(context.getClassLoader(), new Class<?>[] { t }, handler); }); return result; } }
public boolean isStaticInit(String className) { byte result = isStaticInit.getOrDefault(className, (byte) -1); if (result < 0) { ClassReader cls = classSource.get(className); result = cls != null && cls.getAnnotations().get(StaticInit.class.getName()) != null ? (byte) 1 : 0; isStaticInit.put(className, result); } return result != 0; }
private String getSpecialName(MethodReference methodReference) { MethodReader method = classSource.resolve(methodReference); if (method == null) { return null; } AnnotationReader exportAnnot = method.getAnnotations().get(Export.class.getName()); if (exportAnnot != null) { return exportAnnot.getValue("name").getString(); } AnnotationReader importAnnot = method.getAnnotations().get(Import.class.getName()); if (importAnnot != null) { return importAnnot.getValue("name").getString(); } return null; }
@Override public void methodReached(DependencyAgent agent, MethodDependency method) { if (method.getMethod() != null && method.getMethod().getAnnotations().get(Async.class.getName()) != null) { new AsyncMethodGenerator().methodReached(agent, method); } } }
Variable unwrapReturnValue(CallLocation location, Variable var, ValueType type) { if (type instanceof ValueType.Object) { String className = ((ValueType.Object) type).getClassName(); ClassReader cls = classSource.get(className); if (cls != null && cls.getAnnotations().get(JSFunctor.class.getName()) != null) { return unwrapFunctor(location, var, cls); } } return unwrap(location, var, type); }
private void attachDependencyPlugin(MethodDependency methodDep) { if (methodDep.dependencyPluginAttached) { return; } methodDep.dependencyPluginAttached = true; methodDep.dependencyPlugin = dependencyPlugins.get(methodDep.getReference()); if (methodDep.dependencyPlugin != null || isBootstrap()) { return; } AnnotationReader depAnnot = methodDep.getMethod().getAnnotations().get(PluggableDependency.class.getName()); if (depAnnot == null) { return; } ValueType depType = depAnnot.getValue("value").getJavaClass(); String depClassName = ((ValueType.Object) depType).getClassName(); Class<?> depClass; try { depClass = Class.forName(depClassName, true, classLoader); } catch (ClassNotFoundException e) { throw new RuntimeException("Dependency plugin not found: " + depClassName, e); } try { methodDep.dependencyPlugin = (DependencyPlugin) depClass.newInstance(); } catch (IllegalAccessException | InstantiationException e) { throw new RuntimeException("Can't instantiate dependency plugin " + depClassName, e); } }