private AnnotationHolder readAnnotation(DataInput input) throws IOException { AnnotationHolder annotation = new AnnotationHolder(symbolTable.at(input.readInt())); int valueCount = input.readShort(); for (int i = 0; i < valueCount; ++i) { String name = symbolTable.at(input.readInt()); AnnotationValue value = readAnnotationValue(input); annotation.getValues().put(name, value); } return annotation; }
private AnnotationHolder rename(AnnotationHolder annot) { AnnotationHolder renamedAnnot = new AnnotationHolder(classNameMapper.map(annot.getType())); for (Map.Entry<String, AnnotationValue> entry : annot.getValues().entrySet()) { renamedAnnot.getValues().put(entry.getKey(), entry.getValue()); } return renamedAnnot; }
static void makeSync(MethodHolder method) { if (method.getAnnotations().get(Sync.class.getName()) == null) { AnnotationHolder annot = new AnnotationHolder(Sync.class.getName()); method.getAnnotations().add(annot); } }
private void parseAnnotations(AnnotationContainer annotations, List<AnnotationNode> visibleAnnotations, List<AnnotationNode> invisibleAnnotations) { List<Object> annotNodes = new ArrayList<>(); if (visibleAnnotations != null) { annotNodes.addAll(visibleAnnotations); } if (invisibleAnnotations != null) { annotNodes.addAll(invisibleAnnotations); } for (Object obj : annotNodes) { AnnotationNode annotNode = (AnnotationNode) obj; String desc = annotNode.desc; if (desc.startsWith("L") && desc.endsWith(";")) { desc = desc.substring(1, desc.length() - 1); } desc = desc.replace('/', '.'); if (annotations.get(desc) != null) { continue; } AnnotationHolder annot = new AnnotationHolder(referenceCache.getCached(desc)); parseAnnotationValues(annot, annotNode.values); annotations.add(annot); } }
private static AnnotationHolder copyAnnotation(AnnotationReader annot) { AnnotationHolder copy = new AnnotationHolder(annot.getType()); for (String fieldName : annot.getAvailableFields()) { copy.getValues().put(fieldName, copyAnnotationValue(annot.getValue(fieldName))); } return copy; }
@Override public void transformClass(ClassHolder cls, ClassHolderTransformerContext context) { for (MethodHolder method : cls.getMethods()) { if (method.getAnnotations().get(JavaScriptBody.class.getName()) != null) { AnnotationHolder genAnnot = new AnnotationHolder(GeneratedBy.class.getName()); genAnnot.getValues().put("value", new AnnotationValue(ValueType.object( JavaScriptBodyGenerator.class.getName()))); method.getAnnotations().add(genAnnot); method.setProgram(null); method.getModifiers().add(ElementModifier.NATIVE); } } } }
void createJSMethods(ClassHolder cls) { for (MethodHolder method : cls.getMethods().toArray(new MethodHolder[0])) { MethodReference methodRef = method.getReference(); if (method.getAnnotations().get(JSBody.class.getName()) == null) { continue; } requireJSBody(diagnostics, method); if (!repository.methodMap.containsKey(method.getReference())) { continue; } MethodReference proxyRef = repository.methodMap.get(methodRef); MethodHolder proxyMethod = new MethodHolder(proxyRef.getDescriptor()); proxyMethod.getModifiers().add(ElementModifier.NATIVE); proxyMethod.getModifiers().add(ElementModifier.STATIC); boolean inline = repository.inlineMethods.contains(methodRef); AnnotationHolder generatorAnnot = new AnnotationHolder(inline ? DynamicInjector.class.getName() : DynamicGenerator.class.getName()); proxyMethod.getAnnotations().add(generatorAnnot); cls.addMethod(proxyMethod); Set<MethodReference> callbacks = repository.callbackMethods.get(proxyRef); if (callbacks != null) { for (MethodReference callback : callbacks) { generateCallbackCaller(cls, callback); } } } }
private void addFunctorField(ClassHolder cls, MethodReference method) { if (cls.getAnnotations().get(FunctorImpl.class.getName()) != null) { return; } FieldHolder field = new FieldHolder("$$jso_functor$$"); field.setLevel(AccessLevel.PUBLIC); field.setType(ValueType.parse(JSObject.class)); cls.addField(field); AnnotationHolder annot = new AnnotationHolder(FunctorImpl.class.getName()); annot.getValues().put("value", new AnnotationValue(method.getDescriptor().toString())); cls.getAnnotations().add(annot); }
@Override public void transformClass(ClassHolder cls, ClassHolderTransformerContext context) { int index = 0; for (MethodHolder method : cls.getMethods().toArray(new MethodHolder[0])) { AnnotationReader providerAnnot = method.getAnnotations().get(MetadataProvider.class.getName()); if (providerAnnot != null) { transformMetadataMethod(cls, method, context.getDiagnostics(), context.getHierarchy(), index++); } providerAnnot = method.getAnnotations().get(ClassScopedMetadataProvider.class.getName()); if (providerAnnot != null) { ValueType[] params = method.getParameterTypes(); if (params.length != 1 && params[0].isObject(PlatformClass.class.getName())) { context.getDiagnostics().error(new CallLocation(method.getReference()), "Method {{m0}} marked with {{c1}} must take exactly one parameter of type {{c2}}", method.getReference(), ClassScopedMetadataProvider.class.getName(), PlatformClass.class.getName()); } AnnotationHolder genAnnot = new AnnotationHolder(GeneratedBy.class.getName()); genAnnot.getValues().put("value", new AnnotationValue(ValueType.object( ClassScopedMetadataProviderNativeGenerator.class.getName()))); method.getAnnotations().add(genAnnot); } } }
AnnotationNode annotNode = (AnnotationNode) value; ValueType.Object object = (ValueType.Object) referenceCache.getCached(ValueType.parse(annotNode.desc)); AnnotationHolder annotation = new AnnotationHolder(object.getClassName()); parseAnnotationValues(annotation, annotNode.values); return new AnnotationValue(annotation);
createMethod.getModifiers().add(ElementModifier.STATIC); cls.addMethod(createMethod); AnnotationHolder genAnnot = new AnnotationHolder(GeneratedBy.class.getName()); genAnnot.getValues().put("value", new AnnotationValue(ValueType.object( MetadataProviderNativeGenerator.class.getName()))); ModelUtils.copyAnnotations(method.getAnnotations(), createMethod.getAnnotations()); AnnotationHolder refAnnot = new AnnotationHolder(MetadataProviderRef.class.getName()); refAnnot.getValues().put("value", new AnnotationValue(method.getReference().toString())); createMethod.getAnnotations().add(refAnnot);
AnnotationHolder annot = new AnnotationHolder(JSMethodToExpose.class.getName()); annot.getValues().put("name", new AnnotationValue(publicAlias)); exportedMethod.getAnnotations().add(annot);
private AnnotationHolder rename(AnnotationHolder annot) { AnnotationHolder renamedAnnot = new AnnotationHolder(classNameMapper.map(annot.getType())); for (Map.Entry<String, AnnotationValue> entry : annot.getValues().entrySet()) { renamedAnnot.getValues().put(entry.getKey(), entry.getValue()); } return renamedAnnot; }
private AnnotationHolder readAnnotation(DataInput input) throws IOException { AnnotationHolder annotation = new AnnotationHolder(symbolTable.at(input.readInt())); int valueCount = input.readShort(); for (int i = 0; i < valueCount; ++i) { String name = symbolTable.at(input.readInt()); AnnotationValue value = readAnnotationValue(input); annotation.getValues().put(name, value); } return annotation; }
private void parseAnnotations(AnnotationContainer annotations, List<AnnotationNode> visibleAnnotations, List<AnnotationNode> invisibleAnnotations) { List<Object> annotNodes = new ArrayList<>(); if (visibleAnnotations != null) { annotNodes.addAll(visibleAnnotations); } if (invisibleAnnotations != null) { annotNodes.addAll(invisibleAnnotations); } for (Object obj : annotNodes) { AnnotationNode annotNode = (AnnotationNode) obj; String desc = annotNode.desc; if (desc.startsWith("L") && desc.endsWith(";")) { desc = desc.substring(1, desc.length() - 1); } desc = desc.replace('/', '.'); if (annotations.get(desc) != null) { continue; } AnnotationHolder annot = new AnnotationHolder(desc); parseAnnotationValues(annot, annotNode.values); annotations.add(annot); } }
void makeSync(ClassHolder cls) { Set<MethodDescriptor> methods = new HashSet<>(); findInheritedMethods(cls, methods, new HashSet<>()); for (MethodHolder method : cls.getMethods()) { if (methods.contains(method.getDescriptor()) && method.getAnnotations().get(Sync.class.getName()) == null) { AnnotationHolder annot = new AnnotationHolder(Sync.class.getName()); method.getAnnotations().add(annot); } } }
private static AnnotationHolder copyAnnotation(AnnotationReader annot) { AnnotationHolder copy = new AnnotationHolder(annot.getType()); for (String fieldName : annot.getAvailableFields()) { copy.getValues().put(fieldName, copyAnnotationValue(annot.getValue(fieldName))); } return copy; }
@Override public void transformClass(ClassHolder cls, ClassReaderSource innerSource, Diagnostics diagnostics) { for (MethodHolder method : cls.getMethods().toArray(new MethodHolder[0])) { AnnotationReader providerAnnot = method.getAnnotations().get(MetadataProvider.class.getName()); if (providerAnnot != null) { transformMetadataMethod(cls, method, diagnostics, innerSource); } providerAnnot = method.getAnnotations().get(ClassScopedMetadataProvider.class.getName()); if (providerAnnot != null) { ValueType[] params = method.getParameterTypes(); if (params.length != 1 && params[0].isObject(PlatformClass.class.getName())) { diagnostics.error(new CallLocation(method.getReference()), "Method {{m0}} marked with {{c1}} " + "must take exactly one parameter of type {{c2}}", method.getReference(), ClassScopedMetadataProvider.class.getName(), PlatformClass.class.getName()); } AnnotationHolder genAnnot = new AnnotationHolder(GeneratedBy.class.getName()); genAnnot.getValues().put("value", new AnnotationValue(ValueType.object( ClassScopedMetadataProviderNativeGenerator.class.getName()))); method.getAnnotations().add(genAnnot); AnnotationHolder noCacheAnnot = new AnnotationHolder(NoCache.class.getName()); method.getAnnotations().add(noCacheAnnot); } } }
private void addFunctorField(ClassHolder cls, MethodReference method) { if (cls.getAnnotations().get(FunctorImpl.class.getName()) != null) { return; } FieldHolder field = new FieldHolder("$$jso_functor$$"); field.setLevel(AccessLevel.PUBLIC); field.setType(ValueType.parse(JSObject.class)); cls.addField(field); AnnotationHolder annot = new AnnotationHolder(FunctorImpl.class.getName()); annot.getValues().put("value", new AnnotationValue(method.getDescriptor().toString())); cls.getAnnotations().add(annot); }
method.getReference(), asyncMethod.getReference()); AnnotationHolder annot = new AnnotationHolder(GeneratedBy.class.getName()); annot.getValues().put("value", new AnnotationValue(ValueType.parse(AsyncMethodGenerator.class))); method.getAnnotations().add(annot); annot = new AnnotationHolder(PluggableDependency.class.getName()); annot.getValues().put("value", new AnnotationValue(ValueType.parse(AsyncMethodGenerator.class))); method.getAnnotations().add(annot);