Example #1
0
 /**
  * Makes the given method visitor visit this method.
  *
  * @param mv a method visitor.
  */
 public void accept(final MethodVisitor mv) {
   // visits the method parameters
   int i, j, n;
   n = parameters == null ? 0 : parameters.size();
   for (i = 0; i < n; i++) {
     ParameterNode parameter = parameters.get(i);
     mv.visitParameter(parameter.name, parameter.access);
   }
   // visits the method attributes
   if (annotationDefault != null) {
     AnnotationVisitor av = mv.visitAnnotationDefault();
     AnnotationNode.accept(av, null, annotationDefault);
     if (av != null) {
       av.visitEnd();
     }
   }
   n = visibleAnnotations == null ? 0 : visibleAnnotations.size();
   for (i = 0; i < n; ++i) {
     AnnotationNode an = visibleAnnotations.get(i);
     an.accept(mv.visitAnnotation(an.desc, true));
   }
   n = invisibleAnnotations == null ? 0 : invisibleAnnotations.size();
   for (i = 0; i < n; ++i) {
     AnnotationNode an = invisibleAnnotations.get(i);
     an.accept(mv.visitAnnotation(an.desc, false));
   }
   n = visibleTypeAnnotations == null ? 0 : visibleTypeAnnotations.size();
   for (i = 0; i < n; ++i) {
     TypeAnnotationNode an = visibleTypeAnnotations.get(i);
     an.accept(mv.visitTypeAnnotation(an.typeRef, an.typePath, an.desc, true));
   }
   n = invisibleTypeAnnotations == null ? 0 : invisibleTypeAnnotations.size();
   for (i = 0; i < n; ++i) {
     TypeAnnotationNode an = invisibleTypeAnnotations.get(i);
     an.accept(mv.visitTypeAnnotation(an.typeRef, an.typePath, an.desc, false));
   }
   n = visibleParameterAnnotations == null ? 0 : visibleParameterAnnotations.length;
   for (i = 0; i < n; ++i) {
     List<?> l = visibleParameterAnnotations[i];
     if (l == null) {
       continue;
     }
     for (j = 0; j < l.size(); ++j) {
       AnnotationNode an = (AnnotationNode) l.get(j);
       an.accept(mv.visitParameterAnnotation(i, an.desc, true));
     }
   }
   n = invisibleParameterAnnotations == null ? 0 : invisibleParameterAnnotations.length;
   for (i = 0; i < n; ++i) {
     List<?> l = invisibleParameterAnnotations[i];
     if (l == null) {
       continue;
     }
     for (j = 0; j < l.size(); ++j) {
       AnnotationNode an = (AnnotationNode) l.get(j);
       an.accept(mv.visitParameterAnnotation(i, an.desc, false));
     }
   }
   if (visited) {
     instructions.resetLabels();
   }
   n = attrs == null ? 0 : attrs.size();
   for (i = 0; i < n; ++i) {
     mv.visitAttribute(attrs.get(i));
   }
   // visits the method's code
   if (instructions.size() > 0) {
     mv.visitCode();
     // visits try catch blocks
     n = tryCatchBlocks == null ? 0 : tryCatchBlocks.size();
     for (i = 0; i < n; ++i) {
       tryCatchBlocks.get(i).updateIndex(i);
       tryCatchBlocks.get(i).accept(mv);
     }
     // visits instructions
     instructions.accept(mv);
     // visits local variables
     n = localVariables == null ? 0 : localVariables.size();
     for (i = 0; i < n; ++i) {
       localVariables.get(i).accept(mv);
     }
     // visits local variable annotations
     n = visibleLocalVariableAnnotations == null ? 0 : visibleLocalVariableAnnotations.size();
     for (i = 0; i < n; ++i) {
       visibleLocalVariableAnnotations.get(i).accept(mv, true);
     }
     n = invisibleLocalVariableAnnotations == null ? 0 : invisibleLocalVariableAnnotations.size();
     for (i = 0; i < n; ++i) {
       invisibleLocalVariableAnnotations.get(i).accept(mv, false);
     }
     // visits maxs
     mv.visitMaxs(maxStack, maxLocals);
     visited = true;
   }
   mv.visitEnd();
 }