本文整理汇总了Java中org.apache.bcel.classfile.ConstantNameAndType类的典型用法代码示例。如果您正苦于以下问题:Java ConstantNameAndType类的具体用法?Java ConstantNameAndType怎么用?Java ConstantNameAndType使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ConstantNameAndType类属于org.apache.bcel.classfile包,在下文中一共展示了ConstantNameAndType类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: visitConstantMethodref
import org.apache.bcel.classfile.ConstantNameAndType; //导入依赖的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;
}
}
}
}
示例2: checkCode
import org.apache.bcel.classfile.ConstantNameAndType; //导入依赖的package包/类
public boolean checkCode(InstructionHandle[] match)
{
InstructionHandle ih = match[0];
CPInstruction ldc_w = (CPInstruction) ih.getInstruction();
Constant cc = cpool.getConstant(ldc_w.getIndex());
if (cc.getTag() != CONSTANT_Class)
return false;
ih = match[1];
CPInstruction invokevirtual = (CPInstruction) ih.getInstruction();
ConstantMethodref cm = (ConstantMethodref) cpool.getConstant(invokevirtual.getIndex());
ConstantNameAndType cnt = (ConstantNameAndType) cpool.getConstant(cm.getNameAndTypeIndex());
if (!cnt.getName(cpool.getConstantPool()).equals("desiredAssertionStatus"))
return false;
return true;
}
示例3: visitClass
import org.apache.bcel.classfile.ConstantNameAndType; //导入依赖的package包/类
@Override
public void visitClass(ClassDescriptor classDescriptor) throws CheckedAnalysisException {
IAnalysisCache analysisCache = Global.getAnalysisCache();
ObligationFactory factory = database.getFactory();
JavaClass jclass = analysisCache.getClassAnalysis(JavaClass.class, classDescriptor);
for (Constant c : jclass.getConstantPool().getConstantPool()) {
if (c instanceof ConstantNameAndType) {
ConstantNameAndType cnt = (ConstantNameAndType) c;
String signature = cnt.getSignature(jclass.getConstantPool());
if (factory.signatureInvolvesObligations(signature)) {
super.visitClass(classDescriptor);
return;
}
} else if (c instanceof ConstantClass) {
String className = ((ConstantClass) c).getBytes(jclass.getConstantPool());
if (factory.signatureInvolvesObligations(className)) {
super.visitClass(classDescriptor);
return;
}
}
}
if (DEBUG)
System.out.println(classDescriptor + " isn't interesting for obligation analysis");
}
示例4: setField
import org.apache.bcel.classfile.ConstantNameAndType; //导入依赖的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);
}
}
示例5: setField
import org.apache.bcel.classfile.ConstantNameAndType; //导入依赖的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);
}
}
示例6: addNameAndType
import org.apache.bcel.classfile.ConstantNameAndType; //导入依赖的package包/类
/**
* Add a new NameAndType constant to the ConstantPool if it is not already
* in there.
*
* @param name Name string to add
* @param signature signature string to add
* @return index of entry
*/
public int addNameAndType( String name, String signature ) {
int ret;
int name_index, signature_index;
if ((ret = lookupNameAndType(name, signature)) != -1) {
return ret; // Already in CP
}
adjustSize();
name_index = addUtf8(name);
signature_index = addUtf8(signature);
ret = index;
constants[index++] = new ConstantNameAndType(name_index, signature_index);
String key = name + NAT_DELIM + signature;
if (!n_a_t_table.containsKey(key)) {
n_a_t_table.put(key, new Index(ret));
}
return ret;
}
示例7: CPESSC_Visitor
import org.apache.bcel.classfile.ConstantNameAndType; //导入依赖的package包/类
private CPESSC_Visitor(JavaClass _jc){
jc = _jc;
cp = _jc.getConstantPool();
cplen = cp.getLength();
CONST_Class = org.apache.bcel.classfile.ConstantClass.class;
/*
CONST_Fieldref = org.apache.bcel.classfile.ConstantFieldref.class;
CONST_Methodref = org.apache.bcel.classfile.ConstantMethodref.class;
CONST_InterfaceMethodref = org.apache.bcel.classfile.ConstantInterfaceMethodref.class;
*/
CONST_String = org.apache.bcel.classfile.ConstantString.class;
CONST_Integer = org.apache.bcel.classfile.ConstantInteger.class;
CONST_Float = org.apache.bcel.classfile.ConstantFloat.class;
CONST_Long = org.apache.bcel.classfile.ConstantLong.class;
CONST_Double = org.apache.bcel.classfile.ConstantDouble.class;
CONST_NameAndType = org.apache.bcel.classfile.ConstantNameAndType.class;
CONST_Utf8 = org.apache.bcel.classfile.ConstantUtf8.class;
carrier = new DescendingVisitor(_jc, this);
carrier.visit();
}
示例8: visitConstantNameAndType
import org.apache.bcel.classfile.ConstantNameAndType; //导入依赖的package包/类
/**
* Visit a name and type ref
*
* Look for class references in this
*
* @param obj the name and type reference being visited.
*/
@Override
public void visitConstantNameAndType(final ConstantNameAndType obj) {
final String name = obj.getName(constantPool);
if ("Ljava/lang/Class;".equals(obj.getSignature(constantPool))
&& name.startsWith("class$")) {
String classname
= name.substring("class$".length()).replace('$', '.');
// does the class have a package structure
final int index = classname.lastIndexOf('.');
if (index > 0) {
char start;
// check if the package structure is more than 1 level deep
final int index2 = classname.lastIndexOf('.', index - 1);
if (index2 != -1) {
// class name has more than 1 package level 'com.company.Class'
start = classname.charAt(index2 + 1);
} else {
// class name has only 1 package level 'package.Class'
start = classname.charAt(0);
}
// Check to see if it's an inner class 'com.company.Class$Inner'
// CheckStyle:MagicNumber OFF
if ((start > 0x40) && (start < 0x5B)) {
// first letter of the previous segment of the class name 'Class'
// is upper case ascii. so according to the spec it's an inner class
classname = classname.substring(0, index) + "$"
+ classname.substring(index + 1);
addClass(classname);
} else {
// Add the class in dotted notation 'com.company.Class'
addClass(classname);
}
// CheckStyle:MagicNumber ON
} else {
// Add a class with no package 'Class'
addClass(classname);
}
}
}
示例9: visit
import org.apache.bcel.classfile.ConstantNameAndType; //导入依赖的package包/类
@Override
public void visit(ConstantNameAndType obj) {
String methodName = obj.getName(getConstantPool());
String methodSig = obj.getSignature(getConstantPool());
if (!methodName.equals("clone"))
return;
if (!methodSig.startsWith("()"))
return;
referencesCloneMethod = true;
}
示例10: getSignature
import org.apache.bcel.classfile.ConstantNameAndType; //导入依赖的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();
}
示例11: getName
import org.apache.bcel.classfile.ConstantNameAndType; //导入依赖的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();
}
示例12: visitConstantNameAndType
import org.apache.bcel.classfile.ConstantNameAndType; //导入依赖的package包/类
public void visitConstantNameAndType(ConstantNameAndType obj){
if (obj.getTag() != Constants.CONSTANT_NameAndType){
throw new ClassConstraintException("Wrong constant tag in '"+tostring(obj)+"'.");
}
checkIndex(obj, obj.getNameIndex(), CONST_Utf8);
//checkIndex(obj, obj.getDescriptorIndex(), CONST_Utf8); //inconsistently named in BCEL, see below.
checkIndex(obj, obj.getSignatureIndex(), CONST_Utf8);
}
示例13: visitConstantFieldref
import org.apache.bcel.classfile.ConstantNameAndType; //导入依赖的package包/类
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){
throw new ClassConstraintException("Illegal descriptor (==signature) '"+sig+"' used by '"+tostring(obj)+"'.");
}
}
示例14: visitConstantMethodref
import org.apache.bcel.classfile.ConstantNameAndType; //导入依赖的package包/类
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.");
}
}
catch (ClassFormatException cfe){
throw new ClassConstraintException("Illegal descriptor (==signature) '"+sig+"' used by '"+tostring(obj)+"'.");
}
}
示例15: visitConstantInterfaceMethodref
import org.apache.bcel.classfile.ConstantNameAndType; //导入依赖的package包/类
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.");
}
}
catch (ClassFormatException cfe){
throw new ClassConstraintException("Illegal descriptor (==signature) '"+sig+"' used by '"+tostring(obj)+"'.");
}
}