r1912 - trunk/jaxx-compiler/src/main/java/jaxx/compiler/script
Author: tchemit Date: 2010-05-18 05:48:28 +0200 (Tue, 18 May 2010) New Revision: 1912 Url: http://nuiton.org/repositories/revision/jaxx/1912 Log: Anomalie #620: Improve error when fail to load a script Anomalie #621: Make script parse correctly field declaration with generics Modified: trunk/jaxx-compiler/src/main/java/jaxx/compiler/script/ScriptManager.java Modified: trunk/jaxx-compiler/src/main/java/jaxx/compiler/script/ScriptManager.java =================================================================== --- trunk/jaxx-compiler/src/main/java/jaxx/compiler/script/ScriptManager.java 2010-05-17 10:31:06 UTC (rev 1911) +++ trunk/jaxx-compiler/src/main/java/jaxx/compiler/script/ScriptManager.java 2010-05-18 03:48:28 UTC (rev 1912) @@ -32,6 +32,8 @@ import jaxx.compiler.reflect.FieldDescriptor; import jaxx.compiler.reflect.MethodDescriptor; import jaxx.compiler.tags.TagManager; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import java.io.StringReader; import java.lang.reflect.Modifier; @@ -213,9 +215,14 @@ compiler.appendBodyCode(modifiers + " " + node.getText().substring(0, node.getText().length() - 1) + code + "}"); } + + /** Logger */ + static private final Log log = LogFactory.getLog(ScriptManager.class); + private void scanScriptNode(SimpleNode node) throws CompilerException { int nodeType = getLineType(node); - if (nodeType == JavaParserTreeConstants.JJTIMPORTDECLARATION) { // have to handle imports early so the preprocessing takes them into account + if (nodeType == JavaParserTreeConstants.JJTIMPORTDECLARATION) { + // have to handle imports early so the preprocessing takes them into account String text = node.getChild(0).getText().trim(); if (text.startsWith("import")) { text = text.substring("import".length()).trim(); @@ -287,6 +294,30 @@ declaration = declaration.substring(0, equals); } declaration = declaration.trim(); + if (declaration.contains("<")) { + + // generic declaration detected + + if (log.isDebugEnabled()) { + log.info("Found a declaration with generics : " + declaration); + } + + int last = declaration.lastIndexOf('>'); + + // copy everything before first '<' + String newDeclaration = declaration.substring(0, declaration.indexOf('<')); + if (last < declaration.length()) { + + // copy everithing after last '>' + newDeclaration += declaration.substring(last + 1); + } + + if (log.isDebugEnabled()) { + log.info("==> declaration without generics : " + newDeclaration); + } + declaration = newDeclaration; + } + String[] declarationTokens = declaration.split("\\s"); boolean isFinal = Arrays.asList(declarationTokens).contains("final"); boolean isStatic = Arrays.asList(declarationTokens).contains("static"); @@ -295,10 +326,19 @@ name = name.substring(0, name.length() - 1).trim(); } String className = declarationTokens[declarationTokens.length - 2]; + if (log.isInfoEnabled()) { + log.info("Found type : "+className +": ()"+ Arrays.toString(declarationTokens)); + } String type = TagManager.resolveClassName(className, compiler); + if (type == null) { + + throw new CompilerException("Could not find type of " + className+" for expression " + text); + } compiler.addScriptField(new FieldDescriptor(name, Modifier.PUBLIC, type, compiler.getClassLoader())); // TODO: determine the actual modifiers - if (equals != -1 && !isFinal && !isStatic) { // declare the field in the class body, but wait to actually initialize it + if (equals != -1 && !isFinal && !isStatic) { + + // declare the field in the class body, but wait to actually initialize it compiler.appendBodyCode(text.substring(0, equals).trim() + ";"); String initializer = text.substring(equals + 1).trim(); if (type.endsWith("[]")) {
participants (1)
-
tchemit@users.nuiton.org