Author: tchemit Date: 2011-03-18 12:18:55 +0100 (Fri, 18 Mar 2011) New Revision: 2242 Url: http://nuiton.org/repositories/revision/jaxx/2242 Log: Anomalie #1406: NPE when cloning method with arguments Evolution #1407: Can simplify body code of method while cloning it Modified: trunk/jaxx-compiler/src/main/java/jaxx/compiler/java/JavaElementFactory.java trunk/jaxx-compiler/src/main/java/jaxx/compiler/java/JavaFile.java trunk/jaxx-compiler/src/main/java/jaxx/compiler/java/JavaMethod.java Modified: trunk/jaxx-compiler/src/main/java/jaxx/compiler/java/JavaElementFactory.java =================================================================== --- trunk/jaxx-compiler/src/main/java/jaxx/compiler/java/JavaElementFactory.java 2011-03-18 09:33:24 UTC (rev 2241) +++ trunk/jaxx-compiler/src/main/java/jaxx/compiler/java/JavaElementFactory.java 2011-03-18 11:18:55 UTC (rev 2242) @@ -158,9 +158,11 @@ String[] exceptions = new String[incomingExceptions.length]; System.arraycopy(incomingExceptions, 0, exceptions, 0, exceptions.length); - JavaArgument[] arguments = new JavaArgument[method.getArguments().length]; - for (int i = 0; i < arguments.length; i++) { - JavaArgument argument = arguments[i]; + JavaArgument[] oldArguments = method.getArguments(); + int nbArguments = oldArguments.length; + JavaArgument[] arguments = new JavaArgument[nbArguments]; + for (int i = 0; i < nbArguments; i++) { + JavaArgument argument = oldArguments[i]; arguments[i] = cloneArgument(argument); } return newMethod( Modified: trunk/jaxx-compiler/src/main/java/jaxx/compiler/java/JavaFile.java =================================================================== --- trunk/jaxx-compiler/src/main/java/jaxx/compiler/java/JavaFile.java 2011-03-18 09:33:24 UTC (rev 2241) +++ trunk/jaxx-compiler/src/main/java/jaxx/compiler/java/JavaFile.java 2011-03-18 11:18:55 UTC (rev 2242) @@ -143,6 +143,14 @@ return importManager; } + public String getImportedType(Class<?> type) { + return getImportManager().getType(type); + } + + public String getImportedType(String type) { + return getImportManager().getType(type); + } + public String[] getImports() { List<String> result = new ArrayList<String>(imports); Collections.sort(result); @@ -253,7 +261,8 @@ String type = importManager.getType(anInterface); anInterface = type; } catch (Exception e) { - log.error("Could not determine simple name of interface " + anInterface); + log.error("Could not determine simple name of interface " + + anInterface); } simpleInterfaces.add(anInterface); } @@ -270,7 +279,8 @@ String type = importManager.getReturnType(returnType); method.setReturnType(type); } catch (Exception e) { - log.error("Could not determine simple name of return type " + returnType + " for method " + method.getName()); + log.error("Could not determine simple name of return type " + + returnType + " for method " + method.getName()); } for (JavaArgument argument : method.getArguments()) { String argumentType = argument.getType(); @@ -278,7 +288,9 @@ String type = importManager.getType(argumentType); argument.setType(type); } catch (Exception e) { - log.error("Could not determine simple name of argument type " + argumentType + " of argument " + argument.getName() + " for method " + method.getName()); + log.error("Could not determine simple name of argument type " + + argumentType + " of argument " + argument.getName() + + " for method " + method.getName()); } } @@ -289,7 +301,8 @@ String exceptionSimple = importManager.getType(exception); exceptions[i] = exceptionSimple; } catch (Exception e) { - log.error("Could not determine simple name of exception " + exception + " for method " + method.getName()); + log.error("Could not determine simple name of exception " + + exception + " for method " + method.getName()); } } @@ -367,8 +380,13 @@ ); addMethod(method); } - String content = String.format(SETTER_PATTERN, field.getType(), id, constantId); - JavaArgument arg = JavaElementFactory.newArgument(field.getType(), id); + String content = String.format(SETTER_PATTERN, + field.getType(), + id, + constantId + ); + JavaArgument arg = JavaElementFactory.newArgument(field.getType(), + id); JavaMethod method = JavaElementFactory.newMethod( Modifier.PUBLIC, JAXXCompilerFinalizer.TYPE_VOID, @@ -393,7 +411,8 @@ field.getName() + "] type " + fieldType); } if (field.hasInitializerTypes()) { - String code = simplifyCode(field.getInitializer(), field.getInitializerTypes()); + String code = simplifyCode(field.getInitializer(), + field.getInitializerTypes()); if (log.isDebugEnabled()) { log.debug("Use simplify text : " + code); } Modified: trunk/jaxx-compiler/src/main/java/jaxx/compiler/java/JavaMethod.java =================================================================== --- trunk/jaxx-compiler/src/main/java/jaxx/compiler/java/JavaMethod.java 2011-03-18 09:33:24 UTC (rev 2241) +++ trunk/jaxx-compiler/src/main/java/jaxx/compiler/java/JavaMethod.java 2011-03-18 11:18:55 UTC (rev 2242) @@ -122,6 +122,10 @@ return body; } + public void setBody(String body) { + this.body = body; + } + @Override public int compareTo(JavaMethod o) { return JavaElementComparator.compare(this, o);