当前位置: 首页>>代码示例>>Java>>正文


Java ConstantPool.getConstant方法代码示例

本文整理汇总了Java中org.apache.bcel.classfile.ConstantPool.getConstant方法的典型用法代码示例。如果您正苦于以下问题:Java ConstantPool.getConstant方法的具体用法?Java ConstantPool.getConstant怎么用?Java ConstantPool.getConstant使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.bcel.classfile.ConstantPool的用法示例。


在下文中一共展示了ConstantPool.getConstant方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: visitConstantMethodref

import org.apache.bcel.classfile.ConstantPool; //导入方法依赖的package包/类
public void visitConstantMethodref(ConstantMethodref ref)
{
    ConstantPool    pool = javaClass.getConstantPool();
    String          cstr = ref.getClass(pool);

    if (cstr.equals("java.lang.Class"))
    {
        int     iname = ref.getNameAndTypeIndex();
        String  name = ((ConstantNameAndType)pool.getConstant(iname)).getName(pool);

        if (name.equals("forName")) {
            System.out.println("found Class.forName('" + javaClass.getClassName() + "')");
            ConstantNameAndType cnat = (ConstantNameAndType)pool.getConstant(iname);
            String cfnStr = cnat.getName(pool);
            if (lastConst != null) {
                refClasses.add(lastConst.replace('.', '/'));
                lastConst = null;
            }
        }
    }
}
 
开发者ID:thahn0720,项目名称:agui_eclipse_plugin,代码行数:22,代码来源:ClassVisitorSearchCFN.java

示例2: processConstant

import org.apache.bcel.classfile.ConstantPool; //导入方法依赖的package包/类
private void processConstant(ConstantPool pool, Constant c, int i) {
	if (c == null) // don't know why, but constant[0] seems to be always
					// null.
		return;

	log("      const[" + i + "]=" + pool.constantToString(c) + " inst=" + c.getClass().getName(),
			Project.MSG_DEBUG);
	byte tag = c.getTag();
	switch (tag) {
	// reverse engineered from ConstantPool.constantToString..
	case Constants.CONSTANT_Class:
		int ind = ((ConstantClass) c).getNameIndex();
		c = pool.getConstant(ind, Constants.CONSTANT_Utf8);
		String className = Utility.compactClassName(((ConstantUtf8) c).getBytes(), false);
		log("      classNamePre=" + className, Project.MSG_DEBUG);
		className = getRidOfArray(className);
		String firstLetter = className.charAt(0) + "";
		if (primitives.contains(firstLetter))
			return;
		log("      className=" + className, Project.MSG_VERBOSE);
		design.checkClass(className);
		break;
	default:

	}
}
 
开发者ID:cniweb,项目名称:ant-contrib,代码行数:27,代码来源:VerifyDesignDelegate.java

示例3: getSurroundingTryBlock

import org.apache.bcel.classfile.ConstantPool; //导入方法依赖的package包/类
public static @CheckForNull
CodeException getSurroundingTryBlock(ConstantPool constantPool, Code code, @CheckForNull String vmNameOfExceptionClass, int pc) {
    int size = Integer.MAX_VALUE;
    if (code.getExceptionTable() == null)
        return null;
    CodeException result = null;
    for (CodeException catchBlock : code.getExceptionTable()) {
        if (vmNameOfExceptionClass != null) {
            Constant catchType = constantPool.getConstant(catchBlock.getCatchType());
            if (catchType == null || catchType instanceof ConstantClass
                    && !((ConstantClass) catchType).getBytes(constantPool).equals(vmNameOfExceptionClass))
                continue;
        }
        int startPC = catchBlock.getStartPC();
        int endPC = catchBlock.getEndPC();
        if (pc >= startPC && pc <= endPC) {
            int thisSize = endPC - startPC;
            if (size > thisSize) {
                size = thisSize;
                result = catchBlock;
            }
        }
    }
    return result;
}
 
开发者ID:ytus,项目名称:findbugs-all-the-bugs,代码行数:26,代码来源:Util.java

示例4: setField

import org.apache.bcel.classfile.ConstantPool; //导入方法依赖的package包/类
/**
 * Called to indicate that a field load or store was encountered.
 *
 * @param cpIndex
 *            the constant pool index of the fieldref
 * @param isStatic
 *            true if it is a static field access
 * @param isLoad
 *            true if the access is a load
 */
private void setField(int cpIndex, boolean isStatic, boolean isLoad) {
    // We only allow one field access for an accessor method.
    accessCount++;
    if (accessCount != 1) {
        access = null;
        return;
    }

    ConstantPool cp = javaClass.getConstantPool();
    ConstantFieldref fieldref = (ConstantFieldref) cp.getConstant(cpIndex);

    ConstantClass cls = (ConstantClass) cp.getConstant(fieldref.getClassIndex());
    String className = cls.getBytes(cp).replace('/', '.');

    ConstantNameAndType nameAndType = (ConstantNameAndType) cp.getConstant(fieldref.getNameAndTypeIndex());
    String fieldName = nameAndType.getName(cp);
    String fieldSig = nameAndType.getSignature(cp);


        XField xfield = Hierarchy.findXField(className, fieldName, fieldSig, isStatic);
        if (xfield != null && xfield.isStatic() == isStatic && isValidAccessMethod(methodSig, xfield, isLoad)) {
            access = new InnerClassAccess(methodName, methodSig, xfield, isLoad);
        }
   
}
 
开发者ID:ytus,项目名称:findbugs-all-the-bugs,代码行数:36,代码来源:InnerClassAccessMap.java

示例5: setField

import org.apache.bcel.classfile.ConstantPool; //导入方法依赖的package包/类
/**
 * Called to indicate that a field load or store was encountered.
 *
 * @param cpIndex
 *            the constant pool index of the fieldref
 * @param isStatic
 *            true if it is a static field access
 * @param isLoad
 *            true if the access is a load
 */
private void setField(int cpIndex, boolean isStatic, boolean isLoad) {
    // We only allow one field access for an accessor method.
    accessCount++;
    if (accessCount != 1) {
        access = null;
        return;
    }

    ConstantPool cp = javaClass.getConstantPool();
    ConstantFieldref fieldref = (ConstantFieldref) cp.getConstant(cpIndex);

    ConstantClass cls = (ConstantClass) cp.getConstant(fieldref.getClassIndex());
    String className = cls.getBytes(cp).replace('/', '.');

    ConstantNameAndType nameAndType = (ConstantNameAndType) cp.getConstant(fieldref.getNameAndTypeIndex());
    String fieldName = nameAndType.getName(cp);
    String fieldSig = nameAndType.getSignature(cp);


        XField xfield = Hierarchy.findXField(className, fieldName, fieldSig, isStatic);
        if (xfield != null && xfield.isStatic() == isStatic && isValidAccessMethod(methodSig, xfield, isLoad)) {
            access = new InnerClassAccess(methodName, methodSig, xfield, isLoad);
        }

}
 
开发者ID:OpenNTF,项目名称:FindBug-for-Domino-Designer,代码行数:36,代码来源:InnerClassAccessMap.java

示例6: createClass

import org.apache.bcel.classfile.ConstantPool; //导入方法依赖的package包/类
/** 
 * Override this method to create you own classes on the fly. The
 * name contains the special token $$BCEL$$. Everything before that
 * token is consddered to be a package name. You can encode you own
 * arguments into the subsequent string. You must regard however not
 * to use any "illegal" characters, i.e., characters that may not
 * appear in a Java class name too<br>
 *
 * The default implementation interprets the string as a encoded compressed
 * Java class, unpacks and decodes it with the Utility.decode() method, and
 * parses the resulting byte array and returns the resulting JavaClass object.
 *
 * @param class_name compressed byte code with "$$BCEL$$" in it
 */
protected JavaClass createClass( String class_name ) {
    int index = class_name.indexOf("$$BCEL$$");
    String real_name = class_name.substring(index + 8);
    JavaClass clazz = null;
    try {
        byte[] bytes = Utility.decode(real_name, true);
        ClassParser parser = new ClassParser(new ByteArrayInputStream(bytes), "foo");
        clazz = parser.parse();
    } catch (Throwable e) {
        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;
}
 
开发者ID:Hu6,项目名称:VestaClient,代码行数:36,代码来源:ClassLoader.java

示例7: flagTests

import org.apache.bcel.classfile.ConstantPool; //导入方法依赖的package包/类
public void flagTests(HashSet<String> tests) {
    if (true == _clazz.isAbstract()) {
        return;
    }

    ConstantPool pool = _clazz.getConstantPool();
    for (int i = 0; i < pool.getLength(); ++i) {
        Constant constant = pool.getConstant(i);
        if (null == constant) {
            continue;
        }
        Byte tag = constant.getTag();
        if (Constants.CONSTANT_Utf8 != tag) {
            continue;
        }
        String constantAsString = pool.constantToString(constant);
        if (constantAsString.contains("Lorg/junit/Test")) {
            tests.add(_clazz.getClassName());
        }
    }
}
 
开发者ID:burkemw3,项目名称:turbo-athena,代码行数:22,代码来源:TestVisitor.java

示例8: JavaClass

import org.apache.bcel.classfile.ConstantPool; //导入方法依赖的package包/类
/**
 * Read class definition from an input stream.
 * 
 * @param filename
 *          the name of the class file (used to determine the class name)
 * @param is
 *          the input stream to read the class file from
 * @throws IOException
 *           if I/O exception occurs while reading from the input stream
 */
public JavaClass(String filename, InputStream is) throws IOException {
  ClassParser parser = new ClassParser(is, filename);
  org.apache.bcel.classfile.JavaClass clazz = parser.parse();
  ConstantPool cp = clazz.getConstantPool();
  name = clazz.getClassName();

  for (Constant c : cp.getConstantPool()) {
    if (c instanceof ConstantClass) {
      ConstantClass cc = (ConstantClass) c;
      ConstantUtf8 cs = (ConstantUtf8) cp.getConstant(cc.getNameIndex());
      String cn = new String(cs.getBytes());
      if (cn.contains("["))
        continue;
      cn = cn.replaceAll("^\\[L", "");
      cn = cn.replaceAll(";", "");
      cn = cn.replaceAll("/", ".");
      getDependencies().add(cn);
    }
  }
}
 
开发者ID:mizdebsk,项目名称:java-deptools,代码行数:31,代码来源:JavaClass.java

示例9: toString

import org.apache.bcel.classfile.ConstantPool; //导入方法依赖的package包/类
/**
 * @return mnemonic for instruction with symbolic references resolved
 */
public String toString( ConstantPool cp ) {
    Constant c = cp.getConstant(index);
    StringTokenizer tok = new StringTokenizer(cp.constantToString(c));
    return Constants.OPCODE_NAMES[opcode] + " " + tok.nextToken().replace('.', '/')
            + tok.nextToken();
}
 
开发者ID:Hu6,项目名称:VestaClient,代码行数:10,代码来源:InvokeInstruction.java

示例10: getSignature

import org.apache.bcel.classfile.ConstantPool; //导入方法依赖的package包/类
/** @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();
}
 
开发者ID:Hu6,项目名称:VestaClient,代码行数:9,代码来源:FieldOrMethod.java

示例11: getName

import org.apache.bcel.classfile.ConstantPool; //导入方法依赖的package包/类
/** @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();
}
 
开发者ID:Hu6,项目名称:VestaClient,代码行数:9,代码来源:FieldOrMethod.java

示例12: getClassName

import org.apache.bcel.classfile.ConstantPool; //导入方法依赖的package包/类
/** @return name of the referenced class/interface
 *  @deprecated If the instruction references an array class,
 *    this method will return "java.lang.Object".
 *    For code generated by Java 1.5, this answer is
 *    sometimes wrong (e.g., if the "clone()" method is
 *    called on an array).  A better idea is to use
 *    the getReferenceType() method, which correctly distinguishes
 *    between class types and array types.
 */
public String getClassName( ConstantPoolGen cpg ) {
    ConstantPool cp = cpg.getConstantPool();
    ConstantCP cmr = (ConstantCP) cp.getConstant(index);
    String className = cp.getConstantString(cmr.getClassIndex(),
            org.apache.bcel.Constants.CONSTANT_Class);
    if (className.startsWith("[")) {
        // Turn array classes into java.lang.Object.
        return "java.lang.Object";
    }
    return className.replace('/', '.');
}
 
开发者ID:Hu6,项目名称:VestaClient,代码行数:21,代码来源:FieldOrMethod.java

示例13: getReferenceType

import org.apache.bcel.classfile.ConstantPool; //导入方法依赖的package包/类
/**
 * Return the reference type representing the class, interface,
 * or array class referenced by the instruction.
 * @param cpg the ConstantPoolGen used to create the instruction
 * @return an ObjectType (if the referenced class type is a class
 *   or interface), or an ArrayType (if the referenced class
 *   type is an array class)
 */
public ReferenceType getReferenceType( ConstantPoolGen cpg ) {
    ConstantPool cp = cpg.getConstantPool();
    ConstantCP cmr = (ConstantCP) cp.getConstant(index);
    String className = cp.getConstantString(cmr.getClassIndex(),
            org.apache.bcel.Constants.CONSTANT_Class);
    if (className.startsWith("[")) {
        return (ArrayType) Type.getType(className);
    } else {
        className = className.replace('/', '.');
        return new ObjectType(className);
    }
}
 
开发者ID:Hu6,项目名称:VestaClient,代码行数:21,代码来源:FieldOrMethod.java

示例14: toString

import org.apache.bcel.classfile.ConstantPool; //导入方法依赖的package包/类
/**
 * @return mnemonic for instruction with symbolic references resolved
 */
public String toString( ConstantPool cp ) {
    Constant c = cp.getConstant(index);
    String str = cp.constantToString(c);
    if (c instanceof ConstantClass) {
        str = str.replace('.', '/');
    }
    return org.apache.bcel.Constants.OPCODE_NAMES[opcode] + " " + str;
}
 
开发者ID:Hu6,项目名称:VestaClient,代码行数:12,代码来源:CPInstruction.java

示例15: toString

import org.apache.bcel.classfile.ConstantPool; //导入方法依赖的package包/类
/**
 * @return mnemonic for instruction with symbolic references resolved
 */
public String toString(ConstantPool cp) {
    Constant c = cp.getConstant(index);
    StringTokenizer tok = new StringTokenizer(cp.constantToString(c));

    return Constants.OPCODE_NAMES[opcode] + " " +
            tok.nextToken().replace('.', '/') + tok.nextToken();
}
 
开发者ID:miuirussia,项目名称:KJBE,代码行数:11,代码来源:InvokeInstruction.java


注:本文中的org.apache.bcel.classfile.ConstantPool.getConstant方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。