private void parseAnnotationValues(AnnotationHolder annot, List<Object> values) { if (values == null) { return; } for (int i = 0; i < values.size(); i += 2) { String key = (String) values.get(i); Object value = values.get(i + 1); annot.getValues().put(key, parseAnnotationValue(value)); } }
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 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); } } } }
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); } } }
public NativeMethodNode decompileNative(MethodHolder method) { Generator generator = generators.get(method.getReference()); if (generator == null && !isBootstrap()) { AnnotationHolder annotHolder = method.getAnnotations().get(GeneratedBy.class.getName()); if (annotHolder == null) { throw new DecompilationException("Method " + method.getOwnerName() + "." + method.getDescriptor() + " is native, but no " + GeneratedBy.class.getName() + " annotation found"); } ValueType annotValue = annotHolder.getValues().get("value").getJavaClass(); String generatorClassName = ((ValueType.Object) annotValue).getClassName(); try { Class<?> generatorClass = Class.forName(generatorClassName, true, classLoader); generator = (Generator) generatorClass.newInstance(); } catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) { throw new DecompilationException("Error instantiating generator " + generatorClassName + " for native method " + method.getOwnerName() + "." + method.getDescriptor()); } } NativeMethodNode methodNode = new NativeMethodNode(method.getReference()); methodNode.getModifiers().addAll(method.getModifiers()); methodNode.setGenerator(generator); methodNode.setAsync(asyncMethods.contains(method.getReference())); return methodNode; }
public MethodHolder rename(MethodHolder method) { String methodName = method.getName(); AnnotationHolder renameAnnot = method.getAnnotations().get(Rename.class.getName()); if (renameAnnot != null) { methodName = renameAnnot.getValues().get("value").getString(); } ValueType[] signature = method.getSignature(); for (int i = 0; i < signature.length; ++i) { signature[i] = rename(signature[i]); } MethodHolder renamedMethod = new MethodHolder(methodName, signature); renamedMethod.getModifiers().addAll(method.getModifiers()); renamedMethod.setLevel(method.getLevel()); renamedMethod.setProgram(method.getProgram()); rename(method.getAnnotations(), renamedMethod.getAnnotations()); rename(renamedMethod.getProgram()); return renamedMethod; }
AnnotationHolder superclassAnnot = cls.getAnnotations().get(Superclass.class.getName()); if (superclassAnnot != null) { parent = superclassAnnot.getValues().get("value").getString(); if (parent.isEmpty()) { parent = null;
cls.addMethod(createMethod); AnnotationHolder genAnnot = new AnnotationHolder(GeneratedBy.class.getName()); genAnnot.getValues().put("value", new AnnotationValue(ValueType.object( MetadataProviderNativeGenerator.class.getName()))); createMethod.getAnnotations().add(genAnnot); refAnnot.getValues().put("value", new AnnotationValue(method.getReference().toString())); createMethod.getAnnotations().add(refAnnot);
annot.getValues().put("name", new AnnotationValue(publicAlias)); exportedMethod.getAnnotations().add(annot);
private void parseAnnotationValues(AnnotationHolder annot, List<Object> values) { if (values == null) { return; } for (int i = 0; i < values.size(); i += 2) { String key = (String) values.get(i); Object value = values.get(i + 1); annot.getValues().put(key, parseAnnotationValue(value)); } }
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 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; }
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, 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); } } }
public NativeMethodNode decompileNative(MethodHolder method) { Generator generator = generators.get(method.getReference()); if (generator == null) { AnnotationHolder annotHolder = method.getAnnotations().get(GeneratedBy.class.getName()); if (annotHolder == null) { throw new DecompilationException("Method " + method.getOwnerName() + "." + method.getDescriptor() + " is native, but no " + GeneratedBy.class.getName() + " annotation found"); } ValueType annotValue = annotHolder.getValues().get("value").getJavaClass(); String generatorClassName = ((ValueType.Object) annotValue).getClassName(); try { Class<?> generatorClass = Class.forName(generatorClassName, true, classLoader); generator = (Generator) generatorClass.newInstance(); } catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) { throw new DecompilationException("Error instantiating generator " + generatorClassName + " for native method " + method.getOwnerName() + "." + method.getDescriptor()); } } NativeMethodNode methodNode = new NativeMethodNode(new MethodReference(method.getOwnerName(), method.getDescriptor())); methodNode.getModifiers().addAll(method.getModifiers()); methodNode.setGenerator(generator); methodNode.setAsync(asyncMethods.contains(method.getReference())); return methodNode; }
public MethodHolder rename(MethodHolder method) { String methodName = method.getName(); AnnotationHolder renameAnnot = method.getAnnotations().get(Rename.class.getName()); if (renameAnnot != null) { methodName = renameAnnot.getValues().get("value").getString(); } ValueType[] signature = method.getSignature(); for (int i = 0; i < signature.length; ++i) { signature[i] = rename(signature[i]); } MethodHolder renamedMethod = new MethodHolder(methodName, signature); renamedMethod.getModifiers().addAll(method.getModifiers()); renamedMethod.setLevel(method.getLevel()); renamedMethod.setProgram(method.getProgram()); rename(method.getAnnotations(), renamedMethod.getAnnotations()); rename(renamedMethod.getProgram()); return renamedMethod; }