Author: scabanovich
Date: 2008-09-25 10:46:38 -0400 (Thu, 25 Sep 2008)
New Revision: 10480
Added:
trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/core/model/ELUtil.java
Modified:
trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/core/model/ELObject.java
trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/core/parser/ELParser.java
trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/core/parser/ELParserFactory.java
trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/core/parser/Tokenizer.java
trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/core/parser/TokenizerFactory.java
trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/internal/core/model/ELInvocationExpressionImpl.java
trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/internal/core/model/ELMethodInvocationImpl.java
trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/internal/core/model/ELObjectImpl.java
trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/internal/core/parser/ELParserImpl.java
Log:
JBIDE-1497.
Minor improvements
Modified:
trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/core/model/ELObject.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/core/model/ELObject.java 2008-09-25
14:39:36 UTC (rev 10479)
+++
trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/core/model/ELObject.java 2008-09-25
14:46:38 UTC (rev 10480)
@@ -25,6 +25,8 @@
public ELModel getModel();
+ public int getStartPosition();
+ public int getEndPosition();
public int getLength();
public String getText();
Added:
trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/core/model/ELUtil.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/core/model/ELUtil.java
(rev 0)
+++
trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/core/model/ELUtil.java 2008-09-25
14:46:38 UTC (rev 10480)
@@ -0,0 +1,45 @@
+/*******************************************************************************
+ * 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.common.el.core.model;
+
+import java.util.List;
+
+public class ELUtil {
+
+ public static ELInvocationExpression findExpression(ELModel model, int offset) {
+ ELInvocationExpression result = null;
+ int off = -1;
+ List<ELInstance> is = model.getInstances();
+ for (ELInstance i: is) {
+ ELExpression expr = i.getExpression();
+ if(expr == null) continue;
+ if(expr.getFirstToken().getStart() > offset) continue;
+ List<ELInvocationExpression> invs = expr.getInvocations();
+ for (ELInvocationExpression inv: invs) {
+ if(inv.getStartPosition() <= offset && inv.getEndPosition() >= offset)
{
+ if(off < inv.getStartPosition()) {
+ result = inv;
+ off = inv.getStartPosition();
+ ELInvocationExpression l = inv.getLeft();
+ while(l != null && l.getEndPosition() >= offset) {
+ result = l;
+ l = l.getLeft();
+ }
+ }
+ }
+ }
+
+ }
+
+ return result;
+ }
+
+}
Modified:
trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/core/parser/ELParser.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/core/parser/ELParser.java 2008-09-25
14:39:36 UTC (rev 10479)
+++
trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/core/parser/ELParser.java 2008-09-25
14:46:38 UTC (rev 10480)
@@ -23,6 +23,8 @@
public ELModel parse(String source);
+ public ELModel parse(String source, int start, int length);
+
public List<SyntaxError> getSyntaxErrors();
}
Modified:
trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/core/parser/ELParserFactory.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/core/parser/ELParserFactory.java 2008-09-25
14:39:36 UTC (rev 10479)
+++
trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/core/parser/ELParserFactory.java 2008-09-25
14:46:38 UTC (rev 10480)
@@ -24,51 +24,47 @@
public class ELParserFactory {
public static ELParser createDefaultParser() {
- return new ELParser() {
- ELParserImpl impl = new ELParserImpl();
- List<SyntaxError> errors = null;
-
- public ELModel parse(String source) {
- Tokenizer t = TokenizerFactory.createDefaultTokenizer();
- LexicalToken token = t.parse(source);
- errors = t.getErrors();
- if(token == null) {
- return null;
- }
- ELModelImpl model = impl.parse(token);
- model.setSource(source);
- model.setErrors(errors);
- return model;
+ return new DefaultParser() {
+ protected Tokenizer createTokenizer() {
+ return TokenizerFactory.createDefaultTokenizer();
}
+ };
+ }
- public List<SyntaxError> getSyntaxErrors() {
- return errors;
+ public static ELParser createJbossParser() {
+ return new DefaultParser() {
+ protected Tokenizer createTokenizer() {
+ return TokenizerFactory.createJbossTokenizer();
}
};
}
- public static ELParser createJbossParser() {
- return new ELParser() {
- ELParserImpl impl = new ELParserImpl();
- List<SyntaxError> errors = null;
+ private static abstract class DefaultParser implements ELParser {
+ ELParserImpl impl = new ELParserImpl();
+ List<SyntaxError> errors = null;
- public ELModel parse(String source) {
- Tokenizer t = TokenizerFactory.createJbossTokenizer();
- LexicalToken token = t.parse(source);
- errors = t.getErrors();
- if(token == null) {
- return null;
- }
- ELModelImpl model = impl.parse(token);
- model.setSource(source);
- model.setErrors(errors);
- return model;
- }
+ public ELModel parse(String source) {
+ return parse(source, 0, source.length());
+ }
- public List<SyntaxError> getSyntaxErrors() {
- return errors;
+ public ELModel parse(String source, int start, int length) {
+ Tokenizer t = createTokenizer();
+ LexicalToken token = t.parse(source, start, length);
+ errors = t.getErrors();
+ if(token == null) {
+ return null;
}
- };
+ ELModelImpl model = impl.parse(token);
+ model.setSource(source);
+ model.setErrors(errors);
+ return model;
+ }
+
+ public List<SyntaxError> getSyntaxErrors() {
+ return errors;
+ }
+
+ protected abstract Tokenizer createTokenizer();
}
}
Modified:
trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/core/parser/Tokenizer.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/core/parser/Tokenizer.java 2008-09-25
14:39:36 UTC (rev 10479)
+++
trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/core/parser/Tokenizer.java 2008-09-25
14:46:38 UTC (rev 10480)
@@ -70,14 +70,20 @@
}
public LexicalToken parse(String sourceString) {
+ return parse(sourceString, 0, sourceString.length());
+ }
+
+ public LexicalToken parse(String sourceString, int initialOffset, int length) {
this.sourceString = sourceString;
errors.clear();
- index = 0;
+ index = initialOffset;
start = new LexicalToken(0, 0, "", -1000);
last = start;
state = BasicStates.STATE_EXPECTING_EL;
-
- while(index < sourceString.length()) {
+
+ int lastIndex = initialOffset + length;
+ if(lastIndex > sourceString.length()) lastIndex = sourceString.length();
+ while(index < lastIndex) {
boolean done = false;
List<IRule> rs = rules.get(state);
for (IRule rule : rs) {
Modified:
trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/core/parser/TokenizerFactory.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/core/parser/TokenizerFactory.java 2008-09-25
14:39:36 UTC (rev 10479)
+++
trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/core/parser/TokenizerFactory.java 2008-09-25
14:46:38 UTC (rev 10480)
@@ -15,6 +15,7 @@
import org.jboss.tools.common.el.core.model.ELExpression;
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.ELUtil;
import org.jboss.tools.common.el.internal.core.parser.rule.ArgRule;
import org.jboss.tools.common.el.internal.core.parser.rule.CallRule;
import org.jboss.tools.common.el.internal.core.parser.rule.ErrorRecoveryRule;
@@ -100,7 +101,7 @@
}
public static void main(String[] args) {
- String text = "#{a.b().b()}";
+ String text = "#{g11.g12.y13} #{a14.b15(x.t.u(uu.ii[9],
j)).b16(m17(v18(i19[2]).u20).)+ a21(c.).b.}";
//"#{not a.b(x,y) + s.h((6 != -8) & (7 + -iy88.g[9].h(7 div 8).i.j)+(8) ? 4 :
7,'p', a.b.c.d[null])}";
//"q82#{a( g.h(7 + 8) + 8, g['h'].j(),'p')}k#{b}";
Tokenizer t = createJbossTokenizer();
@@ -117,7 +118,7 @@
System.out.println("state=" + e.getState() + " position=" +
e.getPosition());
}
ELParser parser = ELParserFactory.createJbossParser();
- ELModel model = parser.parse(text);
+ ELModel model = parser.parse(text, 0, 13);
System.out.println(model);
ELExpression expr = model.getInstances().get(0).getExpression();
System.out.println("Expression=" + expr);
@@ -126,6 +127,11 @@
for (ELInvocationExpression i : is) {
System.out.println(i);
}
+
+ int off = 2;
+ ELExpression expr1 = ELUtil.findExpression(model, off);
+ System.out.println("Expression at " + off + ": " + expr1);
+
}
}
Modified:
trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/internal/core/model/ELInvocationExpressionImpl.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/internal/core/model/ELInvocationExpressionImpl.java 2008-09-25
14:39:36 UTC (rev 10479)
+++
trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/internal/core/model/ELInvocationExpressionImpl.java 2008-09-25
14:46:38 UTC (rev 10480)
@@ -51,6 +51,13 @@
public void collectInvocations(List<ELInvocationExpression> list) {
list.add(this);
- //We do not need left part expression, it is part of this invocation
+ //We do not need left part expression, it is part of this invocation
+ ELInvocationExpressionImpl l = this;
+ while(l != null) {
+ if(l instanceof ELMethodInvocationImpl) {
+ ((ELMethodInvocationImpl)l).collectInvocationsInParameters(list);
+ }
+ l = l.getLeft();
+ }
}
}
Modified:
trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/internal/core/model/ELMethodInvocationImpl.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/internal/core/model/ELMethodInvocationImpl.java 2008-09-25
14:39:36 UTC (rev 10479)
+++
trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/internal/core/model/ELMethodInvocationImpl.java 2008-09-25
14:46:38 UTC (rev 10480)
@@ -53,8 +53,7 @@
return ELObjectType.EL_METHOD_INVOCATION;
}
- public void collectInvocations(List<ELInvocationExpression> list) {
- super.collectInvocations(list);
+ public void collectInvocationsInParameters(List<ELInvocationExpression> list) {
if(parameters != null) {
List<ELExpression> ps = parameters.getParameters();
for (ELExpression expr: ps) {
Modified:
trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/internal/core/model/ELObjectImpl.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/internal/core/model/ELObjectImpl.java 2008-09-25
14:39:36 UTC (rev 10479)
+++
trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/internal/core/model/ELObjectImpl.java 2008-09-25
14:46:38 UTC (rev 10480)
@@ -35,10 +35,15 @@
}
public int getLength() {
- int start = firstToken.getStart();
+ return getEndPosition() - getStartPosition();
+ }
+
+ public int getStartPosition() {
+ return firstToken == null ? -1 : firstToken.getStart();
+ }
+ public int getEndPosition() {
LexicalToken lt = (lastToken != null) ? lastToken : firstToken;
- int end = lt.getStart() + lt.getLength();
- return end - start;
+ return lt == null ? -1 : lt.getStart() + lt.getLength();
}
public String getText() {
Modified:
trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/internal/core/parser/ELParserImpl.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/internal/core/parser/ELParserImpl.java 2008-09-25
14:39:36 UTC (rev 10479)
+++
trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/internal/core/parser/ELParserImpl.java 2008-09-25
14:46:38 UTC (rev 10480)
@@ -199,6 +199,12 @@
}
r.setLeft(result);
result = right;
+ } else {
+ ELPropertyInvocationImpl incompleteProperty = new ELPropertyInvocationImpl();
+ incompleteProperty.setSeparator(dot);
+ incompleteProperty.setLastToken(dot);
+ incompleteProperty.setLeft(result);
+ result = incompleteProperty;
}
}
return result;