git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@271118 13f79535-47bb-0310-9956-ffa450edef68master
@@ -63,52 +63,41 @@ import org.apache.tools.ant.taskdefs.optional.depend.constantpool.ConstantPool; | |||
import org.apache.tools.ant.taskdefs.optional.depend.constantpool.ConstantPoolEntry; | |||
/** | |||
* A ClassFile object stores information about a Java class. | |||
* | |||
* The class may be read from a DataInputStream.and written | |||
* to a DataOutputStream. These are usually streams from a Java | |||
* class file or a class file component of a Jar file. | |||
* A ClassFile object stores information about a Java class. The class may | |||
* be read from a DataInputStream.and written to a DataOutputStream. These | |||
* are usually streams from a Java class file or a class file component of a | |||
* Jar file. | |||
* | |||
* @author Conor MacNeill | |||
*/ | |||
public class ClassFile { | |||
/** | |||
* The Magic Value that marks the start of a Java class file | |||
*/ | |||
/** The Magic Value that marks the start of a Java class file */ | |||
private final static int CLASS_MAGIC = 0xCAFEBABE; | |||
/** | |||
* This class' constant pool. | |||
*/ | |||
/** This class' constant pool. */ | |||
private ConstantPool constantPool; | |||
/** | |||
* The class name for this class. | |||
*/ | |||
/** The class name for this class. */ | |||
private String className; | |||
/** | |||
* Read the class from a data stream. | |||
* Read the class from a data stream. This method takes an InputStream | |||
* as input and parses the class from the stream. <p> | |||
* | |||
* This method takes an InputStream as input and | |||
* parses the class from the stream. | |||
* <p> | |||
* | |||
* @param stream an InputStream from which the class will be read | |||
* | |||
* @throws IOException if there is a problem reading from the given stream. | |||
* @throws ClassFormatError if the class cannot be parsed correctly | |||
* | |||
* @param stream an InputStream from which the class will be read | |||
* @exception IOException if there is a problem reading from the given | |||
* stream. | |||
* @exception ClassFormatError if the class cannot be parsed correctly | |||
*/ | |||
public void read(InputStream stream) throws IOException, ClassFormatError { | |||
DataInputStream classStream = new DataInputStream(stream); | |||
if (classStream.readInt() != CLASS_MAGIC) { | |||
throw new ClassFormatError("No Magic Code Found - probably not a Java class file."); | |||
throw new ClassFormatError("No Magic Code Found " | |||
+ "- probably not a Java class file."); | |||
} | |||
// right we have a good looking class file. | |||
@@ -124,12 +113,16 @@ public class ClassFile { | |||
int accessFlags = classStream.readUnsignedShort(); | |||
int thisClassIndex = classStream.readUnsignedShort(); | |||
int superClassIndex = classStream.readUnsignedShort(); | |||
className = ((ClassCPInfo) constantPool.getEntry(thisClassIndex)).getClassName(); | |||
ClassCPInfo classInfo | |||
= (ClassCPInfo)constantPool.getEntry(thisClassIndex); | |||
className = classInfo.getClassName(); | |||
} | |||
/** | |||
* Get the classes which this class references. | |||
* | |||
* @return a vector of class names which this class references | |||
*/ | |||
public Vector getClassRefs() { | |||
@@ -138,8 +131,9 @@ public class ClassFile { | |||
for (int i = 0; i < constantPool.size(); ++i) { | |||
ConstantPoolEntry entry = constantPool.getEntry(i); | |||
if (entry != null && entry.getTag() == ConstantPoolEntry.CONSTANT_Class) { | |||
ClassCPInfo classEntry = (ClassCPInfo) entry; | |||
if (entry != null | |||
&& entry.getTag() == ConstantPoolEntry.CONSTANT_CLASS) { | |||
ClassCPInfo classEntry = (ClassCPInfo)entry; | |||
if (!classEntry.getClassName().equals(className)) { | |||
classRefs.addElement(ClassFileUtils.convertSlashName(classEntry.getClassName())); | |||
@@ -53,8 +53,18 @@ | |||
*/ | |||
package org.apache.tools.ant.taskdefs.optional.depend; | |||
/** | |||
* Iterator interface for iterating over a set of class files | |||
* | |||
* @author <a href="mailto:conor@apache.org">Conor MacNeill</a> | |||
*/ | |||
public interface ClassFileIterator { | |||
/** | |||
* Get the next class file in the iteration | |||
* | |||
* @return the next class file in the iterationr | |||
*/ | |||
ClassFile getNextClassFile(); | |||
} | |||
@@ -54,13 +54,12 @@ | |||
package org.apache.tools.ant.taskdefs.optional.depend; | |||
/** | |||
* Utility class file routines. | |||
* | |||
* This class porovides a number of static utility methods to convert between the | |||
* formats used in the Java class file format and those commonly used in Java | |||
* programming. | |||
* Utility class file routines. This class provides a number of static | |||
* utility methods to convert between the formats used in the Java class | |||
* file format and those commonly used in Java programming. | |||
* | |||
* @author Conor MacNeill | |||
* | |||
*/ | |||
public class ClassFileUtils { | |||
@@ -68,8 +67,7 @@ public class ClassFileUtils { | |||
* Convert a class name from class file slash notation to java source | |||
* file dot notation. | |||
* | |||
* @param slashName the class name in slash notation (eg. java/lang/Object) | |||
* | |||
* @param name the class name in slash notation org/apache/ant | |||
* @return the class name in dot notation (eg. java.lang.Object). | |||
*/ | |||
public static String convertSlashName(String name) { | |||
@@ -77,10 +75,10 @@ public class ClassFileUtils { | |||
} | |||
/** | |||
* Convert a class name from java source file dot notation to class file slash notation.. | |||
* Convert a class name from java source file dot notation to class file | |||
* slash notation.. | |||
* | |||
* @param dotName the class name in dot notation (eg. java.lang.Object). | |||
* | |||
* @return the class name in slash notation (eg. java/lang/Object). | |||
*/ | |||
public static String convertDotName(String dotName) { | |||
@@ -51,7 +51,6 @@ | |||
* information on the Apache Software Foundation, please see | |||
* <http://www.apache.org/>. | |||
*/ | |||
package org.apache.tools.ant.taskdefs.optional.depend; | |||
import java.io.BufferedReader; | |||
@@ -74,7 +73,6 @@ import org.apache.tools.ant.taskdefs.MatchingTask; | |||
import org.apache.tools.ant.types.Path; | |||
import org.apache.tools.ant.types.Reference; | |||
/** | |||
* Generate a dependency file for a given set of classes | |||
* | |||
@@ -83,79 +81,76 @@ import org.apache.tools.ant.types.Reference; | |||
public class Depend extends MatchingTask { | |||
/** | |||
* A class (struct) user to manage information about a class | |||
* | |||
* @author <a href="mailto:conor@apache.org">Conor MacNeill</a> | |||
*/ | |||
private static class ClassFileInfo { | |||
/** The file where the class file is stored in the file system */ | |||
public File absoluteFile; | |||
/** The location of the file relative to its base directory - the root | |||
of the package namespace */ | |||
/** | |||
* The location of the file relative to its base directory - the | |||
* root of the package namespace | |||
*/ | |||
public String relativeName; | |||
/** The Java class name of this class */ | |||
public String className; | |||
} | |||
/** | |||
* The path where source files exist | |||
*/ | |||
/** The path where source files exist */ | |||
private Path srcPath; | |||
/** | |||
* The path where compiled class files exist. | |||
*/ | |||
/** The path where compiled class files exist. */ | |||
private Path destPath; | |||
/** | |||
* The directory which contains the dependency cache. | |||
*/ | |||
/** The directory which contains the dependency cache. */ | |||
private File cache; | |||
/** | |||
* A map which gives for every class a list of te class which it affects. | |||
* A map which gives for every class a list of te class which it | |||
* affects. | |||
*/ | |||
private Hashtable affectedClassMap; | |||
/** | |||
* A map which gives information about a class | |||
*/ | |||
/** A map which gives information about a class */ | |||
private Hashtable classFileInfoMap; | |||
/** | |||
* A map which gives the list of jars and classes from the classpath that | |||
* a class depends upon | |||
* A map which gives the list of jars and classes from the classpath | |||
* that a class depends upon | |||
*/ | |||
private Hashtable classpathDependencies; | |||
/** | |||
* The list of classes which are out of date. | |||
*/ | |||
/** The list of classes which are out of date. */ | |||
private Hashtable outOfDateClasses; | |||
/** | |||
* indicates that the dependency relationships should be extended | |||
* beyond direct dependencies to include all classes. So if A directly | |||
* affects B abd B directly affects C, then A indirectly affects C. | |||
* indicates that the dependency relationships should be extended beyond | |||
* direct dependencies to include all classes. So if A directly affects | |||
* B abd B directly affects C, then A indirectly affects C. | |||
*/ | |||
private boolean closure = false; | |||
/** | |||
* Flag which controls whether the reversed dependencies should be dumped | |||
* to the log | |||
* Flag which controls whether the reversed dependencies should be | |||
* dumped to the log | |||
*/ | |||
private boolean dump = false; | |||
/** The classpath to look for additional dependencies */ | |||
private Path dependClasspath; | |||
/** | |||
* constants used with the cache file | |||
*/ | |||
/** constants used with the cache file */ | |||
private final static String CACHE_FILE_NAME = "dependencies.txt"; | |||
/** String Used to separate classnames in the dependency file */ | |||
private final static String CLASSNAME_PREPEND = "||:"; | |||
/** | |||
* Set the classpath to be used for this dependency check. | |||
* | |||
* @param classpath the classpath to be used when checking for | |||
* dependencies on elements in the classpath | |||
*/ | |||
public void setClasspath(Path classpath) { | |||
if (dependClasspath == null) { | |||
@@ -165,13 +160,19 @@ public class Depend extends MatchingTask { | |||
} | |||
} | |||
/** Gets the classpath to be used for this dependency check. */ | |||
/** | |||
* Gets the classpath to be used for this dependency check. | |||
* | |||
* @return the current dependency classpath | |||
*/ | |||
public Path getClasspath() { | |||
return dependClasspath; | |||
} | |||
/** | |||
* Creates a nested classpath element. | |||
* | |||
* @return A path object to be configured by Ant | |||
*/ | |||
public Path createClasspath() { | |||
if (dependClasspath == null) { | |||
@@ -182,6 +183,9 @@ public class Depend extends MatchingTask { | |||
/** | |||
* Adds a reference to a CLASSPATH defined elsewhere. | |||
* | |||
* @param r a reference to a path object to be used as the depend | |||
* classpath | |||
*/ | |||
public void setClasspathRef(Reference r) { | |||
createClasspath().setRefid(r); | |||
@@ -189,6 +193,9 @@ public class Depend extends MatchingTask { | |||
/** | |||
* Read the dependencies from cache file | |||
* | |||
* @return a collection of class dependencies | |||
* @exception IOException if the dependnecy file cannot be read | |||
*/ | |||
private Hashtable readCachedDependencies() throws IOException { | |||
Hashtable dependencyMap = new Hashtable(); | |||
@@ -225,8 +232,12 @@ public class Depend extends MatchingTask { | |||
/** | |||
* Write the dependencies to cache file | |||
* | |||
* @param dependencyMap the map of dependencies to be written out. | |||
* @exception IOException if the dependency file cannot be written out. | |||
*/ | |||
private void writeCachedDependencies(Hashtable dependencyMap) throws IOException { | |||
private void writeCachedDependencies(Hashtable dependencyMap) | |||
throws IOException { | |||
if (cache != null) { | |||
PrintWriter pw = null; | |||
try { | |||
@@ -234,12 +245,14 @@ public class Depend extends MatchingTask { | |||
File depFile = new File(cache, CACHE_FILE_NAME); | |||
pw = new PrintWriter(new FileWriter(depFile)); | |||
for (Enumeration deps = dependencyMap.keys(); deps.hasMoreElements();) { | |||
String className = (String) deps.nextElement(); | |||
Enumeration e = dependencyMap.keys(); | |||
while (e.hasMoreElements()) { | |||
String className = (String)e.nextElement(); | |||
pw.println(CLASSNAME_PREPEND + className); | |||
Vector dependencyList = (Vector) dependencyMap.get(className); | |||
Vector dependencyList | |||
= (Vector)dependencyMap.get(className); | |||
int size = dependencyList.size(); | |||
for (int x = 0; x < size; x++) { | |||
pw.println(dependencyList.elementAt(x)); | |||
@@ -255,10 +268,12 @@ public class Depend extends MatchingTask { | |||
/** | |||
* Determine the dependencies between classes. | |||
* Determine the dependencies between classes. Class dependencies are | |||
* determined by examining the class references in a class file to other | |||
* classes | |||
* | |||
* Class dependencies are determined by examining the class references in a class file | |||
* to other classes | |||
* @exception IOException if either the dependnecies cache or the class | |||
* files cannot be read or written | |||
*/ | |||
private void determineDependencies() throws IOException { | |||
affectedClassMap = new Hashtable(); | |||
@@ -277,8 +292,8 @@ public class Depend extends MatchingTask { | |||
depCacheFileExists = depCacheFile.exists(); | |||
depCacheFileLastModified = depCacheFile.lastModified(); | |||
} | |||
for (Enumeration e = getClassFiles(destPath).elements(); e.hasMoreElements();) { | |||
ClassFileInfo info = (ClassFileInfo) e.nextElement(); | |||
for (Enumeration e = getClassFiles(destPath).elements(); e.hasMoreElements(); ) { | |||
ClassFileInfo info = (ClassFileInfo)e.nextElement(); | |||
log("Adding class info for " + info.className, Project.MSG_DEBUG); | |||
classFileInfoMap.put(info.className, info); | |||
@@ -289,7 +304,7 @@ public class Depend extends MatchingTask { | |||
if (depCacheFileExists && depCacheFileLastModified > info.absoluteFile.lastModified()) { | |||
// depFile exists and is newer than the class file | |||
// need to get dependency list from the map. | |||
dependencyList = (Vector) dependencyMap.get(info.className); | |||
dependencyList = (Vector)dependencyMap.get(info.className); | |||
} | |||
} | |||
@@ -306,7 +321,6 @@ public class Depend extends MatchingTask { | |||
cacheDirty = true; | |||
dependencyMap.put(info.className, dependencyList); | |||
} | |||
} finally { | |||
if (inFileStream != null) { | |||
inFileStream.close(); | |||
@@ -316,10 +330,10 @@ public class Depend extends MatchingTask { | |||
// This class depends on each class in the dependency list. For each | |||
// one of those, add this class into their affected classes list | |||
for (Enumeration depEnum = dependencyList.elements(); depEnum.hasMoreElements();) { | |||
String dependentClass = (String) depEnum.nextElement(); | |||
for (Enumeration depEnum = dependencyList.elements(); depEnum.hasMoreElements(); ) { | |||
String dependentClass = (String)depEnum.nextElement(); | |||
Hashtable affectedClasses = (Hashtable) affectedClassMap.get(dependentClass); | |||
Hashtable affectedClasses = (Hashtable)affectedClassMap.get(dependentClass); | |||
if (affectedClasses == null) { | |||
affectedClasses = new Hashtable(); | |||
affectedClassMap.put(dependentClass, affectedClasses); | |||
@@ -337,13 +351,13 @@ public class Depend extends MatchingTask { | |||
Hashtable classpathFileCache = new Hashtable(); | |||
Object nullFileMarker = new Object(); | |||
for (Enumeration e = dependencyMap.keys(); e.hasMoreElements();) { | |||
String className = (String) e.nextElement(); | |||
Vector dependencyList = (Vector) dependencyMap.get(className); | |||
for (Enumeration e = dependencyMap.keys(); e.hasMoreElements(); ) { | |||
String className = (String)e.nextElement(); | |||
Vector dependencyList = (Vector)dependencyMap.get(className); | |||
Hashtable dependencies = new Hashtable(); | |||
classpathDependencies.put(className, dependencies); | |||
for (Enumeration e2 = dependencyList.elements(); e2.hasMoreElements();) { | |||
String dependency = (String) e2.nextElement(); | |||
for (Enumeration e2 = dependencyList.elements(); e2.hasMoreElements(); ) { | |||
String dependency = (String)e2.nextElement(); | |||
Object classpathFileObject = classpathFileCache.get(dependency); | |||
if (classpathFileObject == null) { | |||
classpathFileObject = nullFileMarker; | |||
@@ -363,15 +377,15 @@ public class Depend extends MatchingTask { | |||
classpathFileObject = new File(classFilePath); | |||
} | |||
log("Class " + className + | |||
" depends on " + classpathFileObject + | |||
" due to " + dependency, Project.MSG_DEBUG); | |||
" depends on " + classpathFileObject + | |||
" due to " + dependency, Project.MSG_DEBUG); | |||
} | |||
} | |||
classpathFileCache.put(dependency, classpathFileObject); | |||
} | |||
if (classpathFileObject != null && classpathFileObject != nullFileMarker) { | |||
// we need to add this jar to the list for this class. | |||
File jarFile = (File) classpathFileObject; | |||
File jarFile = (File)classpathFileObject; | |||
dependencies.put(jarFile, jarFile); | |||
} | |||
} | |||
@@ -384,12 +398,18 @@ public class Depend extends MatchingTask { | |||
} | |||
} | |||
/** | |||
* Delete all the class files which are out of date, by way of their | |||
* dependency on a class which is out of date | |||
* | |||
* @return the number of files deleted. | |||
*/ | |||
private int deleteAllAffectedFiles() { | |||
int count = 0; | |||
for (Enumeration e = outOfDateClasses.elements(); e.hasMoreElements();) { | |||
String className = (String) e.nextElement(); | |||
for (Enumeration e = outOfDateClasses.elements(); e.hasMoreElements(); ) { | |||
String className = (String)e.nextElement(); | |||
count += deleteAffectedFiles(className); | |||
ClassFileInfo classInfo = (ClassFileInfo) classFileInfoMap.get(className); | |||
ClassFileInfo classInfo = (ClassFileInfo)classFileInfoMap.get(className); | |||
if (classInfo != null && classInfo.absoluteFile.exists()) { | |||
classInfo.absoluteFile.delete(); | |||
count++; | |||
@@ -398,17 +418,24 @@ public class Depend extends MatchingTask { | |||
return count; | |||
} | |||
/** | |||
* Delete all the class files of classes which depend on the given class | |||
* | |||
* @param className the name of the class whose dependent classes willbe | |||
* deleted | |||
* @return the number of class files removed | |||
*/ | |||
private int deleteAffectedFiles(String className) { | |||
int count = 0; | |||
Hashtable affectedClasses = (Hashtable) affectedClassMap.get(className); | |||
Hashtable affectedClasses = (Hashtable)affectedClassMap.get(className); | |||
if (affectedClasses != null) { | |||
for (Enumeration e = affectedClasses.keys(); e.hasMoreElements();) { | |||
String affectedClassName = (String) e.nextElement(); | |||
ClassFileInfo affectedClassInfo = (ClassFileInfo) affectedClasses.get(affectedClassName); | |||
for (Enumeration e = affectedClasses.keys(); e.hasMoreElements(); ) { | |||
String affectedClassName = (String)e.nextElement(); | |||
ClassFileInfo affectedClassInfo = (ClassFileInfo)affectedClasses.get(affectedClassName); | |||
if (affectedClassInfo.absoluteFile.exists()) { | |||
log("Deleting file " + affectedClassInfo.absoluteFile.getPath() + " since " + | |||
className + " out of date", Project.MSG_VERBOSE); | |||
className + " out of date", Project.MSG_VERBOSE); | |||
affectedClassInfo.absoluteFile.delete(); | |||
count++; | |||
if (closure) { | |||
@@ -420,14 +447,14 @@ public class Depend extends MatchingTask { | |||
if (affectedClassName.indexOf("$") != -1) { | |||
// need to delete the main class | |||
String topLevelClassName | |||
= affectedClassName.substring(0, affectedClassName.indexOf("$")); | |||
= affectedClassName.substring(0, affectedClassName.indexOf("$")); | |||
log("Top level class = " + topLevelClassName, Project.MSG_VERBOSE); | |||
ClassFileInfo topLevelClassInfo | |||
= (ClassFileInfo) classFileInfoMap.get(topLevelClassName); | |||
= (ClassFileInfo)classFileInfoMap.get(topLevelClassName); | |||
if (topLevelClassInfo != null && | |||
topLevelClassInfo.absoluteFile.exists()) { | |||
topLevelClassInfo.absoluteFile.exists()) { | |||
log("Deleting file " + topLevelClassInfo.absoluteFile.getPath() + " since " + | |||
"one of its inner classes was removed", Project.MSG_VERBOSE); | |||
"one of its inner classes was removed", Project.MSG_VERBOSE); | |||
topLevelClassInfo.absoluteFile.delete(); | |||
count++; | |||
if (closure) { | |||
@@ -445,7 +472,7 @@ public class Depend extends MatchingTask { | |||
/** | |||
* Does the work. | |||
* | |||
* @exception BuildException Thrown in unrecovrable error. | |||
* @exception BuildException Thrown in case of an unrecoverable error. | |||
*/ | |||
public void execute() throws BuildException { | |||
try { | |||
@@ -471,38 +498,37 @@ public class Depend extends MatchingTask { | |||
if (dump) { | |||
log("Reverse Dependency Dump for " + affectedClassMap.size() + | |||
" classes:", Project.MSG_DEBUG); | |||
for (Enumeration e = affectedClassMap.keys(); e.hasMoreElements();) { | |||
String className = (String) e.nextElement(); | |||
" classes:", Project.MSG_DEBUG); | |||
for (Enumeration e = affectedClassMap.keys(); e.hasMoreElements(); ) { | |||
String className = (String)e.nextElement(); | |||
log(" Class " + className + " affects:", Project.MSG_DEBUG); | |||
Hashtable affectedClasses = (Hashtable) affectedClassMap.get(className); | |||
for (Enumeration e2 = affectedClasses.keys(); e2.hasMoreElements();) { | |||
String affectedClass = (String) e2.nextElement(); | |||
ClassFileInfo info = (ClassFileInfo) affectedClasses.get(affectedClass); | |||
Hashtable affectedClasses = (Hashtable)affectedClassMap.get(className); | |||
for (Enumeration e2 = affectedClasses.keys(); e2.hasMoreElements(); ) { | |||
String affectedClass = (String)e2.nextElement(); | |||
ClassFileInfo info = (ClassFileInfo)affectedClasses.get(affectedClass); | |||
log(" " + affectedClass + " in " + info.absoluteFile.getPath(), Project.MSG_DEBUG); | |||
} | |||
} | |||
if (classpathDependencies != null) { | |||
log("Classpath file dependencies (Forward):", Project.MSG_DEBUG); | |||
for (Enumeration e = classpathDependencies.keys(); e.hasMoreElements();) { | |||
String className = (String) e.nextElement(); | |||
for (Enumeration e = classpathDependencies.keys(); e.hasMoreElements(); ) { | |||
String className = (String)e.nextElement(); | |||
log(" Class " + className + " depends on:", Project.MSG_DEBUG); | |||
Hashtable dependencies = (Hashtable) classpathDependencies.get(className); | |||
for (Enumeration e2 = dependencies.elements(); e2.hasMoreElements();) { | |||
File classpathFile = (File) e2.nextElement(); | |||
Hashtable dependencies = (Hashtable)classpathDependencies.get(className); | |||
for (Enumeration e2 = dependencies.elements(); e2.hasMoreElements(); ) { | |||
File classpathFile = (File)e2.nextElement(); | |||
log(" " + classpathFile.getPath(), Project.MSG_DEBUG); | |||
} | |||
} | |||
} | |||
} | |||
// we now need to scan for out of date files. When we have the list | |||
// we go through and delete all class files which are affected by these files. | |||
outOfDateClasses = new Hashtable(); | |||
for (int i = 0; i < srcPathList.length; i++) { | |||
File srcDir = (File) project.resolveFile(srcPathList[i]); | |||
File srcDir = (File)project.resolveFile(srcPathList[i]); | |||
if (srcDir.exists()) { | |||
DirectoryScanner ds = this.getDirectoryScanner(srcDir); | |||
String[] files = ds.getIncludedFiles(); | |||
@@ -512,20 +538,20 @@ public class Depend extends MatchingTask { | |||
// now check classpath file dependencies | |||
if (classpathDependencies != null) { | |||
for (Enumeration e = classpathDependencies.keys(); e.hasMoreElements();) { | |||
String className = (String) e.nextElement(); | |||
for (Enumeration e = classpathDependencies.keys(); e.hasMoreElements(); ) { | |||
String className = (String)e.nextElement(); | |||
if (!outOfDateClasses.containsKey(className)) { | |||
ClassFileInfo info = (ClassFileInfo) classFileInfoMap.get(className); | |||
ClassFileInfo info = (ClassFileInfo)classFileInfoMap.get(className); | |||
// if we have no info about the class - it may have been deleted already and we | |||
// are using cached info. | |||
if (info != null) { | |||
Hashtable dependencies = (Hashtable) classpathDependencies.get(className); | |||
for (Enumeration e2 = dependencies.elements(); e2.hasMoreElements();) { | |||
File classpathFile = (File) e2.nextElement(); | |||
Hashtable dependencies = (Hashtable)classpathDependencies.get(className); | |||
for (Enumeration e2 = dependencies.elements(); e2.hasMoreElements(); ) { | |||
File classpathFile = (File)e2.nextElement(); | |||
if (classpathFile.lastModified() > info.absoluteFile.lastModified()) { | |||
log("Class " + className + | |||
" is out of date with respect to " + classpathFile, Project.MSG_DEBUG); | |||
" is out of date with respect to " + classpathFile, Project.MSG_DEBUG); | |||
outOfDateClasses.put(className, className); | |||
break; | |||
} | |||
@@ -547,8 +573,13 @@ public class Depend extends MatchingTask { | |||
} | |||
/** | |||
* Scans the directory looking for source files that are newer than their class files. | |||
* The results are returned in the class variable compileList | |||
* Scans the directory looking for source files that are newer than | |||
* their class files. The results are returned in the class variable | |||
* compileList | |||
* | |||
* @param srcDir the source directory | |||
* @param files the names of the files in the source dir which are to be | |||
* checked. | |||
*/ | |||
protected void scanDir(File srcDir, String files[]) { | |||
@@ -559,9 +590,9 @@ public class Depend extends MatchingTask { | |||
if (files[i].endsWith(".java")) { | |||
String filePath = srcFile.getPath(); | |||
String className = filePath.substring(srcDir.getPath().length() + 1, | |||
filePath.length() - ".java".length()); | |||
filePath.length() - ".java".length()); | |||
className = ClassFileUtils.convertSlashName(className); | |||
ClassFileInfo info = (ClassFileInfo) classFileInfoMap.get(className); | |||
ClassFileInfo info = (ClassFileInfo)classFileInfoMap.get(className); | |||
if (info == null) { | |||
// there was no class file. add this class to the list | |||
outOfDateClasses.put(className, className); | |||
@@ -579,7 +610,7 @@ public class Depend extends MatchingTask { | |||
* Get the list of class files we are going to analyse. | |||
* | |||
* @param classLocations a path structure containing all the directories | |||
* where classes can be found. | |||
* where classes can be found. | |||
* @return a vector containing the classes to analyse. | |||
*/ | |||
private Vector getClassFiles(Path classLocations) { | |||
@@ -599,12 +630,16 @@ public class Depend extends MatchingTask { | |||
} | |||
/** | |||
* Add the list of class files from the given directory to the | |||
* class file vector, including any subdirectories. | |||
* Add the list of class files from the given directory to the class | |||
* file vector, including any subdirectories. | |||
* | |||
* @param classLocations a path structure containing all the directories | |||
* where classes can be found. | |||
* @return a vector containing the classes to analyse. | |||
* @param classFileList a list of ClassFileInfo objects for all the | |||
* files in the diretcort tree | |||
* @param dir tyhe directory tree to be searched, recursivley, for class | |||
* files | |||
* @param root the root of the source tree. This is used to determine | |||
* the absoluate class name from the relative position in the | |||
* source tree | |||
*/ | |||
private void addClassFiles(Vector classFileList, File dir, File root) { | |||
String[] filesInDir = dir.list(); | |||
@@ -620,7 +655,7 @@ public class Depend extends MatchingTask { | |||
ClassFileInfo info = new ClassFileInfo(); | |||
info.absoluteFile = file; | |||
info.relativeName = file.getPath().substring(root.getPath().length() + 1, | |||
file.getPath().length() - 6); | |||
file.getPath().length() - 6); | |||
info.className = ClassFileUtils.convertSlashName(info.relativeName); | |||
classFileList.addElement(info); | |||
} | |||
@@ -631,6 +666,8 @@ public class Depend extends MatchingTask { | |||
/** | |||
* Set the source dirs to find the source Java files. | |||
* | |||
* @param srcPath the source path | |||
*/ | |||
public void setSrcdir(Path srcPath) { | |||
this.srcPath = srcPath; | |||
@@ -638,21 +675,39 @@ public class Depend extends MatchingTask { | |||
/** | |||
* Set the destination directory where the compiled java files exist. | |||
* | |||
* @param destPath the destination areas where build files are written | |||
*/ | |||
public void setDestDir(Path destPath) { | |||
this.destPath = destPath; | |||
} | |||
/** | |||
* Sets the dependency cache file | |||
* | |||
* @param cache the dependency cache file | |||
*/ | |||
public void setCache(File cache) { | |||
this.cache = cache; | |||
} | |||
/** | |||
* Set the closure flag. When not set, the depend task will only follow | |||
* direct dependencies between classes. When set, transitive | |||
* dependenecies are followed until the closure of the dependency set if | |||
* reached. | |||
* | |||
* @param closure indicate if dependency closure is required. | |||
*/ | |||
public void setClosure(boolean closure) { | |||
this.closure = closure; | |||
} | |||
/** | |||
* Flag to indicate whether the reverse dependency list should be dumped to debug | |||
* Flag to indicate whether the reverse dependency list should be dumped | |||
* to debug | |||
* | |||
* @param dump set to true to dump dependency information to the log | |||
*/ | |||
public void setDump(boolean dump) { | |||
this.dump = dump; | |||
@@ -61,10 +61,9 @@ import java.util.Stack; | |||
import java.util.Vector; | |||
/** | |||
* An iterator which iterates through the contents of a java directory. | |||
* | |||
* The iterator should be created with the directory at the root of the | |||
* Java namespace. | |||
* An iterator which iterates through the contents of a java directory. The | |||
* iterator should be created with the directory at the root of the Java | |||
* namespace. | |||
* | |||
* @author Conor MacNeill | |||
*/ | |||
@@ -78,32 +77,34 @@ public class DirectoryIterator implements ClassFileIterator { | |||
/** | |||
* The current directory iterator. As directories encounter lower level | |||
* directories, the current iterator is pushed onto the iterator | |||
* stack and a new iterator over the sub directory becomes the current | |||
* directory. This implements a depth first traversal of the directory namespace. | |||
* directories, the current iterator is pushed onto the iterator stack | |||
* and a new iterator over the sub directory becomes the current | |||
* directory. This implements a depth first traversal of the directory | |||
* namespace. | |||
*/ | |||
private Enumeration currentEnum; | |||
/** | |||
* The length of the root directory. This is used to remove the root directory | |||
* from full paths. | |||
* The length of the root directory. This is used to remove the root | |||
* directory from full paths. | |||
*/ | |||
int rootLength; | |||
private int rootLength; | |||
/** | |||
* Creates a directory iterator. | |||
* | |||
* The directory iterator is created to scan the root directory. If the | |||
* changeInto flag is given, then the entries returned will be relative to this | |||
* directory and not the current directory. | |||
* | |||
* @param rootDirectory the root if the directory namespace which is to be iterated over | |||
* @param changeInto if true then the returned entries will be relative to the rootDirectory | |||
* and not the current directory. | |||
* Creates a directory iterator. The directory iterator is created to | |||
* scan the root directory. If the changeInto flag is given, then the | |||
* entries returned will be relative to this directory and not the | |||
* current directory. | |||
* | |||
* @throws IOException if there is a problem reading the directory information. | |||
* @param rootDirectory the root if the directory namespace which is to | |||
* be iterated over | |||
* @param changeInto if true then the returned entries will be relative | |||
* to the rootDirectory and not the current directory. | |||
* @exception IOException if there is a problem reading the directory | |||
* information. | |||
*/ | |||
public DirectoryIterator(File rootDirectory, boolean changeInto) throws IOException { | |||
public DirectoryIterator(File rootDirectory, boolean changeInto) | |||
throws IOException { | |||
super(); | |||
enumStack = new Stack(); | |||
@@ -120,11 +121,12 @@ public class DirectoryIterator implements ClassFileIterator { | |||
} | |||
/** | |||
* Get a vector covering all the entries (files and subdirectories in a directory). | |||
* Get a vector covering all the entries (files and subdirectories in a | |||
* directory). | |||
* | |||
* @param directory the directory to be scanned. | |||
* | |||
* @return a vector containing File objects for each entry in the directory. | |||
* @return a vector containing File objects for each entry in the | |||
* directory. | |||
*/ | |||
private Vector getDirectoryEntries(File directory) { | |||
Vector files = new Vector(); | |||
@@ -144,15 +146,16 @@ public class DirectoryIterator implements ClassFileIterator { | |||
} | |||
/** | |||
* Template method to allow subclasses to supply elements for the iteration. | |||
* | |||
* The directory iterator maintains a stack of iterators covering each level | |||
* in the directory hierarchy. The current iterator covers the current directory | |||
* being scanned. If the next entry in that directory is a subdirectory, the current | |||
* iterator is pushed onto the stack and a new iterator is created for the | |||
* subdirectory. If the entry is a file, it is returned as the next element and the | |||
* iterator remains valid. If there are no more entries in the current directory, | |||
* the topmost iterator on the statck is popped off to become the current iterator. | |||
* Template method to allow subclasses to supply elements for the | |||
* iteration. The directory iterator maintains a stack of iterators | |||
* covering each level in the directory hierarchy. The current iterator | |||
* covers the current directory being scanned. If the next entry in that | |||
* directory is a subdirectory, the current iterator is pushed onto the | |||
* stack and a new iterator is created for the subdirectory. If the | |||
* entry is a file, it is returned as the next element and the iterator | |||
* remains valid. If there are no more entries in the current directory, | |||
* the topmost iterator on the statck is popped off to become the | |||
* current iterator. | |||
* | |||
* @return the next ClassFile in the iteration. | |||
*/ | |||
@@ -162,7 +165,7 @@ public class DirectoryIterator implements ClassFileIterator { | |||
try { | |||
while (nextElement == null) { | |||
if (currentEnum.hasMoreElements()) { | |||
File element = (File) currentEnum.nextElement(); | |||
File element = (File)currentEnum.nextElement(); | |||
if (element.isDirectory()) { | |||
@@ -176,11 +179,13 @@ public class DirectoryIterator implements ClassFileIterator { | |||
} else { | |||
// we have a file. create a stream for it | |||
FileInputStream inFileStream = new FileInputStream(element); | |||
FileInputStream inFileStream | |||
= new FileInputStream(element); | |||
if (element.getName().endsWith(".class")) { | |||
// create a data input stream from the jar input stream | |||
// create a data input stream from the jar | |||
// input stream | |||
ClassFile javaClass = new ClassFile(); | |||
javaClass.read(inFileStream); | |||
@@ -193,7 +198,7 @@ public class DirectoryIterator implements ClassFileIterator { | |||
if (enumStack.empty()) { | |||
break; | |||
} else { | |||
currentEnum = (Enumeration) enumStack.pop(); | |||
currentEnum = (Enumeration)enumStack.pop(); | |||
} | |||
} | |||
} | |||
@@ -60,19 +60,34 @@ import java.util.zip.ZipEntry; | |||
import java.util.zip.ZipInputStream; | |||
/** | |||
* A class file iterator which iterates through the contents of a Java jar file. | |||
* A class file iterator which iterates through the contents of a Java jar | |||
* file. | |||
* | |||
* @author Conor MacNeill | |||
*/ | |||
public class JarFileIterator implements ClassFileIterator { | |||
/** The jar stream from the jar file being iterated over*/ | |||
private ZipInputStream jarStream; | |||
/** | |||
* Construct a iterartor over a jar stream | |||
* | |||
* @param stream the basic input stream from which the Jar is recived | |||
* @exception IOException if the jar stream connot be created | |||
*/ | |||
public JarFileIterator(InputStream stream) throws IOException { | |||
super(); | |||
jarStream = new ZipInputStream(stream); | |||
} | |||
/** | |||
* Read a stream into an array of bytes | |||
* | |||
* @param stream the stream from which the bytes are read | |||
* @return the stream's content as a byte array | |||
* @exception IOException if the stream cannot be read | |||
*/ | |||
private byte[] getEntryBytes(InputStream stream) throws IOException { | |||
byte[] buffer = new byte[8192]; | |||
ByteArrayOutputStream baos = new ByteArrayOutputStream(2048); | |||
@@ -85,6 +100,11 @@ public class JarFileIterator implements ClassFileIterator { | |||
return baos.toByteArray(); | |||
} | |||
/** | |||
* Get the next ClassFile object from the jar | |||
* | |||
* @return a ClassFile object describing the class from the jar | |||
*/ | |||
public ClassFile getNextClassFile() { | |||
ZipEntry jarEntry; | |||
ClassFile nextElement = null; | |||
@@ -92,7 +112,6 @@ public class JarFileIterator implements ClassFileIterator { | |||
try { | |||
jarEntry = jarStream.getNextEntry(); | |||
while (nextElement == null && jarEntry != null) { | |||
String entryName = jarEntry.getName(); | |||
@@ -56,7 +56,6 @@ package org.apache.tools.ant.taskdefs.optional.depend.constantpool; | |||
import java.io.DataInputStream; | |||
import java.io.IOException; | |||
/** | |||
* The constant pool entry which stores class information. | |||
* | |||
@@ -65,33 +64,32 @@ import java.io.IOException; | |||
public class ClassCPInfo extends ConstantPoolEntry { | |||
/** | |||
* The class' name. This will be only valid if the entry has been resolved | |||
* against the constant pool. | |||
* The class' name. This will be only valid if the entry has been | |||
* resolved against the constant pool. | |||
*/ | |||
private String className; | |||
/** | |||
* The index into the constant pool where this class' name is stored. If the class | |||
* name is changed, this entry is invalid until this entry is connected to a constant | |||
* pool. | |||
* The index into the constant pool where this class' name is stored. If | |||
* the class name is changed, this entry is invalid until this entry is | |||
* connected to a constant pool. | |||
*/ | |||
private int index; | |||
/** | |||
* Constructor. | |||
* | |||
* Sets the tag value for this entry to type Class | |||
* Constructor. Sets the tag value for this entry to type Class | |||
*/ | |||
public ClassCPInfo() { | |||
super(CONSTANT_Class, 1); | |||
super(CONSTANT_CLASS, 1); | |||
} | |||
/** | |||
* Read the entry from a stream. | |||
* | |||
* @param cpStream the stream containing the constant pool entry to be read. | |||
* | |||
* @exception IOException thrown if there is a problem reading the entry from the stream. | |||
* @param cpStream the stream containing the constant pool entry to be | |||
* read. | |||
* @exception IOException thrown if there is a problem reading the entry | |||
* from the stream. | |||
*/ | |||
public void read(DataInputStream cpStream) throws IOException { | |||
index = cpStream.readUnsignedShort(); | |||
@@ -100,6 +98,8 @@ public class ClassCPInfo extends ConstantPoolEntry { | |||
/** | |||
* Generate a string readable version of this entry | |||
* | |||
* @return string representation of this constant pool entry | |||
*/ | |||
public String toString() { | |||
return "Class Constant Pool Entry for " + className + "[" + index + "]"; | |||
@@ -108,10 +108,11 @@ public class ClassCPInfo extends ConstantPoolEntry { | |||
/** | |||
* Resolve this class info against the given constant pool. | |||
* | |||
* @param constantPool the constant pool with which to resolve the class. | |||
* @param constantPool the constant pool with which to resolve the | |||
* class. | |||
*/ | |||
public void resolve(ConstantPool constantPool) { | |||
className = ((Utf8CPInfo) constantPool.getEntry(index)).getValue(); | |||
className = ((Utf8CPInfo)constantPool.getEntry(index)).getValue(); | |||
super.resolve(constantPool); | |||
} | |||
@@ -53,20 +53,17 @@ | |||
*/ | |||
package org.apache.tools.ant.taskdefs.optional.depend.constantpool; | |||
/** | |||
* A Constant Pool entry which represents a constant value. | |||
* | |||
* | |||
* @author Conor MacNeill | |||
*/ | |||
public abstract class ConstantCPInfo extends ConstantPoolEntry { | |||
/** | |||
* The entry's untyped value. | |||
* | |||
* Each subclass interprets the constant value based on the subclass's type. | |||
* The value here must be compatible. | |||
* The entry's untyped value. Each subclass interprets the constant | |||
* value based on the subclass's type. The value here must be | |||
* compatible. | |||
*/ | |||
private Object value; | |||
@@ -74,7 +71,8 @@ public abstract class ConstantCPInfo extends ConstantPoolEntry { | |||
* Initialise the constant entry. | |||
* | |||
* @param tagValue the constant pool entry type to be used. | |||
* @param entries the number of constant pool entry slots occupied by this entry. | |||
* @param entries the number of constant pool entry slots occupied by | |||
* this entry. | |||
*/ | |||
protected ConstantCPInfo(int tagValue, int entries) { | |||
super(tagValue, entries); | |||
@@ -60,30 +60,26 @@ import java.util.Hashtable; | |||
import java.util.Vector; | |||
/** | |||
* The constant pool of a Java class. | |||
* | |||
* The constant pool is a collection of constants used in a Java class file. It stores | |||
* strings, constant values, class names, method names, field names etc. | |||
* | |||
* @see <a href="http://java.sun.com/docs/books/vmspec/">The Java Virtual Machine Specification</a> | |||
* The constant pool of a Java class. The constant pool is a collection of | |||
* constants used in a Java class file. It stores strings, constant values, | |||
* class names, method names, field names etc. | |||
* | |||
* @author Conor MacNeill | |||
* @see <a href="http://java.sun.com/docs/books/vmspec/">The Java Virtual | |||
* Machine Specification</a> | |||
*/ | |||
public class ConstantPool { | |||
/** | |||
* The entries in the constant pool. | |||
*/ | |||
/** The entries in the constant pool. */ | |||
private Vector entries; | |||
/** | |||
* A Hashtable of UTF8 entries - used to get constant pool indexes of the UTF8 values quickly | |||
* A Hashtable of UTF8 entries - used to get constant pool indexes of | |||
* the UTF8 values quickly | |||
*/ | |||
private Hashtable utf8Indexes; | |||
/** | |||
* Initialise the constant pool. | |||
*/ | |||
/** Initialise the constant pool. */ | |||
public ConstantPool() { | |||
entries = new Vector(); | |||
@@ -98,15 +94,15 @@ public class ConstantPool { | |||
* Read the constant pool from a class input stream. | |||
* | |||
* @param classStream the DataInputStream of a class file. | |||
* | |||
* @throws IOException if there is a problem reading the constant pool | |||
* from the stream | |||
* @exception IOException if there is a problem reading the constant pool | |||
* from the stream | |||
*/ | |||
public void read(DataInputStream classStream) throws IOException { | |||
int numEntries = classStream.readUnsignedShort(); | |||
for (int i = 1; i < numEntries;) { | |||
ConstantPoolEntry nextEntry = ConstantPoolEntry.readEntry(classStream); | |||
for (int i = 1; i < numEntries; ) { | |||
ConstantPoolEntry nextEntry | |||
= ConstantPoolEntry.readEntry(classStream); | |||
i += nextEntry.getNumEntries(); | |||
@@ -116,6 +112,8 @@ public class ConstantPool { | |||
/** | |||
* Get the size of the constant pool. | |||
* | |||
* @return the size of the constant pool | |||
*/ | |||
public int size() { | |||
return entries.size(); | |||
@@ -125,8 +123,8 @@ public class ConstantPool { | |||
* Add an entry to the constant pool. | |||
* | |||
* @param entry the new entry to be added to the constant pool. | |||
* | |||
* @return the index into the constant pool at which the entry is stored. | |||
* @return the index into the constant pool at which the entry is | |||
* stored. | |||
*/ | |||
public int addEntry(ConstantPoolEntry entry) { | |||
int index = entries.size(); | |||
@@ -141,7 +139,7 @@ public class ConstantPool { | |||
} | |||
if (entry instanceof Utf8CPInfo) { | |||
Utf8CPInfo utf8Info = (Utf8CPInfo) entry; | |||
Utf8CPInfo utf8Info = (Utf8CPInfo)entry; | |||
utf8Indexes.put(utf8Info.getValue(), new Integer(index)); | |||
} | |||
@@ -150,14 +148,13 @@ public class ConstantPool { | |||
} | |||
/** | |||
* Resolve the entries in the constant pool. | |||
* | |||
* Resolution of the constant pool involves transforming indexes to | |||
* other constant pool entries into the actual data for that entry. | |||
* Resolve the entries in the constant pool. Resolution of the constant | |||
* pool involves transforming indexes to other constant pool entries | |||
* into the actual data for that entry. | |||
*/ | |||
public void resolve() { | |||
for (Enumeration i = entries.elements(); i.hasMoreElements();) { | |||
ConstantPoolEntry poolInfo = (ConstantPoolEntry) i.nextElement(); | |||
for (Enumeration i = entries.elements(); i.hasMoreElements(); ) { | |||
ConstantPoolEntry poolInfo = (ConstantPoolEntry)i.nextElement(); | |||
if (poolInfo != null && !poolInfo.isResolved()) { | |||
poolInfo.resolve(this); | |||
@@ -170,24 +167,22 @@ public class ConstantPool { | |||
* Get an constant pool entry at a particular index. | |||
* | |||
* @param index the index into the constant pool. | |||
* | |||
* @return the constant pool entry at that index. | |||
*/ | |||
public ConstantPoolEntry getEntry(int index) { | |||
return (ConstantPoolEntry) entries.elementAt(index); | |||
return (ConstantPoolEntry)entries.elementAt(index); | |||
} | |||
/** | |||
* Get the index of a given UTF8 constant pool entry. | |||
* | |||
* @param value the string value of the UTF8 entry. | |||
* | |||
* @return the index at which the given string occurs in the | |||
* constant pool or -1 if the value does not occur. | |||
* @return the index at which the given string occurs in the constant | |||
* pool or -1 if the value does not occur. | |||
*/ | |||
public int getUTF8Entry(String value) { | |||
int index = -1; | |||
Integer indexInteger = (Integer) utf8Indexes.get(value); | |||
Integer indexInteger = (Integer)utf8Indexes.get(value); | |||
if (indexInteger != null) { | |||
index = indexInteger.intValue(); | |||
@@ -197,12 +192,12 @@ public class ConstantPool { | |||
} | |||
/** | |||
* Get the index of a given CONSTANT_Class entry in the constant pool. | |||
* | |||
* @param className the name of the class for which the class entry index is required. | |||
* Get the index of a given CONSTANT_CLASS entry in the constant pool. | |||
* | |||
* @param className the name of the class for which the class entry | |||
* index is required. | |||
* @return the index at which the given class entry occurs in the | |||
* constant pool or -1 if the value does not occur. | |||
* constant pool or -1 if the value does not occur. | |||
*/ | |||
public int getClassEntry(String className) { | |||
int index = -1; | |||
@@ -211,7 +206,7 @@ public class ConstantPool { | |||
Object element = entries.elementAt(i); | |||
if (element instanceof ClassCPInfo) { | |||
ClassCPInfo classinfo = (ClassCPInfo) element; | |||
ClassCPInfo classinfo = (ClassCPInfo)element; | |||
if (classinfo.getClassName().equals(className)) { | |||
index = i; | |||
@@ -225,10 +220,10 @@ public class ConstantPool { | |||
/** | |||
* Get the index of a given constant value entry in the constant pool. | |||
* | |||
* @param constantValue the constant value for which the index is required. | |||
* | |||
* @param constantValue the constant value for which the index is | |||
* required. | |||
* @return the index at which the given value entry occurs in the | |||
* constant pool or -1 if the value does not occur. | |||
* constant pool or -1 if the value does not occur. | |||
*/ | |||
public int getConstantEntry(Object constantValue) { | |||
int index = -1; | |||
@@ -237,7 +232,7 @@ public class ConstantPool { | |||
Object element = entries.elementAt(i); | |||
if (element instanceof ConstantCPInfo) { | |||
ConstantCPInfo constantEntry = (ConstantCPInfo) element; | |||
ConstantCPInfo constantEntry = (ConstantCPInfo)element; | |||
if (constantEntry.getValue().equals(constantValue)) { | |||
index = i; | |||
@@ -249,27 +244,29 @@ public class ConstantPool { | |||
} | |||
/** | |||
* Get the index of a given CONSTANT_MethodRef entry in the constant pool. | |||
* Get the index of a given CONSTANT_METHODREF entry in the constant | |||
* pool. | |||
* | |||
* @param methodClassName the name of the class which contains the method | |||
* being referenced. | |||
* @param methodClassName the name of the class which contains the | |||
* method being referenced. | |||
* @param methodName the name of the method being referenced. | |||
* @param methodType the type descriptor of the metho dbeing referenced. | |||
* | |||
* @return the index at which the given method ref entry occurs in the | |||
* constant pool or -1 if the value does not occur. | |||
* constant pool or -1 if the value does not occur. | |||
*/ | |||
public int getMethodRefEntry(String methodClassName, String methodName, String methodType) { | |||
public int getMethodRefEntry(String methodClassName, String methodName, | |||
String methodType) { | |||
int index = -1; | |||
for (int i = 0; i < entries.size() && index == -1; ++i) { | |||
Object element = entries.elementAt(i); | |||
if (element instanceof MethodRefCPInfo) { | |||
MethodRefCPInfo methodRefEntry = (MethodRefCPInfo) element; | |||
MethodRefCPInfo methodRefEntry = (MethodRefCPInfo)element; | |||
if (methodRefEntry.getMethodClassName().equals(methodClassName) | |||
&& methodRefEntry.getMethodName().equals(methodName) && methodRefEntry.getMethodType().equals(methodType)) { | |||
&& methodRefEntry.getMethodName().equals(methodName) | |||
&& methodRefEntry.getMethodType().equals(methodType)) { | |||
index = i; | |||
} | |||
} | |||
@@ -279,28 +276,32 @@ public class ConstantPool { | |||
} | |||
/** | |||
* Get the index of a given CONSTANT_InterfaceMethodRef entry in the constant pool. | |||
* Get the index of a given CONSTANT_INTERFACEMETHODREF entry in the | |||
* constant pool. | |||
* | |||
* @param interfaceMethodClassName the name of the interface which contains the method | |||
* being referenced. | |||
* @param interfaceMethodClassName the name of the interface which | |||
* contains the method being referenced. | |||
* @param interfaceMethodName the name of the method being referenced. | |||
* @param interfaceMethodType the type descriptor of the metho dbeing referenced. | |||
* | |||
* @param interfaceMethodType the type descriptor of the metho dbeing | |||
* referenced. | |||
* @return the index at which the given method ref entry occurs in the | |||
* constant pool or -1 if the value does not occur. | |||
* constant pool or -1 if the value does not occur. | |||
*/ | |||
public int getInterfaceMethodRefEntry(String interfaceMethodClassName, String interfaceMethodName, String interfaceMethodType) { | |||
public int getInterfaceMethodRefEntry(String interfaceMethodClassName, | |||
String interfaceMethodName, | |||
String interfaceMethodType) { | |||
int index = -1; | |||
for (int i = 0; i < entries.size() && index == -1; ++i) { | |||
Object element = entries.elementAt(i); | |||
if (element instanceof InterfaceMethodRefCPInfo) { | |||
InterfaceMethodRefCPInfo interfaceMethodRefEntry = (InterfaceMethodRefCPInfo) element; | |||
InterfaceMethodRefCPInfo interfaceMethodRefEntry | |||
= (InterfaceMethodRefCPInfo)element; | |||
if (interfaceMethodRefEntry.getInterfaceMethodClassName().equals(interfaceMethodClassName) | |||
&& interfaceMethodRefEntry.getInterfaceMethodName().equals(interfaceMethodName) | |||
&& interfaceMethodRefEntry.getInterfaceMethodType().equals(interfaceMethodType)) { | |||
&& interfaceMethodRefEntry.getInterfaceMethodName().equals(interfaceMethodName) | |||
&& interfaceMethodRefEntry.getInterfaceMethodType().equals(interfaceMethodType)) { | |||
index = i; | |||
} | |||
} | |||
@@ -310,27 +311,29 @@ public class ConstantPool { | |||
} | |||
/** | |||
* Get the index of a given CONSTANT_FieldRef entry in the constant pool. | |||
* Get the index of a given CONSTANT_FIELDREF entry in the constant | |||
* pool. | |||
* | |||
* @param fieldClassName the name of the class which contains the field | |||
* being referenced. | |||
* being referenced. | |||
* @param fieldName the name of the field being referenced. | |||
* @param fieldType the type descriptor of the field being referenced. | |||
* | |||
* @return the index at which the given field ref entry occurs in the | |||
* constant pool or -1 if the value does not occur. | |||
* constant pool or -1 if the value does not occur. | |||
*/ | |||
public int getFieldRefEntry(String fieldClassName, String fieldName, String fieldType) { | |||
public int getFieldRefEntry(String fieldClassName, String fieldName, | |||
String fieldType) { | |||
int index = -1; | |||
for (int i = 0; i < entries.size() && index == -1; ++i) { | |||
Object element = entries.elementAt(i); | |||
if (element instanceof FieldRefCPInfo) { | |||
FieldRefCPInfo fieldRefEntry = (FieldRefCPInfo) element; | |||
FieldRefCPInfo fieldRefEntry = (FieldRefCPInfo)element; | |||
if (fieldRefEntry.getFieldClassName().equals(fieldClassName) && fieldRefEntry.getFieldName().equals(fieldName) | |||
&& fieldRefEntry.getFieldType().equals(fieldType)) { | |||
if (fieldRefEntry.getFieldClassName().equals(fieldClassName) | |||
&& fieldRefEntry.getFieldName().equals(fieldName) | |||
&& fieldRefEntry.getFieldType().equals(fieldType)) { | |||
index = i; | |||
} | |||
} | |||
@@ -340,13 +343,13 @@ public class ConstantPool { | |||
} | |||
/** | |||
* Get the index of a given CONSTANT_NameAndType entry in the constant pool. | |||
* Get the index of a given CONSTANT_NAMEANDTYPE entry in the constant | |||
* pool. | |||
* | |||
* @param name the name | |||
* @param type the type | |||
* | |||
* @return the index at which the given NameAndType entry occurs in the | |||
* constant pool or -1 if the value does not occur. | |||
* constant pool or -1 if the value does not occur. | |||
*/ | |||
public int getNameAndTypeEntry(String name, String type) { | |||
int index = -1; | |||
@@ -355,9 +358,10 @@ public class ConstantPool { | |||
Object element = entries.elementAt(i); | |||
if (element instanceof NameAndTypeCPInfo) { | |||
NameAndTypeCPInfo nameAndTypeEntry = (NameAndTypeCPInfo) element; | |||
NameAndTypeCPInfo nameAndTypeEntry = (NameAndTypeCPInfo)element; | |||
if (nameAndTypeEntry.getName().equals(name) && nameAndTypeEntry.getType().equals(type)) { | |||
if (nameAndTypeEntry.getName().equals(name) | |||
&& nameAndTypeEntry.getType().equals(type)) { | |||
index = i; | |||
} | |||
} | |||
@@ -56,75 +56,52 @@ package org.apache.tools.ant.taskdefs.optional.depend.constantpool; | |||
import java.io.DataInputStream; | |||
import java.io.IOException; | |||
/** | |||
* An entry in the constant pool. | |||
* | |||
* This class contains a represenation of the constant pool entries. It is | |||
* an abstract base class for all the different forms of constant pool entry. | |||
* An entry in the constant pool. This class contains a represenation of the | |||
* constant pool entries. It is an abstract base class for all the different | |||
* forms of constant pool entry. | |||
* | |||
* @author Conor MacNeill | |||
* @see ConstantPool | |||
*/ | |||
public abstract class ConstantPoolEntry { | |||
/** | |||
* Tag value for UTF8 entries. | |||
*/ | |||
public final static int CONSTANT_Utf8 = 1; | |||
/** Tag value for UTF8 entries. */ | |||
public final static int CONSTANT_UTF8 = 1; | |||
/** | |||
* Tag value for Integer entries. | |||
*/ | |||
public final static int CONSTANT_Integer = 3; | |||
/** Tag value for Integer entries. */ | |||
public final static int CONSTANT_INTEGER = 3; | |||
/** | |||
* Tag value for Float entries. | |||
*/ | |||
public final static int CONSTANT_Float = 4; | |||
/** Tag value for Float entries. */ | |||
public final static int CONSTANT_FLOAT = 4; | |||
/** | |||
* Tag value for Long entries. | |||
*/ | |||
public final static int CONSTANT_Long = 5; | |||
/** Tag value for Long entries. */ | |||
public final static int CONSTANT_LONG = 5; | |||
/** | |||
* Tag value for Double entries. | |||
*/ | |||
public final static int CONSTANT_Double = 6; | |||
/** Tag value for Double entries. */ | |||
public final static int CONSTANT_DOUBLE = 6; | |||
/** | |||
* Tag value for Class entries. | |||
*/ | |||
public final static int CONSTANT_Class = 7; | |||
/** Tag value for Class entries. */ | |||
public final static int CONSTANT_CLASS = 7; | |||
/** | |||
* Tag value for String entries. | |||
*/ | |||
public final static int CONSTANT_String = 8; | |||
/** Tag value for String entries. */ | |||
public final static int CONSTANT_STRING = 8; | |||
/** | |||
* Tag value for Field Reference entries. | |||
*/ | |||
public final static int CONSTANT_FieldRef = 9; | |||
/** Tag value for Field Reference entries. */ | |||
public final static int CONSTANT_FIELDREF = 9; | |||
/** | |||
* Tag value for Method Reference entries. | |||
*/ | |||
public final static int CONSTANT_MethodRef = 10; | |||
/** Tag value for Method Reference entries. */ | |||
public final static int CONSTANT_METHODREF = 10; | |||
/** | |||
* Tag value for Interface Method Reference entries. | |||
*/ | |||
public final static int CONSTANT_InterfaceMethodRef = 11; | |||
/** Tag value for Interface Method Reference entries. */ | |||
public final static int CONSTANT_INTERFACEMETHODREF = 11; | |||
/** | |||
* Tag value for Name and Type entries. | |||
*/ | |||
public final static int CONSTANT_NameAndType = 12; | |||
/** Tag value for Name and Type entries. */ | |||
public final static int CONSTANT_NAMEANDTYPE = 12; | |||
/** | |||
* This entry's tag which identifies the type of this constant pool entry. | |||
* This entry's tag which identifies the type of this constant pool | |||
* entry. | |||
*/ | |||
private int tag; | |||
@@ -141,8 +118,10 @@ public abstract class ConstantPoolEntry { | |||
/** | |||
* Initialse the constant pool entry. | |||
* | |||
* @param tagValue the tag value which identifies which type of constant pool entry this is. | |||
* @param entries the number of constant pool entry slots this entry occupies. | |||
* @param tagValue the tag value which identifies which type of constant | |||
* pool entry this is. | |||
* @param entries the number of constant pool entry slots this entry | |||
* occupies. | |||
*/ | |||
public ConstantPoolEntry(int tagValue, int entries) { | |||
tag = tagValue; | |||
@@ -151,82 +130,71 @@ public abstract class ConstantPoolEntry { | |||
} | |||
/** | |||
* Read a constant pool entry from a stream. | |||
* | |||
* This is a factory method which reads a constant pool entry | |||
* form a stream and returns the appropriate subclass for the | |||
* entry. | |||
* | |||
* @param cpStream the stream from which the constant pool entry is to be read. | |||
* Read a constant pool entry from a stream. This is a factory method | |||
* which reads a constant pool entry form a stream and returns the | |||
* appropriate subclass for the entry. | |||
* | |||
* @returns the appropriate ConstantPoolEntry subclass representing the | |||
* constant pool entry from the stream. | |||
* | |||
* @throws IOExcception if there is a problem reading the entry from the stream. | |||
* @param cpStream the stream from which the constant pool entry is to | |||
* be read. | |||
* @return the appropriate ConstantPoolEntry subclass representing the | |||
* constant pool entry from the stream. | |||
* @exception IOException if the constant pool entry cannot be read | |||
* from the stream | |||
*/ | |||
public static ConstantPoolEntry readEntry(DataInputStream cpStream) throws IOException { | |||
public static ConstantPoolEntry readEntry(DataInputStream cpStream) | |||
throws IOException { | |||
ConstantPoolEntry cpInfo = null; | |||
int cpTag = cpStream.readUnsignedByte(); | |||
switch (cpTag) { | |||
case CONSTANT_Utf8: | |||
case CONSTANT_UTF8: | |||
cpInfo = new Utf8CPInfo(); | |||
break; | |||
case CONSTANT_Integer: | |||
case CONSTANT_INTEGER: | |||
cpInfo = new IntegerCPInfo(); | |||
break; | |||
case CONSTANT_Float: | |||
case CONSTANT_FLOAT: | |||
cpInfo = new FloatCPInfo(); | |||
break; | |||
case CONSTANT_Long: | |||
case CONSTANT_LONG: | |||
cpInfo = new LongCPInfo(); | |||
break; | |||
case CONSTANT_Double: | |||
case CONSTANT_DOUBLE: | |||
cpInfo = new DoubleCPInfo(); | |||
break; | |||
case CONSTANT_Class: | |||
case CONSTANT_CLASS: | |||
cpInfo = new ClassCPInfo(); | |||
break; | |||
case CONSTANT_String: | |||
case CONSTANT_STRING: | |||
cpInfo = new StringCPInfo(); | |||
break; | |||
case CONSTANT_FieldRef: | |||
case CONSTANT_FIELDREF: | |||
cpInfo = new FieldRefCPInfo(); | |||
break; | |||
case CONSTANT_MethodRef: | |||
case CONSTANT_METHODREF: | |||
cpInfo = new MethodRefCPInfo(); | |||
break; | |||
case CONSTANT_InterfaceMethodRef: | |||
case CONSTANT_INTERFACEMETHODREF: | |||
cpInfo = new InterfaceMethodRefCPInfo(); | |||
break; | |||
case CONSTANT_NameAndType: | |||
case CONSTANT_NAMEANDTYPE: | |||
cpInfo = new NameAndTypeCPInfo(); | |||
break; | |||
default: | |||
throw new ClassFormatError("Invalid Constant Pool entry Type " + cpTag); | |||
throw new ClassFormatError("Invalid Constant Pool entry Type " | |||
+ cpTag); | |||
} | |||
cpInfo.read(cpStream); | |||
@@ -235,11 +203,10 @@ public abstract class ConstantPoolEntry { | |||
} | |||
/** | |||
* Indicates whether this entry has been resolved. | |||
* | |||
* In general a constant pool entry can reference another constant | |||
* pool entry by its index value. Resolution involves replacing this | |||
* index value with the constant pool entry at that index. | |||
* Indicates whether this entry has been resolved. In general a constant | |||
* pool entry can reference another constant pool entry by its index | |||
* value. Resolution involves replacing this index value with the | |||
* constant pool entry at that index. | |||
* | |||
* @return true if this entry has been resolved. | |||
*/ | |||
@@ -252,7 +219,7 @@ public abstract class ConstantPoolEntry { | |||
* the constant pool. | |||
* | |||
* @param constantPool the constant pool of which this entry is a member | |||
* and against which this entry is to be resolved. | |||
* and against which this entry is to be resolved. | |||
*/ | |||
public void resolve(ConstantPool constantPool) { | |||
resolved = true; | |||
@@ -261,9 +228,10 @@ public abstract class ConstantPoolEntry { | |||
/** | |||
* read a constant pool entry from a class stream. | |||
* | |||
* @param cpStream the DataInputStream which contains the constant pool entry to be read. | |||
* | |||
* @throws IOException if there is a problem reading the entry from the stream. | |||
* @param cpStream the DataInputStream which contains the constant pool | |||
* entry to be read. | |||
* @exception IOException if there is a problem reading the entry from | |||
* the stream. | |||
*/ | |||
public abstract void read(DataInputStream cpStream) throws IOException; | |||
@@ -277,10 +245,10 @@ public abstract class ConstantPoolEntry { | |||
} | |||
/** | |||
* Get the number of Constant Pool Entry slots within the constant pool occupied by this entry. | |||
* Get the number of Constant Pool Entry slots within the constant pool | |||
* occupied by this entry. | |||
* | |||
* @return the number of slots used. | |||
* | |||
*/ | |||
public final int getNumEntries() { | |||
return numEntries; | |||
@@ -56,23 +56,27 @@ package org.apache.tools.ant.taskdefs.optional.depend.constantpool; | |||
import java.io.DataInputStream; | |||
import java.io.IOException; | |||
/** | |||
* The constant pool entry subclass used to represent double constant values. | |||
* The constant pool entry subclass used to represent double constant | |||
* values. | |||
* | |||
* @author Conor MacNeill | |||
*/ | |||
public class DoubleCPInfo extends ConstantCPInfo { | |||
/** | |||
* Constructor | |||
*/ | |||
public DoubleCPInfo() { | |||
super(CONSTANT_Double, 2); | |||
super(CONSTANT_DOUBLE, 2); | |||
} | |||
/** | |||
* read a constant pool entry from a class stream. | |||
* | |||
* @param cpStream the DataInputStream which contains the constant pool entry to be read. | |||
* | |||
* @throws IOException if there is a problem reading the entry from the stream. | |||
* @param cpStream the DataInputStream which contains the constant pool | |||
* entry to be read. | |||
* @exception IOException if there is a problem reading the entry from the | |||
* stream. | |||
*/ | |||
public void read(DataInputStream cpStream) throws IOException { | |||
setValue(new Double(cpStream.readDouble())); | |||
@@ -56,33 +56,35 @@ package org.apache.tools.ant.taskdefs.optional.depend.constantpool; | |||
import java.io.DataInputStream; | |||
import java.io.IOException; | |||
/** | |||
* A FieldRef CP Info | |||
* | |||
* @author Conor MacNeill | |||
*/ | |||
public class FieldRefCPInfo extends ConstantPoolEntry { | |||
/** Name of the field's class */ | |||
private String fieldClassName; | |||
/** name of the field in that class */ | |||
private String fieldName; | |||
/** The type of the field */ | |||
private String fieldType; | |||
/** Index into the constant pool for the class */ | |||
private int classIndex; | |||
/** Index into the constant pool for the name and type entry */ | |||
private int nameAndTypeIndex; | |||
/** | |||
* Constructor. | |||
* | |||
*/ | |||
/** Constructor. */ | |||
public FieldRefCPInfo() { | |||
super(CONSTANT_FieldRef, 1); | |||
super(CONSTANT_FIELDREF, 1); | |||
} | |||
/** | |||
* read a constant pool entry from a class stream. | |||
* | |||
* @param cpStream the DataInputStream which contains the constant pool entry to be read. | |||
* | |||
* @throws IOException if there is a problem reading the entry from the stream. | |||
* @param cpStream the DataInputStream which contains the constant pool | |||
* entry to be read. | |||
* @exception IOException if there is a problem reading the entry from | |||
* the stream. | |||
*/ | |||
public void read(DataInputStream cpStream) throws IOException { | |||
classIndex = cpStream.readUnsignedShort(); | |||
@@ -94,16 +96,17 @@ public class FieldRefCPInfo extends ConstantPoolEntry { | |||
* the constant pool. | |||
* | |||
* @param constantPool the constant pool of which this entry is a member | |||
* and against which this entry is to be resolved. | |||
* and against which this entry is to be resolved. | |||
*/ | |||
public void resolve(ConstantPool constantPool) { | |||
ClassCPInfo fieldClass = (ClassCPInfo) constantPool.getEntry(classIndex); | |||
ClassCPInfo fieldClass = (ClassCPInfo)constantPool.getEntry(classIndex); | |||
fieldClass.resolve(constantPool); | |||
fieldClassName = fieldClass.getClassName(); | |||
NameAndTypeCPInfo nt = (NameAndTypeCPInfo) constantPool.getEntry(nameAndTypeIndex); | |||
NameAndTypeCPInfo nt | |||
= (NameAndTypeCPInfo)constantPool.getEntry(nameAndTypeIndex); | |||
nt.resolve(constantPool); | |||
@@ -122,22 +125,39 @@ public class FieldRefCPInfo extends ConstantPoolEntry { | |||
String value; | |||
if (isResolved()) { | |||
value = "Field : Class = " + fieldClassName + ", name = " + fieldName + ", type = " + fieldType; | |||
value = "Field : Class = " + fieldClassName + ", name = " | |||
+ fieldName + ", type = " + fieldType; | |||
} else { | |||
value = "Field : Class index = " + classIndex + ", name and type index = " + nameAndTypeIndex; | |||
value = "Field : Class index = " + classIndex | |||
+ ", name and type index = " + nameAndTypeIndex; | |||
} | |||
return value; | |||
} | |||
/** | |||
* Gets the name of the class definint the field | |||
* | |||
* @return the name of the class definint the field | |||
*/ | |||
public String getFieldClassName() { | |||
return fieldClassName; | |||
} | |||
/** | |||
* Get the name of the field | |||
* | |||
* @return the field's name | |||
*/ | |||
public String getFieldName() { | |||
return fieldName; | |||
} | |||
/** | |||
* Get the type of the field | |||
* | |||
* @return the field's type in string format | |||
*/ | |||
public String getFieldType() { | |||
return fieldType; | |||
} | |||
@@ -63,20 +63,18 @@ import java.io.IOException; | |||
*/ | |||
public class FloatCPInfo extends ConstantCPInfo { | |||
/** | |||
* Constructor. | |||
* | |||
*/ | |||
/** Constructor. */ | |||
public FloatCPInfo() { | |||
super(CONSTANT_Float, 1); | |||
super(CONSTANT_FLOAT, 1); | |||
} | |||
/** | |||
* read a constant pool entry from a class stream. | |||
* | |||
* @param cpStream the DataInputStream which contains the constant pool entry to be read. | |||
* | |||
* @throws IOException if there is a problem reading the entry from the stream. | |||
* @param cpStream the DataInputStream which contains the constant pool | |||
* entry to be read. | |||
* @exception IOException if there is a problem reading the entry from | |||
* the stream. | |||
*/ | |||
public void read(DataInputStream cpStream) throws IOException { | |||
setValue(new Float(cpStream.readFloat())); | |||
@@ -63,20 +63,18 @@ import java.io.IOException; | |||
*/ | |||
public class IntegerCPInfo extends ConstantCPInfo { | |||
/** | |||
* Constructor. | |||
* | |||
*/ | |||
/** Constructor. */ | |||
public IntegerCPInfo() { | |||
super(CONSTANT_Integer, 1); | |||
super(CONSTANT_INTEGER, 1); | |||
} | |||
/** | |||
* read a constant pool entry from a class stream. | |||
* | |||
* @param cpStream the DataInputStream which contains the constant pool entry to be read. | |||
* | |||
* @throws IOException if there is a problem reading the entry from the stream. | |||
* @param cpStream the DataInputStream which contains the constant pool | |||
* entry to be read. | |||
* @exception IOException if there is a problem reading the entry from | |||
* the stream. | |||
*/ | |||
public void read(DataInputStream cpStream) throws IOException { | |||
setValue(new Integer(cpStream.readInt())); | |||
@@ -56,34 +56,41 @@ package org.apache.tools.ant.taskdefs.optional.depend.constantpool; | |||
import java.io.DataInputStream; | |||
import java.io.IOException; | |||
/** | |||
* A InterfaceMethodRef CP Info | |||
* | |||
* | |||
* @author Conor MacNeill | |||
*/ | |||
public class InterfaceMethodRefCPInfo extends ConstantPoolEntry { | |||
/** the class name of the class defining the interafce method */ | |||
private String interfaceMethodClassName; | |||
/** the name of the interface nmethod */ | |||
private String interfaceMethodName; | |||
/** the method signature of the interface method */ | |||
private String interfaceMethodType; | |||
/** | |||
* the index into the constant pool of the class entry for the interface | |||
* class | |||
*/ | |||
private int classIndex; | |||
private int nameAndTypeIndex; | |||
/** | |||
* Constructor. | |||
* | |||
* the index into the constant pool of the name and type entry | |||
* describing the method | |||
*/ | |||
private int nameAndTypeIndex; | |||
/** Constructor. */ | |||
public InterfaceMethodRefCPInfo() { | |||
super(CONSTANT_InterfaceMethodRef, 1); | |||
super(CONSTANT_INTERFACEMETHODREF, 1); | |||
} | |||
/** | |||
* read a constant pool entry from a class stream. | |||
* | |||
* @param cpStream the DataInputStream which contains the constant pool entry to be read. | |||
* | |||
* @throws IOException if there is a problem reading the entry from the stream. | |||
* @param cpStream the DataInputStream which contains the constant pool | |||
* entry to be read. | |||
* @exception IOException if there is a problem reading the entry from | |||
* the stream. | |||
*/ | |||
public void read(DataInputStream cpStream) throws IOException { | |||
classIndex = cpStream.readUnsignedShort(); | |||
@@ -95,16 +102,18 @@ public class InterfaceMethodRefCPInfo extends ConstantPoolEntry { | |||
* the constant pool. | |||
* | |||
* @param constantPool the constant pool of which this entry is a member | |||
* and against which this entry is to be resolved. | |||
* and against which this entry is to be resolved. | |||
*/ | |||
public void resolve(ConstantPool constantPool) { | |||
ClassCPInfo interfaceMethodClass = (ClassCPInfo) constantPool.getEntry(classIndex); | |||
ClassCPInfo interfaceMethodClass | |||
= (ClassCPInfo)constantPool.getEntry(classIndex); | |||
interfaceMethodClass.resolve(constantPool); | |||
interfaceMethodClassName = interfaceMethodClass.getClassName(); | |||
NameAndTypeCPInfo nt = (NameAndTypeCPInfo) constantPool.getEntry(nameAndTypeIndex); | |||
NameAndTypeCPInfo nt | |||
= (NameAndTypeCPInfo)constantPool.getEntry(nameAndTypeIndex); | |||
nt.resolve(constantPool); | |||
@@ -123,23 +132,40 @@ public class InterfaceMethodRefCPInfo extends ConstantPoolEntry { | |||
String value; | |||
if (isResolved()) { | |||
value = "InterfaceMethod : Class = " + interfaceMethodClassName + ", name = " + interfaceMethodName + ", type = " | |||
+ interfaceMethodType; | |||
value = "InterfaceMethod : Class = " + interfaceMethodClassName | |||
+ ", name = " + interfaceMethodName + ", type = " | |||
+ interfaceMethodType; | |||
} else { | |||
value = "InterfaceMethod : Class index = " + classIndex + ", name and type index = " + nameAndTypeIndex; | |||
value = "InterfaceMethod : Class index = " + classIndex | |||
+ ", name and type index = " + nameAndTypeIndex; | |||
} | |||
return value; | |||
} | |||
/** | |||
* Gets the name of the class defining the interface method | |||
* | |||
* @return the name of the class defining the interface method | |||
*/ | |||
public String getInterfaceMethodClassName() { | |||
return interfaceMethodClassName; | |||
} | |||
/** | |||
* Get the name of the interface method | |||
* | |||
* @return the name of the interface method | |||
*/ | |||
public String getInterfaceMethodName() { | |||
return interfaceMethodName; | |||
} | |||
/** | |||
* Gets the type of the interface method | |||
* | |||
* @return the interface method's type signature | |||
*/ | |||
public String getInterfaceMethodType() { | |||
return interfaceMethodType; | |||
} | |||
@@ -63,20 +63,18 @@ import java.io.IOException; | |||
*/ | |||
public class LongCPInfo extends ConstantCPInfo { | |||
/** | |||
* Constructor. | |||
* | |||
*/ | |||
/** Constructor. */ | |||
public LongCPInfo() { | |||
super(CONSTANT_Long, 2); | |||
super(CONSTANT_LONG, 2); | |||
} | |||
/** | |||
* read a constant pool entry from a class stream. | |||
* | |||
* @param cpStream the DataInputStream which contains the constant pool entry to be read. | |||
* | |||
* @throws IOException if there is a problem reading the entry from the stream. | |||
* @param cpStream the DataInputStream which contains the constant pool | |||
* entry to be read. | |||
* @exception IOException if there is a problem reading the entry from | |||
* the stream. | |||
*/ | |||
public void read(DataInputStream cpStream) throws IOException { | |||
setValue(new Long(cpStream.readLong())); | |||
@@ -56,33 +56,38 @@ package org.apache.tools.ant.taskdefs.optional.depend.constantpool; | |||
import java.io.DataInputStream; | |||
import java.io.IOException; | |||
/** | |||
* A MethodRef CP Info | |||
* | |||
* @author Conor MacNeill | |||
*/ | |||
public class MethodRefCPInfo extends ConstantPoolEntry { | |||
/** the name of the class defining this method */ | |||
private String methodClassName; | |||
/** the name of the method */ | |||
private String methodName; | |||
/** the method's type descriptor */ | |||
private String methodType; | |||
/** The index into the constant pool which defines the class of this method. */ | |||
private int classIndex; | |||
private int nameAndTypeIndex; | |||
/** | |||
* Constructor. | |||
* | |||
* the index into the constant pool which defined the name and type | |||
* signature of the method | |||
*/ | |||
private int nameAndTypeIndex; | |||
/** Constructor. */ | |||
public MethodRefCPInfo() { | |||
super(CONSTANT_MethodRef, 1); | |||
super(CONSTANT_METHODREF, 1); | |||
} | |||
/** | |||
* read a constant pool entry from a class stream. | |||
* | |||
* @param cpStream the DataInputStream which contains the constant pool entry to be read. | |||
* | |||
* @throws IOException if there is a problem reading the entry from the stream. | |||
* @param cpStream the DataInputStream which contains the constant pool | |||
* entry to be read. | |||
* @exception IOException if there is a problem reading the entry from | |||
* the stream. | |||
*/ | |||
public void read(DataInputStream cpStream) throws IOException { | |||
classIndex = cpStream.readUnsignedShort(); | |||
@@ -98,9 +103,11 @@ public class MethodRefCPInfo extends ConstantPoolEntry { | |||
String value; | |||
if (isResolved()) { | |||
value = "Method : Class = " + methodClassName + ", name = " + methodName + ", type = " + methodType; | |||
value = "Method : Class = " + methodClassName + ", name = " | |||
+ methodName + ", type = " + methodType; | |||
} else { | |||
value = "Method : Class index = " + classIndex + ", name and type index = " + nameAndTypeIndex; | |||
value = "Method : Class index = " + classIndex | |||
+ ", name and type index = " + nameAndTypeIndex; | |||
} | |||
return value; | |||
@@ -111,16 +118,18 @@ public class MethodRefCPInfo extends ConstantPoolEntry { | |||
* the constant pool. | |||
* | |||
* @param constantPool the constant pool of which this entry is a member | |||
* and against which this entry is to be resolved. | |||
* and against which this entry is to be resolved. | |||
*/ | |||
public void resolve(ConstantPool constantPool) { | |||
ClassCPInfo methodClass = (ClassCPInfo) constantPool.getEntry(classIndex); | |||
ClassCPInfo methodClass | |||
= (ClassCPInfo)constantPool.getEntry(classIndex); | |||
methodClass.resolve(constantPool); | |||
methodClassName = methodClass.getClassName(); | |||
NameAndTypeCPInfo nt = (NameAndTypeCPInfo) constantPool.getEntry(nameAndTypeIndex); | |||
NameAndTypeCPInfo nt | |||
= (NameAndTypeCPInfo)constantPool.getEntry(nameAndTypeIndex); | |||
nt.resolve(constantPool); | |||
@@ -130,14 +139,29 @@ public class MethodRefCPInfo extends ConstantPoolEntry { | |||
super.resolve(constantPool); | |||
} | |||
/** | |||
* Get the name of the class defining the method | |||
* | |||
* @return the name of the class defining this method | |||
*/ | |||
public String getMethodClassName() { | |||
return methodClassName; | |||
} | |||
/** | |||
* Get the name of the method. | |||
* | |||
* @return the name of the method. | |||
*/ | |||
public String getMethodName() { | |||
return methodName; | |||
} | |||
/** | |||
* Get the type signature of the method. | |||
* | |||
* @return the type signature of the method. | |||
*/ | |||
public String getMethodType() { | |||
return methodType; | |||
} | |||
@@ -56,7 +56,6 @@ package org.apache.tools.ant.taskdefs.optional.depend.constantpool; | |||
import java.io.DataInputStream; | |||
import java.io.IOException; | |||
/** | |||
* A NameAndType CP Info | |||
* | |||
@@ -64,20 +63,18 @@ import java.io.IOException; | |||
*/ | |||
public class NameAndTypeCPInfo extends ConstantPoolEntry { | |||
/** | |||
* Constructor. | |||
* | |||
*/ | |||
/** Constructor. */ | |||
public NameAndTypeCPInfo() { | |||
super(CONSTANT_NameAndType, 1); | |||
super(CONSTANT_NAMEANDTYPE, 1); | |||
} | |||
/** | |||
* read a constant pool entry from a class stream. | |||
* | |||
* @param cpStream the DataInputStream which contains the constant pool entry to be read. | |||
* | |||
* @throws IOException if there is a problem reading the entry from the stream. | |||
* @param cpStream the DataInputStream which contains the constant pool | |||
* entry to be read. | |||
* @exception IOException if there is a problem reading the entry from | |||
* the stream. | |||
*/ | |||
public void read(DataInputStream cpStream) throws IOException { | |||
nameIndex = cpStream.readUnsignedShort(); | |||
@@ -95,7 +92,8 @@ public class NameAndTypeCPInfo extends ConstantPoolEntry { | |||
if (isResolved()) { | |||
value = "Name = " + name + ", type = " + type; | |||
} else { | |||
value = "Name index = " + nameIndex + ", descriptor index = " + descriptorIndex; | |||
value = "Name index = " + nameIndex | |||
+ ", descriptor index = " + descriptorIndex; | |||
} | |||
return value; | |||
@@ -106,26 +104,46 @@ public class NameAndTypeCPInfo extends ConstantPoolEntry { | |||
* the constant pool. | |||
* | |||
* @param constantPool the constant pool of which this entry is a member | |||
* and against which this entry is to be resolved. | |||
* and against which this entry is to be resolved. | |||
*/ | |||
public void resolve(ConstantPool constantPool) { | |||
name = ((Utf8CPInfo) constantPool.getEntry(nameIndex)).getValue(); | |||
type = ((Utf8CPInfo) constantPool.getEntry(descriptorIndex)).getValue(); | |||
name = ((Utf8CPInfo)constantPool.getEntry(nameIndex)).getValue(); | |||
type = ((Utf8CPInfo)constantPool.getEntry(descriptorIndex)).getValue(); | |||
super.resolve(constantPool); | |||
} | |||
/** | |||
* Get the name component of this entry | |||
* | |||
* @return the name of this name and type entry | |||
*/ | |||
public String getName() { | |||
return name; | |||
} | |||
/** | |||
* Get the type signature of this entry | |||
* | |||
* @return the type signature of this entry | |||
*/ | |||
public String getType() { | |||
return type; | |||
} | |||
/** the name component of this entry */ | |||
private String name; | |||
/** the type component of this entry */ | |||
private String type; | |||
/** | |||
* the index into the constant pool at which the name component's string | |||
* value is stored | |||
*/ | |||
private int nameIndex; | |||
/** | |||
* the index into the constant pool where the type descriptor string is | |||
* stored. | |||
*/ | |||
private int descriptorIndex; | |||
} | |||
@@ -56,31 +56,26 @@ package org.apache.tools.ant.taskdefs.optional.depend.constantpool; | |||
import java.io.DataInputStream; | |||
import java.io.IOException; | |||
/** | |||
* A String Constant Pool Entry. | |||
* | |||
* The String info contains an index into the constant pool where | |||
* a UTF8 string is stored. | |||
* A String Constant Pool Entry. The String info contains an index into the | |||
* constant pool where a UTF8 string is stored. | |||
* | |||
* @author Conor MacNeill | |||
*/ | |||
public class StringCPInfo extends ConstantCPInfo { | |||
/** | |||
* Constructor. | |||
* | |||
*/ | |||
/** Constructor. */ | |||
public StringCPInfo() { | |||
super(CONSTANT_String, 1); | |||
super(CONSTANT_STRING, 1); | |||
} | |||
/** | |||
* read a constant pool entry from a class stream. | |||
* | |||
* @param cpStream the DataInputStream which contains the constant pool entry to be read. | |||
* | |||
* @throws IOException if there is a problem reading the entry from the stream. | |||
* @param cpStream the DataInputStream which contains the constant pool | |||
* entry to be read. | |||
* @exception IOException if there is a problem reading the entry from | |||
* the stream. | |||
*/ | |||
public void read(DataInputStream cpStream) throws IOException { | |||
index = cpStream.readUnsignedShort(); | |||
@@ -94,7 +89,8 @@ public class StringCPInfo extends ConstantCPInfo { | |||
* @return the string representation of this constant pool entry. | |||
*/ | |||
public String toString() { | |||
return "String Constant Pool Entry for " + getValue() + "[" + index + "]"; | |||
return "String Constant Pool Entry for " | |||
+ getValue() + "[" + index + "]"; | |||
} | |||
/** | |||
@@ -102,13 +98,14 @@ public class StringCPInfo extends ConstantCPInfo { | |||
* the constant pool. | |||
* | |||
* @param constantPool the constant pool of which this entry is a member | |||
* and against which this entry is to be resolved. | |||
* and against which this entry is to be resolved. | |||
*/ | |||
public void resolve(ConstantPool constantPool) { | |||
setValue(((Utf8CPInfo) constantPool.getEntry(index)).getValue()); | |||
setValue(((Utf8CPInfo)constantPool.getEntry(index)).getValue()); | |||
super.resolve(constantPool); | |||
} | |||
/** the index into the constant pool containing the string's content */ | |||
private int index; | |||
} | |||
@@ -56,29 +56,27 @@ package org.apache.tools.ant.taskdefs.optional.depend.constantpool; | |||
import java.io.DataInputStream; | |||
import java.io.IOException; | |||
/** | |||
* A UTF8 Constant Pool Entry. | |||
* | |||
* @author Conor MacNeill | |||
*/ | |||
public class Utf8CPInfo extends ConstantPoolEntry { | |||
/** The String value of the UTF-8 entry */ | |||
private String value; | |||
/** | |||
* Constructor. | |||
* | |||
*/ | |||
/** Constructor. */ | |||
public Utf8CPInfo() { | |||
super(CONSTANT_Utf8, 1); | |||
super(CONSTANT_UTF8, 1); | |||
} | |||
/** | |||
* read a constant pool entry from a class stream. | |||
* | |||
* @param cpStream the DataInputStream which contains the constant pool entry to be read. | |||
* | |||
* @throws IOException if there is a problem reading the entry from the stream. | |||
* @param cpStream the DataInputStream which contains the constant pool | |||
* entry to be read. | |||
* @exception IOException if there is a problem reading the entry from | |||
* the stream. | |||
*/ | |||
public void read(DataInputStream cpStream) throws IOException { | |||
value = cpStream.readUTF(); | |||
@@ -93,6 +91,11 @@ public class Utf8CPInfo extends ConstantPoolEntry { | |||
return "UTF8 Value = " + value; | |||
} | |||
/** | |||
* Get the string value of the UTF-8 entry | |||
* | |||
* @return the UTF-8 value as a Java string | |||
*/ | |||
public String getValue() { | |||
return value; | |||
} | |||