Author: akazakov
Date: 2007-07-23 10:10:02 -0400 (Mon, 23 Jul 2007)
New Revision: 2606
Modified:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/core/SeamPreferences.java
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/el/SeamELCompletionEngine.java
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/el/SeamExpressionResolver.java
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/preferences/SeamPreferenceInitializer.java
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/validation/SeamELValidator.java
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/validation/SeamValidator.java
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/validation/messages.properties
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/preferences/SeamPreferencesMessages.java
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/preferences/SeamPreferencesMessages.properties
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/preferences/SeamValidatorConfigurationBlock.java
Log:
http://jira.jboss.com/jira/browse/JBIDE-517
Modified:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/core/SeamPreferences.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/core/SeamPreferences.java 2007-07-23
14:04:30 UTC (rev 2605)
+++
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/core/SeamPreferences.java 2007-07-23
14:10:02 UTC (rev 2606)
@@ -80,6 +80,7 @@
// Seam Expression language
public static final String INVALID_EXPRESSION =
createSeverityOption("invalidExpression");
+ public static final String UNPAIRED_GETTER_OR_SETTER =
createSeverityOption("unpairedGetterOrSetter");
private static String createSeverityOption(String shortName) {
String name = SeamCorePlugin.PLUGIN_ID + ".validator.problem." + shortName;
Modified:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/el/SeamELCompletionEngine.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/el/SeamELCompletionEngine.java 2007-07-23
14:04:30 UTC (rev 2605)
+++
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/el/SeamELCompletionEngine.java 2007-07-23
14:10:02 UTC (rev 2606)
@@ -13,6 +13,7 @@
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
+import java.util.Map;
import java.util.Set;
import java.util.TreeSet;
@@ -64,7 +65,7 @@
if(document!=null) {
documentContent = document.get();
}
- return getCompletions(project, file, documentContent, prefix, position, false);
+ return getCompletions(project, file, documentContent, prefix, position, false, null,
null);
}
/**
@@ -75,6 +76,8 @@
* @param prefix the prefix to search for
* @param position Offset of the prefix
* @return the list of all possible suggestions
+ * @param usedVariables - Set of variables which are used in this Expression. It's
useful in incremental validation.
+ * @param unpairedGettersOrSetters - map of unpaired getters or setters of property
which is used in last segment of Expression. 'key' is property name.
* @param returnCompletedVariablesOnly - if 'true' then returns only variables
that equals prefix. It's useful for validation.
* for example:
* we have 'variableName.variableProperty',
'variableName.variableProperty1', 'variableName.variableProperty2'
@@ -87,7 +90,7 @@
* Result is {'1','2'}
*/
public List<String> getCompletions(ISeamProject project, IFile file, String
documentContent, CharSequence prefix,
- int position, boolean returnEqualedVariablesOnly) throws BadLocationException,
StringIndexOutOfBoundsException {
+ int position, boolean returnEqualedVariablesOnly, Set<ISeamContextVariable>
usedVariables, Map<String, IMethod> unpairedGettersOrSetters) throws
BadLocationException, StringIndexOutOfBoundsException {
List<String> res= new ArrayList<String>();
SeamELTokenizer tokenizer = new SeamELTokenizer(documentContent, position +
prefix.length());
@@ -112,6 +115,11 @@
}
}
+ // Save all resolved variables. It's useful for incremental validation.
+ if(resolvedVariables!=null && resolvedVariables.size()>0 &&
usedVariables!=null) {
+ usedVariables.addAll(resolvedVariables);
+ }
+
// Here we have a list of vars for some part of expression
// OK. we'll proceed with members of these vars
if (areEqualExpressions(resolvedExpressionPart, tokens)) {
@@ -201,7 +209,7 @@
try {
IType type = (mbr instanceof IType ? (IType)mbr :
EclipseJavaUtil.findType(mbr.getJavaProject(),
EclipseJavaUtil.getMemberTypeAsString(mbr)));
proposals.addAll(SeamExpressionResolver.getMethodPresentations(type));
- proposals.addAll(SeamExpressionResolver.getPropertyPresentations(type));
+ proposals.addAll(SeamExpressionResolver.getPropertyPresentations(type,
unpairedGettersOrSetters));
} catch (JavaModelException ex) {
SeamCorePlugin.getPluginLog().logError(ex);
}
@@ -219,7 +227,7 @@
type = EclipseJavaUtil.findType(mbr.getJavaProject(),
EclipseJavaUtil.getMemberTypeAsString(mbr));
}
proposalsToFilter.addAll(SeamExpressionResolver.getMethodPresentations(type));
- proposalsToFilter.addAll(SeamExpressionResolver.getPropertyPresentations(type));
+ proposalsToFilter.addAll(SeamExpressionResolver.getPropertyPresentations(type,
unpairedGettersOrSetters));
} catch (JavaModelException ex) {
SeamCorePlugin.getPluginLog().logError(ex);
}
@@ -231,6 +239,14 @@
// This is used for validation.
if (proposal.equals(filter)) {
proposals.add(proposal);
+ if(unpairedGettersOrSetters!=null) {
+ IMethod unpirMethod = unpairedGettersOrSetters.get(filter);
+ unpairedGettersOrSetters.clear();
+ if(unpirMethod!=null) {
+ unpairedGettersOrSetters.put(filter, unpirMethod);
+ }
+ }
+ break;
}
} else {
// This is used for CA.
@@ -243,7 +259,7 @@
res.addAll(proposals);
}
}
-
+
return res;
}
Modified:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/el/SeamExpressionResolver.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/el/SeamExpressionResolver.java 2007-07-23
14:04:30 UTC (rev 2605)
+++
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/el/SeamExpressionResolver.java 2007-07-23
14:10:02 UTC (rev 2606)
@@ -13,8 +13,10 @@
import java.lang.reflect.Modifier;
import java.util.ArrayList;
+import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
+import java.util.Map;
import java.util.Set;
import java.util.TreeSet;
@@ -256,21 +258,57 @@
* @return
*/
public static Set<String> getPropertyPresentations(IType type) {
+ return getPropertyPresentations(type, null);
+ }
+
+ /**
+ * Returns the property presentation strings for the type specified
+ *
+ * @param type
+ * @param unpairedGettersOrSetters - map of unpaired getters or setters of type's
properties. 'key' is property name.
+ * @return
+ */
+ public static Set<String> getPropertyPresentations(IType type, Map<String,
IMethod> unpairedGettersOrSetters) {
Set<String> properties = new
TreeSet<String>(String.CASE_INSENSITIVE_ORDER);
if (type != null) {
try {
IMethod[] props = type.getMethods();
+ HashMap<String, IMethod> getters = new HashMap<String, IMethod>();
+ HashMap<String, IMethod> setters = new HashMap<String, IMethod>();
for (int i = 0; props != null && i < props.length; i++) {
IMethod m = props[i];
- if (Modifier.isPublic(m.getFlags()) &&
- (m.getElementName().startsWith("get") &&
!"get".equals(m.getElementName())) ||
- (m.getElementName().startsWith("set") &&
!"set".equals(m.getElementName()))) {
-
- StringBuffer name = new StringBuffer(m.getElementName());
- name.delete(0, 3);
- name.setCharAt(0, Character.toLowerCase(name.charAt(0)));
-
- properties.add(name.toString());
+ if (Modifier.isPublic(m.getFlags())) {
+ String methodName = m.getElementName();
+ boolean getter = (methodName.startsWith("get") &&
!"get".equals(methodName)) ||
+ (methodName.startsWith("is") &&
!"is".equals(methodName));
+ boolean setter = methodName.startsWith("set") &&
!"set".equals(methodName);
+ if(getter || setter) {
+ StringBuffer name = new StringBuffer(methodName);
+ if(methodName.startsWith("i")) {
+ name.delete(0, 2);
+ } else {
+ name.delete(0, 3);
+ }
+ name.setCharAt(0, Character.toLowerCase(name.charAt(0)));
+ String propertyName = name.toString();
+ if(!properties.contains(propertyName)) {
+ properties.add(propertyName);
+ }
+ if(unpairedGettersOrSetters!=null) {
+ IMethod previousGetter = getters.get(propertyName);
+ IMethod previousSetter = setters.get(propertyName);
+ if((previousGetter!=null && setter)||(previousSetter!=null &&
getter)) {
+ // We have both Getter and Setter
+ unpairedGettersOrSetters.remove(propertyName);
+ } else if(setter) {
+ setters.put(propertyName, m);
+ unpairedGettersOrSetters.put(propertyName, m);
+ } else if(getter) {
+ getters.put(propertyName, m);
+ unpairedGettersOrSetters.put(propertyName, m);
+ }
+ }
+ }
}
}
} catch (JavaModelException e) {
Modified:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/preferences/SeamPreferenceInitializer.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/preferences/SeamPreferenceInitializer.java 2007-07-23
14:04:30 UTC (rev 2605)
+++
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/preferences/SeamPreferenceInitializer.java 2007-07-23
14:10:02 UTC (rev 2606)
@@ -33,5 +33,6 @@
}
defaultPreferences.put(SeamPreferences.INVALID_EXPRESSION, SeamPreferences.WARNING);
defaultPreferences.put(SeamPreferences.UNKNOWN_VARIABLE_NAME,
SeamPreferences.WARNING);
+ defaultPreferences.put(SeamPreferences.UNPAIRED_GETTER_OR_SETTER,
SeamPreferences.WARNING);
}
}
\ No newline at end of file
Modified:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/validation/SeamELValidator.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/validation/SeamELValidator.java 2007-07-23
14:04:30 UTC (rev 2605)
+++
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/validation/SeamELValidator.java 2007-07-23
14:10:02 UTC (rev 2606)
@@ -12,14 +12,17 @@
import java.io.IOException;
import java.util.Collection;
+import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
+import java.util.Map;
import java.util.Set;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jdt.core.IMethod;
import org.eclipse.jdt.internal.ui.text.FastJavaPartitionScanner;
import org.eclipse.jdt.ui.text.IJavaPartitions;
import org.eclipse.jface.text.BadLocationException;
@@ -36,6 +39,7 @@
import org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel;
import org.eclipse.wst.xml.core.internal.regions.DOMRegionContext;
import org.jboss.tools.common.util.FileUtil;
+import org.jboss.tools.seam.core.ISeamContextVariable;
import org.jboss.tools.seam.core.SeamCorePlugin;
import org.jboss.tools.seam.core.SeamPreferences;
import org.jboss.tools.seam.internal.core.el.SeamELCompletionEngine;
@@ -187,39 +191,55 @@
}
for(EL el: els) {
- if(!validateEl(file, el)) {
- // Mark EL
- addError(INVALID_EXPRESSION_MESSAGE_ID, SeamPreferences.INVALID_EXPRESSION, new
String[]{el.getValue()}, el.getLength(), el.getOffset(), file,
MARKED_SEAM_RESOURCE_MESSAGE_GROUP);
- }
+ validateEl(file, el);
}
}
- private boolean validateEl(IFile file, EL el) {
+ private void validateEl(IFile file, EL el) {
try {
-// String exp = "#{" + el.value + "}";
String exp = el.value;
int offset = exp.length();
-// String prefix= SeamELCompletionEngine.getPrefix(exp, offset);
-// prefix = (prefix == null ? "" : prefix);
String prefix = SeamELCompletionEngine.getPrefix(exp, offset);
- if(prefix==null) {
- return false;
- }
- int possition = 0;
+ if(prefix!=null) {
+ int possition = 0;
+
+ Set<ISeamContextVariable> usedVariables = new
HashSet<ISeamContextVariable>();
+ Map<String, IMethod> unpairedGettersOrSetters = new HashMap<String,
IMethod>();
+
+ List<String> suggestions = engine.getCompletions(project, file, exp, prefix,
possition, true, usedVariables, unpairedGettersOrSetters);
- // TODO ?
- List<String> suggestions = engine.getCompletions(project, file, exp, prefix,
possition, true);
+ // Check pair for getter/setter
+ if(unpairedGettersOrSetters.size()>0) {
+ IMethod unpairedMethod = unpairedGettersOrSetters.values().iterator().next();
+ String methodName = unpairedMethod.getElementName();
+// int indexOfPropertyName = 3;
+// if(methodName.startsWith("i")) {
+// indexOfPropertyName = 2;
+// }
+ String propertyName = unpairedGettersOrSetters.keySet().iterator().next();
+// propertyName.setCharAt(0, Character.toLowerCase(propertyName.charAt(0)));
+ String missingMethodName = "Setter";
+ String existedMethodName = "Getter";
+ if(methodName.startsWith("s")) {
+ missingMethodName = existedMethodName;
+ existedMethodName = "Setter";
+ }
+ addError(UNPAIRED_GETTER_OR_SETTER_MESSAGE_ID,
SeamPreferences.UNPAIRED_GETTER_OR_SETTER, new String[]{propertyName, existedMethodName,
missingMethodName}, el.getLength(), el.getOffset(), file,
MARKED_SEAM_RESOURCE_MESSAGE_GROUP);
+ }
- if (suggestions != null && suggestions.size() > 0) {
- return true;
+ if (suggestions != null && suggestions.size() > 0) {
+ // It's valid EL.
+ return;
+ }
}
} catch (BadLocationException e) {
SeamCorePlugin.getDefault().logError("Error validating Seam EL", e);
} catch (StringIndexOutOfBoundsException e) {
SeamCorePlugin.getDefault().logError("Error validating Seam EL", e);
}
- return false;
+ // Mark invalid EL
+ addError(INVALID_EXPRESSION_MESSAGE_ID, SeamPreferences.INVALID_EXPRESSION, new
String[]{el.getValue()}, el.getLength(), el.getOffset(), file,
MARKED_SEAM_RESOURCE_MESSAGE_GROUP);
}
private IJavaProject getJavaProject() {
Modified:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/validation/SeamValidator.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/validation/SeamValidator.java 2007-07-23
14:04:30 UTC (rev 2605)
+++
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/validation/SeamValidator.java 2007-07-23
14:10:02 UTC (rev 2606)
@@ -54,6 +54,7 @@
protected static final String UNKNOWN_COMPONENT_CLASS_NAME_MESSAGE_ID =
"UNKNOWN_COMPONENT_CLASS_NAME";
protected static final String UNKNOWN_COMPONENT_PROPERTY_MESSAGE_ID =
"UNKNOWN_COMPONENT_PROPERTY";
protected static final String INVALID_EXPRESSION_MESSAGE_ID =
"INVALID_EXPRESSION";
+ protected static final String UNPAIRED_GETTER_OR_SETTER_MESSAGE_ID =
"UNPAIRED_GETTER_OR_SETTER";
protected SeamValidationHelper coreHelper;
protected IReporter reporter;
Modified:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/validation/messages.properties
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/validation/messages.properties 2007-07-23
14:04:30 UTC (rev 2605)
+++
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/validation/messages.properties 2007-07-23
14:10:02 UTC (rev 2606)
@@ -41,4 +41,5 @@
UNKNOWN_VARIABLE_NAME=Unknown context variable name: {0}
#Seam Expression language
-INVALID_EXPRESSION=Invalid Expression: {0}
\ No newline at end of file
+INVALID_EXPRESSION=Invalid Expression: {0}
+UNPAIRED_GETTER_OR_SETTER=Property "{0}" has only {1}. {2} is missing.
\ No newline at end of file
Modified:
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/preferences/SeamPreferencesMessages.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/preferences/SeamPreferencesMessages.java 2007-07-23
14:04:30 UTC (rev 2605)
+++
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/preferences/SeamPreferencesMessages.java 2007-07-23
14:10:02 UTC (rev 2606)
@@ -66,6 +66,7 @@
//Seam Expression language
public static String SeamValidatorConfigurationBlock_section_el;
public static String SeamValidatorConfigurationBlock_pb_invalidExpression_label;
+ public static String SeamValidatorConfigurationBlock_pb_unpairedGetterOrSetter_label;
static {
NLS.initializeMessages(BUNDLE_NAME, SeamPreferencesMessages.class);
Modified:
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/preferences/SeamPreferencesMessages.properties
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/preferences/SeamPreferencesMessages.properties 2007-07-23
14:04:30 UTC (rev 2605)
+++
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/preferences/SeamPreferencesMessages.properties 2007-07-23
14:10:02 UTC (rev 2606)
@@ -55,4 +55,5 @@
##Seam Expression language
SeamValidatorConfigurationBlock_section_el=Expression language
-SeamValidatorConfigurationBlock_pb_invalidExpression_label=Invalid Expression:
\ No newline at end of file
+SeamValidatorConfigurationBlock_pb_invalidExpression_label=Invalid Expression:
+SeamValidatorConfigurationBlock_pb_unpairedGetterOrSetter_label=Unpaired Getter/Setter:
\ No newline at end of file
Modified:
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/preferences/SeamValidatorConfigurationBlock.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/preferences/SeamValidatorConfigurationBlock.java 2007-07-23
14:04:30 UTC (rev 2605)
+++
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/preferences/SeamValidatorConfigurationBlock.java 2007-07-23
14:10:02 UTC (rev 2606)
@@ -113,6 +113,7 @@
SeamPreferencesMessages.SeamValidatorConfigurationBlock_section_el,
new String[][]{
{SeamPreferences.INVALID_EXPRESSION,
SeamPreferencesMessages.SeamValidatorConfigurationBlock_pb_invalidExpression_label},
+ {SeamPreferences.UNPAIRED_GETTER_OR_SETTER,
SeamPreferencesMessages.SeamValidatorConfigurationBlock_pb_unpairedGetterOrSetter_label}
}
);