Author: tchemit Date: 2011-05-15 15:20:25 +0200 (Sun, 15 May 2011) New Revision: 2283 Url: http://nuiton.org/repositories/revision/jaxx/2283 Log: Anomalie #1442: Non public classes make generation fails Added: trunk/jaxx-compiler/src/test/java/jaxx/compiler/reflect/MyChildClass2.java Modified: trunk/jaxx-compiler/src/main/java/jaxx/compiler/reflect/resolvers/ClassDescriptorResolverFromJavaFile.java trunk/jaxx-compiler/src/test/java/jaxx/compiler/reflect/MyChildClass.java trunk/jaxx-compiler/src/test/java/jaxx/compiler/reflect/resolvers/ClassDescriptorResolverFromJavaFileTest.java Modified: trunk/jaxx-compiler/src/main/java/jaxx/compiler/reflect/resolvers/ClassDescriptorResolverFromJavaFile.java =================================================================== --- trunk/jaxx-compiler/src/main/java/jaxx/compiler/reflect/resolvers/ClassDescriptorResolverFromJavaFile.java 2011-05-15 12:43:38 UTC (rev 2282) +++ trunk/jaxx-compiler/src/main/java/jaxx/compiler/reflect/resolvers/ClassDescriptorResolverFromJavaFile.java 2011-05-15 13:20:25 UTC (rev 2283) @@ -211,6 +211,16 @@ public static final String[] EMPTY_STRING_ARRAY = new String[0]; + + /** + * To test if a compilation unit was already parsed. If so, then stop + * parsing the java file : one parsing can only give one class + * descriptor. + * + * @since 2.4.2 + */ + private boolean firstTypeScanned; + protected JavaFileParser(ClassLoader classLoader) { //FIXME-TC-20100504 : shoudl remove this to make the parser free of jaxx :) // We could imagine just to offers to the parser a list of namespaces @@ -227,6 +237,10 @@ public void doParse(String className, Reader src) throws ClassNotFoundException { + + // reset this internal state + firstTypeScanned = false; + try { JavaParser p = new JavaParser(src); p.CompilationUnit(); @@ -281,6 +295,15 @@ } private void scanCompilationUnitChild(SimpleNode child) { + if (firstTypeScanned) { + + // already scan the first class of the java file + // for the moment, can not do anything else... + if (log.isWarnEnabled()) { + log.warn("There is more than one type in current file, skip next type..."); + } + return; + } int nodeType = child.getId(); switch (nodeType) { case JavaParserTreeConstants.JJTPACKAGEDECLARATION: @@ -321,6 +344,7 @@ // scans the main ClassOrInterfaceDeclaration private void scanClass(SimpleNode node) { + firstTypeScanned = true; // boolean isInterface = node.firstToken.image.equals("interface"); className = node.firstToken.next.image; if (packageName != null) { Modified: trunk/jaxx-compiler/src/test/java/jaxx/compiler/reflect/MyChildClass.java =================================================================== --- trunk/jaxx-compiler/src/test/java/jaxx/compiler/reflect/MyChildClass.java 2011-05-15 12:43:38 UTC (rev 2282) +++ trunk/jaxx-compiler/src/test/java/jaxx/compiler/reflect/MyChildClass.java 2011-05-15 13:20:25 UTC (rev 2283) @@ -5,7 +5,7 @@ * $Id$ * $HeadURL$ * %% - * Copyright (C) 2008 - 2011 CodeLutin + * Copyright (C) 2008 - 2011 CodeLutin, Tony Chemit * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as Added: trunk/jaxx-compiler/src/test/java/jaxx/compiler/reflect/MyChildClass2.java =================================================================== --- trunk/jaxx-compiler/src/test/java/jaxx/compiler/reflect/MyChildClass2.java (rev 0) +++ trunk/jaxx-compiler/src/test/java/jaxx/compiler/reflect/MyChildClass2.java 2011-05-15 13:20:25 UTC (rev 2283) @@ -0,0 +1,40 @@ +/* + * #%L + * JAXX :: Compiler + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2008 - 2011 CodeLutin, Tony Chemit + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * #L% + */ +package jaxx.compiler.reflect; + +/** + * To test the bug : http://nuiton.org/issues/show/1442 + * + * @author tchemit <chemit@codelutin.com> + * @since 2.4.2 + */ +public class MyChildClass2 extends MyClass { + private static final long serialVersionUID = 1L; +} + +// This class will not be scanned! +class MyPackageClass { + +} Property changes on: trunk/jaxx-compiler/src/test/java/jaxx/compiler/reflect/MyChildClass2.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Modified: trunk/jaxx-compiler/src/test/java/jaxx/compiler/reflect/resolvers/ClassDescriptorResolverFromJavaFileTest.java =================================================================== --- trunk/jaxx-compiler/src/test/java/jaxx/compiler/reflect/resolvers/ClassDescriptorResolverFromJavaFileTest.java 2011-05-15 12:43:38 UTC (rev 2282) +++ trunk/jaxx-compiler/src/test/java/jaxx/compiler/reflect/resolvers/ClassDescriptorResolverFromJavaFileTest.java 2011-05-15 13:20:25 UTC (rev 2283) @@ -29,6 +29,7 @@ import jaxx.compiler.reflect.FieldDescriptor; import jaxx.compiler.reflect.MyAbstractClass; import jaxx.compiler.reflect.MyChildClass; +import jaxx.compiler.reflect.MyChildClass2; import jaxx.compiler.reflect.MyClass; import jaxx.compiler.reflect.MyEnum; import jaxx.compiler.reflect.MyInterface; @@ -215,7 +216,6 @@ String.class, Modifier.PUBLIC ); - } @Test @@ -270,6 +270,50 @@ } + @Test + public void parseMyChildClass2() throws Exception { + + ClassDescriptor descriptor = getDescriptor(MyChildClass2.class); + + assertInterfaces(descriptor, MyChildClass2.class.getInterfaces()); + assertSuperClass(descriptor, MyClass.class); + assertIsAssignableFrom(descriptor, + Serializable.class, + MyInterface.class, + MyAbstractClass.class, + MyClass.class + ); + + assertDeclaredField( + descriptor, + "serialVersionUID", + long.class, + Modifier.PRIVATE | Modifier.FINAL | Modifier.STATIC + ); + + assertDeclaredField( + descriptor, + "myPrivateStringField", + String.class, + Modifier.PRIVATE | Modifier.FINAL + ); + + assertDeclaredField( + descriptor, + "myProtectedStringField", + String.class, + Modifier.PROTECTED + ); + + assertField( + descriptor, + "myPublicStringField", + String.class, + Modifier.PUBLIC + ); + + } + public static void assertField(ClassDescriptor descriptor, String fieldName, Class<?> fieldType,