Author: alexsmirnov
Date: 2010-07-01 20:31:47 -0400 (Thu, 01 Jul 2010)
New Revision: 17703
Added:
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/freemarker/DefaultImports.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/freemarker/TemplatesFolder.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/java/LibraryModel.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/TemplateModel.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/model/CdkCaseElement.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/model/CdkDefaultElement.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/model/CdkSwitchElement.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/CaseStatement.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/FreeMarkerTemplateStatementBase.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/SwitchStatement.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/TemplateStatementImpl.java
root/cdk/branches/RF8755/plugins/generator/src/main/resources/META-INF/templates/java/case.ftl
root/cdk/branches/RF8755/plugins/generator/src/main/resources/META-INF/templates/java/switch.ftl
root/cdk/branches/RF8755/plugins/generator/src/main/resources/META-INF/templates/java/util.ftl
root/cdk/branches/RF8755/plugins/generator/src/test/java/org/richfaces/cdk/templatecompiler/statements/
root/cdk/branches/RF8755/plugins/generator/src/test/java/org/richfaces/cdk/templatecompiler/statements/FreeMarkerTemplateStatementTest.java
root/cdk/branches/RF8755/plugins/generator/src/test/java/org/richfaces/cdk/templatecompiler/statements/FreeMarkerTemplateStatementTest1.java
root/cdk/branches/RF8755/plugins/generator/src/test/java/org/richfaces/cdk/templatecompiler/statements/StatatementsContainerTest.java
root/cdk/branches/RF8755/plugins/generator/src/test/resources/META-INF/templates/java/
root/cdk/branches/RF8755/plugins/generator/src/test/resources/META-INF/templates/java/addConstant.ftl
root/cdk/branches/RF8755/plugins/generator/src/test/resources/META-INF/templates/java/addImport.ftl
root/cdk/branches/RF8755/plugins/generator/src/test/resources/META-INF/templates/java/addMethod.ftl
root/cdk/branches/RF8755/plugins/generator/src/test/resources/META-INF/templates/java/foo.ftl
Removed:
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/freemarker/FreeMakerModule.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/JavaClassConfiguration.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/TemplateStatementBase.java
Modified:
root/cdk/branches/RF8755/plugins/commons/src/test/java/org/richfaces/cdk/CdkTestRunner.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/Generator.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/freemarker/CdkConfiguration.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/java/BehaviorClassGenerator.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/java/ClassGeneratorModule.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/java/ComponentClassGenerator.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/java/ConverterClassGenerator.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/java/EventSourceInterfaceGenerator.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/java/ValidatorClassGenerator.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/java/taghandler/ListenerTagHandlerGenerator.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/java/taghandler/TagHandlerClassGenerator.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/RendererClassGenerator.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/RendererClassVisitor.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/TemplateModule.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/model/ModelFragment.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/model/TemplateVisitor.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/ConstantReturnMethodBodyStatement.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/DefineObjectStatement.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/ElementStatement.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/EncodeMethodPrefaceStatement.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/EndElementStatement.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/ForEachStatement.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/HelperMethodFactoryImpl.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/IfElseStatement.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/IfStatement.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/StartElementStatement.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/StatementsContainer.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/WriteAttributeStatement.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/WriteAttributesSetStatement.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/WriteTextStatement.java
root/cdk/branches/RF8755/plugins/generator/src/main/resources/META-INF/schema/cdk-template.xsd
root/cdk/branches/RF8755/plugins/generator/src/test/java/org/richfaces/cdk/LibraryBuilderTest.java
root/cdk/branches/RF8755/plugins/generator/src/test/java/org/richfaces/cdk/generate/java/AbstractClassGeneratorTest.java
Log:
Merged revisions 17695 via svnmerge from
https://svn.jboss.org/repos/richfaces/root/cdk/trunk
.......
r17695 | nbelaevski | 2010-07-01 06:15:39 -0700 (Thu, 01 Jul 2010) | 1 line
Added support for cdk:switch/cdk:case/cdk:default elements
.......
tested improved templates
Modified:
root/cdk/branches/RF8755/plugins/commons/src/test/java/org/richfaces/cdk/CdkTestRunner.java
===================================================================
---
root/cdk/branches/RF8755/plugins/commons/src/test/java/org/richfaces/cdk/CdkTestRunner.java 2010-07-01
19:58:07 UTC (rev 17702)
+++
root/cdk/branches/RF8755/plugins/commons/src/test/java/org/richfaces/cdk/CdkTestRunner.java 2010-07-02
00:31:47 UTC (rev 17703)
@@ -45,6 +45,7 @@
import com.google.inject.Injector;
import com.google.inject.Module;
import com.google.inject.Provider;
+import com.google.inject.ScopeAnnotation;
import com.google.inject.TypeLiteral;
import com.google.inject.binder.AnnotatedBindingBuilder;
@@ -155,29 +156,11 @@
Class<? extends Annotation> annotationType =
annotation.annotationType();
if (/* annotationType.isAnnotationPresent(Qualifier.class)||
*/annotationType
.isAnnotationPresent(BindingAnnotation.class)) {
- Implementation implementation =
annotationType.getAnnotation(Implementation.class);
- if (null != implementation) {
- try {
- Annotation value =
-
implementation.value().getConstructor(annotationType).newInstance(annotation);
- builder.annotatedWith(value);
- } catch (SecurityException e) {
- throw new RuntimeException(e);
- } catch (NoSuchMethodException e) {
- builder.annotatedWith(annotationType);
- } catch (IllegalArgumentException e) {
- throw new RuntimeException(e);
- } catch (InstantiationException e) {
- throw new RuntimeException(e);
- } catch (IllegalAccessException e) {
- throw new RuntimeException(e);
- } catch (InvocationTargetException e) {
- throw new RuntimeException(e);
- }
- } else {
- builder.annotatedWith(annotationType);
- }
+ builder.annotatedWith(annotation);
}
+ if (annotationType.isAnnotationPresent(ScopeAnnotation.class)){
+ builder.in(annotationType);
+ }
}
Binding binding = fields.get(field);
if (null != binding.getValue()) {
Modified:
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/Generator.java
===================================================================
---
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/Generator.java 2010-07-01
19:58:07 UTC (rev 17702)
+++
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/Generator.java 2010-07-02
00:31:47 UTC (rev 17703)
@@ -34,7 +34,6 @@
import java.util.Map;
import org.richfaces.cdk.apt.AptModule;
-import org.richfaces.cdk.generate.freemarker.FreeMakerModule;
import org.richfaces.cdk.generate.java.ClassGeneratorModule;
import org.richfaces.cdk.generate.taglib.TaglibModule;
import org.richfaces.cdk.model.ModelModule;
@@ -115,7 +114,7 @@
public void init() {
injector =
Guice.createInjector(Stage.PRODUCTION, new CdkConfigurationModule(), new
AptModule(), new ModelModule(),
- new FreeMakerModule(),new ClassGeneratorModule(), new TemplateModule(),
+ new ClassGeneratorModule(), new TemplateModule(),
new XmlModule(), new TaglibModule());
if (!log.isDebugEnabled()) {
Modified:
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/freemarker/CdkConfiguration.java
===================================================================
---
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/freemarker/CdkConfiguration.java 2010-07-01
19:58:07 UTC (rev 17702)
+++
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/freemarker/CdkConfiguration.java 2010-07-02
00:31:47 UTC (rev 17703)
@@ -46,6 +46,8 @@
public class CdkConfiguration extends Configuration implements FreeMarkerRenderer {
private static final String TEMPLATES = "/META-INF/templates";
+
+ private String templatesFolder=TEMPLATES;
private Logger log;
@@ -74,6 +76,11 @@
}
}
}
+
+ @Inject(optional=true)
+ public synchronized void setImports(@DefaultImports Map<String,String> map) {
+ super.setAutoImports(map);
+ }
@Override
public void writeTemplate(String templateName, Object object, Writer writer) throws
IOException, TemplateException {
@@ -102,9 +109,19 @@
/**
* <p class="changed_added_4_0"></p>
+ * @param templatesFolder the templatesFolder to set
+ */
+ @Inject(optional=true)
+ public void setTemplatesFolder(@TemplatesFolder String templatesFolder) {
+ setClassForTemplateLoading(this.getClass(), templatesFolder);
+ this.templatesFolder = templatesFolder;
+ }
+
+ /**
+ * <p class="changed_added_4_0"></p>
* @return the templates
*/
- public static String getTemplatesFolder() {
- return TEMPLATES;
+ public String getTemplatesFolder() {
+ return templatesFolder;
}
}
Added:
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/freemarker/DefaultImports.java
===================================================================
---
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/freemarker/DefaultImports.java
(rev 0)
+++
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/freemarker/DefaultImports.java 2010-07-02
00:31:47 UTC (rev 17703)
@@ -0,0 +1,48 @@
+/*
+ * $Id$
+ *
+ * License Agreement.
+ *
+ * Rich Faces - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.richfaces.cdk.generate.freemarker;
+
+import static java.lang.annotation.ElementType.*;
+import static java.lang.annotation.RetentionPolicy.*;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+import com.google.inject.BindingAnnotation;
+
+/**
+ * <p class="changed_added_4_0">
+ * Marks {@link org.richfaces.cdk.generate.freemarker.FreeMarkerRenderer} instance that
is targeted to work with JSF
+ * library model
+ * </p>
+ *
+ * @author asmirnov(a)exadel.com
+ *
+ */
+@Retention(RUNTIME)
+@Target({ FIELD, PARAMETER, METHOD })
+@BindingAnnotation
+public @interface DefaultImports {
+
+}
Property changes on:
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/freemarker/DefaultImports.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Deleted:
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/freemarker/FreeMakerModule.java
===================================================================
---
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/freemarker/FreeMakerModule.java 2010-07-01
19:58:07 UTC (rev 17702)
+++
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/freemarker/FreeMakerModule.java 2010-07-02
00:31:47 UTC (rev 17703)
@@ -1,40 +0,0 @@
-/*
- * $Id$
- *
- * License Agreement.
- *
- * Rich Faces - Natural Ajax for Java Server Faces (JSF)
- *
- * Copyright (C) 2007 Exadel, Inc.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License version 2.1 as published by the Free Software Foundation.
- *
- * This library 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
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-package org.richfaces.cdk.generate.freemarker;
-
-import com.google.inject.AbstractModule;
-
-/**
- * <p class="changed_added_4_0"></p>
- * @author asmirnov(a)exadel.com
- *
- */
-public class FreeMakerModule extends AbstractModule {
-
- @Override
- protected void configure() {
- bind(FreeMarkerRenderer.class).to(CdkConfiguration.class);
- }
-
-}
Added:
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/freemarker/TemplatesFolder.java
===================================================================
---
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/freemarker/TemplatesFolder.java
(rev 0)
+++
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/freemarker/TemplatesFolder.java 2010-07-02
00:31:47 UTC (rev 17703)
@@ -0,0 +1,16 @@
+package org.richfaces.cdk.generate.freemarker;
+
+import static java.lang.annotation.ElementType.*;
+import static java.lang.annotation.RetentionPolicy.*;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+import com.google.inject.BindingAnnotation;
+
+@Retention(RUNTIME)
+@Target({ FIELD, PARAMETER, METHOD })
+@BindingAnnotation
+public @interface TemplatesFolder {
+
+}
Property changes on:
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/freemarker/TemplatesFolder.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified:
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/java/BehaviorClassGenerator.java
===================================================================
---
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/java/BehaviorClassGenerator.java 2010-07-01
19:58:07 UTC (rev 17702)
+++
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/java/BehaviorClassGenerator.java 2010-07-02
00:31:47 UTC (rev 17703)
@@ -43,7 +43,7 @@
public class BehaviorClassGenerator extends FreeMarkerWriter<BehaviorModel>
implements CdkWriter {
@Inject
- public BehaviorClassGenerator(FreeMarkerRenderer configuration,
+ public BehaviorClassGenerator(@LibraryModel FreeMarkerRenderer configuration,
@Output(Outputs.JAVA_CLASSES) FileManager output) {
super(configuration, output);
}
Modified:
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/java/ClassGeneratorModule.java
===================================================================
---
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/java/ClassGeneratorModule.java 2010-07-01
19:58:07 UTC (rev 17702)
+++
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/java/ClassGeneratorModule.java 2010-07-02
00:31:47 UTC (rev 17703)
@@ -23,15 +23,16 @@
package org.richfaces.cdk.generate.java;
-import java.util.Set;
-
import org.richfaces.cdk.CdkWriter;
+import org.richfaces.cdk.generate.freemarker.CdkConfiguration;
+import org.richfaces.cdk.generate.freemarker.FreeMakerUtils;
+import org.richfaces.cdk.generate.freemarker.FreeMarkerRenderer;
import org.richfaces.cdk.generate.freemarker.LibraryModelWrapper;
import org.richfaces.cdk.generate.java.taghandler.ListenerTagHandlerGenerator;
import org.richfaces.cdk.generate.java.taghandler.TagHandlerWriter;
-import com.google.inject.PrivateModule;
-import com.google.inject.TypeLiteral;
+import com.google.inject.AbstractModule;
+import com.google.inject.PrivateBinder;
import com.google.inject.multibindings.Multibinder;
import freemarker.template.ObjectWrapper;
@@ -43,7 +44,7 @@
* @author asmirnov(a)exadel.com
*
*/
-public class ClassGeneratorModule extends PrivateModule {
+public class ClassGeneratorModule extends AbstractModule {
/*
* (non-Javadoc)
@@ -60,9 +61,11 @@
setBinder.addBinding().to(EventSourceInterfaceGenerator.class);
setBinder.addBinding().to(TagHandlerWriter.class);
setBinder.addBinding().to(ListenerTagHandlerGenerator.class);
- TypeLiteral<Set<CdkWriter>> writersType = new
TypeLiteral<Set<CdkWriter>>(){};
- expose(writersType);
- bind(ObjectWrapper.class).to(LibraryModelWrapper.class);
+ PrivateBinder privateBinder = binder().newPrivateBinder();
+
privateBinder.bind(FreeMarkerRenderer.class).annotatedWith(LibraryModel.class).to(CdkConfiguration.class);
+
privateBinder.expose(FreeMarkerRenderer.class).annotatedWith(LibraryModel.class);
+ privateBinder.bind(ObjectWrapper.class).to(LibraryModelWrapper.class);
+ privateBinder.bind(FreeMakerUtils.class);
}
}
Modified:
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/java/ComponentClassGenerator.java
===================================================================
---
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/java/ComponentClassGenerator.java 2010-07-01
19:58:07 UTC (rev 17702)
+++
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/java/ComponentClassGenerator.java 2010-07-02
00:31:47 UTC (rev 17703)
@@ -47,7 +47,7 @@
public class ComponentClassGenerator extends FreeMarkerWriter<ComponentModel>
implements CdkWriter {
@Inject
- public ComponentClassGenerator(FreeMarkerRenderer configuration,
@Output(Outputs.JAVA_CLASSES) FileManager output) {
+ public ComponentClassGenerator(@LibraryModel FreeMarkerRenderer configuration,
@Output(Outputs.JAVA_CLASSES) FileManager output) {
super(configuration, output);
}
Modified:
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/java/ConverterClassGenerator.java
===================================================================
---
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/java/ConverterClassGenerator.java 2010-07-01
19:58:07 UTC (rev 17702)
+++
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/java/ConverterClassGenerator.java 2010-07-02
00:31:47 UTC (rev 17703)
@@ -43,7 +43,7 @@
public class ConverterClassGenerator extends FreeMarkerWriter<ConverterModel>
implements CdkWriter {
@Inject
- public ConverterClassGenerator(FreeMarkerRenderer configuration,
+ public ConverterClassGenerator(@LibraryModel FreeMarkerRenderer configuration,
@Output(Outputs.JAVA_CLASSES) FileManager output) {
super(configuration, output);
}
Modified:
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/java/EventSourceInterfaceGenerator.java
===================================================================
---
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/java/EventSourceInterfaceGenerator.java 2010-07-01
19:58:07 UTC (rev 17702)
+++
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/java/EventSourceInterfaceGenerator.java 2010-07-02
00:31:47 UTC (rev 17703)
@@ -44,7 +44,7 @@
public class EventSourceInterfaceGenerator extends FreeMarkerWriter<EventModel>
implements CdkWriter {
@Inject
- public EventSourceInterfaceGenerator(FreeMarkerRenderer configuration,
+ public EventSourceInterfaceGenerator(@LibraryModel FreeMarkerRenderer configuration,
@Output(Outputs.JAVA_CLASSES) FileManager output) {
super(configuration, output);
}
Added:
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/java/LibraryModel.java
===================================================================
---
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/java/LibraryModel.java
(rev 0)
+++
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/java/LibraryModel.java 2010-07-02
00:31:47 UTC (rev 17703)
@@ -0,0 +1,48 @@
+/*
+ * $Id$
+ *
+ * License Agreement.
+ *
+ * Rich Faces - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.richfaces.cdk.generate.java;
+
+import static java.lang.annotation.ElementType.*;
+import static java.lang.annotation.RetentionPolicy.*;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+import com.google.inject.BindingAnnotation;
+
+/**
+ * <p class="changed_added_4_0">
+ * Marks {@link org.richfaces.cdk.generate.freemarker.FreeMarkerRenderer} instance that
is targeted to work with JSF
+ * library model
+ * </p>
+ *
+ * @author asmirnov(a)exadel.com
+ *
+ */
+@Retention(RUNTIME)
+@Target({ FIELD, PARAMETER, METHOD })
+@BindingAnnotation
+public @interface LibraryModel {
+
+}
Property changes on:
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/java/LibraryModel.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified:
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/java/ValidatorClassGenerator.java
===================================================================
---
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/java/ValidatorClassGenerator.java 2010-07-01
19:58:07 UTC (rev 17702)
+++
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/java/ValidatorClassGenerator.java 2010-07-02
00:31:47 UTC (rev 17703)
@@ -43,7 +43,7 @@
public class ValidatorClassGenerator extends FreeMarkerWriter<ValidatorModel>
implements CdkWriter {
@Inject
- public ValidatorClassGenerator(FreeMarkerRenderer configuration,
@Output(Outputs.JAVA_CLASSES) FileManager output) {
+ public ValidatorClassGenerator(@LibraryModel FreeMarkerRenderer configuration,
@Output(Outputs.JAVA_CLASSES) FileManager output) {
super(configuration, output);
}
Modified:
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/java/taghandler/ListenerTagHandlerGenerator.java
===================================================================
---
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/java/taghandler/ListenerTagHandlerGenerator.java 2010-07-01
19:58:07 UTC (rev 17702)
+++
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/java/taghandler/ListenerTagHandlerGenerator.java 2010-07-02
00:31:47 UTC (rev 17703)
@@ -33,6 +33,7 @@
import org.richfaces.cdk.annotations.TagType;
import org.richfaces.cdk.generate.freemarker.FreeMarkerRenderer;
import org.richfaces.cdk.generate.freemarker.FreeMarkerWriter;
+import org.richfaces.cdk.generate.java.LibraryModel;
import org.richfaces.cdk.model.ComponentLibrary;
import org.richfaces.cdk.model.EventModel;
import org.richfaces.cdk.model.TagModel;
@@ -46,7 +47,7 @@
public class ListenerTagHandlerGenerator extends
FreeMarkerWriter<TagWithModel<EventModel>> implements CdkWriter {
@Inject
- public ListenerTagHandlerGenerator(FreeMarkerRenderer configuration,
+ public ListenerTagHandlerGenerator(@LibraryModel FreeMarkerRenderer configuration,
@Output(Outputs.JAVA_CLASSES) FileManager output) {
super(configuration, output);
}
Modified:
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/java/taghandler/TagHandlerClassGenerator.java
===================================================================
---
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/java/taghandler/TagHandlerClassGenerator.java 2010-07-01
19:58:07 UTC (rev 17702)
+++
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/java/taghandler/TagHandlerClassGenerator.java 2010-07-02
00:31:47 UTC (rev 17703)
@@ -31,6 +31,7 @@
import org.richfaces.cdk.Output;
import org.richfaces.cdk.Outputs;
import org.richfaces.cdk.generate.freemarker.FreeMarkerRenderer;
+import org.richfaces.cdk.generate.java.LibraryModel;
import org.richfaces.cdk.model.ModelElementBase;
import org.richfaces.cdk.model.TagModel;
import org.richfaces.cdk.model.Trackable;
@@ -52,7 +53,7 @@
private final FreeMarkerRenderer configuration;
@Inject
- public TagHandlerClassGenerator(FreeMarkerRenderer configuration,
@Output(Outputs.JAVA_CLASSES) FileManager output) {
+ public TagHandlerClassGenerator(@LibraryModel FreeMarkerRenderer configuration,
@Output(Outputs.JAVA_CLASSES) FileManager output) {
this.configuration = configuration;
this.output = output;
}
Deleted:
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/JavaClassConfiguration.java
===================================================================
---
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/JavaClassConfiguration.java 2010-07-01
19:58:07 UTC (rev 17702)
+++
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/JavaClassConfiguration.java 2010-07-02
00:31:47 UTC (rev 17703)
@@ -1,92 +0,0 @@
-/*
- * $Id$
- *
- * License Agreement.
- *
- * Rich Faces - Natural Ajax for Java Server Faces (JSF)
- *
- * Copyright (C) 2007 Exadel, Inc.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License version 2.1 as published by the Free Software Foundation.
- *
- * This library 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
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-package org.richfaces.cdk.templatecompiler;
-
-import java.io.IOException;
-import java.io.StringWriter;
-import java.io.Writer;
-import java.util.HashMap;
-import java.util.Map;
-
-import org.richfaces.cdk.generate.freemarker.FreeMarkerRenderer;
-
-import freemarker.template.Configuration;
-import freemarker.template.Template;
-import freemarker.template.TemplateException;
-
-/**
- * <p class="changed_added_4_0"></p>
- * TODO: injection.
- * @author asmirnov(a)exadel.com
- */
-public class JavaClassConfiguration extends Configuration implements FreeMarkerRenderer
{
- private static final String TEMPLATES = "/META-INF/templates/java";
-
- public JavaClassConfiguration() {
-
- // TODO set proper template loader.
- setClassForTemplateLoading(this.getClass(), TEMPLATES);
-
- // TODO create an object wrapper for library model.
- setObjectWrapper(new JavaClassModelWrapper());
-
- // Add context variables
-// this.setSharedVariable("context", new BeanModel(context, new
BeansWrapper()));
- }
-
- /* (non-Javadoc)
- * @see
org.richfaces.cdk.templatecompiler.FreeMarkerRenderer#writeSnippet(java.lang.String,
java.lang.Object, java.io.Writer)
- */
- public void writeTemplate(String templateName, Object object, Writer writer) throws
IOException, TemplateException {
- Template t = getTemplate(templateName + ".ftl");
- Map<String, Object> rootMap = new HashMap<String, Object>();
- rootMap.put("modelItem", object);
-
- rootMap.put("facesContextVariable",
RendererClassVisitor.FACES_CONTEXT_VARIABLE);
- rootMap.put("componentVariable",
RendererClassVisitor.COMPONENT_VARIABLE);
- rootMap.put("responseWriterVariable",
RendererClassVisitor.RESPONSE_WRITER_VARIABLE);
- rootMap.put("clientIdVariable",
RendererClassVisitor.CLIENT_ID_VARIABLE);
-
- t.process(rootMap, writer);
- }
-
- /* (non-Javadoc)
- * @see
org.richfaces.cdk.templatecompiler.FreeMarkerRenderer#renderSnippet(java.lang.String,
java.lang.Object)
- */
- public String renderTemplate(String templateName, Object object) {
- StringWriter writer = new StringWriter();
- try {
- writeTemplate(templateName, object, writer);
-
- return writer.toString();
- } catch (IOException e) {
- // TODO: handle exception
- return e.getMessage();
- } catch (TemplateException e) {
- // TODO: handle exception
- return e.getMessage();
- }
- }
-
-}
Modified:
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/RendererClassGenerator.java
===================================================================
---
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/RendererClassGenerator.java 2010-07-01
19:58:07 UTC (rev 17702)
+++
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/RendererClassGenerator.java 2010-07-02
00:31:47 UTC (rev 17703)
@@ -70,7 +70,7 @@
*/
@Inject
public RendererClassGenerator((a)Output(Outputs.JAVA_CLASSES) FileManager output,
Logger log,
- TemplateVisitorFactory<RendererClassVisitor> visitorFactory,
FreeMarkerRenderer renderer) {
+ TemplateVisitorFactory<RendererClassVisitor> visitorFactory, @TemplateModel
FreeMarkerRenderer renderer) {
this.output = output;
this.log = log;
this.visitorFactory = visitorFactory;
@@ -102,12 +102,8 @@
attributes.addAll(renderer.getAttributes());
RendererClassVisitor visitor =
visitorFactory.createVisitor(template.getInterface(), attributes);
- try {
- // TODO - put real parameters.
- template.getImplementation().visit(visitor);
- } finally {
- RendererClassVisitor.clearCaches();
- }
+ // TODO - put real parameters.
+ template.getImplementation().visit(visitor);
JavaClass javaClass = visitor.getGeneratedClass();
String fullName = javaClass.getName();
@@ -116,7 +112,7 @@
output.createOutput(fullName.replace('.',
'/') + ".java", library.lastModified());
if (null != outFile) {
- this.renderer.writeTemplate("class", javaClass,
outFile);
+ this.renderer.writeTemplate("class.ftl", javaClass,
outFile);
outFile.close();
}
} catch (IOException e) {
Modified:
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/RendererClassVisitor.java
===================================================================
---
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/RendererClassVisitor.java 2010-07-01
19:58:07 UTC (rev 17702)
+++
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/RendererClassVisitor.java 2010-07-02
00:31:47 UTC (rev 17703)
@@ -23,33 +23,20 @@
package org.richfaces.cdk.templatecompiler;
-import static org.richfaces.cdk.templatecompiler.QNameComparator.QNAME_COMPARATOR;
-import static org.richfaces.cdk.util.JavaUtils.getEscapedString;
-import static org.richfaces.cdk.util.JavaUtils.getEscapedStringsArray;
-
import java.io.IOException;
import java.lang.reflect.Type;
import java.util.Collection;
-import java.util.Collections;
-import java.util.EnumMap;
import java.util.EnumSet;
-import java.util.HashSet;
import java.util.Map;
import java.util.Set;
-import java.util.TreeMap;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.context.ResponseWriter;
-import javax.faces.render.Renderer;
import javax.xml.namespace.QName;
import org.richfaces.cdk.CdkException;
import org.richfaces.cdk.Logger;
-import org.richfaces.cdk.attributes.Attribute;
-import org.richfaces.cdk.attributes.Element;
-import org.richfaces.cdk.attributes.Schema;
-import org.richfaces.cdk.model.EventName;
import org.richfaces.cdk.model.PropertyBase;
import org.richfaces.cdk.templatecompiler.builder.model.Argument;
import org.richfaces.cdk.templatecompiler.builder.model.JavaAnnotation;
@@ -58,52 +45,43 @@
import org.richfaces.cdk.templatecompiler.builder.model.JavaMethod;
import org.richfaces.cdk.templatecompiler.builder.model.JavaModifier;
import org.richfaces.cdk.templatecompiler.builder.model.JavaStatement;
-import org.richfaces.cdk.templatecompiler.builder.model.StatementImpl;
-import org.richfaces.cdk.templatecompiler.el.ELParserUtils;
-import org.richfaces.cdk.templatecompiler.el.ELVisitor;
-import org.richfaces.cdk.templatecompiler.el.ParsingException;
import org.richfaces.cdk.templatecompiler.el.types.ELType;
import org.richfaces.cdk.templatecompiler.el.types.TypesFactory;
-import org.richfaces.cdk.templatecompiler.el.types.TypesFactoryImpl;
import org.richfaces.cdk.templatecompiler.model.AnyElement;
import org.richfaces.cdk.templatecompiler.model.CdkBodyElement;
import org.richfaces.cdk.templatecompiler.model.CdkCallElement;
+import org.richfaces.cdk.templatecompiler.model.CdkCaseElement;
import org.richfaces.cdk.templatecompiler.model.CdkChooseElement;
+import org.richfaces.cdk.templatecompiler.model.CdkDefaultElement;
import org.richfaces.cdk.templatecompiler.model.CdkForEachElement;
import org.richfaces.cdk.templatecompiler.model.CdkIfElement;
import org.richfaces.cdk.templatecompiler.model.CdkObjectElement;
import org.richfaces.cdk.templatecompiler.model.CdkOtherwiseElement;
+import org.richfaces.cdk.templatecompiler.model.CdkSwitchElement;
import org.richfaces.cdk.templatecompiler.model.CdkWhenElement;
import org.richfaces.cdk.templatecompiler.model.CompositeImplementation;
import org.richfaces.cdk.templatecompiler.model.CompositeInterface;
import org.richfaces.cdk.templatecompiler.model.Template;
import org.richfaces.cdk.templatecompiler.model.TemplateVisitor;
import org.richfaces.cdk.templatecompiler.statements.AttributesStatement;
+import org.richfaces.cdk.templatecompiler.statements.CaseStatement;
import org.richfaces.cdk.templatecompiler.statements.ConstantReturnMethodBodyStatement;
-import
org.richfaces.cdk.templatecompiler.statements.ConversionToBooleanMethodBodyStatement;
-import
org.richfaces.cdk.templatecompiler.statements.ConversionToStringMethodBodyStatement;
import org.richfaces.cdk.templatecompiler.statements.DefineObjectStatement;
-import
org.richfaces.cdk.templatecompiler.statements.EmptinessCheckingMethodBodyStatement;
import org.richfaces.cdk.templatecompiler.statements.EncodeMethodPrefaceStatement;
import org.richfaces.cdk.templatecompiler.statements.EndElementStatement;
-import org.richfaces.cdk.templatecompiler.statements.EqualsCheckingMethodBodyStatement;
import org.richfaces.cdk.templatecompiler.statements.ForEachStatement;
-import org.richfaces.cdk.templatecompiler.statements.HelperJavaMethod;
import org.richfaces.cdk.templatecompiler.statements.HelperMethod;
-import org.richfaces.cdk.templatecompiler.statements.HelperMethodBodyStatement;
import org.richfaces.cdk.templatecompiler.statements.HelperMethodFactory;
import org.richfaces.cdk.templatecompiler.statements.IfElseStatement;
import org.richfaces.cdk.templatecompiler.statements.IfStatement;
import org.richfaces.cdk.templatecompiler.statements.StartElementStatement;
import org.richfaces.cdk.templatecompiler.statements.StatementsContainer;
+import org.richfaces.cdk.templatecompiler.statements.SwitchStatement;
import org.richfaces.cdk.templatecompiler.statements.TemplateStatement;
-import org.richfaces.cdk.templatecompiler.statements.WriteAttributeStatement;
-import org.richfaces.cdk.templatecompiler.statements.WriteAttributesSetStatement;
+import org.richfaces.cdk.templatecompiler.statements.TemplateStatementImpl;
import org.richfaces.cdk.templatecompiler.statements.WriteTextStatement;
import org.richfaces.cdk.util.Strings;
-import com.google.common.base.Function;
-import com.google.common.collect.Collections2;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.inject.Injector;
@@ -146,12 +124,11 @@
*/
static final String CLIENT_ID_VARIABLE = "clientId";
- static final ImmutableMap<String, Object> ENCODE_METHOD_VARIABLES =
ImmutableMap.<String, Object>builder()
- .put("facesContextVariable", RendererClassVisitor.FACES_CONTEXT_VARIABLE)
- .put("componentVariable", RendererClassVisitor.COMPONENT_VARIABLE)
- .put("responseWriterVariable",
RendererClassVisitor.RESPONSE_WRITER_VARIABLE)
- .put("clientIdVariable", RendererClassVisitor.CLIENT_ID_VARIABLE)
- .build();
+ static final ImmutableMap<String, Object> ENCODE_METHOD_VARIABLES =
ImmutableMap.<String, Object> builder()
+ .put("facesContextVariable",
RendererClassVisitor.FACES_CONTEXT_VARIABLE)
+ .put("componentVariable", RendererClassVisitor.COMPONENT_VARIABLE)
+ .put("responseWriterVariable",
RendererClassVisitor.RESPONSE_WRITER_VARIABLE)
+ .put("clientIdVariable",
RendererClassVisitor.CLIENT_ID_VARIABLE).build();
/**
*
@@ -245,93 +222,6 @@
return typesFactory.getType(type);
}
- private String createPassThroughAttributeCode(String htmlAttributeName, String
componentAttributeName) {
-
-
generatedClass.addImport("org.richfaces.renderkit.ComponentAttribute");
-
- StringBuilder sb = new StringBuilder();
- sb.append("new ComponentAttribute(");
-
- sb.append(getEscapedString(htmlAttributeName));
-
- sb.append(")");
-
- String attributeName = htmlAttributeName;
- if (!attributeName.equals(componentAttributeName)) {
- attributeName = componentAttributeName;
-
- sb.append(".setComponentAttributeName(");
- sb.append(getEscapedString(componentAttributeName));
- sb.append(")");
- }
-
- // OPTIMIZATION - use ModelSet with lookup method
- for (PropertyBase property : attributes) {
- if (attributeName.equals(property.getName())) {
- Set<EventName> eventNames = property.getEventNames();
- if (eventNames != null && !eventNames.isEmpty()) {
- sb.append(".setEventNames(");
- sb.append("new String[] {");
- Collection<String> eventNamesStrings =
- Collections2.transform(eventNames, new Function<EventName,
String>() {
- @Override
- public String apply(EventName from) {
- return from.getName();
- }
- });
- sb.append(getEscapedStringsArray(eventNamesStrings));
- sb.append("})");
- }
- break;
- }
- }
-
- return sb.toString();
- }
-
- private String createPassThroughField(Map<String, Attribute> htmlAttributesMap)
{
- String fieldName = PASS_THROUGH_ATTRIBUTES_FIELD_NAME;
- if (passThroughCounter >= 0) {
- fieldName += "_" + passThroughCounter;
- }
- passThroughCounter++;
-
- // TODO generic arguments
- JavaField passThroughField = new JavaField(Map.class, fieldName);
- passThroughField.addModifier(JavaModifier.PRIVATE);
- passThroughField.addModifier(JavaModifier.STATIC);
- passThroughField.addModifier(JavaModifier.FINAL);
-
-
generatedClass.addImport("org.richfaces.renderkit.ComponentAttribute");
- addRendererUtilsImport();
- generatedClass.addImport(Collections.class);
-
- // TODO - get rid of FQNs for classes via imports
- passThroughField.setGenericArguments(new JavaClass[] { new
JavaClass(String.class),
- new JavaClass("org.richfaces.renderkit.ComponentAttribute") });
-
- StringBuilder fieldValue = new
StringBuilder("Collections.unmodifiableMap(ComponentAttribute.createMap(");
- boolean isFirstArgument = true;
- for (Map.Entry<String, Attribute> entry : htmlAttributesMap.entrySet()) {
- if (isFirstArgument) {
- isFirstArgument = false;
- } else {
- fieldValue.append(", ");
- }
-
- String htmlAttributeName = entry.getKey();
- String componentAttributeName =
entry.getValue().getComponentAttributeName();
- fieldValue.append(createPassThroughAttributeCode(htmlAttributeName,
componentAttributeName));
- }
-
- fieldValue.append("))");
-
- passThroughField.setValue(new StatementImpl(fieldValue.toString()));
- generatedClass.addField(passThroughField);
-
- return fieldName;
- }
-
private void createMethodContext() {
this.currentStatement = new StatementsContainer();
currentStatement.setVariable(FACES_CONTEXT_VARIABLE,
getType(FacesContext.class));
@@ -371,11 +261,6 @@
createMethodContext();
}
- private void defineObject(ELType type, String name, String initializationExpression)
{
- addStatement(new DefineObjectStatement(type, name, initializationExpression));
- currentStatement.setVariable(name, type);
- }
-
private void createRendersChildrenMethod() {
Boolean rendersChildren = compositeInterface.getRendersChildren();
if (rendersChildren != null) {
@@ -395,6 +280,12 @@
currentStatement = container;
}
+ protected <T extends StatementsContainer> T pushStatement(Class<T>
container) {
+ T statement = createStatement(container);
+ pushStatement(container);
+ return statement;
+ }
+
protected void popStatement() {
currentStatement = currentStatement.getParent();
}
@@ -460,59 +351,59 @@
AttributesStatement attributesStatement =
createStatement(AttributesStatement.class);
addStatement(attributesStatement);
attributesStatement.setAttributes(elementAttributes);
-// Set<String> writtenAttributes = new HashSet<String>();
-// boolean shouldEncodePassThrough = false;
-// String[] passThroughExclusions = null;
-//
-// Map<QName, Object> sortedElementAttributes = new TreeMap<QName,
Object>(QNAME_COMPARATOR);
-// sortedElementAttributes.putAll(elementAttributes);
-//
-// for (Map.Entry<QName, Object> attribute :
sortedElementAttributes.entrySet()) {
-// QName attributeName = attribute.getKey();
-// Object attributeValue = attribute.getValue();
-//
-// if (!isDefaultNamespace(attributeName.getNamespaceURI())) {
-// // TODO: add support
-// if (Template.CDK_NAMESPACE.equals(attributeName.getNamespaceURI())
-// &&
"passThroughWithExclusions".equals(attributeName.getLocalPart())) {
-//
-// shouldEncodePassThrough = true;
-// if (attributeValue != null) {
-// passThroughExclusions =
attributeValue.toString().split("\\s+");
-// }
-// }
-// } else {
-// String attributeLocalName = attributeName.getLocalPart();
-// if (writtenAttributes.add(attributeLocalName)) {
-// addStatement(new WriteAttributeStatement(attributeLocalName,
compileEl(
-// attributeValue.toString(), Object.class)));
-// }
-// }
-// }
-//
-// if (shouldEncodePassThrough) {
-// Element attributesElement =
attributesSchema.getElements().get(elementName.getLocalPart());
-// if (attributesElement != null) {
-// // make a copy of original set
-// TreeMap<String, Attribute> actualAttributesMap =
-// new TreeMap<String,
Attribute>(attributesElement.getAttributes());
-//
-// if (passThroughExclusions != null) {
-// for (String passThroughExclusion : passThroughExclusions) {
-// actualAttributesMap.remove(passThroughExclusion);
-// }
-// }
-//
-// for (String writtenAttribute : writtenAttributes) {
-// actualAttributesMap.remove(writtenAttribute);
-// }
-//
-// if (!actualAttributesMap.isEmpty()) {
-// String passThroughFieldName =
createPassThroughField(actualAttributesMap);
-// addStatement(new
WriteAttributesSetStatement(passThroughFieldName));
-// }
-// }
-// }
+ // Set<String> writtenAttributes = new HashSet<String>();
+ // boolean shouldEncodePassThrough = false;
+ // String[] passThroughExclusions = null;
+ //
+ // Map<QName, Object> sortedElementAttributes = new TreeMap<QName,
Object>(QNAME_COMPARATOR);
+ // sortedElementAttributes.putAll(elementAttributes);
+ //
+ // for (Map.Entry<QName, Object> attribute :
sortedElementAttributes.entrySet()) {
+ // QName attributeName = attribute.getKey();
+ // Object attributeValue = attribute.getValue();
+ //
+ // if (!isDefaultNamespace(attributeName.getNamespaceURI())) {
+ // // TODO: add support
+ // if (Template.CDK_NAMESPACE.equals(attributeName.getNamespaceURI())
+ // &&
"passThroughWithExclusions".equals(attributeName.getLocalPart())) {
+ //
+ // shouldEncodePassThrough = true;
+ // if (attributeValue != null) {
+ // passThroughExclusions = attributeValue.toString().split("\\s+");
+ // }
+ // }
+ // } else {
+ // String attributeLocalName = attributeName.getLocalPart();
+ // if (writtenAttributes.add(attributeLocalName)) {
+ // addStatement(new WriteAttributeStatement(attributeLocalName, compileEl(
+ // attributeValue.toString(), Object.class)));
+ // }
+ // }
+ // }
+ //
+ // if (shouldEncodePassThrough) {
+ // Element attributesElement =
attributesSchema.getElements().get(elementName.getLocalPart());
+ // if (attributesElement != null) {
+ // // make a copy of original set
+ // TreeMap<String, Attribute> actualAttributesMap =
+ // new TreeMap<String, Attribute>(attributesElement.getAttributes());
+ //
+ // if (passThroughExclusions != null) {
+ // for (String passThroughExclusion : passThroughExclusions) {
+ // actualAttributesMap.remove(passThroughExclusion);
+ // }
+ // }
+ //
+ // for (String writtenAttribute : writtenAttributes) {
+ // actualAttributesMap.remove(writtenAttribute);
+ // }
+ //
+ // if (!actualAttributesMap.isEmpty()) {
+ // String passThroughFieldName = createPassThroughField(actualAttributesMap);
+ // addStatement(new WriteAttributesSetStatement(passThroughFieldName));
+ // }
+ // }
+ // }
}
/*
@@ -526,8 +417,8 @@
public void endElement(AnyElement anyElement) throws CdkException {
QName elementName = anyElement.getName();
EndElementStatement endElementStatement =
createStatement(EndElementStatement.class);
- endElementStatement.setElementName(elementName.getLocalPart());
addStatement(endElementStatement);
+ endElementStatement.setElementName(elementName.getLocalPart());
}
/*
@@ -541,7 +432,9 @@
if (text != null) {
String trimmedText = text.trim();
if (!Strings.isEmpty(trimmedText)) {
- addStatement(new WriteTextStatement(compileEl(trimmedText,
String.class)));
+ WriteTextStatement statement =
createStatement(WriteTextStatement.class);
+ addStatement(statement);
+ statement.setExpression(trimmedText);
}
}
}
@@ -560,7 +453,7 @@
expression = cdkCallElement.getBodyValue();
}
- addStatement(new StatementImpl(expression + ";"));
+ addStatement(new TemplateStatementImpl(expression + ";"));
}
/*
@@ -572,10 +465,10 @@
@Override
public void startElement(CdkIfElement cdkIfElement) {
- String compiledTestExpression = compileEl(cdkIfElement.getTest(), Boolean.TYPE);
-
- pushStatement(new IfElseStatement());
- pushStatement(new IfStatement(compiledTestExpression));
+ pushStatement(createStatement(IfElseStatement.class));
+ IfStatement ifStatement = createStatement(IfStatement.class);
+ pushStatement(ifStatement);
+ ifStatement.setTest(cdkIfElement.getTest());
}
/*
@@ -600,7 +493,7 @@
@Override
public void startElement(CdkChooseElement cdkChooseElement) {
- pushStatement(new IfElseStatement());
+ pushStatement(createStatement(IfElseStatement.class));
}
/*
@@ -624,9 +517,9 @@
@Override
public void startElement(CdkWhenElement cdkWhenElement) {
- String compiledTestExpression = compileEl(cdkWhenElement.getTest(),
Boolean.TYPE);
-
- pushStatement(new IfStatement(compiledTestExpression));
+ IfStatement ifStatement = createStatement(IfStatement.class);
+ pushStatement(ifStatement);
+ ifStatement.setTest(cdkWhenElement.getTest());
}
/*
@@ -650,7 +543,8 @@
@Override
public void startElement(CdkOtherwiseElement cdkOtherwiseElement) {
- pushStatement(new IfStatement(""));
+ IfStatement ifStatement = createStatement(IfStatement.class);
+ pushStatement(ifStatement);
}
/*
@@ -688,30 +582,33 @@
typeString += "<" + typeArgumentsString + ">";
}
- ELType type = null;
- if (!Strings.isEmpty(typeString)) {
- type = TypesFactoryImpl.getType(typeString, typesFactory);
- }
-
- if (!Strings.isEmpty(value)) {
- Class<?> valueType;
- if (type != null) {
- valueType = type.getRawType();
- } else {
- valueType = Object.class;
- }
-
- value = compileEl(value, valueType);
- if (type == null) {
- type = lastCompiledExpressionType;
- }
- }
-
- if (type == null) {
- type = TypesFactory.OBJECT_TYPE;
- }
-
- defineObject(type, name, value);
+ // ELType type = null;
+ // if (!Strings.isEmpty(typeString)) {
+ // type = TypesFactoryImpl.getType(typeString, typesFactory);
+ // }
+ //
+ // if (!Strings.isEmpty(value)) {
+ // Class<?> valueType;
+ // if (type != null) {
+ // valueType = type.getRawType();
+ // } else {
+ // valueType = Object.class;
+ // }
+ //
+ // value = compileEl(value, valueType);
+ // if (type == null) {
+ // type = lastCompiledExpressionType;
+ // }
+ // }
+ //
+ // if (type == null) {
+ // type = TypesFactory.OBJECT_TYPE;
+ // }
+ //
+ // defineObject(type, name, value);
+ DefineObjectStatement statement = createStatement(DefineObjectStatement.class);
+ addStatement(statement);
+ // TODO - set parameters.
}
/*
@@ -724,17 +621,16 @@
@Override
public void startElement(CdkForEachElement cdkForEachElement) {
String items = cdkForEachElement.getItems();
- String itemsExpression = compileEl(items, Iterable.class);
+// String itemsExpression = compileEl(items, Iterable.class);
// TODO - review
- Class<?> collectionElementClass =
lastCompiledExpressionType.getContainerType().getRawType();
- if (collectionElementClass == null) {
- collectionElementClass = Object.class;
- }
-
- pushStatement(new ForEachStatement(itemsExpression, cdkForEachElement.getVar(),
- collectionElementClass.getName()));
- currentStatement.setVariable(cdkForEachElement.getVar(),
lastCompiledExpressionType.getContainerType());
+ // Class<?> collectionElementClass =
lastCompiledExpressionType.getContainerType().getRawType();
+ // if (collectionElementClass == null) {
+ // collectionElementClass = Object.class;
+ // }
+ ForEachStatement forEachStatement = pushStatement(ForEachStatement.class);
+ forEachStatement.setItemsExpression(items);
+ // currentStatement.setVariable(cdkForEachElement.getVar(),
lastCompiledExpressionType.getContainerType());
}
/*
@@ -749,6 +645,41 @@
popStatement();
}
+ @Override
+ public void startElement(CdkSwitchElement cdkSwitchElement) {
+ String key = cdkSwitchElement.getKey();
+ // String keyExpression = compileEl(key, Object.class);
+ SwitchStatement switchStatement = createStatement(SwitchStatement.class);
+ pushStatement(switchStatement);
+ switchStatement.setKeyExpression(key);
+ }
+
+ @Override
+ public void endElement(CdkSwitchElement cdkSwitchElement) {
+ popStatement();
+ }
+
+ @Override
+ public void startElement(CdkCaseElement cdkCaseElement) {
+ CaseStatement caseStatement = pushStatement(CaseStatement.class);
+ caseStatement.setValues(cdkCaseElement.getValues());
+ }
+
+ @Override
+ public void endElement(CdkCaseElement cdkCaseElement) {
+ popStatement();
+ }
+
+ @Override
+ public void startElement(CdkDefaultElement cdkDefaultElement) {
+ pushStatement(new CaseStatement());
+ }
+
+ @Override
+ public void endElement(CdkDefaultElement cdkDefaultElement) {
+ popStatement();
+ }
+
/**
*
*/
@@ -765,8 +696,4 @@
createRendersChildrenMethod();
}
- public static void clearCaches() {
- TypesFactoryImpl.clearCaches();
- ELParserUtils.clearCaches();
- }
}
Added:
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/TemplateModel.java
===================================================================
---
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/TemplateModel.java
(rev 0)
+++
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/TemplateModel.java 2010-07-02
00:31:47 UTC (rev 17703)
@@ -0,0 +1,16 @@
+package org.richfaces.cdk.templatecompiler;
+
+import static java.lang.annotation.ElementType.*;
+import static java.lang.annotation.RetentionPolicy.*;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+import com.google.inject.BindingAnnotation;
+
+@Retention(RUNTIME)
+@Target({ FIELD, PARAMETER, METHOD })
+@BindingAnnotation
+public @interface TemplateModel {
+
+}
Property changes on:
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/TemplateModel.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified:
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/TemplateModule.java
===================================================================
---
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/TemplateModule.java 2010-07-01
19:58:07 UTC (rev 17702)
+++
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/TemplateModule.java 2010-07-02
00:31:47 UTC (rev 17703)
@@ -24,11 +24,15 @@
package org.richfaces.cdk.templatecompiler;
import java.util.Map;
-import java.util.Set;
import org.richfaces.cdk.CdkWriter;
import org.richfaces.cdk.ModelBuilder;
import org.richfaces.cdk.attributes.Schema;
+import org.richfaces.cdk.generate.freemarker.CdkConfiguration;
+import org.richfaces.cdk.generate.freemarker.DefaultImports;
+import org.richfaces.cdk.generate.freemarker.FreeMakerUtils;
+import org.richfaces.cdk.generate.freemarker.FreeMarkerRenderer;
+import org.richfaces.cdk.generate.freemarker.TemplatesFolder;
import org.richfaces.cdk.templatecompiler.el.ELParserImpl;
import org.richfaces.cdk.templatecompiler.el.types.TypesFactory;
import org.richfaces.cdk.templatecompiler.el.types.TypesFactoryImpl;
@@ -36,7 +40,9 @@
import org.richfaces.cdk.templatecompiler.statements.HelperMethodFactory;
import org.richfaces.cdk.templatecompiler.statements.HelperMethodFactoryImpl;
-import com.google.inject.PrivateModule;
+import com.google.common.collect.ImmutableMap;
+import com.google.inject.AbstractModule;
+import com.google.inject.PrivateBinder;
import com.google.inject.Singleton;
import com.google.inject.TypeLiteral;
import com.google.inject.multibindings.Multibinder;
@@ -45,32 +51,41 @@
import freemarker.template.ObjectWrapper;
/**
- * <p class="changed_added_4_0"></p>
+ * <p class="changed_added_4_0">
+ * </p>
+ *
* @author asmirnov(a)exadel.com
- *
+ *
*/
-public class TemplateModule extends PrivateModule {
+public class TemplateModule extends AbstractModule {
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see com.google.inject.AbstractModule#configure()
*/
@Override
protected void configure() {
Multibinder<ModelBuilder> modelBinder = Multibinder.newSetBinder(binder(),
ModelBuilder.class);
modelBinder.addBinding().to(RendererTemplateParser.class);
- TypeLiteral<Set<ModelBuilder>> buildersType = new
TypeLiteral<Set<ModelBuilder>>(){};
- expose(buildersType);
Multibinder.newSetBinder(binder(),
CdkWriter.class).addBinding().to(RendererClassGenerator.class);
- TypeLiteral<Set<CdkWriter>> writersType = new
TypeLiteral<Set<CdkWriter>>(){};
- expose(writersType);
- // Private bindings.
- bind(new
TypeLiteral<TemplateVisitorFactory<RendererClassVisitor>>(){}).to(VisitorFactoryImpl.class).in(Singleton.class);
+ bind(new TypeLiteral<TemplateVisitorFactory<RendererClassVisitor>>()
{
+ }).to(VisitorFactoryImpl.class).in(Singleton.class);
bind(TypesFactory.class).to(TypesFactoryImpl.class);
bind(ELParser.class).to(ELParserImpl.class);
bind(HelperMethodFactory.class).to(HelperMethodFactoryImpl.class).in(Singleton.class);
-
bind(Schema.class).annotatedWith(Names.named(Template.XHTML_EL_NAMESPACE)).toProvider(XhtmlElSchemaProvider.class).in(Singleton.class);
- bind(ObjectWrapper.class).to(JavaClassModelWrapper.class);
- bind(new
TypeLiteral<Map<String,Object>>(){}).toInstance(RendererClassVisitor.ENCODE_METHOD_VARIABLES);
+ bind(Schema.class).annotatedWith(Names.named(Template.XHTML_EL_NAMESPACE))
+ .toProvider(XhtmlElSchemaProvider.class).in(Singleton.class);
+ // Private bindings.
+ PrivateBinder privateBinder = binder().newPrivateBinder();
+
privateBinder.bind(FreeMarkerRenderer.class).annotatedWith(TemplateModel.class).to(CdkConfiguration.class);
+
privateBinder.expose(FreeMarkerRenderer.class).annotatedWith(TemplateModel.class);
+ privateBinder.bind(FreeMakerUtils.class);
+ privateBinder.bind(ObjectWrapper.class).to(JavaClassModelWrapper.class);
+ privateBinder.bind(new TypeLiteral<Map<String, Object>>() {
+ }).toInstance(RendererClassVisitor.ENCODE_METHOD_VARIABLES);
+
privateBinder.bind(String.class).annotatedWith(TemplatesFolder.class).toInstance("/META-INF/templates/java");
+ privateBinder.bind(new
TypeLiteral<Map<String,String>>(){}).annotatedWith(DefaultImports.class).toInstance(ImmutableMap.of("util","util.ftl"));
}
}
Copied:
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/model/CdkCaseElement.java
(from rev 17695,
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/model/CdkCaseElement.java)
===================================================================
---
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/model/CdkCaseElement.java
(rev 0)
+++
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/model/CdkCaseElement.java 2010-07-02
00:31:47 UTC (rev 17703)
@@ -0,0 +1,56 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This 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 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.richfaces.cdk.templatecompiler.model;
+
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlRootElement;
+
+import org.richfaces.cdk.CdkException;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+@XmlRootElement(name = "case", namespace = Template.CDK_NAMESPACE)
+public class CdkCaseElement extends ModelFragment {
+
+ @XmlAttribute
+ private String[] values;
+
+ public String[] getValues() {
+ return values;
+ }
+
+ public void setValues(String[] values) {
+ this.values = values;
+ }
+
+ @Override
+ public void beforeVisit(TemplateVisitor visitor) throws CdkException {
+ visitor.startElement(this);
+ }
+
+ @Override
+ public void afterVisit(TemplateVisitor visitor) throws CdkException {
+ visitor.endElement(this);
+ }
+}
Copied:
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/model/CdkDefaultElement.java
(from rev 17695,
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/model/CdkDefaultElement.java)
===================================================================
---
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/model/CdkDefaultElement.java
(rev 0)
+++
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/model/CdkDefaultElement.java 2010-07-02
00:31:47 UTC (rev 17703)
@@ -0,0 +1,44 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This 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 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.richfaces.cdk.templatecompiler.model;
+
+import javax.xml.bind.annotation.XmlRootElement;
+
+import org.richfaces.cdk.CdkException;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+@XmlRootElement(name = "default", namespace = Template.CDK_NAMESPACE)
+public class CdkDefaultElement extends ModelFragment {
+
+ @Override
+ public void beforeVisit(TemplateVisitor visitor) throws CdkException {
+ visitor.startElement(this);
+ }
+
+ @Override
+ public void afterVisit(TemplateVisitor visitor) throws CdkException {
+ visitor.endElement(this);
+ }
+}
Copied:
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/model/CdkSwitchElement.java
(from rev 17695,
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/model/CdkSwitchElement.java)
===================================================================
---
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/model/CdkSwitchElement.java
(rev 0)
+++
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/model/CdkSwitchElement.java 2010-07-02
00:31:47 UTC (rev 17703)
@@ -0,0 +1,56 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This 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 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.richfaces.cdk.templatecompiler.model;
+
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlRootElement;
+
+import org.richfaces.cdk.CdkException;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+@XmlRootElement(name = "switch", namespace = Template.CDK_NAMESPACE)
+public class CdkSwitchElement extends ModelFragment {
+
+ @XmlAttribute
+ private String key;
+
+ public String getKey() {
+ return key;
+ }
+
+ public void setKey(String key) {
+ this.key = key;
+ }
+
+ @Override
+ public void beforeVisit(TemplateVisitor visitor) throws CdkException {
+ visitor.startElement(this);
+ }
+
+ @Override
+ public void afterVisit(TemplateVisitor visitor) throws CdkException {
+ visitor.endElement(this);
+ }
+}
Modified:
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/model/ModelFragment.java
===================================================================
---
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/model/ModelFragment.java 2010-07-01
19:58:07 UTC (rev 17702)
+++
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/model/ModelFragment.java 2010-07-02
00:31:47 UTC (rev 17703)
@@ -22,7 +22,10 @@
CdkChooseElement.class,
CdkWhenElement.class,
CdkOtherwiseElement.class,
- CdkForEachElement.class
+ CdkForEachElement.class,
+ CdkSwitchElement.class,
+ CdkCaseElement.class,
+ CdkDefaultElement.class
})
public class ModelFragment implements LeafModelElement {
Modified:
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/model/TemplateVisitor.java
===================================================================
---
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/model/TemplateVisitor.java 2010-07-01
19:58:07 UTC (rev 17702)
+++
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/model/TemplateVisitor.java 2010-07-02
00:31:47 UTC (rev 17703)
@@ -66,6 +66,18 @@
void endElement(CdkForEachElement cdkForEachElement);
+ void startElement(CdkSwitchElement cdkSwitchElement);
+
+ void endElement(CdkSwitchElement cdkSwitchElement);
+
+ void startElement(CdkCaseElement cdkCaseElement);
+
+ void endElement(CdkCaseElement cdkCaseElement);
+
+ void startElement(CdkDefaultElement cdkDefaultElement);
+
+ void endElement(CdkDefaultElement cdkDefaultElement);
+
void preProcess(CompositeImplementation compositeImplementation);
void postProcess(CompositeImplementation compositeImplementation);
Copied:
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/CaseStatement.java
(from rev 17695,
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/CaseStatement.java)
===================================================================
---
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/CaseStatement.java
(rev 0)
+++
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/CaseStatement.java 2010-07-02
00:31:47 UTC (rev 17703)
@@ -0,0 +1,60 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This 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 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.richfaces.cdk.templatecompiler.statements;
+
+import org.richfaces.cdk.generate.freemarker.FreeMarkerRenderer;
+import org.richfaces.cdk.templatecompiler.TemplateModel;
+
+import com.google.inject.Inject;
+
+/**
+ * @author Nick Belaevski
+ */
+public class CaseStatement extends FreeMarkerTemplateStatementBase {
+
+ private String[] values;
+
+ public CaseStatement() {
+ this(null);
+ }
+
+ @Inject
+ public CaseStatement(@TemplateModel FreeMarkerRenderer renderer) {
+ super(renderer,"case");
+ }
+
+ public String[] getValues() {
+ return values;
+ }
+
+ /**
+ * <p class="changed_added_4_0"></p>
+ * @param values the values to set
+ */
+ public void setValues(String[] values) {
+ this.values = values;
+ }
+
+ public boolean isDefault() {
+ return values == null;
+ }
+}
Modified:
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/ConstantReturnMethodBodyStatement.java
===================================================================
---
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/ConstantReturnMethodBodyStatement.java 2010-07-01
19:58:07 UTC (rev 17702)
+++
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/ConstantReturnMethodBodyStatement.java 2010-07-02
00:31:47 UTC (rev 17703)
@@ -22,6 +22,7 @@
package org.richfaces.cdk.templatecompiler.statements;
import org.richfaces.cdk.generate.freemarker.FreeMarkerRenderer;
+import org.richfaces.cdk.templatecompiler.TemplateModel;
import com.google.inject.Inject;
@@ -29,12 +30,12 @@
* @author Nick Belaevski
*
*/
-public class ConstantReturnMethodBodyStatement extends TemplateStatementBase {
+public class ConstantReturnMethodBodyStatement extends FreeMarkerTemplateStatementBase {
private String returnValue;
@Inject
- public ConstantReturnMethodBodyStatement(FreeMarkerRenderer renderer) {
+ public ConstantReturnMethodBodyStatement(@TemplateModel FreeMarkerRenderer renderer)
{
super(renderer,"constant-return");
}
Modified:
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/DefineObjectStatement.java
===================================================================
---
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/DefineObjectStatement.java 2010-07-01
19:58:07 UTC (rev 17702)
+++
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/DefineObjectStatement.java 2010-07-02
00:31:47 UTC (rev 17703)
@@ -23,6 +23,7 @@
import org.richfaces.cdk.generate.freemarker.FreeMarkerRenderer;
import org.richfaces.cdk.templatecompiler.ELParser;
+import org.richfaces.cdk.templatecompiler.TemplateModel;
import org.richfaces.cdk.templatecompiler.el.ParsingException;
import org.richfaces.cdk.templatecompiler.el.types.ELType;
import org.richfaces.cdk.templatecompiler.el.types.TypesFactory;
@@ -32,7 +33,7 @@
/**
* @author Nick Belaevski
*/
-public class DefineObjectStatement extends TemplateStatementBase {
+public class DefineObjectStatement extends FreeMarkerTemplateStatementBase {
private ELType type;
@@ -43,7 +44,7 @@
private TypedTemplateStatement initializationStatement;
@Inject
- public DefineObjectStatement(FreeMarkerRenderer renderer, ELParser parser) {
+ public DefineObjectStatement(@TemplateModel FreeMarkerRenderer renderer, ELParser
parser) {
super(renderer, "define-object");
this.parser = parser;
}
Modified:
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/ElementStatement.java
===================================================================
---
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/ElementStatement.java 2010-07-01
19:58:07 UTC (rev 17702)
+++
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/ElementStatement.java 2010-07-02
00:31:47 UTC (rev 17703)
@@ -27,15 +27,14 @@
* @author Nick Belaevski
* @since 4.0
*/
-public class ElementStatement extends TemplateStatementBase {
+public class ElementStatement extends FreeMarkerTemplateStatementBase {
private String elementName;
- public ElementStatement(FreeMarkerRenderer renderer,String template) {
- super(renderer,template);
+ public ElementStatement(FreeMarkerRenderer renderer, String template) {
+ super(renderer, template);
}
-
/**
* @return the elementName
*/
@@ -44,8 +43,11 @@
}
/**
- * <p class="changed_added_4_0"></p>
- * @param elementName the elementName to set
+ * <p class="changed_added_4_0">
+ * </p>
+ *
+ * @param elementName
+ * the elementName to set
*/
public void setElementName(String elementName) {
this.elementName = elementName;
Modified:
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/EncodeMethodPrefaceStatement.java
===================================================================
---
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/EncodeMethodPrefaceStatement.java 2010-07-01
19:58:07 UTC (rev 17702)
+++
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/EncodeMethodPrefaceStatement.java 2010-07-02
00:31:47 UTC (rev 17703)
@@ -22,19 +22,20 @@
package org.richfaces.cdk.templatecompiler.statements;
import org.richfaces.cdk.generate.freemarker.FreeMarkerRenderer;
+import org.richfaces.cdk.templatecompiler.TemplateModel;
import com.google.inject.Inject;
/**
* @author Nick Belaevski
*/
-public class EncodeMethodPrefaceStatement extends TemplateStatementBase {
+public class EncodeMethodPrefaceStatement extends FreeMarkerTemplateStatementBase {
/**
* @param templateName
*/
@Inject
- public EncodeMethodPrefaceStatement(FreeMarkerRenderer renderer) {
+ public EncodeMethodPrefaceStatement(@TemplateModel FreeMarkerRenderer renderer) {
super(renderer,"encode-method-preface");
}
Modified:
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/EndElementStatement.java
===================================================================
---
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/EndElementStatement.java 2010-07-01
19:58:07 UTC (rev 17702)
+++
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/EndElementStatement.java 2010-07-02
00:31:47 UTC (rev 17703)
@@ -22,6 +22,7 @@
package org.richfaces.cdk.templatecompiler.statements;
import org.richfaces.cdk.generate.freemarker.FreeMarkerRenderer;
+import org.richfaces.cdk.templatecompiler.TemplateModel;
import com.google.inject.Inject;
@@ -32,7 +33,7 @@
public class EndElementStatement extends ElementStatement {
@Inject
- public EndElementStatement(FreeMarkerRenderer renderer) {
+ public EndElementStatement(@TemplateModel FreeMarkerRenderer renderer) {
super(renderer,"end-element");
}
Modified:
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/ForEachStatement.java
===================================================================
---
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/ForEachStatement.java 2010-07-01
19:58:07 UTC (rev 17702)
+++
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/ForEachStatement.java 2010-07-02
00:31:47 UTC (rev 17703)
@@ -22,13 +22,14 @@
package org.richfaces.cdk.templatecompiler.statements;
import org.richfaces.cdk.generate.freemarker.FreeMarkerRenderer;
+import org.richfaces.cdk.templatecompiler.TemplateModel;
import com.google.inject.Inject;
/**
* @author Nick Belaevski
*/
-public class ForEachStatement extends TemplateStatementBase {
+public class ForEachStatement extends FreeMarkerTemplateStatementBase {
private String itemsExpression;
@@ -37,7 +38,7 @@
private String varType;
@Inject
- public ForEachStatement(FreeMarkerRenderer renderer) {
+ public ForEachStatement(@TemplateModel FreeMarkerRenderer renderer) {
super(renderer,"for-each");
}
Copied:
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/FreeMarkerTemplateStatementBase.java
(from rev 17697,
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/TemplateStatementBase.java)
===================================================================
---
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/FreeMarkerTemplateStatementBase.java
(rev 0)
+++
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/FreeMarkerTemplateStatementBase.java 2010-07-02
00:31:47 UTC (rev 17703)
@@ -0,0 +1,119 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This 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 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.richfaces.cdk.templatecompiler.statements;
+
+import java.util.EnumSet;
+import java.util.List;
+import java.util.Set;
+
+import org.richfaces.cdk.generate.freemarker.FreeMarkerRenderer;
+import org.richfaces.cdk.templatecompiler.builder.model.JavaField;
+import org.richfaces.cdk.templatecompiler.builder.model.JavaImport;
+import org.richfaces.cdk.templatecompiler.builder.model.JavaModifier;
+import org.richfaces.cdk.templatecompiler.builder.model.RuntimeImport;
+import org.richfaces.cdk.templatecompiler.el.types.ReferencedType;
+import org.richfaces.cdk.util.Strings;
+
+import com.google.common.collect.Iterables;
+import com.google.common.collect.Lists;
+import com.google.common.collect.Sets;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public class FreeMarkerTemplateStatementBase extends StatementsContainer {
+
+ protected StatementsContainer parent;
+ private final String templateName;
+ private final FreeMarkerRenderer renderer;
+ private final Set<JavaImport> imports =
Sets.newTreeSet(JavaImport.COMPARATOR);
+ private final EnumSet<HelperMethod> requiredMethods =
EnumSet.noneOf(HelperMethod.class);
+ private final List<JavaField> fields = Lists.newArrayList();
+
+ private boolean parsed = false;
+ private String code;
+
+ protected FreeMarkerTemplateStatementBase(FreeMarkerRenderer renderer, String
templateName) {
+ super();
+ this.renderer = renderer;
+ this.templateName = templateName+".ftl";
+ }
+
+
+ @Override
+ public String getCode() {
+ parse();
+ return code;
+ }
+
+ private void parse() {
+ if(!parsed){
+ code = renderer.renderTemplate(templateName, this);
+ parsed = true;
+ }
+ }
+
+ @Override
+ public Iterable<JavaImport> getRequiredImports() {
+ parse();
+ return Iterables.concat(super.getRequiredImports(),imports);
+ }
+
+ @Override
+ public Iterable<JavaField> getRequiredFields() {
+ parse();
+ return Iterables.concat(super.getRequiredFields(),fields);
+ }
+
+ @Override
+ public Iterable<HelperMethod> getRequiredMethods() {
+ parse();
+ return Iterables.concat(super.getRequiredMethods(),requiredMethods);
+ }
+
+ protected void addRequiredMethods(HelperMethod... methods) {
+ for (HelperMethod helperMethod : methods) {
+ requiredMethods.add(helperMethod);
+ }
+ }
+
+ public void addConstant(String type, String name, String code) {
+ JavaField field = new JavaField(new ReferencedType(type),name);
+ field.addModifier(JavaModifier.PRIVATE);
+ field.addModifier(JavaModifier.STATIC);
+ field.addModifier(JavaModifier.FINAL);
+ if(!Strings.isEmpty(code)){
+ field.setValue(new TemplateStatementImpl(code));
+ }
+ fields.add(field);
+ }
+
+ public void addImport(String name) {
+ imports.add(new RuntimeImport(name));
+ }
+
+ public void addRequiredMethod(String helperMethodName) {
+ HelperMethod helperMethod = HelperMethod.valueOf(helperMethodName);
+ requiredMethods.add(helperMethod);
+ }
+}
\ No newline at end of file
Property changes on:
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/FreeMarkerTemplateStatementBase.java
___________________________________________________________________
Name: svn:keywords
+ LastChangedDate LastChangedRevision LastChangedBy HeadURL Id
Modified:
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/HelperMethodFactoryImpl.java
===================================================================
---
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/HelperMethodFactoryImpl.java 2010-07-01
19:58:07 UTC (rev 17702)
+++
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/HelperMethodFactoryImpl.java 2010-07-02
00:31:47 UTC (rev 17703)
@@ -28,6 +28,7 @@
import org.richfaces.cdk.Generator;
import org.richfaces.cdk.Logger;
import org.richfaces.cdk.generate.freemarker.FreeMarkerRenderer;
+import org.richfaces.cdk.templatecompiler.TemplateModel;
import org.richfaces.cdk.templatecompiler.builder.model.Argument;
import org.richfaces.cdk.templatecompiler.builder.model.JavaMethod;
import org.richfaces.cdk.templatecompiler.builder.model.JavaModifier;
@@ -73,7 +74,7 @@
* @param typesFactory
*/
@Inject
- public void initHelperMethods(FreeMarkerRenderer renderer, TypesFactory typesFactory)
{
+ public void initHelperMethods(@TemplateModel FreeMarkerRenderer renderer,
TypesFactory typesFactory) {
this.renderer = renderer;
this.typesFactory = typesFactory;
buildHelperMethod(HelperMethod.EMPTINESS_CHECK, false,
"emptiness-check-method", "object");
@@ -98,7 +99,7 @@
helperJavaMethod = new JavaMethod(helperMethod.getName(), returnType,
arguments);
helperJavaMethod.addModifier(JavaModifier.PRIVATE);
helperJavaMethod.addModifier(JavaModifier.STATIC);
- helperJavaMethod.setMethodBody(new TemplateStatementBase(renderer,
templateName));
+ helperJavaMethod.setMethodBody(new FreeMarkerTemplateStatementBase(renderer,
templateName));
}
helperMethods.put(helperMethod, helperJavaMethod);
return helperJavaMethod;
Modified:
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/IfElseStatement.java
===================================================================
---
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/IfElseStatement.java 2010-07-01
19:58:07 UTC (rev 17702)
+++
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/IfElseStatement.java 2010-07-02
00:31:47 UTC (rev 17703)
@@ -22,6 +22,7 @@
package org.richfaces.cdk.templatecompiler.statements;
import org.richfaces.cdk.generate.freemarker.FreeMarkerRenderer;
+import org.richfaces.cdk.templatecompiler.TemplateModel;
import com.google.inject.Inject;
@@ -29,10 +30,10 @@
* @author Nick Belaevski
* @since 4.0
*/
-public class IfElseStatement extends TemplateStatementBase {
+public class IfElseStatement extends FreeMarkerTemplateStatementBase {
@Inject
- public IfElseStatement(FreeMarkerRenderer renderer) {
+ public IfElseStatement(@TemplateModel FreeMarkerRenderer renderer) {
super(renderer,"if-else");
}
Modified:
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/IfStatement.java
===================================================================
---
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/IfStatement.java 2010-07-01
19:58:07 UTC (rev 17702)
+++
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/IfStatement.java 2010-07-02
00:31:47 UTC (rev 17703)
@@ -26,8 +26,15 @@
private String test;
- public IfStatement(String test) {
+ public IfStatement() {
super();
+ }
+
+ /**
+ * <p class="changed_added_4_0"></p>
+ * @param test the test to set
+ */
+ public void setTest(String test) {
this.test = test;
}
Modified:
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/StartElementStatement.java
===================================================================
---
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/StartElementStatement.java 2010-07-01
19:58:07 UTC (rev 17702)
+++
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/StartElementStatement.java 2010-07-02
00:31:47 UTC (rev 17703)
@@ -22,6 +22,7 @@
package org.richfaces.cdk.templatecompiler.statements;
import org.richfaces.cdk.generate.freemarker.FreeMarkerRenderer;
+import org.richfaces.cdk.templatecompiler.TemplateModel;
import com.google.inject.Inject;
@@ -32,7 +33,7 @@
public class StartElementStatement extends ElementStatement {
@Inject
- public StartElementStatement(FreeMarkerRenderer renderer) {
+ public StartElementStatement(@TemplateModel FreeMarkerRenderer renderer) {
super(renderer,"start-element");
}
Modified:
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/StatementsContainer.java
===================================================================
---
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/StatementsContainer.java 2010-07-01
19:58:07 UTC (rev 17702)
+++
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/StatementsContainer.java 2010-07-02
00:31:47 UTC (rev 17703)
@@ -67,8 +67,20 @@
}
};
- private final List<TemplateStatement> statements = new
ArrayList<TemplateStatement>();
+ @SuppressWarnings("serial")
+ private final List<TemplateStatement> statements = new
ArrayList<TemplateStatement>() {
+ public boolean add(TemplateStatement e) {
+ e.setParent(StatementsContainer.this);
+ return super.add(e);
+ };
+
+ public void add(int index, TemplateStatement element) {
+ element.setParent(StatementsContainer.this);
+ super.add(index, element);
+ };
+ };
+
private StatementsContainer parent;
private final Map<String, ELType> localVariablesMap = Maps.newHashMap();
@@ -78,12 +90,10 @@
}
public void addStatement(TemplateStatement statement) {
- statement.setParent(this);
getStatements().add(statement);
}
public void addStatement(int index, TemplateStatement statement) {
- statement.setParent(this);
getStatements().add(index, statement);
}
@@ -173,8 +183,9 @@
return concatStatements(HELPER_METHODS_TRANSFORM);
}
- @Override
- public String toString() {
- return getCode();
- }
+// @Override
+// public String toString() {
+// return getCode();
+// }
+
}
Copied:
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/SwitchStatement.java
(from rev 17695,
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/SwitchStatement.java)
===================================================================
---
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/SwitchStatement.java
(rev 0)
+++
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/SwitchStatement.java 2010-07-02
00:31:47 UTC (rev 17703)
@@ -0,0 +1,55 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This 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 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.richfaces.cdk.templatecompiler.statements;
+
+import org.richfaces.cdk.generate.freemarker.FreeMarkerRenderer;
+import org.richfaces.cdk.templatecompiler.TemplateModel;
+
+import com.google.inject.Inject;
+
+/**
+ * @author Nick Belaevski
+ */
+public class SwitchStatement extends FreeMarkerTemplateStatementBase {
+
+ private String keyExpression;
+
+ @Inject
+ public SwitchStatement(@TemplateModel FreeMarkerRenderer renderer) {
+ super(renderer,"switch");
+ }
+
+ /**
+ * @return the keyExpression
+ */
+ public String getKeyExpression() {
+ return keyExpression;
+ }
+
+ /**
+ * <p class="changed_added_4_0"></p>
+ * @param keyExpression the keyExpression to set
+ */
+ public void setKeyExpression(String keyExpression) {
+ this.keyExpression = keyExpression;
+ }
+}
Deleted:
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/TemplateStatementBase.java
===================================================================
---
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/TemplateStatementBase.java 2010-07-01
19:58:07 UTC (rev 17702)
+++
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/TemplateStatementBase.java 2010-07-02
00:31:47 UTC (rev 17703)
@@ -1,120 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2009, Red Hat, Inc. and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This 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 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software 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
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
- */
-package org.richfaces.cdk.templatecompiler.statements;
-
-import java.util.EnumSet;
-import java.util.List;
-import java.util.Set;
-
-import org.richfaces.cdk.generate.freemarker.FreeMarkerRenderer;
-import org.richfaces.cdk.templatecompiler.builder.model.JavaField;
-import org.richfaces.cdk.templatecompiler.builder.model.JavaImport;
-import org.richfaces.cdk.templatecompiler.builder.model.JavaModifier;
-import org.richfaces.cdk.templatecompiler.builder.model.RuntimeImport;
-import org.richfaces.cdk.templatecompiler.builder.model.StatementImpl;
-import org.richfaces.cdk.templatecompiler.el.types.ReferencedType;
-import org.richfaces.cdk.util.Strings;
-
-import com.google.common.collect.Iterables;
-import com.google.common.collect.Lists;
-import com.google.common.collect.Sets;
-
-/**
- * @author Nick Belaevski
- *
- */
-public class TemplateStatementBase extends StatementsContainer {
-
- protected StatementsContainer parent;
- private final String templateName;
- private final FreeMarkerRenderer renderer;
- private final Set<JavaImport> imports =
Sets.newTreeSet(JavaImport.COMPARATOR);
- private final EnumSet<HelperMethod> requiredMethods =
EnumSet.noneOf(HelperMethod.class);
- private final List<JavaField> fields = Lists.newArrayList();
-
- private boolean parsed = false;
- private String code;
-
- protected TemplateStatementBase(FreeMarkerRenderer renderer, String templateName) {
- super();
- this.renderer = renderer;
- this.templateName = templateName;
- }
-
-
- @Override
- public String getCode() {
- parse();
- return code;
- }
-
- private void parse() {
- if(!parsed){
- code = renderer.renderTemplate(templateName, this);
- parsed = true;
- }
- }
-
- @Override
- public Iterable<JavaImport> getRequiredImports() {
- parse();
- return Iterables.concat(super.getRequiredImports(),imports);
- }
-
- @Override
- public Iterable<JavaField> getRequiredFields() {
- parse();
- return Iterables.concat(super.getRequiredFields(),fields);
- }
-
- @Override
- public Iterable<HelperMethod> getRequiredMethods() {
- parse();
- return Iterables.concat(super.getRequiredMethods(),requiredMethods);
- }
-
- protected void addRequiredMethods(HelperMethod... methods) {
- for (HelperMethod helperMethod : methods) {
- requiredMethods.add(helperMethod);
- }
- }
-
- public void addConstant(String type, String name, String code) {
- JavaField field = new JavaField(new ReferencedType(type),name);
- field.addModifier(JavaModifier.PRIVATE);
- field.addModifier(JavaModifier.STATIC);
- field.addModifier(JavaModifier.FINAL);
- if(!Strings.isEmpty(code)){
- field.setValue(new StatementImpl(code));
- }
- fields.add(field);
- }
-
- public void addImport(String name) {
- imports.add(new RuntimeImport(name));
- }
-
- public void addRequiredMethod(String helperMethodName) {
- HelperMethod helperMethod = HelperMethod.valueOf(helperMethodName);
- requiredMethods.add(helperMethod);
- }
-}
\ No newline at end of file
Added:
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/TemplateStatementImpl.java
===================================================================
---
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/TemplateStatementImpl.java
(rev 0)
+++
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/TemplateStatementImpl.java 2010-07-02
00:31:47 UTC (rev 17703)
@@ -0,0 +1,85 @@
+/*
+ * $Id$
+ *
+ * License Agreement.
+ *
+ * Rich Faces - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.richfaces.cdk.templatecompiler.statements;
+
+import java.util.Collections;
+
+import org.richfaces.cdk.templatecompiler.builder.model.JavaField;
+import org.richfaces.cdk.templatecompiler.builder.model.JavaImport;
+
+/**
+ * <p class="changed_added_4_0"></p>
+ * @author asmirnov(a)exadel.com
+ *
+ */
+public class TemplateStatementImpl implements TemplateStatement {
+
+ private final String code;
+ private StatementsContainer parent;
+
+ public TemplateStatementImpl(String code) {
+ this.code = code;
+ // TODO Auto-generated constructor stub
+ }
+ /* (non-Javadoc)
+ * @see org.richfaces.cdk.templatecompiler.builder.model.JavaStatement#getCode()
+ */
+ @Override
+ public String getCode() {
+ return code;
+ }
+
+ /* (non-Javadoc)
+ * @see
org.richfaces.cdk.templatecompiler.builder.model.RequireImports#getRequiredImports()
+ */
+ @Override
+ public Iterable<JavaImport> getRequiredImports() {
+ return Collections.emptySet();
+ }
+
+ /* (non-Javadoc)
+ * @see
org.richfaces.cdk.templatecompiler.statements.TemplateStatement#getRequiredFields()
+ */
+ @Override
+ public Iterable<JavaField> getRequiredFields() {
+ return Collections.emptySet();
+ }
+
+ /* (non-Javadoc)
+ * @see
org.richfaces.cdk.templatecompiler.statements.TemplateStatement#getRequiredMethods()
+ */
+ @Override
+ public Iterable<HelperMethod> getRequiredMethods() {
+ return Collections.emptySet();
+ }
+
+ /* (non-Javadoc)
+ * @see
org.richfaces.cdk.templatecompiler.statements.TemplateStatement#setParent(org.richfaces.cdk.templatecompiler.statements.StatementsContainer)
+ */
+ @Override
+ public void setParent(StatementsContainer parent) {
+ this.parent = parent;
+ }
+
+}
Property changes on:
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/TemplateStatementImpl.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified:
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/WriteAttributeStatement.java
===================================================================
---
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/WriteAttributeStatement.java 2010-07-01
19:58:07 UTC (rev 17702)
+++
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/WriteAttributeStatement.java 2010-07-02
00:31:47 UTC (rev 17703)
@@ -22,13 +22,14 @@
package org.richfaces.cdk.templatecompiler.statements;
import org.richfaces.cdk.generate.freemarker.FreeMarkerRenderer;
+import org.richfaces.cdk.templatecompiler.TemplateModel;
import com.google.inject.Inject;
/**
* @author Nick Belaevski
*/
-public class WriteAttributeStatement extends TemplateStatementBase {
+public class WriteAttributeStatement extends FreeMarkerTemplateStatementBase {
private String name;
@@ -36,7 +37,7 @@
@Inject
- public WriteAttributeStatement(FreeMarkerRenderer renderer) {
+ public WriteAttributeStatement(@TemplateModel FreeMarkerRenderer renderer) {
super(renderer,"write-attribute");
}
Modified:
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/WriteAttributesSetStatement.java
===================================================================
---
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/WriteAttributesSetStatement.java 2010-07-01
19:58:07 UTC (rev 17702)
+++
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/WriteAttributesSetStatement.java 2010-07-02
00:31:47 UTC (rev 17703)
@@ -24,13 +24,14 @@
import java.util.concurrent.atomic.AtomicInteger;
import org.richfaces.cdk.generate.freemarker.FreeMarkerRenderer;
+import org.richfaces.cdk.templatecompiler.TemplateModel;
import com.google.inject.Inject;
/**
* @author Nick Belaevski
*/
-public class WriteAttributesSetStatement extends TemplateStatementBase {
+public class WriteAttributesSetStatement extends FreeMarkerTemplateStatementBase {
/**
*
@@ -42,7 +43,7 @@
private String passThroughFieldName;
@Inject
- public WriteAttributesSetStatement(FreeMarkerRenderer renderer) {
+ public WriteAttributesSetStatement(@TemplateModel FreeMarkerRenderer renderer) {
super(renderer, "write-attributes-set");
passThroughFieldName = PASS_THROUGH_ATTRIBUTES_FIELD_NAME +
fieldCounter.getAndIncrement();
}
Modified:
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/WriteTextStatement.java
===================================================================
---
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/WriteTextStatement.java 2010-07-01
19:58:07 UTC (rev 17702)
+++
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/WriteTextStatement.java 2010-07-02
00:31:47 UTC (rev 17703)
@@ -24,8 +24,10 @@
import java.util.Collections;
import java.util.List;
+import org.richfaces.cdk.Logger;
import org.richfaces.cdk.generate.freemarker.FreeMarkerRenderer;
import org.richfaces.cdk.templatecompiler.ELParser;
+import org.richfaces.cdk.templatecompiler.TemplateModel;
import org.richfaces.cdk.templatecompiler.el.ParsingException;
import org.richfaces.cdk.templatecompiler.el.types.TypesFactory;
@@ -34,15 +36,17 @@
/**
* @author Nick Belaevski
*/
-public class WriteTextStatement extends TemplateStatementBase {
+public class WriteTextStatement extends FreeMarkerTemplateStatementBase {
private TemplateStatement textStatement;
private final ELParser parser;
+ private final Logger log;
@Inject
- public WriteTextStatement(FreeMarkerRenderer renderer,ELParser parser) {
+ public WriteTextStatement(@TemplateModel FreeMarkerRenderer renderer,ELParser parser,
Logger log) {
super(renderer,"write-text");
this.parser = parser;
+ this.log = log;
}
public TemplateStatement getTextStatement() {
@@ -58,9 +62,13 @@
* @param textExpression the textExpression to set
* @throws ParsingException
*/
- public void setExpression(String textExpression) throws ParsingException {
- textStatement = parser.parse(textExpression,this,TypesFactory.OBJECT_TYPE);
- textStatement.setParent(this);
+ public void setExpression(String textExpression) {
+ try {
+ textStatement = parser.parse(textExpression,this,TypesFactory.OBJECT_TYPE);
+ textStatement.setParent(this);
+ } catch (ParsingException e) {
+ log.error("Error parsing EL expression", e);
+ }
}
}
Modified:
root/cdk/branches/RF8755/plugins/generator/src/main/resources/META-INF/schema/cdk-template.xsd
===================================================================
---
root/cdk/branches/RF8755/plugins/generator/src/main/resources/META-INF/schema/cdk-template.xsd 2010-07-01
19:58:07 UTC (rev 17702)
+++
root/cdk/branches/RF8755/plugins/generator/src/main/resources/META-INF/schema/cdk-template.xsd 2010-07-02
00:31:47 UTC (rev 17703)
@@ -518,4 +518,30 @@
</xs:choice>
</xs:sequence>
</xs:complexType>
+
+ <xs:element name="switch">
+ <xs:complexType>
+ <xs:sequence>
+ <xs:sequence>
+ <xs:element name="case"
maxOccurs="unbounded">
+ <xs:complexType>
+ <xs:complexContent>
+ <xs:extension base="c:arbitraryContent">
+ <xs:attribute name="values"
form="unqualified" use="required" type="xs:NMTOKENS" />
+ </xs:extension>
+ </xs:complexContent>
+ </xs:complexType>
+ </xs:element>
+ </xs:sequence>
+ <xs:element name="default" minOccurs="0">
+ <xs:complexType>
+ <xs:complexContent>
+ <xs:extension base="c:arbitraryContent" />
+ </xs:complexContent>
+ </xs:complexType>
+ </xs:element>
+ </xs:sequence>
+ <xs:attribute name="key" use="required"
form="unqualified" type="elStrictExpression" />
+ </xs:complexType>
+ </xs:element>
</xs:schema>
Copied:
root/cdk/branches/RF8755/plugins/generator/src/main/resources/META-INF/templates/java/case.ftl
(from rev 17695,
root/cdk/trunk/plugins/generator/src/main/resources/META-INF/templates/java/case.ftl)
===================================================================
---
root/cdk/branches/RF8755/plugins/generator/src/main/resources/META-INF/templates/java/case.ftl
(rev 0)
+++
root/cdk/branches/RF8755/plugins/generator/src/main/resources/META-INF/templates/java/case.ftl 2010-07-02
00:31:47 UTC (rev 17703)
@@ -0,0 +1,12 @@
+<#if modelItem.default>
+ default:
+<#else>
+ <#list modelItem.values as value>
+ case ${value}:
+ </#list>
+</#if>
+ <#list modelItem.statements as subStatement>
+ ${subStatement.code}
+ </#list>
+
+ break;
\ No newline at end of file
Copied:
root/cdk/branches/RF8755/plugins/generator/src/main/resources/META-INF/templates/java/switch.ftl
(from rev 17695,
root/cdk/trunk/plugins/generator/src/main/resources/META-INF/templates/java/switch.ftl)
===================================================================
---
root/cdk/branches/RF8755/plugins/generator/src/main/resources/META-INF/templates/java/switch.ftl
(rev 0)
+++
root/cdk/branches/RF8755/plugins/generator/src/main/resources/META-INF/templates/java/switch.ftl 2010-07-02
00:31:47 UTC (rev 17703)
@@ -0,0 +1,5 @@
+switch (${modelItem.keyExpression}) {
+ <#list modelItem.statements as subStatement>
+ ${subStatement.code}
+ </#list>
+}
\ No newline at end of file
Added:
root/cdk/branches/RF8755/plugins/generator/src/main/resources/META-INF/templates/java/util.ftl
===================================================================
---
root/cdk/branches/RF8755/plugins/generator/src/main/resources/META-INF/templates/java/util.ftl
(rev 0)
+++
root/cdk/branches/RF8755/plugins/generator/src/main/resources/META-INF/templates/java/util.ftl 2010-07-02
00:31:47 UTC (rev 17703)
@@ -0,0 +1,3 @@
+<#macro constant type name><#assign
code><#nested></#assign>${addConstant(type,name,code)}</#macro>
+<#macro require name>${addRequiredMethod(name)}</#macro>
+<#macro import name>${addImport(name)}</#macro>
Modified:
root/cdk/branches/RF8755/plugins/generator/src/test/java/org/richfaces/cdk/LibraryBuilderTest.java
===================================================================
---
root/cdk/branches/RF8755/plugins/generator/src/test/java/org/richfaces/cdk/LibraryBuilderTest.java 2010-07-01
19:58:07 UTC (rev 17702)
+++
root/cdk/branches/RF8755/plugins/generator/src/test/java/org/richfaces/cdk/LibraryBuilderTest.java 2010-07-02
00:31:47 UTC (rev 17703)
@@ -6,15 +6,10 @@
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
-import java.util.Collection;
import java.util.Collections;
-import java.util.HashSet;
import java.util.List;
-import java.util.Set;
-import org.apache.maven.model.FileSet;
import org.apache.maven.plugin.MojoExecutionException;
-import org.codehaus.plexus.util.DirectoryScanner;
import org.junit.Test;
/**
Modified:
root/cdk/branches/RF8755/plugins/generator/src/test/java/org/richfaces/cdk/generate/java/AbstractClassGeneratorTest.java
===================================================================
---
root/cdk/branches/RF8755/plugins/generator/src/test/java/org/richfaces/cdk/generate/java/AbstractClassGeneratorTest.java 2010-07-01
19:58:07 UTC (rev 17702)
+++
root/cdk/branches/RF8755/plugins/generator/src/test/java/org/richfaces/cdk/generate/java/AbstractClassGeneratorTest.java 2010-07-02
00:31:47 UTC (rev 17703)
@@ -59,6 +59,7 @@
@Inject
@As(CdkConfiguration.class)
+ @LibraryModel
protected FreeMarkerRenderer configuration;
@Inject
Added:
root/cdk/branches/RF8755/plugins/generator/src/test/java/org/richfaces/cdk/templatecompiler/statements/FreeMarkerTemplateStatementTest.java
===================================================================
---
root/cdk/branches/RF8755/plugins/generator/src/test/java/org/richfaces/cdk/templatecompiler/statements/FreeMarkerTemplateStatementTest.java
(rev 0)
+++
root/cdk/branches/RF8755/plugins/generator/src/test/java/org/richfaces/cdk/templatecompiler/statements/FreeMarkerTemplateStatementTest.java 2010-07-02
00:31:47 UTC (rev 17703)
@@ -0,0 +1,125 @@
+package org.richfaces.cdk.templatecompiler.statements;
+
+import static org.easymock.EasyMock.*;
+import static org.junit.Assert.*;
+
+import java.util.Collections;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.richfaces.cdk.CdkTestRunner;
+import org.richfaces.cdk.Mock;
+import org.richfaces.cdk.MockController;
+import org.richfaces.cdk.Stub;
+import org.richfaces.cdk.generate.freemarker.FreeMarkerRenderer;
+import org.richfaces.cdk.templatecompiler.builder.model.JavaField;
+import org.richfaces.cdk.templatecompiler.builder.model.JavaImport;
+import org.richfaces.cdk.templatecompiler.builder.model.RuntimeImport;
+import org.richfaces.cdk.templatecompiler.el.types.TypesFactory;
+
+import com.google.common.collect.Iterables;
+import com.google.inject.Inject;
+import com.google.inject.name.Named;
+
+(a)RunWith(CdkTestRunner.class)
+public class FreeMarkerTemplateStatementTest {
+
+ private static final String FOO_CODE = "private static final String foo;";
+
+ @Mock
+ private FreeMarkerRenderer renderer;
+
+ @Stub
+ private TemplateStatement statement;
+
+ @Stub
+ @Named("second")
+ private TemplateStatement statement1;
+
+ @Inject
+ private MockController controller;
+
+ private FreeMarkerTemplateStatementBase freeMarkerStatement;
+
+ @Before
+ public void setUp() {
+ freeMarkerStatement = new FreeMarkerTemplateStatementBase(renderer,
"foo");
+ }
+
+ public void tearDown() {
+ freeMarkerStatement = null;
+ }
+
+ @Test
+ public void testGetCode() {
+ expect(renderer.renderTemplate("foo.ftl",
freeMarkerStatement)).andReturn(FOO_CODE);
+ controller.replay();
+ String code = freeMarkerStatement.getCode();
+ controller.verify();
+ assertEquals(FOO_CODE, code);
+ }
+
+ @Test
+ public void testGetRequiredImports() {
+ freeMarkerStatement.addImport("foo.Bar");
+ expect(statement.getRequiredImports()).andStubReturn(
+ Collections.<JavaImport> singleton(new
RuntimeImport("foo.baz")));
+ expect(renderer.renderTemplate("foo.ftl",
freeMarkerStatement)).andReturn(FOO_CODE);
+ controller.replay();
+ freeMarkerStatement.addStatement(statement);
+ Iterable<JavaImport> requiredImports =
freeMarkerStatement.getRequiredImports();
+ assertEquals(2, Iterables.size(requiredImports));
+ controller.verify();
+ }
+
+ @Test
+ public void testGetRequiredFields() {
+ freeMarkerStatement.addConstant("boolean", "foo", FOO_CODE);
+ expect(statement.getRequiredFields()).andStubReturn(
+ Collections.<JavaField> singleton(new JavaField(TypesFactory.INT_TYPE,
"bar")));
+ expect(renderer.renderTemplate("foo.ftl",
freeMarkerStatement)).andReturn(FOO_CODE);
+ controller.replay();
+ freeMarkerStatement.addStatement(statement);
+ Iterable<JavaField> requiredFields =
freeMarkerStatement.getRequiredFields();
+ assertEquals(2, Iterables.size(requiredFields));
+ controller.verify();
+ }
+
+ @Test
+ public void testGetRequiredMethods() {
+ freeMarkerStatement.addRequiredMethod(HelperMethod.EMPTINESS_CHECK.toString());
+ expect(renderer.renderTemplate("foo.ftl",
freeMarkerStatement)).andReturn(FOO_CODE);
+ expect(statement.getRequiredMethods()).andStubReturn(
+ Collections.<HelperMethod> singleton(HelperMethod.EQUALS_CHECK));
+ controller.replay();
+ freeMarkerStatement.addStatement(statement);
+ Iterable<HelperMethod> requiredMethods =
freeMarkerStatement.getRequiredMethods();
+ assertEquals(2, Iterables.size(requiredMethods));
+ controller.verify();
+ }
+
+ @Test
+ public void testAddConstant() {
+
freeMarkerStatement.addConstant("java.util.List<java.lang.String>",
"foo", FOO_CODE);
+ JavaField javaField =
Iterables.getOnlyElement(freeMarkerStatement.getRequiredFields());
+ assertEquals("foo", javaField.getName());
+ assertEquals("java.util.List<java.lang.String>",
javaField.getType().getCode());
+ assertEquals(FOO_CODE, javaField.getValue().getCode());
+ }
+
+ @Test
+ public void testAddImport() {
+ freeMarkerStatement.addImport("java.util.List");
+ JavaImport javaImport =
Iterables.getOnlyElement(freeMarkerStatement.getRequiredImports());
+ assertEquals("java.util.List",javaImport.getName());
+ }
+
+ @Test
+ public void testAddRequiredMethod() {
+ freeMarkerStatement.addRequiredMethod(HelperMethod.EMPTINESS_CHECK.toString());
+ HelperMethod helperMethod =
Iterables.getOnlyElement(freeMarkerStatement.getRequiredMethods());
+ assertEquals(HelperMethod.EMPTINESS_CHECK, helperMethod);
+ }
+
+}
Property changes on:
root/cdk/branches/RF8755/plugins/generator/src/test/java/org/richfaces/cdk/templatecompiler/statements/FreeMarkerTemplateStatementTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
root/cdk/branches/RF8755/plugins/generator/src/test/java/org/richfaces/cdk/templatecompiler/statements/FreeMarkerTemplateStatementTest1.java
===================================================================
---
root/cdk/branches/RF8755/plugins/generator/src/test/java/org/richfaces/cdk/templatecompiler/statements/FreeMarkerTemplateStatementTest1.java
(rev 0)
+++
root/cdk/branches/RF8755/plugins/generator/src/test/java/org/richfaces/cdk/templatecompiler/statements/FreeMarkerTemplateStatementTest1.java 2010-07-02
00:31:47 UTC (rev 17703)
@@ -0,0 +1,101 @@
+package org.richfaces.cdk.templatecompiler.statements;
+
+import static org.junit.Assert.*;
+
+import java.util.Map;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.richfaces.cdk.CdkTestBase;
+import org.richfaces.cdk.CdkTestRunner;
+import org.richfaces.cdk.Logger;
+import org.richfaces.cdk.MockController;
+import org.richfaces.cdk.Stub;
+import org.richfaces.cdk.generate.freemarker.CdkConfiguration;
+import org.richfaces.cdk.generate.freemarker.DefaultImports;
+import org.richfaces.cdk.generate.freemarker.FreeMarkerRenderer;
+import org.richfaces.cdk.generate.freemarker.TemplatesFolder;
+import org.richfaces.cdk.templatecompiler.JavaClassModelWrapper;
+import org.richfaces.cdk.templatecompiler.TemplateModel;
+import org.richfaces.cdk.templatecompiler.builder.model.JavaField;
+import org.richfaces.cdk.templatecompiler.builder.model.JavaImport;
+
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.Iterables;
+import com.google.inject.Binder;
+import com.google.inject.Inject;
+import com.google.inject.TypeLiteral;
+
+import freemarker.template.ObjectWrapper;
+
+(a)RunWith(CdkTestRunner.class)
+public class FreeMarkerTemplateStatementTest1 extends CdkTestBase {
+
+ private static final String FOO_CODE = "private static final String foo;";
+
+ @Stub
+ private Logger log;
+
+ @Inject
+ @TemplateModel
+ private FreeMarkerRenderer renderer;
+
+
+
+ @Inject
+ private MockController controller;
+
+
+
+ @Override
+ public void configure(Binder binder) {
+ super.configure(binder);
+ binder.bind(ObjectWrapper.class).to(JavaClassModelWrapper.class);
+
binder.bind(FreeMarkerRenderer.class).annotatedWith(TemplateModel.class).to(CdkConfiguration.class);
+
binder.bind(String.class).annotatedWith(TemplatesFolder.class).toInstance("/META-INF/templates/java");
+ binder.bind(new
TypeLiteral<Map<String,String>>(){}).annotatedWith(DefaultImports.class).toInstance(ImmutableMap.of("util","util.ftl"));
+ }
+
+ public FreeMarkerTemplateStatementBase setUpStatement(String template) {
+ FreeMarkerTemplateStatementBase freeMarkerStatement = new
FreeMarkerTemplateStatementBase(renderer, template);
+ return freeMarkerStatement;
+ }
+
+
+ @Test
+ public void testGetCode() {
+ FreeMarkerTemplateStatementBase statement = setUpStatement("foo");
+ controller.replay();
+ String code = statement.getCode();
+ controller.verify();
+ assertEquals(FOO_CODE, code);
+ }
+
+ @Test
+ public void testAddConstant() {
+ FreeMarkerTemplateStatementBase statement =
setUpStatement("addConstant");
+ JavaField javaField = Iterables.getOnlyElement(statement.getRequiredFields());
+ assertEquals("foo", javaField.getName());
+ assertEquals("List<String>", javaField.getType().getCode());
+ assertNotNull(javaField.getValue());
+ assertEquals(FOO_CODE, javaField.getValue().getCode());
+ assertEquals("",statement.getCode());
+ }
+
+ @Test
+ public void testAddImport() {
+ FreeMarkerTemplateStatementBase statement =
setUpStatement("addImport");
+ JavaImport javaImport =
Iterables.getOnlyElement(statement.getRequiredImports());
+ assertEquals("java.util.List",javaImport.getName());
+ assertEquals("",statement.getCode());
+ }
+
+ @Test
+ public void testAddRequiredMethod() {
+ FreeMarkerTemplateStatementBase statement =
setUpStatement("addMethod");
+ HelperMethod helperMethod =
Iterables.getOnlyElement(statement.getRequiredMethods());
+ assertEquals(HelperMethod.EMPTINESS_CHECK, helperMethod);
+ assertEquals("",statement.getCode());
+ }
+
+}
Property changes on:
root/cdk/branches/RF8755/plugins/generator/src/test/java/org/richfaces/cdk/templatecompiler/statements/FreeMarkerTemplateStatementTest1.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
root/cdk/branches/RF8755/plugins/generator/src/test/java/org/richfaces/cdk/templatecompiler/statements/StatatementsContainerTest.java
===================================================================
---
root/cdk/branches/RF8755/plugins/generator/src/test/java/org/richfaces/cdk/templatecompiler/statements/StatatementsContainerTest.java
(rev 0)
+++
root/cdk/branches/RF8755/plugins/generator/src/test/java/org/richfaces/cdk/templatecompiler/statements/StatatementsContainerTest.java 2010-07-02
00:31:47 UTC (rev 17703)
@@ -0,0 +1,140 @@
+package org.richfaces.cdk.templatecompiler.statements;
+
+import static org.easymock.EasyMock.*;
+import static org.junit.Assert.*;
+
+import java.util.Collections;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.richfaces.cdk.CdkTestBase;
+import org.richfaces.cdk.CdkTestRunner;
+import org.richfaces.cdk.Mock;
+import org.richfaces.cdk.MockController;
+import org.richfaces.cdk.templatecompiler.builder.model.JavaImport;
+import org.richfaces.cdk.templatecompiler.el.types.TypesFactory;
+
+import com.google.common.collect.Iterables;
+import com.google.inject.Inject;
+import com.google.inject.internal.ImmutableSet;
+import com.google.inject.name.Named;
+
+(a)RunWith(CdkTestRunner.class)
+public class StatatementsContainerTest extends CdkTestBase {
+
+ @Mock
+ private TemplateStatement statement;
+
+ @Mock
+ @Named("second")
+ private TemplateStatement statement1;
+
+ @Mock
+ private JavaImport import1;
+ @Mock
+ @Named("second")
+ private JavaImport import2;
+ @Mock
+ @Named("third")
+ private JavaImport import3;
+
+ @Inject
+ private MockController controller;
+
+ @Inject
+ private StatementsContainer container;
+
+ @Test
+ public void addStatement() throws Exception {
+ statement.setParent(container);
+ expectLastCall();
+ controller.replay();
+ container.addStatement(statement);
+ controller.verify();
+ assertSame(statement, container.getStatements().get(0));
+ }
+
+ @Test
+ public void addStatement1() throws Exception {
+ statement.setParent(container);
+ expectLastCall();
+ controller.replay();
+ container.getStatements().add(statement);
+ controller.verify();
+ assertSame(statement, container.getStatements().get(0));
+ }
+
+ @Test
+ public void addStatement2() throws Exception {
+ statement.setParent(container);
+ expectLastCall();
+ statement1.setParent(container);
+ expectLastCall();
+ controller.replay();
+ container.addStatement(statement);
+ container.addStatement(statement1);
+ controller.verify();
+ assertEquals(2, container.getStatements().size());
+ assertSame(statement, container.getStatements().get(0));
+ }
+
+ @Test
+ public void getImports() throws Exception {
+ statement.setParent(container);
+ expectLastCall();
+
expect(statement.getRequiredImports()).andReturn(Collections.singleton(import1));
+ statement1.setParent(container);
+ expectLastCall();
+ expect(statement1.getRequiredImports()).andReturn(ImmutableSet.of(import2,
import3));
+ controller.replay();
+ container.addStatement(statement);
+ container.addStatement(statement1);
+ JavaImport[] javaImports = Iterables.toArray(container.getRequiredImports(),
JavaImport.class);
+ controller.verify();
+ assertEquals(3, javaImports.length);
+ assertSame(import1, javaImports[0]);
+ }
+
+ @Test
+ public void getCode() throws Exception {
+ statement.setParent(container);
+ expectLastCall();
+ expect(statement.getCode()).andReturn("first ");
+ statement1.setParent(container);
+ expectLastCall();
+ expect(statement1.getCode()).andReturn("second");
+ controller.replay();
+ container.addStatement(statement);
+ container.addStatement(statement1);
+ String code = container.getCode();
+ controller.verify();
+ assertTrue(code.contains("first"));
+ assertTrue(code.contains("second"));
+ }
+
+ @Test
+ public void testVariables() throws Exception {
+ StatementsContainer parent = new StatementsContainer();
+ parent.addStatement(container);
+ parent.setVariable("foo", TypesFactory.OBJECT_TYPE);
+ assertTrue(container.isDefined("foo"));
+ }
+
+ @Test
+ public void testVariables1() throws Exception {
+ StatementsContainer parent = new StatementsContainer();
+ parent.addStatement(container);
+ container.setVariable("foo", TypesFactory.OBJECT_TYPE);
+ assertFalse(parent.isDefined("foo"));
+ }
+
+ @Test
+ public void testVariables2() throws Exception {
+ StatementsContainer parent = new StatementsContainer();
+ parent.addStatement(container);
+ parent.setVariable("foo", TypesFactory.OBJECT_TYPE);
+ container.setVariable("foo", TypesFactory.INTEGER_TYPE);
+ assertTrue(container.isDefined("foo"));
+ assertEquals(TypesFactory.INTEGER_TYPE, container.getVariable("foo"));
+ }
+}
Property changes on:
root/cdk/branches/RF8755/plugins/generator/src/test/java/org/richfaces/cdk/templatecompiler/statements/StatatementsContainerTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
root/cdk/branches/RF8755/plugins/generator/src/test/resources/META-INF/templates/java/addConstant.ftl
===================================================================
---
root/cdk/branches/RF8755/plugins/generator/src/test/resources/META-INF/templates/java/addConstant.ftl
(rev 0)
+++
root/cdk/branches/RF8755/plugins/generator/src/test/resources/META-INF/templates/java/addConstant.ftl 2010-07-02
00:31:47 UTC (rev 17703)
@@ -0,0 +1 @@
+<(a)util.constant "List<String>" "foo">private static final
String foo;</(a)util.constant>
\ No newline at end of file
Added:
root/cdk/branches/RF8755/plugins/generator/src/test/resources/META-INF/templates/java/addImport.ftl
===================================================================
---
root/cdk/branches/RF8755/plugins/generator/src/test/resources/META-INF/templates/java/addImport.ftl
(rev 0)
+++
root/cdk/branches/RF8755/plugins/generator/src/test/resources/META-INF/templates/java/addImport.ftl 2010-07-02
00:31:47 UTC (rev 17703)
@@ -0,0 +1 @@
+<(a)util.import "java.util.List" />
\ No newline at end of file
Added:
root/cdk/branches/RF8755/plugins/generator/src/test/resources/META-INF/templates/java/addMethod.ftl
===================================================================
---
root/cdk/branches/RF8755/plugins/generator/src/test/resources/META-INF/templates/java/addMethod.ftl
(rev 0)
+++
root/cdk/branches/RF8755/plugins/generator/src/test/resources/META-INF/templates/java/addMethod.ftl 2010-07-02
00:31:47 UTC (rev 17703)
@@ -0,0 +1 @@
+<(a)util.require "EMPTINESS_CHECK"/>
\ No newline at end of file
Added:
root/cdk/branches/RF8755/plugins/generator/src/test/resources/META-INF/templates/java/foo.ftl
===================================================================
---
root/cdk/branches/RF8755/plugins/generator/src/test/resources/META-INF/templates/java/foo.ftl
(rev 0)
+++
root/cdk/branches/RF8755/plugins/generator/src/test/resources/META-INF/templates/java/foo.ftl 2010-07-02
00:31:47 UTC (rev 17703)
@@ -0,0 +1 @@
+private static final String foo;
\ No newline at end of file