openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ppod...@apache.org
Subject svn commit: r835756 - /openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/util/SourceCode.java
Date Fri, 13 Nov 2009 06:32:43 GMT
Author: ppoddar
Date: Fri Nov 13 06:32:43 2009
New Revision: 835756

URL: http://svn.apache.org/viewvc?rev=835756&view=rev
Log:
OPENJPA-1386: Support field types that can hide each other

Modified:
    openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/util/SourceCode.java

Modified: openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/util/SourceCode.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/util/SourceCode.java?rev=835756&r1=835755&r2=835756&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/util/SourceCode.java
(original)
+++ openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/util/SourceCode.java
Fri Nov 13 06:32:43 2009
@@ -99,6 +99,12 @@
 		String pkgName = name.getPackageName();
 		if ("java.lang".equals(pkgName))
 			return false;
+		for (Import i : imports) {
+		    if (i.getClassName().hides(name)) {
+		        i.getClassName().useFullName();
+		        name.useFullName();
+		    }
+		}
 		return imports.add(new Import(name));
 	}
 	
@@ -584,6 +590,8 @@
 		}
 		
 		public void write(PrintWriter out, int tab) {
+		    if (name.usingFullName())
+		        return;
 		    String pkg = name.getPackageName();
 		    if (pkg.length() == 0 || pkg.equals(getPackage().name))
 		        return;
@@ -597,6 +605,10 @@
 			}
 			return false;
 		}
+		
+		ClassName getClassName() {
+		    return name;
+		}
 	}
 	
 	/**
@@ -729,6 +741,7 @@
         public final String simpleName;
         public final String pkgName;
         private String  arrayMarker = BLANK;
+        private boolean useFullName = false;
         
 	    ClassName(String name) {
 	    	while (isArray(name)) {
@@ -769,10 +782,10 @@
 	    }
 	    
 	    /**
-	     * Gets the simple name of this receiver.
+	     * Gets the full or simple name of this receiver based on useFullName flag.
 	     */
 	    public String toString() {
-	        return getSimpleName();
+	        return (useFullName ? fullName : simpleName) + arrayMarker;
 	    }
 	    
 	    /**
@@ -806,6 +819,19 @@
 	    		name.substring(0, name.length()-"[]".length());
 	    }
 	    
+	    boolean hides(ClassName other) {
+	        return this.getSimpleName().equals(other.getSimpleName())
+	            && !this.fullName.equals(other.fullName);
+	    }
+	    
+	    void useFullName() {
+	        useFullName = true;
+	    }
+	    
+	    boolean usingFullName() {
+	        return useFullName;
+	    }
+	    
 	}
 	
 	static {



Mime
View raw message