com.sun.org.apache.bcel.internal.classfile.JavaClass Java Examples
The following examples show how to use
com.sun.org.apache.bcel.internal.classfile.JavaClass.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SyntheticRepository.java From Bytecoder with Apache License 2.0 | 5 votes |
/** * 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(); }
Example #2
Source File: ObjectType.java From JDKSourceCode1.8 with MIT License | 5 votes |
/** * 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()); } }
Example #3
Source File: XSLTC.java From Bytecoder with Apache License 2.0 | 5 votes |
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.doesFileExist(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(); } }
Example #4
Source File: XSLTC.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
/** * 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(); }
Example #5
Source File: ObjectType.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
/** * 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()); } }
Example #6
Source File: ClassSet.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
public boolean add(JavaClass clazz) { boolean result = false; if(!_map.containsKey(clazz.getClassName())) { result = true; _map.put(clazz.getClassName(), clazz); } return result; }
Example #7
Source File: ObjectType.java From JDKSourceCode1.8 with MIT License | 5 votes |
/** * 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(); }
Example #8
Source File: ObjectType.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
/** * 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(); }
Example #9
Source File: ClassSet.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
public boolean add(JavaClass clazz) { boolean result = false; if(!_map.containsKey(clazz.getClassName())) { result = true; _map.put(clazz.getClassName(), clazz); } return result; }
Example #10
Source File: ObjectType.java From hottub with GNU General Public License v2.0 | 5 votes |
/** * 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(); }
Example #11
Source File: ObjectType.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
/** * 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(); }
Example #12
Source File: Class2HTML.java From Bytecoder with Apache License 2.0 | 5 votes |
/** * 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(); }
Example #13
Source File: ClassSet.java From openjdk-8 with GNU General Public License v2.0 | 4 votes |
public JavaClass[] toArray() { Collection values = _map.values(); JavaClass[] classes = new JavaClass[values.size()]; values.toArray(classes); return classes; }
Example #14
Source File: ClassQueue.java From TencentKona-8 with GNU General Public License v2.0 | 4 votes |
public JavaClass dequeue() { return (JavaClass)vec.removeFirst(); }
Example #15
Source File: Repository.java From JDKSourceCode1.8 with MIT License | 4 votes |
/** * Add clazz to repository if there isn't an equally named class already in there. * * @return old entry in repository */ public static JavaClass addClass(JavaClass clazz) { JavaClass old = _repository.findClass(clazz.getClassName()); _repository.storeClass(clazz); return old; }
Example #16
Source File: Repository.java From JDKSourceCode1.8 with MIT License | 4 votes |
/** * Try to find class source via getResourceAsStream(). * @see Class * @return JavaClass object for given runtime class */ public static JavaClass lookupClass(Class clazz) { try { return _repository.loadClass(clazz); } catch(ClassNotFoundException ex) { return null; } }
Example #17
Source File: BCELifier.java From Bytecoder with Apache License 2.0 | 4 votes |
/** @param clazz Java class to "decompile" * @param out where to output Java program */ public BCELifier(final JavaClass clazz, final OutputStream out) { _clazz = clazz; _out = new PrintWriter(out); _cp = new ConstantPoolGen(_clazz.getConstantPool()); }
Example #18
Source File: Repository.java From jdk1.8-source-analysis with Apache License 2.0 | 4 votes |
/** * @return true, if clazz is an implementation of interface inter */ public static boolean implementationOf(JavaClass clazz, JavaClass inter) { return clazz.implementationOf(inter); }
Example #19
Source File: ClassQueue.java From JDKSourceCode1.8 with MIT License | 4 votes |
public JavaClass dequeue() { return (JavaClass)vec.removeFirst(); }
Example #20
Source File: ReferenceType.java From openjdk-jdk8u with GNU General Public License v2.0 | 4 votes |
/** * This commutative operation returns the first common superclass (narrowest ReferenceType * referencing a class, not an interface). * If one of the types is a superclass of the other, the former is returned. * If "this" is Type.NULL, then t is returned. * If t is Type.NULL, then "this" is returned. * If "this" equals t ['this.equals(t)'] "this" is returned. * If "this" or t is an ArrayType, then Type.OBJECT is returned. * If "this" or t is a ReferenceType referencing an interface, then Type.OBJECT is returned. * If not all of the two classes' superclasses cannot be found, "null" is returned. * See the JVM specification edition 2, "4.9.2 The Bytecode Verifier". * * @deprecated use getFirstCommonSuperclass(ReferenceType t) which has * slightly changed semantics. */ public ReferenceType firstCommonSuperclass(ReferenceType t) { if (this.equals(Type.NULL)) return t; if (t.equals(Type.NULL)) return this; if (this.equals(t)) return this; /* * TODO: Above sounds a little arbitrary. On the other hand, there is * no object referenced by Type.NULL so we can also say all the objects * referenced by Type.NULL were derived from java.lang.Object. * However, the Java Language's "instanceof" operator proves us wrong: * "null" is not referring to an instance of java.lang.Object :) */ if ((this instanceof ArrayType) || (t instanceof ArrayType)) return Type.OBJECT; // TODO: Is there a proof of OBJECT being the direct ancestor of every ArrayType? if (((this instanceof ObjectType) && ((ObjectType) this).referencesInterface()) || ((t instanceof ObjectType) && ((ObjectType) t).referencesInterface())) return Type.OBJECT; // TODO: The above line is correct comparing to the vmspec2. But one could // make class file verification a bit stronger here by using the notion of // superinterfaces or even castability or assignment compatibility. // this and t are ObjectTypes, see above. ObjectType thiz = (ObjectType) this; ObjectType other = (ObjectType) t; JavaClass[] thiz_sups = Repository.getSuperClasses(thiz.getClassName()); JavaClass[] other_sups = Repository.getSuperClasses(other.getClassName()); if ((thiz_sups == null) || (other_sups == null)) { return null; } // Waaahh... JavaClass[] this_sups = new JavaClass[thiz_sups.length + 1]; JavaClass[] t_sups = new JavaClass[other_sups.length + 1]; System.arraycopy(thiz_sups, 0, this_sups, 1, thiz_sups.length); System.arraycopy(other_sups, 0, t_sups, 1, other_sups.length); this_sups[0] = Repository.lookupClass(thiz.getClassName()); t_sups[0] = Repository.lookupClass(other.getClassName()); for (int i = 0; i < t_sups.length; i++) { for (int j = 0; j < this_sups.length; j++) { if (this_sups[j].equals(t_sups[i])) return new ObjectType(this_sups[j].getClassName()); } } // Huh? Did you ask for Type.OBJECT's superclass?? return null; }
Example #21
Source File: Repository.java From Bytecoder with Apache License 2.0 | 4 votes |
/** * Add clazz to repository if there isn't an equally named class already in there. * * @return old entry in repository */ public static JavaClass addClass( final JavaClass clazz ) { final JavaClass old = repository.findClass(clazz.getClassName()); repository.storeClass(clazz); return old; }
Example #22
Source File: ClassVector.java From openjdk-8 with GNU General Public License v2.0 | 4 votes |
public JavaClass[] toArray() { JavaClass[] classes = new JavaClass[vec.size()]; vec.toArray(classes); return classes; }
Example #23
Source File: ClassSet.java From Bytecoder with Apache License 2.0 | 4 votes |
public JavaClass[] toArray() { final Collection<JavaClass> values = map.values(); final JavaClass[] classes = new JavaClass[values.size()]; values.toArray(classes); return classes; }
Example #24
Source File: ClassStack.java From Bytecoder with Apache License 2.0 | 4 votes |
public void push( final JavaClass clazz ) { stack.push(clazz); }
Example #25
Source File: ClassQueue.java From jdk1.8-source-analysis with Apache License 2.0 | 4 votes |
public JavaClass dequeue() { return (JavaClass)vec.removeFirst(); }
Example #26
Source File: ClassSet.java From openjdk-8-source with GNU General Public License v2.0 | 4 votes |
public JavaClass[] toArray() { Collection values = _map.values(); JavaClass[] classes = new JavaClass[values.size()]; values.toArray(classes); return classes; }
Example #27
Source File: Repository.java From jdk8u60 with GNU General Public License v2.0 | 4 votes |
/** * @return true, if clazz is an implementation of interface inter */ public static boolean implementationOf(String clazz, JavaClass inter) { return implementationOf(lookupClass(clazz), inter); }
Example #28
Source File: Repository.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 4 votes |
/** * Add clazz to repository if there isn't an equally named class already in there. * * @return old entry in repository */ public static JavaClass addClass(JavaClass clazz) { JavaClass old = _repository.findClass(clazz.getClassName()); _repository.storeClass(clazz); return old; }
Example #29
Source File: ClassSet.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
public JavaClass[] toArray() { Collection values = _map.values(); JavaClass[] classes = new JavaClass[values.size()]; values.toArray(classes); return classes; }
Example #30
Source File: Repository.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 4 votes |
/** * Remove given class from repository. */ public static void removeClass(JavaClass clazz) { _repository.removeClass(clazz); }