Package org.aspectj.apache.bcel.generic

Examples of org.aspectj.apache.bcel.generic.InvokeInstruction


  public static BcelShadow makeStaticInitialization(BcelWorld world, LazyMethodGen enclosingMethod) {
    InstructionList body = enclosingMethod.getBody();
    // move the start past ajc$preClinit
    InstructionHandle clinitStart = body.getStart();
    if (clinitStart.getInstruction() instanceof InvokeInstruction) {
      InvokeInstruction ii = (InvokeInstruction) clinitStart.getInstruction();
      if (ii.getName(enclosingMethod.getEnclosingClass().getConstantPool()).equals(NameMangler.AJC_PRE_CLINIT_NAME)) {
        clinitStart = clinitStart.getNext();
      }
    }

    InstructionHandle clinitEnd = body.getEnd();
View Full Code Here


  }

  private Type[] getSuperConstructorParameterTypes() {
    // assert getKind() == PreInitialization
    InstructionHandle superCallHandle = getRange().getEnd().getNext();
    InvokeInstruction superCallInstruction = (InvokeInstruction) superCallHandle.getInstruction();
    return superCallInstruction.getArgumentTypes(getEnclosingClass().getConstantPool());
  }
View Full Code Here

      InstructionHandle next = curr.getNext();
      Instruction inst = curr.getInstruction();

      // open-up method call
      if ((inst instanceof InvokeInstruction)) {
        InvokeInstruction invoke = (InvokeInstruction) inst;
        ResolvedType callee = m_aspectGen.getWorld().resolve(UnresolvedType.forName(invoke.getClassName(cpg)));

        // look in the whole method list and not just declared for super calls and alike
        List<ResolvedMember> methods = callee.getMethodsWithoutIterator(false, true, false);
        for (ResolvedMember resolvedMember : methods) {
          if (invoke.getName(cpg).equals(resolvedMember.getName())
              && invoke.getSignature(cpg).equals(resolvedMember.getSignature()) && !resolvedMember.isPublic()) {
            if ("<init>".equals(invoke.getName(cpg))) {
              // skipping open up for private constructor
              // can occur when aspect new a private inner type
              // too complex to handle new + dup + .. + invokespecial here.
              aroundAdvice.setCanInline(false);
              realizedCannotInline = true;
            } else {
              // specific handling for super.foo() calls, where foo is non public
              ResolvedType memberType = m_aspectGen.getWorld().resolve(resolvedMember.getDeclaringType());
              if (!aspectType.equals(memberType) && memberType.isAssignableFrom(aspectType)) {
                // old test was...
                // if (aspectType.getSuperclass() != null
                // && aspectType.getSuperclass().getName().equals(resolvedMember.getDeclaringType().getName())) {
                ResolvedMember accessor = createOrGetInlineAccessorForSuperDispatch(resolvedMember);
                InvokeInstruction newInst = factory.createInvoke(aspectType.getName(), accessor.getName(),
                    BcelWorld.makeBcelType(accessor.getReturnType()),
                    BcelWorld.makeBcelTypes(accessor.getParameterTypes()), Constants.INVOKEVIRTUAL);
                curr.setInstruction(newInst);
              } else {
                ResolvedMember accessor = createOrGetInlineAccessorForMethod(resolvedMember);
                InvokeInstruction newInst = factory.createInvoke(aspectType.getName(), accessor.getName(),
                    BcelWorld.makeBcelType(accessor.getReturnType()),
                    BcelWorld.makeBcelTypes(accessor.getParameterTypes()), Constants.INVOKESTATIC);
                curr.setInstruction(newInst);
              }
            }

            break;// ok we found a matching callee member and swapped the instruction with the accessor
          }
        }
      } else if (inst instanceof FieldInstruction) {
        FieldInstruction invoke = (FieldInstruction) inst;
        ResolvedType callee = m_aspectGen.getWorld().resolve(UnresolvedType.forName(invoke.getClassName(cpg)));
        for (int i = 0; i < callee.getDeclaredJavaFields().length; i++) {
          ResolvedMember resolvedMember = callee.getDeclaredJavaFields()[i];
          if (invoke.getName(cpg).equals(resolvedMember.getName())
              && invoke.getSignature(cpg).equals(resolvedMember.getSignature()) && !resolvedMember.isPublic()) {
            final ResolvedMember accessor;
            if ((inst.opcode == Constants.GETFIELD) || (inst.opcode == Constants.GETSTATIC)) {
              accessor = createOrGetInlineAccessorForFieldGet(resolvedMember);
            } else {
              accessor = createOrGetInlineAccessorForFieldSet(resolvedMember);
            }
            InvokeInstruction newInst = factory.createInvoke(aspectType.getName(), accessor.getName(),
                BcelWorld.makeBcelType(accessor.getReturnType()),
                BcelWorld.makeBcelTypes(accessor.getParameterTypes()), Constants.INVOKESTATIC);
            curr.setInstruction(newInst);

            break;// ok we found a matching callee member and swapped the instruction with the accessor
View Full Code Here

        InstructionList insList = aMethod.getBody();
        InstructionHandle handle = insList.getStart();
        while (handle != null) {
          if (handle.getInstruction().opcode == Constants.INVOKESPECIAL) {
            ConstantPool cpg = newParentTarget.getConstantPool();
            InvokeInstruction invokeSpecial = (InvokeInstruction) handle.getInstruction();
            if (invokeSpecial.getClassName(cpg).equals(currentParent)
                && invokeSpecial.getMethodName(cpg).equals("<init>")) {
              // System.err.println("Transforming super call '<init>" + invokeSpecial.getSignature(cpg) + "'");

              // 1. Check there is a ctor in the new parent with
              // the same signature
              ResolvedMember newCtor = getConstructorWithSignature(newParent, invokeSpecial.getSignature(cpg));

              if (newCtor == null) {

                // 2. Check ITDCs to see if the necessary ctor is provided that way
                boolean satisfiedByITDC = false;
                for (Iterator<ConcreteTypeMunger> ii = newParentTarget.getType()
                    .getInterTypeMungersIncludingSupers().iterator(); ii.hasNext() && !satisfiedByITDC;) {
                  ConcreteTypeMunger m = ii.next();
                  if (m.getMunger() instanceof NewConstructorTypeMunger) {
                    if (m.getSignature().getSignature().equals(invokeSpecial.getSignature(cpg))) {
                      satisfiedByITDC = true;
                    }
                  }
                }

                if (!satisfiedByITDC) {
                  String csig = createReadableCtorSig(newParent, cpg, invokeSpecial);
                  weaver.getWorld()
                      .getMessageHandler()
                      .handleMessage(
                          MessageUtil.error(
                              "Unable to modify hierarchy for " + newParentTarget.getClassName()
                                  + " - the constructor " + csig + " is missing",
                              this.getSourceLocation()));
                  return false;
                }
              }

              int idx = cpg.addMethodref(newParent.getName(), invokeSpecial.getMethodName(cpg),
                  invokeSpecial.getSignature(cpg));
              invokeSpecial.setIndex(idx);
            }
          }
          handle = handle.getNext();
        }
      }
View Full Code Here

      r.associateWithTargets(Range.genStart(body, call.getNext()), Range.genEnd(body));
    }
  }

  private boolean isThisCall(InstructionHandle ih) {
    InvokeInstruction inst = (InvokeInstruction) ih.getInstruction();
    return inst.getClassName(cpg).equals(clazz.getName());
  }
View Full Code Here

   * get a called method: Assumes the called method is in this class, and the reference to it is exact (a la INVOKESPECIAL).
   *
   * @param ih The InvokeInstruction instructionHandle pointing to the called method.
   */
  private LazyMethodGen getCalledMethod(InstructionHandle ih) {
    InvokeInstruction inst = (InvokeInstruction) ih.getInstruction();

    String methodName = inst.getName(cpg);
    String signature = inst.getSignature(cpg);

    return clazz.getLazyMethodGen(methodName, signature);
  }
View Full Code Here

        if (canMatch(Shadow.FieldGet)) {
          matchGetInstruction(mg, ih, enclosingShadow, shadowAccumulator);
        }
      }
    } else if (i instanceof InvokeInstruction) {
      InvokeInstruction ii = (InvokeInstruction) i;
      if (ii.getMethodName(clazz.getConstantPool()).equals("<init>")) {
        if (canMatch(Shadow.ConstructorCall)) {
          match(BcelShadow.makeConstructorCall(world, mg, ih, enclosingShadow), shadowAccumulator);
        }
      } else if (ii.opcode == Constants.INVOKESPECIAL) {
        String onTypeName = ii.getClassName(cpg);
        if (onTypeName.equals(mg.getEnclosingClass().getName())) {
          // we are private
          matchInvokeInstruction(mg, ih, ii, enclosingShadow, shadowAccumulator);
        } else {
          // we are a super call, and this is not a join point in
View Full Code Here

      r.associateWithTargets(Range.genStart(body, call.getNext()), Range.genEnd(body));
    }
  }

  private boolean isThisCall(InstructionHandle ih) {
    InvokeInstruction inst = (InvokeInstruction) ih.getInstruction();
    return inst.getClassName(cpg).equals(clazz.getName());
  }
View Full Code Here

   * get a called method: Assumes the called method is in this class, and the reference to it is exact (a la INVOKESPECIAL).
   *
   * @param ih The InvokeInstruction instructionHandle pointing to the called method.
   */
  private LazyMethodGen getCalledMethod(InstructionHandle ih) {
    InvokeInstruction inst = (InvokeInstruction) ih.getInstruction();

    String methodName = inst.getName(cpg);
    String signature = inst.getSignature(cpg);

    return clazz.getLazyMethodGen(methodName, signature);
  }
View Full Code Here

        if (canMatch(Shadow.FieldGet)) {
          matchGetInstruction(mg, ih, enclosingShadow, shadowAccumulator);
        }
      }
    } else if (i instanceof InvokeInstruction) {
      InvokeInstruction ii = (InvokeInstruction) i;
      if (ii.getMethodName(clazz.getConstantPool()).equals("<init>")) {
        if (canMatch(Shadow.ConstructorCall)) {
          match(BcelShadow.makeConstructorCall(world, mg, ih, enclosingShadow), shadowAccumulator);
        }
      } else if (ii.opcode == Constants.INVOKESPECIAL) {
        String onTypeName = ii.getClassName(cpg);
        if (onTypeName.equals(mg.getEnclosingClass().getName())) {
          // we are private
          matchInvokeInstruction(mg, ih, ii, enclosingShadow, shadowAccumulator);
        } else {
          // we are a super call, and this is not a join point in
View Full Code Here

TOP

Related Classes of org.aspectj.apache.bcel.generic.InvokeInstruction

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.