本文整理汇总了Java中org.apache.bcel.classfile.ConstantUtf8类的典型用法代码示例。如果您正苦于以下问题:Java ConstantUtf8类的具体用法?Java ConstantUtf8怎么用?Java ConstantUtf8使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ConstantUtf8类属于org.apache.bcel.classfile包,在下文中一共展示了ConstantUtf8类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: processConstant
import org.apache.bcel.classfile.ConstantUtf8; //导入依赖的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:
}
}
示例2: visitClassContext
import org.apache.bcel.classfile.ConstantUtf8; //导入依赖的package包/类
@Override
public void visitClassContext(ClassContext classContext) {
JavaClass jclass = classContext.getJavaClass();
// We can ignore classes that were compiled for anything
// less than JDK 1.5. This should avoid lots of unnecessary work
// when analyzing code for older VM targets.
if (BCELUtil.preTiger(jclass))
return;
boolean sawUtilConcurrentLocks = false;
for (Constant c : jclass.getConstantPool().getConstantPool())
if (c instanceof ConstantMethodref) {
ConstantMethodref m = (ConstantMethodref) c;
ConstantClass cl = (ConstantClass) jclass.getConstantPool().getConstant(m.getClassIndex());
ConstantUtf8 name = (ConstantUtf8) jclass.getConstantPool().getConstant(cl.getNameIndex());
String nameAsString = name.getBytes();
if (nameAsString.startsWith("java/util/concurrent/locks"))
sawUtilConcurrentLocks = true;
}
if (sawUtilConcurrentLocks)
super.visitClassContext(classContext);
}
示例3: visitNEW
import org.apache.bcel.classfile.ConstantUtf8; //导入依赖的package包/类
/** Checks if the constraints of operands of the said instruction(s) are satisfied. */
public void visitNEW(NEW o){
indexValid(o, o.getIndex());
Constant c = cpg.getConstant(o.getIndex());
if (! (c instanceof ConstantClass)){
constraintViolated(o, "Expecting a CONSTANT_Class operand, but found a '"+c+"'.");
}
else{
ConstantUtf8 cutf8 = (ConstantUtf8) (cpg.getConstant( ((ConstantClass) c).getNameIndex() ));
Type t = Type.getType("L"+cutf8.getBytes()+";");
if (t instanceof ArrayType){
constraintViolated(o, "NEW must not be used to create an array.");
}
}
}
示例4: CPESSC_Visitor
import org.apache.bcel.classfile.ConstantUtf8; //导入依赖的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();
}
示例5: visitSourceFile
import org.apache.bcel.classfile.ConstantUtf8; //导入依赖的package包/类
public void visitSourceFile(SourceFile obj){//vmspec2 4.7.7
// zero or one SourceFile attr per ClassFile: see visitJavaClass()
checkIndex(obj, obj.getNameIndex(), CONST_Utf8);
String name = ((ConstantUtf8) cp.getConstant(obj.getNameIndex())).getBytes();
if (! name.equals("SourceFile")){
throw new ClassConstraintException("The SourceFile attribute '"+tostring(obj)+"' is not correctly named 'SourceFile' but '"+name+"'.");
}
checkIndex(obj, obj.getSourceFileIndex(), CONST_Utf8);
String sourcefilename = ((ConstantUtf8) cp.getConstant(obj.getSourceFileIndex())).getBytes(); //==obj.getSourceFileName() ?
String sourcefilenamelc = sourcefilename.toLowerCase(Locale.ENGLISH);
if ( (sourcefilename.indexOf('/') != -1) ||
(sourcefilename.indexOf('\\') != -1) ||
(sourcefilename.indexOf(':') != -1) ||
(sourcefilenamelc.lastIndexOf(".java") == -1) ){
addMessage("SourceFile attribute '"+tostring(obj)+"' has a funny name: remember not to confuse certain parsers working on javap's output. Also, this name ('"+sourcefilename+"') is considered an unqualified (simple) file name only.");
}
}
示例6: createClass
import org.apache.bcel.classfile.ConstantUtf8; //导入依赖的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;
}
示例7: JavaClass
import org.apache.bcel.classfile.ConstantUtf8; //导入依赖的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);
}
}
}
示例8: visitClassContext
import org.apache.bcel.classfile.ConstantUtf8; //导入依赖的package包/类
@Override
public void visitClassContext(ClassContext classContext) {
JavaClass javaClass = classContext.getJavaClass();
if (!javaClass.getPackageName().contains(".pages")) {
return;
}
//The package contains ".pages" and has some references to tapestry
// then it must be an endpoint.
//The constants pool contains all references that are reused in the bytecode
// including full class name and interface name.
if (javaClass.getPackageName().contains(".pages")) {
ConstantPool constants = javaClass.getConstantPool();
for (Constant c : constants.getConstantPool()) {
if (c instanceof ConstantUtf8) {
ConstantUtf8 utf8 = (ConstantUtf8) c;
String constantValue = String.valueOf(utf8.getBytes());
if (constantValue.startsWith("Lorg/apache/tapestry5/annotations")) {
bugReporter.reportBug(new BugInstance(this, TAPESTRY_ENDPOINT_TYPE, Priorities.LOW_PRIORITY) //
.addClass(javaClass));
return;
}
}
}
}
}
示例9: removeLocalTypeTables
import org.apache.bcel.classfile.ConstantUtf8; //导入依赖的package包/类
static void removeLocalTypeTables(MethodGen mg) {
ConstantPoolGen cpg = mg.getConstantPool();
Attribute[] a = mg.getCodeAttributes();
for (int i = 0; i < a.length; i++) {
String attribName = ((ConstantUtf8) cpg.getConstant(a[i]
.getNameIndex())).getBytes();
if (attribName.equals("LocalVariableTypeTable")) {
mg.removeCodeAttribute(a[i]);
}
}
}
示例10: visitConstantUtf8
import org.apache.bcel.classfile.ConstantUtf8; //导入依赖的package包/类
@Override
public void visitConstantUtf8(ConstantUtf8 obj) {
String name = obj.getBytes();
if (this.parser.isDebug()) {
this.parser.debug("visitConstantUtf8: obj.getBytes(this.cp) = " + name);
}
if (SqlParseUtil.isSQL(name)) {
List<TableInfo> tables = SqlParseUtil.parserSql(name);
if (tables != null) {
for (TableInfo table : tables) {
this.jClass.getDetail().addTable(table);
}
}
}
}
示例11: readAnnotationValues
import org.apache.bcel.classfile.ConstantUtf8; //导入依赖的package包/类
private Map<String, Object> readAnnotationValues(DataInputStream bytes, int numPairs) throws IOException {
Map<String, Object> values = new HashMap<String, Object>();
for (int j = 0; j < numPairs; j++) {
int memberNameIndex = bytes.readUnsignedShort();
String memberName = ((ConstantUtf8) getConstantPool().getConstant(memberNameIndex)).getBytes();
if (DEBUG)
System.out.println("memberName: " + memberName);
Object value = readAnnotationValue(bytes);
if (DEBUG)
System.out.println(memberName + ":" + value);
values.put(memberName, value);
}
return values;
}
示例12: getAnnotationName
import org.apache.bcel.classfile.ConstantUtf8; //导入依赖的package包/类
private @DottedClassName
String getAnnotationName(DataInputStream bytes) throws IOException {
int annotationNameIndex = bytes.readUnsignedShort();
String annotationName = ((ConstantUtf8) getConstantPool().getConstant(annotationNameIndex)).getBytes().replace('/', '.');
annotationName = annotationName.substring(1, annotationName.length() - 1);
if (DEBUG)
System.out.println("Annotation name: " + annotationName);
return annotationName;
}
示例13: addUtf8
import org.apache.bcel.classfile.ConstantUtf8; //导入依赖的package包/类
/**
* Add a new Utf8 constant to the ConstantPool, if it is not already in there.
*
* @param n Utf8 string to add
* @return index of entry
*/
public int addUtf8( String n ) {
int ret;
if ((ret = lookupUtf8(n)) != -1) {
return ret; // Already in CP
}
adjustSize();
ret = index;
constants[index++] = new ConstantUtf8(n);
if (!utf8_table.containsKey(n)) {
utf8_table.put(n, new Index(ret));
}
return ret;
}
示例14: getSignature
import org.apache.bcel.classfile.ConstantUtf8; //导入依赖的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();
}
示例15: getName
import org.apache.bcel.classfile.ConstantUtf8; //导入依赖的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();
}