jakarta-bcel-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tcu...@apache.org
Subject svn commit: r897695 - /jakarta/bcel/trunk/src/main/java/org/apache/bcel/util/ClassPath.java
Date Sun, 10 Jan 2010 20:06:47 GMT
Author: tcurdt
Date: Sun Jan 10 20:06:47 2010
New Revision: 897695

URL: http://svn.apache.org/viewvc?rev=897695&view=rev
Log:
hierarchical ClassPath support

https://issues.apache.org/bugzilla/show_bug.cgi?id=38426


Modified:
    jakarta/bcel/trunk/src/main/java/org/apache/bcel/util/ClassPath.java

Modified: jakarta/bcel/trunk/src/main/java/org/apache/bcel/util/ClassPath.java
URL: http://svn.apache.org/viewvc/jakarta/bcel/trunk/src/main/java/org/apache/bcel/util/ClassPath.java?rev=897695&r1=897694&r2=897695&view=diff
==============================================================================
--- jakarta/bcel/trunk/src/main/java/org/apache/bcel/util/ClassPath.java (original)
+++ jakarta/bcel/trunk/src/main/java/org/apache/bcel/util/ClassPath.java Sun Jan 10 20:06:47
2010
@@ -47,7 +47,12 @@
     public static final ClassPath SYSTEM_CLASS_PATH = new ClassPath();
     private PathEntry[] paths;
     private String class_path;
+    private ClassPath parent;
 
+    public ClassPath(ClassPath parent, String class_path) {
+        this(class_path);
+        this.parent = parent;
+    }
 
     /**
      * Search for classes in given path.
@@ -90,18 +95,24 @@
     /** @return used class path string
      */
     public String toString() {
+        if (parent != null) {
+            return parent.toString() + File.pathSeparator + class_path;
+        }
         return class_path;
     }
 
-
     public int hashCode() {
+        if (parent != null) {
+            return class_path.hashCode() + parent.hashCode();            
+        }
         return class_path.hashCode();
     }
 
 
     public boolean equals( Object o ) {
         if (o instanceof ClassPath) {
-            return class_path.equals(((ClassPath) o).class_path);
+            ClassPath cp = (ClassPath)o;
+            return class_path.toString().equals(cp.toString());
         }
         return false;
     }
@@ -240,14 +251,37 @@
      */
     public ClassFile getClassFile( String name, String suffix ) throws IOException {
         for (int i = 0; i < paths.length; i++) {
-            ClassFile cf;
-            if ((cf = paths[i].getClassFile(name, suffix)) != null) {
+            ClassFile cf = null;
+
+            if(parent != null) {
+                cf = parent.getClassFileInternal(name, suffix);
+            }
+            
+            if(cf == null) {
+                cf = getClassFileInternal(name,suffix);
+            }
+            
+            if(cf != null) {
                 return cf;
             }
         }
+
         throw new IOException("Couldn't find: " + name + suffix);
     }
 
+    private ClassFile getClassFileInternal(String name, String suffix) throws IOException
{
+
+      for(int i=0; i < paths.length; i++) {
+          ClassFile cf = paths[i].getClassFile(name, suffix);
+          
+          if(cf != null) {
+              return cf;
+          }
+      }
+
+      return null;
+   }
+
 
     /**
      * @param name fully qualified class name, e.g. java.lang.String



---------------------------------------------------------------------
To unsubscribe, e-mail: bcel-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: bcel-dev-help@jakarta.apache.org


Mime
View raw message