Package org.objectweb.asm.commons

Examples of org.objectweb.asm.commons.Method


    //We're going to implement this method, so make it non abstract!
    access &= ~ACC_ABSTRACT;
    //If we already implement this method (from another interface) then we don't
    //want a duplicate. We also don't want to copy any static init blocks (these
    //initialize static fields on the interface that we don't copy
    if(adapter.getKnownMethods().contains(new Method(name, desc)) ||
        "<clinit>".equals(name))
      return null;
    else
      return adapter.visitMethod(access, name, desc, null, arg4);
  }
View Full Code Here


      String signature, String[] exceptions) {
    LOGGER.debug(Constants.LOG_ENTRY, "visitMethod", new Object[] { access,
        name, desc, signature, exceptions });

   
    Method currentMethod = new Method(name, desc);
   
    getKnownMethods().add(currentMethod);
   
    MethodVisitor methodVisitorToReturn = null;

    // Only weave "real" instance methods. Not constructors, initializers or
    // compiler generated ones.
    if ((access & (ACC_STATIC | ACC_PRIVATE | ACC_SYNTHETIC | ACC_ABSTRACT
        | ACC_NATIVE | ACC_BRIDGE)) == 0 && !!!name.equals("<init>") &&
        !!!name.equals("<clinit>")) {

      // found a method we should weave

      //Create a field name and store it for later
      String methodStaticFieldName = "methodField" + getSanitizedUUIDString();
      transformedMethods.put(methodStaticFieldName, new TypeMethod(
           getDeclaringTypeForCurrentMethod(), currentMethod));

      // Surround the MethodVisitor with our weaver so we can manipulate the code
      methodVisitorToReturn = getWeavingMethodVisitor(access, name, desc,
          signature, exceptions, currentMethod, methodStaticFieldName);
    } else if (name.equals("<clinit>")){
      //there is an existing clinit method, change the fields we use
      //to write our init code to static_init_UUID instead
      staticInitMethod = new Method("static_init_" + UU_ID, Type.VOID_TYPE, NO_ARGS);
      staticInitMethodFlags = staticInitMethodFlags | ACC_FINAL;
      methodVisitorToReturn = new AdviceAdapter(cv.visitMethod(access, name, desc, signature,
          exceptions), access, name, desc){
        @Override
        protected void onMethodEnter()
        {
          //add into the <clinit> a call to our synthetic static_init_UUID
          invokeStatic(typeBeingWoven, staticInitMethod);
          super.onMethodEnter();
        }
      };
    } else {
      if(currentMethod.getArgumentTypes().length == 0 && name.equals("<init>"))
        hasNoArgsConstructor = true;
      //This isn't a method we want to weave, so just get the default visitor
      methodVisitorToReturn = cv.visitMethod(access, name, desc, signature,
          exceptions);
    }
View Full Code Here

    // a general methodAdapter field that we will use to with GeneratorAdapters
    // to create the methods required to implement WovenProxy
    GeneratorAdapter methodAdapter;

    // add a method for unwrapping the dispatcher
    methodAdapter = getMethodGenerator(PUBLIC_GENERATED_METHOD_ACCESS, new Method(
        "org_apache_aries_proxy_weaving_WovenProxy_unwrap", DISPATCHER_TYPE,
        NO_ARGS));

    // /////////////////////////////////////////////////////
    // Implement the method

    // load this to get the field
    methodAdapter.loadThis();
    // get the dispatcher field and return
    methodAdapter.getField(typeBeingWoven, DISPATCHER_FIELD, DISPATCHER_TYPE);
    methodAdapter.returnValue();
    methodAdapter.endMethod();

    // /////////////////////////////////////////////////////

    // add a method for checking if the dispatcher is set
    methodAdapter = getMethodGenerator(PUBLIC_GENERATED_METHOD_ACCESS, new Method(
        "org_apache_aries_proxy_weaving_WovenProxy_isProxyInstance",
        Type.BOOLEAN_TYPE, NO_ARGS));

    // /////////////////////////////////////////////////////
    // Implement the method
View Full Code Here

   * We write createNewProxyInstance separately because it isn't final, and is
   * overridden on each class, we also write a constructor for this method to
   * use if we don't have one.
   */
  private final void writeCreateNewProxyInstanceAndConstructor() {
    GeneratorAdapter methodAdapter = getMethodGenerator(ACC_PUBLIC, new Method(
        "org_apache_aries_proxy_weaving_WovenProxy_createNewProxyInstance",
        WOVEN_PROXY_IFACE_TYPE, DISPATCHER_LISTENER_METHOD_ARGS));

    // /////////////////////////////////////////////////////
    // Implement the method

    // Create and instantiate a new instance, then return it
    methodAdapter.newInstance(typeBeingWoven);
    methodAdapter.dup();
    methodAdapter.loadArgs();
    methodAdapter.invokeConstructor(typeBeingWoven, new Method("<init>",
        Type.VOID_TYPE, DISPATCHER_LISTENER_METHOD_ARGS));
    methodAdapter.returnValue();
    methodAdapter.endMethod();
    //////////////////////////////////////////////////////////

View Full Code Here

        index++;
      }

      // invoke the getMethod
      staticAdapter.invokeVirtual(CLASS_TYPE,
          new Method("getDeclaredMethod", METHOD_TYPE, new Type[] {
              STRING_TYPE, CLASS_ARRAY_TYPE}));

      // store the reflected method in the static field
      staticAdapter.putStatic(typeBeingWoven, methodStaticFieldName,
          METHOD_TYPE);
View Full Code Here

    if (!!!name.equals("<init>") && !!!name.equals("<clinit>")
        && (access & (ACC_STATIC | ACC_PRIVATE | ACC_SYNTHETIC | ACC_ABSTRACT
            | ACC_NATIVE | ACC_BRIDGE)) == 0) {

      // identify the target method parameters and return type
      Method currentTransformMethod = new Method(name, desc);
      // We don't want to duplicate a method we already overrode!
      if(!!!knownMethods.add(currentTransformMethod))
        return null;
     
      // found a method we should weave
View Full Code Here

    ClassReader cr = new ClassReader(bytes);
    ClassWriter cw = new ClassWriter(cr, ClassWriter.COMPUTE_MAXS
        | ClassWriter.COMPUTE_FRAMES);
    cr.accept(cw, 0);

    Method md = Method
        .getMethod("org.eclipse.swt.graphics.Color getForeground ()");
    MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, md.getName(),
        md.getDescriptor(), null, null);
   
    final GeneratorAdapter mg = new GeneratorAdapter(ACC_PUBLIC, md, mv);
    final Label LABEL_SKIP_CALL_TO_SUPER = new Label();
    final Label LABEL_LOOP_CMP = new Label();
    final Label LABEL_LOOP_START = new Label();
View Full Code Here

    public UnitTestAdviceAdapter(int access, String name, String desc,
            MethodVisitor mv) {
        super(ASM4, mv, access, name, desc);
//        super(mv, access, name, desc);
        _methodName = name;
        method = new Method(_methodName, desc);
    }
View Full Code Here

    public UnitTestAdviceAdapter(int access, String name, String desc,
            MethodVisitor mv, String className) {
        this(access, name, desc, mv);
        _className = className;
        _methodName = name;
        method = new Method(_methodName, desc);
    }
View Full Code Here

//        super(visitor);

        _className = className;
        _methodName = methodName;
        _parameters = parameters;
        method = new Method(_methodName, _parameters);
        isReplaceMethod = WeavingConfigUtil.INSTANCE.isReplaceMethod(className, methodName);
        // 是否不需要注入的方法
        isNoWeavingMethod = WeavingConfigUtil.INSTANCE.isNoWeavingMethod(methodName);
        if (isNoWeavingMethod) {
            if (_parameters.contains("(Ljava/lang/Class;)")) {
View Full Code Here

TOP

Related Classes of org.objectweb.asm.commons.Method

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.