Author: tchemit Date: 2010-05-04 17:14:14 +0200 (Tue, 04 May 2010) New Revision: 1872 Url: http://nuiton.org/repositories/revision/jaxx/1872 Log: add jaxxObjectDescriptor available in classDescriptor when coming from a java source Modified: trunk/jaxx-compiler/src/main/java/jaxx/compiler/reflect/JavaFileParser.java Modified: trunk/jaxx-compiler/src/main/java/jaxx/compiler/reflect/JavaFileParser.java =================================================================== --- trunk/jaxx-compiler/src/main/java/jaxx/compiler/reflect/JavaFileParser.java 2010-05-04 09:50:39 UTC (rev 1871) +++ trunk/jaxx-compiler/src/main/java/jaxx/compiler/reflect/JavaFileParser.java 2010-05-04 15:14:14 UTC (rev 1872) @@ -33,6 +33,8 @@ import jaxx.compiler.java.parser.ParseException; import jaxx.compiler.java.parser.SimpleNode; import jaxx.compiler.tags.TagManager; +import jaxx.runtime.JAXXObjectDescriptor; +import jaxx.runtime.JAXXUtil; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -72,6 +74,8 @@ private List<FieldDescriptor> declaredFields = new ArrayList<FieldDescriptor>(); + private String jaxxObjectDescriptorValue; + public static final String[] EMPTY_STRING_ARRAY = new String[0]; private JavaFileParser(ClassLoader classLoader) { @@ -100,6 +104,17 @@ throw new RuntimeException(e); } + JAXXObjectDescriptor jaxxObjectDescriptor = null; + + if (parser.jaxxObjectDescriptorValue != null) { + + // compute the jaxx object descriptor + + jaxxObjectDescriptor = JAXXUtil.decodeCompressedJAXXObjectDescriptor( + parser.jaxxObjectDescriptorValue + ); + + } List<MethodDescriptor> publicMethods = parser.methods; List<FieldDescriptor> publicFields = parser.fields; List<FieldDescriptor> declaredFields = parser.declaredFields; @@ -142,7 +157,7 @@ parser.isInterface, false, null, - null, + jaxxObjectDescriptor, classLoader, publicMethods.toArray(new MethodDescriptor[publicMethods.size()]), publicFields.toArray(new FieldDescriptor[publicFields.size()]), @@ -209,6 +224,8 @@ case JavaParserTreeConstants.JJTPACKAGEDECLARATION: packageName = child.getChild(1).getText().trim(); compiler.addImport(packageName + ".*"); + + // add implicit java.lnag namespace available compiler.addImport("java.lang.*"); break; case JavaParserTreeConstants.JJTIMPORTDECLARATION: @@ -413,24 +430,21 @@ String text = node.getText(); String declaration = text; + String value = null; int equals = text.indexOf("="); if (equals != -1) { + value = declaration.substring(equals + 1).trim(); declaration = declaration.substring(0, equals); } declaration = declaration.trim(); - SimpleNode parentNode = node.getParent(); - int modifiers = 0; + // get modifiers of the field + + int modifiers; if (isInterface) { modifiers = Modifier.PUBLIC | Modifier.STATIC | Modifier.FINAL; } else { - for (int i = 0; i < parentNode.jjtGetNumChildren(); i++) { - SimpleNode child = parentNode.getChild(i); - if (child.getId() == JavaParserTreeConstants.JJTMODIFIERS) { - String modifiersStr = child.getText().trim(); - modifiers = scanModifiers(modifiersStr); - } - } + modifiers = getModifiers(node); } log.info("field [" + declaration + "] modifiers == " + Modifier.toString(modifiers)); @@ -449,6 +463,22 @@ type, compiler.getClassLoader() ); + + if ("$jaxxObjectDescriptor".equals(name) && value != null) { + + // we are in a jaxx object, save the value of the field + + // value have this form : = "XXX";, we just want the XXX part + int firstIndex = value.indexOf("\""); + int lastIndex = value.lastIndexOf("\""); + + jaxxObjectDescriptorValue = value.substring(firstIndex + 1, lastIndex); + + log.info("detected a $jaxxObjectDescriptor = " + + jaxxObjectDescriptorValue); + + } + if (Modifier.isPublic(modifiers)) { fields.add(descriptor); } else { @@ -463,6 +493,19 @@ } } + protected int getModifiers(SimpleNode node) { + SimpleNode parentNode = node.getParent(); + for (int i = 0; i < parentNode.jjtGetNumChildren(); i++) { + SimpleNode child = parentNode.getChild(i); + if (child.getId() == JavaParserTreeConstants.JJTMODIFIERS) { + String modifiersStr = child.getText().trim(); + int modifiers = scanModifiers(modifiersStr); + return modifiers; + } + } + return 0; + } + protected int scanModifiers(String modifiersStr) { int modifiers = 0; if (modifiersStr.contains("public")) {
participants (1)
-
tchemit@users.nuiton.org