Return-Path: Delivered-To: apmail-jakarta-ant-dev-archive@apache.org Received: (qmail 16032 invoked from network); 9 Jan 2002 00:10:19 -0000 Received: from unknown (HELO nagoya.betaversion.org) (192.18.49.131) by daedalus.apache.org with SMTP; 9 Jan 2002 00:10:19 -0000 Received: (qmail 14439 invoked by uid 97); 9 Jan 2002 00:05:58 -0000 Delivered-To: qmlist-jakarta-archive-ant-dev@jakarta.apache.org Received: (qmail 14410 invoked by uid 97); 9 Jan 2002 00:05:57 -0000 Mailing-List: contact ant-dev-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Ant Developers List" Reply-To: "Ant Developers List" Delivered-To: mailing list ant-dev@jakarta.apache.org Received: (qmail 14390 invoked by uid 97); 9 Jan 2002 00:05:57 -0000 Date: 8 Jan 2002 23:57:47 -0000 Message-ID: <20020108235747.48556.qmail@icarus.apache.org> From: sbailliez@apache.org To: jakarta-ant-cvs@apache.org Subject: cvs commit: jakarta-ant/src/main/org/apache/tools/ant/taskdefs/optional/sitraka/bytecode ClassPathLoader.java MethodInfo.java Utils.java X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N sbailliez 02/01/08 15:57:47 Modified: src/main/org/apache/tools/ant/taskdefs/optional/sitraka/bytecode ClassPathLoader.java MethodInfo.java Utils.java Log: Code layout only. Revision Changes Path 1.5 +64 -50 jakarta-ant/src/main/org/apache/tools/ant/taskdefs/optional/sitraka/bytecode/ClassPathLoader.java Index: ClassPathLoader.java =================================================================== RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/optional/sitraka/bytecode/ClassPathLoader.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- ClassPathLoader.java 27 Nov 2001 18:04:54 -0000 1.4 +++ ClassPathLoader.java 8 Jan 2002 23:57:47 -0000 1.5 @@ -53,21 +53,21 @@ */ package org.apache.tools.ant.taskdefs.optional.sitraka.bytecode; -import java.io.File; -import java.io.IOException; -import java.io.InputStream; import java.io.BufferedInputStream; -import java.io.ByteArrayOutputStream; import java.io.ByteArrayInputStream; -import java.io.FilenameFilter; +import java.io.ByteArrayOutputStream; +import java.io.File; import java.io.FileInputStream; +import java.io.FilenameFilter; +import java.io.IOException; +import java.io.InputStream; import java.util.Enumeration; -import java.util.StringTokenizer; -import java.util.Vector; import java.util.Hashtable; import java.util.NoSuchElementException; -import java.util.zip.ZipFile; +import java.util.StringTokenizer; +import java.util.Vector; import java.util.zip.ZipEntry; +import java.util.zip.ZipFile; /** * Core of the bytecode analyzer. It loads classes from a given classpath. @@ -86,10 +86,10 @@ * separated by the platform specific path separator. * @param classPath the classpath to load all the classes from. */ - public ClassPathLoader(String classPath){ + public ClassPathLoader(String classPath) { StringTokenizer st = new StringTokenizer(classPath, File.pathSeparator); Vector entries = new Vector(); - while (st.hasMoreTokens()){ + while (st.hasMoreTokens()) { File file = new File(st.nextToken()); entries.addElement(file); } @@ -101,9 +101,9 @@ * create a new instance with a given set of urls. * @param entries valid file urls (either .jar, .zip or directory) */ - public ClassPathLoader(String[] entries){ + public ClassPathLoader(String[] entries) { files = new File[entries.length]; - for (int i = 0; i < entries.length; i++){ + for (int i = 0; i < entries.length; i++) { files[i] = new File(entries[i]); } } @@ -112,7 +112,7 @@ * create a new instance with a given set of urls * @param entries file urls to look for classes (.jar, .zip or directory) */ - public ClassPathLoader(File[] entries){ + public ClassPathLoader(File[] entries) { files = entries; } @@ -120,6 +120,7 @@ public interface FileLoader { /** the file url that is looked for .class files */ public File getFile(); + /** return the set of classes found in the file */ public ClassFile[] getClasses() throws IOException; } @@ -127,7 +128,7 @@ /** * @return the set of FileLoader loaders matching the given classpath. */ - public Enumeration loaders(){ + public Enumeration loaders() { return new LoaderEnumeration(); } @@ -145,18 +146,18 @@ public Hashtable getClasses() throws IOException { Hashtable map = new Hashtable(); Enumeration enum = loaders(); - while ( enum.hasMoreElements() ){ - FileLoader loader = (FileLoader)enum.nextElement(); + while (enum.hasMoreElements()) { + FileLoader loader = (FileLoader) enum.nextElement(); System.out.println("Processing " + loader.getFile()); long t0 = System.currentTimeMillis(); ClassFile[] classes = loader.getClasses(); long dt = System.currentTimeMillis() - t0; System.out.println("" + classes.length + " classes loaded in " + dt + "ms"); - for (int j = 0; j < classes.length; j++){ + for (int j = 0; j < classes.length; j++) { String name = classes[j].getFullName(); // do not allow duplicates entries to preserve 'classpath' behavior // first class in wins - if ( !map.containsKey(name) ){ + if (!map.containsKey(name)) { map.put(name, classes[j]); } } @@ -167,21 +168,23 @@ /** the loader enumeration that will return loaders */ protected class LoaderEnumeration implements Enumeration { protected int index = 0; - public boolean hasMoreElements(){ + + public boolean hasMoreElements() { return index < files.length; } - public Object nextElement(){ - if (index >= files.length){ + + public Object nextElement() { + if (index >= files.length) { throw new NoSuchElementException(); } File file = files[index++]; - if ( !file.exists() ){ + if (!file.exists()) { return new NullLoader(file); } - if ( file.isDirectory() ){ + if (file.isDirectory()) { // it's a directory return new DirectoryLoader(file); - } else if ( file.getName().endsWith(".zip") || file.getName().endsWith(".jar") ){ + } else if (file.getName().endsWith(".zip") || file.getName().endsWith(".jar")) { // it's a jar/zip file return new JarLoader(file); } @@ -212,15 +215,19 @@ /** a null loader to return when the file is not valid */ class NullLoader implements ClassPathLoader.FileLoader { private File file; - NullLoader(){ + + NullLoader() { this(null); } - NullLoader(File file){ + + NullLoader(File file) { this.file = file; } - public File getFile(){ + + public File getFile() { return file; } + public ClassFile[] getClasses() throws IOException { return new ClassFile[0]; } @@ -233,19 +240,22 @@ */ class JarLoader implements ClassPathLoader.FileLoader { private File file; - JarLoader(File file){ + + JarLoader(File file) { this.file = file; } - public File getFile(){ + + public File getFile() { return file; } + public ClassFile[] getClasses() throws IOException { ZipFile zipFile = new ZipFile(file); Vector v = new Vector(); Enumeration entries = zipFile.entries(); - while (entries.hasMoreElements()){ - ZipEntry entry = (ZipEntry)entries.nextElement(); - if (entry.getName().endsWith(".class")){ + while (entries.hasMoreElements()) { + ZipEntry entry = (ZipEntry) entries.nextElement(); + if (entry.getName().endsWith(".class")) { InputStream is = ClassPathLoader.getCachedStream(zipFile.getInputStream(entry)); ClassFile classFile = new ClassFile(is); is.close(); @@ -266,17 +276,19 @@ class DirectoryLoader implements ClassPathLoader.FileLoader { private File directory; - DirectoryLoader(File dir){ + DirectoryLoader(File dir) { directory = dir; } - public File getFile(){ + + public File getFile() { return directory; } + public ClassFile[] getClasses() throws IOException { Vector v = new Vector(); - Vector files = listFiles( directory, new ClassFilter(), true); - for (int i = 0; i < files.size(); i++){ - File file = (File)files.elementAt(i); + Vector files = listFiles(directory, new ClassFilter(), true); + for (int i = 0; i < files.size(); i++) { + File file = (File) files.elementAt(i); InputStream is = null; try { is = ClassPathLoader.getCachedStream(new FileInputStream(file)); @@ -285,10 +297,11 @@ is = null; v.addElement(classFile); } finally { - if (is != null){ + if (is != null) { try { is.close(); - } catch (IOException ignored){} + } catch (IOException ignored) { + } } } } @@ -306,9 +319,9 @@ * @return the list of File objects that applies to the given * filter. */ - public static Vector listFiles(File directory, FilenameFilter filter, boolean recurse){ - if (!directory.isDirectory()){ - throw new IllegalArgumentException(directory + " is not a directory"); + public static Vector listFiles(File directory, FilenameFilter filter, boolean recurse) { + if (!directory.isDirectory()) { + throw new IllegalArgumentException(directory + " is not a directory"); } Vector list = new Vector(); listFilesTo(list, directory, filter, recurse); @@ -324,15 +337,15 @@ * @param recurse tells whether or not the listing is recursive. * @return the list instance that was passed as the list argument. */ - private static Vector listFilesTo(Vector list, File directory, FilenameFilter filter, boolean recurse){ + private static Vector listFilesTo(Vector list, File directory, FilenameFilter filter, boolean recurse) { String[] files = directory.list(filter); - for (int i = 0; i < files.length; i++){ - list.addElement( new File(directory, files[i]) ); + for (int i = 0; i < files.length; i++) { + list.addElement(new File(directory, files[i])); } files = null; // we don't need it anymore - if (recurse){ - String[] subdirs = directory.list( new DirectoryFilter() ); - for (int i = 0; i < subdirs.length; i++){ + if (recurse) { + String[] subdirs = directory.list(new DirectoryFilter()); + for (int i = 0; i < subdirs.length; i++) { listFilesTo(list, new File(directory, subdirs[i]), filter, recurse); } } @@ -343,14 +356,15 @@ /** Convenient filter that accepts only directory File */ class DirectoryFilter implements FilenameFilter { - public boolean accept(File directory, String name){ + public boolean accept(File directory, String name) { File pathname = new File(directory, name); return pathname.isDirectory(); } } + /** convenient filter to accept only .class files */ class ClassFilter implements FilenameFilter { - public boolean accept(File dir, String name){ + public boolean accept(File dir, String name) { return name.endsWith(".class"); } } 1.4 +2 -2 jakarta-ant/src/main/org/apache/tools/ant/taskdefs/optional/sitraka/bytecode/MethodInfo.java Index: MethodInfo.java =================================================================== RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/optional/sitraka/bytecode/MethodInfo.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- MethodInfo.java 18 Nov 2001 00:45:51 -0000 1.3 +++ MethodInfo.java 8 Jan 2002 23:57:47 -0000 1.4 @@ -78,7 +78,7 @@ access_flags = dis.readShort(); int name_index = dis.readShort(); - name = Utils.getUTF8Value(constantPool, name_index); + name = Utils.getUTF8Value(constantPool, name_index); int descriptor_index = dis.readShort(); descriptor = Utils.getUTF8Value(constantPool, descriptor_index); @@ -99,7 +99,7 @@ protected void readCode(ConstantPool constantPool, DataInputStream dis) throws IOException { // skip max_stack (short), max_local (short) - dis.skipBytes(2*2); + dis.skipBytes(2 * 2); // skip bytecode... int bytecode_len = dis.readInt(); 1.4 +77 -45 jakarta-ant/src/main/org/apache/tools/ant/taskdefs/optional/sitraka/bytecode/Utils.java Index: Utils.java =================================================================== RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/optional/sitraka/bytecode/Utils.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- Utils.java 27 Nov 2001 18:04:54 -0000 1.3 +++ Utils.java 8 Jan 2002 23:57:47 -0000 1.4 @@ -54,9 +54,10 @@ package org.apache.tools.ant.taskdefs.optional.sitraka.bytecode; +import java.util.Vector; + import org.apache.tools.ant.taskdefs.optional.depend.constantpool.ConstantPool; import org.apache.tools.ant.taskdefs.optional.depend.constantpool.Utf8CPInfo; -import java.util.Vector; /** * Utilities mostly to manipulate methods and access flags. @@ -92,7 +93,7 @@ public final static short ACC_STRICT = 2048; /** private constructor */ - private Utils(){ + private Utils() { } /** @@ -102,8 +103,8 @@ * @return the value of the string if it exists * @throws ClassCastException if the index is not an UTF8 constant. */ - public static String getUTF8Value(ConstantPool pool, int index){ - return ((Utf8CPInfo)pool.getEntry(index)).getValue(); + public static String getUTF8Value(ConstantPool pool, int index) { + return ((Utf8CPInfo) pool.getEntry(index)).getValue(); } /** @@ -113,18 +114,18 @@ * represent a java object with its fully qualified classname or the * primitive name such as int, long, ... */ - public static String[] getMethodParams(String descriptor){ + public static String[] getMethodParams(String descriptor) { int i = 0; - if (descriptor.charAt(i) != '('){ + if (descriptor.charAt(i) != '(') { throw new IllegalArgumentException("Method descriptor should start with a '('"); } Vector params = new Vector(); StringBuffer param = new StringBuffer(); i++; - while ( (i = descriptor2java(descriptor, i, param)) < descriptor.length() ){ + while ((i = descriptor2java(descriptor, i, param)) < descriptor.length()) { params.add(param.toString()); param.setLength(0); // reset - if (descriptor.charAt(i) == ')'){ + if (descriptor.charAt(i) == ')') { i++; break; } @@ -139,7 +140,7 @@ * @param descriptor * @return get the return type objet of a given descriptor */ - public static String getMethodReturnType(String descriptor){ + public static String getMethodReturnType(String descriptor) { int pos = descriptor.indexOf(')'); StringBuffer rettype = new StringBuffer(); descriptor2java(descriptor, pos + 1, rettype); @@ -153,23 +154,41 @@ * @param sb the stringbuffer to return the java equivalent of the symbol * @return the index after the descriptor symbol */ - public static int descriptor2java(String descriptor, int i, StringBuffer sb){ + public static int descriptor2java(String descriptor, int i, StringBuffer sb) { // get the dimension StringBuffer dim = new StringBuffer(); - for (;descriptor.charAt(i) == '['; i++){ + for (; descriptor.charAt(i) == '['; i++) { dim.append("[]"); } // now get the type - switch (descriptor.charAt(i)){ - case 'B': sb.append("byte"); break; - case 'C': sb.append("char"); break; - case 'D': sb.append("double"); break; - case 'F': sb.append("float"); break; - case 'I': sb.append("int"); break; - case 'J': sb.append("long"); break; - case 'S': sb.append("short"); break; - case 'Z': sb.append("boolean"); break; - case 'V': sb.append("void"); break; + switch (descriptor.charAt(i)) { + case 'B': + sb.append("byte"); + break; + case 'C': + sb.append("char"); + break; + case 'D': + sb.append("double"); + break; + case 'F': + sb.append("float"); + break; + case 'I': + sb.append("int"); + break; + case 'J': + sb.append("long"); + break; + case 'S': + sb.append("short"); + break; + case 'Z': + sb.append("boolean"); + break; + case 'V': + sb.append("void"); + break; case 'L': // it is a class int pos = descriptor.indexOf(';', i + 1); @@ -196,6 +215,7 @@ public static boolean isAbstract(int access_flags) { return (access_flags & ACC_ABSTRACT) != 0; } + /** * check for public access * @param access_flags access flags @@ -203,6 +223,7 @@ public static boolean isPublic(int access_flags) { return (access_flags & ACC_PUBLIC) != 0; } + /** * check for a static access * @param access_flags access flags @@ -210,6 +231,7 @@ public static boolean isStatic(int access_flags) { return (access_flags & ACC_STATIC) != 0; } + /** * check for native access * @param access_flags access flags @@ -217,6 +239,7 @@ public static boolean isNative(int access_flags) { return (access_flags & ACC_NATIVE) != 0; } + /** * check for class access * @param access_flags access flags @@ -224,6 +247,7 @@ public static boolean isClass(int access_flags) { return !isInterface(access_flags); } + /** * check for strict access * @param access_flags access flags @@ -231,6 +255,7 @@ public static boolean isStrict(int access_flags) { return (access_flags & ACC_STRICT) != 0; } + /** * check for interface access * @param access_flags access flags @@ -238,6 +263,7 @@ public static boolean isInterface(int access_flags) { return (access_flags & ACC_INTERFACE) != 0; } + /** * check for private access * @param access_flags access flags @@ -245,6 +271,7 @@ public static boolean isPrivate(int access_flags) { return (access_flags & ACC_PRIVATE) != 0; } + /** * check for transient flag * @param access_flags access flags @@ -252,13 +279,15 @@ public static boolean isTransient(int access_flags) { return (access_flags & ACC_TRANSIENT) != 0; } + /** * check for volatile flag * @param access_flags access flags */ - public static boolean isVolatile(int access_flags){ + public static boolean isVolatile(int access_flags) { return (access_flags & ACC_VOLATILE) != 0; } + /** * check for super flag * @param access_flags access flag @@ -266,6 +295,7 @@ public static boolean isSuper(int access_flags) { return (access_flags & ACC_SUPER) != 0; } + /** * check for protected flag * @param access_flags access flags @@ -273,6 +303,7 @@ public static boolean isProtected(int access_flags) { return (access_flags & ACC_PROTECTED) != 0; } + /** * chck for final flag * @param access_flags access flags @@ -280,6 +311,7 @@ public static boolean isFinal(int access_flags) { return (access_flags & ACC_FINAL) != 0; } + /** * check for synchronized flag * @param access_flags access flags @@ -295,26 +327,26 @@ */ public static String getMethodAccess(int access_flags) { StringBuffer sb = new StringBuffer(); - if(isPublic(access_flags)){ + if (isPublic(access_flags)) { sb.append("public "); - } else if(isPrivate(access_flags)){ + } else if (isPrivate(access_flags)) { sb.append("private "); - } else if(isProtected(access_flags)){ + } else if (isProtected(access_flags)) { sb.append("protected "); } - if(isFinal(access_flags)){ + if (isFinal(access_flags)) { sb.append("final "); } - if(isStatic(access_flags)){ + if (isStatic(access_flags)) { sb.append("static "); } - if(isSynchronized(access_flags)){ + if (isSynchronized(access_flags)) { sb.append("synchronized "); } - if(isNative(access_flags)){ + if (isNative(access_flags)) { sb.append("native "); } - if(isAbstract(access_flags)){ + if (isAbstract(access_flags)) { sb.append("abstract "); } return sb.toString().trim(); @@ -327,23 +359,23 @@ */ public static String getFieldAccess(int access_flags) { StringBuffer sb = new StringBuffer(); - if(isPublic(access_flags)){ + if (isPublic(access_flags)) { sb.append("public "); - } else if(isPrivate(access_flags)){ + } else if (isPrivate(access_flags)) { sb.append("private "); - } else if (isProtected(access_flags)){ + } else if (isProtected(access_flags)) { sb.append("protected "); } - if(isFinal(access_flags)){ + if (isFinal(access_flags)) { sb.append("final "); } - if(isStatic(access_flags)){ + if (isStatic(access_flags)) { sb.append("static "); } - if(isVolatile(access_flags)){ + if (isVolatile(access_flags)) { sb.append("volatile "); } - if(isTransient(access_flags)){ + if (isTransient(access_flags)) { sb.append("transient "); } return sb.toString().trim(); @@ -356,26 +388,26 @@ */ public static String getClassAccess(int access_flags) { StringBuffer sb = new StringBuffer(); - if(isPublic(access_flags)){ + if (isPublic(access_flags)) { sb.append("public "); - } else if (isProtected(access_flags)){ + } else if (isProtected(access_flags)) { sb.append("protected "); - } else if (isPrivate(access_flags)){ + } else if (isPrivate(access_flags)) { sb.append("private "); } - if(isFinal(access_flags)){ + if (isFinal(access_flags)) { sb.append("final "); } - if(isSuper(access_flags)){ + if (isSuper(access_flags)) { sb.append("/*super*/ "); } - if(isInterface(access_flags)){ + if (isInterface(access_flags)) { sb.append("interface "); } - if(isAbstract(access_flags)){ + if (isAbstract(access_flags)) { sb.append("abstract "); } - if(isClass(access_flags)){ + if (isClass(access_flags)) { sb.append("class "); } return sb.toString().trim(); -- To unsubscribe, e-mail: For additional commands, e-mail: