Author: tchemit Date: 2011-03-18 12:19:23 +0100 (Fri, 18 Mar 2011) New Revision: 2243 Url: http://nuiton.org/repositories/revision/jaxx/2243 Log: Evolution #1405: Improve import manager usage Anomalie #1404: Using decorator='boxed' or icon="img.png" miss import jaxx.runtime.SwingUtil Added: trunk/maven-jaxx-plugin/src/test/resources/org/nuiton/jaxx/plugin/bug1404Test/Test2.jaxx Modified: trunk/jaxx-compiler/src/main/java/jaxx/compiler/CompiledObject.java trunk/jaxx-compiler/src/main/java/jaxx/compiler/JAXXCompiler.java trunk/jaxx-compiler/src/main/java/jaxx/compiler/binding/DataSource.java trunk/jaxx-compiler/src/main/java/jaxx/compiler/css/StylesheetHelper.java trunk/jaxx-compiler/src/main/java/jaxx/compiler/decorators/BoxedCompiledObjectDecorator.java trunk/jaxx-compiler/src/main/java/jaxx/compiler/decorators/DefaultCompiledObjectDecorator.java trunk/jaxx-compiler/src/main/java/jaxx/compiler/decorators/HelpRootCompiledObjectDecorator.java trunk/jaxx-compiler/src/main/java/jaxx/compiler/finalizers/AbstractFinalizer.java trunk/jaxx-compiler/src/main/java/jaxx/compiler/finalizers/DefaultFinalizer.java trunk/jaxx-compiler/src/main/java/jaxx/compiler/finalizers/ValidatorFinalizer.java trunk/jaxx-compiler/src/main/java/jaxx/compiler/script/ScriptManager.java trunk/jaxx-compiler/src/main/java/jaxx/compiler/tags/DefaultComponentHandler.java trunk/jaxx-compiler/src/main/java/jaxx/compiler/tags/swing/JRadioButtonHandler.java trunk/jaxx-compiler/src/main/java/jaxx/compiler/tags/swing/JSpinnerHandler.java trunk/jaxx-compiler/src/main/java/jaxx/compiler/tags/swing/JTabbedPaneHandler.java trunk/jaxx-compiler/src/main/java/jaxx/compiler/tags/swing/JTextComponentHandler.java trunk/jaxx-compiler/src/main/java/jaxx/compiler/tags/validator/BeanValidatorHandler.java trunk/jaxx-compiler/src/main/java/jaxx/compiler/tasks/GenerateConstructorsTask.java trunk/jaxx-compiler/src/main/java/jaxx/compiler/tasks/GenerateTask.java trunk/maven-jaxx-plugin/src/test/java/org/nuiton/jaxx/plugin/Bug1404Test.java Modified: trunk/jaxx-compiler/src/main/java/jaxx/compiler/CompiledObject.java =================================================================== --- trunk/jaxx-compiler/src/main/java/jaxx/compiler/CompiledObject.java 2011-03-18 11:18:55 UTC (rev 2242) +++ trunk/jaxx-compiler/src/main/java/jaxx/compiler/CompiledObject.java 2011-03-18 11:19:23 UTC (rev 2243) @@ -516,8 +516,8 @@ protected String getInitializationCode(EventHandler handler, JAXXCompiler compiler) { MethodDescriptor addMethod = handler.getAddMethod(); ClassDescriptor listenerClass = addMethod.getParameterTypes()[0]; - String type = compiler.getImportManager().getType(listenerClass.getName()); - String prefix = compiler.getImportManager().getType(JAXXUtil.class); + String type = compiler.getImportedType(listenerClass.getName()); + String prefix = compiler.getImportedType(JAXXUtil.class); //TC-20091026 use 'this' instead of root object javaCode //TC-20091105 JAXXUtil.getEventListener is generic, no more need cast and use simple name Modified: trunk/jaxx-compiler/src/main/java/jaxx/compiler/JAXXCompiler.java =================================================================== --- trunk/jaxx-compiler/src/main/java/jaxx/compiler/JAXXCompiler.java 2011-03-18 11:18:55 UTC (rev 2242) +++ trunk/jaxx-compiler/src/main/java/jaxx/compiler/JAXXCompiler.java 2011-03-18 11:19:23 UTC (rev 2243) @@ -293,7 +293,11 @@ * A flag to know if SwingUtil msut be imported. * * @since 2.4 + * @deprecated since 2.4.1, will be removed in version 3.0, it is not a good + * idea to do special treatment for a particular class, to use SwingUtil, + * do like for other class : import it! */ + @Deprecated protected boolean needSwingUtil; public static final String[] EMPTY_STRING_ARRAY = new String[0]; @@ -784,7 +788,7 @@ // types are not the same String simpleType = - getImportManager().getType(getCanonicalName(object)); + getImportedType(getCanonicalName(object)); if (log.isDebugEnabled()) { log.debug("Simple type for " + object.getId() + " : " + getCanonicalName(object) + @@ -1581,7 +1585,7 @@ public void preFinalizeCompiler() throws Exception { } - + public void finalizeCompiler() throws Exception { int dotPos = getOutputClassName().lastIndexOf("."); @@ -1926,14 +1930,62 @@ this.classLoader = classLoader; } + /** + * Try to import the given type into the underlying java file of this compiler. + * <p/> + * If import can not be done, will then returns the fully qualified name of + * the type. + * + * @param type the type to simplify + * @return the simplify type or the fqn if type could not be imported for the underlying java file. + * @since 2.4.1 + */ + public String getImportedType(Class<?> type) { + return getJavaFile().getImportedType(type); + } + + /** + * Try to import the given type into the underlying java file of this compiler. + * <p/> + * If import can not be done, will then returns the fully qualified name of + * the type. + * + * @param type the fqn of the type to simplify + * @return the simplify type or the fqn if type could not be imported for the underlying java file. + * @since 2.4.1 + */ + public String getImportedType(String type) { + return getJavaFile().getImportedType(type); + } + + /** + * @return the javafile import manager + * @since 2.4 + * @deprecated since 2.4.1, will be removed in version 3.0 : do not want + * to expose eugene export manager in rest of api, this is purpose of + * JavaFile only + */ + @Deprecated public ImportsManager getImportManager() { return getJavaFile().getImportManager(); } + /** + * @return + * @since 2.4 + * @deprecated since 2.4.1, will be removed in version 3.0, has no effect do not use it... + */ + @Deprecated public boolean isNeedSwingUtil() { return needSwingUtil; } + /** + * @param needSwingUtil + * @since 2.4 + * @deprecated since 2.4.1, will be removed in version 3.0, has no effect do not use it... + */ + @Deprecated public void setNeedSwingUtil(boolean needSwingUtil) { this.needSwingUtil = needSwingUtil; } Modified: trunk/jaxx-compiler/src/main/java/jaxx/compiler/binding/DataSource.java =================================================================== --- trunk/jaxx-compiler/src/main/java/jaxx/compiler/binding/DataSource.java 2011-03-18 11:18:55 UTC (rev 2242) +++ trunk/jaxx-compiler/src/main/java/jaxx/compiler/binding/DataSource.java 2011-03-18 11:19:23 UTC (rev 2243) @@ -671,7 +671,7 @@ String methodName = "$pr" + compiler.getUniqueId(propertyChangeListenerCode.equals("this") ? constantId : propertyChangeListenerCode); boolean methodExists = hasMethod(methodName); ClassDescriptor eventClass = DefaultObjectHandler.getEventClass(eventInfo.getListenerClass()); - String type = compiler.getImportManager().getType(JAXXCompiler.getCanonicalName(eventClass)); + String type = compiler.getImportedType(JAXXCompiler.getCanonicalName(eventClass)); if (!methodExists) { String code = JavaFileGenerator.addDebugLoggerInvocation(compiler, "event"); code += "propertyChange(null);"; @@ -688,8 +688,8 @@ result.append("$bindingSources.put(\"").append(code).append("\", ").append(code).append(");").append(JAXXCompiler.getLineSeparator()); //TC-20091105 JAXXUtil.getEventListener is generic, no more need cast and use simple listener name ClassDescriptor listenerClass = eventInfo.getListenerClass(); - String listenerType = compiler.getImportManager().getType(listenerClass.getName()); - String jaxxUtilPrefix = compiler.getImportManager().getType(JAXXUtil.class); + String listenerType = compiler.getImportedType(listenerClass.getName()); + String jaxxUtilPrefix = compiler.getImportedType(JAXXUtil.class); result.append(code); result.append('.'); result.append(eventInfo.getAddMethod()); @@ -771,7 +771,7 @@ boolean methodExists = hasMethod(methodName); if (!methodExists) { ClassDescriptor eventClass = DefaultObjectHandler.getEventClass(eventInfo.getListenerClass()); - String type = compiler.getImportManager().getType(JAXXCompiler.getCanonicalName(eventClass)); + String type = compiler.getImportedType(JAXXCompiler.getCanonicalName(eventClass)); String code = JavaFileGenerator.addDebugLoggerInvocation(compiler, "event"); code += "propertyChange(null);"; JavaMethod method = JavaElementFactory.newMethod( @@ -786,16 +786,16 @@ try { String modelMemberName = eventInfo.getModelName() != null ? "get" + StringUtils.capitalize(eventInfo.getModelName()) : null; String modelClassName = modelMemberName != null ? handler.getBeanClass().getMethodDescriptor(modelMemberName).getReturnType().getName() : JAXXCompiler.getCanonicalName(handler.getBeanClass()); - String modelType = compiler.getImportManager().getType(modelClassName); + String modelType = compiler.getImportedType(modelClassName); String code = objectCode + (eventInfo.getModelName() != null ? "." + modelMemberName + "()" : ""); String eol = JAXXCompiler.getLineSeparator(); - String jaxxUtilPrefix = compiler.getImportManager().getType(JAXXUtil.class); + String jaxxUtilPrefix = compiler.getImportedType(JAXXUtil.class); result.append(modelType).append(" $target = (").append(modelType).append(") $bindingSources.remove(\"").append(code).append("\");").append(eol); //TC-20091105 test if $target is not null result.append("if ($target != null) {").append(eol); //TC-20091105 JAXXUtil.getEventListener is generic, no more need cast and use simple listener name ClassDescriptor listenerClass = eventInfo.getListenerClass(); - String listenerType = compiler.getImportManager().getType(listenerClass.getName()); + String listenerType = compiler.getImportedType(listenerClass.getName()); result.append(" $target."); result.append(eventInfo.getRemoveMethod()); result.append("( ").append(jaxxUtilPrefix).append(".getEventListener("); Modified: trunk/jaxx-compiler/src/main/java/jaxx/compiler/css/StylesheetHelper.java =================================================================== --- trunk/jaxx-compiler/src/main/java/jaxx/compiler/css/StylesheetHelper.java 2011-03-18 11:18:55 UTC (rev 2242) +++ trunk/jaxx-compiler/src/main/java/jaxx/compiler/css/StylesheetHelper.java 2011-03-18 11:19:23 UTC (rev 2243) @@ -47,7 +47,6 @@ import jaxx.runtime.css.Stylesheet; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.nuiton.eugene.java.extension.ImportsManager; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; @@ -361,15 +360,14 @@ String pseudoClassesPrefix = null; String dataBindingPrefix = null; - ImportsManager importManager = compiler.getImportManager(); if (!properties.isEmpty()) { - pseudoClassesPrefix = importManager.getType(Pseudoclasses.class); - dataBindingPrefix = importManager.getType(jaxx.runtime.css.DataBinding.class); + pseudoClassesPrefix = compiler.getImportedType(Pseudoclasses.class); + dataBindingPrefix = compiler.getImportedType(jaxx.runtime.css.DataBinding.class); } String outputClassName = - importManager.getType(compiler.getOutputClassName()); + compiler.getImportedType(compiler.getOutputClassName()); for (Map.Entry<String, String> e : properties.entrySet()) { String property = e.getKey(); @@ -384,7 +382,7 @@ String dataBindingCode = DataBindingHelper.processDataBindings(e.getValue()); String valueCode; - String simpleType = importManager.getType(JAXXCompiler.getCanonicalName(type)); + String simpleType = compiler.getImportedType(JAXXCompiler.getCanonicalName(type)); if (dataBindingCode != null) { String code = object.getId() + "." + property + "." + priority; @@ -471,7 +469,7 @@ for (Map.Entry<String, String> e : properties.entrySet()) { String property = e.getKey(); ClassDescriptor type = handler.getPropertyType(object, property, compiler); - String simpleType = importManager.getType(JAXXCompiler.getCanonicalName(type)); + String simpleType = compiler.getImportedType(JAXXCompiler.getCanonicalName(type)); if (log.isDebugEnabled()) { log.debug("will test if databinding : [" + e.getValue() + "] type=" + type); } Modified: trunk/jaxx-compiler/src/main/java/jaxx/compiler/decorators/BoxedCompiledObjectDecorator.java =================================================================== --- trunk/jaxx-compiler/src/main/java/jaxx/compiler/decorators/BoxedCompiledObjectDecorator.java 2011-03-18 11:18:55 UTC (rev 2242) +++ trunk/jaxx-compiler/src/main/java/jaxx/compiler/decorators/BoxedCompiledObjectDecorator.java 2011-03-18 11:19:23 UTC (rev 2243) @@ -61,12 +61,7 @@ for (ChildRef child : parent.getChilds()) { if (child.getChild() == object) { String javaCode = child.getChildJavaCode(); - String type = - compiler.getImportManager().getType(SwingUtil.class); - if (log.isInfoEnabled()) { - log.info("SwingUtil type " + type); - } - compiler.setNeedSwingUtil(true); + String type = compiler.getImportedType(SwingUtil.class); child.setChildJavaCode( type + ".boxComponentWithJxLayer(" + javaCode + ")"); Modified: trunk/jaxx-compiler/src/main/java/jaxx/compiler/decorators/DefaultCompiledObjectDecorator.java =================================================================== --- trunk/jaxx-compiler/src/main/java/jaxx/compiler/decorators/DefaultCompiledObjectDecorator.java 2011-03-18 11:18:55 UTC (rev 2242) +++ trunk/jaxx-compiler/src/main/java/jaxx/compiler/decorators/DefaultCompiledObjectDecorator.java 2011-03-18 11:19:23 UTC (rev 2243) @@ -201,7 +201,7 @@ // on special init, use constructor String canonicalName = JAXXCompiler.getCanonicalName(object); - String impl = compiler.getImportManager().getType(canonicalName); + String impl = compiler.getImportedType(canonicalName); init.append("new ").append(impl).append("("); Modified: trunk/jaxx-compiler/src/main/java/jaxx/compiler/decorators/HelpRootCompiledObjectDecorator.java =================================================================== --- trunk/jaxx-compiler/src/main/java/jaxx/compiler/decorators/HelpRootCompiledObjectDecorator.java 2011-03-18 11:18:55 UTC (rev 2242) +++ trunk/jaxx-compiler/src/main/java/jaxx/compiler/decorators/HelpRootCompiledObjectDecorator.java 2011-03-18 11:19:23 UTC (rev 2243) @@ -162,7 +162,7 @@ // } if (buffer.length() > 0) { - String type = compiler.getImportManager().getType(helpBrokerFQN); + String type = compiler.getImportedType(helpBrokerFQN); StringBuilder extraCode = new StringBuilder(type); extraCode.append(" _broker = getBroker();"); Modified: trunk/jaxx-compiler/src/main/java/jaxx/compiler/finalizers/AbstractFinalizer.java =================================================================== --- trunk/jaxx-compiler/src/main/java/jaxx/compiler/finalizers/AbstractFinalizer.java 2011-03-18 11:18:55 UTC (rev 2242) +++ trunk/jaxx-compiler/src/main/java/jaxx/compiler/finalizers/AbstractFinalizer.java 2011-03-18 11:19:23 UTC (rev 2243) @@ -73,11 +73,17 @@ * * @param file the file where to add the cloned method * @param method the method to clone + * @param types optional types to use to simplify the body of the method * @since 2.4 */ - protected void addMethod(JavaFile file, JavaMethod method) { + protected void addMethod(JavaFile file, JavaMethod method, String... types) { JavaMethod clonedMethod = JavaElementFactory.cloneMethod(method); + if (types.length > 0) { + String body = clonedMethod.getBody(); + String simplifiedBody = file.simplifyCode(body, types); + clonedMethod.setBody(simplifiedBody); + } file.addMethod(clonedMethod); } Modified: trunk/jaxx-compiler/src/main/java/jaxx/compiler/finalizers/DefaultFinalizer.java =================================================================== --- trunk/jaxx-compiler/src/main/java/jaxx/compiler/finalizers/DefaultFinalizer.java 2011-03-18 11:18:55 UTC (rev 2242) +++ trunk/jaxx-compiler/src/main/java/jaxx/compiler/finalizers/DefaultFinalizer.java 2011-03-18 11:19:23 UTC (rev 2243) @@ -50,6 +50,7 @@ import jaxx.runtime.JAXXObject; import jaxx.runtime.JAXXObjectDescriptor; import jaxx.runtime.JAXXUtil; +import jaxx.runtime.SwingUtil; import org.apache.commons.lang.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -316,7 +317,7 @@ PUBLIC, "<O extends Container> O", "getParentContainer", - "return SwingUtil.getParentContainer(source, clazz);", + "return %s.getParentContainer(source, clazz);", true, newArgument(TYPE_OBJECT, "source"), newArgument("Class<O>", "clazz") @@ -329,7 +330,7 @@ PUBLIC, "<O extends Container> O", "getParentContainer", - "return SwingUtil.getParentContainer(this, clazz);", + "return %s.getParentContainer(this, clazz);", true, newArgument("Class<O>", "clazz") ); @@ -351,7 +352,8 @@ PUBLIC | STATIC, JAXXObjectDescriptor.class.getName(), METHOD_NAME_$GET_JAXXOBJECT_DESCRIPTOR, - "return JAXXUtil.decodeCompressedJAXXObjectDescriptor(" + FIELD_NAME_$JAXX_OBJECT_DESCRIPTOR + ");", + "return %s.decodeCompressedJAXXObjectDescriptor(" + + FIELD_NAME_$JAXX_OBJECT_DESCRIPTOR + ");", false ); @@ -541,7 +543,10 @@ addSimpleField(javaFile, ALL_COMPONENTS_CREATED_FIELD); addJAXXObjectDescriptorField(compiler, javaFile); - addMethod(javaFile, GET_JAXX_OBJECT_DESCRIPTOR_METHOD); + addMethod(javaFile, + GET_JAXX_OBJECT_DESCRIPTOR_METHOD, + JAXXUtil.class.getName() + ); addPreviousValuesField(compiler, javaFile, root); @@ -673,7 +678,7 @@ // JAXXContext String type = - javaFile.getImportManager().getType(jaxxContextImplementorClass); + javaFile.getImportedType(jaxxContextImplementorClass); javaFile.addField(newField( PROTECTED | FINAL, @@ -691,8 +696,10 @@ javaFile.addMethod(GET_CONTEXT_VALUE_NAMED_METHOD); javaFile.addMethod(REMOVE_CONTEXT_VALUE_METHOD); javaFile.addMethod(REMOVE_CONTEXT_VALUE_NAMED_METHOD); - javaFile.addMethod(GET_PARENT_CONTAINER_METHOD); - javaFile.addMethod(GET_PARENT_CONTAINER_MORE_METHOD); + addMethod(javaFile, GET_PARENT_CONTAINER_METHOD, SwingUtil.class.getName()); + addMethod(javaFile, GET_PARENT_CONTAINER_MORE_METHOD, SwingUtil.class.getName()); +// javaFile.addMethod(GET_PARENT_CONTAINER_METHOD); +// javaFile.addMethod(GET_PARENT_CONTAINER_MORE_METHOD); // PropertyChangeSupport addPropertyChangeSupport(root, javaFile); @@ -1021,7 +1028,7 @@ // } // } if (!superclassIsJAXXObject) { - String prefix = compiler.getImportManager().getType(JAXXUtil.class); + String prefix = compiler.getImportedType(JAXXUtil.class); code.append(prefix); code.append(".initContext(this, " + PARAMETER_NAME_PARENT_CONTEXT + ");"); code.append(eol); Modified: trunk/jaxx-compiler/src/main/java/jaxx/compiler/finalizers/ValidatorFinalizer.java =================================================================== --- trunk/jaxx-compiler/src/main/java/jaxx/compiler/finalizers/ValidatorFinalizer.java 2011-03-18 11:18:55 UTC (rev 2242) +++ trunk/jaxx-compiler/src/main/java/jaxx/compiler/finalizers/ValidatorFinalizer.java 2011-03-18 11:19:23 UTC (rev 2243) @@ -102,10 +102,12 @@ ); if (found) { - compiler.setNeedSwingUtil(true); +// compiler.setNeedSwingUtil(true); + String type = + compiler.getImportedType(SwingUtil.class); // box the child component in a JxLayer child.setChildJavaCode( - SwingUtil.class.getSimpleName() + + type + ".boxComponentWithJxLayer(" + javaCode + ")"); } } @@ -117,9 +119,9 @@ BeanValidatorHandler.getValidators(compiler); // javaFile.addImport(Validator.class); // javaFile.addImport(ValidatorField.class); - javaFile.addImport(SwingValidatorUtil.class); +// javaFile.addImport(SwingValidatorUtil.class); String validatorUtilPrefix = - compiler.getImportManager().getType(SwingValidatorUtil.class) + + compiler.getImportedType(SwingValidatorUtil.class) + "."; compiler.getJavaFile().addMethod(JavaElementFactory.newMethod( @@ -173,7 +175,7 @@ // implements JAXXValidator addField(javaFile, VALIDATOR_IDS_FIELD); - String type = compiler.getImportManager().getType(validatorClass); + String type = compiler.getImportedType(validatorClass); String initializer = "return (" + type + "<?>) (validatorIds.contains(validatorId) ? " + @@ -198,8 +200,8 @@ String validatorId = TypeManager.getJavaCode(validator.getId()); - String type = compiler.getImportManager().getType(Validator.class); - String fieldType = compiler.getImportManager().getType(ValidatorField.class); + String type = compiler.getImportedType(Validator.class); + String fieldType = compiler.getImportedType(ValidatorField.class); String validatorAnnotation = type + "( validatorId = " + validatorId + ")"; Modified: trunk/jaxx-compiler/src/main/java/jaxx/compiler/script/ScriptManager.java =================================================================== --- trunk/jaxx-compiler/src/main/java/jaxx/compiler/script/ScriptManager.java 2011-03-18 11:18:55 UTC (rev 2242) +++ trunk/jaxx-compiler/src/main/java/jaxx/compiler/script/ScriptManager.java 2011-03-18 11:19:23 UTC (rev 2243) @@ -154,9 +154,9 @@ // for (FieldDescriptor field : fields) { // if (field.getName().equals(lhs)) { // //lhs.substring(lhs.lastIndexOf(".") + 1); -// String prefix = compiler.getImportManager().getType(JAXXUtil.class); +// String prefix = compiler.getImportedType(JAXXUtil.class); // node.firstToken.image = prefix + ".assignment(" + node.firstToken.image; -// String outputClassName = compiler.getImportManager().getType(compiler.getOutputClassName()); +// String outputClassName = compiler.getImportedType(compiler.getOutputClassName()); // node.lastToken.image = node.lastToken.image + ", \"" + lhs + "\", " + outputClassName + ".this)"; // } // } Modified: trunk/jaxx-compiler/src/main/java/jaxx/compiler/tags/DefaultComponentHandler.java =================================================================== --- trunk/jaxx-compiler/src/main/java/jaxx/compiler/tags/DefaultComponentHandler.java 2011-03-18 11:18:55 UTC (rev 2242) +++ trunk/jaxx-compiler/src/main/java/jaxx/compiler/tags/DefaultComponentHandler.java 2011-03-18 11:19:23 UTC (rev 2243) @@ -223,13 +223,15 @@ return id + ".setLocation(" + id + ".getX(), " + valueCode + ");"; } if (WIDTH_ATTRIBUTE.equals(name)) { - compiler.setNeedSwingUtil(true); + String type = compiler.getImportedType(SwingUtil.class); +// compiler.setNeedSwingUtil(true); // need to optimize case when both width and height are being assigned - return SwingUtil.class.getSimpleName() + ".setComponentWidth(" + id + "," + valueCode + ");"; + return type + ".setComponentWidth(" + id + "," + valueCode + ");"; } if (HEIGHT_ATTRIBUTE.equals(name)) { - compiler.setNeedSwingUtil(true); - return SwingUtil.class.getSimpleName() + ".setComponentHeight(" + id + "," + valueCode + ");"; +// compiler.setNeedSwingUtil(true); + String type = compiler.getImportedType(SwingUtil.class); + return type + ".setComponentHeight(" + id + "," + valueCode + ");"; } if (FONT_FACE_ATTRIBUTE.equals(name)) { return "if (" + id + ".getFont() != null) {\n " + id + ".setFont(new Font(" + valueCode + ", " + id + ".getFont().getStyle(), " + id + ".getFont().getSize()));\n}"; @@ -239,36 +241,36 @@ } if (FONT_WEIGHT_ATTRIBUTE.equals(name)) { if (valueCode.equals("\"bold\"")) { - compiler.addImport(Font.class); - return "if (" + id + ".getFont() != null) {\n " + id + ".setFont(" + id + ".getFont().deriveFont(" + id + ".getFont().getStyle() | Font.BOLD));\n}"; + String type = compiler.getImportedType(Font.class); + return "if (" + id + ".getFont() != null) {\n " + id + ".setFont(" + id + ".getFont().deriveFont(" + id + ".getFont().getStyle() | "+type+".BOLD));\n}"; } if (valueCode.equals("\"normal\"")) { - compiler.addImport(Font.class); - return "if (" + id + ".getFont() != null) {\n " + id + ".setFont(" + id + ".getFont().deriveFont(" + id + ".getFont().getStyle() & ~Font.BOLD));\n}"; + String type = compiler.getImportedType(Font.class); + return "if (" + id + ".getFont() != null) {\n " + id + ".setFont(" + id + ".getFont().deriveFont(" + id + ".getFont().getStyle() & ~"+type+".BOLD));\n}"; } if (!valueCode.startsWith("\"")) { - compiler.addImport(Font.class); + String type = compiler.getImportedType(Font.class); return "if (" + id + ".getFont() != null) {\n if ((" + valueCode + ").equals(\"bold\")) {\n " + - id + ".setFont(" + id + ".getFont().deriveFont(" + id + ".getFont().getStyle() | Font.BOLD));\n } else {\n " + - id + ".setFont(" + id + ".getFont().deriveFont(" + id + ".getFont().getStyle() & ~Font.BOLD));\n }\n}"; + id + ".setFont(" + id + ".getFont().deriveFont(" + id + ".getFont().getStyle() | "+type+".BOLD));\n } else {\n " + + id + ".setFont(" + id + ".getFont().deriveFont(" + id + ".getFont().getStyle() & ~"+type+".BOLD));\n }\n}"; } compiler.reportError("font-weight must be either \"normal\" or \"bold\", found " + valueCode); return ""; } if (FONT_STYLE_ATTRIBUTE.equals(name)) { if (valueCode.equals("\"italic\"")) { - compiler.addImport(Font.class); - return "if (" + id + ".getFont() != null) {\n " + id + ".setFont(" + id + ".getFont().deriveFont(" + id + ".getFont().getStyle() | Font.ITALIC));\n}"; + String type = compiler.getImportedType(Font.class); + return "if (" + id + ".getFont() != null) {\n " + id + ".setFont(" + id + ".getFont().deriveFont(" + id + ".getFont().getStyle() | "+type+".ITALIC));\n}"; } if (valueCode.equals("\"normal\"")) { - compiler.addImport(Font.class); - return "if (" + id + ".getFont() != null) {\n " + id + ".setFont(" + id + ".getFont().deriveFont(" + id + ".getFont().getStyle() & ~Font.ITALIC));\n}"; + String type = compiler.getImportedType(Font.class); + return "if (" + id + ".getFont() != null) {\n " + id + ".setFont(" + id + ".getFont().deriveFont(" + id + ".getFont().getStyle() & ~"+type+".ITALIC));\n}"; } if (!valueCode.startsWith("\"")) { - compiler.addImport(Font.class); + String type = compiler.getImportedType(Font.class); return "if (" + id + ".getFont() != null) {\n if ((" + valueCode + ").equals(\"italic\")) {\n " + - id + ".setFont(" + id + ".getFont().deriveFont(" + id + ".getFont().getStyle() | Font.ITALIC));\n } else {\n " + - id + ".setFont(" + id + ".getFont().deriveFont(" + id + ".getFont().getStyle() & ~Font.ITALIC));\n }\n}"; + id + ".setFont(" + id + ".getFont().deriveFont(" + id + ".getFont().getStyle() | "+type+".ITALIC));\n } else {\n " + + id + ".setFont(" + id + ".getFont().deriveFont(" + id + ".getFont().getStyle() & ~"+type+".ITALIC));\n }\n}"; } compiler.reportError("font-style must be either \"normal\" or \"italic\", found " + valueCode); return ""; @@ -315,11 +317,14 @@ if (ICON_ATTRIBUTE.equals(propertyName)) { if (!(stringValue.startsWith("{") || stringValue.endsWith("}"))) { // this is a customized icon, add the icon creation code +// compiler.setNeedSwingUtil(true); + String type = + compiler.getImportedType(SwingUtil.class); + if (compiler.getConfiguration().isUseUIManagerForIcon()) { - compiler.setNeedSwingUtil(true); - stringValue = "{" + SwingUtil.class.getSimpleName() + ".getUIManagerIcon(\"" + stringValue + "\")}"; + stringValue = "{" + type + ".getUIManagerIcon(\"" + stringValue + "\")}"; } else { - stringValue = "{" + SwingUtil.class.getSimpleName() + ".createImageIcon(\"" + stringValue + "\")}"; + stringValue = "{" + type + ".createImageIcon(\"" + stringValue + "\")}"; } } } else if (ACTION_ICON_ATTRIBUTE.equals(propertyName)) { @@ -330,11 +335,12 @@ return; } propertyName = ICON_ATTRIBUTE; +// compiler.setNeedSwingUtil(true); + String type = compiler.getImportedType(SwingUtil.class); if (compiler.getConfiguration().isUseUIManagerForIcon()) { - compiler.setNeedSwingUtil(true); - stringValue = "{" + SwingUtil.class.getSimpleName() + ".getUIManagerActionIcon(\"" + stringValue + "\")}"; + stringValue = "{" + type + ".getUIManagerActionIcon(\"" + stringValue + "\")}"; } else { - stringValue = "{" + SwingUtil.class.getSimpleName() + ".createActionIcon(\"" + stringValue + "\")}"; + stringValue = "{" + type + ".createActionIcon(\"" + stringValue + "\")}"; } } super.setAttribute(object, propertyName, stringValue, inline, compiler); Modified: trunk/jaxx-compiler/src/main/java/jaxx/compiler/tags/swing/JRadioButtonHandler.java =================================================================== --- trunk/jaxx-compiler/src/main/java/jaxx/compiler/tags/swing/JRadioButtonHandler.java 2011-03-18 11:18:55 UTC (rev 2242) +++ trunk/jaxx-compiler/src/main/java/jaxx/compiler/tags/swing/JRadioButtonHandler.java 2011-03-18 11:19:23 UTC (rev 2243) @@ -93,12 +93,12 @@ compiler.registerCompiledObject(buttonGroup); } } - String type = compiler.getImportManager().getType( + String type = compiler.getImportedType( ButtonGroup.class.getName()); return "{ " + type + " $buttonGroup = " + valueCode + "; " + id + ".putClientProperty(\"$buttonGroup\", $buttonGroup); $buttonGroup.add(" + id + "); }\n"; } else if (name.equals(VALUE_PROPERTY)) { - String type = compiler.getImportManager().getType( + String type = compiler.getImportedType( JAXXButtonGroup.class.getName()); return "{ " + id + ".putClientProperty(\"" + JAXXButtonGroup.VALUE_CLIENT_PROPERTY + "\", " + valueCode + "); Object $buttonGroup = " + id + ".getClientProperty(\"" + JAXXButtonGroup.BUTTON8GROUP_CLIENT_PROPERTY + "\");" + " if ($buttonGroup instanceof " + type + ") { ((" + type + ") $buttonGroup).updateSelectedValue(); } }\n"; Modified: trunk/jaxx-compiler/src/main/java/jaxx/compiler/tags/swing/JSpinnerHandler.java =================================================================== --- trunk/jaxx-compiler/src/main/java/jaxx/compiler/tags/swing/JSpinnerHandler.java 2011-03-18 11:18:55 UTC (rev 2242) +++ trunk/jaxx-compiler/src/main/java/jaxx/compiler/tags/swing/JSpinnerHandler.java 2011-03-18 11:19:23 UTC (rev 2243) @@ -114,7 +114,7 @@ if (spinner.value == null) { spinner.value = spinner.minimum; } - String type = compiler.getImportManager().getType(SpinnerNumberModel.class); + String type = compiler.getImportedType(SpinnerNumberModel.class); spinner.setConstructorParams("new " + type + "(" + spinner.value + ", " + spinner.minimum + ", " + spinner.maximum + ", 1)"); } Modified: trunk/jaxx-compiler/src/main/java/jaxx/compiler/tags/swing/JTabbedPaneHandler.java =================================================================== --- trunk/jaxx-compiler/src/main/java/jaxx/compiler/tags/swing/JTabbedPaneHandler.java 2011-03-18 11:18:55 UTC (rev 2242) +++ trunk/jaxx-compiler/src/main/java/jaxx/compiler/tags/swing/JTabbedPaneHandler.java 2011-03-18 11:19:23 UTC (rev 2243) @@ -83,7 +83,7 @@ } int tabIndex = ++tabCount - 1; - String type = compiler.getImportManager().getType(TabInfoPropertyChangeListener.class); + String type = compiler.getImportedType(TabInfoPropertyChangeListener.class); appendAdditionCode(tabInfo.getId() + ".addPropertyChangeListener(new " + type + "(" + getId() + ", " + tabIndex + "));"); String title = tabInfo.getTitle(); Modified: trunk/jaxx-compiler/src/main/java/jaxx/compiler/tags/swing/JTextComponentHandler.java =================================================================== --- trunk/jaxx-compiler/src/main/java/jaxx/compiler/tags/swing/JTextComponentHandler.java 2011-03-18 11:18:55 UTC (rev 2242) +++ trunk/jaxx-compiler/src/main/java/jaxx/compiler/tags/swing/JTextComponentHandler.java 2011-03-18 11:19:23 UTC (rev 2243) @@ -89,7 +89,7 @@ String valueCode, JAXXCompiler compiler) throws CompilerException { if (name.equals(ATTRIBUTE_TEXT)) { - String prefix = compiler.getImportManager().getType(SwingUtil.class); + String prefix = compiler.getImportedType(SwingUtil.class); return prefix + ".setText(" + id + ", " + valueCode + ");" + JAXXCompiler.getLineSeparator(); Modified: trunk/jaxx-compiler/src/main/java/jaxx/compiler/tags/validator/BeanValidatorHandler.java =================================================================== --- trunk/jaxx-compiler/src/main/java/jaxx/compiler/tags/validator/BeanValidatorHandler.java 2011-03-18 11:18:55 UTC (rev 2242) +++ trunk/jaxx-compiler/src/main/java/jaxx/compiler/tags/validator/BeanValidatorHandler.java 2011-03-18 11:19:23 UTC (rev 2243) @@ -466,7 +466,7 @@ ); withError = true; } else { - String prefix = compiler.getImportManager().getType(uiClazz.getName()); + String prefix = compiler.getImportedType(uiClazz.getName()); String code = handler.getSetPropertyCode( getJavaCode(), UI_CLASS_ATTRIBUTE, @@ -625,7 +625,7 @@ } } - String prefix = compiler.getImportManager().getType(SwingValidatorUtil.class); + String prefix = compiler.getImportedType(SwingValidatorUtil.class); String code = prefix + ".registerErrorListMouseListener(" + errorList + ");"; @@ -654,7 +654,7 @@ } } - String prefix = compiler.getImportManager().getType(SwingValidatorUtil.class); + String prefix = compiler.getImportedType(SwingValidatorUtil.class); String code = prefix + ".registerErrorTableMouseListener(" + errorTable + @@ -752,12 +752,12 @@ } String beanClassName = beanInfo.getJAXXBeanDescriptor().getClassDescriptor().getName(); - String type = compiler.getImportManager().getType(beanClassName); + String type = compiler.getImportedType(beanClassName); // contextName must be in constructor to able to init validator with his correct contextName String constructorParams = type + ".class, " + TypeManager.getJavaCode(contextName); // setConstructorParams(constructorParams); - String prefix = compiler.getImportManager().getType(SwingValidatorUtil.class); + String prefix = compiler.getImportedType(SwingValidatorUtil.class); setInitializer( prefix + ".newValidator(" + constructorParams + ")" ); Modified: trunk/jaxx-compiler/src/main/java/jaxx/compiler/tasks/GenerateConstructorsTask.java =================================================================== --- trunk/jaxx-compiler/src/main/java/jaxx/compiler/tasks/GenerateConstructorsTask.java 2011-03-18 11:18:55 UTC (rev 2242) +++ trunk/jaxx-compiler/src/main/java/jaxx/compiler/tasks/GenerateConstructorsTask.java 2011-03-18 11:19:23 UTC (rev 2243) @@ -494,7 +494,7 @@ if (!superclassIsJAXXObject) { // call explicitly the init code of the parentContext - String prefix = compiler.getImportManager().getType(JAXXUtil.class); + String prefix = compiler.getImportedType(JAXXUtil.class); code.append(prefix); code.append(".initContext(this, " + PARAMETER_NAME_PARENT_CONTEXT + ");"); code.append(eol); Modified: trunk/jaxx-compiler/src/main/java/jaxx/compiler/tasks/GenerateTask.java =================================================================== --- trunk/jaxx-compiler/src/main/java/jaxx/compiler/tasks/GenerateTask.java 2011-03-18 11:18:55 UTC (rev 2242) +++ trunk/jaxx-compiler/src/main/java/jaxx/compiler/tasks/GenerateTask.java 2011-03-18 11:19:23 UTC (rev 2243) @@ -31,8 +31,6 @@ import jaxx.compiler.java.JavaConstructor; import jaxx.compiler.java.JavaFile; import jaxx.compiler.java.JavaFileGenerator; -import jaxx.runtime.JAXXUtil; -import jaxx.runtime.SwingUtil; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.nuiton.eugene.java.extension.ImportsManager; @@ -104,10 +102,7 @@ String packageName = javaFile.getPackageName(); // optimize imports - List<String> imports = optimizeImports( - javaFile, - packageName, - compiler.isNeedSwingUtil()); + List<String> imports = optimizeImports(javaFile, packageName); String packageToExclude = packageName + ".*"; @@ -116,7 +111,7 @@ if (!packageToExclude.equals(importFQN) && !imports.contains(importFQN)) { imports.add(importFQN); - } + } } // set them to the file to generate @@ -128,8 +123,7 @@ } public List<String> optimizeImports(JavaFile f, - String packageName, - boolean needSwingUtil) { + String packageName) { ImportsManager importsManager = f.getImportManager(); @@ -171,13 +165,13 @@ // optimize constructors parameters optimizeConstructorParameters(f, importsManager); - importsManager.addImport(JAXXUtil.class); - if (!f.isSuperclassIsJAXXObject() || needSwingUtil) { - - // while implementing JAXXObject contract we sure need the - // SwingUtil class - importsManager.addImport(SwingUtil.class); - } +// importsManager.addImport(JAXXUtil.class); +// if (!f.isSuperclassIsJAXXObject() || needSwingUtil) { +// +// // while implementing JAXXObject contract we sure need the +// // SwingUtil class +// importsManager.addImport(SwingUtil.class); +// } result = importsManager.getImports(packageName); result.remove(packageName + ".*"); if (log.isDebugEnabled()) { Modified: trunk/maven-jaxx-plugin/src/test/java/org/nuiton/jaxx/plugin/Bug1404Test.java =================================================================== --- trunk/maven-jaxx-plugin/src/test/java/org/nuiton/jaxx/plugin/Bug1404Test.java 2011-03-18 11:18:55 UTC (rev 2242) +++ trunk/maven-jaxx-plugin/src/test/java/org/nuiton/jaxx/plugin/Bug1404Test.java 2011-03-18 11:19:23 UTC (rev 2243) @@ -39,8 +39,9 @@ GenerateMojo mojo = getMojo(); mojo.execute(); - assertNumberJaxxFiles(2); + assertNumberJaxxFiles(3); checkPattern(mojo, "import jaxx.runtime.SwingUtil;", true); + checkPattern(mojo, "import jaxx.runtime.JAXXUtil;", true); } } \ No newline at end of file Copied: trunk/maven-jaxx-plugin/src/test/resources/org/nuiton/jaxx/plugin/bug1404Test/Test2.jaxx (from rev 2241, trunk/maven-jaxx-plugin/src/test/resources/org/nuiton/jaxx/plugin/bug1404Test/Test1.jaxx) =================================================================== --- trunk/maven-jaxx-plugin/src/test/resources/org/nuiton/jaxx/plugin/bug1404Test/Test2.jaxx (rev 0) +++ trunk/maven-jaxx-plugin/src/test/resources/org/nuiton/jaxx/plugin/bug1404Test/Test2.jaxx 2011-03-18 11:19:23 UTC (rev 2243) @@ -0,0 +1,27 @@ +<!-- + #%L + JAXX :: Maven plugin + + $Id$ + $HeadURL$ + %% + Copyright (C) 2008 - 2011 CodeLutin + %% + 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% + --> + <TestParent> + <JLabel id='icon' icon='myicon.png'/> + </TestParent>