本文整理汇总了Java中com.sun.org.apache.bcel.internal.classfile.JavaClass类的典型用法代码示例。如果您正苦于以下问题:Java JavaClass类的具体用法?Java JavaClass怎么用?Java JavaClass使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
JavaClass类属于com.sun.org.apache.bcel.internal.classfile包,在下文中一共展示了JavaClass类的19个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: getJavaClass
import com.sun.org.apache.bcel.internal.classfile.JavaClass; //导入依赖的package包/类
/**
* @return the (finally) built up Java class object.
*/
public JavaClass getJavaClass() {
final int[] interfaces = getInterfaces();
final Field[] fields = getFields();
final Method[] methods = getMethods();
Attribute[] attributes;
if (annotation_vec.isEmpty()) {
attributes = getAttributes();
} else {
// TODO: Sometime later, trash any attributes called 'RuntimeVisibleAnnotations' or 'RuntimeInvisibleAnnotations'
final Attribute[] annAttributes = AnnotationEntryGen.getAnnotationAttributes(cp, getAnnotationEntries());
attributes = new Attribute[attribute_vec.size() + annAttributes.length];
attribute_vec.toArray(attributes);
System.arraycopy(annAttributes, 0, attributes, attribute_vec.size(), annAttributes.length);
}
// Must be last since the above calls may still add something to it
final ConstantPool _cp = this.cp.getFinalConstantPool();
return new JavaClass(class_name_index, superclass_name_index, file_name, major, minor,
super.getAccessFlags(), _cp, interfaces, fields, methods, attributes);
}
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:23,代码来源:ClassGen.java
示例2: loadClass
import com.sun.org.apache.bcel.internal.classfile.JavaClass; //导入依赖的package包/类
/**
* Finds a JavaClass object by name. If it is already in this Repository, the
* Repository version is returned.
*
* @param className the name of the class
* @return the JavaClass object
* @throws ClassNotFoundException if the class is not in the Repository
*/
@Override
public JavaClass loadClass(String className) throws ClassNotFoundException {
if ((className == null) || className.isEmpty()) {
throw new IllegalArgumentException("Invalid class name " + className);
}
className = className.replace('/', '.'); // Just in case, canonical form
final JavaClass clazz = findClass(className);
if (clazz != null) {
return clazz;
}
IOException e = new IOException("Couldn't find: " + className + ".class");
throw new ClassNotFoundException("Exception while looking for class " +
className + ": " + e, e);
}
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:24,代码来源:SyntheticRepository.java
示例3: referencesClass
import com.sun.org.apache.bcel.internal.classfile.JavaClass; //导入依赖的package包/类
/**
* If "this" doesn't reference a class, it references an interface
* or a non-existant entity.
*/
public boolean referencesClass(){
JavaClass jc = Repository.lookupClass(class_name);
if (jc == null)
return false;
else
return jc.isClass();
}
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:12,代码来源:ObjectType.java
示例4: referencesInterface
import com.sun.org.apache.bcel.internal.classfile.JavaClass; //导入依赖的package包/类
/**
* If "this" doesn't reference an interface, it references a class
* or a non-existant entity.
*/
public boolean referencesInterface(){
JavaClass jc = Repository.lookupClass(class_name);
if (jc == null)
return false;
else
return !jc.isClass();
}
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:12,代码来源:ObjectType.java
示例5: accessibleTo
import com.sun.org.apache.bcel.internal.classfile.JavaClass; //导入依赖的package包/类
/**
* Java Virtual Machine Specification edition 2, 5.4.4 Access Control
*/
public boolean accessibleTo(ObjectType accessor) {
JavaClass jc = Repository.lookupClass(class_name);
if(jc.isPublic()) {
return true;
} else {
JavaClass acc = Repository.lookupClass(accessor.class_name);
return acc.getPackageName().equals(jc.getPackageName());
}
}
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:14,代码来源:ObjectType.java
示例6: lookupClass
import com.sun.org.apache.bcel.internal.classfile.JavaClass; //导入依赖的package包/类
/** Lookup class somewhere found on your CLASSPATH, or whereever the
* repository instance looks for it.
*
* @return class object for given fully qualified class name, or null
* if the class could not be found or parsed correctly
*/
public static JavaClass lookupClass(String class_name) {
try {
JavaClass clazz = _repository.findClass(class_name);
if(clazz == null) {
return _repository.loadClass(class_name);
} else {
return clazz;
}
} catch(ClassNotFoundException ex) { return null; }
}
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:18,代码来源:Repository.java
示例7: add
import com.sun.org.apache.bcel.internal.classfile.JavaClass; //导入依赖的package包/类
public boolean add(JavaClass clazz) {
boolean result = false;
if(!_map.containsKey(clazz.getClassName())) {
result = true;
_map.put(clazz.getClassName(), clazz);
}
return result;
}
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:11,代码来源:ClassSet.java
示例8: dumpClass
import com.sun.org.apache.bcel.internal.classfile.JavaClass; //导入依赖的package包/类
public void dumpClass(JavaClass clazz) {
if (_outputType == BYTEARRAY_AND_FILE_OUTPUT)
{
File outFile = getOutputFile(clazz.getClassName());
String parentDir = outFile.getParent();
if (parentDir != null) {
File parentFile = new File(parentDir);
if (!SecuritySupport.getFileExists(parentFile))
parentFile.mkdirs();
}
}
try {
switch (_outputType) {
case JAR_OUTPUT:
_bcelClasses.add(clazz);
break;
case BYTEARRAY_OUTPUT:
case BYTEARRAY_AND_FILE_OUTPUT:
case BYTEARRAY_AND_JAR_OUTPUT:
case CLASSLOADER_OUTPUT:
ByteArrayOutputStream out = new ByteArrayOutputStream(2048);
clazz.dump(out);
_classes.add(out);
if (_outputType == BYTEARRAY_AND_FILE_OUTPUT)
clazz.dump(getOutputFile(clazz.getClassName()));
else if (_outputType == BYTEARRAY_AND_JAR_OUTPUT)
_bcelClasses.add(clazz);
break;
}
}
catch (Exception e) {
e.printStackTrace();
}
}
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:39,代码来源:XSLTC.java
示例9: outputToJar
import com.sun.org.apache.bcel.internal.classfile.JavaClass; //导入依赖的package包/类
/**
* Generate output JAR-file and packages
*/
public void outputToJar() throws IOException {
// create the manifest
final Manifest manifest = new Manifest();
final java.util.jar.Attributes atrs = manifest.getMainAttributes();
atrs.put(java.util.jar.Attributes.Name.MANIFEST_VERSION, "1.2");
final Map<String, Attributes> map = manifest.getEntries();
// create manifest
final String now = (new Date()).toString();
final java.util.jar.Attributes.Name dateAttr =
new java.util.jar.Attributes.Name("Date");
final File jarFile = new File(_destDir, _jarFileName);
final JarOutputStream jos =
new JarOutputStream(new FileOutputStream(jarFile), manifest);
for (JavaClass clazz : _bcelClasses) {
final String className = clazz.getClassName().replace('.', '/');
final java.util.jar.Attributes attr = new java.util.jar.Attributes();
attr.put(dateAttr, now);
map.put(className + ".class", attr);
jos.putNextEntry(new JarEntry(className + ".class"));
final ByteArrayOutputStream out = new ByteArrayOutputStream(2048);
clazz.dump(out); // dump() closes it's output stream
out.writeTo(jos);
}
jos.close();
}
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:32,代码来源:XSLTC.java
示例10: referencesClass
import com.sun.org.apache.bcel.internal.classfile.JavaClass; //导入依赖的package包/类
/**
* If "this" doesn't reference a class, it references an interface
* or a non-existant entity.
* @deprecated (since 6.0) this method returns an inaccurate result
* if the class or interface referenced cannot
* be found: use referencesClassExact() instead
*/
@Deprecated
public boolean referencesClass() {
try {
final JavaClass jc = Repository.lookupClass(class_name);
return jc.isClass();
} catch (final ClassNotFoundException e) {
return false;
}
}
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:17,代码来源:ObjectType.java
示例11: referencesInterface
import com.sun.org.apache.bcel.internal.classfile.JavaClass; //导入依赖的package包/类
/**
* If "this" doesn't reference an interface, it references a class
* or a non-existant entity.
* @deprecated (since 6.0) this method returns an inaccurate result
* if the class or interface referenced cannot
* be found: use referencesInterfaceExact() instead
*/
@Deprecated
public boolean referencesInterface() {
try {
final JavaClass jc = Repository.lookupClass(class_name);
return !jc.isClass();
} catch (final ClassNotFoundException e) {
return false;
}
}
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:17,代码来源:ObjectType.java
示例12: accessibleTo
import com.sun.org.apache.bcel.internal.classfile.JavaClass; //导入依赖的package包/类
/**
* Java Virtual Machine Specification edition 2, 5.4.4 Access Control
* @throws ClassNotFoundException if the class referenced by this type
* can't be found
*/
public boolean accessibleTo( final ObjectType accessor ) throws ClassNotFoundException {
final JavaClass jc = Repository.lookupClass(class_name);
if (jc.isPublic()) {
return true;
}
final JavaClass acc = Repository.lookupClass(accessor.class_name);
return acc.getPackageName().equals(jc.getPackageName());
}
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:14,代码来源:ObjectType.java
示例13: ClassGen
import com.sun.org.apache.bcel.internal.classfile.JavaClass; //导入依赖的package包/类
/**
* Initialize with existing class.
*
* @param clazz JavaClass object (e.g. read from file)
*/
public ClassGen(final JavaClass clazz) {
super(clazz.getAccessFlags());
class_name_index = clazz.getClassNameIndex();
superclass_name_index = clazz.getSuperclassNameIndex();
class_name = clazz.getClassName();
super_class_name = clazz.getSuperclassName();
file_name = clazz.getSourceFileName();
cp = new ConstantPoolGen(clazz.getConstantPool());
major = clazz.getMajor();
minor = clazz.getMinor();
final Attribute[] attributes = clazz.getAttributes();
// J5TODO: Could make unpacking lazy, done on first reference
final AnnotationEntryGen[] annotations = unpackAnnotations(attributes);
final Method[] methods = clazz.getMethods();
final Field[] fields = clazz.getFields();
final String[] interfaces = clazz.getInterfaceNames();
for (final String interface1 : interfaces) {
addInterface(interface1);
}
for (final Attribute attribute : attributes) {
if (!(attribute instanceof Annotations)) {
addAttribute(attribute);
}
}
for (final AnnotationEntryGen annotation : annotations) {
addAnnotationEntry(annotation);
}
for (final Method method : methods) {
addMethod(method);
}
for (final Field field : fields) {
addField(field);
}
}
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:40,代码来源:ClassGen.java
示例14: Class2HTML
import com.sun.org.apache.bcel.internal.classfile.JavaClass; //导入依赖的package包/类
/**
* Write contents of the given JavaClass into HTML files.
*
* @param java_class The class to write
* @param dir The directory to put the files in
*/
public Class2HTML(final JavaClass java_class, final String dir) throws IOException {
final Method[] methods = java_class.getMethods();
this.java_class = java_class;
this.dir = dir;
class_name = java_class.getClassName(); // Remember full name
constant_pool = java_class.getConstantPool();
// Get package name by tacking off everything after the last `.'
final int index = class_name.lastIndexOf('.');
if (index > -1) {
class_package = class_name.substring(0, index);
} else {
class_package = ""; // default package
}
final ConstantHTML constant_html = new ConstantHTML(dir, class_name, class_package, methods,
constant_pool);
/* Attributes can't be written in one step, so we just open a file
* which will be written consequently.
*/
final AttributeHTML attribute_html = new AttributeHTML(dir, class_name, constant_pool,
constant_html);
new MethodHTML(dir, class_name, methods, java_class.getFields(),
constant_html, attribute_html);
// Write main file (with frames, yuk)
writeMainHTML(attribute_html);
new CodeHTML(dir, class_name, methods, constant_pool, constant_html);
attribute_html.close();
}
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:34,代码来源:Class2HTML.java
示例15: findClass
import com.sun.org.apache.bcel.internal.classfile.JavaClass; //导入依赖的package包/类
/**
* Find an already defined (cached) JavaClass object by name.
*/
@Override
public JavaClass findClass(final String className) {
final SoftReference<JavaClass> ref = loadedClasses.get(className);
if (ref == null) {
return null;
}
return ref.get();
}
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:12,代码来源:SyntheticRepository.java
示例16: _main
import com.sun.org.apache.bcel.internal.classfile.JavaClass; //导入依赖的package包/类
/** Default main method
*/
public static void _main( final String[] argv ) throws Exception {
if (argv.length != 1) {
System.out.println("Usage: BCELifier classname");
System.out.println("\tThe class must exist on the classpath");
return;
}
final JavaClass java_class = getJavaClass(argv[0]);
final BCELifier bcelifier = new BCELifier(java_class, System.out);
bcelifier.start();
}
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:13,代码来源:BCELifier.java
示例17: getJavaClass
import com.sun.org.apache.bcel.internal.classfile.JavaClass; //导入依赖的package包/类
static JavaClass getJavaClass(final String name) throws ClassNotFoundException, IOException {
JavaClass java_class;
if ((java_class = Repository.lookupClass(name)) == null) {
java_class = new ClassParser(name).parse(); // May throw IOException
}
return java_class;
}
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:8,代码来源:BCELifier.java
示例18: add
import com.sun.org.apache.bcel.internal.classfile.JavaClass; //导入依赖的package包/类
public boolean add( final JavaClass clazz ) {
boolean result = false;
if (!map.containsKey(clazz.getClassName())) {
result = true;
map.put(clazz.getClassName(), clazz);
}
return result;
}
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:9,代码来源:ClassSet.java
示例19: test
import com.sun.org.apache.bcel.internal.classfile.JavaClass; //导入依赖的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
注:本文中的com.sun.org.apache.bcel.internal.classfile.JavaClass类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论