diff options
author | cbateman | 2010-01-25 18:45:40 +0000 |
---|---|---|
committer | cbateman | 2010-01-25 18:45:40 +0000 |
commit | e656f15a4f8b95ebfce1f1d999128bcb89e38aff (patch) | |
tree | 3d11002c161e446f42da5099c4987cac5f8a1cf6 | |
parent | 050a4bfeac009426726c899d14adc5d0ea0916df (diff) | |
download | webtools.jsf-e656f15a4f8b95ebfce1f1d999128bcb89e38aff.tar.gz webtools.jsf-e656f15a4f8b95ebfce1f1d999128bcb89e38aff.tar.xz webtools.jsf-e656f15a4f8b95ebfce1f1d999128bcb89e38aff.zip |
Forward port 3.0.5P patch for https://bugs.eclipse.org/bugs/show_bug.cgi?id=293211 to 3.1.2 and 3.2 streams.
4 files changed, 123 insertions, 64 deletions
diff --git a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/util/JDTBeanIntrospector.java b/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/util/JDTBeanIntrospector.java index 526d717ff..5175158cf 100644 --- a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/util/JDTBeanIntrospector.java +++ b/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/util/JDTBeanIntrospector.java @@ -49,6 +49,7 @@ public class JDTBeanIntrospector private final static String IS_PREFIX = "is"; //$NON-NLS-1$ private final IType _type; + private final HashMap<String, String> _resolvedSignatures; /** * @param type @@ -56,6 +57,7 @@ public class JDTBeanIntrospector public JDTBeanIntrospector(IType type) { _type = type; + _resolvedSignatures = new HashMap<String, String>(); } /** @@ -65,6 +67,8 @@ public class JDTBeanIntrospector */ public Map<String, JDTBeanProperty> getProperties() { + _resolvedSignatures.clear(); + final Map<String, JDTBeanProperty> propertiesWorkingCopy = new HashMap<String, JDTBeanProperty>(); final IMethod[] methods = getAllMethods(); @@ -138,7 +142,7 @@ public class JDTBeanIntrospector if (workingCopy == null) { - workingCopy = new JDTBeanPropertyWorkingCopy(_type); + workingCopy = new JDTBeanPropertyWorkingCopy(_type, _resolvedSignatures); properties.put(propertyName, workingCopy); } diff --git a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/util/JDTBeanPropertyWorkingCopy.java b/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/util/JDTBeanPropertyWorkingCopy.java index f3bdf1408..4179f0901 100644 --- a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/util/JDTBeanPropertyWorkingCopy.java +++ b/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/util/JDTBeanPropertyWorkingCopy.java @@ -11,8 +11,10 @@ package org.eclipse.jst.jsf.common.util; import java.util.ArrayList; +import java.util.HashMap; import java.util.Iterator; import java.util.List; +import java.util.Map; import org.eclipse.jdt.core.IMethod; import org.eclipse.jdt.core.IType; @@ -35,8 +37,20 @@ public class JDTBeanPropertyWorkingCopy extends JDTBeanProperty * the IMethod for the boolean "is" accessor method */ private IMethod _isGetter; + + private final Map<String, String> _resolvedSignatureMap; /** + * @param type + * @param resolvedSignatureMap + */ + public JDTBeanPropertyWorkingCopy(IType type, Map<String, String> resolvedSignatureMap) + { + super(type); + _setters = new ArrayList(); + _resolvedSignatureMap = resolvedSignatureMap; + } + /** * Constructor * @param type */ @@ -44,6 +58,7 @@ public class JDTBeanPropertyWorkingCopy extends JDTBeanProperty { super(type); _setters = new ArrayList(); + _resolvedSignatureMap = new HashMap<String, String>(); } /** @@ -80,36 +95,39 @@ public class JDTBeanPropertyWorkingCopy extends JDTBeanProperty beanProp.setGetter(getter); beanProp.setSetter(matchedSetter); return beanProp; + } private IMethod determineMatchedSetter(IMethod getter) { IMethod matchedSetter = null; - try + // if there are no setters, there is no point in proceeding + if (_setters.size() < 1) { - final String getterSig = - TypeUtil.resolveTypeSignature(_type, getter.getReturnType()); + return null; + } + try + { + final String getterSig = getResolvedSignature(_type, getter.getReturnType()); FIND_MATCHING_SETTER:for (final Iterator it = _setters.iterator(); it.hasNext();) { final IMethod setter = (IMethod) it.next(); - if (setter.getNumberOfParameters() == 1) + assert (setter.getNumberOfParameters() == 1); + final String paramSig = + getResolvedSignature + (_type,setter.getParameterTypes()[0]); + + if (paramSig.equals(getterSig)) { - final String paramSig = - TypeUtil.resolveTypeSignature - (_type,setter.getParameterTypes()[0]); - - if (paramSig.equals(getterSig)) - { - // we've found our match since only one - // setter with the same name as the getter - // can have the same matching type for a - // single arg method - matchedSetter = setter; - break FIND_MATCHING_SETTER; - } + // we've found our match since only one + // setter with the same name as the getter + // can have the same matching type for a + // single arg method + matchedSetter = setter; + break FIND_MATCHING_SETTER; } } } @@ -160,4 +178,16 @@ public class JDTBeanPropertyWorkingCopy extends JDTBeanProperty public IMethod getIsGetter() { return _isGetter; } + + private String getResolvedSignature(final IType type, final String unresolved) + { + String resolved = _resolvedSignatureMap.get(unresolved); + + if (resolved == null) + { + resolved = TypeUtil.resolveTypeSignature(_type, unresolved); + _resolvedSignatureMap.put(unresolved, resolved); + } + return resolved; + } } diff --git a/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/validation/internal/appconfig/PropertyNameValidationVisitor.java b/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/validation/internal/appconfig/PropertyNameValidationVisitor.java index 0f54e5a56..c076c1b9e 100644 --- a/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/validation/internal/appconfig/PropertyNameValidationVisitor.java +++ b/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/validation/internal/appconfig/PropertyNameValidationVisitor.java @@ -10,11 +10,21 @@ *******************************************************************************/ package org.eclipse.jst.jsf.validation.internal.appconfig; +import java.util.HashMap; import java.util.List; +import java.util.Map; import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IProject; import org.eclipse.emf.ecore.EObject; import org.eclipse.emf.ecore.EStructuralFeature; +import org.eclipse.jdt.core.IJavaProject; +import org.eclipse.jdt.core.IType; +import org.eclipse.jdt.core.JavaCore; +import org.eclipse.jdt.core.JavaModelException; +import org.eclipse.jst.jsf.common.util.JDTBeanIntrospector; +import org.eclipse.jst.jsf.common.util.JDTBeanProperty; +import org.eclipse.jst.jsf.core.internal.JSFCorePlugin; import org.eclipse.jst.jsf.facesconfig.emf.PropertyNameType; /** @@ -25,6 +35,8 @@ import org.eclipse.jst.jsf.facesconfig.emf.PropertyNameType; class PropertyNameValidationVisitor extends EObjectValidationVisitor { private final EStructuralFeature _parentClassNameFeature; + private final Map<IType, Map<String, JDTBeanProperty>> _propertyCache; + private final Map<String, IType> _typeCache; /** * @param feature @@ -36,6 +48,8 @@ class PropertyNameValidationVisitor extends EObjectValidationVisitor { super(feature, version); _parentClassNameFeature = parentClassNameFeature; + _propertyCache = new HashMap<IType, Map<String, JDTBeanProperty>>(); + _typeCache = new HashMap<String, IType>(); } protected EObjectValidationVisitor[] getChildNodeValidators() @@ -49,13 +63,13 @@ class PropertyNameValidationVisitor extends EObjectValidationVisitor if (parentClassType != null) { - String typeSig = - PropertyValidationVisitor.validateProperty((PropertyNameType)object + final boolean isBeanProperty = + validateProperty((PropertyNameType)object , file.getProject(), parentClassType); final String propertyName = ((PropertyNameType)object).getTextContent(); - if (typeSig == null) + if (!isBeanProperty) { PropertyValidationVisitor.addMessageInfo(messages, DiagnosticFactory @@ -98,4 +112,58 @@ class PropertyNameValidationVisitor extends EObjectValidationVisitor return parentClassType; } + + private boolean validateProperty(PropertyNameType object, IProject project, String parentClassType) + { + boolean isBeanProperty = false; + + final IType type = getType(parentClassType, project); + + if (type != null) + { + final String propertyName = object.getTextContent(); + + Map<String, JDTBeanProperty> cachedType = _propertyCache.get(type); + if (cachedType == null) + { + cachedType = getProperties(type, project); + _propertyCache.put(type, cachedType); + } + + final JDTBeanProperty beanProperty = cachedType.get(propertyName); + + if (beanProperty != null) + { + isBeanProperty = true; + } + } + return isBeanProperty; + } + + private Map<String, JDTBeanProperty> getProperties(final IType type, final IProject project) + { + final JDTBeanIntrospector introspector = new JDTBeanIntrospector(type); + return introspector.getProperties(); + } + + private IType getType(final String typeName, final IProject project) + { + IType type = _typeCache.get(typeName); + if (type == null) + { + IJavaProject javaProject = JavaCore.create(project); + try + { + type = javaProject.findType(typeName); + _typeCache.put(typeName, type); + } + catch (JavaModelException e) + { + JSFCorePlugin + .log(new Exception(e), + "Problem validating on parent: "+typeName); //$NON-NLS-1$ + } + } + return type; + } }
\ No newline at end of file diff --git a/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/validation/internal/appconfig/PropertyValidationVisitor.java b/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/validation/internal/appconfig/PropertyValidationVisitor.java index d3f12497b..5ff1e81d8 100644 --- a/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/validation/internal/appconfig/PropertyValidationVisitor.java +++ b/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/validation/internal/appconfig/PropertyValidationVisitor.java @@ -11,21 +11,11 @@ package org.eclipse.jst.jsf.validation.internal.appconfig; import java.util.List; -import java.util.Map; import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IProject; import org.eclipse.emf.ecore.EObject; import org.eclipse.emf.ecore.EStructuralFeature; -import org.eclipse.jdt.core.IJavaProject; -import org.eclipse.jdt.core.IType; -import org.eclipse.jdt.core.JavaCore; -import org.eclipse.jdt.core.JavaModelException; -import org.eclipse.jst.jsf.common.util.JDTBeanIntrospector; -import org.eclipse.jst.jsf.common.util.JDTBeanProperty; -import org.eclipse.jst.jsf.core.internal.JSFCorePlugin; import org.eclipse.jst.jsf.facesconfig.emf.FacesConfigPackage; -import org.eclipse.jst.jsf.facesconfig.emf.PropertyNameType; /** * Validates property's @@ -73,38 +63,5 @@ public class PropertyValidationVisitor extends EObjectValidationVisitor }; } - static String validateProperty(PropertyNameType object, IProject project, String parentClassType) - { - String signatureBeanProperty = null; - try - { - IJavaProject javaProject = JavaCore.create(project); - IType type = javaProject.findType(parentClassType); - - if (type != null) - { - final JDTBeanIntrospector introspector = - new JDTBeanIntrospector(type); - - final Map properties = introspector.getProperties(); - - final String propertyName = object.getTextContent(); - if (properties.containsKey(propertyName)) - { - final JDTBeanProperty beanProperty = - (JDTBeanProperty) properties.get(propertyName); - signatureBeanProperty = - beanProperty.getTypeSignature(); - } - } - } - catch(JavaModelException jme) - { - JSFCorePlugin - .log(new Exception(jme), - "Problem validating on parent: "+parentClassType); //$NON-NLS-1$ - } - return signatureBeanProperty; - } } |