本文整理汇总了Java中com.sun.tools.classfile.ClassFile.getAttribute方法的典型用法代码示例。如果您正苦于以下问题:Java ClassFile.getAttribute方法的具体用法?Java ClassFile.getAttribute怎么用?Java ClassFile.getAttribute使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.sun.tools.classfile.ClassFile
的用法示例。
在下文中一共展示了ClassFile.getAttribute方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: verifyBytecode
import com.sun.tools.classfile.ClassFile; //导入方法依赖的package包/类
void verifyBytecode() {
File compiledTest = new File("Test.class");
try {
ClassFile cf = ClassFile.read(compiledTest);
BootstrapMethods_attribute bsm_attr =
(BootstrapMethods_attribute)cf
.getAttribute(Attribute.BootstrapMethods);
int length = bsm_attr.bootstrap_method_specifiers.length;
if (length != 1) {
throw new Error("Bad number of method specifiers " +
"in BootstrapMethods attribute: " + length);
}
} catch (Exception e) {
e.printStackTrace();
throw new Error("error reading " + compiledTest +": " + e);
}
}
示例2: test
import com.sun.tools.classfile.ClassFile; //导入方法依赖的package包/类
private void test(String src) {
addTestCase(src);
printf("Testing test case :\n%s\n", src);
try {
Map<String, ? extends JavaFileObject> classes = compile(src).getClasses();
String outerClassName = classes.containsKey("deprecated")
? "deprecated"
: "notDeprecated";
echo("Testing outer class : " + outerClassName);
ClassFile cf = readClassFile(classes.get(outerClassName));
Deprecated_attribute attr = (Deprecated_attribute)
cf.getAttribute(Attribute.Deprecated);
testAttribute(outerClassName, attr, cf);
testInnerClasses(cf, classes);
testMethods(cf);
testFields(cf);
} catch (Exception e) {
addFailure(e);
}
}
示例3: testInnerClasses
import com.sun.tools.classfile.ClassFile; //导入方法依赖的package包/类
private void testInnerClasses(ClassFile cf, Map<String, ? extends JavaFileObject> classes)
throws ConstantPoolException, IOException {
InnerClasses_attribute innerAttr = (InnerClasses_attribute)
cf.getAttribute(Attribute.InnerClasses);
for (Info innerClass : innerAttr.classes) {
String innerClassName = cf.constant_pool.
getClassInfo(innerClass.inner_class_info_index).getName();
echo("Testing inner class : " + innerClassName);
ClassFile innerCf = readClassFile(classes.get(innerClassName));
Deprecated_attribute attr = (Deprecated_attribute)
innerCf.getAttribute(Attribute.Deprecated);
String innerClassSimpleName = innerClass.getInnerName(cf.constant_pool);
testAttribute(innerClassSimpleName, attr, innerCf);
if (innerClassName.contains("Local")) {
testMethods(innerCf);
testFields(innerCf);
}
}
}
示例4: verifySourceFileAttribute
import com.sun.tools.classfile.ClassFile; //导入方法依赖的package包/类
/** Check the SourceFileAttribute is the simple name of the original source file. */
void verifySourceFileAttribute(File f) {
System.err.println("verify: " + f);
try {
ClassFile cf = ClassFile.read(f);
SourceFile_attribute sfa = (SourceFile_attribute) cf.getAttribute(Attribute.SourceFile);
String found = sfa.getSourceFile(cf.constant_pool);
String expect = f.getName().replaceAll("([$.].*)?\\.class", ".java");
if (!expect.equals(found)) {
error("bad value found: " + found + ", expected: " + expect);
}
} catch (Exception e) {
error("error reading " + f +": " + e);
}
}
示例5: test
import com.sun.tools.classfile.ClassFile; //导入方法依赖的package包/类
private void test(String package_info, String src) {
addTestCase(src);
printf("Testing test case: \n%s\n", src);
try {
ClassFile cf = readClassFile(compile(
new String[]{"package-info.java", package_info},
new String[]{"notDeprecated.java", src})
.getClasses().get(CLASS_NAME));
Deprecated_attribute attr =
(Deprecated_attribute) cf.getAttribute(Attribute.Deprecated);
checkNull(attr, "Class can not have deprecated attribute : " + CLASS_NAME);
} catch (Exception e) {
addFailure(e);
}
}
示例6: test
import com.sun.tools.classfile.ClassFile; //导入方法依赖的package包/类
public void test() throws TestFailedException {
try {
addTestCase("Source is InnerClassesIndexTest.java");
ClassFile classFile = readClassFile(InnerClassesIndexTest.class);
InnerClasses_attribute attr = (InnerClasses_attribute)
classFile.getAttribute(Attribute.InnerClasses);
Set<String> foundClasses = new HashSet<>();
for (Info info : attr.classes) {
String innerName = classFile.constant_pool.
getClassInfo(info.inner_class_info_index).getBaseName();
echo("Testing class : " + innerName);
if (isExcluded(innerName)) {
echo("Ignored : " + innerName);
continue;
}
foundClasses.add(innerName);
checkEquals(info.outer_class_info_index, 0,
"outer_class_info_index of " + innerName);
if (innerName.matches("\\$\\d+")) {
checkEquals(info.inner_name_index, 0,
"inner_name_index of anonymous class");
}
}
Set<String> expectedClasses = getInnerClasses();
expectedClasses.remove("InnerClassesIndexTest$Inner");
checkEquals(foundClasses, expectedClasses, "All classes are found");
} catch (Exception e) {
addFailure(e);
} finally {
checkStatus();
}
}
示例7: testModuleAttribute
import com.sun.tools.classfile.ClassFile; //导入方法依赖的package包/类
protected void testModuleAttribute(Path modulePath, ModuleDescriptor moduleDescriptor) throws Exception {
ClassFile classFile = ClassFile.read(modulePath.resolve("module-info.class"));
Module_attribute moduleAttribute = (Module_attribute) classFile.getAttribute("Module");
ConstantPool constantPool = classFile.constant_pool;
testModuleName(moduleDescriptor, moduleAttribute, constantPool);
testModuleFlags(moduleDescriptor, moduleAttribute);
testRequires(moduleDescriptor, moduleAttribute, constantPool);
testExports(moduleDescriptor, moduleAttribute, constantPool);
testOpens(moduleDescriptor, moduleAttribute, constantPool);
testProvides(moduleDescriptor, moduleAttribute, constantPool);
testUses(moduleDescriptor, moduleAttribute, constantPool);
}