Author: akazakov
Date: 2007-10-11 13:41:32 -0400 (Thu, 11 Oct 2007)
New Revision: 4123
Added:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/el/ELOperandToken.java
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/el/SeamELOperandTokenizer.java
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/validation/SeamELValidator.java
Log:
http://jira.jboss.com/jira/browse/JBIDE-1039
Added:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/el/ELOperandToken.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/el/ELOperandToken.java
(rev 0)
+++
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/el/ELOperandToken.java 2007-10-11
17:41:32 UTC (rev 4123)
@@ -0,0 +1,115 @@
+ /*******************************************************************************
+ * Copyright (c) 2007 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.seam.internal.core.el;
+
+import org.eclipse.jface.text.rules.IToken;
+
+/**
+ * Token for the EX expression operand parts
+ *
+ * @author Jeremy
+ */
+public class ELOperandToken implements IToken {
+ public static final ELOperandToken EOF = new ELOperandToken(-1, -1, null, -1);
+ public static final int EL_NAME_TOKEN = 1;
+ public static final int EL_METHOD_TOKEN = 2;
+ public static final int EL_SEPARATOR_TOKEN = 3;
+
+ int start;
+ int length;
+ CharSequence chars;
+ int type;
+
+ /**
+ * Constructs the ELToken object
+ *
+ * @param start
+ * @param length
+ * @param chars
+ * @param type
+ */
+ public ELOperandToken(int start, int length, CharSequence chars, int type) {
+ this.start = start;
+ this.length = length;
+ this.chars = chars;
+ this.type = type;
+ }
+
+ /**
+ * Returns string representation for the token
+ */
+ public String toString() {
+ return "ELToken(" + start + ", " + length + ", " + type +
") [" + (chars == null ? "<Empty>" : chars.toString()) +
"]"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
//$NON-NLS-6$
+ }
+
+ /*
+ * @see org.eclipse.jface.text.rules.IToken#getData()
+ */
+ public Object getData() {
+ return (chars == null ? null : chars.subSequence(start, start+length).toString());
+ }
+
+ /*
+ * @see org.eclipse.jface.text.rules.IToken#isEOF()
+ */
+ public boolean isEOF() {
+ return (start == -1 && length == -1 && chars == null);
+ }
+
+ /*
+ * @see org.eclipse.jface.text.rules.IToken#isOther()
+ */
+ public boolean isOther() {
+ return false;
+ }
+
+ /*
+ * @see org.eclipse.jface.text.rules.IToken#isUndefined()
+ */
+ public boolean isUndefined() {
+ return false;
+ }
+
+ /*
+ * @see org.eclipse.jface.text.rules.IToken#isWhitespace()
+ */
+ public boolean isWhitespace() {
+ return false;
+ }
+
+ /**
+ * Returns the token type
+ */
+ public int getType(){
+ return type;
+ }
+
+ /**
+ * Returns the token text
+ */
+ public String getText() {
+ return chars.toString();
+ }
+
+ /**
+ * @return offset of token
+ */
+ public int getStart() {
+ return start;
+ }
+
+ /**
+ * @return length of token
+ */
+ public int getLength() {
+ return length;
+ }
+}
\ No newline at end of file
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-10-11
16:53:32 UTC (rev 4122)
+++
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/el/SeamELCompletionEngine.java 2007-10-11
17:41:32 UTC (rev 4123)
@@ -405,337 +405,6 @@
}
/**
- * EL string parser.
- * Creates list of tokens for the name, method and separator parts
- *
- * @author Jeremy
- */
- public static class SeamELOperandTokenizer {
- static final int STATE_INITIAL = 0;
- static final int STATE_VAR = 1;
- static final int STATE_METHOD = 2;
- static final int STATE_SEPARATOR = 3;
-
- String documentContent;
- List<ELOperandToken> fTokens;
- int index;
-
- /**
- * Constructs SeamELTokenizer object.
- * Parse expression from offset to first operator or space.
- * Tokenizer parses document from offset to beginning.
- * For example: documentContetn is '<tag
attr="#{var1.pr!=var2.pr}"/>'
- * offset = 29 ("...var2.pr|}")
- * then tokens are {"pr",".","var2"}
- * @param documentContent
- * @param offset
- */
- public SeamELOperandTokenizer(String documentContent, int offset) {
- this.documentContent = documentContent;
- index = (documentContent == null || documentContent.length() < offset? -1 :
offset);
- fTokens = new ArrayList<ELOperandToken>();
- parseBackward();
- }
-
- /**
- * Constructs SeamELTokenizer object.
- * @param document
- * @param offset
- */
- public SeamELOperandTokenizer(IDocument document, int offset) {
- this(document.get(), offset);
- }
-
- /**
- * Returns list of tokens for the expression parsed
- *
- * @return
- */
- public List<ELOperandToken> getTokens() {
- return fTokens;
- }
-
- /*
- * Performs backward parsing of document text for expression
- */
- private void parseBackward() {
- ELOperandToken token;
- fState = STATE_INITIAL;
- while ((token = getNextToken()) != ELOperandToken.EOF) {
-
- if (token.type == ELOperandToken.EL_NAME_TOKEN ||
- token.type == ELOperandToken.EL_METHOD_TOKEN ||
- token.type == ELOperandToken.EL_SEPARATOR_TOKEN) {
-
- fTokens.add(0, token);
- }
- }
- }
-
- int fState;
- int fEndOfToken;
-
- /*
- * Calculates and returns next token for expression
- *
- * @return
- */
- private ELOperandToken getNextToken() {
- switch (fState) {
- case STATE_INITIAL: // Just started
- {
- int ch = readCharBackward();
- if (ch == -1) {
- return ELOperandToken.EOF;
- }
- if (Character.isJavaIdentifierPart((char)ch)) {
- releaseChar();
- return readVarToken();
- }
- if (ch == '.') {
- releaseChar();
- return readSeparatorToken();
- }
- if (ch == ')') {
- releaseChar();
- return readMethodToken();
- }
- releaseChar();
- return ELOperandToken.EOF;
- }
- case STATE_VAR: // Variable name is read - expecting a separator
- {
- int ch = readCharBackward();
- if (ch == -1) {
- return ELOperandToken.EOF;
- }
- if (ch == '.') {
- releaseChar();
- return readSeparatorToken();
- }
- releaseChar();
- return ELOperandToken.EOF;
- }
- case STATE_METHOD: // Method name and parameters are read - expecting a separator
- {
- int ch = readCharBackward();
- if (ch == -1) {
- return ELOperandToken.EOF;
- }
- if (ch == '.') {
- releaseChar();
- return readSeparatorToken();
- }
- releaseChar();
- return ELOperandToken.EOF;
- }
- case STATE_SEPARATOR: // Separator is read - expecting a var or method
- {
- int ch = readCharBackward();
- if (ch == -1) {
- return ELOperandToken.EOF;
- }
- if (Character.isJavaIdentifierPart((char)ch)) {
- releaseChar();
- return readVarToken();
- }
- if (ch == ')') {
- releaseChar();
- return readMethodToken();
- }
- releaseChar();
- return ELOperandToken.EOF;
- }
- }
- return ELOperandToken.EOF;
- }
-
- /* Reads and returns the method token from the expression
- *
- * @return
- */
- ELOperandToken readMethodToken() {
- fState = STATE_METHOD;
- int endOfToken = index;
-
- // read the method parameters
- if (!skipMethodParameters())
- return ELOperandToken.EOF;
-
- // skip spaces between the method's name and it's parameters
- if (!skipSpaceChars())
- return ELOperandToken.EOF;
- // read the method name
- if (!skipMethodName())
- return ELOperandToken.EOF;
-
- return (endOfToken - index > 0 ? new ELOperandToken(index, endOfToken - index,
getCharSequence(index, endOfToken - index), ELOperandToken.EL_METHOD_TOKEN) :
ELOperandToken.EOF);
- }
-
- /*
- * Returns the CharSequence object
- *
- * @param start
- * @param length
- * @return
- */
- private CharSequence getCharSequence(int start, int length) {
- String text = ""; //$NON-NLS-1$
- try {
- text = documentContent.substring(start, start + length);
- } catch (StringIndexOutOfBoundsException e) {
- SeamCorePlugin.getDefault().logError(e);
- text = ""; // For sure //$NON-NLS-1$
- }
- return text.subSequence(0, text.length());
- }
-
-
- /*
- * Skips the space characters in the document
- */
- boolean skipSpaceChars() {
- int ch;
- while ((ch = readCharBackward()) != -1) {
- if (!Character.isSpaceChar(ch)) {
- releaseChar();
- break;
- }
- }
- return true;
- }
-
- /*
- * Skips the method name characters in the document
- *
- * @return boolean true if at least 1 character had been read
- */
- boolean skipMethodName() {
- int endOfToken = index;
- int ch;
- while((ch = readCharBackward()) != -1) {
- if (!Character.isJavaIdentifierPart(ch)) {
- releaseChar();
- return (endOfToken - index > 0);
- }
- }
- return false;
- }
-
- /*
- * Skips the method parameters characters in the document
- *
- * @return boolean true if complete parameters set had been read
- */
- boolean skipMethodParameters() {
- int ch = readCharBackward();
- if (ch != ')')
- return false;
- int pCount = 1;
- while (pCount > 0) {
- ch = readCharBackward();
- if (ch == -1)
- return false;
-
- if (ch == '"' || ch == '\'') {
- skipQuotedChars((char)ch);
- continue;
- }
- if (ch == ')') {
- pCount++;
- continue;
- }
- if (ch == '(') {
- pCount--;
- continue;
- }
- }
- return true;
- }
-
- /*
- * Skips the quoted characters
- *
- */
- void skipQuotedChars(char pair) {
- int ch = readCharBackward();
-
- while (ch != -1) {
- if (ch == pair) {
- ch = readCharBackward();
- if (ch == '\\') {
- int backSlashCount = 0;
- while (ch == '\\') {
- backSlashCount++;
- ch = readCharBackward();
- }
- releaseChar(); // Return the last non-slash char to the buffer
- if ((backSlashCount/2)*2 == backSlashCount) {
- return;
- }
- }
- }
- ch = readCharBackward();
- }
- }
-
- /* Reads and returns the separator token from the expression
- *
- * @return
- */
- ELOperandToken readSeparatorToken() {
- fState = STATE_SEPARATOR;
- int ch = readCharBackward();
-
- return (ch == '.' ? new ELOperandToken(index, 1, getCharSequence(index, 1),
ELOperandToken.EL_SEPARATOR_TOKEN) :
- ELOperandToken.EOF);
- }
-
- /* Reads and returns the variable token from the expression
- *
- * @return
- */
- ELOperandToken readVarToken() {
- fState = STATE_VAR;
- int endOfToken = index;
- int ch;
- while((ch = readCharBackward()) != -1) {
- if (!Character.isJavaIdentifierPart(ch)) {
- releaseChar();
- return (endOfToken - index > 0 ? new ELOperandToken(index, endOfToken - index,
getCharSequence(index, endOfToken - index), ELOperandToken.EL_NAME_TOKEN) :
ELOperandToken.EOF);
- }
- }
- releaseChar();
- return (endOfToken - index > 0 ? new ELOperandToken(index, endOfToken - index,
getCharSequence(index, endOfToken - index), ELOperandToken.EL_NAME_TOKEN) :
ELOperandToken.EOF);
- }
-
- /* Reads the next character in the document
- *
- * @return
- */
- int readCharBackward() {
- if (--index < 0 ||
- documentContent == null ||
- documentContent.length() <= index)
- return -1;
-
- try {
- return documentContent.charAt(index);
- } catch (StringIndexOutOfBoundsException e) {
- return -1;
- }
- }
-
- /*
- * returns the character to the document
- */
- void releaseChar() {
- if (index < documentContent.length())
- index++;
- }
- }
-
- /**
* Calculates the EX expression operand string
*
* @param viewer
@@ -975,92 +644,4 @@
return res;
}
-}
-
-/**
- * Token for the EX expression operand parts
- *
- * @author Jeremy
- */
-class ELOperandToken implements IToken {
- static final ELOperandToken EOF = new ELOperandToken(-1, -1, null, -1);
- static final int EL_NAME_TOKEN = 1;
- static final int EL_METHOD_TOKEN = 2;
- static final int EL_SEPARATOR_TOKEN = 3;
-
- int start;
- int length;
- CharSequence chars;
- int type;
-
- /**
- * Constructs the ELToken object
- *
- * @param start
- * @param length
- * @param chars
- * @param type
- */
- public ELOperandToken(int start, int length, CharSequence chars, int type) {
- this.start = start;
- this.length = length;
- this.chars = chars;
- this.type = type;
- }
-
- /**
- * Returns string representation for the token
- */
- public String toString() {
- return "ELToken(" + start + ", " + length + ", " + type +
") [" + (chars == null ? "<Empty>" : chars.toString()) +
"]"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
//$NON-NLS-6$
- }
-
- /*
- * @see org.eclipse.jface.text.rules.IToken#getData()
- */
- public Object getData() {
- return (chars == null ? null : chars.subSequence(start, start+length).toString());
- }
-
- /*
- * @see org.eclipse.jface.text.rules.IToken#isEOF()
- */
- public boolean isEOF() {
- return (start == -1 && length == -1 && chars == null);
- }
-
- /*
- * @see org.eclipse.jface.text.rules.IToken#isOther()
- */
- public boolean isOther() {
- return false;
- }
-
- /*
- * @see org.eclipse.jface.text.rules.IToken#isUndefined()
- */
- public boolean isUndefined() {
- return false;
- }
-
- /*
- * @see org.eclipse.jface.text.rules.IToken#isWhitespace()
- */
- public boolean isWhitespace() {
- return false;
- }
-
- /*
- * Returns the token type
- */
- public int getType(){
- return type;
- }
-
- /*
- * Returns the token text
- */
- public String getText() {
- return chars.toString();
- }
}
\ No newline at end of file
Added:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/el/SeamELOperandTokenizer.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/el/SeamELOperandTokenizer.java
(rev 0)
+++
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/el/SeamELOperandTokenizer.java 2007-10-11
17:41:32 UTC (rev 4123)
@@ -0,0 +1,348 @@
+ /*******************************************************************************
+ * Copyright (c) 2007 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.seam.internal.core.el;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.jface.text.IDocument;
+import org.jboss.tools.seam.core.SeamCorePlugin;
+
+/**
+ * EL string parser.
+ * Creates list of tokens for the name, method and separator parts
+ *
+ * @author Jeremy
+ */
+public class SeamELOperandTokenizer {
+ static final int STATE_INITIAL = 0;
+ static final int STATE_VAR = 1;
+ static final int STATE_METHOD = 2;
+ static final int STATE_SEPARATOR = 3;
+
+ String documentContent;
+ List<ELOperandToken> fTokens;
+ int index;
+
+ /**
+ * Constructs SeamELTokenizer object.
+ * Parse expression from offset to first operator or space.
+ * Tokenizer parses document from offset to beginning.
+ * For example: documentContetn is '<tag
attr="#{var1.pr!=var2.pr}"/>'
+ * offset = 29 ("...var2.pr|}")
+ * then tokens are {"pr",".","var2"}
+ * @param documentContent
+ * @param offset
+ */
+ public SeamELOperandTokenizer(String documentContent, int offset) {
+ this.documentContent = documentContent;
+ index = (documentContent == null || documentContent.length() < offset? -1 :
offset);
+ fTokens = new ArrayList<ELOperandToken>();
+ parseBackward();
+ }
+
+ /**
+ * Constructs SeamELTokenizer object.
+ * @param document
+ * @param offset
+ */
+ public SeamELOperandTokenizer(IDocument document, int offset) {
+ this(document.get(), offset);
+ }
+
+ /**
+ * Returns list of tokens for the expression parsed
+ *
+ * @return
+ */
+ public List<ELOperandToken> getTokens() {
+ return fTokens;
+ }
+
+ /*
+ * Performs backward parsing of document text for expression
+ */
+ private void parseBackward() {
+ ELOperandToken token;
+ fState = STATE_INITIAL;
+ while ((token = getNextToken()) != ELOperandToken.EOF) {
+
+ if (token.type == ELOperandToken.EL_NAME_TOKEN ||
+ token.type == ELOperandToken.EL_METHOD_TOKEN ||
+ token.type == ELOperandToken.EL_SEPARATOR_TOKEN) {
+
+ fTokens.add(0, token);
+ }
+ }
+ }
+
+ int fState;
+ int fEndOfToken;
+
+ /*
+ * Calculates and returns next token for expression
+ *
+ * @return
+ */
+ private ELOperandToken getNextToken() {
+ switch (fState) {
+ case STATE_INITIAL: // Just started
+ {
+ int ch = readCharBackward();
+ if (ch == -1) {
+ return ELOperandToken.EOF;
+ }
+ if (Character.isJavaIdentifierPart((char)ch)) {
+ releaseChar();
+ return readVarToken();
+ }
+ if (ch == '.') {
+ releaseChar();
+ return readSeparatorToken();
+ }
+ if (ch == ')') {
+ releaseChar();
+ return readMethodToken();
+ }
+ releaseChar();
+ return ELOperandToken.EOF;
+ }
+ case STATE_VAR: // Variable name is read - expecting a separator
+ {
+ int ch = readCharBackward();
+ if (ch == -1) {
+ return ELOperandToken.EOF;
+ }
+ if (ch == '.') {
+ releaseChar();
+ return readSeparatorToken();
+ }
+ releaseChar();
+ return ELOperandToken.EOF;
+ }
+ case STATE_METHOD: // Method name and parameters are read - expecting a separator
+ {
+ int ch = readCharBackward();
+ if (ch == -1) {
+ return ELOperandToken.EOF;
+ }
+ if (ch == '.') {
+ releaseChar();
+ return readSeparatorToken();
+ }
+ releaseChar();
+ return ELOperandToken.EOF;
+ }
+ case STATE_SEPARATOR: // Separator is read - expecting a var or method
+ {
+ int ch = readCharBackward();
+ if (ch == -1) {
+ return ELOperandToken.EOF;
+ }
+ if (Character.isJavaIdentifierPart((char)ch)) {
+ releaseChar();
+ return readVarToken();
+ }
+ if (ch == ')') {
+ releaseChar();
+ return readMethodToken();
+ }
+ releaseChar();
+ return ELOperandToken.EOF;
+ }
+ }
+ return ELOperandToken.EOF;
+ }
+
+ /* Reads and returns the method token from the expression
+ *
+ * @return
+ */
+ ELOperandToken readMethodToken() {
+ fState = STATE_METHOD;
+ int endOfToken = index;
+
+ // read the method parameters
+ if (!skipMethodParameters())
+ return ELOperandToken.EOF;
+
+ // skip spaces between the method's name and it's parameters
+ if (!skipSpaceChars())
+ return ELOperandToken.EOF;
+ // read the method name
+ if (!skipMethodName())
+ return ELOperandToken.EOF;
+
+ return (endOfToken - index > 0 ? new ELOperandToken(index, endOfToken - index,
getCharSequence(index, endOfToken - index), ELOperandToken.EL_METHOD_TOKEN) :
ELOperandToken.EOF);
+ }
+
+ /*
+ * Returns the CharSequence object
+ *
+ * @param start
+ * @param length
+ * @return
+ */
+ private CharSequence getCharSequence(int start, int length) {
+ String text = ""; //$NON-NLS-1$
+ try {
+ text = documentContent.substring(start, start + length);
+ } catch (StringIndexOutOfBoundsException e) {
+ SeamCorePlugin.getDefault().logError(e);
+ text = ""; // For sure //$NON-NLS-1$
+ }
+ return text.subSequence(0, text.length());
+ }
+
+
+ /*
+ * Skips the space characters in the document
+ */
+ boolean skipSpaceChars() {
+ int ch;
+ while ((ch = readCharBackward()) != -1) {
+ if (!Character.isSpaceChar(ch)) {
+ releaseChar();
+ break;
+ }
+ }
+ return true;
+ }
+
+ /*
+ * Skips the method name characters in the document
+ *
+ * @return boolean true if at least 1 character had been read
+ */
+ boolean skipMethodName() {
+ int endOfToken = index;
+ int ch;
+ while((ch = readCharBackward()) != -1) {
+ if (!Character.isJavaIdentifierPart(ch)) {
+ releaseChar();
+ return (endOfToken - index > 0);
+ }
+ }
+ return false;
+ }
+
+ /*
+ * Skips the method parameters characters in the document
+ *
+ * @return boolean true if complete parameters set had been read
+ */
+ boolean skipMethodParameters() {
+ int ch = readCharBackward();
+ if (ch != ')')
+ return false;
+ int pCount = 1;
+ while (pCount > 0) {
+ ch = readCharBackward();
+ if (ch == -1)
+ return false;
+
+ if (ch == '"' || ch == '\'') {
+ skipQuotedChars((char)ch);
+ continue;
+ }
+ if (ch == ')') {
+ pCount++;
+ continue;
+ }
+ if (ch == '(') {
+ pCount--;
+ continue;
+ }
+ }
+ return true;
+ }
+
+ /*
+ * Skips the quoted characters
+ *
+ */
+ void skipQuotedChars(char pair) {
+ int ch = readCharBackward();
+
+ while (ch != -1) {
+ if (ch == pair) {
+ ch = readCharBackward();
+ if (ch == '\\') {
+ int backSlashCount = 0;
+ while (ch == '\\') {
+ backSlashCount++;
+ ch = readCharBackward();
+ }
+ releaseChar(); // Return the last non-slash char to the buffer
+ if ((backSlashCount/2)*2 == backSlashCount) {
+ return;
+ }
+ }
+ }
+ ch = readCharBackward();
+ }
+ }
+
+ /* Reads and returns the separator token from the expression
+ *
+ * @return
+ */
+ ELOperandToken readSeparatorToken() {
+ fState = STATE_SEPARATOR;
+ int ch = readCharBackward();
+
+ return (ch == '.' ? new ELOperandToken(index, 1, getCharSequence(index, 1),
ELOperandToken.EL_SEPARATOR_TOKEN) :
+ ELOperandToken.EOF);
+ }
+
+ /* Reads and returns the variable token from the expression
+ *
+ * @return
+ */
+ ELOperandToken readVarToken() {
+ fState = STATE_VAR;
+ int endOfToken = index;
+ int ch;
+ while((ch = readCharBackward()) != -1) {
+ if (!Character.isJavaIdentifierPart(ch)) {
+ releaseChar();
+ return (endOfToken - index > 0 ? new ELOperandToken(index, endOfToken - index,
getCharSequence(index, endOfToken - index), ELOperandToken.EL_NAME_TOKEN) :
ELOperandToken.EOF);
+ }
+ }
+ releaseChar();
+ return (endOfToken - index > 0 ? new ELOperandToken(index, endOfToken - index,
getCharSequence(index, endOfToken - index), ELOperandToken.EL_NAME_TOKEN) :
ELOperandToken.EOF);
+ }
+
+ /* Reads the next character in the document
+ *
+ * @return
+ */
+ int readCharBackward() {
+ if (--index < 0 ||
+ documentContent == null ||
+ documentContent.length() <= index)
+ return -1;
+
+ try {
+ return documentContent.charAt(index);
+ } catch (StringIndexOutOfBoundsException e) {
+ return -1;
+ }
+ }
+
+ /*
+ * returns the character to the document
+ */
+ void releaseChar() {
+ if (index < documentContent.length())
+ index++;
+ }
+}
\ 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-10-11
16:53:32 UTC (rev 4122)
+++
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/validation/SeamELValidator.java 2007-10-11
17:41:32 UTC (rev 4123)
@@ -13,7 +13,6 @@
import java.io.IOException;
import java.util.HashMap;
import java.util.HashSet;
-import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -49,8 +48,10 @@
import org.jboss.tools.seam.core.SeamCoreMessages;
import org.jboss.tools.seam.core.SeamCorePlugin;
import org.jboss.tools.seam.core.SeamPreferences;
+import org.jboss.tools.seam.internal.core.el.ELOperandToken;
import org.jboss.tools.seam.internal.core.el.ELToken;
import org.jboss.tools.seam.internal.core.el.SeamELCompletionEngine;
+import org.jboss.tools.seam.internal.core.el.SeamELOperandTokenizer;
import org.jboss.tools.seam.internal.core.el.SeamELTokenizer;
/**
@@ -256,20 +257,23 @@
private void validateElOperand(IFile file, ELToken operandToken, int documnetOffset) {
String operand = operandToken.getText();
+ String varName = operand;
+ int offsetOfVarName = documnetOffset + operandToken.getStart();
+ int lengthOfVarName = varName.length();
try {
int offset = operand.length();
if (!operand.endsWith(".")) { //$NON-NLS-1$
String prefix = SeamELCompletionEngine.getPrefix(operand, offset);
if(prefix!=null) {
- int possition = operand.indexOf(prefix);
- if (possition == -1) {
- possition = 0;
+ int position = operand.indexOf(prefix);
+ if (position == -1) {
+ position = 0;
}
Set<ISeamContextVariable> usedVariables = new
HashSet<ISeamContextVariable>();
Map<String, IMethod> unpairedGettersOrSetters = new HashMap<String,
IMethod>();
- List<String> suggestions = engine.getCompletions(project, file, operand,
prefix, possition, true, usedVariables, unpairedGettersOrSetters);
+ List<String> suggestions = engine.getCompletions(project, file, operand,
prefix, position, true, usedVariables, unpairedGettersOrSetters);
if(usedVariables.size()==0 && suggestions.size()==0) {
// Save resources with unknown variables names
@@ -299,6 +303,19 @@
// It's valid EL.
return;
}
+
+ SeamELOperandTokenizer tokenizer = new SeamELOperandTokenizer(operand, position +
prefix.length());
+ List<ELOperandToken> tokens = tokenizer.getTokens();
+ for (ELOperandToken token : tokens) {
+ if((token.getType()==ELOperandToken.EL_NAME_TOKEN) ||
(token.getType()==ELOperandToken.EL_METHOD_TOKEN)) {
+ if(!isResolvedVar(token.getText(), usedVariables)) {
+ varName = token.getText();
+ offsetOfVarName = documnetOffset + operandToken.getStart() + token.getStart();
+ lengthOfVarName = varName.length();
+ break;
+ }
+ }
+ }
}
}
} catch (BadLocationException e) {
@@ -307,9 +324,18 @@
SeamCorePlugin.getDefault().logError(SeamCoreMessages.getString("SEAM_EL_VALIDATOR_ERROR_VALIDATING_SEAM_EL"),
e); //$NON-NLS-1$
}
// Mark invalid EL
- addError(INVALID_EXPRESSION_MESSAGE_ID, SeamPreferences.INVALID_EXPRESSION, new
String[]{operand}, operand.length(), documnetOffset + operandToken.getStart(), file);
+ addError(INVALID_EXPRESSION_MESSAGE_ID, SeamPreferences.INVALID_EXPRESSION, new
String[]{varName}, lengthOfVarName, offsetOfVarName, file);
}
+ private boolean isResolvedVar(String varName, Set<ISeamContextVariable>
usedVariables) {
+ for (ISeamContextVariable seamContextVariable : usedVariables) {
+ if(varName.equals(seamContextVariable.getName())) {
+ return true;
+ }
+ }
+ return false;
+ }
+
public static class EL {
private String value;
private int length;