CtClassType(ClassFile cf, ClassPool cp) { this((String)null, cp); classfile = cf; qualifiedName = classfile.getName(); }
CtClassType(ClassFile cf, ClassPool cp) { this((String)null, cp); classfile = cf; qualifiedName = classfile.getName(); }
public String getClassName(final ClassFile cls) { return cls.getName(); }
public String getClassName(final ClassFile cls) { return cls.getName(); }
CtClassType(InputStream ins, ClassPool cp) throws IOException { this((String)null, cp); classfile = new ClassFile(new DataInputStream(ins)); qualifiedName = classfile.getName(); }
CtClassType(InputStream ins, ClassPool cp) throws IOException { this((String)null, cp); classfile = new ClassFile(new DataInputStream(ins)); qualifiedName = classfile.getName(); }
private static void writeFile0(ClassFile cf, String directoryName) throws CannotCompileException, IOException { String classname = cf.getName(); String filename = directoryName + File.separatorChar + classname.replace('.', File.separatorChar) + ".class"; int pos = filename.lastIndexOf(File.separatorChar); if (pos > 0) { String dir = filename.substring(0, pos); if (!dir.equals(".")) new File(dir).mkdirs(); } DataOutputStream out = new DataOutputStream(new BufferedOutputStream( new FileOutputStream(filename))); try { cf.write(out); } catch (IOException e) { throw e; } finally { out.close(); } } }
private void testExistingMethod(MethodInfo newMinfo) throws DuplicateMemberException { String name = newMinfo.getName(); String descriptor = newMinfo.getDescriptor(); ListIterator it = methods.listIterator(0); while (it.hasNext()) if (isDuplicated(newMinfo, name, descriptor, (MethodInfo)it.next(), it)) throw new DuplicateMemberException("duplicate method: " + name + " in " + this.getName()); }
public CtClass[] getNestedClasses() throws NotFoundException { ClassFile cf = getClassFile2(); InnerClassesAttribute ica = (InnerClassesAttribute)cf.getAttribute(InnerClassesAttribute.tag); if (ica == null) return new CtClass[0]; String thisName = cf.getName() + "$"; int n = ica.tableLength(); ArrayList list = new ArrayList(n); for (int i = 0; i < n; i++) { String name = ica.innerClass(i); if (name != null) if (name.startsWith(thisName)) { // if it is an immediate nested class if (name.lastIndexOf('$') < thisName.length()) list.add(classPool.get(name)); } } return (CtClass[])list.toArray(new CtClass[list.size()]); }
private static void writeFile0(ClassFile cf, String directoryName) throws CannotCompileException, IOException { String classname = cf.getName(); String filename = directoryName + File.separatorChar + classname.replace('.', File.separatorChar) + ".class"; int pos = filename.lastIndexOf(File.separatorChar); if (pos > 0) { String dir = filename.substring(0, pos); if (!dir.equals(".")) new File(dir).mkdirs(); } DataOutputStream out = new DataOutputStream(new BufferedOutputStream( new FileOutputStream(filename))); try { cf.write(out); } catch (IOException e) { throw e; } finally { out.close(); } } }
private void testExistingMethod(MethodInfo newMinfo) throws DuplicateMemberException { String name = newMinfo.getName(); String descriptor = newMinfo.getDescriptor(); ListIterator<MethodInfo> it = methods.listIterator(0); while (it.hasNext()) if (isDuplicated(newMinfo, name, descriptor, it.next(), it)) throw new DuplicateMemberException("duplicate method: " + name + " in " + this.getName()); }
@Override public CtClass[] getNestedClasses() throws NotFoundException { ClassFile cf = getClassFile2(); InnerClassesAttribute ica = (InnerClassesAttribute)cf.getAttribute(InnerClassesAttribute.tag); if (ica == null) return new CtClass[0]; String thisName = cf.getName() + "$"; int n = ica.tableLength(); List<CtClass> list = new ArrayList<CtClass>(n); for (int i = 0; i < n; i++) { String name = ica.innerClass(i); if (name != null) if (name.startsWith(thisName)) { // if it is an immediate nested class if (name.lastIndexOf('$') < thisName.length()) list.add(classPool.get(name)); } } return list.toArray(new CtClass[list.size()]); }
/** * Returns access and property flags of this nested class. * This method returns -1 if the class is not a nested class. * * <p>The returned value is obtained from <code>inner_class_access_flags</code> * of the entry representing this nested class itself * in <code>InnerClasses_attribute</code>. */ public int getInnerAccessFlags() { InnerClassesAttribute ica = (InnerClassesAttribute)getAttribute(InnerClassesAttribute.tag); if (ica == null) return -1; String name = getName(); int n = ica.tableLength(); for (int i = 0; i < n; ++i) if (name.equals(ica.innerClass(i))) return ica.accessFlags(i); return -1; }
private ClassDescriptor toClassDescriptor(ClassFile classFile, ArchiveEntry entry) { ClassDescriptor.Categorization categorization = ClassDescriptor.Categorization.OTHER;; final AnnotationsAttribute visibleAnnotations = (AnnotationsAttribute) classFile.getAttribute( AnnotationsAttribute.visibleTag ); if ( visibleAnnotations != null ) { if ( visibleAnnotations.getAnnotation( Entity.class.getName() ) != null || visibleAnnotations.getAnnotation( MappedSuperclass.class.getName() ) != null || visibleAnnotations.getAnnotation( Embeddable.class.getName() ) != null ) { categorization = ClassDescriptor.Categorization.MODEL; } else if ( visibleAnnotations.getAnnotation( Converter.class.getName() ) != null ) { categorization = ClassDescriptor.Categorization.CONVERTER; } } return new ClassDescriptorImpl( classFile.getName(), categorization, entry.getStreamAccess() ); } }
/** * Loads a class file by a given class loader. * * @param neighbor a class belonging to the same package that * the loaded class belongs to. * It can be null. * @param loader The class loader. It can be null if {@code neighbor} * is not null. * @param domain if it is null, a default domain is used. * @since 3.3 */ public static Class<?> toClass(ClassFile cf, Class<?> neighbor, ClassLoader loader, ProtectionDomain domain) throws CannotCompileException { try { byte[] b = toBytecode(cf); if (ProxyFactory.onlyPublicMethods) return DefineClassHelper.toPublicClass(cf.getName(), b); else return DefineClassHelper.toClass(cf.getName(), neighbor, loader, domain, b); } catch (IOException e) { throw new CannotCompileException(e); } }
/** * Returns access and property flags of this nested class. * This method returns -1 if the class is not a nested class. * * <p>The returned value is obtained from <code>inner_class_access_flags</code> * of the entry representing this nested class itself * in <code>InnerClasses_attribute</code>. */ public int getInnerAccessFlags() { InnerClassesAttribute ica = (InnerClassesAttribute)getAttribute(InnerClassesAttribute.tag); if (ica == null) return -1; String name = getName(); int n = ica.tableLength(); for (int i = 0; i < n; ++i) if (name.equals(ica.innerClass(i))) return ica.accessFlags(i); return -1; }
@Override public void scan(final Object cls) { final ClassFile classFile = (ClassFile)cls; String className = classFile.getName(); String superclass = classFile.getSuperclass(); boolean isAbstract = (classFile.getAccessFlags() & (AccessFlag.INTERFACE | AccessFlag.ABSTRACT)) != 0; ChildClassDescriptor scannedClass = new ChildClassDescriptor(className, isAbstract); if (!superclass.equals(Object.class.getName())) { children.put(superclass, scannedClass); } for (String anInterface : classFile.getInterfaces()) { children.put(anInterface, scannedClass); } }
+ " modifiers: " + Integer.toHexString(cf.getAccessFlags())); out.println(Modifier.toString(mod) + " class " + cf.getName() + " extends " + cf.getSuperclass());