Author: alexsmirnov
Date: 2010-06-22 19:05:28 -0400 (Tue, 22 Jun 2010)
New Revision: 17660
Added:
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/Variables.java
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/generate/freemarker/LibraryModelWrapper.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/VisitorFactoryImpl.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/MethodBodyStatementsContainer.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/ELVisitor.java
root/cdk/branches/RF8755/plugins/generator/src/main/resources/META-INF/templates/component.ftl
root/cdk/branches/RF8755/plugins/generator/src/test/java/org/richfaces/cdk/templatecompiler/parser/el/test/ELParserTest.java
Log:
Template compiler optimization
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-06-22
19:08:34 UTC (rev 17659)
+++
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/Generator.java 2010-06-22
23:05:28 UTC (rev 17660)
@@ -18,7 +18,7 @@
* 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;
@@ -48,27 +48,33 @@
import com.google.inject.Guice;
import com.google.inject.Injector;
import com.google.inject.Stage;
+import com.google.inject.TypeLiteral;
import com.google.inject.name.Names;
+import com.google.inject.util.Providers;
/**
* @author asmirnov
* @version $Id$
- *
+ *
*/
public class Generator {
-
+
+ public static final String RENDERER_UTILS_CLASS = "rendererUtils";
+
+ public static final String OPTIONS = "OPTIONS";
+
private CdkClassLoader loader;
-
+
private Logger log = new JavaLogger();
-
+
private Injector injector;
private String namespace;
-
+
private Locale locale = Locale.getDefault();
-
+
private Charset charset = Charset.defaultCharset();
-
+
private Map<Outputs, FileManager> outputFolders =
Maps.newEnumMap(Outputs.class);
private Map<Sources, FileManager> sources = Maps.newEnumMap(Sources.class);
@@ -76,19 +82,17 @@
private LibraryBuilder libraryBuilder;
private Map<String, String> options = Maps.newHashMap();
-
-
+
public Generator() {
EmptyFileManager emptyFileManager = new EmptyFileManager();
for (Sources source : Sources.values()) {
sources.put(source, emptyFileManager);
}
-
+
for (Outputs output : Outputs.values()) {
- outputFolders.put(output, emptyFileManager);
+ outputFolders.put(output, emptyFileManager);
}
}
-
public void setLoader(CdkClassLoader loader) {
this.loader = loader;
@@ -105,24 +109,17 @@
public void addSources(Sources type, Iterable<File> files, Iterable<File>
folders) {
this.sources.put(type, new SourceFileManagerImpl(files, folders));
}
-
+
public void setOptions(Map<String, String> options) {
this.options = options;
-
+
}
-
public void init() {
- injector = Guice.createInjector(Stage.PRODUCTION,
- new CdkConfigurationModule(),
- new AptModule(),
- new ModelModule(),
- new ClassGeneratorModule(),
- new TagHandlerModule(),
- new FreeMakerModule(),
- new TemplateModule(),
- new XmlModule(),
- new TaglibModule());
+ injector =
+ Guice.createInjector(Stage.PRODUCTION, new CdkConfigurationModule(), new
AptModule(), new ModelModule(),
+ new ClassGeneratorModule(), new TagHandlerModule(), new
FreeMakerModule(), new TemplateModule(),
+ new XmlModule(), new TaglibModule());
if (!log.isDebugEnabled()) {
try {
@@ -135,12 +132,12 @@
// Create builder instance.
this.libraryBuilder = injector.getInstance(LibraryBuilder.class);
}
-
+
public void execute() {
checkNotNull(libraryBuilder, "initialized");
libraryBuilder.build();
-// libraryBuilder.generate(); // TODO ?
+ // libraryBuilder.generate(); // TODO ?
}
public static final class EmptyFileManager implements FileManager {
@@ -148,17 +145,17 @@
public Iterable<File> getFolders() {
return Collections.emptyList();
}
-
+
@Override
public Iterable<File> getFiles() {
return Collections.emptyList();
}
-
+
@Override
public File getFile(String path) throws FileNotFoundException {
throw new FileNotFoundException();
}
-
+
@Override
public Writer createOutput(String path, long lastModified) throws IOException {
throw new IOException("read-only");
@@ -182,11 +179,17 @@
}
bind(NamingConventions.class).to(RichFacesConventions.class);
bind(ModelValidator.class).to(ValidatorImpl.class);
-
- Names.bindProperties(binder(), options);
+
+ bind(new TypeLiteral<Map<String, String>>() {
+ }).annotatedWith(Names.named(OPTIONS)).toInstance(options);
+ bindOption(RENDERER_UTILS_CLASS);
}
-
-
+
+ private void bindOption(String name) {
+ bind(String.class).annotatedWith(Names.named(name)).toProvider(
+ Providers.of(options.get(name)));
+ }
+
}
public String getNamespace() {
Modified:
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/freemarker/LibraryModelWrapper.java
===================================================================
---
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/freemarker/LibraryModelWrapper.java 2010-06-22
19:08:34 UTC (rev 17659)
+++
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/freemarker/LibraryModelWrapper.java 2010-06-22
23:05:28 UTC (rev 17660)
@@ -21,33 +21,42 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
-
-
package org.richfaces.cdk.generate.freemarker;
import org.richfaces.cdk.model.ClassName;
import org.richfaces.cdk.model.EventModel;
+import org.richfaces.cdk.model.FacesId;
import org.richfaces.cdk.model.ModelElementBase;
import org.richfaces.cdk.model.PropertyBase;
import org.richfaces.cdk.model.TagModel;
import freemarker.ext.beans.BeansWrapper;
+import freemarker.ext.beans.StringModel;
+import freemarker.ext.util.ModelFactory;
import freemarker.template.ObjectWrapper;
import freemarker.template.TemplateModel;
import freemarker.template.TemplateModelException;
/**
- * <p class="changed_added_4_0"></p>
+ * <p class="changed_added_4_0">
+ * </p>
+ *
* @author asmirnov(a)exadel.com
- *
+ *
*/
public class LibraryModelWrapper extends BeansWrapper implements ObjectWrapper {
+ static final ModelFactory STRING_MODEL_FACTORY = new ModelFactory() {
+ public TemplateModel create(Object object, ObjectWrapper wrapper) {
+ return new StringModel(object, (BeansWrapper) wrapper);
+ }
+ };
+
public LibraryModelWrapper() {
super();
setStrict(true);
setSimpleMapWrapper(true);
-// setNullModel(TemplateScalarModel.EMPTY_STRING);
+ // setNullModel(TemplateScalarModel.EMPTY_STRING);
setUseCache(true);
}
@@ -57,12 +66,14 @@
return create(obj, PropertyModel.FACTORY);
} else if (obj instanceof ClassName) {
return create(obj, ClassNameModel.FACTORY);
+ } else if (obj instanceof FacesId) {
+ return create(obj, STRING_MODEL_FACTORY);
} else if (obj instanceof EventModel) {
return create(obj, EventTemplateModel.FACTORY);
} else if (obj instanceof TagModel) {
return create(obj, TagTemplateModel.FACTORY);
} else if (obj instanceof ModelElementBase) {
- return create(obj,ModelElementBaseTemplateModel.FACTORY);
+ return create(obj, ModelElementBaseTemplateModel.FACTORY);
} else {
return super.wrap(obj);
}
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-06-22
19:08:34 UTC (rev 17659)
+++
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/RendererClassVisitor.java 2010-06-22
23:05:28 UTC (rev 17660)
@@ -49,7 +49,6 @@
import org.richfaces.cdk.attributes.Attribute;
import org.richfaces.cdk.attributes.Element;
import org.richfaces.cdk.attributes.Schema;
-import org.richfaces.cdk.attributes.SchemaSet;
import org.richfaces.cdk.model.EventName;
import org.richfaces.cdk.model.PropertyBase;
import org.richfaces.cdk.templatecompiler.builder.model.Argument;
@@ -79,7 +78,6 @@
import org.richfaces.cdk.templatecompiler.model.Template;
import org.richfaces.cdk.templatecompiler.model.TemplateVisitor;
import org.richfaces.cdk.util.Strings;
-import org.richfaces.cdk.xmlconfig.JAXB;
import com.google.common.base.Function;
import com.google.common.collect.Collections2;
@@ -146,30 +144,31 @@
private MethodBodyStatementsContainer currentStatement;
- private Schema attributesSchema = null;
+ private final Schema attributesSchema ;
private JavaClass generatedClass;
private CompositeInterface compositeInterface;
private final LinkedList<MethodBodyStatementsContainer> statements =
Lists.newLinkedList();
private Map<String, Type> localsTypesMap;
- private ClassLoader classLoader;
+ private final ClassLoader classLoader;
private Set<HelperMethod> addedHelperMethods =
EnumSet.noneOf(HelperMethod.class);
private Type lastCompiledExpressionType;
private int passThroughCounter;
- private Collection<PropertyBase> attributes;
+ private final Collection<PropertyBase> attributes;
+
+ private final VisitorFactoryImpl visitorFactoryImpl;
public RendererClassVisitor(CompositeInterface compositeInterface,
Collection<PropertyBase> attributes,
- ClassLoader classLoader, JAXB jaxbBinding, Logger log) {
+ VisitorFactoryImpl factory) {
this.compositeInterface = compositeInterface;
this.attributes = attributes;
- this.classLoader = classLoader;
- this.log = log;
- // TODO - cache unmarshalled data (as CDKWorker?)
- SchemaSet schemaSet =
jaxbBinding.unmarshal("urn:attributes:xhtml-el.xml", null, SchemaSet.class);
- this.attributesSchema = schemaSet.getSchemas().get(Template.XHTML_EL_NAMESPACE);
+ this.visitorFactoryImpl = factory;
+ this.classLoader = factory.classLoader;
+ this.log = factory.log;
+ this.attributesSchema = factory.attributesSchema;
}
private void initializeJavaClass() {
@@ -221,7 +220,7 @@
private String compileEl(String expression, Class<?> type) {
try {
ELVisitor elVisitor = new ELVisitor();
- elVisitor.parse(expression, localsTypesMap, TypesFactory.getType(type));
+ elVisitor.parse(expression, currentStatement, TypesFactory.getType(type));
lastCompiledExpressionType = elVisitor.getExpressionType();
String parsedExpression = elVisitor.getParsedExpression();
@@ -331,7 +330,7 @@
passThroughField.addModifier(JavaModifier.FINAL);
generatedClass.addImport("org.richfaces.renderkit.ComponentAttribute");
- generatedClass.addImport(RENDER_KIT_UTILS_CLASS_NAME);
+ addRendererUtilsImport();
generatedClass.addImport(Collections.class);
// TODO - get rid of FQNs for classes via imports
@@ -360,6 +359,12 @@
return fieldName;
}
+ private void addRendererUtilsImport() {
+ if (!Strings.isEmpty(this.visitorFactoryImpl.rendererUtilsClassName)) {
+ generatedClass.addImport("static " +
this.visitorFactoryImpl.rendererUtilsClassName + ".*");
+ }
+ }
+
private void createMethodContext() {
this.currentStatement = new MethodBody();
this.localsTypesMap = new HashMap<String, Type>();
@@ -518,7 +523,7 @@
} else {
String attributeLocalName = attributeName.getLocalPart();
if (writtenAttributes.add(attributeLocalName)) {
- generatedClass.addImport(RENDER_KIT_UTILS_CLASS_NAME);
+ addRendererUtilsImport();
currentStatement.addStatement(new
WriteAttributeStatement(attributeLocalName, compileEl(
attributeValue.toString(), Object.class)));
}
@@ -544,7 +549,7 @@
if (!actualAttributesMap.isEmpty()) {
String passThroughFieldName =
createPassThroughField(actualAttributesMap);
- generatedClass.addImport(RENDER_KIT_UTILS_CLASS_NAME);
+ addRendererUtilsImport();
currentStatement.addStatement(new
WriteAttributesSetStatement(passThroughFieldName));
}
}
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-06-22
19:08:34 UTC (rev 17659)
+++
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/TemplateModule.java 2010-06-22
23:05:28 UTC (rev 17660)
@@ -27,6 +27,7 @@
import org.richfaces.cdk.ModelBuilder;
import com.google.inject.AbstractModule;
+import com.google.inject.Singleton;
import com.google.inject.TypeLiteral;
import com.google.inject.multibindings.Multibinder;
@@ -45,7 +46,7 @@
Multibinder<ModelBuilder> modelBinder = Multibinder.newSetBinder(binder(),
ModelBuilder.class);
modelBinder.addBinding().to(RendererTemplateParser.class);
Multibinder.newSetBinder(binder(),
CdkWriter.class).addBinding().to(RendererClassGenerator.class);
- bind(new
TypeLiteral<TemplateVisitorFactory<RendererClassVisitor>>(){}).to(VisitorFactoryImpl.class);
+ bind(new
TypeLiteral<TemplateVisitorFactory<RendererClassVisitor>>(){}).to(VisitorFactoryImpl.class).in(Singleton.class);
bind(FreeMarkerRenderer.class).to(JavaClassConfiguration.class);
}
Modified:
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/VisitorFactoryImpl.java
===================================================================
---
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/VisitorFactoryImpl.java 2010-06-22
19:08:34 UTC (rev 17659)
+++
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/VisitorFactoryImpl.java 2010-06-22
23:05:28 UTC (rev 17660)
@@ -26,12 +26,18 @@
import java.util.Collection;
import org.richfaces.cdk.CdkClassLoader;
+import org.richfaces.cdk.Generator;
import org.richfaces.cdk.Logger;
+import org.richfaces.cdk.attributes.Schema;
+import org.richfaces.cdk.attributes.SchemaSet;
import org.richfaces.cdk.model.PropertyBase;
import org.richfaces.cdk.templatecompiler.model.CompositeInterface;
+import org.richfaces.cdk.templatecompiler.model.Template;
import org.richfaces.cdk.xmlconfig.JAXB;
import com.google.inject.Inject;
+import com.google.inject.internal.Nullable;
+import com.google.inject.name.Named;
/**
* <p class="changed_added_4_0"></p>
@@ -40,9 +46,10 @@
*/
public class VisitorFactoryImpl implements
TemplateVisitorFactory<RendererClassVisitor> {
- private CdkClassLoader classLoader;
- private JAXB jaxbBinding;
- private Logger log;
+ final CdkClassLoader classLoader;
+ final Logger log;
+ final Schema attributesSchema;
+ final String rendererUtilsClassName;
/**
* <p class="changed_added_4_0"></p>
@@ -51,10 +58,12 @@
* @param log
*/
@Inject
- public VisitorFactoryImpl(CdkClassLoader classLoader, JAXB jaxbBinding, Logger log)
{
+ public VisitorFactoryImpl(CdkClassLoader classLoader, JAXB jaxbBinding, Logger
log,(a)Named(Generator.RENDERER_UTILS_CLASS) @Nullable String rendererUtilsClassName) {
this.classLoader = classLoader;
- this.jaxbBinding = jaxbBinding;
this.log = log;
+ SchemaSet schemaSet =
jaxbBinding.unmarshal("urn:attributes:xhtml-el.xml", null, SchemaSet.class);
+ this.attributesSchema = schemaSet.getSchemas().get(Template.XHTML_EL_NAMESPACE);
+ this.rendererUtilsClassName = rendererUtilsClassName;
}
/* (non-Javadoc)
@@ -62,7 +71,7 @@
*/
@Override
public RendererClassVisitor createVisitor(CompositeInterface composite,
Collection<PropertyBase> attributes) {
- return new RendererClassVisitor(composite, attributes, classLoader, jaxbBinding,
log);
+ return new RendererClassVisitor(composite, attributes, this);
}
}
Modified:
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/MethodBodyStatementsContainer.java
===================================================================
---
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/MethodBodyStatementsContainer.java 2010-06-22
19:08:34 UTC (rev 17659)
+++
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/MethodBodyStatementsContainer.java 2010-06-22
23:05:28 UTC (rev 17660)
@@ -23,22 +23,36 @@
import java.util.ArrayList;
import java.util.List;
+import java.util.Map;
import org.richfaces.cdk.templatecompiler.FreeMarkerRenderer;
+import org.richfaces.cdk.templatecompiler.el.ParsingException;
+import org.richfaces.cdk.templatecompiler.el.Type;
+import com.google.common.collect.Maps;
+
/**
* @author Nick Belaevski
* @since 4.0
*/
-public class MethodBodyStatementsContainer implements MethodBodyStatement {
+public class MethodBodyStatementsContainer implements MethodBodyStatement, Variables {
private List<MethodBodyStatement> statements = new
ArrayList<MethodBodyStatement>();
+
+ private MethodBodyStatementsContainer parent;
+
+ private final Map<String, Type> localVariablesMap = Maps.newHashMap();
+
public List<MethodBodyStatement> getStatements() {
return statements;
}
public void addStatement(MethodBodyStatement statement) {
+ if (statement instanceof MethodBodyStatementsContainer) {
+ MethodBodyStatementsContainer container = (MethodBodyStatementsContainer)
statement;
+ container.setParent(this);
+ }
statements.add(statement);
}
@@ -54,6 +68,22 @@
addStatement(index, new MethodBodyStatementImpl(statementCode));
}
+ /**
+ * <p class="changed_added_4_0"></p>
+ * @param parent the parent to set
+ */
+ public void setParent(MethodBodyStatementsContainer parent) {
+ this.parent = parent;
+ }
+
+ /**
+ * <p class="changed_added_4_0"></p>
+ * @return the parent
+ */
+ public MethodBodyStatementsContainer getParent() {
+ return parent;
+ }
+
public boolean isEmpty() {
return statements.isEmpty();
}
@@ -71,4 +101,29 @@
return sb.toString();
}
+
+ @Override
+ public Type getVariable(String name) throws ParsingException {
+ Type type = localVariablesMap.get(name);
+ if(null == type && null != parent){
+ type = parent.getVariable(name);
+ }
+ return type;
+ }
+
+ @Override
+ public boolean isDefined(String name) throws ParsingException {
+ boolean defined = localVariablesMap.containsKey(name);
+ if(!defined && null != parent){
+ defined = parent.isDefined(name);
+ }
+ return defined;
+ }
+
+ @Override
+ public Type setVariable(String name, Type type) throws ParsingException {
+ Type variable = getVariable(name);
+ localVariablesMap.put(name, type);
+ return variable;
+ }
}
Added:
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/Variables.java
===================================================================
---
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/Variables.java
(rev 0)
+++
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/Variables.java 2010-06-22
23:05:28 UTC (rev 17660)
@@ -0,0 +1,14 @@
+package org.richfaces.cdk.templatecompiler.builder.model;
+
+import org.richfaces.cdk.templatecompiler.el.ParsingException;
+import org.richfaces.cdk.templatecompiler.el.Type;
+
+public interface Variables {
+
+ public Type getVariable(String name) throws ParsingException;
+
+ public boolean isDefined(String name) throws ParsingException;
+
+ public Type setVariable(String name, Type type) throws ParsingException;
+
+}
Property changes on:
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/Variables.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified:
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/ELVisitor.java
===================================================================
---
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/ELVisitor.java 2010-06-22
19:08:34 UTC (rev 17659)
+++
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/ELVisitor.java 2010-06-22
23:05:28 UTC (rev 17660)
@@ -26,12 +26,12 @@
import java.text.MessageFormat;
import java.util.EnumSet;
-import java.util.Map;
import java.util.Set;
import org.jboss.el.parser.AstCompositeExpression;
import org.jboss.el.parser.ELParser;
import org.jboss.el.parser.Node;
+import org.richfaces.cdk.templatecompiler.builder.model.Variables;
import org.richfaces.cdk.templatecompiler.el.node.ITreeNode;
import org.richfaces.cdk.templatecompiler.el.types.TypesFactory;
/**
@@ -45,7 +45,7 @@
private Type expressionType = null;
- private Map<String, Type> variables = null;
+ private Variables variables = null;
private Set<HelperMethod> usedHelperMethods =
EnumSet.noneOf(HelperMethod.class);
@@ -59,15 +59,8 @@
this.expressionType = variableType;
}
- /**
- * @return the variables
- */
- public Map<String, Type> getVariables() {
- return variables;
- }
-
public Type getVariable(String name) throws ParsingException {
- Type variableType = variables.get(name);
+ Type variableType = variables.getVariable(name);
if (variableType == null) {
throw new ParsingException(MessageFormat.format(
"No type found in context for identifier ''{0}'',
handling as generic Object", name));
@@ -98,11 +91,11 @@
* @return generated Java code.
* @throws ParsingException - if error occurred during parsing.
*/
- public void parse(String expression, Map<String, Type> contextMap, Type
expectedType) throws ParsingException {
+ public void parse(String expression, Variables contextVariables, Type expectedType)
throws ParsingException {
reset();
Node ret = ELParser.parse(expression);
- variables = contextMap;
+ variables = contextVariables;
if (ret instanceof AstCompositeExpression && ret.jjtGetNumChildren()
>= 2) {
//AstCompositeExpression with 2+ children is a mixed expression
Modified:
root/cdk/branches/RF8755/plugins/generator/src/main/resources/META-INF/templates/component.ftl
===================================================================
---
root/cdk/branches/RF8755/plugins/generator/src/main/resources/META-INF/templates/component.ftl 2010-06-22
19:08:34 UTC (rev 17659)
+++
root/cdk/branches/RF8755/plugins/generator/src/main/resources/META-INF/templates/component.ftl 2010-06-22
23:05:28 UTC (rev 17660)
@@ -39,9 +39,11 @@
return COMPONENT_FAMILY;
}</#if>
+ <#if rendererType?exists>
public ${targetClass.simpleName}() {
+ super();
setRendererType("${rendererType}");
- }
+ }</#if>
<#if (eventNames?size > 0)>
private static final Collection<String> EVENT_NAMES =
Collections.unmodifiableCollection(Arrays.asList(
Modified:
root/cdk/branches/RF8755/plugins/generator/src/test/java/org/richfaces/cdk/templatecompiler/parser/el/test/ELParserTest.java
===================================================================
---
root/cdk/branches/RF8755/plugins/generator/src/test/java/org/richfaces/cdk/templatecompiler/parser/el/test/ELParserTest.java 2010-06-22
19:08:34 UTC (rev 17659)
+++
root/cdk/branches/RF8755/plugins/generator/src/test/java/org/richfaces/cdk/templatecompiler/parser/el/test/ELParserTest.java 2010-06-22
23:05:28 UTC (rev 17660)
@@ -31,6 +31,7 @@
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
+import org.richfaces.cdk.templatecompiler.builder.model.Variables;
import org.richfaces.cdk.templatecompiler.el.ELVisitor;
import org.richfaces.cdk.templatecompiler.el.ParsingException;
import org.richfaces.cdk.templatecompiler.el.Type;
@@ -45,8 +46,26 @@
}
private void parseExpression(String expression, Class<?> returnType) throws
ParsingException {
- Map<String, Type> contextMap = new HashMap<String, Type>();
+ final Map<String, Type> contextMap = new HashMap<String, Type>();
+ Variables variables = new Variables(){
+
+ @Override
+ public Type getVariable(String name) throws ParsingException {
+ return contextMap.get(name);
+ }
+
+ @Override
+ public boolean isDefined(String name) throws ParsingException {
+ return contextMap.containsKey(name);
+ }
+
+ @Override
+ public Type setVariable(String name, Type type) throws ParsingException {
+ return contextMap.put(name, type);
+ }
+
+ };
contextMap.put("action",
TypesFactory.getType(org.richfaces.cdk.templatecompiler.parser.el.test.Bean.class));
contextMap.put("clientId", TypesFactory.getType(String.class));
contextMap.put("test", TypesFactory.getType(boolean.class));
@@ -55,7 +74,7 @@
contextMap.put("super", TypesFactory.getType(Object.class));
contextMap.put("objectVar", TypesFactory.getType(Object.class));
- visitor.parse(expression, contextMap, TypesFactory.getType(returnType));
+ visitor.parse(expression, variables, TypesFactory.getType(returnType));
}
@Before