Author: scabanovich
Date: 2008-10-01 11:31:11 -0400 (Wed, 01 Oct 2008)
New Revision: 10596
Added:
trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/core/parser/ELParserUtil.java
trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/core/resolver/
trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/core/resolver/ELCompletionEngine.java
trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/core/resolver/ELOperandResolveStatus.java
trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/core/resolver/ElVarSearcher.java
trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/core/resolver/TypeInfoCollector.java
trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/core/resolver/Var.java
Modified:
trunk/common/plugins/org.jboss.tools.common.el.core/META-INF/MANIFEST.MF
trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/core/Activator.java
trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/core/model/ELModel.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/LexicalToken.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/ELModelImpl.java
trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/internal/core/model/ELObjectImpl.java
Log:
JBIDE-1497.
Refactoring
Modified: trunk/common/plugins/org.jboss.tools.common.el.core/META-INF/MANIFEST.MF
===================================================================
--- trunk/common/plugins/org.jboss.tools.common.el.core/META-INF/MANIFEST.MF 2008-10-01
15:26:10 UTC (rev 10595)
+++ trunk/common/plugins/org.jboss.tools.common.el.core/META-INF/MANIFEST.MF 2008-10-01
15:31:11 UTC (rev 10596)
@@ -7,10 +7,16 @@
Bundle-Version: 2.0.0
Provide-Package: org.jboss.tools.common.el.core,
org.jboss.tools.common.el.core.model,
- org.jboss.tools.common.el.core.parser
+ org.jboss.tools.common.el.core.parser,
+ org.jboss.tools.common.el.core.resolver
Bundle-Activator: org.jboss.tools.common.el.core.Activator
Require-Bundle: org.eclipse.ui,
org.eclipse.core.runtime,
org.eclipse.core.resources,
+ org.eclipse.jdt.core,
org.eclipse.jface.text,
+ org.eclipse.wst.sse.core,
+ org.eclipse.wst.sse.ui,
+ org.jboss.tools.common,
+ org.jboss.tools.common.model,
org.jboss.tools.common.resref.core;reprovide=true
Modified:
trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/core/Activator.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/core/Activator.java 2008-10-01
15:26:10 UTC (rev 10595)
+++
trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/core/Activator.java 2008-10-01
15:31:11 UTC (rev 10596)
@@ -10,13 +10,14 @@
******************************************************************************/
package org.jboss.tools.common.el.core;
-import org.eclipse.ui.plugin.AbstractUIPlugin;
+import org.jboss.tools.common.log.BaseUIPlugin;
+import org.jboss.tools.common.log.IPluginLog;
import org.osgi.framework.BundleContext;
/**
* The activator class controls the plug-in life cycle
*/
-public class Activator extends AbstractUIPlugin {
+public class Activator extends BaseUIPlugin {
// The plug-in ID
public static final String PLUGIN_ID = "org.jboss.tools.common.el";
@@ -57,4 +58,8 @@
return plugin;
}
+ public static IPluginLog getPluginLog() {
+ return getDefault();
+ }
+
}
Modified:
trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/core/model/ELModel.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/core/model/ELModel.java 2008-10-01
15:26:10 UTC (rev 10595)
+++
trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/core/model/ELModel.java 2008-10-01
15:31:11 UTC (rev 10596)
@@ -25,4 +25,6 @@
public List<ELInstance> getInstances();
+ public void shift(int delta);
+
}
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-10-01
15:26:10 UTC (rev 10595)
+++
trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/core/parser/ELParserFactory.java 2008-10-01
15:31:11 UTC (rev 10596)
@@ -10,58 +10,13 @@
******************************************************************************/
package org.jboss.tools.common.el.core.parser;
-import java.util.List;
-
-import org.jboss.tools.common.el.core.model.ELModel;
-import org.jboss.tools.common.el.internal.core.model.ELModelImpl;
-import org.jboss.tools.common.el.internal.core.parser.ELParserImpl;
-
/**
*
* @author V. Kabanovich
*
*/
-public class ELParserFactory {
+public interface ELParserFactory {
- public static ELParser createDefaultParser() {
- return new DefaultParser() {
- protected Tokenizer createTokenizer() {
- return TokenizerFactory.createDefaultTokenizer();
- }
- };
- }
+ public ELParser createParser();
- public static ELParser createJbossParser() {
- return new DefaultParser() {
- protected Tokenizer createTokenizer() {
- return TokenizerFactory.createJbossTokenizer();
- }
- };
- }
-
- private static abstract class DefaultParser implements ELParser {
- ELParserImpl impl = new ELParserImpl();
- List<SyntaxError> errors = null;
-
- public ELModel parse(String source) {
- return parse(source, 0, source.length());
- }
-
- public ELModel parse(String source, int start, int length) {
- Tokenizer t = createTokenizer();
- LexicalToken token = t.parse(source, start, length);
- errors = t.getErrors();
- ELModelImpl model = impl.parse(token);
- model.setSource(source);
- model.setErrors(errors);
- return model;
- }
-
- public List<SyntaxError> getSyntaxErrors() {
- return errors;
- }
-
- protected abstract Tokenizer createTokenizer();
- }
-
}
Added:
trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/core/parser/ELParserUtil.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/core/parser/ELParserUtil.java
(rev 0)
+++
trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/core/parser/ELParserUtil.java 2008-10-01
15:31:11 UTC (rev 10596)
@@ -0,0 +1,75 @@
+/*******************************************************************************
+ * 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.parser;
+
+import java.util.List;
+
+import org.jboss.tools.common.el.core.model.ELModel;
+import org.jboss.tools.common.el.internal.core.model.ELModelImpl;
+import org.jboss.tools.common.el.internal.core.parser.ELParserImpl;
+
+/**
+ *
+ * @author V. Kabanovich
+ *
+ */
+public class ELParserUtil {
+
+ public static ELParserFactory getDefaultFactory() {
+ return new ELParserFactory() {
+ public ELParser createParser() {
+ return new DefaultParser() {
+ protected Tokenizer createTokenizer() {
+ return TokenizerFactory.createDefaultTokenizer();
+ }
+ };
+ }
+ };
+ }
+
+ public static ELParserFactory getJbossFactory() {
+ return new ELParserFactory() {
+ public ELParser createParser() {
+ return new DefaultParser() {
+ protected Tokenizer createTokenizer() {
+ return TokenizerFactory.createJbossTokenizer();
+ }
+ };
+ }
+ };
+ }
+
+ private static abstract class DefaultParser implements ELParser {
+ ELParserImpl impl = new ELParserImpl();
+ List<SyntaxError> errors = null;
+
+ public ELModel parse(String source) {
+ return parse(source, 0, source.length());
+ }
+
+ public ELModel parse(String source, int start, int length) {
+ Tokenizer t = createTokenizer();
+ LexicalToken token = t.parse(source, start, length);
+ errors = t.getErrors();
+ 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/LexicalToken.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/core/parser/LexicalToken.java 2008-10-01
15:26:10 UTC (rev 10595)
+++
trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/core/parser/LexicalToken.java 2008-10-01
15:31:11 UTC (rev 10596)
@@ -138,4 +138,9 @@
return next.findTokenForward(type);
}
+ public void shift(int delta) {
+ start += delta;
+ if(next != null) next.shift(delta);
+ }
+
}
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-10-01
15:26:10 UTC (rev 10595)
+++
trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/core/parser/TokenizerFactory.java 2008-10-01
15:31:11 UTC (rev 10596)
@@ -13,6 +13,7 @@
import java.util.List;
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.ELUtil;
@@ -101,13 +102,14 @@
}
public static void main(String[] args) {
- String text = "#{g11.g12.y13} #{a14.b15(x.t.u(uu.ii[9],
j)).b16(m17(v18(i19[2]).u20).)+ a21(c.).b.}";
+ String text = "#{.8 +(.9d / - (-.8))}";
+//"#{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();
LexicalToken token = t.parse(text);
LexicalToken ti = token;
-
+
while(ti != null) {
int type = ti.getType();
System.out.println(type + ":" + ti.getText() + ":");
@@ -117,9 +119,10 @@
for (SyntaxError e: errors) {
System.out.println("state=" + e.getState() + " position=" +
e.getPosition());
}
- ELParser parser = ELParserFactory.createJbossParser();
- ELModel model = parser.parse(text, 0, 13);
+ ELParser parser = ELParserUtil.getJbossFactory().createParser();
+ ELModel model = parser.parse(text, 0, 90);
System.out.println(model);
+
ELExpression expr = model.getInstances().get(0).getExpression();
System.out.println("Expression=" + expr);
List<ELInvocationExpression> is = expr.getInvocations();
Added:
trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/core/resolver/ELCompletionEngine.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/core/resolver/ELCompletionEngine.java
(rev 0)
+++
trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/core/resolver/ELCompletionEngine.java 2008-10-01
15:31:11 UTC (rev 10596)
@@ -0,0 +1,26 @@
+/*******************************************************************************
+ * 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.resolver;
+
+import java.util.List;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.jface.text.BadLocationException;
+import org.jboss.tools.common.el.core.model.ELExpression;
+import org.jboss.tools.common.el.core.parser.ELParserFactory;
+
+public interface ELCompletionEngine {
+
+ public ELOperandResolveStatus resolveELOperand(IFile file, ELExpression operand,
+ boolean returnEqualedVariablesOnly, List<Var> vars, ElVarSearcher varSearcher)
throws BadLocationException, StringIndexOutOfBoundsException;
+
+ public ELParserFactory getParserFactory();
+}
Added:
trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/core/resolver/ELOperandResolveStatus.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/core/resolver/ELOperandResolveStatus.java
(rev 0)
+++
trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/core/resolver/ELOperandResolveStatus.java 2008-10-01
15:31:11 UTC (rev 10596)
@@ -0,0 +1,165 @@
+/*******************************************************************************
+ * 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.resolver;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeSet;
+
+import org.jboss.tools.common.el.core.model.ELInvocationExpression;
+
+/**
+ * Status of EL resolving.
+ * @author Jeremy
+ */
+public class ELOperandResolveStatus {
+ private ELInvocationExpression tokens;
+ Map<String, TypeInfoCollector.MethodInfo> unpairedGettersOrSetters;
+ Set<String> proposals;
+ private ELInvocationExpression lastResolvedToken;
+ private boolean isMapOrCollectionOrBundleAmoungTheTokens = false;
+ private TypeInfoCollector.MemberInfo memberOfResolvedOperand;
+
+ /**
+ * @return MemberInfo of last segment of EL operand. Null if El is not resolved.
+ */
+ public TypeInfoCollector.MemberInfo getMemberOfResolvedOperand() {
+ return memberOfResolvedOperand;
+ }
+
+ /**
+ * Sets MemberInfo for last segment of EL operand.
+ * @param lastResolvedMember
+ */
+ public void setMemberOfResolvedOperand(
+ TypeInfoCollector.MemberInfo lastResolvedMember) {
+ this.memberOfResolvedOperand = lastResolvedMember;
+ }
+
+ /**
+ * Constructor
+ * @param tokens Tokens of EL
+ */
+ public ELOperandResolveStatus(ELInvocationExpression tokens) {
+ this.tokens = tokens;
+ }
+
+ /**
+ * @return true if EL contains any not parametrized Collection or ResourceBundle.
+ */
+ public boolean isMapOrCollectionOrBundleAmoungTheTokens() {
+ return this.isMapOrCollectionOrBundleAmoungTheTokens;
+ }
+
+ public void setMapOrCollectionOrBundleAmoungTheTokens() {
+ this.isMapOrCollectionOrBundleAmoungTheTokens = true;
+ }
+
+ /**
+ * @return true if EL is resolved.
+ */
+ public boolean isOK() {
+ return !getProposals().isEmpty() || isMapOrCollectionOrBundleAmoungTheTokens();
+ }
+
+ /**
+ * @return false if El is not resolved.
+ */
+ public boolean isError() {
+ return !isOK();
+ }
+
+ /**
+ * @return List of resolved tokens of EL. Includes separators "."
+ */
+ public ELInvocationExpression getResolvedTokens() {
+ return lastResolvedToken;
+ }
+
+ /**
+ * @return List of unresolved tokens of EL.
+ */
+ public ELInvocationExpression getUnresolvedTokens() {
+ if(lastResolvedToken == tokens) return null;
+ if(lastResolvedToken != null && (lastResolvedToken.getParent() instanceof
ELInvocationExpression)) {
+ return (ELInvocationExpression)lastResolvedToken.getParent();
+ }
+ ELInvocationExpression l = tokens;
+ while(l != null && l.getLeft() != lastResolvedToken) {
+ l = l.getLeft();
+ }
+ return l;
+ }
+
+ /**
+ * @return Last resolved token of EL. Can be separator "." // no, change it
+ */
+ public ELInvocationExpression getLastResolvedToken() {
+ return lastResolvedToken;
+ }
+
+ /**
+ * @param lastResolvedToken Last resolved token of EL. Can be separator "."
+ */
+ public void setLastResolvedToken(ELInvocationExpression lastResolvedToken) {
+ this.lastResolvedToken = lastResolvedToken;
+ }
+
+ /**
+ * @return Tokens of EL.
+ */
+ public ELInvocationExpression getTokens() {
+ return tokens;
+ }
+
+ /**
+ * @param tokens Tokens of EL.
+ */
+ public void setTokens(ELInvocationExpression tokens) {
+ this.tokens = tokens;
+ }
+
+ /**
+ * @return Set of proposals for EL.
+ */
+ public Set<String> getProposals() {
+ return proposals == null ? new TreeSet<String>() : proposals;
+ }
+
+ /**
+ * @param proposals Set of proposals.
+ */
+ public void setProposals(Set<String> proposals) {
+ this.proposals = proposals;
+ }
+
+ /**
+ * @return Map of unpaired getters and setters (getters/setters without proper
setters/getters).
+ * of all properties used in EL.
+ * Key - name of property.
+ * Value - MethodInfo of existed getter/setter.
+ */
+ public Map<String, TypeInfoCollector.MethodInfo> getUnpairedGettersOrSetters() {
+ if (unpairedGettersOrSetters == null) {
+ unpairedGettersOrSetters = new HashMap<String, TypeInfoCollector.MethodInfo>();
+ }
+ return unpairedGettersOrSetters;
+ }
+
+ /**
+ * Clear Map of unpaired getters and setters.
+ */
+ public void clearUnpairedGettersOrSetters() {
+ getUnpairedGettersOrSetters().clear();
+ }
+
+}
Copied:
trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/core/resolver/ElVarSearcher.java
(from rev 10526,
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/el/ElVarSearcher.java)
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/core/resolver/ElVarSearcher.java
(rev 0)
+++
trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/core/resolver/ElVarSearcher.java 2008-10-01
15:31:11 UTC (rev 10596)
@@ -0,0 +1,284 @@
+ /*******************************************************************************
+ * 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.resolver;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.jface.text.ITextViewer;
+import org.eclipse.wst.sse.core.StructuredModelManager;
+import org.eclipse.wst.sse.core.internal.provisional.IModelManager;
+import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel;
+import org.eclipse.wst.sse.core.internal.provisional.IndexedRegion;
+import org.eclipse.wst.sse.ui.internal.contentassist.ContentAssistUtils;
+import org.eclipse.wst.xml.core.internal.provisional.document.IDOMAttr;
+import org.jboss.tools.common.el.core.Activator;
+import org.jboss.tools.common.el.core.model.ELExpression;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+
+/**
+ * This class helps to find var/value attributes in DOM tree.
+ * @author Alexey Kazakov
+ */
+public class ElVarSearcher {
+
+ private final static String VAR_ATTRIBUTE_NAME = "var";
+ private final static String VALUE_ATTRIBUTE_NAME = "value";
+
+ private IFile file;
+ private ELCompletionEngine 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(IFile file, ELCompletionEngine engine) {
+ 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(ELCompletionEngine engine) {
+ this(null, engine);
+ }
+
+ /**
+ * @param file File where we will look for vars.
+ */
+ public void setFile(IFile file) {
+ this.file = file;
+ }
+
+ /**
+ * @param viewer
+ * @param offset
+ * @return
+ */
+ public static Node getNode(ITextViewer viewer, int offset) {
+ IndexedRegion treeNode = ContentAssistUtils.getNodeAt(viewer, offset);
+ if(treeNode instanceof Node) {
+ return (Node)treeNode;
+ }
+ return null;
+ }
+
+ /**
+ * @param viewer
+ * @param offset
+ * @return
+ */
+
+ public static Node getNode(IFile file, int offset) {
+ IndexedRegion treeNode = getNodeAt(file, offset);
+ if(treeNode instanceof Node) {
+ return (Node)treeNode;
+ }
+ return null;
+ }
+
+ /**
+ * Returns the closest IndexedRegion for the offset and viewer allowing
+ * for differences between viewer offsets and model positions. note: this
+ * method returns an IndexedRegion for read only
+ *
+ * @param file
+ * the file whose document is used to compute the proposals
+ * @param documentOffset
+ * an offset within the document for which completions should
+ * be computed
+ * @return an IndexedRegion
+ */
+
+ public static IndexedRegion getNodeAt(IFile file, int documentOffset) {
+
+ if (file == null)
+ return null;
+
+ IndexedRegion node = null;
+ IModelManager mm = StructuredModelManager.getModelManager();
+ IStructuredModel model = null;
+ if (mm != null) {
+ try {
+ model = mm.getModelForRead(file);
+ } catch (IOException e) {
+ return null;
+ } catch (CoreException e) {
+ return null;
+ }
+ }
+ try {
+ if (model != null) {
+ int lastOffset = documentOffset;
+ node = model.getIndexedRegion(documentOffset);
+ while (node == null && lastOffset >= 0) {
+ lastOffset--;
+ node = model.getIndexedRegion(lastOffset);
+ }
+ }
+ } finally {
+ if (model != null)
+ model.releaseFromRead();
+ }
+ return node;
+ }
+
+ /**
+ * @param node
+ * @return All var/value that can be used in this position and null if can't find
anyone.
+ */
+ public List<Var> findAllVars(ITextViewer viewer, int offset) {
+ Node node = getNode(viewer, offset);
+ if(node!=null) {
+ return findAllVars(node);
+ }
+ return null;
+ }
+
+ /**
+ * @param node
+ * @return All var/value that can be used in this position and null if can't find
anyone.
+ */
+ public List<Var> findAllVars(IFile file, int offset) {
+ Node node = getNode(file, offset);
+ if(node!=null) {
+ return findAllVars(node);
+ }
+ return null;
+ }
+
+ /**
+ * @param node
+ * @return All var/value that can be used in node and null if can't find anyone.
+ */
+ public List<Var> findAllVars(Node node) {
+ ArrayList<Var> vars = null;
+ Node parentNode = node.getParentNode();
+ while(parentNode!=null) {
+ Var var = findVar(parentNode);
+ if(var!=null) {
+ if(vars == null) {
+ vars = new ArrayList<Var>();
+ }
+ vars.add(0, var);
+ }
+ parentNode = parentNode.getParentNode();
+ }
+ return vars;
+ }
+
+ /**
+ * @param node
+ * @return found var/value that can be used in this position and null if can't find
anyone.
+ */
+ public Var findVar(IFile file, int offset) {
+ Node node = getNode(file, offset);
+ if(node!=null) {
+ return findVar(node);
+ }
+ return null;
+ }
+
+ /**
+ * Finds var/value attribute in node
+ * @param node
+ * @param vars
+ * @return found var/value or null
+ */
+ public Var findVar(Node node) {
+ if(node!=null && Node.ELEMENT_NODE == node.getNodeType()) {
+ Element element = (Element)node;
+ String var = element.getAttribute(VAR_ATTRIBUTE_NAME);
+ if(var!=null) {
+ int declOffset = 0;
+ int declLength = 0;
+ Node varAttr = element.getAttributeNode(VAR_ATTRIBUTE_NAME);
+ if (varAttr instanceof IDOMAttr) {
+ int varNameStart = ((IDOMAttr)varAttr).getNameRegionStartOffset();
+ int varNameEnd = ((IDOMAttr)varAttr).getNameRegionEndOffset();
+ declOffset = varNameStart;
+ declLength = varNameEnd - varNameStart;
+ }
+ var = var.trim();
+ if(!"".equals(var)) {
+ String value = element.getAttribute(VALUE_ATTRIBUTE_NAME);
+ if(value!=null) {
+ value = value.trim();
+ Var newVar = new Var(engine.getParserFactory(), var, value, declOffset,
declLength);
+ if(newVar.getElToken()!=null) {
+ return newVar;
+ }
+ }
+ }
+ }
+ }
+
+ return null;
+ }
+
+ /**
+ * Finds var in list of vars that is used in given EL.
+ * @param el EL without brackets.
+ * @param vars
+ * @param initializeNestedVars
+ * @return
+ */
+ public Var findVarForEl(String el, List<Var> vars, boolean initializeNestedVars)
{
+ if(vars!=null) {
+ ArrayList<Var> parentVars = new ArrayList<Var>();
+ for (Var var : vars) {
+ ELExpression token = var.getElToken();
+ if(token!=null && !token.getText().endsWith(".")) {
+ String varName = var.getName();
+ if(el.startsWith(varName)) { //TODO it was el.equals(varName) and did not work.
Why?
+ if(var.getElToken()!=null && initializeNestedVars) {
+ Var parentVar = findVarForEl(var.getElToken().getText(), parentVars, true);
+ if(parentVar!=null) {
+ ELExpression resolvedToken = parentVar.getResolvedElToken();
+ if(resolvedToken==null && parentVar.getElToken()!=null) {
+ try {
+ // Initialize parent vars.
+ engine.resolveELOperand(file, var.getElToken(), true, parentVars, this);
+ resolvedToken = parentVar.getResolvedElToken();
+ } catch (StringIndexOutOfBoundsException e) {
+ Activator.getPluginLog().logError(e);
+ } catch (BadLocationException e) {
+ Activator.getPluginLog().logError(e);
+ }
+ }
+ if(resolvedToken!=null) {
+ String oldText = var.getElToken().getText();
+ String newValue = "#{" + resolvedToken.getText() +
oldText.substring(parentVar.getName().length()) + "}";
+ var.value = newValue;
+ var.elToken = var.parseEl(newValue);
+ }
+ }
+ }
+ return var;
+ }
+ }
+ parentVars.add(var);
+ }
+ }
+ return null;
+ }
+
+}
Copied:
trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/core/resolver/TypeInfoCollector.java
(from rev 10439,
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/util/TypeInfoCollector.java)
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/core/resolver/TypeInfoCollector.java
(rev 0)
+++
trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/core/resolver/TypeInfoCollector.java 2008-10-01
15:31:11 UTC (rev 10596)
@@ -0,0 +1,1236 @@
+/*******************************************************************************
+ * 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
+ *
+ * Contributor:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+
+package org.jboss.tools.common.el.core.resolver;
+
+import java.lang.reflect.Modifier;
+import java.util.ArrayList;
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeSet;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.jdt.core.IField;
+import org.eclipse.jdt.core.IJavaElement;
+import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jdt.core.IMember;
+import org.eclipse.jdt.core.IMethod;
+import org.eclipse.jdt.core.IType;
+import org.eclipse.jdt.core.ITypeHierarchy;
+import org.eclipse.jdt.core.ITypeParameter;
+import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.jdt.core.Signature;
+import org.jboss.tools.common.el.core.Activator;
+import org.jboss.tools.common.model.util.EclipseJavaUtil;
+
+/**
+ * This class helps to collect information of java elements used in Seam EL.
+ * @author Viktor Rubezhny, Alexey Kazakov
+ */
+public class TypeInfoCollector {
+ IType fType;
+ MemberInfo fMember;
+ TypeInfo fTypeInfo;
+ List<MethodInfo> fMethods;
+ List<FieldInfo> fFields;
+
+ private static class ProjectCache {
+ Map<IMember, MemberInfo> memberInfoCacheFalse = new HashMap<IMember,
MemberInfo>();
+ Map<IMember, MemberInfo> memberInfoCacheTrue = new HashMap<IMember,
MemberInfo>();
+ Map<IType, SuperTypeInfo> superTypesCache = new HashMap<IType,
SuperTypeInfo>();
+ }
+
+ private static Caches caches = new Caches();
+
+ private static class Caches {
+ ProjectCache common = new ProjectCache();
+// Map<IProject, ProjectCache> cache = new HashMap<IProject,
ProjectCache>();
+
+ public boolean contains(IProject p) {
+// return p != null && cache.containsKey(p);
+ return true;
+ }
+
+ public void clean(IProject p) {
+// if(contains(p)) {
+// cache.remove(p);
+// }
+ common = new ProjectCache();
+ }
+
+ public ProjectCache get(IProject p) {
+ if(p == null || !p.isAccessible()) return null;
+ return common;
+// ProjectCache c = cache.get(p);
+// if(c == null) {
+// c = new ProjectCache();
+// cache.put(p, c);
+// }
+// return c;
+ }
+
+ public ProjectCache get(IJavaElement element) {
+ if(element == null) {
+ return null;
+ }
+ IJavaProject jp = element.getJavaProject();
+ IProject p = jp == null ? null : jp.getProject();
+ return get(p);
+ }
+ }
+
+ public static class Type {
+ private String fName;
+ private String fQualifiedName;
+ private Type[] fParameters;
+ private IType fSource;
+ private String fSignature;
+ private boolean fIsArray;
+ private Type fTypeOfArrayElement;
+ private String fQualifiedTypeNameOfArrayElement;
+
+ private Type() {
+ }
+
+ public static Type valueOf(String name) {
+ Type instance = new Type();
+ instance.setName(name);
+ instance.setParameters(new Type[0]);
+ return instance;
+ }
+
+ public Type(String signature, IType source) {
+ if(signature!=null) {
+ String erasureSignature = Signature.getTypeErasure(signature);
+ String typeOfArraySiganture = Signature.getElementType(erasureSignature);
+ fName = String.valueOf(Signature.toString(erasureSignature));
+ if(!erasureSignature.equals(typeOfArraySiganture)) {
+ // this is an array
+ fIsArray = true;
+ fTypeOfArrayElement = new Type(typeOfArraySiganture, source);
+ }
+ String[] signaturesOfParametersOfType = Signature.getTypeArguments(signature);
+ fParameters = new Type[signaturesOfParametersOfType.length];
+ for (int i = 0; i < signaturesOfParametersOfType.length; i++) {
+ fParameters[i] = new Type(signaturesOfParametersOfType[i], source);
+ }
+ } else {
+ fName = source.getFullyQualifiedName();
+ setParameters(new Type[0]);
+ }
+ fSource = source;
+ }
+
+ public void initializeParameters(Map<String, Type> parameters) {
+ Type type = parameters.get(fName);
+ if(type!=null) {
+ fName = type.getName();
+ fParameters = type.getParameters();
+ fSource = type.getSource();
+ fIsArray = type.isArray();
+ fTypeOfArrayElement = type.getTypeOfArrayElement();
+ }
+ for (int i = 0; i < fParameters.length; i++) {
+ fParameters[i].initializeParameters(parameters);
+ }
+ }
+
+ public Type getParameter(int index) {
+ if(fParameters.length>index) {
+ return fParameters[index];
+ }
+ return null;
+ }
+
+ public String getQualifiedTypeNameOfArrayElement() {
+ if(fQualifiedTypeNameOfArrayElement==null && fSource!=null) {
+ fQualifiedTypeNameOfArrayElement = EclipseJavaUtil.resolveType(fSource,
fTypeOfArrayElement.getName());
+ }
+ return fQualifiedTypeNameOfArrayElement;
+ }
+
+ public String getQualifiedName() {
+ if(fQualifiedName == null && fSource!=null) {
+ fQualifiedName = EclipseJavaUtil.resolveType(fSource, fName);
+ }
+ return fQualifiedName;
+ }
+
+ public boolean isArray() {
+ return fIsArray;
+ }
+
+ public void setArray(boolean array) {
+ fIsArray = array;
+ }
+
+ public Type getTypeOfArrayElement() {
+ return fTypeOfArrayElement;
+ }
+
+ public void setTypeOfArrayElement(Type typeOfArrayElement) {
+ fTypeOfArrayElement = typeOfArrayElement;
+ }
+
+ public String getName() {
+ return fName;
+ }
+
+ public void setName(String name) {
+ fName = name;
+ }
+
+ public Type[] getParameters() {
+ return fParameters;
+ }
+
+ public void setParameters(Type[] parameters) {
+ this.fParameters = parameters;
+ }
+
+ public IType getSource() {
+ return fSource;
+ }
+
+ public void setSource(IType source) {
+ this.fSource = source;
+ }
+
+ public String getSignature() {
+ return fSignature;
+ }
+
+ public void setSignature(String signature) {
+ this.fSignature = signature;
+ }
+ }
+
+ public abstract static class MemberInfo {
+ private String fDeclaringTypeQualifiedName;
+ private String fName;
+ private int fModifiers;
+ private IType fSourceType;
+ private MemberInfo fParentMember;
+ private IType fMemberType;
+ private boolean isDataModel;
+ private Type fType;
+
+ protected MemberInfo (
+ IType sourceType,
+ String declaringTypeQualifiedName, String name, int modifiers, MemberInfo
parentMember, boolean dataModel, Type type) {
+ setSourceType(sourceType);
+ setDeclaringTypeQualifiedName(declaringTypeQualifiedName);
+ setName(name);
+ setModifiers(modifiers);
+ setParentMember(parentMember);
+ setDataModel(dataModel);
+ setType(type);
+ }
+
+ abstract void initializeParameters();
+
+ protected void setType(Type type) {
+ fType = type;
+ }
+
+ public Type getType() {
+ return fType;
+ }
+
+ public void setSourceType(IType sourceType) {
+ fSourceType = sourceType;
+ }
+
+ public IType getSourceType() {
+ return fSourceType;
+ }
+
+ protected void setName (String name) {
+ this.fName = name;
+ }
+
+ public String getName() {
+ return fName;
+ }
+
+ protected void setDeclaringTypeQualifiedName(String declaringTypeQualifiedName) {
+ this.fDeclaringTypeQualifiedName = declaringTypeQualifiedName;
+ }
+
+ public String getDeclaringTypeQualifiedName() {
+ return fDeclaringTypeQualifiedName;
+ }
+
+ protected void setModifiers (int modifiers) {
+ this.fModifiers = modifiers;
+ }
+
+ public int getModifiers() {
+ return fModifiers;
+ }
+
+ public boolean isPublic() {
+ return Modifier.isPublic(fModifiers);
+ }
+
+ public boolean isStatic() {
+ return Modifier.isStatic(fModifiers);
+ }
+
+ public boolean isJavaLangObject() {
+ return "java.lang.Object".equals(getDeclaringTypeQualifiedName());
+ }
+
+ public MemberInfo getParentMember() {
+ return fParentMember;
+ }
+
+ protected void setParentMember(MemberInfo parentMember) {
+ fParentMember = parentMember;
+ }
+
+ public IType getMemberType() {
+ if(fMemberType==null) {
+ initializeParameters();
+ try {
+ if(isDataModel() && getType().isArray()) {
+ fMemberType =
getSourceType().getJavaProject().findType(getType().getQualifiedTypeNameOfArrayElement());
+ } else if(getType().getQualifiedName()!=null) {
+ fMemberType =
getSourceType().getJavaProject().findType(getType().getQualifiedName());
+ }
+ } catch (JavaModelException e) {
+ Activator.getPluginLog().logError(e);
+ }
+ }
+ return fMemberType;
+ }
+
+ public boolean isDataModel() {
+ return isDataModel;
+ }
+
+ protected void setDataModel(boolean isDataModel) {
+ this.isDataModel = isDataModel;
+ }
+
+ public TypeInfoCollector getTypeCollector() {
+ // The rev. 7651 results in a deadlock, typeInfo is not stored anymore
+ // The rev. 7623 results in a deadlock, so, it's rolled back
+ // >>> Fix for JBIDE-2090
+ return new TypeInfoCollector(this);
+ // <<< Fix for JBIDE-2090
+ }
+
+ abstract public IJavaElement getJavaElement();
+ }
+
+ public static class TypeInfo extends MemberInfo {
+ private IType fType;
+ private TypeInfo superType;
+ private Map<String, Type> params = new HashMap<String, Type>();
+
+ public TypeInfo(IType type, MemberInfo parentMember, boolean dataModel) throws
JavaModelException {
+ super(type.getDeclaringType(),
+ (type.getDeclaringType() == null ? null :
type.getDeclaringType().getFullyQualifiedName()),
+ type.getFullyQualifiedName(),
+ type.getFlags(),
+ parentMember,
+ dataModel,
+ Type.valueOf(type.getFullyQualifiedName()));
+ this.fType = type;
+ }
+
+ public Type getParameterType(String name) {
+ return params.get(name);
+ }
+
+ @Override
+ public IType getMemberType() {
+ return fType;
+ }
+
+ @Override
+ public IJavaElement getJavaElement() {
+ return fType;
+ }
+
+ /* (non-Javadoc)
+ * @see
org.jboss.tools.common.model.util.TypeInfoCollector.MemberInfo#initializeParameters()
+ */
+ @Override
+ void initializeParameters() {
+ try {
+ MemberInfo parent = getParentMember();
+ if(parent!=null && parent instanceof TypeMemberInfo) {
+ ITypeParameter[] parameters = fType.getTypeParameters();
+ for (int i = 0; i < parameters.length; i++) {
+ Type type = parent.getType().getParameter(i);
+ if(type!=null) {
+ params.put(parameters[i].getElementName(), type);
+ }
+ }
+ }
+ if(superType!=null) {
+ superType.initializeParameters(this);
+ }
+ } catch (JavaModelException e) {
+ Activator.getPluginLog().logError(e);
+ }
+ }
+
+ private void initializeParameters(TypeInfo inheritedType) throws JavaModelException {
+ ITypeParameter[] parameters = fType.getTypeParameters();
+ String signature = inheritedType.fType.getSuperclassTypeSignature();
+ Type classType = new Type(signature, inheritedType.fType);
+ for (int i = 0; i < parameters.length; i++) {
+ Type paramType = classType.getParameter(i);
+ if(paramType!=null) {
+ Type resolvedType = inheritedType.getParameterType(paramType.getName());
+ if(resolvedType!=null) {
+ paramType = resolvedType;
+ }
+ params.put(parameters[i].getElementName(), paramType);
+ }
+ }
+ if(superType!=null) {
+ superType.initializeParameters(this);
+ }
+ }
+
+ public TypeInfo getSuperType() {
+ return superType;
+ }
+
+ public void setSuperType(TypeInfo superType) {
+ this.superType = superType;
+ }
+ }
+
+ public abstract static class TypeMemberInfo extends MemberInfo {
+ private String[] fParametersNamesOfDeclaringType;
+ private TypeInfo declaratedType;
+
+ /**
+ * @param sourceType
+ * @param declaringTypeQualifiedName
+ * @param name
+ * @param modifiers
+ * @param parentMember
+ * @param dataModel
+ * @param type
+ */
+ protected TypeMemberInfo(IType sourceType,
+ String declaringTypeQualifiedName, String name, int modifiers,
+ TypeInfo parentMember, TypeInfo declaratedType, boolean dataModel, Type type) {
+ super(sourceType, declaringTypeQualifiedName, name, modifiers, parentMember,
+ dataModel, type);
+ this.declaratedType = declaratedType;
+ }
+
+ public String[] getParametersNamesOfDeclaringType() {
+ return fParametersNamesOfDeclaringType;
+ }
+
+ void setParametersNamesOfDeclaringType(
+ String[] parametersNamesOfDeclaringType) {
+ fParametersNamesOfDeclaringType = parametersNamesOfDeclaringType;
+ }
+
+ protected void initializeParameters() {
+ if(fParametersNamesOfDeclaringType!=null &&
fParametersNamesOfDeclaringType.length>0 && getParentMember()!=null) {
+ Map<String, Type> parametersOfDeclaringType = new HashMap<String,
Type>();
+ TypeInfo parentTypeInfo = (TypeInfo)getParentMember();
+ parentTypeInfo.initializeParameters();
+ for (int i = 0; i < fParametersNamesOfDeclaringType.length; i++) {
+ String parameterName =
getParameterNameFromType(fParametersNamesOfDeclaringType[i]);
+ Type paramType = declaratedType.getParameterType(parameterName);
+ if(paramType!=null) {
+ parametersOfDeclaringType.put(parameterName, paramType);
+ }
+ }
+ getType().initializeParameters(parametersOfDeclaringType);
+ }
+ }
+
+ public TypeInfo getDeclaratedType() {
+ return declaratedType;
+ }
+
+ protected void setDeclaratedType(TypeInfo declaratedType) {
+ this.declaratedType = declaratedType;
+ }
+ }
+
+ public static class FieldInfo extends TypeMemberInfo {
+ private IJavaElement fJavaElement;
+
+ public FieldInfo(IField field, TypeInfo parentMember, TypeInfo declaratedType, boolean
dataModel) throws JavaModelException {
+ super(field.getDeclaringType(),
+ (field.getDeclaringType() == null ? null :
field.getDeclaringType().getFullyQualifiedName()),
+ field.getElementName(),
+ field.getFlags(),
+ parentMember,
+ declaratedType,
+ dataModel,
+ new Type(field.getTypeSignature(),
+ field.getDeclaringType()));
+
+ setParametersNamesOfDeclaringType(getTypeErasureFromSignatureArray(field.getDeclaringType().getTypeParameterSignatures()));
+ }
+
+ public IJavaElement getJavaElement () {
+ if(fJavaElement == null) {
+ try {
+ if(getDeclaringTypeQualifiedName()==null) {
+ return null;
+ }
+ IType declType =
getSourceType().getJavaProject().findType(getDeclaringTypeQualifiedName());
+ fJavaElement = (declType == null ? null : declType.getField(getName()));
+ } catch (JavaModelException e) {
+ Activator.getPluginLog().logError(e);
+ }
+ }
+ return fJavaElement;
+ }
+ }
+
+ public static class MethodInfo extends TypeMemberInfo {
+ private String[] fParameterTypeNames;
+ private String[] fParameterTypeQualifiedNames;
+ private String[] fParameterNames;
+ private IJavaElement fJavaElement;
+
+ public MethodInfo(IType sourceType, String declaringTypeQualifiedName, String name,
+ int modifiers, String[] parameterTypeQualifiedNames,
+ String[] parameterNames,
+ String returnTypeQualifiedName,
+ TypeInfo parentMember,
+ TypeInfo declaratedType,
+ boolean dataModel) {
+ super(sourceType, declaringTypeQualifiedName, name, modifiers, parentMember,
declaratedType, dataModel, Type.valueOf(name));
+ setParameterTypeNames(parameterTypeQualifiedNames);
+ setParameterNames(parameterNames);
+ }
+
+ public MethodInfo(IMethod method, TypeInfo parentMember, TypeInfo declaratedType,
boolean dataModel) throws JavaModelException {
+ super(method.getDeclaringType(),
+ (method.getDeclaringType() == null ? null :
method.getDeclaringType().getFullyQualifiedName()),
+ method.getElementName(),
+ method.getFlags(),
+ parentMember,
+ declaratedType,
+ dataModel,
+ new Type(method.getReturnType(),
+ method.getDeclaringType()));
+
+ setParameterNames(method.getParameterNames());
+ setParameterTypeNames(resolveSignatures(method.getDeclaringType(),
method.getParameterTypes()));
+ setParametersNamesOfDeclaringType(getTypeErasureFromSignatureArray(method.getDeclaringType().getTypeParameterSignatures()));
+ }
+
+ protected void setParameterTypeNames(String[] parameterTypeNames) {
+ fParameterTypeNames = (parameterTypeNames == null ?
+ new String[0] : parameterTypeNames);
+ }
+
+ public String[] getParameterTypeQualifiedNames() {
+ if(fParameterTypeQualifiedNames==null) {
+ fParameterTypeQualifiedNames = new String[fParameterTypeNames.length];
+ for (int i = 0; i < fParameterTypeQualifiedNames.length; i++) {
+ fParameterTypeQualifiedNames[i] = EclipseJavaUtil.resolveType(getSourceType(),
fParameterTypeNames[i]);
+ }
+ }
+ return fParameterTypeQualifiedNames;
+ }
+
+ public String[] getParameterTypeNames() {
+ return fParameterTypeNames;
+ }
+
+ protected void setParameterNames(String[] parameterNames) {
+ fParameterNames = (parameterNames == null ?
+ new String[0] : parameterNames);
+ }
+
+ public String[] getParameterNames() {
+ return fParameterNames;
+ }
+
+ public int getNumberOfParameters() {
+ return (getParameterNames() == null ? 0 : getParameterNames().length);
+ }
+
+ public IType getReturnType() {
+ return getMemberType();
+ }
+
+ public boolean isConstructor () {
+ return getDeclaringTypeQualifiedName()!=null &&
getDeclaringTypeQualifiedName().equals(getName());
+ }
+
+ public boolean isGetter() {
+ if (null == getType()) {
+ return false;
+ }
+
+ return (((getName().startsWith("get") &&
!getName().equals("get")) || getName().startsWith("is")) &&
getNumberOfParameters() == 0);
+ }
+
+ public boolean isSetter() {
+ return ((getName().startsWith("set") &&
!getName().equals("set")) && getNumberOfParameters() == 1);
+ }
+
+ public List<String> getAsPresentedStrings() {
+ List<String> list = new ArrayList<String>(2);
+ StringBuffer name = new StringBuffer(getName());
+
+ // Add method as 'foo'
+ list.add(name.toString());
+
+ // Add method as 'foo(param1,param2)'
+ name.append('(');
+ String[] mParams = getParameterNames();
+ for (int j = 0; mParams != null && j < mParams.length; j++) {
+ if (j > 0) name.append(", "); //$NON-NLS-1$
+ name.append(mParams[j]);
+ }
+ name.append(')');
+ list.add(name.toString());
+ return list;
+ }
+
+ @Override
+ public IJavaElement getJavaElement () {
+ if(fJavaElement == null) {
+ try {
+ IType declType =
getSourceType().getJavaProject().findType(getDeclaringTypeQualifiedName());
+ if(declType==null) {
+ return null;
+ }
+ IMethod[] allMethods = declType.getMethods();
+
+ // filter methods by name
+ List<IMethod> methods = new ArrayList<IMethod>();
+ for (int i = 0; allMethods != null && i < allMethods.length; i++) {
+ if (allMethods[i].getElementName().equals(getName())) {
+ methods.add(allMethods[i]);
+ }
+ }
+ if (!methods.isEmpty()) {
+ if (methods.size() == 1) {
+ fJavaElement = methods.get(0);
+ } else {
+ // filter methods by number of parameters
+ List<IMethod> filteredMethods = new ArrayList<IMethod>();
+ for (IMethod method : methods) {
+ if (method.getNumberOfParameters() == getNumberOfParameters()) {
+ filteredMethods.add(method);
+ }
+ }
+ if (!filteredMethods.isEmpty()) {
+ if (filteredMethods.size() == 1) {
+ fJavaElement = filteredMethods.get(0);
+ } else {
+ methods = filteredMethods;
+
+ // filter methods by parameter types
+ for(IMethod method : methods) {
+ String[] methodParameterTypes =
+ resolveSignatures(method.getDeclaringType(),
+ method.getParameterTypes());
+ String[] parameterTypes = getParameterTypeQualifiedNames();
+
+ boolean equal = true;
+ for (int i = 0; parameterTypes != null && i < parameterTypes.length;
i++) {
+ // simple types must be equal, but complex types may not
+ if (!parameterTypes[i].equals(methodParameterTypes[i])) {
+ // sure - it's Complex Type
+ if (! (parameterTypes[i].indexOf('.') != -1)
+ && (methodParameterTypes[i].indexOf('.') == -1)) {
+ equal = false;
+ break;
+ }
+ }
+ }
+ if (equal) {
+ fJavaElement = method;
+ }
+ }
+ }
+ }
+ }
+ }
+ } catch (JavaModelException e) {
+ Activator.getPluginLog().logError(e);
+ }
+ }
+ return fJavaElement;
+ }
+ }
+
+ public TypeInfoCollector(MemberInfo member) {
+ this.fMember = member;
+ this.fType = member.getMemberType();
+ collectInfo();
+ }
+
+ public IType getType() {
+ return this.fType;
+ }
+
+ public void collectInfo() {
+ if (fMethods == null) {
+ fMethods = new ArrayList<MethodInfo>();
+ } else {
+ fMethods.clear();
+ }
+
+ if (fFields == null) {
+ fFields = new ArrayList<FieldInfo>();
+ } else {
+ fFields.clear();
+ }
+
+ if (fType == null) {
+ return;
+ }
+ try {
+ IType binType = fType;
+ MemberInfo originalParent = fMember;
+ if(fMember instanceof TypeInfo) {
+ fTypeInfo = (TypeInfo)fMember;
+ } else {
+ fTypeInfo = new TypeInfo(binType, fMember, fMember.isDataModel());
+ }
+ TypeInfo parent = fTypeInfo;
+ while (binType != null) {
+ IMethod[] binMethods = binType.getMethods();
+ for (int i = 0; binMethods != null && i < binMethods.length; i++) {
+ if (binMethods[i].isConstructor()) {
+ continue;
+ }
+ fMethods.add(new MethodInfo(binMethods[i], fTypeInfo, parent, false));
+ }
+ binType = getSuperclass(binType);
+ if(binType!=null) {
+ TypeInfo superType = new TypeInfo(binType, originalParent, parent.isDataModel());
+ parent.setSuperType(superType);
+ parent = superType;
+ }
+ }
+
+ // This inserts here methods "public int size()" and "public boolean
isEmpty()" for javax.faces.model.DataModel
+ // as requested by Gavin in JBIDE-1256
+ if(isDataModelObject(fType)) {
+ addInfoForDataModelObject();
+ }
+ // This inserts here methods "public int getRowCount()" for @DataModel
variables.
+ if(fMember.isDataModel) {
+ addInfoForDataModelVariable();
+ }
+ } catch (JavaModelException e) {
+ Activator.getPluginLog().logError(e);
+ }
+ }
+
+ boolean isDataModelObject(IType type) throws JavaModelException {
+ return isInstanceofType(type, "javax.faces.model.DataModel");
+ }
+
+ public static boolean isResourceBundle(IType type) {
+ try {
+ return isInstanceofType(type, "java.util.ResourceBundle");
+ } catch (JavaModelException e) {
+ return false;
+ }
+ }
+
+ public static boolean isNotParameterizedCollection(TypeInfoCollector.MemberInfo mbr) {
+ try {
+ if(mbr.getType().getParameters()!=null &&
mbr.getType().getParameters().length>0) {
+ return false;
+ }
+ IType type = mbr.getMemberType();
+ if(type!=null) {
+ return isInstanceofType(type, "java.util.Map") || isInstanceofType(type,
"java.util.Collection");
+ }
+ return false;
+ } catch (JavaModelException e) {
+ return false;
+ }
+ }
+
+ public static class SuperTypeInfo {
+ IType type;
+ Set<String> names = new HashSet<String>();
+ IType[] superTypes = new IType[0];
+
+ SuperTypeInfo(IType type) throws JavaModelException {
+ this.type = type;
+ ProjectCache cache = caches.get(type);
+ if(cache != null) {
+ cache.superTypesCache.put(type, this);
+ }
+ ITypeHierarchy typeHierarchy = type.newSupertypeHierarchy(new NullProgressMonitor());
+ superTypes = typeHierarchy == null ? null : typeHierarchy.getAllSupertypes(type);
+ if(superTypes != null) for (int i = 0; i < superTypes.length; i++) {
+ names.add(superTypes[i].getFullyQualifiedName());
+ }
+ if(superTypes == null) superTypes = new IType[0];
+ }
+
+ public Set<String> getNames() {
+ return names;
+ }
+
+ public IType[] getSuperTypes() {
+ return superTypes;
+ }
+ }
+
+ public static SuperTypeInfo getSuperTypes(IType type) throws JavaModelException {
+ if(type == null) return null;
+ ProjectCache cache = caches.get(type);
+ SuperTypeInfo ts = (cache != null) ? cache.superTypesCache.get(type) : null;
+ if(ts == null) {
+ ts = new SuperTypeInfo(type);
+ }
+ return ts;
+ }
+
+ public static boolean isInstanceofType(IType type, String qualifiedTypeName) throws
JavaModelException {
+ if (qualifiedTypeName == null || type == null) return false;
+ boolean isInstanceofType = qualifiedTypeName.equals(type.getFullyQualifiedName());
+ if (!isInstanceofType) {
+ SuperTypeInfo ts = getSuperTypes(type);
+ if(ts != null && ts.getNames().contains(qualifiedTypeName)) {
+ return true;
+ }
+ return false;
+ }
+ return true;
+ }
+
+ void addInfoForDataModelVariable() {
+ fMethods.add(new MethodInfo(fType,
+ fType.getFullyQualifiedName(),
+ "getRowCount", Modifier.PUBLIC,
+ new String[0],
+ new String[0],
+ "int",
+ fTypeInfo,
+ fTypeInfo,
+ false));
+ }
+
+ void addInfoForDataModelObject() {
+ fMethods.add(new MethodInfo(fType,
+ fType.getFullyQualifiedName(),
+ "size", Modifier.PUBLIC,
+ new String[0],
+ new String[0],
+ "int",
+ fTypeInfo,
+ fTypeInfo,
+ false));
+ fMethods.add(new MethodInfo(fType,
+ fType.getFullyQualifiedName(),
+ "isEmpty", Modifier.PUBLIC,
+ new String[0],
+ new String[0],
+ "boolean",
+ fTypeInfo,
+ fTypeInfo,
+ false));
+ }
+
+ private static IType getSuperclass(IType type) throws JavaModelException {
+ String superclassName = type.getSuperclassName();
+ if(superclassName!=null) {
+ String fullySuperclassName = EclipseJavaUtil.resolveType(type, superclassName);
+ if(fullySuperclassName!=null&&!fullySuperclassName.equals("java.lang.Object"))
{ //$NON-NLS-1$
+ if(fullySuperclassName.equals(type.getFullyQualifiedName())) {
+ //FIX JBIDE-1642
+ return null;
+ }
+ IType superType = type.getJavaProject().findType(fullySuperclassName);
+ return superType;
+ }
+ }
+ return null;
+ }
+
+ public MethodInfo[] findMethodInfos(IMethod iMethod) {
+ List<MethodInfo> methods = new ArrayList<MethodInfo>();
+
+ // filter methods by name
+ for (MethodInfo info : fMethods) {
+ if (info.getName().equals(iMethod.getElementName())) {
+ methods.add(info);
+ }
+ }
+ if (methods.isEmpty())
+ return new MethodInfo[0];
+
+ EclipseJavaUtil.getMemberTypeAsString(iMethod);
+
+ if (methods.size() == 1)
+ return methods.toArray(new MethodInfo[0]);
+
+ // filter methods by number of parameters
+ List<MethodInfo> filteredMethods = new ArrayList<MethodInfo>();
+ for (MethodInfo method : methods) {
+ if (method.getNumberOfParameters() == iMethod.getNumberOfParameters())
+ filteredMethods.add(method);
+ }
+ if (filteredMethods.isEmpty())
+ return new MethodInfo[0];
+ if (filteredMethods.size() == 1)
+ return filteredMethods.toArray(new MethodInfo[0]);
+
+ methods = filteredMethods;
+
+ // filter methods by parameter types
+ filteredMethods = new ArrayList<MethodInfo>();
+ for(MethodInfo method : methods) {
+ String[] methodParameterTypes =
+ resolveSignatures(iMethod.getDeclaringType(),
+ iMethod.getParameterTypes());
+ String[] parameterTypes = method.getParameterTypeQualifiedNames();
+
+ boolean equal = true;
+ for (int i = 0; equal && parameterTypes != null && i <
parameterTypes.length; i++) {
+ // simple types must be equal, but complex types may not
+ if (!parameterTypes[i].equals(methodParameterTypes[i])) {
+ // sure - it's Complex Type
+ if ((parameterTypes[i].indexOf('.') != -1)
+ && (methodParameterTypes[i].indexOf('.') == -1)) {
+ equal = false;
+ }
+ }
+ }
+ if (equal) {
+ filteredMethods.add(method);
+ }
+ }
+ return filteredMethods.toArray(new MethodInfo[0]);
+ }
+
+ /**
+ * Returns the methods for the type specified
+ *
+ * @return
+ */
+ public List<MemberInfo> getMethods() {
+ List<MemberInfo> methods = new ArrayList<MemberInfo>();
+ for (MethodInfo info : fMethods) {
+ if (info.isPublic() && !info.isConstructor()
+ && !info.isStatic() && !info.isJavaLangObject()
+ && !info.isGetter() && !info.isSetter())
+ methods.add(info);
+ }
+ return methods;
+ }
+
+ /**
+ * String presentation of member
+ * @author Alexey Kazakov
+ */
+ public static class MemberPresentation {
+ private String presentation;
+ private MemberInfo member;
+
+ public MemberPresentation(String presentation, MemberInfo member) {
+ super();
+ this.presentation = presentation;
+ this.member = member;
+ }
+
+ public String getPresentation() {
+ return presentation;
+ }
+
+ public MemberInfo getMember() {
+ return member;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if(obj!=null && obj instanceof MemberPresentation) {
+ return presentation.equals(((MemberPresentation)obj).getPresentation());
+ }
+ return false;
+ }
+
+ @Override
+ public int hashCode() {
+ return presentation.hashCode();
+ }
+
+ @Override
+ public String toString() {
+ return presentation;
+ }
+ }
+
+ private static class MemberPresentationComparator implements
Comparator<MemberPresentation> {
+ /* (non-Javadoc)
+ * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
+ */
+ public int compare(MemberPresentation m1, MemberPresentation m2) {
+ return m1.getPresentation().compareTo(m2.getPresentation());
+ }
+ }
+
+ public final static MemberPresentationComparator MEMBER_PRESENTATION_COMPARATOR = new
MemberPresentationComparator();
+
+ /**
+ * Returns the method presentation strings for the type specified
+ * @return
+ */
+ public Set<String> getMethodPresentationStrings() {
+ Set<MemberPresentation> set = getMethodPresentations();
+ Set<String> result = new HashSet<String>();
+ for (MemberPresentation presentation : set) {
+ result.add(presentation.getPresentation());
+ }
+ return result;
+ }
+
+ /**
+ * Returns the method presentations for the type specified
+ * @return
+ */
+ public Set<MemberPresentation> getMethodPresentations() {
+ Set<MemberPresentation> methods = new
TreeSet<MemberPresentation>(MEMBER_PRESENTATION_COMPARATOR);
+ List<MemberInfo> mthds = getMethods();
+ for (MemberInfo info : mthds) {
+ if (!(info instanceof MethodInfo))
+ continue;
+
+ MethodInfo method = (MethodInfo)info;
+
+ StringBuffer name = new StringBuffer(method.getName());
+
+ // Add method as 'foo'
+ methods.add(new MemberPresentation(name.toString(), method));
+
+ // Add method as 'foo(param1,param2)'
+ name.append('(');
+ String[] mParams = method.getParameterNames();
+ for (int j = 0; mParams != null && j < mParams.length; j++) {
+ if (j > 0) name.append(", "); //$NON-NLS-1$
+ name.append(mParams[j]);
+ }
+ name.append(')');
+
+ methods.add(new MemberPresentation(name.toString(), method));
+ }
+ return methods;
+ }
+
+ /**
+ * Returns the properties for the type specified
+ *
+ * @return
+ */
+ public List<MemberInfo> getProperties() {
+ List<MemberInfo> properties = new ArrayList<MemberInfo>();
+ for (MethodInfo info : fMethods) {
+ if (info.isPublic() && !info.isConstructor()
+ && !info.isStatic() && !info.isJavaLangObject()
+ && (info.isGetter() || info.isSetter()))
+ properties.add(info);
+ }
+
+ /*
+ * The following code was excluded due to the following issue:
+ *
+ *
http://jira.jboss.com/jira/browse/JBIDE-1203#action_12385823
+ *
+ *
+ for (FieldInfo info : fFields) {
+ if (info.isPublic()
+ && !info.isStatic() && !info.isJavaLangObject())
+ properties.add(info);
+ }
+ */
+
+ return properties;
+ }
+
+ /**
+ * Returns the property presentations for the type specified
+ *
+ * @return
+ */
+ public Set<MemberPresentation> getPropertyPresentations() {
+ return getPropertyPresentations(null);
+ }
+
+ /**
+ * Returns the property presentation strings for the type specified
+ *
+ * @return
+ */
+ public Set<String> getPropertyPresentationStrings() {
+ return getPropertyPresentationStrings(null);
+ }
+
+ /**
+ * Returns the property presentation strings for the type specified
+ *
+ * @param unpairedGettersOrSetters - map of unpaired getters or setters of type's
properties. 'key' is property name.
+ * @return
+ */
+ public Set<String> getPropertyPresentationStrings(Map<String, MethodInfo>
unpairedGettersOrSetters) {
+ Set<MemberPresentation> set =
getPropertyPresentations(unpairedGettersOrSetters);
+ Set<String> result = new HashSet<String>();
+ for (MemberPresentation presentation : set) {
+ result.add(presentation.getPresentation());
+ }
+ return result;
+ }
+
+ /**
+ * Returns the property presentations for the type specified
+ *
+ * @param unpairedGettersOrSetters - map of unpaired getters or setters of type's
properties. 'key' is property name.
+ * @return
+ */
+ public Set<MemberPresentation> getPropertyPresentations(Map<String,
MethodInfo> unpairedGettersOrSetters) {
+ Set<MemberPresentation> properties = new
TreeSet<MemberPresentation>(MEMBER_PRESENTATION_COMPARATOR);
+ List<MemberInfo> props = getProperties();
+ HashMap<String, MethodInfo> getters = new HashMap<String, MethodInfo>();
+ HashMap<String, MethodInfo> setters = new HashMap<String, MethodInfo>();
+ for (MemberInfo info : props) {
+ if (info instanceof MethodInfo) {
+ MethodInfo m = (MethodInfo)info;
+
+ if (m.isGetter() || m.isSetter()) {
+ StringBuffer name = new StringBuffer(m.getName());
+ if(m.getName().startsWith("i")) { //$NON-NLS-1$
+ name.delete(0, 2);
+ } else {
+ name.delete(0, 3);
+ }
+ if(name.length()<2 || Character.isLowerCase(name.charAt(1))) {
+ name.setCharAt(0, Character.toLowerCase(name.charAt(0)));
+ }
+ String propertyName = name.toString();
+ MemberPresentation pr = new MemberPresentation(propertyName, m);
+ if(!properties.contains(pr)) {
+ properties.add(pr);
+ }
+ if(unpairedGettersOrSetters!=null) {
+ MethodInfo previousGetter = getters.get(propertyName);
+ MethodInfo previousSetter = setters.get(propertyName);
+ if((previousGetter!=null && m.isSetter())||(previousSetter!=null &&
m.isGetter())) {
+ // We have both Getter and Setter
+ unpairedGettersOrSetters.remove(propertyName);
+ } else if(m.isSetter()) {
+ setters.put(propertyName, m);
+ unpairedGettersOrSetters.put(propertyName, m);
+ } else if(m.isGetter()) {
+ getters.put(propertyName, m);
+ unpairedGettersOrSetters.put(propertyName, m);
+ }
+ }
+ }
+ } else {
+ properties.add(new MemberPresentation(info.getName(), info));
+ }
+ }
+ return properties;
+ }
+
+ public static void cleanCache() {
+ caches = new Caches();
+ }
+
+ public static MemberInfo createMemberInfo(IMember member, boolean dataModel) {
+ ProjectCache pcache = caches.get(member);
+
+ Map<IMember, MemberInfo> cache = null;
+ if(pcache != null) {
+ cache = dataModel ? pcache.memberInfoCacheTrue : pcache.memberInfoCacheFalse;
+ }
+ MemberInfo result = cache == null ? null : cache.get(member);
+ if(result != null) return result;
+ try {
+ if (member instanceof IType) {
+ result = new TypeInfo((IType)member, null, dataModel);
+ } else if (member instanceof IField) {
+ IField field = (IField)member;
+ TypeInfo declaringType = new TypeInfo(field.getDeclaringType(), null, dataModel);
+ result = new FieldInfo(field, declaringType, declaringType, dataModel);
+ } else if (member instanceof IMethod) {
+ IMethod method = (IMethod)member;
+ TypeInfo declaringType = new TypeInfo(method.getDeclaringType(), null, dataModel);
+ result = new MethodInfo(method, declaringType, declaringType, dataModel);
+ }
+ } catch (JavaModelException e) {
+ Activator.getPluginLog().logError(e);
+ }
+ if(result != null) {
+ cache.put(member, result);
+ }
+
+ return result;
+ }
+
+ public static MemberInfo createMemberInfo(IMember member) {
+ return createMemberInfo(member, false);
+ }
+
+ static String[] resolveSignatures (IType type, String[] signatures) {
+ if (signatures == null || signatures.length == 0)
+ return new String[0];
+
+ String[] resolvedSignatures = new String[signatures.length];
+ for (int i = 0; i < signatures.length; i++) {
+ resolvedSignatures[i] = EclipseJavaUtil.resolveTypeAsString(type, signatures[i]);
+ }
+ return resolvedSignatures;
+ }
+
+ static String[] convertToStringArray(char[][] names) {
+ if (names == null || names.length == 0)
+ return new String[0];
+ String[] sNames = new String[names.length];
+ for (int i = 0; i < sNames.length; i++) {
+ sNames[i] = String.valueOf(names[i]);
+ }
+ return sNames;
+ }
+
+ static String[] getTypeErasureFromSignatureArray(String[] signatures) {
+ if (signatures == null || signatures.length == 0)
+ return new String[0];
+ String[] result = new String[signatures.length];
+ for (int i = 0; i < signatures.length; i++) {
+ result[i] = Signature.getTypeErasure(signatures[i]);
+ }
+ return result;
+ }
+
+ static String getParameterNameFromType(String typeSignatures) {
+ if(typeSignatures==null) {
+ return null;
+ }
+ return Signature.getTypeVariable(typeSignatures);
+ }
+}
\ No newline at end of file
Copied:
trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/core/resolver/Var.java
(from rev 10454,
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/el/Var.java)
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/core/resolver/Var.java
(rev 0)
+++
trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/core/resolver/Var.java 2008-10-01
15:31:11 UTC (rev 10596)
@@ -0,0 +1,149 @@
+/*******************************************************************************
+ * 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.resolver;
+
+import java.util.List;
+
+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.ELModel;
+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.ELParserUtil;
+
+/**
+ * Represents "var"/"value" attributes.
+ * @author Alexey Kazakov
+ */
+public class Var {
+ String name;
+ String value;
+ ELExpression elToken;
+ String resolvedValue;
+ ELExpression resolvedElToken;
+ int declOffset;
+ int declLength;
+ ELParserFactory factory;
+
+ /**
+ * Constructor
+ * @param name - value of "var" attribute.
+ * @param value - value of "value" attribute.
+ */
+ public Var(ELParserFactory factory, String name, String value, int declOffset, int
declLength) {
+ this.factory = factory;
+ this.name = name;
+ this.value = value;
+ elToken = parseEl(value);
+ this.declOffset = declOffset;
+ this.declLength = declLength;
+ }
+
+ ELExpression parseEl(String el) {
+ if(el.length()>3 && el.startsWith("#{") &&
el.endsWith("}")) {
+ ELParser parser = factory.createParser();
+ ELModel model = parser.parse(el);
+ if(model == null || parser.getSyntaxErrors().size() > 0) return null;
+ List<ELInstance> is = model.getInstances();
+ if(is.size() == 0) return null;
+ return is.get(0).getExpression();
+ }
+ return null;
+ }
+
+ /**
+ * Sets value to new resolved EL which we got as result of parsing value.
+ * For example:
+ * <h:datatable value="#{list}" var="item">
+ * <h:dataTable value="#{item.anotherList}" var="innerItem">
+ * ...
+ * </h:dataTable>
+ * </h:dataTable>
+ * Original El is #{item.anotherList}
+ * Resolved El is #{list.iterator().next().anotherList}
+ * It's very useful for nested vars.
+ * @param newEl
+ */
+ public void resolveValue(String newEl) {
+ resolvedValue = newEl;
+ resolvedElToken = parseEl(newEl);
+ }
+
+ /**
+ * @return parsed EL from "value" attribute. Returns null if EL is not valid.
+ */
+ public ELExpression getElToken() {
+ return elToken;
+ }
+
+ /**
+ * @return parsed resolved EL from "value" attribute. May be null.
+ */
+ public ELExpression getResolvedElToken() {
+ return resolvedElToken;
+ }
+
+ /**
+ * @return name of variable.
+ */
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * @return value of variable. It's EL.
+ */
+ public String getValue() {
+ return value;
+ }
+
+ /**
+ * @return resolved value of variable. It's EL. May be null.
+ */
+ public String getResolvedValue() {
+ return resolvedValue;
+ }
+
+ /**
+ * @return offset of the var declaration
+ */
+ public int getDeclarationOffset() {
+ return declOffset;
+ }
+
+ /**
+ * @return length of the var declaration
+ */
+ public int getDeclarationLength() {
+ return declLength;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (obj instanceof Var) {
+ Var compare = (Var)obj;
+ String str = getName();
+ if (str != null) {
+ if (!str.equals(compare.getName()))
+ return false;
+ } else {
+ if (compare.getName() != null)
+ return false;
+ }
+ str = getValue();
+ return (str != null ?
+ str.equals(compare.getValue()) :
+ compare.getValue() == null);
+ }
+ return false;
+ }
+
+}
Modified:
trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/internal/core/model/ELModelImpl.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/internal/core/model/ELModelImpl.java 2008-10-01
15:26:10 UTC (rev 10595)
+++
trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/internal/core/model/ELModelImpl.java 2008-10-01
15:31:11 UTC (rev 10596)
@@ -26,6 +26,7 @@
public class ELModelImpl extends ELObjectImpl implements ELModel {
String source;
List<ELInstance> instances = new ArrayList<ELInstance>();
+ int delta = 0;
public ELModelImpl() {}
@@ -83,4 +84,10 @@
}
+ public void shift(int delta) {
+ this.delta = delta;
+ if(instances.size() > 0) {
+ instances.get(0).getFirstToken().shift(delta);
+ }
+ }
}
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-10-01
15:26:10 UTC (rev 10595)
+++
trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/internal/core/model/ELObjectImpl.java 2008-10-01
15:31:11 UTC (rev 10596)
@@ -49,9 +49,9 @@
public String getText() {
if(getModel() == null) return null;
String source = getModel().getSource();
- int start = firstToken.getStart();
+ int start = firstToken.getStart() - getModel().delta;
LexicalToken lt = (lastToken != null) ? lastToken : firstToken;
- int end = lt.getStart() + lt.getLength();
+ int end = lt.getStart() + lt.getLength() - getModel().delta;
return source.substring(start, end);
}