Package org.aspectj.apache.bcel.classfile

Examples of org.aspectj.apache.bcel.classfile.ConstantPool


    }
    return retval;
  }

  public Member makeJoinPointSignatureForMethodInvocation(LazyClassGen cg, InvokeInstruction ii) {
    ConstantPool cpg = cg.getConstantPool();
    String name = ii.getName(cpg);
    String declaring = ii.getClassName(cpg);
    UnresolvedType declaringType = null;

    String signature = ii.getSignature(cpg);
View Full Code Here


    // try finding outer class name from InnerClasses attribute assigned to this class
    for (Attribute attr : javaClass.getAttributes()) {
      if (attr instanceof InnerClasses) {
        // search for InnerClass entry that has current class as inner and some other class as outer
        InnerClass[] innerClss = ((InnerClasses) attr).getInnerClasses();
        ConstantPool cpool = javaClass.getConstantPool();
        for (InnerClass innerCls : innerClss) {

          // skip entries that miss any necessary component, 0 index means "undefined", from JVM Spec 2nd ed. par. 4.7.5
          if (innerCls.getInnerClassIndex() == 0 || innerCls.getOuterClassIndex() == 0) {
            continue;
          }

          // resolve inner class name, check if it matches current class name
          ConstantClass innerClsInfo = (ConstantClass) cpool.getConstant(innerCls.getInnerClassIndex());

          // class names in constant pool use '/' instead of '.', from JVM Spec 2nd ed. par. 4.2
          String innerClsName = cpool.getConstantUtf8(innerClsInfo.getNameIndex()).getValue().replace('/', '.');

          if (innerClsName.compareTo(className) == 0) {
            // resolve outer class name
            ConstantClass outerClsInfo = (ConstantClass) cpool.getConstant(innerCls.getOuterClassIndex());

            // class names in constant pool use '/' instead of '.', from JVM Spec 2nd ed. par. 4.2
            String outerClsName = cpool.getConstantUtf8(outerClsInfo.getNameIndex()).getValue().replace('/', '.');

            UnresolvedType outer = UnresolvedType.forName(outerClsName);
            return outer.resolve(getResolvedTypeX().getWorld());
          }
        }
View Full Code Here

   * @param aroundAdvice
   */
  private void openAroundAdvice(LazyMethodGen aroundAdvice) {
    InstructionHandle curr = aroundAdvice.getBody().getStart();
    InstructionHandle end = aroundAdvice.getBody().getEnd();
    ConstantPool cpg = aroundAdvice.getEnclosingClass().getConstantPool();
    InstructionFactory factory = aroundAdvice.getEnclosingClass().getFactory();

    boolean realizedCannotInline = false;
    while (curr != end) {
      if (realizedCannotInline) {
View Full Code Here

    InstructionList ret = new InstructionList();
    InstructionList sourceList = donor.getBody();

    Map<InstructionHandle, InstructionHandle> srcToDest = new HashMap<InstructionHandle, InstructionHandle>();
    ConstantPool donorCpg = donor.getEnclosingClass().getConstantPool();
    ConstantPool recipientCpg = recipient.getEnclosingClass().getConstantPool();

    boolean isAcrossClass = donorCpg != recipientCpg;

    // first pass: copy the instructions directly, populate the srcToDest
    // map,
    // fix frame instructions
    for (InstructionHandle src = sourceList.getStart(); src != null; src = src.getNext()) {
      Instruction fresh = Utility.copyInstruction(src.getInstruction());
      InstructionHandle dest;

      // OPTIMIZE optimize this stuff?
      if (fresh.isConstantPoolInstruction()) {
        // need to reset index to go to new constant pool. This is
        // totally
        // a computation leak... we're testing this LOTS of times. Sigh.
        if (isAcrossClass) {
          InstructionCP cpi = (InstructionCP) fresh;
          cpi.setIndex(recipientCpg.addConstant(donorCpg.getConstant(cpi.getIndex()), donorCpg));
        }
      }
      if (src.getInstruction() == Range.RANGEINSTRUCTION) {
        dest = ret.append(Range.RANGEINSTRUCTION);
      } else if (fresh.isReturnInstruction()) {
View Full Code Here

        // belt and braces, do the attribute even on Java 5 in addition
        // to the modifier flag
        // Attribute[] oldAttrs = field.getAttributes();
        // Attribute[] newAttrs = new Attribute[oldAttrs.length + 1];
        // System.arraycopy(oldAttrs, 0, newAttrs, 0, oldAttrs.length);
        ConstantPool cpg = myGen.getConstantPool();
        int index = cpg.addUtf8("Synthetic");
        Attribute synthetic = new Synthetic(index, 0, new byte[0], cpg);
        field.addAttribute(synthetic);
        // newAttrs[newAttrs.length - 1] = synthetic;
        // field.setAttributes(newAttrs);
      }
View Full Code Here

      }
    }
  }

  public void setValue(int index) {
    ConstantPool cp = this.cp;
    Constant c = cp.getConstant(index);
    value = ((ConstantObject) c).getConstantValue(cp);
  }
View Full Code Here

      if (aMethod.getName().equals("<init>")) {
        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 ii = newParentTarget.getType().getInterTypeMungersIncludingSupers().iterator(); ii
                    .hasNext()
                    && !satisfiedByITDC;) {
                  ConcreteTypeMunger m = (ConcreteTypeMunger) 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

      e.printStackTrace();
      return null;
    }

    // Adapt the class name to the passed value
    ConstantPool cp = clazz.getConstantPool();

    ConstantClass cl = (ConstantClass)cp.getConstant(clazz.getClassNameIndex(),
                 Constants.CONSTANT_Class);
    ConstantUtf8 name = (ConstantUtf8)cp.getConstant(cl.getNameIndex(),
                 Constants.CONSTANT_Utf8);
    name.setBytes(class_name.replace('.', '/'));

    return clazz;
  }
View Full Code Here

  }

  /** @return type related with this instruction.
   */
  public Type getType(ConstantPoolGen cpg) {
    ConstantPool cp   = cpg.getConstantPool();
    String       name = cp.getConstantString(index, org.aspectj.apache.bcel.Constants.CONSTANT_Class);

    if(!name.startsWith("["))
      name = "L" + name + ";";

    return Type.getType(name);
View Full Code Here

      }
    }
  }

  private void setValue(int index) {
    ConstantPool cp  = this.cp.getConstantPool();
    Constant     c   = cp.getConstant(index);
    value = ((ConstantObject)c).getConstantValue(cp);
  }
View Full Code Here

TOP

Related Classes of org.aspectj.apache.bcel.classfile.ConstantPool

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.