Java Code Examples for org.apache.bcel.classfile.ConstantFieldref#getClassIndex()
The following examples show how to use
org.apache.bcel.classfile.ConstantFieldref#getClassIndex() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Pass2Verifier.java From commons-bcel with Apache License 2.0 | 5 votes |
@Override public void visitConstantFieldref(final ConstantFieldref obj) { if (obj.getTag() != Const.CONSTANT_Fieldref) { throw new ClassConstraintException("ConstantFieldref '"+tostring(obj)+"' has wrong tag!"); } final int name_and_type_index = obj.getNameAndTypeIndex(); final ConstantNameAndType cnat = (ConstantNameAndType) (cp.getConstant(name_and_type_index)); final 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)+"'."); } final int class_index = obj.getClassIndex(); final ConstantClass cc = (ConstantClass) (cp.getConstant(class_index)); final 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)+"'."); } final String sig = ((ConstantUtf8) (cp.getConstant(cnat.getSignatureIndex()))).getBytes(); // Field or Method sig.(=descriptor) try{ Type.getType(sig); /* Don't need the return value */ } catch (final ClassFormatException cfe) { throw new ClassConstraintException("Illegal descriptor (==signature) '"+sig+"' used by '"+tostring(obj)+"'.", cfe); } }