Package org.aspectj.apache.bcel.classfile

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


   * @return signature of referenced method/field.
   */
  public String getSignature(ConstantPool cp) {
    if (signature == null) {
      ConstantCP cmr = (ConstantCP) cp.getConstant(index);
      ConstantNameAndType cnat = (ConstantNameAndType) cp.getConstant(cmr.getNameAndTypeIndex());
      signature = ((ConstantUtf8) cp.getConstant(cnat.getSignatureIndex())).getValue();
    }
    return signature;
  }
View Full Code Here


   * @return name of referenced method/field.
   */
  public String getName(ConstantPool cp) {
    if (name == null) {
      ConstantCP cmr = (ConstantCP) cp.getConstant(index);
      ConstantNameAndType cnat = (ConstantNameAndType) cp.getConstant(cmr.getNameAndTypeIndex());
      name = ((ConstantUtf8) cp.getConstant(cnat.getNameIndex())).getValue();
    }
    return name;
  }
View Full Code Here

      String short_method_class   = Utility.compactClassName(method_class); // I.e., remove java.lang.
      short_method_class = Utility.compactClassName(method_class); // I.e., remove java.lang.
      short_method_class = Utility.compactClassName(short_method_class, class_package + ".", true); // Remove class package prefix

      // Get method signature
      ConstantNameAndType c2 = (ConstantNameAndType)constant_pool.getConstant(name_index, CONSTANT_NameAndType);
      String signature = constant_pool.constantToString(c2.getSignatureIndex(), CONSTANT_Utf8);
      // Get array of strings containing the argument types
      String[] args = Utility.methodSignatureArgumentTypes(signature, false);
     
      // Get return type string
      String type = Utility.methodSignatureReturnType(signature, false);
      String ret_type = Class2HTML.referenceType(type);

      StringBuffer buf = new StringBuffer("(");
      for(int i=0; i < args.length; i++) {
  buf.append(Class2HTML.referenceType(args[i]));
  if(i < args.length - 1)
    buf.append(",&nbsp;");
      }     
      buf.append(")");

      String arg_types = buf.toString();
     
      if(method_class.equals(class_name)) // Method is local to class
  ref = "<A HREF=\"" + class_name + "_code.html#method" + getMethodNumber(method_name + signature) +
    "\" TARGET=Code>" + html_method_name + "</A>";
      else
  ref = "<A HREF=\"" + method_class + ".html" + "\" TARGET=_top>" + short_method_class +
    "</A>." + html_method_name;

      constant_ref[index] = ret_type + "&nbsp;<A HREF=\"" + class_name + "_cp.html#cp" + class_index +
  "\" TARGET=Constants>" +
  short_method_class + "</A>.<A HREF=\"" + class_name + "_cp.html#cp" +
  index +  "\" TARGET=ConstantPool>" + html_method_name + "</A>&nbsp;" + arg_types;

      file.println("<P><TT>" + ret_type + "&nbsp;" + ref + arg_types + "&nbsp;</TT>\n<UL>" +
       "<LI><A HREF=\"#cp" + class_index + "\">Class index(" + class_index +  ")</A>\n" +
       "<LI><A HREF=\"#cp" + name_index + "\">NameAndType index(" + name_index + ")</A></UL>");
      break;

    case CONSTANT_Fieldref:
      // Get class_index and name_and_type_index
      ConstantFieldref c3 = (ConstantFieldref)constant_pool.getConstant(index, CONSTANT_Fieldref);
      class_index = c3.getClassIndex();
      name_index  = c3.getNameAndTypeIndex();

      // Get method name and its class (compacted)
      String field_class = constant_pool.constantToString(class_index, CONSTANT_Class);
      String short_field_class = Utility.compactClassName(field_class); // I.e., remove java.lang.
      short_field_class = Utility.compactClassName(short_field_class, class_package + ".", true); // Remove class package prefix

      String field_name  = constant_pool.constantToString(name_index, CONSTANT_NameAndType);

      if(field_class.equals(class_name)) // Field is local to class
  ref = "<A HREF=\"" + field_class + "_methods.html#field" +
    field_name + "\" TARGET=Methods>" + field_name + "</A>";
      else
  ref = "<A HREF=\"" + field_class + ".html\" TARGET=_top>" +
    short_field_class + "</A>." + field_name + "\n";

      constant_ref[index] = "<A HREF=\"" + class_name + "_cp.html#cp" + class_index +  "\" TARGET=Constants>" +
  short_field_class + "</A>.<A HREF=\"" + class_name + "_cp.html#cp" +
  index +  "\" TARGET=ConstantPool>" + field_name + "</A>";
                        
      file.println("<P><TT>" + ref + "</TT><BR>\n" + "<UL>" +
       "<LI><A HREF=\"#cp" + class_index + "\">Class(" + class_index +  ")</A><BR>\n" +
       "<LI><A HREF=\"#cp" + name_index + "\">NameAndType(" + name_index + ")</A></UL>");
      break;
       
    case CONSTANT_Class:
      ConstantClass c4 = (ConstantClass)constant_pool.getConstant(index, CONSTANT_Class);
      name_index  = c4.getNameIndex();
      String class_name2  = constant_pool.constantToString(index, tag); // / -> .
      String short_class_name = Utility.compactClassName(class_name2); // I.e., remove java.lang.
      short_class_name = Utility.compactClassName(short_class_name, class_package + ".", true); // Remove class package prefix

      ref = "<A HREF=\"" + class_name2 + ".html\" TARGET=_top>" + short_class_name + "</A>";
      constant_ref[index] = "<A HREF=\"" + class_name + "_cp.html#cp" + index +
  "\" TARGET=ConstantPool>" + short_class_name + "</A>";
                     
      file.println("<P><TT>" + ref + "</TT><UL>" +
       "<LI><A HREF=\"#cp" + name_index + "\">Name index(" + name_index +   ")</A></UL>\n");
      break;
 
    case CONSTANT_String:
      ConstantString c5 = (ConstantString)constant_pool.getConstant(index, CONSTANT_String);
      name_index = c5.getStringIndex();

      String str = Class2HTML.toHTML(constant_pool.constantToString(index, tag));
 
      file.println("<P><TT>" + str + "</TT><UL>" +
       "<LI><A HREF=\"#cp" + name_index + "\">Name index(" + name_index +  ")</A></UL>\n");
      break;
 
    case CONSTANT_NameAndType:
      ConstantNameAndType c6 = (ConstantNameAndType)constant_pool.getConstant(index, CONSTANT_NameAndType);
      name_index = c6.getNameIndex();
      int signature_index = c6.getSignatureIndex();

      file.println("<P><TT>" + Class2HTML.toHTML(constant_pool.constantToString(index, tag)) + "</TT><UL>" +
       "<LI><A HREF=\"#cp" + name_index + "\">Name index(" + name_index + ")</A>\n" +
       "<LI><A HREF=\"#cp" + signature_index + "\">Signature index(" +
       signature_index + ")</A></UL>\n");
View Full Code Here

    public void visitConstantFieldref(ConstantFieldref obj){
      if (obj.getTag() != Constants.CONSTANT_Fieldref){
        throw new ClassConstraintException("ConstantFieldref '"+tostring(obj)+"' has wrong tag!");
      }
      int name_and_type_index = obj.getNameAndTypeIndex();
      ConstantNameAndType cnat = (ConstantNameAndType) (cp.getConstant(name_and_type_index));
      String name = ((ConstantUtf8) (cp.getConstant(cnat.getNameIndex()))).getBytes(); // Field or Method name
      if (!validFieldName(name)){
        throw new ClassConstraintException("Invalid field name '"+name+"' referenced by '"+tostring(obj)+"'.");
      }
     
      int class_index = obj.getClassIndex();
      ConstantClass cc = (ConstantClass) (cp.getConstant(class_index));
      String className = ((ConstantUtf8) (cp.getConstant(cc.getNameIndex()))).getBytes(); // Class Name in internal form
      if (! validClassName(className)){
        throw new ClassConstraintException("Illegal class name '"+className+"' used by '"+tostring(obj)+"'.");
      }

      String sig  = ((ConstantUtf8) (cp.getConstant(cnat.getSignatureIndex()))).getBytes(); // Field or Method signature(=descriptor)
           
      try{
        Type.getType(sig); /* Don't need the return value */
      }
      catch (ClassFormatError cfe){
View Full Code Here

    public void visitConstantMethodref(ConstantMethodref obj){
      if (obj.getTag() != Constants.CONSTANT_Methodref){
        throw new ClassConstraintException("ConstantMethodref '"+tostring(obj)+"' has wrong tag!");
      }
      int name_and_type_index = obj.getNameAndTypeIndex();
      ConstantNameAndType cnat = (ConstantNameAndType) (cp.getConstant(name_and_type_index));
      String name = ((ConstantUtf8) (cp.getConstant(cnat.getNameIndex()))).getBytes(); // Field or Method name
      if (!validClassMethodName(name)){
        throw new ClassConstraintException("Invalid (non-interface) method name '"+name+"' referenced by '"+tostring(obj)+"'.");
      }

      int class_index = obj.getClassIndex();
      ConstantClass cc = (ConstantClass) (cp.getConstant(class_index));
      String className = ((ConstantUtf8) (cp.getConstant(cc.getNameIndex()))).getBytes(); // Class Name in internal form
      if (! validClassName(className)){
        throw new ClassConstraintException("Illegal class name '"+className+"' used by '"+tostring(obj)+"'.");
      }

      String sig  = ((ConstantUtf8) (cp.getConstant(cnat.getSignatureIndex()))).getBytes(); // Field or Method signature(=descriptor)
           
      try{
        Type   t  = Type.getReturnType(sig);
        if ( name.equals(CONSTRUCTOR_NAME) && (t != Type.VOID) ){
          throw new ClassConstraintException("Instance initialization method must have VOID return type.");
View Full Code Here

    public void visitConstantInterfaceMethodref(ConstantInterfaceMethodref obj){
      if (obj.getTag() != Constants.CONSTANT_InterfaceMethodref){
        throw new ClassConstraintException("ConstantInterfaceMethodref '"+tostring(obj)+"' has wrong tag!");
      }
      int name_and_type_index = obj.getNameAndTypeIndex();
      ConstantNameAndType cnat = (ConstantNameAndType) (cp.getConstant(name_and_type_index));
      String name = ((ConstantUtf8) (cp.getConstant(cnat.getNameIndex()))).getBytes(); // Field or Method name
      if (!validInterfaceMethodName(name)){
        throw new ClassConstraintException("Invalid (interface) method name '"+name+"' referenced by '"+tostring(obj)+"'.");
      }

      int class_index = obj.getClassIndex();
      ConstantClass cc = (ConstantClass) (cp.getConstant(class_index));
      String className = ((ConstantUtf8) (cp.getConstant(cc.getNameIndex()))).getBytes(); // Class Name in internal form
      if (! validClassName(className)){
        throw new ClassConstraintException("Illegal class name '"+className+"' used by '"+tostring(obj)+"'.");
      }

      String sig  = ((ConstantUtf8) (cp.getConstant(cnat.getSignatureIndex()))).getBytes(); // Field or Method signature(=descriptor)
           
      try{
        Type   t  = Type.getReturnType(sig);
        if ( name.equals(STATIC_INITIALIZER_NAME) && (t != Type.VOID) ){
          addMessage("Class or interface initialization method '"+STATIC_INITIALIZER_NAME+"' usually has VOID return type instead of '"+t+"'. Note this is really not a requirement of The Java Virtual Machine Specification, Second Edition.");
View Full Code Here

       
      name = Class2HTML.referenceClass(class_index);
      str = Class2HTML.toHTML(constant_pool.constantToString(constant_pool.getConstant(index, CONSTANT_NameAndType)));

      // Get signature, i.e., types
      ConstantNameAndType c2 = (ConstantNameAndType)constant_pool.
  getConstant(index, CONSTANT_NameAndType);
      signature = constant_pool.constantToString(c2.getSignatureIndex(),
             CONSTANT_Utf8);
      String[] args = Utility.methodSignatureArgumentTypes(signature, false);
      String   type = Utility.methodSignatureReturnType(signature, false);

      buf.append(name + ".<A HREF=\"" + class_name + "_cp.html#cp" + m_index +
View Full Code Here

        if (! (c instanceof ConstantMethodref)){
          constraintViolated(o, "Indexing a constant that's not a CONSTANT_Methodref but a '"+c+"'.");
        }
        else{
          // Constants are okay due to pass2.
          ConstantNameAndType cnat = (ConstantNameAndType) (cpg.getConstant(((ConstantMethodref) c).getNameAndTypeIndex()));
          ConstantUtf8 cutf8 = (ConstantUtf8) (cpg.getConstant(cnat.getNameIndex()));
          if (cutf8.getBytes().equals(Constants.CONSTRUCTOR_NAME) && (!(o instanceof INVOKESPECIAL)) ){
            constraintViolated(o, "Only INVOKESPECIAL is allowed to invoke instance initialization methods.");
          }
          if ( (! (cutf8.getBytes().equals(Constants.CONSTRUCTOR_NAME)) ) && (cutf8.getBytes().startsWith("<")) ){
            constraintViolated(o, "No method with a name beginning with '<' other than the instance initialization methods may be called by the method invocation instructions.");
          }
        }
      }
      else{ //if (o instanceof INVOKEINTERFACE){
        Constant c = cpg.getConstant(o.getIndex());
        if (! (c instanceof ConstantInterfaceMethodref)){
          constraintViolated(o, "Indexing a constant that's not a CONSTANT_InterfaceMethodref but a '"+c+"'.");
        }
        // TODO: From time to time check if BCEL allows to detect if the
        // 'count' operand is consistent with the information in the
        // CONSTANT_InterfaceMethodref and if the last operand is zero.
        // By now, BCEL hides those two operands because they're superfluous.
       
        // Invoked method must not be <init> or <clinit>
        ConstantNameAndType cnat = (ConstantNameAndType) (cpg.getConstant(((ConstantInterfaceMethodref)c).getNameAndTypeIndex()));
        String name = ((ConstantUtf8) (cpg.getConstant(cnat.getNameIndex()))).getBytes();
        if (name.equals(Constants.CONSTRUCTOR_NAME)){
          constraintViolated(o, "Method to invoke must not be '"+Constants.CONSTRUCTOR_NAME+"'.");
        }
        if (name.equals(Constants.STATIC_INITIALIZER_NAME)){
          constraintViolated(o, "Method to invoke must not be '"+Constants.STATIC_INITIALIZER_NAME+"'.");
View Full Code Here

  /** @return signature of referenced method/field.
   */
  public String getSignature(ConstantPoolGen cpg) {
    ConstantPool        cp   = cpg.getConstantPool();
    ConstantCP          cmr  = (ConstantCP)cp.getConstant(index);
    ConstantNameAndType cnat = (ConstantNameAndType)cp.getConstant(cmr.getNameAndTypeIndex());

    return ((ConstantUtf8)cp.getConstant(cnat.getSignatureIndex())).getBytes();
  }
View Full Code Here

  /** @return name of referenced method/field.
   */
  public String getName(ConstantPoolGen cpg) {
    ConstantPool        cp   = cpg.getConstantPool();
    ConstantCP          cmr  = (ConstantCP)cp.getConstant(index);
    ConstantNameAndType cnat = (ConstantNameAndType)cp.getConstant(cmr.getNameAndTypeIndex());
    return ((ConstantUtf8)cp.getConstant(cnat.getNameIndex())).getBytes();
  }
View Full Code Here

TOP

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

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.