Author: scabanovich
Date: 2008-09-29 11:29:27 -0400 (Mon, 29 Sep 2008)
New Revision: 10540
Removed:
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
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/el/SeamELOperandTokenizerForward.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/el/SeamPromptingProvider.java
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/validation/SeamELValidator.java
Log:
JBIDE-1497.
Refactoring for usage of ELOperandToken
Deleted:
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 2008-09-29
15:29:16 UTC (rev 10539)
+++
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/el/ELOperandToken.java 2008-09-29
15:29:27 UTC (rev 10540)
@@ -1,123 +0,0 @@
- /*******************************************************************************
- * 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_VARIABLE_NAME_TOKEN = 1;
- public static final int EL_PROPERTY_NAME_TOKEN = 2;
- public static final int EL_METHOD_TOKEN = 3;
- public static final int EL_SEPARATOR_TOKEN = 4;
-
- 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 type
- */
- public boolean isNameToken(){
- return EL_VARIABLE_NAME_TOKEN == type || EL_PROPERTY_NAME_TOKEN == 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 2008-09-29
15:29:16 UTC (rev 10539)
+++
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/el/SeamELCompletionEngine.java 2008-09-29
15:29:27 UTC (rev 10540)
@@ -35,6 +35,7 @@
import org.jboss.tools.common.el.core.model.ELModel;
import org.jboss.tools.common.el.core.model.ELObjectType;
import org.jboss.tools.common.el.core.model.ELPropertyInvocation;
+import org.jboss.tools.common.el.core.model.ELUtil;
import org.jboss.tools.common.el.core.parser.ELParser;
import org.jboss.tools.common.el.core.parser.ELParserFactory;
import org.jboss.tools.common.el.core.parser.LexicalToken;
@@ -68,16 +69,14 @@
* @param prefix the prefix to search for
* @param position Offset of the prefix
* @param vars - 'var' attributes which can be used in this EL
+ * @param start start of relevant region in document
+ * @param end end of relevant region in document
* @return the list of all possible suggestions
* @throws BadLocationException if accessing the current document fails
*/
public List<String> getCompletions(ISeamProject project, IFile file, IDocument
document, CharSequence prefix,
- int position, List<Var> vars) throws BadLocationException,
StringIndexOutOfBoundsException {
- String documentContent = null;
- if(document!=null) {
- documentContent = document.get();
- }
- return getCompletions(project, file, documentContent, prefix, position, false, vars);
+ int position, List<Var> vars, int start, int end) throws BadLocationException,
StringIndexOutOfBoundsException {
+ return getCompletions(project, file, document, prefix, position, false, vars, start,
end);
}
/**
@@ -89,6 +88,8 @@
* @param position Offset of the prefix
* @param vars - 'var' attributes which can be used in this EL. Can be null.
* @param returnEqualedVariablesOnly 'false' if we get proposals for mask
+ * @param start start of relevant region in document
+ * @param end end of relevant region in document
* for example:
* we have 'variableName.variableProperty',
'variableName.variableProperty1', 'variableName.variableProperty2'
* prefix is 'variableName.variableProperty'
@@ -102,12 +103,11 @@
* @throws BadLocationException if accessing the current document fails
* @throws StringIndexOutOfBoundsException
*/
- public List<String> getCompletions(ISeamProject project, IFile file, String
documentContent, CharSequence prefix,
- int position, boolean returnEqualedVariablesOnly, List<Var> vars) throws
BadLocationException, StringIndexOutOfBoundsException {
+ public List<String> getCompletions(ISeamProject project, IFile file, IDocument
document, CharSequence prefix,
+ int position, boolean returnEqualedVariablesOnly, List<Var> vars, int start, int
end) throws BadLocationException, StringIndexOutOfBoundsException {
List<String> completions = new ArrayList<String>();
- //TODO change algorithm for finding operand.
- String prefix2 = SeamELCompletionEngine.getPrefix(documentContent, position +
prefix.length());
+ String prefix2 = getPrefix(document, position + prefix.length(), start, end);
SeamELOperandResolveStatus status = resolveSeamELOperand(project, file,
parseOperand(prefix2), returnEqualedVariablesOnly, vars, new ElVarSearcher(project, file,
this));
if (status.isOK()) {
@@ -540,7 +540,8 @@
status.setLastResolvedToken(expr);
}
}
-
+
+/**
private String computeVariableName(List<ELOperandToken> tokens){
if (tokens == null)
tokens = new ArrayList<ELOperandToken>();
@@ -555,14 +556,9 @@
}
return sb.toString();
}
+*/
- /*
- * Compares to tokenized expressions.
- *
- * @param first
- * @param second
- * @return boolean true if two expressions are equal
- */
+/**
private boolean areEqualExpressions(List<ELOperandToken>first,
List<ELOperandToken>second) {
if (first == null || second == null)
return (first == second);
@@ -576,6 +572,7 @@
}
return true;
}
+*/
/* Returns scope for the resource
*
@@ -599,15 +596,7 @@
return null;
}
- /*
- * Tries to resolve variables by part of expression
- *
- * @param project
- * @param scope
- * @param part
- * @param tokens
- * @return
- */
+/**
private List<ISeamContextVariable> resolveVariables(ISeamProject project,
ScopeType scope, List<ELOperandToken>part, List<ELOperandToken> tokens,
boolean onlyEqualNames) {
List<ISeamContextVariable>resolvedVars = new
ArrayList<ISeamContextVariable>();
String varName = computeVariableName(part);
@@ -631,6 +620,7 @@
}
return new ArrayList<ISeamContextVariable>();
}
+*/
private List<ISeamContextVariable> resolveVariables(ISeamProject project,
ScopeType scope, ELInvocationExpression expr, boolean isFinal, boolean onlyEqualNames) {
List<ISeamContextVariable>resolvedVars = new
ArrayList<ISeamContextVariable>();
@@ -656,12 +646,7 @@
return new ArrayList<ISeamContextVariable>();
}
- /**
- * Creates and returns list of possible variable name combinations from expression
starting from the longest name
- *
- * @param prefix
- * @return
- */
+/**
public static List<List<ELOperandToken>>
getPossibleVarsFromPrefix(List<ELOperandToken>prefix) {
ArrayList<List<ELOperandToken>> result = new
ArrayList<List<ELOperandToken>>();
for (int i = 0; prefix != null && i < prefix.size(); i++) {
@@ -676,6 +661,7 @@
}
return result;
}
+*/
/**
* Removes duplicates of completion strings
@@ -706,14 +692,16 @@
*
* @param viewer
* @param offset
+ * @param start start of relevant region in document
+ * @param end end of relevant region in document
* @return
* @throws BadLocationException
*/
- public static String getPrefix(ITextViewer viewer, int offset) throws
StringIndexOutOfBoundsException {
+ public static String getPrefix(ITextViewer viewer, int offset, int start, int end)
throws StringIndexOutOfBoundsException {
IDocument doc= viewer.getDocument();
if (doc == null || offset > doc.getLength())
return null;
- return getPrefix(doc.get(), offset);
+ return getPrefix(doc, offset, start, end);
}
/**
@@ -721,20 +709,18 @@
*
* @param viewer
* @param offset
+ * @param start start of relevant region in document
+ * @param end end of relevant region in document
* @return
* @throws StringIndexOutOfBoundsException
*/
- public static String getPrefix(String documentContent, int offset) throws
StringIndexOutOfBoundsException {
- if (documentContent == null || offset > documentContent.length())
+ public static String getPrefix(IDocument document, int offset, int start, int end)
throws StringIndexOutOfBoundsException {
+ if (document == null || document.get() == null || offset > document.get().length())
return null;
-
- SeamELOperandTokenizer tokenizer = new SeamELOperandTokenizer(documentContent,
offset);
- List<ELOperandToken> tokens = tokenizer.getTokens();
-
- if (tokens == null || tokens.size() == 0)
+ ELInvocationExpression expr = findExpressionAtOffset(document, offset, start, end);
+ if (expr == null)
return null;
-
- return documentContent.substring(tokens.get(0).start, offset);
+ return document.get().substring(expr.getStartPosition(), offset);
}
/**
@@ -744,35 +730,35 @@
* @return
* @throws StringIndexOutOfBoundsException
*/
- public String getJavaElementExpression(String documentContent, int offset, IRegion
region) throws StringIndexOutOfBoundsException {
- if (documentContent == null || offset > documentContent.length())
+ public String getJavaElementExpression(IDocument document, int offset, IRegion region,
int start, int end) throws StringIndexOutOfBoundsException {
+ if (document == null || document.get() == null || offset > document.get().length())
return null;
- SeamELOperandTokenizer tokenizer = new SeamELOperandTokenizer(documentContent,
region.getOffset() + region.getLength());
- List<ELOperandToken> tokens = tokenizer.getTokens();
+ ELInvocationExpression expr = findExpressionAtOffset(
+ document,
+ region.getOffset() + region.getLength(),
+ start, end);
- if (tokens == null || tokens.size() == 0)
- return null;
+ if (expr == null) return null;
- List<List<ELOperandToken>> vars = getPossibleVarsFromPrefix(tokens);
- if (vars == null)
- return null;
+ ELInvocationExpression left = expr;
+ while(left != null && left.getLeft() != null) left = left.getLeft();
- String prefixPart = documentContent.substring(tokens.get(0).start, offset);
+ String prefixPart = document.get().substring(expr.getStartPosition(), offset);
- // Search from the shortest variation to the longest one
- for (int i = vars.size() - 1; i >= 0; i--) {
- List<ELOperandToken>var = vars.get(i);
- String varText = computeVariableName(var);
+ while(left != null) {
+ String varText = left.getText();
if (varText != null && varText.startsWith(prefixPart)) {
return varText;
}
+ if(left == expr) break;
+ left = (ELInvocationExpression)left.getParent();
}
return null;
}
/**
- * Create the array of suggestions from {@link ELOperandToken} list.
+ * Create the array of suggestions from expression.
* @param project Seam project
* @param file File
* @param document
@@ -787,14 +773,7 @@
return getJavaElementsForELOperandTokens(project, file, (ELInvocationExpression)expr);
}
- /**
- * Create the array of suggestions.
- * @param project Seam project
- * @param file File
- * @param document
- * @param prefix the prefix to search for
- * @param position Offset of the prefix
- */
+/**
public List<IJavaElement> getJavaElementsForELOperandTokens(
ISeamProject project, IFile file,
List<ELOperandToken> tokens) throws BadLocationException,
StringIndexOutOfBoundsException {
@@ -940,7 +919,7 @@
}
return res;
}
-
+*/
/**
* Create the array of suggestions.
@@ -960,7 +939,6 @@
return res;
}
- List<ELOperandToken> resolvedExpressionPart = new
ArrayList<ELOperandToken>();
List<ISeamContextVariable> resolvedVariables = new
ArrayList<ISeamContextVariable>();
ScopeType scope = getScope(project, file);
ELInvocationExpression left = expr;
@@ -974,6 +952,7 @@
resolvedVariables = resolvedVars;
break;
}
+ int y = 0;
left = (ELInvocationExpression)left.getLeft();
}
@@ -991,7 +970,6 @@
}
// First segment is found - proceed with next tokens
- int startTokenIndex = (resolvedExpressionPart == null ? 0 :
resolvedExpressionPart.size());
List<TypeInfoCollector.MemberInfo> members = new
ArrayList<TypeInfoCollector.MemberInfo>();
for (ISeamContextVariable var : resolvedVariables) {
TypeInfoCollector.MemberInfo member =
SeamExpressionResolver.getMemberInfoByVariable(var, true);
@@ -1110,12 +1088,52 @@
}
/**
- * Returns list of Seam ELOperandToken which are placed under the cursor position
- *
- * @param document
- * @param offset
- * @return
- */
+ *
+ * @param document
+ * @param offset
+ * @param start start of relevant region in document
+ * @param end end of relevant region in document
+ * @return
+ */
+ public static ELInvocationExpression findExpressionAtOffset(IDocument document, int
offset, int start, int end) {
+ String content = document.get();
+
+ //TODO this naive calculations should be removed;
+ // this method should be called with reasonable start and end.
+ if(start <= 0) start = guessStart(content, offset);
+ if(end >= content.length()) end = guessEnd(content, offset);
+
+ ELParser parser = ELParserFactory.createJbossParser();
+ ELModel model = parser.parse(content, start, end - start);
+
+ return ELUtil.findExpression(model, offset);
+ }
+
+ static int guessStart(String content, int offset) {
+ if(offset > content.length()) offset = content.length();
+ if(offset < 2) return 0;
+ int s = offset - 2;
+
+ while(s >= 0) {
+ if(content.charAt(s + 1) == '{') {
+ char ch = content.charAt(s);
+ if(ch == '#' || ch == '$') return s;
+ }
+ s--;
+ }
+ return 0;
+ }
+
+ static int guessEnd(String content, int offset) {
+ if(offset >= content.length()) return content.length();
+ while(offset < content.length()) {
+ if(content.charAt(offset) == '}') return offset;
+ offset++;
+ }
+ return content.length();
+ }
+
+/**
public static List<ELOperandToken> findTokensAtOffset(IDocument document, int
offset) {
List<ELOperandToken> result = new ArrayList<ELOperandToken>();
@@ -1150,11 +1168,9 @@
return result;
}
+*/
- /*
- * Scans the document from the offset to the beginning to find start of Seam EL operand
- * Returns the start position of first Seam EL operand token
- */
+/**
private static int getELStart(IDocument document, int offset) {
SeamELOperandTokenizer tokenizer = new SeamELOperandTokenizer(document, offset);
List<ELOperandToken> tokens = tokenizer.getTokens();
@@ -1165,5 +1181,6 @@
ELOperandToken firstToken = tokens.get(0);
return firstToken.getStart();
}
+*/
}
Deleted:
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 2008-09-29
15:29:16 UTC (rev 10539)
+++
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/el/SeamELOperandTokenizer.java 2008-09-29
15:29:27 UTC (rev 10540)
@@ -1,360 +0,0 @@
- /*******************************************************************************
- * 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 {
- protected static final int STATE_INITIAL = 0;
- protected static final int STATE_VAR = 1;
- protected static final int STATE_METHOD = 2;
- protected static final int STATE_SEPARATOR = 3;
-
- protected String documentContent;
- protected List<ELOperandToken> fTokens;
- protected 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_VARIABLE_NAME_TOKEN ||
- token.type == ELOperandToken.EL_PROPERTY_NAME_TOKEN ||
- token.type == ELOperandToken.EL_METHOD_TOKEN ||
- token.type == ELOperandToken.EL_SEPARATOR_TOKEN) {
-
- fTokens.add(0, token);
- }
- }
- // set first token as variable
- for (int i=0; i<fTokens.size(); i++) {
- token = fTokens.get(i);
- if(token.isNameToken()) {
- token.type = ELOperandToken.EL_VARIABLE_NAME_TOKEN;
- break;
- }
- }
- }
-
- 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
- */
- private 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
- */
- protected 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
- */
- private 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
- */
- private 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
- *
- */
- private 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;
- }
- } else {
- releaseChar(); // Return the last non-slash char to the buffer
- return;
- }
- }
- ch = readCharBackward();
- }
- }
-
- /* Reads and returns the separator token from the expression
- *
- * @return
- */
- private 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
- */
- private ELOperandToken readVarToken() {
- fState = STATE_VAR;
- int endOfToken = index;
- int ch;
- int type = ELOperandToken.EL_PROPERTY_NAME_TOKEN;
- while((ch = readCharBackward()) != -1) {
- if (!Character.isJavaIdentifierPart(ch)) {
- releaseChar();
- return (endOfToken - index > 0 ? new ELOperandToken(index, endOfToken - index,
getCharSequence(index, endOfToken - index), type) : ELOperandToken.EOF);
- }
- }
- releaseChar();
- return (endOfToken - index > 0 ? new ELOperandToken(index, endOfToken - index,
getCharSequence(index, endOfToken - index), type) : ELOperandToken.EOF);
- }
-
- /* Reads the next character in the document
- *
- * @return
- */
- private 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
- */
- private void releaseChar() {
- if (index < documentContent.length())
- index++;
- }
-}
\ No newline at end of file
Deleted:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/el/SeamELOperandTokenizerForward.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/el/SeamELOperandTokenizerForward.java 2008-09-29
15:29:16 UTC (rev 10539)
+++
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/el/SeamELOperandTokenizerForward.java 2008-09-29
15:29:27 UTC (rev 10540)
@@ -1,307 +0,0 @@
- /*******************************************************************************
- * 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 org.eclipse.jface.text.IDocument;
-
-/**
- * EL string parser.
- * Creates list of tokens for the name, method and separator parts
- * Forward parsing
- *
- * @author Jeremy
- */
-
-public class SeamELOperandTokenizerForward extends SeamELOperandTokenizer {
-
- /**
- * Constructs SeamELOperandTokenizerForward object.
- * Parse expression from offset to last operator or space.
- * Tokenizer parses document from offset to ending.
- * For example: documentContetn is '<tag
attr="#{var1.pr!=var2.pr}"/>'
- * offset = 29 ("...var2.pr|}")
- * then tokens are {"pr",".","var2"}
- * @param documentContent
- * @param offset
- */
- public SeamELOperandTokenizerForward(String documentContent, int offset) {
- super(documentContent, offset);
- this.documentContent = documentContent;
- index = (documentContent == null || documentContent.length() < offset? -1 :
offset);
- fTokens = new ArrayList<ELOperandToken>();
- parseForward();
- }
-
- /**
- * Constructs SeamELOperandTokenizerForward object.
- * Parse expression from offset to last operator or space.
- * Tokenizer parses document from offset to ending.
- * For example: documentContetn is '<tag
attr="#{var1.pr!=var2.pr}"/>'
- * offset = 29 ("...var2.pr|}")
- * then tokens are {"pr",".","var2"}
- * @param document
- * @param offset
- */
- public SeamELOperandTokenizerForward(IDocument document, int offset) {
- this(document.get(), offset);
- }
-
- /*
- * Performs forward parsing of document text for expression
- */
- private void parseForward() {
- ELOperandToken token;
- fState = STATE_INITIAL;
- while ((token = getNextToken()) != ELOperandToken.EOF) {
- if (token.type == ELOperandToken.EL_VARIABLE_NAME_TOKEN ||
- token.type == ELOperandToken.EL_PROPERTY_NAME_TOKEN ||
- token.type == ELOperandToken.EL_METHOD_TOKEN ||
- token.type == ELOperandToken.EL_SEPARATOR_TOKEN) {
-
- fTokens.add(token);
- }
- }
- // set first token as variable
- for (int i=0; i<fTokens.size(); i++) {
- token = fTokens.get(i);
- if(token.isNameToken()) {
- token.type = ELOperandToken.EL_VARIABLE_NAME_TOKEN;
- break;
- }
- }
- }
-
- /*
- * Calculates and returns next token for expression.
- * Forward parsing
- *
- * @return
- */
- private ELOperandToken getNextToken() {
- switch (fState) {
- case STATE_INITIAL: // Just started
- {
- int ch = readCharForward();
- if (ch == -1) {
- return ELOperandToken.EOF;
- }
- if (Character.isJavaIdentifierPart((char)ch)) {
- releaseChar();
- return readVarOrMethodToken();
- }
- if (ch == '.') {
- releaseChar();
- return readSeparatorToken();
- }
- releaseChar();
- return ELOperandToken.EOF;
- }
- case STATE_VAR: // Variable name is read - expecting a separator
- {
- int ch = readCharForward();
- 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 = readCharForward();
- 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 = readCharForward();
- if (ch == -1) {
- return ELOperandToken.EOF;
- }
- if (Character.isJavaIdentifierStart((char)ch)) {
- releaseChar();
- return readVarOrMethodToken();
- }
- releaseChar();
- return ELOperandToken.EOF;
- }
- }
- return ELOperandToken.EOF;
- }
-
- /* Reads the next character in the document
- *
- * @return
- */
- int readCharForward() {
- if (index >= documentContent.length() ||
- documentContent == null ||
- index < 0)
- return -1;
-
- try {
- int ch = documentContent.charAt(index);
- index++;
- return ch;
- } catch (StringIndexOutOfBoundsException e) {
- return -1;
- }
- }
-
- /* Reads and returns the variable token from the expression
- * Forward parsing
- *
- * @return
- */
- private ELOperandToken readVarOrMethodToken() {
- fState = STATE_VAR;
- int startOfToken = index;
- int ch;
- while((ch = readCharForward()) != -1) {
- if (!Character.isJavaIdentifierPart(ch)) {
- int marker = index - 1; // save the current index (end of var name)
- // skip spaces between the method's name and it's parameters
- if (Character.isSpaceChar(ch)) {
- if (!skipSpaceChars()) {
- // EOF - return the var
- index = marker; // restore the end of var name in the current index
- return (index - startOfToken> 0 ? new ELOperandToken(startOfToken, index -
startOfToken, getCharSequence(startOfToken, index - startOfToken),
ELOperandToken.EL_PROPERTY_NAME_TOKEN) : ELOperandToken.EOF);
- }
- }
- if (ch == -1) {
- // EOF - return the var
- index = marker; // restore the end of var name in the current index
- return (index - startOfToken> 0 ? new ELOperandToken(startOfToken, index -
startOfToken, getCharSequence(startOfToken, index - startOfToken),
ELOperandToken.EL_PROPERTY_NAME_TOKEN) : ELOperandToken.EOF);
- }
-
- if (ch != '(') {
- // not a method - return the var
- index = marker; // restore the end of var name in the current index
- return (index - startOfToken> 0 ? new ELOperandToken(startOfToken, index -
startOfToken, getCharSequence(startOfToken, index - startOfToken),
ELOperandToken.EL_PROPERTY_NAME_TOKEN) : ELOperandToken.EOF);
- }
- releaseChar();
- fState = STATE_METHOD;
-
- // read the method parameters
- skipMethodParameters(); // Do not use the return value (not a matter)
- return (index - startOfToken> 0 ? new ELOperandToken(startOfToken, index -
startOfToken, getCharSequence(startOfToken, index - startOfToken),
ELOperandToken.EL_METHOD_TOKEN) : ELOperandToken.EOF);
- }
- }
- return (index - startOfToken > 0 ? new ELOperandToken(startOfToken, index -
startOfToken, getCharSequence(startOfToken, index - startOfToken),
ELOperandToken.EL_PROPERTY_NAME_TOKEN) : ELOperandToken.EOF);
- }
-
- /* Reads and returns the separator token from the expression
- * Forward parsing
- *
- * @return
- */
- private ELOperandToken readSeparatorToken() {
- fState = STATE_SEPARATOR;
- int ch = readCharForward();
-
- return (ch == '.' ? new ELOperandToken(index - 1, 1, getCharSequence(index - 1,
1), ELOperandToken.EL_SEPARATOR_TOKEN) :
- ELOperandToken.EOF);
- }
-
-
- /*
- * Skips the space characters in the document
- */
- private boolean skipSpaceChars() {
- int ch;
- while ((ch = readCharForward()) != -1) {
- if (!Character.isSpaceChar(ch)) {
- releaseChar();
- break;
- }
- }
- return true;
- }
-
- /*
- * Skips the method parameters characters in the document
- * Forward parsing
- *
- * @return boolean true if complete parameters set had been read
- */
- private boolean skipMethodParameters() {
- int ch = readCharForward();
- if (ch != '(')
- return false;
- int pCount = 1;
- while (pCount > 0) {
- ch = readCharForward();
- 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
- * Forward parsing
- *
- */
- private void skipQuotedChars(char pair) {
- int ch = readCharForward();
-
- while (ch != -1) {
- if (ch == pair)
- return;
-
- if (ch == '\\') {
- int backSlashCount = 0;
- while (ch == '\\') {
- backSlashCount++;
- ch = readCharForward();
- }
- releaseChar(); // Return the last non-slash char to the buffer
- if ((backSlashCount/2)*2 == backSlashCount) {
- return;
- }
- }
- ch = readCharForward();
- }
- }
-
- /*
- * returns the character to the document
- */
- private void releaseChar() {
- if (index > 0)
- index--;
- }
-}
Modified:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/el/SeamPromptingProvider.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/el/SeamPromptingProvider.java 2008-09-29
15:29:16 UTC (rev 10539)
+++
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/el/SeamPromptingProvider.java 2008-09-29
15:29:27 UTC (rev 10540)
@@ -56,13 +56,15 @@
list.addAll(set);
return list;
} else if(MEMBERS.equals(id)) {
- try {
- String prefix2 = SeamELCompletionEngine.getPrefix(prefix, prefix.length());
- List<String> suggestions = engine.getCompletions(p, f, prefix, prefix2, 2,
true, null);
- return suggestions;
- } catch (BadLocationException e) {
- return EMPTY_LIST;
- }
+ //TODO either refactor or remove this class
+// try {
+// String prefix2 = SeamELCompletionEngine.getPrefix(prefix, prefix.length());
+// List<String> suggestions = engine.getCompletions(p, f, prefix, prefix2, 2,
true, null);
+// return suggestions;
+// } catch (BadLocationException e) {
+// return EMPTY_LIST;
+// }
+ return EMPTY_LIST;
}
return 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-09-29
15:29:16 UTC (rev 10539)
+++
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/validation/SeamELValidator.java 2008-09-29
15:29:27 UTC (rev 10540)
@@ -280,6 +280,7 @@
}
private void validateEl(IFile file, ELExpression el, int offset) {
+ if(el == null) return;
List<ELInvocationExpression> es = el.getInvocations();
for (ELInvocationExpression token: es) {
validateElOperand(file, token, offset);