Author: nbelaevski
Date: 2009-12-16 15:33:00 -0500 (Wed, 16 Dec 2009)
New Revision: 16158
Removed:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/types/UnsupportedType.java
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/ELParserUtils.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AbstractMethodTreeNode.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstPropertySuffixTreeNode.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/types/NullType.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/types/ReferencedType.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/types/TypesFactory.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/RendererClassVisitor.java
Log:
https://jira.jboss.org/jira/browse/RF-7732
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/ELParserUtils.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/ELParserUtils.java 2009-12-16
16:45:26 UTC (rev 16157)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/ELParserUtils.java 2009-12-16
20:33:00 UTC (rev 16158)
@@ -19,8 +19,6 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
-
-
package org.richfaces.cdk.parser.el;
import java.beans.BeanInfo;
@@ -97,8 +95,9 @@
/**
* Class, that encapsulate all functionality, related to Reflection calls, such as
loading classes, get property
* descriptors etc...
+ *
* @author amarkhel
- *
+ *
*/
public final class ELParserUtils {
@@ -148,10 +147,11 @@
}
}
- private static Map<Class<?>, ClassDataHolder> classDataCache =
- Collections.synchronizedMap(new HashMap<Class<?>,
ClassDataHolder>());
+ private static Map<Class<?>, ClassDataHolder> classDataCache =
Collections
+ .synchronizedMap(new HashMap<Class<?>, ClassDataHolder>());
- private ELParserUtils() { }
+ private ELParserUtils() {
+ }
private static ClassDataHolder resolveClassPropertiesAndMethods(Class<?>
initialClass) throws ParsingException {
ClassDataHolder classDataHolder = classDataCache.get(initialClass);
@@ -165,10 +165,13 @@
}
/**
- * This method determine type of parsed node and create wrapper for them, that
extends AbstractTreeNode.
- * If node type is not recognized - throws ParsingException.
- * @param child - parsed node
- * @throws ParsingException - if node type is not recognized.
+ * This method determine type of parsed node and create wrapper for them, that
extends AbstractTreeNode. If node
+ * type is not recognized - throws ParsingException.
+ *
+ * @param child
+ * - parsed node
+ * @throws ParsingException
+ * - if node type is not recognized.
* @return wrapper for parsed node(if node type is recognized), that implement
ITreeNode interface.
*/
public static ITreeNode determineNodeType(Node child) throws ParsingException {
@@ -239,24 +242,26 @@
} else if (child instanceof AstBracketSuffix) {
treeNode = new AstBracketSuffixTreeNode(child);
} else {
- throw new ParsingException("Node " +
child.getClass().getSimpleName() + "[" + child.getImage() + "] is not
recognized;");
+ throw new ParsingException("Node " +
child.getClass().getSimpleName() + "[" + child.getImage()
+ + "] is not recognized;");
}
- //TODO: add support for closures
-
return treeNode;
}
/**
* This method return PropertyDescriptor by specified propertyName and clazz.
- * @param clazz - class to search
- * @param propertyName - propertyName to search
+ *
+ * @param clazz
+ * - class to search
+ * @param propertyName
+ * - propertyName to search
* @return property descriptor if found.
- * @throws ParsingException if error occured.
+ * @throws ParsingException
+ * if error occured.
*/
- public static PropertyDescriptor getPropertyDescriptor(Class<?> clazz, String
propertyName)
- throws ParsingException {
-
+ public static PropertyDescriptor getPropertyDescriptor(Class<?> clazz, String
propertyName) throws ParsingException {
+
if (clazz == null) {
return null;
}
@@ -266,17 +271,23 @@
}
/**
- * <p>Retrieve the property descriptors for the specified class,
- * introspecting and caching them the first time a particular bean class
- * is encountered.</p>
- *
- * <p><strong>FIXME</strong> - Does not work with
DynaBeans.</p>
- *
- * @param beanClass Bean class for which property descriptors are requested
+ * <p>
+ * Retrieve the property descriptors for the specified class, introspecting and
caching them the first time a
+ * particular bean class is encountered.
+ * </p>
+ *
+ * <p>
+ * <strong>FIXME</strong> - Does not work with DynaBeans.
+ * </p>
+ *
+ * @param beanClass
+ * Bean class for which property descriptors are requested
* @return the property descriptors
- * @throws ParsingException if error occured.
- *
- * @exception IllegalArgumentException if <code>beanClass</code> is null
+ * @throws ParsingException
+ * if error occured.
+ *
+ * @exception IllegalArgumentException
+ * if <code>beanClass</code> is null
*/
private static PropertyDescriptor[] getPropertyDescriptors(Class<?> beanClass)
throws ParsingException {
if (beanClass == null) {
@@ -308,31 +319,35 @@
}
/**
- * <p>Find an accessible method that matches the given name and has compatible
parameters.
- * Compatible parameters mean that every method parameter is assignable from
- * the given parameters.
- * In other words, it finds a method with the given name
- * that will take the parameters given.<p>
- *
- * <p>This method is slightly undeterminstic since it loops
- * through methods names and return the first matching method.</p>
- *
- * <p>This method is used by
- * {@link
- * #invokeMethod(Object object,String methodName,Object [] args,Class[]
parameterTypes)}.
- *
- * <p>This method can match primitive parameter by passing in wrapper classes.
- * For example, a <code>Boolean</code> will match a primitive
<code>boolean</code>
- * parameter.
- *
- * @param clazz find method in this class
- * @param methodName find method with this name
- * @param parameterTypes find method with compatible parameters
+ * <p>
+ * Find an accessible method that matches the given name and has compatible
parameters. Compatible parameters mean
+ * that every method parameter is assignable from the given parameters. In other
words, it finds a method with the
+ * given name that will take the parameters given.
+ * <p>
+ *
+ * <p>
+ * This method is slightly undeterminstic since it loops through methods names and
return the first matching method.
+ * </p>
+ *
+ * <p>
+ * This method is used by {@link #invokeMethod(Object object,String methodName,Object
[] args,Class[] parameterTypes)}.
+ *
+ * <p>
+ * This method can match primitive parameter by passing in wrapper classes. For
example, a <code>Boolean</code> will
+ * match a primitive <code>boolean</code> parameter.
+ *
+ * @param clazz
+ * find method in this class
+ * @param methodName
+ * find method with this name
+ * @param parameterTypes
+ * find method with compatible parameters
* @return The accessible method
- * @throws ParsingException if error occured.
+ * @throws ParsingException
+ * if error occured.
*/
- public static Type getMatchingVisibleMethodReturnType(Class<?> clazz, final
String methodName,
- Type[] parameterTypes) throws ParsingException {
+ public static Type getMatchingVisibleMethodReturnType(Class<?> clazz, final
String methodName, Type[] parameterTypes)
+ throws ParsingException {
if (clazz == null) {
return TypesFactory.getType(Object.class);
@@ -345,7 +360,7 @@
int paramSize = parameterTypes.length;
Method bestMatch = null;
- for (Method resolvedMethod: resolvedMethods) {
+ for (Method resolvedMethod : resolvedMethods) {
if (!isMethodVisible(resolvedMethod)) {
continue;
}
@@ -370,9 +385,13 @@
}
if (match) {
- //TODO handle overriden methods
- bestMatch = resolvedMethod;
- break;
+ if (bestMatch == null) {
+ bestMatch = resolvedMethod;
+ } else {
+ throw new ParsingException(
+ "Detected two methods with the alike signature, not able
to select the appropriate one: "
+ + resolvedMethod.toString() + " " +
bestMatch.toString());
+ }
}
}
}
@@ -384,7 +403,6 @@
}
}
-
interface ClassVisitor {
public void visit(Class<?> clazz) throws ParsingException;
}
@@ -402,7 +420,7 @@
}
public void walk(ClassVisitor visitor) throws ParsingException {
- //BFS algorithm
+ // BFS algorithm
while (!classesList.isEmpty()) {
Class<?> clazz = classesList.remove();
@@ -427,10 +445,10 @@
}
}
- //While interfaces do not have Object.class in their hierarchy directly,
- //implementations of interface are always inherited from Object.
- //As methods in this class are primarily designed to work with
implementations (beans),
- //we are adding Object.class explicitly if it hasn't been visited yet.
+ // While interfaces do not have Object.class in their hierarchy directly,
+ // implementations of interface are always inherited from Object.
+ // As methods in this class are primarily designed to work with
implementations (beans),
+ // we are adding Object.class explicitly if it hasn't been visited yet.
if (visitedClasses.add(Object.class)) {
visitor.visit(Object.class);
}
@@ -438,7 +456,7 @@
visitedClasses.clear();
}
}
-
+
public static void clearCaches() {
classDataCache.clear();
}
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AbstractMethodTreeNode.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AbstractMethodTreeNode.java 2009-12-16
16:45:26 UTC (rev 16157)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AbstractMethodTreeNode.java 2009-12-16
20:33:00 UTC (rev 16158)
@@ -31,6 +31,7 @@
import org.richfaces.cdk.parser.el.ELVisitor;
import org.richfaces.cdk.parser.el.ParsingException;
import org.richfaces.cdk.parser.el.Type;
+import org.richfaces.cdk.parser.el.types.TypesFactory;
/**
* @author Nick Belaevski
@@ -72,8 +73,15 @@
sb.append(ELNodeConstants.RIGHT_BRACKET);
- Type returnType =
ELParserUtils.getMatchingVisibleMethodReturnType(methodHolderClass, methodName,
argumentTypes
- .toArray(EMPTY_TYPES_ARRAY));
+ Type returnType = null;
+
+ try {
+ returnType =
ELParserUtils.getMatchingVisibleMethodReturnType(methodHolderClass, methodName,
argumentTypes
+ .toArray(EMPTY_TYPES_ARRAY));
+ } catch (ParsingException e) {
+ // TODO: handle exception
+ returnType = TypesFactory.getType(Object.class);
+ }
visitor.setVariableType(returnType);
}
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstPropertySuffixTreeNode.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstPropertySuffixTreeNode.java 2009-12-16
16:45:26 UTC (rev 16157)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstPropertySuffixTreeNode.java 2009-12-16
20:33:00 UTC (rev 16158)
@@ -50,12 +50,18 @@
return new String(chars);
}
- private final Method getReadMethod(Class<?> clazz, String propertyName) throws
ParsingException {
+ private final Method getReadMethod(Class<?> clazz, String propertyName) {
if (clazz == null) {
return null;
}
- PropertyDescriptor propertyDescriptor =
ELParserUtils.getPropertyDescriptor(clazz, propertyName);
+ PropertyDescriptor propertyDescriptor = null;
+ try {
+ propertyDescriptor = ELParserUtils.getPropertyDescriptor(clazz,
propertyName);
+ } catch (ParsingException e) {
+ // TODO: handle exception
+ }
+
if (propertyDescriptor == null) {
return null;
}
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/types/NullType.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/types/NullType.java 2009-12-16
16:45:26 UTC (rev 16157)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/types/NullType.java 2009-12-16
20:33:00 UTC (rev 16158)
@@ -32,11 +32,11 @@
*/
public final class NullType implements Type {
- public static final Type INSTANCE = new NullType();
-
/**
- *
+ * Singleton instance of {@link NullType}
*/
+ public static final Type INSTANCE = new NullType();
+
private NullType() {
//this class is a singleton, thus has private ctor
}
@@ -70,7 +70,6 @@
*/
@Override
public Class<?> getRawType() {
- //TODO review
return Object.class;
}
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/types/ReferencedType.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/types/ReferencedType.java 2009-12-16
16:45:26 UTC (rev 16157)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/types/ReferencedType.java 2009-12-16
20:33:00 UTC (rev 16158)
@@ -33,26 +33,16 @@
*/
public class ReferencedType implements Type {
- private String referencedClassName;
+ private String classCodeString;
- private Class<?> knownType;
-
- public ReferencedType(String className) {
- this(className, Object.class);
- }
-
- public ReferencedType(String className, Class<?> knownType) {
+ public ReferencedType(String classCodeString) {
super();
- this.referencedClassName = className;
- this.knownType = knownType;
+ this.classCodeString = classCodeString;
}
- /**
- * @return the referencedClassName
- */
- String getReferencedClassName() {
- return referencedClassName;
+ String getClassCodeString() {
+ return classCodeString;
}
/* (non-Javadoc)
@@ -60,7 +50,7 @@
*/
@Override
public String getCode() {
- return referencedClassName;
+ return classCodeString;
}
/* (non-Javadoc)
@@ -76,7 +66,7 @@
*/
@Override
public Class<?> getRawType() {
- return knownType;
+ return Object.class;
}
/* (non-Javadoc)
@@ -102,7 +92,7 @@
public int hashCode() {
final int prime = 31;
int result = 1;
- result = prime * result + ((referencedClassName == null) ? 0 :
referencedClassName.hashCode());
+ result = prime * result + ((classCodeString == null) ? 0 :
classCodeString.hashCode());
return result;
}
@@ -121,11 +111,11 @@
return false;
}
ReferencedType other = (ReferencedType) obj;
- if (referencedClassName == null) {
- if (other.referencedClassName != null) {
+ if (classCodeString == null) {
+ if (other.classCodeString != null) {
return false;
}
- } else if (!referencedClassName.equals(other.referencedClassName)) {
+ } else if (!classCodeString.equals(other.classCodeString)) {
return false;
}
return true;
@@ -163,7 +153,7 @@
if (anotherType instanceof ReferencedType) {
ReferencedType anotherReferencedType = (ReferencedType) anotherType;
- return
getReferencedClassName().equals(anotherReferencedType.getReferencedClassName());
+ return
getClassCodeString().equals(anotherReferencedType.getClassCodeString());
}
return false;
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/types/TypesFactory.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/types/TypesFactory.java 2009-12-16
16:45:26 UTC (rev 16157)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/types/TypesFactory.java 2009-12-16
20:33:00 UTC (rev 16158)
@@ -23,6 +23,7 @@
import java.lang.reflect.GenericArrayType;
import java.lang.reflect.ParameterizedType;
+import java.text.MessageFormat;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
@@ -35,6 +36,8 @@
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
+import org.richfaces.cdk.Logger;
+import org.richfaces.cdk.LoggerFactory;
import org.richfaces.cdk.parser.el.Type;
import org.richfaces.cdk.util.ArrayUtils;
@@ -44,15 +47,17 @@
*/
public final class TypesFactory {
- private static final Map<java.lang.reflect.Type, Type> REFLECTION_TYPES_CACHE =
- Collections.synchronizedMap(new HashMap<java.lang.reflect.Type, Type>());
+ private static final Logger LOG = LoggerFactory.getLogger();
- private static final Map<String, Type> REFERENCED_TYPES_CACHE =
- Collections.synchronizedMap(new HashMap<String, Type>());
-
+ private static final Map<java.lang.reflect.Type, Type> REFLECTION_TYPES_CACHE =
Collections
+ .synchronizedMap(new HashMap<java.lang.reflect.Type, Type>());
+
+ private static final Map<String, Type> REFERENCED_TYPES_CACHE = Collections
+ .synchronizedMap(new HashMap<String, Type>());
+
private static final Map<Class<?>, Class<?>>
PRIMITIVE_TO_WRAPPER_CLASSES_MAP;
private static final Map<String, Class<?>> PRIMITIVE_CLASSES_MAP;
-
+
static {
Map<Class<?>, Class<?>> primitiveToWrapperClassesMap = new
HashMap<Class<?>, Class<?>>();
primitiveToWrapperClassesMap.put(Boolean.TYPE, Boolean.class);
@@ -63,42 +68,35 @@
primitiveToWrapperClassesMap.put(Byte.TYPE, Byte.class);
primitiveToWrapperClassesMap.put(Double.TYPE, Double.class);
primitiveToWrapperClassesMap.put(Character.TYPE, Character.class);
-
+
PRIMITIVE_TO_WRAPPER_CLASSES_MAP =
Collections.unmodifiableMap(primitiveToWrapperClassesMap);
-
+
Map<String, Class<?>> primitiveClassesMap = new HashMap<String,
Class<?>>();
for (Class<?> primitiveClass : PRIMITIVE_TO_WRAPPER_CLASSES_MAP.keySet())
{
primitiveClassesMap.put(primitiveClass.getName(), primitiveClass);
}
-
+
PRIMITIVE_CLASSES_MAP = Collections.unmodifiableMap(primitiveClassesMap);
}
-
- private static final Pattern CLASS_SIGNATURE_PATTERN = Pattern.compile("^"
+
- "\\s*([^\\[<]+)\\s*" + //class name
- "(?:<\\s*(.*)\\s*>)?\\s*" + //generic signature
- "((?:\\[\\s*\\]\\s*)+)?\\s*" + //array signature
- "$");
+ private static final Pattern CLASS_SIGNATURE_PATTERN = Pattern.compile("^"
+ "\\s*([^\\[<]+)\\s*" + // class name
+ "(?:<\\s*(.*)\\s*>)?\\s*" + // generic signature
+ "((?:\\[\\s*\\]\\s*)+)?\\s*" + // array signature
+ "$");
+
private static final int CLASS_NAME_GROUP_IDX = 1;
private static final int TYPE_ARGUMENTS_GROUP_IDX = 2;
-
+
private static final int ARRAY_SIGNATURE_GROUP_IDX = 3;
private static final int ARRAY_SIGNATURE_LENGTH = "[]".length();
-
+
private static final String[] GUESS_PACKAGES;
static {
- Class<?>[] guessPackagesClasses = {
- UIComponent.class,
- Behavior.class,
- Converter.class,
- FacesContext.class,
- Collection.class,
- Object.class
- };
+ Class<?>[] guessPackagesClasses = { UIComponent.class, Behavior.class,
Converter.class, FacesContext.class,
+ Collection.class, Object.class };
GUESS_PACKAGES = new String[guessPackagesClasses.length];
int i = 0;
@@ -116,126 +114,140 @@
plainClassType = new PlainClassType(plainClass);
REFLECTION_TYPES_CACHE.put(plainClass, plainClassType);
}
-
+
return plainClassType;
}
-
- private static Type getReferencedType(String referencedClassName) {
- Type type = REFERENCED_TYPES_CACHE.get(referencedClassName);
+
+ private static Type getReferencedType(String classCodeString) {
+ Type type = REFERENCED_TYPES_CACHE.get(classCodeString);
if (type == null) {
- type = new ReferencedType(referencedClassName);
- REFERENCED_TYPES_CACHE.put(referencedClassName, type);
+ type = new ReferencedType(classCodeString);
+ REFERENCED_TYPES_CACHE.put(classCodeString, type);
}
-
+
return type;
}
-
- private static Class<?> tryLoadClas(String type, ClassLoader classLoader)
throws ClassNotFoundException {
- int dotIndex = type.indexOf('.');
+
+ private static Class<?> tryLoadClas(String className, ClassLoader classLoader)
throws ClassNotFoundException {
+ int dotIndex = className.indexOf('.');
if (dotIndex < 0) {
- //guess type
+ // guess type
for (String guessPackage : GUESS_PACKAGES) {
+ String guessTypeName = guessPackage + "." + className;
try {
- return Class.forName(guessPackage + "." + type, false,
classLoader);
+ return Class.forName(guessTypeName, true, classLoader);
} catch (ClassNotFoundException e) {
- //ignore
+ // ignore
} catch (LinkageError e) {
- // TODO: handle exception
+ if (LOG.isInfoEnabled()) {
+ LOG.info(MessageFormat.format("Class {0} couldn't be
loaded because of: {1}", guessTypeName,
+ e.getMessage()));
+ }
}
}
}
- Class<?> result = PRIMITIVE_CLASSES_MAP.get(type);
+ Class<?> result = PRIMITIVE_CLASSES_MAP.get(className);
if (result == null) {
- result = Class.forName(type, true, classLoader);
+ try {
+ result = Class.forName(className, true, classLoader);
+ } catch (LinkageError e) {
+ String errorMessage = MessageFormat.format("Class {0} couldn't
be loaded because of: {1}", className, e.getMessage());
+ if (LOG.isInfoEnabled()) {
+ LOG.info(errorMessage);
+ }
+ throw new ClassNotFoundException(errorMessage, e);
+ }
}
-
+
return result;
}
-
+
static Type[] parseTypeArgumentsString(String typeArguments, ClassLoader classLoader)
{
if (typeArguments == null) {
return null;
}
-
+
String[] typeArgumentsSplit = typeArguments.trim().split(",");
-
+
Type[] types = new Type[typeArgumentsSplit.length];
for (int i = 0; i < typeArgumentsSplit.length; i++) {
types[i] = getType(typeArgumentsSplit[i], classLoader);
}
-
+
return types;
}
-
+
public static Type getType(String typeString, ClassLoader classLoader) {
Matcher matcher = CLASS_SIGNATURE_PATTERN.matcher(typeString);
boolean matchResult = matcher.matches();
- if (!matchResult) {
- //TODO review
- throw new IllegalArgumentException("Cannot parse type signature: "
+ typeString);
- }
-
- String className = matcher.group(CLASS_NAME_GROUP_IDX).trim();
+ if (matchResult) {
+ String className = matcher.group(CLASS_NAME_GROUP_IDX).trim();
- String typeArgumentsString = matcher.group(TYPE_ARGUMENTS_GROUP_IDX);
- Type[] typeArguments = parseTypeArgumentsString(typeArgumentsString,
classLoader);
-
- String arraySignature = matcher.group(ARRAY_SIGNATURE_GROUP_IDX);
- int arrayDepth = 0;
- if (arraySignature != null) {
- arrayDepth = arraySignature.replaceAll("\\s+",
"").length() / ARRAY_SIGNATURE_LENGTH;
- }
+ String typeArgumentsString = matcher.group(TYPE_ARGUMENTS_GROUP_IDX);
+ Type[] typeArguments = parseTypeArgumentsString(typeArgumentsString,
classLoader);
- Type baseType;
- try {
- //NB: loadedClass can have name that differs from className!
- Class<?> loadedClas = tryLoadClas(className, classLoader);
+ String arraySignature = matcher.group(ARRAY_SIGNATURE_GROUP_IDX);
+ int arrayDepth = 0;
+ if (arraySignature != null) {
+ arrayDepth = arraySignature.replaceAll("\\s+",
"").length() / ARRAY_SIGNATURE_LENGTH;
+ }
- baseType = getType(loadedClas);
- } catch (ClassNotFoundException e) {
- baseType = getReferencedType(className);
- }
-
- if (arrayDepth != 0 || !ArrayUtils.isEmpty(typeArguments)) {
- return new ComplexType(baseType, typeArguments, arrayDepth);
+ Type baseType;
+ try {
+ // NB: loadedClass can have name that differs from className!
+ Class<?> loadedClas = tryLoadClas(className, classLoader);
+
+ baseType = getType(loadedClas);
+ } catch (ClassNotFoundException e) {
+ baseType = getReferencedType(className);
+ }
+
+ if (arrayDepth != 0 || !ArrayUtils.isEmpty(typeArguments)) {
+ return new ComplexType(baseType, typeArguments, arrayDepth);
+ } else {
+ return baseType;
+ }
} else {
- return baseType;
+ if (LOG.isWarnEnabled()) {
+ LOG.warn(MessageFormat.format("Cannot parse type signature:
''{0}''", typeString));
+ }
+ return getReferencedType(typeString);
}
}
-
+
static Type createType(java.lang.reflect.Type reflectionType) {
java.lang.reflect.Type[] actualTypeArguments = null;
Class<?> rawType = null;
int arrayDepth = 0;
-
- java.lang.reflect.Type localReflectionType = reflectionType;
-
+
+ java.lang.reflect.Type localReflectionType = reflectionType;
+
while (localReflectionType instanceof GenericArrayType) {
localReflectionType = ((GenericArrayType)
localReflectionType).getGenericComponentType();
arrayDepth++;
}
-
+
if (localReflectionType instanceof ParameterizedType) {
ParameterizedType parameterizedType = (ParameterizedType)
localReflectionType;
-
+
actualTypeArguments = parameterizedType.getActualTypeArguments();
rawType = (Class<?>) parameterizedType.getRawType();
} else if (localReflectionType instanceof Class<?>) {
rawType = (Class<?>) localReflectionType;
}
-
+
if (rawType != null) {
while (rawType.isArray()) {
arrayDepth++;
rawType = rawType.getComponentType();
}
-
+
Type[] typeArguments = null;
if (!ArrayUtils.isEmpty(actualTypeArguments)) {
typeArguments = getTypesArray(actualTypeArguments);
}
-
+
Type clearComponentType = getPlainClassType(rawType);
if (!ArrayUtils.isEmpty(typeArguments) || arrayDepth != 0) {
return new ComplexType(clearComponentType, typeArguments, arrayDepth);
@@ -243,17 +255,18 @@
return clearComponentType;
}
} else {
- return new UnsupportedType(reflectionType);
+ //TODO better way of handling unknown types
+ return getReferencedType(reflectionType.toString());
}
}
-
+
public static Type getType(java.lang.reflect.Type reflectionType) {
Type result = REFLECTION_TYPES_CACHE.get(reflectionType);
if (result == null) {
result = createType(reflectionType);
REFLECTION_TYPES_CACHE.put(reflectionType, result);
}
-
+
return result;
}
@@ -262,23 +275,22 @@
for (int i = 0; i < reflectionTypes.length; i++) {
types[i] = getType(reflectionTypes[i]);
}
-
+
return types;
}
-
+
public static Type getNullType() {
return NullType.INSTANCE;
}
-
+
public static void clearCaches() {
REFLECTION_TYPES_CACHE.clear();
REFERENCED_TYPES_CACHE.clear();
}
-
+
/**
- * Returns wrapper classes for passed-in class. If type is primitive, then
corresponding
- * wrapper class is returned (e.g. boolean -> Boolean), otherwise does nothing and
returns
- * passed-in class.
+ * Returns wrapper classes for passed-in class. If type is primitive, then
corresponding wrapper class is returned
+ * (e.g. boolean -> Boolean), otherwise does nothing and returns passed-in class.
*
* @return wrapper for primitive types, or passed-in class
*/
Deleted:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/types/UnsupportedType.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/types/UnsupportedType.java 2009-12-16
16:45:26 UTC (rev 16157)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/types/UnsupportedType.java 2009-12-16
20:33:00 UTC (rev 16158)
@@ -1,145 +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.parser.el.types;
-
-import java.util.Collection;
-import java.util.Collections;
-
-import org.richfaces.cdk.parser.el.Type;
-
-/**
- * @author Nick Belaevski
- *
- */
-//TODO replace with referenced type?
-public class UnsupportedType implements Type {
-
- private java.lang.reflect.Type reflectionType;
-
- /**
- * @param reflectionType
- */
- public UnsupportedType(java.lang.reflect.Type reflectionType) {
- this.reflectionType = reflectionType;
- }
-
- /* (non-Javadoc)
- * @see org.richfaces.cdk.parser.el.Type#getCode()
- */
- @Override
- public String getCode() {
- return reflectionType.toString();
- }
-
- /* (non-Javadoc)
- * @see org.richfaces.cdk.parser.el.Type#getContainerType()
- */
- @Override
- public Type getContainerType() {
- return null;
- }
-
- /* (non-Javadoc)
- * @see org.richfaces.cdk.parser.el.Type#getImportsList()
- */
- @Override
- public Collection<Class<?>> getImportsList() {
- return Collections.emptyList();
- }
-
- /* (non-Javadoc)
- * @see org.richfaces.cdk.parser.el.Type#getRawType()
- */
- @Override
- public Class<?> getRawType() {
- return Object.class;
- }
-
- /* (non-Javadoc)
- * @see org.richfaces.cdk.parser.el.Type#getTypeArguments()
- */
- @Override
- public Type[] getTypeArguments() {
- return null;
- }
-
- /* (non-Javadoc)
- * @see org.richfaces.cdk.parser.el.Type#isArray()
- */
- @Override
- public boolean isArray() {
- return false;
- }
-
- /* (non-Javadoc)
- * @see
org.richfaces.cdk.parser.el.Type#isAssignableFrom(org.richfaces.cdk.parser.el.Type)
- */
- @Override
- public boolean isAssignableFrom(Type anotherType) {
- return false;
- }
-
- /* (non-Javadoc)
- * @see org.richfaces.cdk.parser.el.Type#isNullType()
- */
- @Override
- public boolean isNullType() {
- return false;
- }
-
- /* (non-Javadoc)
- * @see java.lang.Object#hashCode()
- */
- @Override
- public int hashCode() {
- final int prime = 31;
- int result = 1;
- result = prime * result + ((reflectionType == null) ? 0 :
reflectionType.hashCode());
- return result;
- }
-
- /* (non-Javadoc)
- * @see java.lang.Object#equals(java.lang.Object)
- */
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (obj == null) {
- return false;
- }
- if (getClass() != obj.getClass()) {
- return false;
- }
- UnsupportedType other = (UnsupportedType) obj;
- if (reflectionType == null) {
- if (other.reflectionType != null) {
- return false;
- }
- } else if (!reflectionType.equals(other.reflectionType)) {
- return false;
- }
- return true;
- }
-
-}
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/RendererClassVisitor.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/RendererClassVisitor.java 2009-12-16
16:45:26 UTC (rev 16157)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/RendererClassVisitor.java 2009-12-16
20:33:00 UTC (rev 16158)
@@ -254,6 +254,29 @@
return false;
}
+ private Type createTypeOfKnownClass(JavaClass initialClass, Class<?>
knownSuperClass) {
+ assert !knownSuperClass.isInterface();
+
+ Type result = null;
+
+ JavaClass javaClass = initialClass;
+ while (javaClass != null) {
+ Type type = TypesFactory.getType(javaClass.getFullName(), classLoader);
+ if (knownSuperClass.isAssignableFrom(type.getRawType())) {
+ result = type;
+ break;
+ }
+
+ javaClass = javaClass.getSuperClass();
+ }
+
+ if (result == null) {
+ result = TypesFactory.getType(knownSuperClass);
+ }
+
+ return result;
+ }
+
private void createMethodContext() {
this.currentStatement = new MethodBody();
this.localsTypesMap = new HashMap<String, Type>();
@@ -264,29 +287,10 @@
//TODO: try load component class
localsTypesMap.put(COMPONENT_VARIABLE, TypesFactory.getType(UIComponent.class));
- Type generatedClassSuperType = null;
+ Type generatedClassType = createTypeOfKnownClass(generatedClass,
Renderer.class);
+ localsTypesMap.put(THIS_VARIABLE, generatedClassType);
- JavaClass superClass = this.generatedClass.getSuperClass();
- if (superClass != null) {
- try {
- //TODO use TypesFactory
- Class<?> loadedSuperClass = Class.forName(superClass.getFullName(),
false, classLoader);
- generatedClassSuperType = TypesFactory.getType(loadedSuperClass);
- } catch (ClassNotFoundException e) {
- LOG.warn(e.getMessage(), e);
- } catch (LinkageError e) {
- LOG.warn(e.getMessage(), e);
- }
- }
-
- if (generatedClassSuperType == null) {
- //fallback to Renderer.class
- generatedClassSuperType = TypesFactory.getType(Renderer.class);
- }
-
- localsTypesMap.put(THIS_VARIABLE, generatedClassSuperType);
-
- //TODO - different classes for 'this' and 'super'
+ Type generatedClassSuperType =
createTypeOfKnownClass(generatedClass.getSuperClass(), Renderer.class);
localsTypesMap.put(SUPER_VARIABLE, generatedClassSuperType);
}
@@ -559,6 +563,7 @@
String typeString = cdkObjectElement.getType();
String typeArgumentsString = cdkObjectElement.getTypeArguments();
if (!Strings.isEmpty(typeArgumentsString)) {
+ //TODO: generic arrays
typeString += "<" + typeArgumentsString + ">";
}