コード例 #1
0
  @SuppressWarnings("unchecked")
  public void visitEnd() {

    // add all the fields of the class we're going to merge.
    for (Iterator<?> it = classToMerge.fields.iterator(); it.hasNext(); ) {
      ((FieldNode) it.next()).accept(this);
    }

    // add all the methods that we to include.
    for (Iterator<?> it = classToMerge.methods.iterator(); it.hasNext(); ) {
      MethodNode mn = (MethodNode) it.next();

      // skip the init.
      if (mn.name.equals("<init>")) continue;

      String[] exceptions = new String[mn.exceptions.size()];
      mn.exceptions.toArray(exceptions);
      MethodVisitor mv =
          cv.visitMethod(mn.access | Modifier.FINAL, mn.name, mn.desc, mn.signature, exceptions);
      mn.instructions.resetLabels();
      // mn.accept(new RemappingMethodAdapter(mn.access, mn.desc, mv, new
      // SimpleRemapper("org.apache.drill.exec.compile.ExampleTemplate", "Bunky")));
      ClassSet top = set;
      while (top.parent != null) top = top.parent;
      mn.accept(
          new RemappingMethodAdapter(
              mn.access,
              mn.desc,
              mv,
              new SimpleRemapper(top.precompiled.slash, top.generated.slash)));
    }
    super.visitEnd();
  }
コード例 #2
0
 @Override
 public void visitEnd() {
   for (Map.Entry<Handle, Handle> entry : lambdaAccessToImplMethods.entrySet()) {
     Handle accessMethod = entry.getKey();
     Handle implMethod = entry.getValue();
     Bytecode.generateDelegateMethod(cv, ACC_STATIC | ACC_SYNTHETIC, accessMethod, implMethod);
   }
   super.visitEnd();
 }
コード例 #3
0
ファイル: TLVInserter.java プロジェクト: jysunhy/disl-android
  @Override
  public void visitEnd() {

    // add fields
    for (ThreadLocalVar tlv : threadLocalVars) {
      super.visitField(Opcodes.ACC_PUBLIC, tlv.getName(), tlv.getTypeAsDesc(), null, null);
    }

    super.visitEnd();
  }
コード例 #4
0
ファイル: InstrumentClass.java プロジェクト: pmbauer/quasar
  @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();
  }
コード例 #5
0
ファイル: ClassNode.java プロジェクト: bric3/jitescript
 /**
  * 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();
 }
コード例 #6
0
  // GroovyClassVisitor interface
  // -------------------------------------------------------------------------
  public void visitClass(ClassNode classNode) {
    try {
      this.classNode = classNode;
      this.internalClassName = BytecodeHelper.getClassInternalName(classNode);

      // System.out.println("Generating class: " + classNode.getName());

      this.internalBaseClassName = BytecodeHelper.getClassInternalName(classNode.getSuperClass());

      cv.visit(
          Opcodes.V1_3,
          classNode.getModifiers(),
          internalClassName,
          (String) null,
          internalBaseClassName,
          BytecodeHelper.getClassInternalNames(classNode.getInterfaces()));

      classNode.visitContents(this);

      for (Iterator iter = innerClasses.iterator(); iter.hasNext(); ) {
        ClassNode innerClass = (ClassNode) iter.next();
        ClassNode innerClassType = innerClass;
        String innerClassInternalName = BytecodeHelper.getClassInternalName(innerClassType);
        String outerClassName = internalClassName; // default for inner classes
        MethodNode enclosingMethod = innerClass.getEnclosingMethod();
        if (enclosingMethod != null) {
          // local inner classes do not specify the outer class name
          outerClassName = null;
        }
        cv.visitInnerClass(
            innerClassInternalName,
            outerClassName,
            innerClassType.getName(),
            innerClass.getModifiers());
      }
      cv.visitEnd();
    } catch (GroovyRuntimeException e) {
      e.setModule(classNode.getModule());
      throw e;
    }
  }
コード例 #7
0
 public void accept(ClassVisitor classVisitor) {
   String factoryName = Util.classNameToInternalName(info.getFactoryDelegateInterfaceName());
   // TODO: the reactor currently has an issue with interfaces
   classVisitor.visit(
       Opcodes.V1_5,
       Opcodes.ACC_PUBLIC | Opcodes.ACC_ABSTRACT | Opcodes.ACC_INTERFACE,
       factoryName,
       null,
       "java/lang/Object",
       new String[0]);
   for (ConstructorInfo constructor : info.getConstructors()) {
     MethodVisitor mv =
         classVisitor.visitMethod(
             Opcodes.ACC_PUBLIC | Opcodes.ACC_ABSTRACT,
             "create",
             constructor.getFactoryDelegateMethodDescriptor(),
             constructor.getSignature(),
             constructor.getExceptions());
     if (mv != null) {
       mv.visitEnd();
     }
   }
   classVisitor.visitEnd();
 }
コード例 #8
0
  public void test() throws Exception {
    ClassWriter cw = new ClassWriter(true);
    ClassVisitor cv = new StaticInitMerger("$clinit$", cw);
    cv.visit(V1_1, ACC_PUBLIC, "A", null, "java/lang/Object", null);
    cv.visitField(ACC_PUBLIC + ACC_STATIC, "counter", "I", null, null);
    for (int i = 0; i < 5; ++i) {
      MethodVisitor mv = cv.visitMethod(ACC_PUBLIC, "<clinit>", "()V", null, null);
      mv.visitFieldInsn(GETSTATIC, "A", "counter", "I");
      mv.visitInsn(ICONST_1);
      mv.visitInsn(IADD);
      mv.visitFieldInsn(PUTSTATIC, "A", "counter", "I");
      mv.visitInsn(RETURN);
      mv.visitMaxs(0, 0);
    }
    MethodVisitor mv = cv.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null);
    mv.visitVarInsn(ALOAD, 0);
    mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>", "()V");
    mv.visitInsn(RETURN);
    mv.visitMaxs(0, 0);
    cv.visitEnd();

    Class c = LOADER.defineClass("A", cw.toByteArray());
    assertEquals(c.getField("counter").getInt(c.newInstance()), 5);
  }
コード例 #9
0
  public static byte[] generate(EventClassModel model) {
    ClassWriter cwriter = new ClassWriter(ClassWriter.COMPUTE_MAXS);

    ClassVisitor cw;
    if (TRACE) {
      cw = new TraceClassVisitor(cwriter, new ASMifier(), new PrintWriter(System.out));
      cw = new CheckClassAdapter(cw);
    } else {
      cw = cwriter;
    }

    FieldVisitor fv;
    MethodVisitor mv;

    String concreteClassName =
        model.getRootPackageInternalPrefix() + "event/" + model.technicalNameCapitalized + "Event";
    String className =
        model.isCustomized
            ? model.getRootPackageInternalPrefix()
                + "event/Abstract"
                + model.technicalNameCapitalized
                + "Event"
            : concreteClassName;

    cw.visit(
        V1_7,
        ACC_PUBLIC + ACC_SUPER + (model.isCustomized ? ACC_ABSTRACT : 0),
        className,
        null,
        "org/instantlogic/interaction/flow/impl/SimpleFlowEvent",
        null);

    // public static final HomeEvent
    {
      fv =
          cw.visitField(
              ACC_PUBLIC + ACC_FINAL + ACC_STATIC,
              "INSTANCE",
              "L" + concreteClassName + ";",
              null,
              null);
      fv.visitEnd();
    }

    {
      mv = cw.visitMethod(ACC_STATIC, "<clinit>", "()V", null, null);
      mv.visitCode();

      // INSTANCE = new HomeEvent();
      mv.visitTypeInsn(NEW, concreteClassName);
      mv.visitInsn(DUP);
      mv.visitMethodInsn(INVOKESPECIAL, concreteClassName, "<init>", "()V");
      mv.visitFieldInsn(PUTSTATIC, className, "INSTANCE", "L" + concreteClassName + ";");

      mv.visitInsn(RETURN);
      mv.visitMaxs(9, 99);
      mv.visitEnd();
    }
    // Default synthetic constructor
    {
      mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null);
      mv.visitCode();
      mv.visitVarInsn(ALOAD, 0);
      mv.visitLdcInsn(model.name);
      mv.visitIntInsn(BIPUSH, model.parameters.size());
      mv.visitTypeInsn(ANEWARRAY, "org/instantlogic/fabric/model/Entity");
      int i = 0;
      for (String parameter : model.parameters) {
        mv.visitInsn(DUP);
        mv.visitIntInsn(BIPUSH, i);
        mv.visitFieldInsn(
            GETSTATIC,
            model.getRootPackageInternalPrefix() + "entity/" + parameter + "Entity",
            "INSTANCE",
            "L" + model.getRootPackageInternalPrefix() + "entity/" + parameter + "Entity;");
        mv.visitInsn(AASTORE);
        i++;
      }
      mv.visitMethodInsn(
          INVOKESPECIAL,
          "org/instantlogic/interaction/flow/impl/SimpleFlowEvent",
          "<init>",
          "(Ljava/lang/String;[Lorg/instantlogic/fabric/model/Entity;)V");
      mv.visitInsn(RETURN);
      mv.visitMaxs(9, 99);
      mv.visitEnd();
    }

    cw.visitEnd();
    return cwriter.toByteArray();
  }
コード例 #10
0
ファイル: Parser.java プロジェクト: ForAnn/CodenameOne
 @Override
 public void visitEnd() {
   super.visitEnd();
 }
コード例 #11
0
 @Override
 public void visitEnd() {
   System.out.println("}");
   super.visitEnd();
 }