Package org.objectweb.asm.tree

Examples of org.objectweb.asm.tree.MethodNode


                .append(key.getRight().getName()).toString();
        importedMethods.put(key, result);
        privilizer().env.debug("importing %s#%s as %s", key.getLeft().getClassName(), key.getRight(), result);
        final int access = Opcodes.ACC_PRIVATE + Opcodes.ACC_STATIC + Opcodes.ACC_SYNTHETIC;

        final MethodNode source = getMethods(key.getLeft()).get(key.getRight());

        @SuppressWarnings("unchecked")
        final String[] exceptions = (String[]) source.exceptions.toArray(ArrayUtils.EMPTY_STRING_ARRAY);

        // non-public fields accessed
        final Set<FieldAccess> fieldAccesses = new LinkedHashSet<FieldAccess>();

        source.accept(new MethodVisitor(Opcodes.ASM4) {
            @Override
            public void visitFieldInsn(final int opcode, final String owner, final String name, final String desc) {
                final FieldAccess fieldAccess = fieldAccess(Type.getObjectType(owner), name);

                super.visitFieldInsn(opcode, owner, name, desc);
                if (!Modifier.isPublic(fieldAccess.access)) {
                    fieldAccesses.add(fieldAccess);
                }
            }
        });

        final MethodNode withAccessibleAdvice =
            new MethodNode(access, result, source.desc, source.signature, exceptions);

        // spider own methods:
        MethodVisitor mv = new NestedMethodInvocationHandler(withAccessibleAdvice, key.getLeft()); //NOPMD

        if (!fieldAccesses.isEmpty()) {
            // accessesNonPublicFields = true;
            mv = new AccessibleAdvisor(mv, access, result, source.desc, new ArrayList<FieldAccess>(fieldAccesses));
        }

        source.accept(mv);

        // private can only be called by other privileged methods, so no need to mark as privileged
        if (!Modifier.isPrivate(source.access)) {
            withAccessibleAdvice.visitAnnotation(Type.getType(Privileged.class).getDescriptor(), false).visitEnd();
        }

        withAccessibleAdvice.accept(this.cv);

        return result;
    }
View Full Code Here


  @Override
  public MethodVisitor visitMethod(int access, String name, String desc,
                                   String signature, String[] exceptions) {
    captureLastMethodNode();
    lastMethodNode = new MethodNode(access, name, desc, signature, exceptions);
    return lastMethodNode;
  }
View Full Code Here

    if (olds.isEmpty()) {
      return;
    }

    for (MethodContractHandle h : olds) {
      MethodNode contractMethod = injectContractMethod(h);
      int k = h.getKey();

      if (!statik) {
        loadThis();
      }
View Full Code Here

    ClassContractHandle h = contracts.getClassHandle(ContractKind.INVARIANT);
    if (h == null) {
      return;
    }

    MethodNode contractMethod = injectContractMethod(h);

    Label skipInvariants = new Label();
    if (isConstructor) {
      loadThis();
      invokeVirtual(thisType, GET_CLASS_METHOD);
View Full Code Here

        contracts.getMethodHandle(ContractKind.PRE, methodName, methodDesc, 0);
    if (h == null) {
      return;
    }

    MethodNode contractMethod = injectContractMethod(h);
    if (!statik) {
      loadThis();
    }
    loadArgs();
    invokeContractMethod(contractMethod);
View Full Code Here

                                  getPostDescOffset(oldLocals, extraIndex));
    if (h == null) {
      return;
    }

    MethodNode contractMethod = injectContractMethod(h);

    if (!statik) {
      loadThis();
    }
    loadArgs();
View Full Code Here

   * @return the method node to invoke
   */
  @Requires("handle != null")
  @Ensures("result != null")
  protected MethodNode injectContractMethod(ContractHandle handle) {
    MethodNode methodNode = handle.getContractMethod();

    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));
      handle.setInjected(true);
    }

    return methodNode;
  }
View Full Code Here

        if ("<init>".equals(name)) {
            // do not add constructors from super classes or private constructors
            if (ownerClass != classNode.getParentClass() || (access & ACC_PRIVATE) > 0) {
                return null;
            }
            MethodNode constructor = new MethodNode(access, name, desc, signature, exceptions);
            classNode.getConstructors().add(constructor);
            return constructor; // return the newly created method in order to have it "filled" with the method code
        }

        // only add non-native, non-abstract methods returning Rules
View Full Code Here

        if ("<init>".equals(name)) {
            // do not add constructors from super classes or private constructors
            if (ownerClass != classNode.getParentClass() || (access & ACC_PRIVATE) > 0) {
                return null;
            }
            MethodNode constructor = new MethodNode(access, name, desc, signature, exceptions);
            classNode.getConstructors().add(constructor);
            return constructor; // return the newly created method in order to have it "filled" with the method code
        }

        // only add non-native, non-abstract methods returning Rules
View Full Code Here

        for (Iterator i = cn.interfaces.iterator(); i.hasNext();) {
            interfaces.add(Type.getObjectType(i.next().toString()));
        }

        for (int i = 0; i < methods.size(); ++i) {
            MethodNode method = (MethodNode) methods.get(i);
            SimpleVerifier verifier = new SimpleVerifier(Type.getObjectType(cn.name),
                    syperType,
                    interfaces,
                    false);
            Analyzer a = new Analyzer(verifier);
View Full Code Here

TOP

Related Classes of org.objectweb.asm.tree.MethodNode

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.