Example #1
0
  @Override
  @SuppressWarnings("CallToThreadDumpStack")
  public void visitEnd() {
    classEntry.setRequiresInstrumentation(false);
    db.recordSuspendableMethods(className, classEntry);

    if (methods != null && !methods.isEmpty()) {
      if (alreadyInstrumented && !forceInstrumentation) {
        for (MethodNode mn : methods) mn.accept(makeOutMV(mn));
      } else {
        if (!alreadyInstrumented) {
          super.visitAnnotation(ALREADY_INSTRUMENTED_NAME, true);
          classEntry.setInstrumented(true);
        }

        for (MethodNode mn : methods) {
          final MethodVisitor outMV = makeOutMV(mn);
          try {
            InstrumentMethod im = new InstrumentMethod(db, className, mn);
            if (db.isDebug())
              db.log(
                  LogLevel.INFO, "About to instrument method %s#%s%s", className, mn.name, mn.desc);

            if (im.collectCodeBlocks()) {
              if (mn.name.charAt(0) == '<')
                throw new UnableToInstrumentException(
                    "special method", className, mn.name, mn.desc);
              im.accept(outMV, hasAnnotation(mn));
            } else mn.accept(outMV);
          } catch (AnalyzerException ex) {
            ex.printStackTrace();
            throw new InternalError(ex.getMessage());
          }
        }
      }
    } else {
      // if we don't have any suspendable methods, but our superclass is instrumented, we mark this
      // class as instrumented, too.
      if (!alreadyInstrumented && classEntry.getSuperName() != null) {
        ClassEntry superClass = db.getClassEntry(classEntry.getSuperName());
        if (superClass != null && superClass.isInstrumented()) {
          super.visitAnnotation(ALREADY_INSTRUMENTED_NAME, true);
          classEntry.setInstrumented(true);
        }
      }
    }
    super.visitEnd();
  }
Example #2
0
 /**
  * Makes the given class visitor visit this class.
  *
  * @param cv a class visitor.
  */
 public void accept(final ClassVisitor cv) {
   // visits header
   String[] interfaces = new String[this.interfaces.size()];
   this.interfaces.toArray(interfaces);
   cv.visit(version, access, name, signature, superName, interfaces);
   // visits source
   if (sourceFile != null || sourceDebug != null) {
     cv.visitSource(sourceFile, sourceDebug);
   }
   // visits outer class
   if (outerClass != null) {
     cv.visitOuterClass(outerClass, outerMethod, outerMethodDesc);
   }
   // visits attributes
   int i, n;
   n = visibleAnnotations == null ? 0 : visibleAnnotations.size();
   for (i = 0; i < n; ++i) {
     AnnotationNode an = visibleAnnotations.get(i);
     an.accept(cv.visitAnnotation(an.desc, true));
   }
   n = invisibleAnnotations == null ? 0 : invisibleAnnotations.size();
   for (i = 0; i < n; ++i) {
     AnnotationNode an = invisibleAnnotations.get(i);
     an.accept(cv.visitAnnotation(an.desc, false));
   }
   n = attrs == null ? 0 : attrs.size();
   for (i = 0; i < n; ++i) {
     cv.visitAttribute(attrs.get(i));
   }
   // visits inner classes
   for (i = 0; i < innerClasses.size(); ++i) {
     innerClasses.get(i).accept(cv);
   }
   // visits fields
   for (i = 0; i < fields.size(); ++i) {
     fields.get(i).accept(cv);
   }
   // visits methods
   for (i = 0; i < methods.size(); ++i) {
     methods.get(i).accept(cv);
   }
   // visits end
   cv.visitEnd();
 }
 @Override
 public AnnotationVisitor visit(String annotationTypeDescriptor, boolean visible) {
   return classVisitor.visitAnnotation(annotationTypeDescriptor, visible);
 }
 public void accept(ClassVisitor cv) {
   AnnotationVisitor av = cv.visitAnnotation(type, visible);
   accept(items, av);
   av.visitEnd();
 }