Author: akazakov
Date: 2008-02-19 11:54:08 -0500 (Tue, 19 Feb 2008)
New Revision: 6437
Modified:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/el/ElVarSearcher.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/validation/SeamELValidator.java
Log:
http://jira.jboss.com/jira/browse/JBIDE-999
Modified:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/el/ElVarSearcher.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/el/ElVarSearcher.java 2008-02-19
16:47:00 UTC (rev 6436)
+++
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/el/ElVarSearcher.java 2008-02-19
16:54:08 UTC (rev 6437)
@@ -13,6 +13,10 @@
import java.util.ArrayList;
import java.util.List;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.jface.text.BadLocationException;
+import org.jboss.tools.seam.core.ISeamProject;
+import org.jboss.tools.seam.core.SeamCorePlugin;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
@@ -25,7 +29,39 @@
private final static String VAR_ATTRIBUTE_NAME = "var";
private final static String VALUE_ATTRIBUTE_NAME = "value";
+ private ISeamProject project;
+ private IFile file;
+ private SeamELCompletionEngine engine;
+
/**
+ * Constructor.
+ * @param project Seam project where we will look for vars.
+ * @param file File where we will look for vars.
+ * @param engine Competion Engine that we will use for resolving vars.
+ */
+ public ElVarSearcher(ISeamProject project, IFile file, SeamELCompletionEngine engine) {
+ this.project = project;
+ this.file = file;
+ this.engine = engine;
+ }
+
+ /**
+ * Constructor.
+ * @param project Seam project where we will look for vars.
+ * @param engine Competion Engine that we will use for resolving vars.
+ */
+ public ElVarSearcher(ISeamProject project, SeamELCompletionEngine engine) {
+ this(project, null, engine);
+ }
+
+ /**
+ * @param file File where we will look for vars.
+ */
+ public void setFile(IFile file) {
+ this.file = file;
+ }
+
+ /**
* @param node
* @return All var/value that can be used in node and null if can't find anyone.
*/
@@ -77,9 +113,10 @@
* Finds var in list of vars that is used in given EL.
* @param el EL without brackets.
* @param vars
+ * @param initializeNestedVars
* @return
*/
- public static Var findVarForEl(String el, List<Var> vars) {
+ public Var findVarForEl(String el, List<Var> vars, boolean initializeNestedVars)
{
if(vars!=null) {
ArrayList<Var> parentVars = new ArrayList<Var>();
for (Var var : vars) {
@@ -87,10 +124,21 @@
if(token!=null && !token.getText().endsWith(".")) {
String varName = var.getName();
if(el.equals(varName) || el.startsWith(varName + ".")) {
- if(var.getElToken()!=null) {
- Var parentVar = findVarForEl(var.getElToken().getText(), parentVars);
+ if(var.getElToken()!=null && initializeNestedVars) {
+ Var parentVar = findVarForEl(var.getElToken().getText(), parentVars, true);
if(parentVar!=null) {
ELToken resolvedToken = parentVar.getResolvedElToken();
+ if(resolvedToken==null && parentVar.getElToken()!=null) {
+ try {
+ // Initialize parent vars.
+ engine.resolveSeamELOperand(project, file, parentVar.getElToken().getText(),
parentVar.getElToken().getText(), 0, true, parentVars, this);
+ resolvedToken = parentVar.getResolvedElToken();
+ } catch (StringIndexOutOfBoundsException e) {
+ SeamCorePlugin.getPluginLog().logError(e);
+ } catch (BadLocationException e) {
+ SeamCorePlugin.getPluginLog().logError(e);
+ }
+ }
if(resolvedToken!=null) {
String oldText = var.getElToken().getText();
String newValue = "#{" + resolvedToken.getText() +
oldText.substring(parentVar.getName().length()) + "}";
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 2008-02-19
16:47:00 UTC (rev 6436)
+++
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/el/SeamELCompletionEngine.java 2008-02-19
16:54:08 UTC (rev 6437)
@@ -94,7 +94,7 @@
public List<String> getCompletions(ISeamProject project, IFile file, String
documentContent, CharSequence prefix,
int position, boolean returnEqualedVariablesOnly, List<Var> vars) throws
BadLocationException, StringIndexOutOfBoundsException {
List<String> completions = new ArrayList<String>();
- SeamELOperandResolveStatus status = resolveSeamELOperand(project, file,
documentContent, prefix, position, returnEqualedVariablesOnly, vars);
+ SeamELOperandResolveStatus status = resolveSeamELOperand(project, file,
documentContent, prefix, position, returnEqualedVariablesOnly, vars, new
ElVarSearcher(project, file, this));
if (status.isOK()) {
completions.addAll(status.getProposals());
}
@@ -209,9 +209,9 @@
private static final String collectionAdditionForMapDataModel =
".entrySet().iterator().next()";
public SeamELOperandResolveStatus resolveSeamELOperand(ISeamProject project, IFile file,
String documentContent, CharSequence prefix,
- int position, boolean returnEqualedVariablesOnly, List<Var> vars) throws
BadLocationException, StringIndexOutOfBoundsException {
+ int position, boolean returnEqualedVariablesOnly, List<Var> vars, ElVarSearcher
varSearcher) throws BadLocationException, StringIndexOutOfBoundsException {
String oldEl = prefix.toString();
- Var var = ElVarSearcher.findVarForEl(oldEl, vars);
+ Var var = varSearcher.findVarForEl(oldEl, vars, true);
String suffix = "";
String newEl = oldEl;
if(var!=null) {
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 2008-02-19
16:47:00 UTC (rev 6436)
+++
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/validation/SeamELValidator.java 2008-02-19
16:54:08 UTC (rev 6437)
@@ -72,11 +72,13 @@
private SeamELCompletionEngine engine = new SeamELCompletionEngine();
private List<Var> varListForCurentValidatedNode = new ArrayList<Var>();
+ private ElVarSearcher elVarSearcher;
public SeamELValidator(SeamValidatorManager validatorManager,
SeamValidationHelper coreHelper, IReporter reporter,
SeamValidationContext validationContext, ISeamProject project) {
super(validatorManager, coreHelper, reporter, validationContext, project);
+ elVarSearcher = new ElVarSearcher(project, engine);
}
/* (non-Javadoc)
@@ -130,6 +132,7 @@
private void validateFile(IFile file) {
displaySubtask(VALIDATING_EL_FILE_MESSAGE_ID, new String[]{projectName,
file.getName()});
+ elVarSearcher.setFile(file);
String ext = file.getFileExtension();
String content = null;
try {
@@ -282,7 +285,7 @@
}
SeamELCompletionEngine.SeamELOperandResolveStatus status =
- engine.resolveSeamELOperand(project, file, operand, prefix, position, true,
varListForCurentValidatedNode);
+ engine.resolveSeamELOperand(project, file, operand, prefix, position, true,
varListForCurentValidatedNode, elVarSearcher);
if(status.getUsedVariables().size()==0 && status.isError()) {
// Save resources with unknown variables names