本文整理汇总了Java中com.sun.org.apache.bcel.internal.classfile.ConstantUtf8类的典型用法代码示例。如果您正苦于以下问题:Java ConstantUtf8类的具体用法?Java ConstantUtf8怎么用?Java ConstantUtf8使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ConstantUtf8类属于com.sun.org.apache.bcel.internal.classfile包,在下文中一共展示了ConstantUtf8类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: addUtf8
import com.sun.org.apache.bcel.internal.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(final 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;
}
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:21,代码来源:ConstantPoolGen.java
示例2: getClassString
import com.sun.org.apache.bcel.internal.classfile.ConstantUtf8; //导入依赖的package包/类
public String getClassString()
{
final ConstantUtf8 cu8 = (ConstantUtf8) getConstantPool().getConstant(idx);
return cu8.getBytes();
// ConstantClass c = (ConstantClass)getConstantPool().getConstant(idx);
// ConstantUtf8 utf8 =
// (ConstantUtf8)getConstantPool().getConstant(c.getNameIndex());
// return utf8.getBytes();
}
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:10,代码来源:ClassElementValueGen.java
示例3: getValueString
import com.sun.org.apache.bcel.internal.classfile.ConstantUtf8; //导入依赖的package包/类
public String getValueString()
{
if (super.getElementValueType() != STRING) {
throw new RuntimeException(
"Dont call getValueString() on a non STRING ElementValue");
}
final ConstantUtf8 c = (ConstantUtf8) getConstantPool().getConstant(idx);
return c.getBytes();
}
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:10,代码来源:SimpleElementValueGen.java
示例4: stringifyValue
import com.sun.org.apache.bcel.internal.classfile.ConstantUtf8; //导入依赖的package包/类
@Override
public String stringifyValue()
{
switch (super.getElementValueType())
{
case PRIMITIVE_INT:
final ConstantInteger c = (ConstantInteger) getConstantPool().getConstant(idx);
return Integer.toString(c.getBytes());
case PRIMITIVE_LONG:
final ConstantLong j = (ConstantLong) getConstantPool().getConstant(idx);
return Long.toString(j.getBytes());
case PRIMITIVE_DOUBLE:
final ConstantDouble d = (ConstantDouble) getConstantPool().getConstant(idx);
return Double.toString(d.getBytes());
case PRIMITIVE_FLOAT:
final ConstantFloat f = (ConstantFloat) getConstantPool().getConstant(idx);
return Float.toString(f.getBytes());
case PRIMITIVE_SHORT:
final ConstantInteger s = (ConstantInteger) getConstantPool().getConstant(idx);
return Integer.toString(s.getBytes());
case PRIMITIVE_BYTE:
final ConstantInteger b = (ConstantInteger) getConstantPool().getConstant(idx);
return Integer.toString(b.getBytes());
case PRIMITIVE_CHAR:
final ConstantInteger ch = (ConstantInteger) getConstantPool().getConstant(idx);
return Integer.toString(ch.getBytes());
case PRIMITIVE_BOOLEAN:
final ConstantInteger bo = (ConstantInteger) getConstantPool().getConstant(idx);
if (bo.getBytes() == 0) {
return "false";
}
return "true";
case STRING:
final ConstantUtf8 cu8 = (ConstantUtf8) getConstantPool().getConstant(idx);
return cu8.getBytes();
default:
throw new RuntimeException(
"SimpleElementValueGen class does not know how to stringify type " + super.getElementValueType());
}
}
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:41,代码来源:SimpleElementValueGen.java
示例5: stringifyValue
import com.sun.org.apache.bcel.internal.classfile.ConstantUtf8; //导入依赖的package包/类
@Override
public String stringifyValue()
{
final ConstantUtf8 cu8 = (ConstantUtf8) getConstantPool().getConstant(valueIdx);
return cu8.getBytes();
// ConstantString cu8 =
// (ConstantString)getConstantPool().getConstant(valueIdx);
// return
// ((ConstantUtf8)getConstantPool().getConstant(cu8.getStringIndex())).getBytes();
}
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:11,代码来源:EnumElementValueGen.java
示例6: getEnumTypeString
import com.sun.org.apache.bcel.internal.classfile.ConstantUtf8; //导入依赖的package包/类
public String getEnumTypeString()
{
// Constant cc = getConstantPool().getConstant(typeIdx);
// ConstantClass cu8 =
// (ConstantClass)getConstantPool().getConstant(typeIdx);
// return
// ((ConstantUtf8)getConstantPool().getConstant(cu8.getNameIndex())).getBytes();
return ((ConstantUtf8) getConstantPool().getConstant(typeIdx))
.getBytes();
// return Utility.signatureToString(cu8.getBytes());
}
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:12,代码来源:EnumElementValueGen.java
示例7: getEnumValueString
import com.sun.org.apache.bcel.internal.classfile.ConstantUtf8; //导入依赖的package包/类
public String getEnumValueString()
{
return ((ConstantUtf8) getConstantPool().getConstant(valueIdx)).getBytes();
// ConstantString cu8 =
// (ConstantString)getConstantPool().getConstant(valueIdx);
// return
// ((ConstantUtf8)getConstantPool().getConstant(cu8.getStringIndex())).getBytes();
}
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:9,代码来源:EnumElementValueGen.java
示例8: getSignature
import com.sun.org.apache.bcel.internal.classfile.ConstantUtf8; //导入依赖的package包/类
/** @return signature of referenced method/field.
*/
public String getSignature( final ConstantPoolGen cpg ) {
final ConstantPool cp = cpg.getConstantPool();
final ConstantCP cmr = (ConstantCP) cp.getConstant(super.getIndex());
final ConstantNameAndType cnat = (ConstantNameAndType) cp.getConstant(cmr.getNameAndTypeIndex());
return ((ConstantUtf8) cp.getConstant(cnat.getSignatureIndex())).getBytes();
}
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:9,代码来源:FieldOrMethod.java
示例9: getName
import com.sun.org.apache.bcel.internal.classfile.ConstantUtf8; //导入依赖的package包/类
/** @return name of referenced method/field.
*/
public String getName( final ConstantPoolGen cpg ) {
final ConstantPool cp = cpg.getConstantPool();
final ConstantCP cmr = (ConstantCP) cp.getConstant(super.getIndex());
final ConstantNameAndType cnat = (ConstantNameAndType) cp.getConstant(cmr.getNameAndTypeIndex());
return ((ConstantUtf8) cp.getConstant(cnat.getNameIndex())).getBytes();
}
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:9,代码来源:FieldOrMethod.java
示例10: test
import com.sun.org.apache.bcel.internal.classfile.ConstantUtf8; //导入依赖的package包/类
@Test
public void test() throws Exception {
String classfile = getClass().getResource("Bug8003147Test.class").getPath();
JavaClass jc = new ClassParser(classfile).parse();
// rename class
ConstantPool cp = jc.getConstantPool();
int cpIndex = ((ConstantClass) cp.getConstant(jc.getClassNameIndex())).getNameIndex();
cp.setConstant(cpIndex, new ConstantUtf8("Bug8003147TestPrime"));
ClassGen gen = new ClassGen(jc);
Method[] methods = jc.getMethods();
int index;
for (index = 0; index < methods.length; index++) {
if (methods[index].getName().equals("doSomething")) {
break;
}
}
Method m = methods[index];
MethodGen mg = new MethodGen(m, gen.getClassName(), gen.getConstantPool());
gen.replaceMethod(m, mg.getMethod());
String path = classfile.replace("Bug8003147Test", "Bug8003147TestPrime");
gen.getJavaClass().dump(new FileOutputStream(path));
try {
Class.forName("Bug8003147TestPrime");
} catch (ClassFormatError cfe) {
cfe.printStackTrace();
Assert.fail("modified version of class does not pass verification");
}
}
开发者ID:campolake,项目名称:openjdk9,代码行数:30,代码来源:Bug8003147Test.java
示例11: getNameString
import com.sun.org.apache.bcel.internal.classfile.ConstantUtf8; //导入依赖的package包/类
public final String getNameString()
{
// ConstantString cu8 = (ConstantString)cpool.getConstant(nameIdx);
return ((ConstantUtf8) cpool.getConstant(nameIdx)).getBytes();
}
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:6,代码来源:ElementValuePairGen.java
示例12: getSignature
import com.sun.org.apache.bcel.internal.classfile.ConstantUtf8; //导入依赖的package包/类
/** @return signature of referenced method/field.
*/
public String getSignature(final ConstantPoolGen cpg) {
final ConstantPool cp = cpg.getConstantPool();
final ConstantNameAndType cnat = getNameAndType(cpg);
return ((ConstantUtf8) cp.getConstant(cnat.getSignatureIndex())).getBytes();
}
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:8,代码来源:NameSignatureInstruction.java
示例13: getName
import com.sun.org.apache.bcel.internal.classfile.ConstantUtf8; //导入依赖的package包/类
/** @return name of referenced method/field.
*/
public String getName(final ConstantPoolGen cpg) {
final ConstantPool cp = cpg.getConstantPool();
final ConstantNameAndType cnat = getNameAndType(cpg);
return ((ConstantUtf8) cp.getConstant(cnat.getNameIndex())).getBytes();
}
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:8,代码来源:NameSignatureInstruction.java
示例14: getTypeSignature
import com.sun.org.apache.bcel.internal.classfile.ConstantUtf8; //导入依赖的package包/类
public final String getTypeSignature() {
// ConstantClass c = (ConstantClass)cpool.getConstant(typeIndex);
final ConstantUtf8 utf8 = (ConstantUtf8) cpool
.getConstant(typeIndex/* c.getNameIndex() */);
return utf8.getBytes();
}
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:7,代码来源:AnnotationEntryGen.java
示例15: test
import com.sun.org.apache.bcel.internal.classfile.ConstantUtf8; //导入依赖的package包/类
@Test
public void test() throws Exception {
// Note: Because BCEL library is always behind java version, to make sure
// JavaClass can parse the class file, create a separate
// Bug8003147TestClass.java, which only uses basic features.
JAXPTestUtilities.tryRunWithTmpPermission(() -> {
String classfile = getSystemProperty("test.classes") + "/parsers/Bug8003147TestClass.class";
JavaClass jc = new ClassParser(classfile).parse();
// rename class
ConstantPool cp = jc.getConstantPool();
int cpIndex = ((ConstantClass) cp.getConstant(jc.getClassNameIndex())).getNameIndex();
cp.setConstant(cpIndex, new ConstantUtf8("parsers/Bug8003147TestClassPrime"));
ClassGen gen = new ClassGen(jc);
Method[] methods = jc.getMethods();
int index;
for (index = 0; index < methods.length; index++) {
if (methods[index].getName().equals("doSomething")) {
break;
}
}
Method m = methods[index];
MethodGen mg = new MethodGen(m, gen.getClassName(), gen.getConstantPool());
// @bug 8064516, not currently used directly by JAXP, but we may need
// to modify preexisting methods in the future.
InstructionFactory f = new InstructionFactory(gen);
InstructionList il = mg.getInstructionList();
InstructionList newInst = new InstructionList();
newInst.append(f.createPrintln("Hello Sekai!"));
il.insert(newInst);
mg.setMaxStack();
gen.replaceMethod(m, mg.getMethod());
String path = classfile.replace("Bug8003147TestClass", "Bug8003147TestClassPrime");
gen.getJavaClass().dump(new FileOutputStream(path));
try {
Class.forName("parsers.Bug8003147TestClassPrime");
} catch (ClassFormatError cfe) {
cfe.printStackTrace();
Assert.fail("modified version of class does not pass verification");
}
}, new FilePermission(getSystemProperty("test.classes") + "/-", "read,write"));
}
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:46,代码来源:Bug8003147Test.java
注:本文中的com.sun.org.apache.bcel.internal.classfile.ConstantUtf8类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论