Package org.apache.bcel.classfile

Examples of org.apache.bcel.classfile.ConstantNameAndType


                ConstantClass s = (ConstantClass) c;
                ConstantUtf8 u8 = (ConstantUtf8) constants[s.getNameIndex()];
                return addClass(u8.getBytes());
            }
            case Constants.CONSTANT_NameAndType: {
                ConstantNameAndType n = (ConstantNameAndType) c;
                ConstantUtf8 u8 = (ConstantUtf8) constants[n.getNameIndex()];
                ConstantUtf8 u8_2 = (ConstantUtf8) constants[n.getSignatureIndex()];
                return addNameAndType(u8.getBytes(), u8_2.getBytes());
            }
            case Constants.CONSTANT_Utf8:
                return addUtf8(((ConstantUtf8) c).getBytes());
            case Constants.CONSTANT_Double:
                return addDouble(((ConstantDouble) c).getBytes());
            case Constants.CONSTANT_Float:
                return addFloat(((ConstantFloat) c).getBytes());
            case Constants.CONSTANT_Long:
                return addLong(((ConstantLong) c).getBytes());
            case Constants.CONSTANT_Integer:
                return addInteger(((ConstantInteger) c).getBytes());
            case Constants.CONSTANT_InterfaceMethodref:
            case Constants.CONSTANT_Methodref:
            case Constants.CONSTANT_Fieldref: {
                ConstantCP m = (ConstantCP) c;
                ConstantClass clazz = (ConstantClass) constants[m.getClassIndex()];
                ConstantNameAndType n = (ConstantNameAndType) constants[m.getNameAndTypeIndex()];
                ConstantUtf8 u8 = (ConstantUtf8) constants[clazz.getNameIndex()];
                String class_name = u8.getBytes().replace('/', '.');
                u8 = (ConstantUtf8) constants[n.getNameIndex()];
                String name = u8.getBytes();
                u8 = (ConstantUtf8) constants[n.getSignatureIndex()];
                String signature = u8.getBytes();
                switch (c.getTag()) {
                    case Constants.CONSTANT_InterfaceMethodref:
                        return addInterfaceMethodref(class_name, name, signature);
                    case Constants.CONSTANT_Methodref:
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).append(".<A HREF=\"").append(class_name).append("_cp.html#cp")
                        .append(m_index).append("\" TARGET=ConstantPool>").append(str).append(
                                "</A>").append("(");
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 (ClassFormatException 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

        JavaClass javaClass = classContext.getJavaClass();
        ConstantPool pool = javaClass.getConstantPool();
        boolean found = false;
        for (Constant constantEntry : pool.getConstantPool()) {
            if (constantEntry instanceof ConstantNameAndType) {
                ConstantNameAndType nt = (ConstantNameAndType) constantEntry;
                if (nt.getName(pool).equals("putIfAbsent")) {
                    found = true;
                    break;
                }
            }
        }
View Full Code Here

        ConstantPool constantPool = javaClass.getConstantPool();
        for(Constant c : constantPool.getConstantPool() ) {
            if (c instanceof ConstantMethodref || c instanceof ConstantInterfaceMethodref) {
                ConstantCP m = (ConstantCP) c;
                @DottedClassName String clazz = m.getClass(constantPool);
                ConstantNameAndType nt = (ConstantNameAndType) constantPool.getConstant(m.getNameAndTypeIndex(), Constants.CONSTANT_NameAndType);
                String name = nt.getName(constantPool);
                if (name.equals("setAttribute") && clazz.equals("javax.servlet.http.HttpSession") || (name.equals("writeObject")
                        && (clazz.equals("java.io.ObjectOutput")
                                || clazz.equals("java.io.ObjectOutputStream")))) {
                    if (DEBUG) {
                        System.out.println("Found call to " + clazz + "." + name);
View Full Code Here

        for (int i = 0; i < numConstants; ++i) {
            try {
                Constant c = cp.getConstant(i);
                if (c instanceof ConstantMethodref) {
                    ConstantMethodref cmr = (ConstantMethodref) c;
                    ConstantNameAndType cnat = (ConstantNameAndType) cp.getConstant(cmr.getNameAndTypeIndex(),
                            CONSTANT_NameAndType);
                    String methodName = ((ConstantUtf8) cp.getConstant(cnat.getNameIndex(), CONSTANT_Utf8)).getBytes();
                    String className = cp.getConstantString(cmr.getClassIndex(), CONSTANT_Class).replace('/', '.');
                    String methodSig = ((ConstantUtf8) cp.getConstant(cnat.getSignatureIndex(), CONSTANT_Utf8)).getBytes();

                    String classNameLC = className.toLowerCase();
                    String methodNameLC = methodName.toLowerCase();

                    boolean voidReturnType = methodSig.endsWith(")V");
View Full Code Here

                                ConstantCP cp = (ConstantCP) constantRefOperand;
                                ConstantClass clazz = (ConstantClass) getConstantPool().getConstant(cp.getClassIndex());
                                classConstantOperand = getStringFromIndex(clazz.getNameIndex());
                                referencedClass = DescriptorFactory.createClassDescriptor(classConstantOperand);
                                referencedXClass = null;
                                ConstantNameAndType sig = (ConstantNameAndType) getConstantPool().getConstant(
                                        cp.getNameAndTypeIndex());
                                nameConstantOperand = getStringFromIndex(sig.getNameIndex());
                                sigConstantOperand = getStringFromIndex(sig.getSignatureIndex());
                                refConstantOperand = null;
                            } else if (constantRefOperand instanceof ConstantInvokeDynamic) {
                                ConstantInvokeDynamic id = (ConstantInvokeDynamic) constantRefOperand;
                                ConstantNameAndType sig = (ConstantNameAndType) getConstantPool().getConstant(
                                        id.getNameAndTypeIndex());
                                nameConstantOperand = getStringFromIndex(sig.getNameIndex());
                                sigConstantOperand = getStringFromIndex(sig.getSignatureIndex());


                            }
                            break;
                        case M_R:
View Full Code Here

  private void visitRef(ConstantCP ccp, boolean method) {
    String class_name = ccp.getClass(_cp);
    add(class_name);

    ConstantNameAndType cnat = (ConstantNameAndType) _cp.getConstant(ccp.getNameAndTypeIndex(),
        Constants.CONSTANT_NameAndType);

    String signature = cnat.getSignature(_cp);

    if (method) {
      Type type = Type.getReturnType(signature);

      checkType(type);
View Full Code Here

TOP

Related Classes of org.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.