Author: kmorin Date: 2009-08-27 10:39:26 +0200 (Thu, 27 Aug 2009) New Revision: 1607 Modified: trunk/guix-compiler/src/main/java/org/nuiton/guix/BindingUtils.java trunk/guix-compiler/src/main/java/org/nuiton/guix/GuixLauncher.java trunk/guix-compiler/src/main/java/org/nuiton/guix/generator/JavaFileGenerator.java trunk/guix-compiler/src/main/java/org/nuiton/guix/model/ClassDescriptor.java trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/DefaultTagHandler.java trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/ScriptHandler.java trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/StyleHandler.java trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/TagHandler.java trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/TagManager.java Log: Correction in the javadoc + clean imports Modified: trunk/guix-compiler/src/main/java/org/nuiton/guix/BindingUtils.java =================================================================== --- trunk/guix-compiler/src/main/java/org/nuiton/guix/BindingUtils.java 2009-08-26 17:03:12 UTC (rev 1606) +++ trunk/guix-compiler/src/main/java/org/nuiton/guix/BindingUtils.java 2009-08-27 08:39:26 UTC (rev 1607) @@ -18,23 +18,18 @@ */ package org.nuiton.guix; -import java.beans.Introspector; import java.util.ArrayList; import java.util.List; -import java.util.logging.Level; -import java.util.logging.Logger; import java.util.regex.Matcher; import java.util.regex.Pattern; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.nuiton.guix.CompilerException; -import org.nuiton.guix.parser.JavaParserConstants; import org.nuiton.guix.parser.JavaParserTreeConstants; import org.nuiton.guix.parser.SimpleNode; /** * - * @author kevin + * @author kmorin */ public class BindingUtils { /** left brace matcher */ @@ -46,14 +41,11 @@ /** * Examine an attribute value for data binding expressions. Returns a 'cooked' expression which - * can be used to determine the resulting value. It is expected that this expression will be used - * as the source expression in a call to {@link #registerDataBinding}. + * can be used to determine the resulting value. * If the attribute value does not invoke data binding, this method returns <code>null</code> * * @param stringValue the string value of the property from the XML - * @param type the type of the property, from the <code>JAXXPropertyDescriptor</code> * @return a processed version of the expression - * @throws jaxx.CompilerException ? */ public static String processDataBindings(String stringValue) { int pos = getNextLeftBrace(stringValue, 0); @@ -97,24 +89,7 @@ expression.append(escapeJavaString(stringValue.substring(lastPos))); expression.append('"'); } -// -// StringBuffer el = new StringBuffer(); -// Pattern p = Pattern .compile("\\.(get|is)([A-Z])([a-zA-Z0-9]*)\\(\\)"); -// Matcher m = p.matcher(expression.toString()); -// int mEnd = 0; -// if(m.find()) { -// do { -// el.append(expression.toString().substring(mEnd, m.start())) -// .append("."); -// mEnd = m.end(); -// el.append(m.group(2).toLowerCase()) -// .append(m.group(3)); -// } while (m.find()); -// } -// else { -// el.append(expression.toString()); -// } -// return el.toString().length() > 0 ? el.toString().substring(0, el.toString().length()) : el.toString(); + return expression.toString(); } return null; @@ -185,7 +160,8 @@ * Examines a node to identify any dependencies it contains. * * @param node node to scan - * @throws jaxx.CompilerException ? + * @return the decomposed expression into tokens + * @throws CompilerException ? */ public static List<String[]> scanNode(SimpleNode node) throws CompilerException { List<String[]> bindings = new ArrayList<String[]>(); @@ -212,102 +188,16 @@ } /** - * Scans through a compound symbol (foo.bar.baz) to identify and track all trackable pieces of it. - * - * @param symbol symbol to scan - * @param contextClass current class context - * @param isMethod flag to search a method - * @param listenerId id of the listener - * @return the type of the symbol (or null if it could not be determined). - */ -// private Class scanCompoundSymbol(String symbol, boolean isMethod) { -// String[] tokens = symbol.split("\\s*\\.\\s*"); -// StringBuffer currentSymbol = new StringBuffer(); -// StringBuffer tokensSeenSoFar = new StringBuffer(); -// boolean accepted; // if this ends up false, it means we weren't able to figure out -// // which object the method is being invoked on -// boolean recognizeClassNames = true; -// for (int j = 0; j < tokens.length - (isMethod ? 1 : 0); j++) { -// accepted = false; -// -// if (tokensSeenSoFar.length() > 0) { -// tokensSeenSoFar.append('.'); -// } -// tokensSeenSoFar.append(tokens[j]); -// if (currentSymbol.length() > 0) { -// currentSymbol.append('.'); -// } -// currentSymbol.append(tokens[j]); -// -// if (currentSymbol.indexOf(".") == -1) { -// String memberName = currentSymbol.toString(); -// CompiledObject object = compiler.getCompiledObject(memberName); -// if (object != null) { -// contextClass = object.getObjectClass(); -// currentSymbol.setLength(0); -// accepted = true; -// recognizeClassNames = false; -// } else { -// try { -// FieldDescriptor field = contextClass.getFieldDescriptor(memberName); -// contextClass = field.getType(); -// currentSymbol.setLength(0); -// accepted = true; -// recognizeClassNames = false; -// } -// catch (NoSuchFieldException e) { -// if (j == 0 || j == 1 && tokens[0].equals(compiler.getRootObject().getId())) { // still in root context -// FieldDescriptor[] newFields = compiler.getScriptFields(); -// for (FieldDescriptor newField : newFields) { -// if (newField.getName().equals(memberName)) { -// addListener(tokensSeenSoFar.toString(), -// null, -// "addPropertyChangeListener(\"" + memberName + "\", " + listenerId + ");" + JAXXCompiler.getLineSeparator(), -// "removePropertyChangeListener(\"" + memberName + "\", " + listenerId + ");" + JAXXCompiler.getLineSeparator()); -// contextClass = newField.getType(); -// assert contextClass != null : "script field '" + memberName + "' is defined, but has type null"; -// currentSymbol.setLength(0); -// accepted = true; -// recognizeClassNames = false; -// break; -// } -// } -// } -// } -// } -// } -// if (currentSymbol.length() > 0 && recognizeClassNames) { -// contextClass = TagManager.resolveClass(currentSymbol.toString(), compiler); -// if (contextClass != null) { -// currentSymbol.setLength(0); -// //accepted = true; -// //recognizeClassNames = false; -// // TODO: for now we don't handle statics -// return null; -// } -// } -// if (!accepted) { -// return null; -// } -// } -// -// return contextClass; -// } - - /** * Adds type information to nodes where possible, and as a side effect adds event listeners to nodes which * can be tracked. * * @param expression the node to scan - * @param listenerId id of the listener - * @return the class descriptor of the return type or null + * @return the decomposed expression into tokens */ private static String[] determineExpressionType(SimpleNode expression) { assert expression.getId() == JavaParserTreeConstants.JJTPRIMARYEXPRESSION; SimpleNode prefix = expression.getChild(0); if (prefix.jjtGetNumChildren() == 1) { -// log.info("1 : " + prefix.getChild(0).getText()); - //return prefix.getChild(0).getText(); int type = prefix.getChild(0).getId(); if (type == JavaParserTreeConstants.JJTLITERAL || type == JavaParserTreeConstants.JJTEXPRESSION) { return null; @@ -318,7 +208,6 @@ } if (expression.jjtGetNumChildren() == 1) { -// log.info("2 " + prefix.getText()); return null; } else { @@ -358,70 +247,6 @@ return result.toArray(new String[result.size()]); } -// Class contextClass = prefix.getJavaType(); -// if (contextClass == null) { -// contextClass = compiler.getRootObject().getObjectClass(); -// } -// String lastNode = prefix.getText().trim(); -// -// for (int i = 1; i < expression.jjtGetNumChildren(); i++) { -// SimpleNode suffix = expression.getChild(i); -// if (suffix.jjtGetNumChildren() == 1 && suffix.getChild(0).getId() == JavaParserTreeConstants.JJTARGUMENTS) { -// if (suffix.getChild(0).jjtGetNumChildren() == 0) { // at the moment only no-argument methods are trackable -// contextClass = scanCompoundSymbol(lastNode, contextClass, true, listenerId); -// if (contextClass == null) { -// return null; -// } -// int dotPos = lastNode.lastIndexOf("."); -// String objectCode = dotPos == -1 ? "" : lastNode.substring(0, dotPos); -// log.info("oc : " + objectCode); -// for (int j = i - 2; j >= 0; j--) { -// log.info(expression.getChild(j).getText()); -// } -// for (int j = i - 2; j >= 0; j--) { -// objectCode = expression.getChild(j).getText() + objectCode; -// } -// return objectCode; -// if (objectCode.length() == 0) { -// objectCode = compiler.getRootObject().getJavaCode(); -// } -// String methodName = lastNode.substring(dotPos + 1).trim(); -// try { -// MethodDescriptor method = contextClass.getMethodDescriptor(methodName); -// trackMemberIfPossible(objectCode, contextClass, method.getName(), true, listenerId); -// return method.getReturnType(); -// } -// catch (NoSuchMethodException e) { -// // happens for methods defined in the current JAXX file via scripts -// String propertyName = null; -// if (methodName.startsWith("is")) { -// propertyName = Introspector.decapitalize(methodName.substring("is".length())); -// } else if (methodName.startsWith("get")) { -// propertyName = Introspector.decapitalize(methodName.substring("get".length())); -// } -// if (propertyName != null) { -// MethodDescriptor[] newMethods = compiler.getScriptMethods(); -// for (MethodDescriptor newMethod : newMethods) { -// if (newMethod.getName().equals(methodName)) { -// addListener(compiler.getRootObject().getId(), -// null, -// "addPropertyChangeListener(\"" + propertyName + "\", " + listenerId + ");" + JAXXCompiler.getLineSeparator(), -// "removePropertyChangeListener(\"" + propertyName + "\", " + listenerId + ");" + JAXXCompiler.getLineSeparator()); -// contextClass = newMethod.getReturnType(); -// break; -// } -// } -// } -// } -// } -// } -// lastNode = suffix.getText().trim(); -// if (lastNode.startsWith(".")) { -// lastNode = lastNode.substring(1); -// } -// } -// -// return null; } /** @@ -429,6 +254,7 @@ * can be tracked. * * @param node node to scan + * @return the decomposed expression into tokens */ private static String[] determineNodeType(SimpleNode node) { String[] result = null; Modified: trunk/guix-compiler/src/main/java/org/nuiton/guix/GuixLauncher.java =================================================================== --- trunk/guix-compiler/src/main/java/org/nuiton/guix/GuixLauncher.java 2009-08-26 17:03:12 UTC (rev 1606) +++ trunk/guix-compiler/src/main/java/org/nuiton/guix/GuixLauncher.java 2009-08-27 08:39:26 UTC (rev 1607) @@ -18,7 +18,6 @@ */ package org.nuiton.guix; -import org.nuiton.guix.GuixCompiler; import java.io.File; import java.io.PrintWriter; import java.io.StringReader; @@ -30,12 +29,10 @@ import java.util.Map; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.nuiton.guix.BindingUtils; import org.nuiton.guix.generator.GuixGenerator; import org.nuiton.guix.generator.JavaArgument; import org.nuiton.guix.generator.JavaField; import org.nuiton.guix.generator.JavaFile; -import org.nuiton.guix.generator.JavaFileGenerator; import org.nuiton.guix.generator.JavaMethod; import org.nuiton.guix.model.ClassDescriptor; import org.nuiton.guix.model.GuixModelObject; @@ -94,10 +91,10 @@ * * @param files the files to compile * @param targetDirectory the directory where to save the generated files - * @param rootPackage teh root package - * @param baseDir directory containing the files to compile + * @param srcDir the directory of the source files * @param mainClass main class of the application * @param generatorClass class of the generator + * @param generationLanguage the output graphical library * @param launcherName name of the class that will launch the application */ public GuixLauncher(File[] files, File targetDirectory, File srcDir, String mainClass, Class<? extends GuixGenerator> generatorClass,String generationLanguage, String launcherName) { @@ -504,35 +501,10 @@ return null; } } -// ClassDescriptor cd = classDescriptors.get(i); -// StringBuffer sb = new StringBuffer(); -// while(cd != null) { -// sb.append(cd.toString()).append(" - "); -// cd = cd.getSuperClass(); -// } -// log.info(sb.toString()); return classDescriptors.get(i); } /** - * Decompose the binding into the different elements to bind - * - * @param node the Node being parsed - * @return the elements to bind - */ - private List<String> browseNode(SimpleNode node) { - List<String> result = new ArrayList<String>(); - for (int i = 0; i < node.jjtGetNumChildren(); i++) { - //if the child is not a String and are not parameters of a method - if (node.getChild(i).getId() == JavaParserTreeConstants.JJTPRIMARYEXPRESSION && !node.getChild(i).getText().trim().startsWith("(") && !node.getChild(i).getText().trim().startsWith("\"")) { - result.add(node.getChild(i).getText().trim()); - } - result.addAll(browseNode(node.getChild(i))); - } - return result; - } - - /** * Adds a root GuixModelObject with its last modification time * * @param gmo the root GuixModelObject to add Modified: trunk/guix-compiler/src/main/java/org/nuiton/guix/generator/JavaFileGenerator.java =================================================================== --- trunk/guix-compiler/src/main/java/org/nuiton/guix/generator/JavaFileGenerator.java 2009-08-26 17:03:12 UTC (rev 1606) +++ trunk/guix-compiler/src/main/java/org/nuiton/guix/generator/JavaFileGenerator.java 2009-08-27 08:39:26 UTC (rev 1607) @@ -77,7 +77,6 @@ /** * Add imports to the generated file * - * @param gmo GuixModelObject which represents the class to generate */ protected abstract void addImports(); Modified: trunk/guix-compiler/src/main/java/org/nuiton/guix/model/ClassDescriptor.java =================================================================== --- trunk/guix-compiler/src/main/java/org/nuiton/guix/model/ClassDescriptor.java 2009-08-26 17:03:12 UTC (rev 1606) +++ trunk/guix-compiler/src/main/java/org/nuiton/guix/model/ClassDescriptor.java 2009-08-27 08:39:26 UTC (rev 1607) @@ -18,7 +18,6 @@ */ package org.nuiton.guix.model; -import org.nuiton.guix.tags.TagHandler; /** * Descriptor of a class found in the guix files. Modified: trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/DefaultTagHandler.java =================================================================== --- trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/DefaultTagHandler.java 2009-08-26 17:03:12 UTC (rev 1606) +++ trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/DefaultTagHandler.java 2009-08-27 08:39:26 UTC (rev 1607) @@ -23,12 +23,9 @@ import java.beans.IntrospectionException; import java.beans.Introspector; import java.beans.PropertyDescriptor; -import java.lang.reflect.Field; import java.lang.reflect.Method; -import java.lang.reflect.Modifier; import java.util.HashMap; import java.util.Map; -import org.nuiton.guix.UnsupportedAttributeException; /** * Default TagHandler, containing common methods for all the tags @@ -243,48 +240,5 @@ public String getDefaultConstructor() { return null; } - - /** - * @param name ? - * @return <code>true</code> if the named member is <i>bound</i> (fires <code>PropertyChangeEvent</code> - * when modified). Members are either fields (represented by the simple name of the field) or <code>get/is</code> - * methods (represented by the simple name of the method, <b>not</b> the simplified JavaBeans-style name). - * Methods which are not actually bound in their native class, but for which proxy events have been - * configured (such as <code>JTextField.getText</code>, return <code>true</code>. - * @throws jaxx.UnsupportedAttributeException - * ? - */ - @Override - public boolean isMemberBound(String member) throws UnsupportedAttributeException { - try { - init(); - } catch (IntrospectionException e) { - throw new RuntimeException(e); - } - - if (eventInfos != null && eventInfos.containsKey(member)) { - return true; - } - - if (member.equals("getClass")) { - return false; - } - - String propertyName = null; - if (member.startsWith("get")) { - propertyName = Introspector.decapitalize(member.substring("get".length())); - } else if (member.startsWith("is")) { - propertyName = Introspector.decapitalize(member.substring("is".length())); - } - PropertyDescriptor property = propertyName != null ? properties.get(propertyName) : null; - if (property != null) { - return property.isBound(); - } - try { - Field field = getClassToGenerate().getField(member); - return Modifier.isFinal(field.getModifiers()); // final fields might as well be considered bound -- they can't be modified anyway - } catch (NoSuchFieldException e) { - throw new UnsupportedAttributeException("cannot find property '" + member + "' of " + getClassToGenerate()); - } - } + } Modified: trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/ScriptHandler.java =================================================================== --- trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/ScriptHandler.java 2009-08-26 17:03:12 UTC (rev 1606) +++ trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/ScriptHandler.java 2009-08-27 08:39:26 UTC (rev 1607) @@ -81,7 +81,7 @@ * Parse the <code>script</code> tag. * * @param xpp the parser referencing the style tag - * @param baseDir the directory of the compiled guix file + * @param scriptFile the file containing the code to compile * @return the content of the file specified by the <code>source</code> attribute * or the script between the script tags * @throws IOException Modified: trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/StyleHandler.java =================================================================== --- trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/StyleHandler.java 2009-08-26 17:03:12 UTC (rev 1606) +++ trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/StyleHandler.java 2009-08-27 08:39:26 UTC (rev 1607) @@ -82,8 +82,7 @@ * Load the file with the name of the class * and creates a <code>StyleSheet</code> with the content of the file. * - * @param baseDir the directory of the compiled guix file - * @param className the name of the file to load + * @param styleFile the file containing the css code * @return a <code>StyleSheet</code> containing the content of the file * @throws FileNotFoundException if the file with the same name as the class * does not exist @@ -101,7 +100,7 @@ * and creates a <code>StyleSheet</code> with this content. * * @param xpp the parser referencing the style tag - * @param baseDir the directory of the compiled guix file + * @param styleFile the file containing the css code * @return a <code>StyleSheet</code> containing the content of the file * @throws java.io.IOException if an error occurs while reading * the file specified by the <code>source</code> attribute @@ -336,5 +335,3 @@ } } - -//~ Formatted by Jindent --- http://www.jindent.com Modified: trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/TagHandler.java =================================================================== --- trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/TagHandler.java 2009-08-26 17:03:12 UTC (rev 1606) +++ trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/TagHandler.java 2009-08-27 08:39:26 UTC (rev 1607) @@ -43,5 +43,4 @@ public String getEventInfosModelName(String methodName); - public boolean isMemberBound(String member); } Modified: trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/TagManager.java =================================================================== --- trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/TagManager.java 2009-08-26 17:03:12 UTC (rev 1606) +++ trunk/guix-compiler/src/main/java/org/nuiton/guix/tags/TagManager.java 2009-08-27 08:39:26 UTC (rev 1607) @@ -21,16 +21,12 @@ //~--- non-JDK imports -------------------------------------------------------- -import java.util.logging.Level; -import java.util.logging.Logger; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; //~--- JDK imports ------------------------------------------------------------ -import java.util.ArrayList; import java.util.HashMap; -import java.util.List; import java.util.Map; /** @@ -53,9 +49,6 @@ /** Maps simple tag names to their default namespaces (package names). */ private static Map<String, String> defaultNamespaces = new HashMap<String, String>(); - /** Keeps track of whether or not named classes exist. */ - private static Map<String, Boolean> classExistenceCache = new HashMap<String, Boolean>(); - private TagManager() { /* not instantiable */ } @@ -83,13 +76,21 @@ } /** + * Register a TagHandler for a particular tag * - * @param className + * @param className the tag or className to catch + * @param clazz the tagHandler class who handles clazz */ public static void registerGuixClassHandler(String className, Class clazz) { guixClassHandlers.put(className.toUpperCase(), clazz); } + /** + * Get the tagHandler registered for a particular tag + * + * @param className the class name or tag you'd like to get the TagHandler + * @return a TagHandler instance which handles the className class or tag + */ public static TagHandler getGuixClassHandler(String className) { if(guixClassHandlers.get(className.toUpperCase()) != null) { try { @@ -127,7 +128,6 @@ * class could be found. * * @param name name to resolve - * @param compiler compile to use * @return the resolved fqn class name */ public static String resolveClassName(String name) { @@ -163,5 +163,3 @@ } } - -//~ Formatted by Jindent --- http://www.jindent.com