Package org.objectweb.asm

Examples of org.objectweb.asm.ClassVisitor


            final MutableBoolean mustRewriteConstructor = new MutableBoolean();
            InputStream bytecode = null;

            try {
                bytecode = env.getClassfile(subtype).getInputStream();
                new ClassReader(bytecode).accept(new ClassVisitor(Opcodes.ASM4) {
                    String superName;

                    @Override
                    public void visit(final int version, final int access, final String name, final String signature,
                        final String superName, final String[] interfaces) {
View Full Code Here


        try {
            bytecode = env.getClassfile(classWrapper.wrapped).getInputStream();
            final ClassReader reader = new ClassReader(bytecode);

            final ClassVisitor writeClass = new WriteClass();

            // we're doing most of this by hand; we only read the original class to hijack signature, ctor exceptions,
            // etc.:

            reader.accept(new ClassVisitor(Opcodes.ASM4) {
                Type supertype;

                @Override
                public void visit(final int version, final int access, final String name, final String signature,
                    final String superName, final String[] interfaces) {
                    supertype = Type.getObjectType(superName);
                    writeClass.visit(version, Opcodes.ACC_PUBLIC, result, signature, superName, interfaces);

                    visitAnnotation(Type.getType(Marker.class).getDescriptor(), false);
                }

                @Override
                public MethodVisitor visitMethod(final int access, final String name, final String desc,
                    final String signature, final String[] exceptions) {
                    if (INIT.equals(name)) {

                        final Method staticCtor = new Method(INIT, key.getRight());
                        final Type[] argumentTypes = staticCtor.getArgumentTypes();
                        final Type[] exceptionTypes = toObjectTypes(exceptions);

                        {
                            final GeneratorAdapter mgen =
                                new GeneratorAdapter(Opcodes.ACC_PUBLIC, staticCtor, signature, exceptionTypes,
                                    writeClass);
                            mgen.visitCode();
                            mgen.loadThis();
                            for (int i = 0; i < argumentTypes.length; i++) {
                                mgen.loadArg(i);
                            }
                            mgen.invokeConstructor(supertype, staticCtor);
                            mgen.returnValue();
                            mgen.endMethod();
                        }
                        /*
                         * now declare a dummy constructor that will match, and discard,
                         * any originally inner-class bound constructor i.e. that set up a this$0 field.
                         * By doing this we can avoid playing with the stack that originally
                         * invoked such a constructor and simply rewrite the method
                         */
                        {
                            final Method instanceCtor =
                                new Method(INIT, Type.VOID_TYPE, ArrayUtils.add(argumentTypes, 0, OBJECT_TYPE));
                            final GeneratorAdapter mgen =
                                new GeneratorAdapter(Opcodes.ACC_PUBLIC, instanceCtor, signature, exceptionTypes,
                                    writeClass);
                            mgen.visitCode();
                            mgen.loadThis();
                            for (int i = 0; i < argumentTypes.length; i++) {
                                mgen.loadArg(i + 1);
                            }
                            mgen.invokeConstructor(supertype, staticCtor);
                            mgen.returnValue();
                            mgen.endMethod();
                        }
                        return null;
                    }
                    return null;
                }

                @Override
                public void visitEnd() {
                    writeClass.visitEnd();
                }
            }, 0);
        } finally {
            IOUtils.closeQuietly(bytecode);
        }
View Full Code Here

        // ProxySubclassHierarchyAdapter
        // to process only methods on that class that are in the list
        ClassReader cr = new ClassReader(loader.getResourceAsStream(currentlyAnalysedClass
            .getName().replaceAll("\\.", "/")
            + ".class"));
        ClassVisitor hierarchyAdapter = new ProxySubclassHierarchyAdapter(this, setOfFoundMethods);
        cr.accept(hierarchyAdapter, ClassReader.SKIP_DEBUG);
      } catch (IOException e) {
        throw new TypeNotPresentException(currentlyAnalysedClassName, e);
      }
      // now add the foundMethods to the overall list of observed methods
View Full Code Here

        // optimization note: per ASM docs COMPUTE_FRAMES makes code generation 2x slower,
        // so we may investigate manual computation options, although that's likely a
        // pain.
        ClassWriter writer = new ClassWriter(reader, ClassWriter.COMPUTE_FRAMES);

        ClassVisitor visitor = visitorFactory.createVisitor(className, writer);
        if (visitor == null) {
            // per instrumentation docs, if no transformation occured, we must return null
            return null;
        }
View Full Code Here

    if (!handle.isInjected()) {
      DebugUtils.info("instrument", "contract method "
                      + className + "." + methodNode.name
                      + methodNode.desc);
      ClassVisitor cv = classAdapter.getParent();
      List<Long> lineNumbers = handle.getLineNumbers();
      if (lineNumbers != null) {
        cv = new LineNumberingClassAdapter(cv, lineNumbers);
      }
      methodNode.accept(new ContractFixingClassAdapter(cv));
View Full Code Here

            throw new GeneratorException( e.getMessage(), e );
        }

        ClassWriter cw = new ClassWriter( 0 );

        ClassVisitor cv = new RemappingClassAdapter( cw, new SimpleRemapper( "HelpMojo",
                                                                             StringUtils.replace( destinationPackage,
                                                                                                  ".", "/" )
                                                                                 + "/HelpMojo" ) );

        try
View Full Code Here

    try {
      ClassReader cReader = new ClassReader(loader.getResourceAsStream(aClass.getName().replaceAll(
          "\\.", "/")
          + ".class"));
      ClassWriter cWriter = new ClassWriter(ClassWriter.COMPUTE_MAXS);
      ClassVisitor dynamicSubclassAdapter = new ProxySubclassAdapter(cWriter, fullNewClassName,
          loader);
      byte[] byteClassData = processClass(cReader, cWriter, dynamicSubclassAdapter);
      clazz = loadClassFromBytes(loader, getBinaryName(fullNewClassName), byteClassData, aClass
          .getName());
    } catch (IOException ioe) {
View Full Code Here

        // ProxySubclassHierarchyAdapter
        // to process only methods on that class that are in the list
        ClassReader cr = new ClassReader(loader.getResourceAsStream(currentlyAnalysedClass
            .getName().replaceAll("\\.", "/")
            + ".class"));
        ClassVisitor hierarchyAdapter = new ProxySubclassHierarchyAdapter(this, setOfFoundMethods);
        cr.accept(hierarchyAdapter, ClassReader.SKIP_DEBUG);
      } catch (IOException e) {
        throw new TypeNotPresentException(currentlyAnalysedClassName, e);
      }
      // now add the foundMethods to the overall list of observed methods
View Full Code Here

            } catch (Throwable t) {
                ;
            }
        }

        ClassVisitor createProxy = new ProxyCompilerClassVisitor(proxyWriter, proxyClassName.replace('.', '/'));
        classReader.accept(createProxy, Attributes.getDefaultAttributes(), true);// no need for debug info
        return proxyWriter.toByteArray();
//
//
//        writer.visit(
View Full Code Here

   *
   * @return
   */
  private void retrieveInvokeInfos(){
    final Map<String, List<LocalVariableSignature>> allVarSigns = new HashMap<String, List<LocalVariableSignature>>();
      ClassVisitor localVarVisitor = new AllMethodLocalVarInfoFetchVisitor(allVarSigns);
      reader.accept(localVarVisitor, ClassReader.SKIP_DEBUG);
      reader.accept(new EmptyVisitor(){
         
          Type classType;

View Full Code Here

TOP

Related Classes of org.objectweb.asm.ClassVisitor

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.