Ejemplo n.º 1
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 = visibleTypeAnnotations == null ? 0 : visibleTypeAnnotations.size();
   for (i = 0; i < n; ++i) {
     TypeAnnotationNode an = visibleTypeAnnotations.get(i);
     an.accept(cv.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(cv.visitTypeAnnotation(an.typeRef, an.typePath, 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();
 }
  /*
   * Add the SVUID if class doesn't have one
   */
  @Override
  public void visitEnd() {
    // compute SVUID and add it to the class
    if (computeSVUID && !hasSVUID) {
      try {
        addSVUID(computeSVUID());
      } catch (Throwable e) {
        throw new RuntimeException("Error while computing SVUID for " + name, e);
      }
    }

    super.visitEnd();
  }