Author: scabanovich
Date: 2008-09-30 09:33:28 -0400 (Tue, 30 Sep 2008)
New Revision: 10566
Modified:
trunk/jst/plugins/org.jboss.tools.jst.jsp/META-INF/MANIFEST.MF
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/contentassist/JSPActiveContentAssistProcessor.java
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/support/kb/WTPKbdBeanPropertyResource.java
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/support/kb/WTPKbdBundlePropertyResource.java
Log:
JBIDE-1497.
Old ELParser replaced.
Modified: trunk/jst/plugins/org.jboss.tools.jst.jsp/META-INF/MANIFEST.MF
===================================================================
--- trunk/jst/plugins/org.jboss.tools.jst.jsp/META-INF/MANIFEST.MF 2008-09-30 13:32:44 UTC
(rev 10565)
+++ trunk/jst/plugins/org.jboss.tools.jst.jsp/META-INF/MANIFEST.MF 2008-09-30 13:33:28 UTC
(rev 10566)
@@ -23,6 +23,7 @@
Require-Bundle: org.jboss.tools.common,
org.jboss.tools.common.kb,
org.jboss.tools.common.model,
+ org.jboss.tools.common.el.core,
org.jboss.tools.common.text.xml,
org.jboss.tools.common.model.ui,
org.jboss.tools.jst.web,
Modified:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/contentassist/JSPActiveContentAssistProcessor.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/contentassist/JSPActiveContentAssistProcessor.java 2008-09-30
13:32:44 UTC (rev 10565)
+++
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/contentassist/JSPActiveContentAssistProcessor.java 2008-09-30
13:33:28 UTC (rev 10566)
@@ -12,12 +12,18 @@
import java.util.Collection;
import java.util.Iterator;
+import java.util.List;
import org.eclipse.wst.sse.core.utils.StringUtils;
import org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode;
import org.eclipse.wst.xml.ui.internal.contentassist.ContentAssistRequest;
import org.eclipse.wst.xml.ui.internal.contentassist.XMLRelevanceConstants;
import org.eclipse.wst.xml.ui.internal.util.SharedXMLEditorPluginImageHelper;
+import org.jboss.tools.common.el.core.model.ELInstance;
+import org.jboss.tools.common.el.core.model.ELModel;
+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.kb.KbException;
import org.jboss.tools.common.kb.KbProposal;
import org.jboss.tools.common.kb.KbQuery;
@@ -264,33 +270,10 @@
* @return
*/
private int getELStartPosition(String matchString) {
- if (matchString == null || matchString.length() == 0)
- return -1;
-
- int offset = matchString.length();
-
- while (--offset >= 0) {
- if ('}' == matchString.charAt(offset))
- return -1;
-
- if ('"' == matchString.charAt(offset) || '\'' ==
matchString.charAt(offset)) {
- int backslashCount = 0;
- while ((offset - 1 - backslashCount) >= 0 &&
matchString.charAt(offset - 1 - backslashCount) == '\\') {
- backslashCount++;
- }
-
- if (backslashCount % 2 == 0)
- return -1;
- }
-
- if ('{' == matchString.charAt(offset) &&
- (offset - 1) >= 0 &&
- ('#' == matchString.charAt(offset - 1) ||
- '$' == matchString.charAt(offset - 1))) {
- return (offset - 1);
- }
- }
- return -1;
+ ELParser p = ELParserFactory.createJbossParser();
+ ELModel model = p.parse(matchString);
+ ELInstance is = ELUtil.findInstance(model, matchString.length());
+ return is == null ? -1 : is.getStartPosition();
}
/* Checks if the preceding character is a Sharp-character
@@ -321,68 +304,12 @@
currentValue.length() < matchString.length())
return -1;
- String restOfCurrentValue = currentValue.substring(matchString.length());
- int offset = -1;
+ ELParser p = ELParserFactory.createJbossParser();
+ ELModel model = p.parse(currentValue);
+ ELInstance is = ELUtil.findInstance(model, matchString.length());
+ if(is == null || is.getCloseInstanceToken() == null) return -1;
- char inQuotesChar = 0;
- while (++offset < restOfCurrentValue.length()) {
- if (inQuotesChar == 0) {
- if ('}' == restOfCurrentValue.charAt(offset))
- return matchString.length() + offset;
-
- if ('#' == restOfCurrentValue.charAt(offset))
- return -1;
-
- if ('"' == restOfCurrentValue.charAt(offset) ||
- '\'' == restOfCurrentValue.charAt(offset)) {
- inQuotesChar = restOfCurrentValue.charAt(offset);
- }
-
- if ('\\' == restOfCurrentValue.charAt(offset)) {
- int backslashCount = 1;
-
- while ((offset + backslashCount) < restOfCurrentValue.length()
&&
- restOfCurrentValue.charAt(offset + backslashCount) == '\\') {
- backslashCount++;
- }
-
- if (offset + backslashCount >= restOfCurrentValue.length())
- return -1;
-
- if (backslashCount % 2 == 1 &&
- ('"' == restOfCurrentValue.charAt(offset +
backslashCount) ||
- '\'' == restOfCurrentValue.charAt(offset +
backslashCount))) {
- inQuotesChar = restOfCurrentValue.charAt(offset + backslashCount);
- offset += backslashCount;
- }
- }
- } else {
- if ('"' == restOfCurrentValue.charAt(offset) ||
- '\'' == restOfCurrentValue.charAt(offset)) {
- inQuotesChar = 0;
- }
-
- if ('\\' == restOfCurrentValue.charAt(offset)) {
- int backslashCount = 1;
-
- while ((offset + backslashCount) < restOfCurrentValue.length()
&&
- restOfCurrentValue.charAt(offset + backslashCount) == '\\') {
- backslashCount++;
- }
-
- if (offset + backslashCount >= restOfCurrentValue.length())
- return -1;
-
- if (backslashCount % 2 == 1 &&
- ('"' == restOfCurrentValue.charAt(offset +
backslashCount) ||
- '\'' == restOfCurrentValue.charAt(offset +
backslashCount))) {
- inQuotesChar = 0;
- offset += backslashCount;
- }
- }
- }
- }
- return -1;
+ return is.getEndPosition();
}
}
\ No newline at end of file
Modified:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/support/kb/WTPKbdBeanPropertyResource.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/support/kb/WTPKbdBeanPropertyResource.java 2008-09-30
13:32:44 UTC (rev 10565)
+++
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/support/kb/WTPKbdBeanPropertyResource.java 2008-09-30
13:33:28 UTC (rev 10566)
@@ -20,11 +20,17 @@
import java.util.TreeSet;
import org.eclipse.ui.IEditorInput;
+import org.jboss.tools.common.el.core.model.ELExpression;
+import org.jboss.tools.common.el.core.model.ELInstance;
+import org.jboss.tools.common.el.core.model.ELInvocationExpression;
+import org.jboss.tools.common.el.core.model.ELModel;
+import org.jboss.tools.common.el.core.model.ELPropertyInvocation;
+import org.jboss.tools.common.el.core.parser.ELParser;
+import org.jboss.tools.common.el.core.parser.ELParserFactory;
import org.jboss.tools.common.kb.KbDinamicResource;
import org.jboss.tools.common.kb.KbProposal;
import org.jboss.tools.common.kb.KbProposal.PostProcessing;
import org.jboss.tools.common.model.XModel;
-import org.jboss.tools.common.model.util.ELParser;
import org.jboss.tools.jst.jsp.JspEditorPlugin;
import org.jboss.tools.jst.web.project.list.IWebPromptingProvider;
import org.jboss.tools.jst.web.project.list.WebPromptingProvider;
@@ -53,53 +59,32 @@
try {
if (!isReadyToUse()) return proposals;
- ELParser p = new ELParser();
- ELParser.Token token = p.parse(query);
+ ELParser p = ELParserFactory.createDefaultParser();
+ ELModel model = p.parse(query);
- ArrayList<ELParser.Token> beans = new ArrayList<ELParser.Token>();
+ List<ELInstance> is = model.getInstances();
+
+ ELInvocationExpression expr = null;
+ ELInvocationExpression current = null;
boolean hasProperty = false;
- ELParser.Token c = token;
- boolean insideSL = false;
- while(c != null) {
- if(c.kind == ELParser.SPACES) {
- if(!insideSL) {
- beans.clear();
- hasProperty = false;
- } else {
- //do nothing
- }
- } else if(c.kind == ELParser.NONE || c.kind == ELParser.OPEN || c.kind ==
ELParser.CLOSE) {
- if(c.kind == ELParser.OPEN) insideSL = true;
- else if(c.kind == ELParser.CLOSE) insideSL = false;
- beans.clear();
- hasProperty = false;
- } else if(c.kind == ELParser.ARGUMENT) {
+ for (ELInstance i: is) {
+ if(!(i.getExpression() instanceof ELInvocationExpression)) continue;
+ expr = (ELInvocationExpression)i.getExpression();
+ ELInvocationExpression inv = expr;
+ current = inv;
+ if(inv.getLeft() != null) {
hasProperty = true;
- } else if(c.kind == ELParser.DOT || c.kind == ELParser.OPEN_ARG) {
- hasProperty = true;
- } else if(c.kind == ELParser.NAME) {
- if(beans.size() > 0 && (c.next == null || (c.next.kind != ELParser.DOT
&& c.next.kind != ELParser.OPEN_ARG))) {
- hasProperty = true;
- } else {
- beans.add(c);
- hasProperty = false;
- }
+ current = inv.getLeft(); //bean
}
- c = c.next;
}
- ELParser.Token b = (beans.size() == 0) ? null : (ELParser.Token)beans.get(0);
- ELParser.Token e = (beans.size() == 0) ? null : (ELParser.Token)beans.get(beans.size()
- 1);
+ String beanNameFromQuery = current == null ? null : current.getText();
- String beanNameFromQuery = b == null ? null : query.substring(b.start, e.end);
- StringBuffer sb = new StringBuffer();
- ELParser.Token bi = b;
- while(bi != null) {
- if(bi.kind != ELParser.SPACES) sb.append(query.substring(bi.start, bi.end));
- bi = bi.next;
+ String restQuery = expr == null ? null : expr.getText();
+ if(expr instanceof ELPropertyInvocation) {
+// restQuery = ((ELPropertyInvocation)expr).getQualifiedName();
}
- String restQuery = b == null ? "" : sb.toString();
Set<String> sorted = new TreeSet<String>(String.CASE_INSENSITIVE_ORDER);
fillSortedProposalStrings(sorted, beanNameFromQuery, hasProperty);
@@ -193,13 +178,27 @@
class PostProcessingImpl implements PostProcessing {
public void process(KbProposal proposal, String value, int offset) {
- ELParser p = new ELParser();
- ELParser.Token token = p.parse(value);
- ELParser.Token c = ELParser.getTokenAt(token, offset);
- ELParser.Token callStart = ELParser.getCallStart(c);
- if(callStart != null) proposal.setStart(callStart.start); else
proposal.setStart(offset);
- ELParser.Token callEnd = ELParser.getCallEnd(c);
- if(callEnd != null && callEnd.end >= offset) proposal.setEnd(callEnd.end);
else proposal.setEnd(offset);
+ ELParser p = ELParserFactory.createDefaultParser();
+ ELModel model = p.parse(value);
+ List<ELInstance> is = model.getInstances();
+ ELInvocationExpression expr = null;
+ for (ELInstance i: is) {
+ if(i.getExpression() instanceof ELInvocationExpression) {
+ expr = (ELInvocationExpression)i.getExpression();
+ break;
+ }
+ }
+ if(expr != null) {
+ proposal.setStart(expr.getStartPosition());
+ } else {
+ proposal.setStart(offset);
+ }
+
+ if(expr != null && expr.getEndPosition() >= offset) {
+ proposal.setEnd(expr.getEndPosition());
+ } else {
+ proposal.setEnd(offset);
+ }
int pos = proposal.getReplacementString().length();
// JBIDE-2437: Because of the issue add EL open/close brackets to the proposal
replacement string
Modified:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/support/kb/WTPKbdBundlePropertyResource.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/support/kb/WTPKbdBundlePropertyResource.java 2008-09-30
13:32:44 UTC (rev 10565)
+++
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/support/kb/WTPKbdBundlePropertyResource.java 2008-09-30
13:33:28 UTC (rev 10566)
@@ -20,10 +20,14 @@
import java.util.TreeSet;
import org.eclipse.ui.IEditorInput;
+import org.jboss.tools.common.el.core.model.ELInstance;
+import org.jboss.tools.common.el.core.model.ELInvocationExpression;
+import org.jboss.tools.common.el.core.model.ELModel;
+import org.jboss.tools.common.el.core.parser.ELParser;
+import org.jboss.tools.common.el.core.parser.ELParserFactory;
import org.jboss.tools.common.kb.KbDinamicResource;
import org.jboss.tools.common.kb.KbProposal;
import org.jboss.tools.common.model.XModelObject;
-import org.jboss.tools.common.model.util.ELParser;
import org.jboss.tools.common.model.util.XModelObjectLoaderUtil;
import org.jboss.tools.jst.jsp.JspEditorPlugin;
import org.jboss.tools.jst.web.project.list.WebPromptingProvider;
@@ -45,61 +49,37 @@
try {
if (!isReadyToUse()) return proposals;
- ELParser p = new ELParser();
- ELParser.Token token = p.parse(query);
+ ELParser p = ELParserFactory.createDefaultParser();
+ ELModel model = p.parse(query);
+
+ List<ELInstance> is = model.getInstances();
+
+ ELInvocationExpression expr = null;
+ ELInvocationExpression current = null;
boolean hasProperty = false;
-// boolean isArgument = false;
- ELParser.Token arg = null;
-
- ArrayList<ELParser.Token> beans = new ArrayList<ELParser.Token>();
-
- ELParser.Token c = token;
- boolean insideSL = false;
- while(c != null) {
- if(c.kind == ELParser.SPACES) {
- if(!insideSL) {
- beans.clear();
- hasProperty = false;
- } else {
- //do nothing
- }
- } else if(c.kind == ELParser.NONE || c.kind == ELParser.OPEN || c.kind ==
ELParser.CLOSE) {
- if(c.kind == ELParser.OPEN) insideSL = true;
- else if(c.kind == ELParser.CLOSE) insideSL = false;
- beans.clear();
- hasProperty = false;
- arg = null;
- } else if(c.kind == ELParser.ARGUMENT) {
+
+ for (ELInstance i: is) {
+ if(!(i.getExpression() instanceof ELInvocationExpression)) continue;
+ expr = (ELInvocationExpression)i.getExpression();
+ ELInvocationExpression inv = expr;
+ current = inv;
+ if(inv.getLeft() != null) {
hasProperty = true;
-// isArgument = true;
- arg = c;
- } else if(c.kind == ELParser.DOT || c.kind == ELParser.OPEN_ARG) {
- hasProperty = true;
- } else if(c.kind == ELParser.NAME) {
- if(beans.size() > 0 && (c.next == null || (c.next.kind != ELParser.DOT
&& c.next.kind != ELParser.OPEN_ARG))) {
- hasProperty = true;
- arg = c;
- } else {
- beans.add(c);
- hasProperty = false;
- }
+ current = inv.getLeft(); //bean
}
- c = c.next;
}
- ELParser.Token b = (beans.size() == 0) ? null : (ELParser.Token)beans.get(0);
- ELParser.Token e = (beans.size() == 0) ? null : (ELParser.Token)beans.get(beans.size()
- 1);
+ String beanNameFromQuery = current == null ? null : current.getText();
- String beanNameFromQuery = b == null ? null : query.substring(b.start, e.end);
-
- StringBuffer sb = new StringBuffer();
- ELParser.Token bi = b;
- while(bi != null) {
- if(bi.kind != ELParser.SPACES) sb.append(query.substring(bi.start, bi.end));
- bi = bi.next;
+ String restQuery = expr == null ? "" : expr.getText();
+ String argName = expr == null ? "" : expr.getMemberName();
+ if(argName == null) argName = "";
+ if(argName.startsWith("\"") || argName.startsWith("'"))
{
+ argName = argName.substring(1);
}
- String restQuery = b == null ? "" : sb.toString();
- String argName = arg == null ? "" : query.substring(arg.start, arg.end);
+ if(argName.endsWith("\"") || argName.endsWith("'")) {
+ argName = argName.substring(0, argName.length() - 1);
+ }
Set<String> sorted = new TreeSet<String>(String.CASE_INSENSITIVE_ORDER);
Show replies by date