public static void acceptAnnotation(final AnnotationVisitor av, final String name, final Object value) { if (value instanceof String[]) { String[] typeconst = (String[]) value; av.visitEnum(name, typeconst[0], typeconst[1]); } else if (value instanceof AnnotationNode) { AnnotationNode an = (AnnotationNode) value; an.accept(av.visitAnnotation(name, an.desc)); } else if (value instanceof List<?>) { AnnotationVisitor v = av.visitArray(name); List<?> array = (List<?>) value; for (int j = 0; j < array.size(); ++j) { acceptAnnotation(v, null, array.get(j)); } v.visitEnd(); } else { av.visit(name, value); } }
v.visit("value", Type.getObjectType(nullnessAnnotationType.getClassName())); v.visitEnd();
).visitArray("value"); for (Type interceptorType : interceptorTypes) { interceptorTypeAnn.visit(null, interceptorType);
dav.visitEnum(name, f.getType(), f.getName()); } else if (o instanceof DexType) { dav.visit(name, Type.getType(((DexType) o).desc)); } else if (o instanceof Method) { System.err.println("WARN: ignored method annotation value"); System.err.println("WARN: ignored null annotation value"); } else { dav.visit(name, o);
private void addClassAnnotation(ClassWriter cw) { AnnotationVisitor annotationVisitor = cw.visitAnnotation("Lorg/glowroot/agent/plugin/api/weaving/Pointcut;", true); annotationVisitor.visit("className", config.className()); annotationVisitor.visit("classAnnotation", config.classAnnotation()); annotationVisitor.visit("subTypeRestriction", config.subTypeRestriction()); annotationVisitor.visit("superTypeRestriction", config.superTypeRestriction()); annotationVisitor.visit("methodName", config.methodName()); annotationVisitor.visit("methodAnnotation", config.methodAnnotation()); AnnotationVisitor arrayAnnotationVisitor = checkNotNull(annotationVisitor.visitArray("methodParameterTypes")); for (String methodParameterType : config.methodParameterTypes()) { arrayAnnotationVisitor.visit(null, methodParameterType); if (config.isTimerOrGreater()) { if (timerName.isEmpty()) { annotationVisitor.visit("timerName", "<no timer name provided>"); } else { annotationVisitor.visit("timerName", timerName); annotationVisitor.visit("nestingGroup", nestingGroup); } else if (!config.traceEntryCaptureSelfNested()) { annotationVisitor.visit("nestingGroup", "__GeneratedAdvice" + uniqueNum); annotationVisitor.visit("order", config.order()); annotationVisitor.visitEnd();
case 'F': // pointer to CONSTANT_Float case 'D': // pointer to CONSTANT_Double av.visit(name, readConst(readUnsignedShort(v), buf)); v += 2; break; case 'B': // pointer to CONSTANT_Byte av.visit(name, (byte) readInt(items[readUnsignedShort(v)])); v += 2; break; case 'Z': // pointer to CONSTANT_Boolean av.visit(name, readInt(items[readUnsignedShort(v)]) == 0 ? Boolean.FALSE : Boolean.TRUE); v += 2; break; case 'S': // pointer to CONSTANT_Short av.visit(name, (short) readInt(items[readUnsignedShort(v)])); v += 2; break; case 'C': // pointer to CONSTANT_Char av.visit(name, (char) readInt(items[readUnsignedShort(v)])); v += 2; break; case 's': // pointer to CONSTANT_Utf8 av.visit(name, readUTF8(v, buf)); v += 2; break; break; case 'c': // class_info av.visit(name, Type.getType(readUTF8(v, buf)));
@Override public void write(AnnotationVisitor visitor, Object value) { int len = Array.getLength(value); AnnotationVisitor arrayVisitor = visitor.visitArray(name); for (int i = 0; i < len; i++) { arrayVisitor.visit(null, Array.get(value, i)); } arrayVisitor.visitEnd(); } };
/** * Visits a primitive value of the annotation. * * @param name the value name. * @param value the actual value, whose type must be {@link Byte}, {@link Boolean}, {@link * Character}, {@link Short}, {@link Integer} , {@link Long}, {@link Float}, {@link Double}, * {@link String} or {@link Type} of {@link Type#OBJECT} or {@link Type#ARRAY} sort. This * value can also be an array of byte, boolean, short, char, int, long, float or double values * (this is equivalent to using {@link #visitArray} and visiting each array element in turn, * but is more convenient). */ public void visit(final String name, final Object value) { if (av != null) { av.visit(name, value); } }
annotationVisitor.visit( elementName, (byte) readInt(cpInfoOffsets[readUnsignedShort(currentOffset)])); currentOffset += 2; break; case 'C': // const_value_index, CONSTANT_Integer annotationVisitor.visit( elementName, (char) readInt(cpInfoOffsets[readUnsignedShort(currentOffset)])); currentOffset += 2; case 'I': // const_value_index, CONSTANT_Integer case 'J': // const_value_index, CONSTANT_Long annotationVisitor.visit( elementName, readConst(readUnsignedShort(currentOffset), charBuffer)); currentOffset += 2; break; case 'S': // const_value_index, CONSTANT_Integer annotationVisitor.visit( elementName, (short) readInt(cpInfoOffsets[readUnsignedShort(currentOffset)])); currentOffset += 2; annotationVisitor.visit( elementName, readInt(cpInfoOffsets[readUnsignedShort(currentOffset)]) == 0 break; case 's': // const_value_index, CONSTANT_Utf8 annotationVisitor.visit(elementName, readUTF8(currentOffset, charBuffer)); currentOffset += 2; break;
@Override public void visit(String name, Object value) { super.visit(name, value); if (!"value".equals(paramName) && !"path".equals(paramName)) { return; } if (value instanceof String) { String sValue = (String) value; methodRequestMappingUrl = sValue; isRequestHandler = true; } }
@Override public void visit(String name, Object value) { super.visit(name, value); String v = value.toString(); if (StringUtil.isNotEmpty(v)) { classRequestMappingUrl = v; } } }
public void instrument(MutableClass mutableClass) { try { // no need to do anything to interfaces if (mutableClass.isInterface()) { return; } makeClassPublic(mutableClass.classNode); if ((mutableClass.classNode.access & Opcodes.ACC_FINAL) == Opcodes.ACC_FINAL) { mutableClass.classNode.visitAnnotation( "Lcom/google/errorprone/annotations/DoNotMock;", true) .visit("value", "This class is final. Consider using the real thing, or " + "adding/enhancing a Robolectric shadow for it."); } mutableClass.classNode.access = mutableClass.classNode.access & ~Opcodes.ACC_FINAL; // Need Java version >=7 to allow invokedynamic mutableClass.classNode.version = Math.max(mutableClass.classNode.version, Opcodes.V1_7); instrumentMethods(mutableClass); // If there is no constructor, adds one addNoArgsConstructor(mutableClass); addDirectCallConstructor(mutableClass); addRoboInitMethod(mutableClass); decorator.decorate(mutableClass); doSpecialHandling(mutableClass); } catch (Exception e) { throw new RuntimeException("failed to instrument " + mutableClass.getName(), e); } }
public void visit(String name, Object value) { value = processConstant(sourceType, value); av.visit(name, value); }
@Override public void visit(@Nullable String name, Object value) { if ("methodName".equals(name) && "<init>".equals(value)) { constructorPointcut = true; } super.visit(name, value); } }
@Override public void visit(String name, Object value) { methodSymbol.defaultValue = value; super.visit(name, value); } };
@Override public void visit(String name, Object value) { if ("forceWeaving".equals(name)) { info.forcePooledWeaving = (Boolean)value; } super.visit(name, value); } }
@Override public void visit(String field, Object value) { if ("using".equals(field)) info.profilerClass = (Type)value; else if ("enabled".equals(field)) info.profilingEnabled = (Boolean)value; super.visit(annotationField, value); }