public MethodHolder(MethodDescriptor descriptor) { super(descriptor.getName()); this.descriptor = descriptor; parameterAnnotations = new AnnotationContainer[descriptor.parameterCount()]; for (int i = 0; i < parameterAnnotations.length; ++i) { parameterAnnotations[i] = new AnnotationContainer(); } }
public void remove(AnnotationHolder annotation) { AnnotationHolder existingAnnot = get(annotation.getType()); if (existingAnnot != annotation) { throw new IllegalArgumentException("There is no such annotation"); } annotations.remove(annotation.getType()); }
private void readAnnotations(DataInput input, AnnotationContainer annotations) throws IOException { int annotCount = input.readShort(); for (int i = 0; i < annotCount; ++i) { AnnotationHolder annot = readAnnotation(input); annotations.add(annot); } }
private void writeAnnotations(DataOutput output, AnnotationContainer annotations) throws IOException { List<AnnotationHolder> annotationList = new ArrayList<>(); for (AnnotationHolder annot : annotations.all()) { annotationList.add(annot); } output.writeShort(annotationList.size()); for (AnnotationHolder annot : annotationList) { writeAnnotation(output, annot); } }
@Override public void transformClass(ClassHolder cls, ClassHolderTransformerContext context) { for (MethodHolder method : cls.getMethods()) { AnnotationReader delegateAnnot = method.getAnnotations().get(DelegateTo.class.getName()); if (delegateAnnot != null) { method.setProgram(null); method.getModifiers().add(ElementModifier.NATIVE); } } } }
public static void copyAnnotations(AnnotationContainerReader src, AnnotationContainer dst) { for (AnnotationReader annot : src.all()) { dst.add(copyAnnotation(annot)); } }
private void writeAnnotations(DataOutput output, AnnotationContainer annotations) throws IOException { List<AnnotationHolder> annotationList = new ArrayList<>(); for (AnnotationHolder annot : annotations.all()) { annotationList.add(annot); } output.writeShort(annotationList.size()); for (AnnotationHolder annot : annotationList) { writeAnnotation(output, 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); } }
@Override public void transformClass(ClassHolder cls, ClassHolderTransformerContext context) { for (MethodHolder method : cls.getMethods()) { AnnotationReader delegateAnnot = method.getAnnotations().get(DelegateTo.class.getName()); if (delegateAnnot != null) { method.setProgram(null); method.getModifiers().add(ElementModifier.NATIVE); } } } }
public MethodHolder(MethodDescriptor descriptor) { super(descriptor.getName()); this.descriptor = descriptor; parameterAnnotations = new AnnotationContainer[descriptor.parameterCount()]; for (int i = 0; i < parameterAnnotations.length; ++i) { parameterAnnotations[i] = new AnnotationContainer(); } }
@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 boolean validate(MethodHolder method, Diagnostics diagnostics) { AnnotationReader providerAnnot = method.getAnnotations().get(MetadataProvider.class.getName()); if (providerAnnot == null) { return false; } if (!method.hasModifier(ElementModifier.NATIVE)) { diagnostics.error(new CallLocation(method.getReference()), "Method {{m0}} is marked with " + "{{c1}} annotation, but it is not native", method.getReference(), MetadataProvider.class.getName()); return false; } return true; } }
AnnotationHolder annot = new AnnotationHolder(JSMethodToExpose.class.getName()); annot.getValues().put("name", new AnnotationValue(publicAlias)); exportedMethod.getAnnotations().add(annot);
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); }
private String[] getExpectedExceptions(MethodHolder method) { AnnotationHolder annot = method.getAnnotations().get(JUNIT4_TEST); if (annot == null) { return new String[0]; } AnnotationValue expected = annot.getValue("expected"); if (expected == null) { return new String[0]; } ValueType result = expected.getJavaClass(); return new String[] { ((ValueType.Object) result).getClassName() }; }
private void readAnnotations(DataInput input, AnnotationContainer annotations) throws IOException { int annotCount = input.readShort(); for (int i = 0; i < annotCount; ++i) { AnnotationHolder annot = readAnnotation(input); annotations.add(annot); } }