Esempio n. 1
0
  public void toAsm(JarOutputStream jos) {
    ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS | ClassWriter.COMPUTE_FRAMES);
    //        ClassWriter cw = new ClassWriter(0);
    CheckClassAdapter cca = new CheckClassAdapter(cw);

    cca.visit(version, access, name, sig, superName, interfaces);
    Iterator it = fieldVisitors.entrySet().iterator();

    while (it.hasNext()) {
      Map.Entry pairs = (Map.Entry) it.next();
      ByteCodeFieldVisitor fv = (ByteCodeFieldVisitor) pairs.getValue();
      fv.toAsm(cca);
    }

    it = methodVisitors.entrySet().iterator();
    while (it.hasNext()) {
      Map.Entry pairs = (Map.Entry) it.next();
      ByteCodeMethodVisitor mv = (ByteCodeMethodVisitor) pairs.getValue();
      mv.toAsm(cca);
    }

    byte[] bytes = cw.toByteArray();
    if (ProjectProperties.getBoolean("fortress.bytecode.verify", false)) {
      PrintWriter pw = new PrintWriter(System.out);
      CheckClassAdapter.verify(new ClassReader(bytes), true, pw);
    }
    System.out.println("About to write " + name);
    ByteCodeWriter.writeJarredClass(jos, name, bytes);
  }
 @Override
 public void visitParameter(String name, int access) {
   if (name != null) {
     checkUnqualifiedName(version, name, "name");
   }
   CheckClassAdapter.checkAccess(
       access, Opcodes.ACC_FINAL + Opcodes.ACC_MANDATED + Opcodes.ACC_SYNTHETIC);
   super.visitParameter(name, access);
 }
Esempio n. 3
0
 @Override
 public AnnotationVisitor visitTypeAnnotation(
     final int typeRef, final TypePath typePath, final String desc, final boolean visible) {
   checkEnd();
   int sort = typeRef >>> 24;
   if (sort != TypeReference.FIELD) {
     throw new IllegalArgumentException(
         "Invalid type reference sort 0x" + Integer.toHexString(sort));
   }
   CheckClassAdapter.checkTypeRefAndPath(typeRef, typePath);
   CheckMethodAdapter.checkDesc(desc, false);
   return new CheckAnnotationAdapter(super.visitTypeAnnotation(typeRef, typePath, desc, visible));
 }
 @Override
 public AnnotationVisitor visitTypeAnnotation(
     final int typeRef, final TypePath typePath, final String desc, final boolean visible) {
   checkEndMethod();
   int sort = typeRef >>> 24;
   if (sort != TypeReference.METHOD_TYPE_PARAMETER
       && sort != TypeReference.METHOD_TYPE_PARAMETER_BOUND
       && sort != TypeReference.METHOD_RETURN
       && sort != TypeReference.METHOD_RECEIVER
       && sort != TypeReference.METHOD_FORMAL_PARAMETER
       && sort != TypeReference.THROWS) {
     throw new IllegalArgumentException(
         "Invalid type reference sort 0x" + Integer.toHexString(sort));
   }
   CheckClassAdapter.checkTypeRefAndPath(typeRef, typePath);
   CheckMethodAdapter.checkDesc(desc, false);
   return new CheckAnnotationAdapter(super.visitTypeAnnotation(typeRef, typePath, desc, visible));
 }
 @Override
 public AnnotationVisitor visitLocalVariableAnnotation(
     int typeRef,
     TypePath typePath,
     Label[] start,
     Label[] end,
     int[] index,
     String desc,
     boolean visible) {
   checkStartCode();
   checkEndCode();
   int sort = typeRef >>> 24;
   if (sort != TypeReference.LOCAL_VARIABLE && sort != TypeReference.RESOURCE_VARIABLE) {
     throw new IllegalArgumentException(
         "Invalid type reference sort 0x" + Integer.toHexString(sort));
   }
   CheckClassAdapter.checkTypeRefAndPath(typeRef, typePath);
   checkDesc(desc, false);
   if (start == null
       || end == null
       || index == null
       || end.length != start.length
       || index.length != start.length) {
     throw new IllegalArgumentException(
         "Invalid start, end and index arrays (must be non null and of identical length");
   }
   for (int i = 0; i < start.length; ++i) {
     checkLabel(start[i], true, "start label");
     checkLabel(end[i], true, "end label");
     checkUnsignedShort(index[i], "Invalid variable index");
     int s = labels.get(start[i]).intValue();
     int e = labels.get(end[i]).intValue();
     if (e < s) {
       throw new IllegalArgumentException(
           "Invalid start and end labels (end must be greater than start)");
     }
   }
   return super.visitLocalVariableAnnotation(typeRef, typePath, start, end, index, desc, visible);
 }
 @Override
 public AnnotationVisitor visitInsnAnnotation(
     final int typeRef, final TypePath typePath, final String desc, final boolean visible) {
   checkStartCode();
   checkEndCode();
   int sort = typeRef >>> 24;
   if (sort != TypeReference.INSTANCEOF
       && sort != TypeReference.NEW
       && sort != TypeReference.CONSTRUCTOR_REFERENCE
       && sort != TypeReference.METHOD_REFERENCE
       && sort != TypeReference.CAST
       && sort != TypeReference.CONSTRUCTOR_INVOCATION_TYPE_ARGUMENT
       && sort != TypeReference.METHOD_INVOCATION_TYPE_ARGUMENT
       && sort != TypeReference.CONSTRUCTOR_REFERENCE_TYPE_ARGUMENT
       && sort != TypeReference.METHOD_REFERENCE_TYPE_ARGUMENT) {
     throw new IllegalArgumentException(
         "Invalid type reference sort 0x" + Integer.toHexString(sort));
   }
   CheckClassAdapter.checkTypeRefAndPath(typeRef, typePath);
   CheckMethodAdapter.checkDesc(desc, false);
   return new CheckAnnotationAdapter(super.visitInsnAnnotation(typeRef, typePath, desc, visible));
 }