本文整理汇总了Java中com.sun.tools.classfile.AccessFlags类的典型用法代码示例。如果您正苦于以下问题:Java AccessFlags类的具体用法?Java AccessFlags怎么用?Java AccessFlags使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
AccessFlags类属于com.sun.tools.classfile包,在下文中一共展示了AccessFlags类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: checkAccess
import com.sun.tools.classfile.AccessFlags; //导入依赖的package包/类
/**
* Checks access of class, field or method.
*/
public boolean checkAccess(AccessFlags flags){
boolean isPublic = flags.is(AccessFlags.ACC_PUBLIC);
boolean isProtected = flags.is(AccessFlags.ACC_PROTECTED);
boolean isPrivate = flags.is(AccessFlags.ACC_PRIVATE);
boolean isPackage = !(isPublic || isProtected || isPrivate);
if ((showAccess == AccessFlags.ACC_PUBLIC) && (isProtected || isPrivate || isPackage))
return false;
else if ((showAccess == AccessFlags.ACC_PROTECTED) && (isPrivate || isPackage))
return false;
else if ((showAccess == 0) && (isPrivate))
return false;
else
return true;
}
示例2: readClass
import com.sun.tools.classfile.AccessFlags; //导入依赖的package包/类
private void readClass(ClassFile c) throws IOException,
ConstantPoolException,
InvalidDescriptor {
klass = new Element("Class");
cfile.add(klass);
String thisk = c.getName();
klass.setAttr("name", thisk);
AccessFlags af = new AccessFlags(c.access_flags.flags);
klass.setAttr("flags", flagString(af, klass));
if (!"java/lang/Object".equals(thisk)) {
klass.setAttr("super", c.getSuperclassName());
}
for (int i : c.interfaces) {
klass.add(new Element("Interface", "name", getCpString(i)));
}
readFields(c, klass);
readMethods(c, klass);
readAttributesFor(c, c.attributes, klass);
klass.trimToSize();
}
示例3: flagString
import com.sun.tools.classfile.AccessFlags; //导入依赖的package包/类
protected String flagString(AccessFlags af, String kind) {
Set<String> mods = null;
switch (kind) {
case "Class":
mods = af.getClassFlags();
break;
case "InnerClass":
mods = af.getInnerClassFlags();
break;
case "Field":
mods = af.getFieldFlags();
break;
case "Method":
mods = af.getMethodFlags();
break;
default:
throw new RuntimeException("should not reach here");
}
StringBuilder sb = new StringBuilder();
for (String x : mods) {
sb.append(x.substring(x.indexOf('_') + 1).toLowerCase()).append(" ");
}
return sb.toString().trim();
}
示例4: main
import com.sun.tools.classfile.AccessFlags; //导入依赖的package包/类
public static void main(String[] args) throws IOException, ConstantPoolException {
Path outdir = Paths.get(".");
ToolBox tb = new ToolBox();
final Path moduleInfo = Paths.get("module-info.java");
tb.writeFile(moduleInfo, "module test_module{}");
new JavacTask(tb)
.outdir(outdir)
.files(moduleInfo)
.run();
AccessFlags accessFlags = ClassFile.read(outdir.resolve("module-info.class"))
.access_flags;
if (!accessFlags.is(AccessFlags.ACC_MODULE)) {
throw new RuntimeException("Classfile doesn't have module access flag");
}
}
示例5: readClass
import com.sun.tools.classfile.AccessFlags; //导入依赖的package包/类
private void readClass(ClassFile c) throws IOException,
ConstantPoolException,
InvalidDescriptor {
klass = new Element("Class");
cfile.add(klass);
String thisk = c.getName();
klass.setAttr("name", thisk);
AccessFlags af = new AccessFlags(c.access_flags.flags);
klass.setAttr("flags", flagString(af, klass));
if (!"java/lang/Object".equals(thisk)) {
if (c.super_class != 0) {
klass.setAttr("super", c.getSuperclassName());
}
}
for (int i : c.interfaces) {
klass.add(new Element("Interface", "name", getCpString(i)));
}
readFields(c, klass);
readMethods(c, klass);
readAttributesFor(c, c.attributes, klass);
klass.trimToSize();
}
示例6: isNativeClass
import com.sun.tools.classfile.AccessFlags; //导入依赖的package包/类
boolean isNativeClass(JarFile jar, JarEntry entry) throws IOException, ConstantPoolException {
String name = entry.getName();
if (name.startsWith("META-INF") || !name.endsWith(".class"))
return false;
//String className = name.substring(0, name.length() - 6).replace("/", ".");
//System.err.println("check " + className);
InputStream in = jar.getInputStream(entry);
ClassFile cf = ClassFile.read(in);
for (int i = 0; i < cf.methods.length; i++) {
Method m = cf.methods[i];
if (m.access_flags.is(AccessFlags.ACC_NATIVE)) {
// System.err.println(className);
return true;
}
}
return false;
}
示例7: isNativeClass
import com.sun.tools.classfile.AccessFlags; //导入依赖的package包/类
boolean isNativeClass(JarFile jar, JarEntry entry) throws IOException, ConstantPoolException {
String name = entry.getName();
if (name.startsWith("META-INF") || !name.endsWith(".class"))
return false;
//String className = name.substring(0, name.length() - 6).replace("/", ".");
//System.err.println("check " + className);
InputStream in = jar.getInputStream(entry);
ClassFile cf = ClassFile.read(in);
in.close();
for (int i = 0; i < cf.methods.length; i++) {
Method m = cf.methods[i];
if (m.access_flags.is(AccessFlags.ACC_NATIVE)) {
// System.err.println(className);
return true;
}
}
return false;
}