Author: jgbutler Date: Mon Jun 22 14:59:46 2009 New Revision: 787263 URL: http://svn.apache.org/viewvc?rev=787263&view=rev Log: [Ibator] more updates to the Java type parser
Modified: ibatis/trunk/java/tools/ibator/core/build/version.properties ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/api/dom/java/FullyQualifiedJavaType.java ibatis/trunk/java/tools/ibator/core/test/org/apache/ibatis/ibator/api/dom/java/FullyQualifiedJavaTypeTests.java Modified: ibatis/trunk/java/tools/ibator/core/build/version.properties URL: http://svn.apache.org/viewvc/ibatis/trunk/java/tools/ibator/core/build/version.properties?rev=787263&r1=787262&r2=787263&view=diff ============================================================================== --- ibatis/trunk/java/tools/ibator/core/build/version.properties (original) +++ ibatis/trunk/java/tools/ibator/core/build/version.properties Mon Jun 22 14:59:46 2009 @@ -1,4 +1,4 @@ #Ibator build version info -#Thu Jun 18 16:12:32 CDT 2009 +#Fri Jun 19 11:52:10 CDT 2009 version=1.2.2 -buildNum=752 +buildNum=753 Modified: ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/api/dom/java/FullyQualifiedJavaType.java URL: http://svn.apache.org/viewvc/ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/api/dom/java/FullyQualifiedJavaType.java?rev=787263&r1=787262&r2=787263&view=diff ============================================================================== --- ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/api/dom/java/FullyQualifiedJavaType.java (original) +++ ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/api/dom/java/FullyQualifiedJavaType.java Mon Jun 22 14:59:46 2009 @@ -93,20 +93,21 @@ } } else { sb.append(baseQualifiedName); - if (typeArguments.size() > 0) { - boolean first = true; - sb.append('<'); - for (FullyQualifiedJavaType fqjt : typeArguments) { - if (first) { - first = false; - } else { - sb.append(", "); //$NON-NLS-1$ - } - sb.append(fqjt.getFullyQualifiedName()); - + } + + if (typeArguments.size() > 0) { + boolean first = true; + sb.append('<'); + for (FullyQualifiedJavaType fqjt : typeArguments) { + if (first) { + first = false; + } else { + sb.append(", "); //$NON-NLS-1$ } - sb.append('>'); + sb.append(fqjt.getFullyQualifiedName()); + } + sb.append('>'); } return sb.toString(); @@ -154,20 +155,21 @@ } } else { sb.append(baseShortName); - if (typeArguments.size() > 0) { - boolean first = true; - sb.append('<'); - for (FullyQualifiedJavaType fqjt : typeArguments) { - if (first) { - first = false; - } else { - sb.append(", "); //$NON-NLS-1$ - } - sb.append(fqjt.getShortName()); - + } + + if (typeArguments.size() > 0) { + boolean first = true; + sb.append('<'); + for (FullyQualifiedJavaType fqjt : typeArguments) { + if (first) { + first = false; + } else { + sb.append(", "); //$NON-NLS-1$ } - sb.append('>'); + sb.append(fqjt.getShortName()); + } + sb.append('>'); } return sb.toString(); @@ -306,17 +308,31 @@ } private void parse(String fullTypeSpecification) { - int index = fullTypeSpecification.indexOf('<'); - if (index == -1) { - index = fullTypeSpecification.indexOf('?'); + String spec = fullTypeSpecification.trim(); + + if (spec.startsWith("?")) { + wildcardType = true; + spec = spec.substring(1).trim(); + if (spec.startsWith("extends ")) { + boundedWildcard = true; + extendsBoundedWildcard = true; + spec = spec.substring(8); + } else if (spec.startsWith("super ")) { + boundedWildcard = true; + extendsBoundedWildcard = false; + spec = spec.substring(6); + } else { + boundedWildcard = false; + } + parse(spec); + } else { + int index = fullTypeSpecification.indexOf('<'); if (index == -1) { simpleParse(fullTypeSpecification); } else { - wildCardParse(fullTypeSpecification); + simpleParse(fullTypeSpecification.substring(0, index)); + genericParse(fullTypeSpecification.substring(index)); } - } else { - simpleParse(fullTypeSpecification.substring(0, index)); - genericParse(fullTypeSpecification.substring(index)); } } @@ -406,27 +422,4 @@ typeArguments.add(new FullyQualifiedJavaType(finalType)); } } - - private void wildCardParse(String wildCardSpecification) { - StringTokenizer st = new StringTokenizer(wildCardSpecification, " "); //$NON-NLS-1$ - int tokenCount = st.countTokens(); - if (tokenCount != 1 && tokenCount != 3) { - throw new RuntimeException(Messages.getString("RuntimeError.22", wildCardSpecification)); //$NON-NLS-1$ - } - - String token = st.nextToken(); - if (!"?".equals(token)) { - throw new RuntimeException(Messages.getString("RuntimeError.22", wildCardSpecification)); //$NON-NLS-1$ - } - - wildcardType = true; - - if (tokenCount == 1) { - boundedWildcard = false; - } else { - boundedWildcard = true; - extendsBoundedWildcard = "extends".equals(st.nextToken()); - simpleParse(st.nextToken()); - } - } } Modified: ibatis/trunk/java/tools/ibator/core/test/org/apache/ibatis/ibator/api/dom/java/FullyQualifiedJavaTypeTests.java URL: http://svn.apache.org/viewvc/ibatis/trunk/java/tools/ibator/core/test/org/apache/ibatis/ibator/api/dom/java/FullyQualifiedJavaTypeTests.java?rev=787263&r1=787262&r2=787263&view=diff ============================================================================== --- ibatis/trunk/java/tools/ibator/core/test/org/apache/ibatis/ibator/api/dom/java/FullyQualifiedJavaTypeTests.java (original) +++ ibatis/trunk/java/tools/ibator/core/test/org/apache/ibatis/ibator/api/dom/java/FullyQualifiedJavaTypeTests.java Mon Jun 22 14:59:46 2009 @@ -123,4 +123,37 @@ assertEquals("java.util", fqjt.getPackageName()); //$NON-NLS-1$ assertEquals(1, fqjt.getImportList().size()); } + + @Test + public void testWildcardType3() { + FullyQualifiedJavaType fqjt = + new FullyQualifiedJavaType("java.util.Map<? extends java.util.List<?>, ?>"); + assertTrue(fqjt.isExplicitlyImported()); + assertEquals("Map<? extends List<?>, ?>", fqjt.getShortName()); //$NON-NLS-1$ + assertEquals("java.util.Map<? extends java.util.List<?>, ?>", fqjt.getFullyQualifiedName()); //$NON-NLS-1$ + assertEquals("java.util", fqjt.getPackageName()); //$NON-NLS-1$ + assertEquals(2, fqjt.getImportList().size()); + } + + @Test + public void testWildcardType4() { + FullyQualifiedJavaType fqjt = + new FullyQualifiedJavaType("java.util.Map<?, ?>"); + assertTrue(fqjt.isExplicitlyImported()); + assertEquals("Map<?, ?>", fqjt.getShortName()); //$NON-NLS-1$ + assertEquals("java.util.Map<?, ?>", fqjt.getFullyQualifiedName()); //$NON-NLS-1$ + assertEquals("java.util", fqjt.getPackageName()); //$NON-NLS-1$ + assertEquals(1, fqjt.getImportList().size()); + } + + @Test + public void testWildcardType5() { + FullyQualifiedJavaType fqjt = + new FullyQualifiedJavaType("java.util.List<? extends java.util.Map<? super java.lang.Object, ?>>"); + assertTrue(fqjt.isExplicitlyImported()); + assertEquals("List<? extends Map<? super Object, ?>>", fqjt.getShortName()); //$NON-NLS-1$ + assertEquals("java.util.List<? extends java.util.Map<? super java.lang.Object, ?>>", fqjt.getFullyQualifiedName()); //$NON-NLS-1$ + assertEquals("java.util", fqjt.getPackageName()); //$NON-NLS-1$ + assertEquals(2, fqjt.getImportList().size()); + } }