JBoss Tools SVN: r16122 - in trunk/seam/plugins/org.jboss.tools.seam.core: src/org/jboss/tools/seam/core and 2 other directories.
by jbosstools-commits@lists.jboss.org
Author: scabanovich
Date: 2009-06-22 13:10:32 -0400 (Mon, 22 Jun 2009)
New Revision: 16122
Modified:
trunk/seam/plugins/org.jboss.tools.seam.core/META-INF/MANIFEST.MF
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/core/ISeamContextVariable.java
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/el/SeamELCompletionEngine.java
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/el/SeamExpressionResolver.java
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/validation/SeamELValidator.java
Log:
https://jira.jboss.org/jira/browse/JBIDE-2808
AbstractELCompletionEngine
Modified: trunk/seam/plugins/org.jboss.tools.seam.core/META-INF/MANIFEST.MF
===================================================================
--- trunk/seam/plugins/org.jboss.tools.seam.core/META-INF/MANIFEST.MF 2009-06-22 17:08:10 UTC (rev 16121)
+++ trunk/seam/plugins/org.jboss.tools.seam.core/META-INF/MANIFEST.MF 2009-06-22 17:10:32 UTC (rev 16122)
@@ -34,7 +34,7 @@
org.eclipse.jst.jsf.facesconfig,
org.eclipse.jst.j2ee.core,
org.eclipse.jst.common.frameworks,
- org.jboss.tools.jst.web.kb
+ org.jboss.tools.jst.web.kb;visibility:=reexport
Bundle-Version: 2.0.0
Export-Package:
org.jboss.tools.seam.core,
Modified: trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/core/ISeamContextVariable.java
===================================================================
--- trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/core/ISeamContextVariable.java 2009-06-22 17:08:10 UTC (rev 16121)
+++ trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/core/ISeamContextVariable.java 2009-06-22 17:10:32 UTC (rev 16122)
@@ -10,11 +10,13 @@
******************************************************************************/
package org.jboss.tools.seam.core;
+import org.jboss.tools.jst.web.kb.AbstractELCompletionEngine.IVariable;
+
/**
* Represents Seam Context Variable.
* @author Alexey Kazakov
*/
-public interface ISeamContextVariable extends ISeamDeclaration {
+public interface ISeamContextVariable extends ISeamDeclaration, IVariable {
/**
* Sets name
Modified: trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/el/SeamELCompletionEngine.java
===================================================================
--- trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/el/SeamELCompletionEngine.java 2009-06-22 17:08:10 UTC (rev 16121)
+++ trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/el/SeamELCompletionEngine.java 2009-06-22 17:10:32 UTC (rev 16122)
@@ -33,11 +33,9 @@
import org.eclipse.jface.text.IRegion;
import org.eclipse.jface.text.ITextViewer;
import org.eclipse.swt.graphics.Image;
-import org.jboss.tools.common.el.core.model.ELArgumentInvocation;
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.ELMethodInvocation;
import org.jboss.tools.common.el.core.model.ELModel;
import org.jboss.tools.common.el.core.model.ELObjectType;
import org.jboss.tools.common.el.core.model.ELPropertyInvocation;
@@ -45,9 +43,7 @@
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;
-import org.jboss.tools.common.el.core.parser.LexicalToken;
import org.jboss.tools.common.el.core.resolver.ELCompletionEngine;
-import org.jboss.tools.common.el.core.resolver.ELContext;
import org.jboss.tools.common.el.core.resolver.ELOperandResolveStatus;
import org.jboss.tools.common.el.core.resolver.ELResolver;
import org.jboss.tools.common.el.core.resolver.ElVarSearcher;
@@ -58,7 +54,7 @@
import org.jboss.tools.common.model.project.ext.event.Change;
import org.jboss.tools.common.model.util.EclipseResourceUtil;
import org.jboss.tools.common.text.TextProposal;
-import org.jboss.tools.jst.web.kb.IPageContext;
+import org.jboss.tools.jst.web.kb.AbstractELCompletionEngine;
import org.jboss.tools.seam.core.IBijectedAttribute;
import org.jboss.tools.seam.core.ISeamComponent;
import org.jboss.tools.seam.core.ISeamContextShortVariable;
@@ -78,7 +74,7 @@
*
* @author Jeremy
*/
-public final class SeamELCompletionEngine implements ELCompletionEngine, ELResolver {
+public final class SeamELCompletionEngine extends AbstractELCompletionEngine<ISeamContextVariable> implements ELCompletionEngine, ELResolver {
private static final Image SEAM_EL_PROPOSAL_IMAGE =
SeamCorePlugin.getDefault().getImage(SeamCorePlugin.CA_SEAM_EL_IMAGE_PATH);
@@ -94,6 +90,10 @@
}
+ public Image getELProposalImage() {
+ return SEAM_EL_PROPOSAL_IMAGE;
+ }
+
/*
* (non-Javadoc)
* @see org.jboss.tools.common.el.core.resolver.ELCompletionEngine#getParserFactory()
@@ -102,215 +102,15 @@
return factory;
}
- /*
- * (non-Javadoc)
- * @see org.jboss.tools.common.el.core.resolver.ELResolver#getCompletions(java.lang.String, boolean, int, org.jboss.tools.common.el.core.resolver.ELContext)
- */
- public List<TextProposal> getCompletions(String elString, boolean returnEqualedVariablesOnly, int position, ELContext context) {
- IDocument document = null;
- if(context instanceof IPageContext) {
- IPageContext pageContext = (IPageContext)context;
- document = pageContext.getDocument();
- }
- List<Var> vars = new ArrayList<Var>();
- Var[] array = context.getVars();
- for (int i = 0; i < array.length; i++) {
- vars.add(array[i]);
- }
- List<TextProposal> proposals = null;
- try {
- proposals = getCompletions(context.getResource(), document, elString.subSequence(0, elString.length()), position, returnEqualedVariablesOnly, vars);
- } catch (StringIndexOutOfBoundsException e) {
- SeamCorePlugin.getPluginLog().logError(e);
- } catch (BadLocationException e) {
- SeamCorePlugin.getPluginLog().logError(e);
- }
- return proposals;
+ protected void log(Exception e) {
+ SeamCorePlugin.getPluginLog().logError(e);
}
- /*
- * (non-Javadoc)
- * @see org.jboss.tools.common.el.core.resolver.ELResolver#resolveELOperand(org.jboss.tools.common.el.core.model.ELExpression, org.jboss.tools.common.el.core.resolver.ELContext, boolean)
- */
- public ELOperandResolveStatus resolveELOperand(ELExpression operand, ELContext context, boolean returnEqualedVariablesOnly) {
- List<Var> vars = new ArrayList<Var>();
- Var[] array = context.getVars();
- for (int i = 0; i < array.length; i++) {
- vars.add(array[i]);
- }
- ELOperandResolveStatus status = null;
- try {
- status = resolveELOperand(context.getResource(), operand, returnEqualedVariablesOnly, vars, new ElVarSearcher(context.getResource(), this));
- } catch (StringIndexOutOfBoundsException e) {
- SeamCorePlugin.getPluginLog().logError(e);
- } catch (BadLocationException e) {
- SeamCorePlugin.getPluginLog().logError(e);
- }
- return status;
+ protected ELOperandResolveStatus newELOperandResolveStatus(ELInvocationExpression tokens) {
+ return new SeamELOperandResolveStatus(tokens);
}
/**
- * Create the list of suggestions.
- * @param seamProject Seam project
- * @param file File
- * @param documentContent
- * @param prefix the prefix to search for
- * @param position Offset of the prefix
- * @param vars - 'var' attributes which can be used in this EL. Can be null.
- * @param returnEqualedVariablesOnly 'false' if we get proposals for mask
- * for example:
- * we have 'variableName.variableProperty', 'variableName.variableProperty1', 'variableName.variableProperty2'
- * prefix is 'variableName.variableProperty'
- * Result is {'variableProperty'}
- * if 'false' then returns ends of variables that starts with prefix. It's useful for CA.
- * for example:
- * we have 'variableName.variableProperty', 'variableName.variableProperty1', 'variableName.variableProperty2'
- * prefix is 'variableName.variableProperty'
- * Result is {'1','2'}
- * @return the list of all possible suggestions
- * @throws BadLocationException if accessing the current document fails
- * @throws StringIndexOutOfBoundsException
- */
- public List<TextProposal> getCompletions(IFile file, IDocument document, CharSequence prefix,
- int position, boolean returnEqualedVariablesOnly, List<Var> vars) throws BadLocationException, StringIndexOutOfBoundsException {
- List<TextProposal> completions = new ArrayList<TextProposal>();
-
- ELOperandResolveStatus status = resolveELOperand(file, parseOperand("" + prefix), returnEqualedVariablesOnly, vars, new ElVarSearcher(file, this));
- if (status.isOK()) {
- completions.addAll(status.getProposals());
- }
-
- return completions;
- }
- private static final String collectionAdditionForCollectionDataModel = ".iterator().next()";
- private static final String collectionAdditionForMapDataModel = ".entrySet().iterator().next()";
-
- private List<String> getVarNameProposals(List <Var> vars, String prefix) {
- List<String> proposals = new ArrayList<String>();
- for (Var var : vars) {
- if(var.getName().startsWith(prefix)) {
- String proposal = var.getName().substring(prefix.length());
- proposals.add(proposal);
- }
- }
- return proposals;
- }
-
- public SeamELOperandResolveStatus resolveELOperand(IFile file, ELExpression operand,
- boolean returnEqualedVariablesOnly, List<Var> vars, ElVarSearcher varSearcher) throws BadLocationException, StringIndexOutOfBoundsException {
- if(operand == null) {
- //TODO
- return new SeamELOperandResolveStatus(null);
- }
- String oldEl = operand.getText();
- Var var = varSearcher.findVarForEl(oldEl, vars, true);
- String suffix = "";
- String newEl = oldEl;
- TypeInfoCollector.MemberInfo member = null;
- boolean isArray = false;
- if(var!=null) {
- member = resolveSeamEL(file, var.getElToken(), true);
- if(member!=null) {
- if(!member.getType().isArray()) {
- IType type = member.getMemberType();
- if(type!=null) {
- try {
- if(TypeInfoCollector.isInstanceofType(type, "java.util.Map")) {
- suffix = collectionAdditionForMapDataModel;
- } else if(TypeInfoCollector.isInstanceofType(type, "java.util.Collection")) {
- suffix = collectionAdditionForCollectionDataModel;
- }
- } catch (JavaModelException e) {
- SeamCorePlugin.getPluginLog().logError(e);
- }
- }
- } else {
- isArray = true;
- }
- }
- if(var.getElToken() != null) {
- newEl = var.getElToken().getText() + suffix + oldEl.substring(var.getName().length());
- }
- }
- boolean prefixWasChanged = !oldEl.equals(newEl);
- if(prefixWasChanged && isArray) {
- member.setDataModel(true);
- }
- ELExpression newOperand = (prefixWasChanged) ? parseOperand(newEl) : operand;
-
- SeamELOperandResolveStatus status = resolveELOperand(file, newOperand, returnEqualedVariablesOnly, prefixWasChanged);
-
- if(prefixWasChanged) {
- ELInvocationExpression newLastResolvedToken = status.getLastResolvedToken();
- status.setTokens((ELInvocationExpression)operand);
- if(newLastResolvedToken != null) {
- if(status.getUnresolvedTokens() != null
- && status.getUnresolvedTokens().getInvocationStartPosition() - status.getUnresolvedTokens().getStartPosition() < var.getElToken().getLength() + suffix.length()) {
- // Last resolved token is token from "var". Set first token of original EL as last resolved one.
- status.setLastResolvedToken(null);
- } else {
- // Last resolved token is token outside "var" prefix. Correct last resolved token.
- int oldLastResolvedTokenStart = newLastResolvedToken.getInvocationStartPosition() - var.getElToken().getText().length() - suffix.length() + var.getName().length();
- if(newLastResolvedToken.getLeft() == null) {
- //In this case we do not need to take into account difference in length of var and its expression.
- oldLastResolvedTokenStart = newLastResolvedToken.getInvocationStartPosition();
- }
- ELInvocationExpression l = (ELInvocationExpression)operand;
- while(l != null) {
- if(l.getInvocationStartPosition() - l.getStartPosition() <= oldLastResolvedTokenStart) {
- status.setLastResolvedToken(l);
- break;
- }
- l = l.getLeft();
- }
- }
- }
- }
-
- if(prefixWasChanged) {
- var.resolveValue("#{" + var.getElToken().getText() + suffix + "}");
- }
-
- if(!returnEqualedVariablesOnly && vars!=null) {
- List<String> varNameProposals = getVarNameProposals(vars, operand.toString());
- if (varNameProposals != null) {
- for (String varNameProposal : varNameProposals) {
- TextProposal proposal = new TextProposal();
- proposal.setReplacementString(varNameProposal);
- proposal.setImage(SEAM_EL_PROPOSAL_IMAGE);
- status.getProposals().add(proposal);
- }
- }
- }
- return status;
- }
-
- public ELExpression parseOperand(String operand) {
- if(operand == null) return null;
- String el = (operand.indexOf("#{") < 0 && operand.indexOf("${") < 0) ? "#{" + operand + "}" : operand;
- ELParser p = factory.createParser();
- ELModel model = p.parse(el);
- List<ELInstance> is = model.getInstances();
- if(is.isEmpty()) return null;
- return is.get(0).getExpression();
- }
-
- /**
- * Returns MemberInfo for last segment of EL. Null if El is not resolved.
- * @param seamProject
- * @param file
- * @param operand EL without #{}
- * @return MemberInfo for last segment of EL. Null if El is not resolved.
- * @throws BadLocationException
- * @throws StringIndexOutOfBoundsException
- */
- public TypeInfoCollector.MemberInfo resolveSeamEL(IFile file, ELExpression operand, boolean varIsUsed) throws BadLocationException, StringIndexOutOfBoundsException {
- if(!(operand instanceof ELInvocationExpression)) return null;
- ELOperandResolveStatus status = resolveELOperand(file, operand, true, varIsUsed);
- return status.getMemberOfResolvedOperand();
- }
-
- /**
* Returns a list of Seam Context Variables that is represented by EL. Null if El is not resolved.
* @param project
* @param file
@@ -366,428 +166,75 @@
return resolvedVariables;
}
- public SeamELOperandResolveStatus resolveELOperand(IFile file, ELExpression operand,
- boolean returnEqualedVariablesOnly, boolean varIsUsed) throws BadLocationException, StringIndexOutOfBoundsException {
- if(!(operand instanceof ELInvocationExpression) || file == null) {
- return new SeamELOperandResolveStatus(null);
- }
-
- ELInvocationExpression expr = (ELInvocationExpression)operand;
- boolean isIncomplete = expr.getType() == ELObjectType.EL_PROPERTY_INVOCATION
- && ((ELPropertyInvocation)expr).getName() == null;
- boolean isArgument = expr.getType() == ELObjectType.EL_ARGUMENT_INVOCATION;
-
- SeamELOperandResolveStatus status = new SeamELOperandResolveStatus(expr);
- ELInvocationExpression left = expr;
-
- List<ISeamContextVariable> resolvedVariables = new ArrayList<ISeamContextVariable>();
+ public List<ISeamContextVariable> resolveVariables(IFile file, ELInvocationExpression expr, boolean isFinal, boolean onlyEqualNames) {
ISeamProject project = SeamCorePlugin.getSeamProject(file.getProject(), false);
ScopeType scope = getScope(project, file);
+ return resolveVariables(project, scope, expr, isFinal, onlyEqualNames);
+ }
- if (expr.getLeft() != null && isArgument) {
- left = expr.getLeft();
- resolvedVariables = resolveVariables(project, scope, left, false,
- true); // is Final and equal names are because of
- // we have no more to resolve the parts of expression,
- // but we have to resolve arguments of probably a message component
- } else if (expr.getLeft() == null && isIncomplete) {
- resolvedVariables = resolveVariables(project, scope, expr, true,
- returnEqualedVariablesOnly);
+ protected TypeInfoCollector.MemberInfo getMemberInfoByVariable(ISeamContextVariable var, boolean onlyEqualNames) {
+ return SeamExpressionResolver.getMemberInfoByVariable(var, true, this);
+ }
+
+ protected void setImage(TextProposal proposal, ISeamContextVariable var) {
+ if (isSeamMessagesComponentVariable((ISeamContextVariable)var)) {
+ proposal.setImage(SEAM_MESSAGES_PROPOSAL_IMAGE);
} else {
- while(left != null) {
- List<ISeamContextVariable>resolvedVars = new ArrayList<ISeamContextVariable>();
- resolvedVars = resolveVariables(project, scope,
- left, left == expr,
- returnEqualedVariablesOnly);
- if (resolvedVars != null && !resolvedVars.isEmpty()) {
- resolvedVariables = resolvedVars;
- status.setLastResolvedToken(left);
- break;
- }
- left = (ELInvocationExpression)left.getLeft();
- }
+ proposal.setImage(getELProposalImage());
}
+ }
- // Save all resolved variables. It's useful for incremental validation.
- if(resolvedVariables != null && !resolvedVariables.isEmpty()) {
- status.setUsedVariables(resolvedVariables);
- }
+ protected void setUsedVariables(ELOperandResolveStatus status, List<ISeamContextVariable> variables) {
+ ((SeamELOperandResolveStatus)status).setUsedVariables(variables);
+ }
- if (status.getResolvedTokens() == null &&
- !returnEqualedVariablesOnly &&
- expr != null &&
- isIncomplete) {
- // no vars are resolved
- // the tokens are the part of var name ended with a separator (.)
- resolvedVariables = resolveVariables(project, scope, expr, true, returnEqualedVariablesOnly);
- Set<TextProposal> proposals = new TreeSet<TextProposal>(TextProposal.KB_PROPOSAL_ORDER);
- for (ISeamContextVariable var : resolvedVariables) {
- String varName = var.getName();
- if(varName.startsWith(operand.getText())) {
- TextProposal proposal = new TextProposal();
- proposal.setReplacementString(varName.substring(operand.getLength()));
- if (isSeamMessagesComponentVariable(var)) {
- proposal.setImage(SEAM_MESSAGES_PROPOSAL_IMAGE);
- } else {
- proposal.setImage(SEAM_EL_PROPOSAL_IMAGE);
- }
- proposals.add(proposal);
- }
- }
- status.setProposals(proposals);
- return status;
- }
+ protected boolean isSingularAttribute(ISeamContextVariable var) {
+ return var instanceof IBijectedAttribute;
+ }
- // Here we have a list of vars for some part of expression
- // OK. we'll proceed with members of these vars
- if (status.getResolvedTokens() == status.getTokens()) {
- // First segment is the last one
- Set<TextProposal> proposals = new TreeSet<TextProposal>(TextProposal.KB_PROPOSAL_ORDER);
- // In some cases there may be a few references to the same variable name.
- // For example @Factory and @DataModel. We should use @DataModel instead of @Factory
- // method which returns null.
- // See https://jira.jboss.org/jira/browse/JBIDE-3694
- TypeInfoCollector.MemberInfo bijectedAttribute = null;
- for (ISeamContextVariable var : resolvedVariables) {
- if(var instanceof IBijectedAttribute) {
- bijectedAttribute = SeamExpressionResolver.getMemberInfoByVariable(var, true, this);
- }
- String varName = var.getName();
- if(operand.getLength()<=varName.length()) {
- TextProposal proposal = new TextProposal();
- proposal.setReplacementString(varName.substring(operand.getLength()));
- if (isSeamMessagesComponentVariable(var)) {
- proposal.setImage(SEAM_MESSAGES_PROPOSAL_IMAGE);
- } else {
- proposal.setImage(SEAM_EL_PROPOSAL_IMAGE);
- }
- proposals.add(proposal);
- } else if(returnEqualedVariablesOnly) {
- TextProposal proposal = new TextProposal();
- proposal.setReplacementString(varName);
- if (isSeamMessagesComponentVariable(var)) {
- proposal.setImage(SEAM_MESSAGES_PROPOSAL_IMAGE);
- } else {
- proposal.setImage(SEAM_EL_PROPOSAL_IMAGE);
- }
- proposals.add(proposal);
- }
- status.setMemberOfResolvedOperand(bijectedAttribute!=null?bijectedAttribute:SeamExpressionResolver.getMemberInfoByVariable(var, true, this));
- }
- status.setLastResolvedToken(expr);
- status.setProposals(proposals);
- return status;
+ protected void setImage(TextProposal kbProposal, TypeInfoCollector.MemberPresentation proposal) {
+ if (proposal.getMember() instanceof MessagesInfo) {
+ kbProposal.setImage(SEAM_MESSAGES_PROPOSAL_IMAGE);
+ } else {
+ super.setImage(kbProposal, proposal);
}
-
- // First segment is found - proceed with next tokens
- List<TypeInfoCollector.MemberInfo> members = new ArrayList<TypeInfoCollector.MemberInfo>();
- for (ISeamContextVariable var : resolvedVariables) {
- TypeInfoCollector.MemberInfo member = SeamExpressionResolver.getMemberInfoByVariable(var, returnEqualedVariablesOnly, this);
- if (member != null && !members.contains(member))
- members.add(member);
- }
- //process segments one by one
- if(left != null) while(left != expr) {
- left = (ELInvocationExpression)left.getParent();
- if (left != expr) { // inside expression
- if(left instanceof ELArgumentInvocation) {
- String s = "#{" + left.getLeft().toString() + collectionAdditionForCollectionDataModel + "}";
- ELParser p = factory.createParser();
- ELInvocationExpression expr1 = (ELInvocationExpression)p.parse(s).getInstances().get(0).getExpression();
- members = resolveSegment(expr1.getLeft(), members, status, returnEqualedVariablesOnly, varIsUsed);
- members = resolveSegment(expr1, members, status, returnEqualedVariablesOnly, varIsUsed);
- if(status.getLastResolvedToken() == expr1) {
- status.setLastResolvedToken(left);
- }
- } else {
- members = resolveSegment(left, members, status, returnEqualedVariablesOnly, varIsUsed);
- }
- } else { // Last segment
- resolveLastSegment((ELInvocationExpression)operand, members, status, returnEqualedVariablesOnly, varIsUsed);
- break;
- }
- }
-
- if(status.getProposals().isEmpty() && status.getUnpairedGettersOrSetters()!=null) {
- status.clearUnpairedGettersOrSetters();
- }
- return status;
}
- private List<TypeInfoCollector.MemberInfo> resolveSegment(ELInvocationExpression expr,
- List<TypeInfoCollector.MemberInfo> members,
- ELOperandResolveStatus status,
- boolean returnEqualedVariablesOnly, boolean varIsUsed) {
- LexicalToken lt = (expr instanceof ELPropertyInvocation)
- ? ((ELPropertyInvocation)expr).getName()
- : (expr instanceof ELMethodInvocation)
- ? ((ELMethodInvocation)expr).getName()
- : null;
- String name = lt != null ? lt.getText() : ""; // token.getText();
- if (expr.getType() == ELObjectType.EL_PROPERTY_INVOCATION) {
- // Find properties for the token
- List<TypeInfoCollector.MemberInfo> newMembers = new ArrayList<TypeInfoCollector.MemberInfo>();
- for (TypeInfoCollector.MemberInfo mbr : members) {
- if (mbr.getMemberType() == null) continue;
- TypeInfoCollector infos = mbr.getTypeCollector(varIsUsed);
- if (TypeInfoCollector.isNotParameterizedCollection(mbr) || TypeInfoCollector.isResourceBundle(mbr.getMemberType())) {
- status.setMapOrCollectionOrBundleAmoungTheTokens();
- }
- List<TypeInfoCollector.MemberInfo> properties = infos.getProperties();
- for (TypeInfoCollector.MemberInfo property : properties) {
- StringBuffer propertyName = new StringBuffer(property.getName());
- if (property instanceof TypeInfoCollector.MethodInfo) { // Setter or getter
- propertyName.delete(0, (propertyName.charAt(0) == 'i' ? 2 : 3));
- propertyName.setCharAt(0, Character.toLowerCase(propertyName.charAt(0)));
- }
- if (name.equals(propertyName.toString())) {
- newMembers.add(property);
- }
- }
- }
- members = newMembers;
- if (members != null && !members.isEmpty())
- status.setLastResolvedToken(expr);
- }
- if (expr.getType() == ELObjectType.EL_METHOD_INVOCATION) {
- // Find methods for the token
- if (name.indexOf('(') != -1) {
- name = name.substring(0, name.indexOf('('));
- }
- List<TypeInfoCollector.MemberInfo> newMembers = new ArrayList<TypeInfoCollector.MemberInfo>();
- for (TypeInfoCollector.MemberInfo mbr : members) {
- if (mbr.getMemberType() == null) continue;
- TypeInfoCollector infos = mbr.getTypeCollector();
- if (TypeInfoCollector.isNotParameterizedCollection(mbr) || TypeInfoCollector.isResourceBundle(mbr.getMemberType())) {
- status.setMapOrCollectionOrBundleAmoungTheTokens();
- }
- List<TypeInfoCollector.MemberInfo> methods = infos.getMethods();
- for (TypeInfoCollector.MemberInfo method : methods) {
- if (name.equals(method.getName())) {
- newMembers.add(method);
- }
- }
- }
- members = newMembers;
- if (members != null && !members.isEmpty())
- status.setLastResolvedToken(expr);
- }
- return members;
+ protected boolean isSingularMember(TypeInfoCollector.MemberInfo mbr) {
+ return (mbr instanceof MessagesInfo);
}
- private void resolveLastSegment(ELInvocationExpression expr,
- List<TypeInfoCollector.MemberInfo> members,
- ELOperandResolveStatus status,
- boolean returnEqualedVariablesOnly, boolean varIsUsed) {
- Set<TextProposal> kbProposals = new TreeSet<TextProposal>(TextProposal.KB_PROPOSAL_ORDER);
-
- if (expr.getType() == ELObjectType.EL_PROPERTY_INVOCATION && ((ELPropertyInvocation)expr).getName() == null) {
- // return all the methods + properties
- for (TypeInfoCollector.MemberInfo mbr : members) {
- if (mbr instanceof MessagesInfo) {
- // Surround the "long" keys containing the dots with [' ']
- TreeSet<String> keys = new TreeSet<String>(String.CASE_INSENSITIVE_ORDER);
- keys.addAll(((MessagesInfo)mbr).getKeys());
- Iterator<String> sortedKeys = keys.iterator();
- while(sortedKeys.hasNext()) {
- String key = sortedKeys.next();
- if (key == null || key.length() == 0)
- continue;
- if (key.indexOf('.') != -1) {
- TextProposal proposal = new TextProposal();
- proposal.setReplacementString("['" + key + "']");
- proposal.setImage(SEAM_MESSAGES_PROPOSAL_IMAGE);
-
- kbProposals.add(proposal);
- } else {
- TextProposal proposal = new TextProposal();
- proposal.setReplacementString(key);
- proposal.setImage(SEAM_MESSAGES_PROPOSAL_IMAGE);
-
- kbProposals.add(proposal);
- }
- }
+ protected void processSingularMember(TypeInfoCollector.MemberInfo mbr, Set<TextProposal> kbProposals) {
+ if (mbr instanceof MessagesInfo) {
+ // Surround the "long" keys containing the dots with [' ']
+ TreeSet<String> keys = new TreeSet<String>(String.CASE_INSENSITIVE_ORDER);
+ keys.addAll(((MessagesInfo)mbr).getKeys());
+ Iterator<String> sortedKeys = keys.iterator();
+ while(sortedKeys.hasNext()) {
+ String key = sortedKeys.next();
+ if (key == null || key.length() == 0)
continue;
- }
- if (mbr.getMemberType() == null) {
- continue;
- }
- TypeInfoCollector infos = mbr.getTypeCollector(varIsUsed);
- if (TypeInfoCollector.isNotParameterizedCollection(mbr) || TypeInfoCollector.isResourceBundle(mbr.getMemberType())) {
- status.setMapOrCollectionOrBundleAmoungTheTokens();
- }
-
- Set<String> methodPresentations =
- infos.getMethodPresentationStrings();
- if (methodPresentations != null) {
- for (String presentation : methodPresentations) {
- TextProposal proposal = new TextProposal();
- proposal.setReplacementString(presentation);
- proposal.setImage(SEAM_EL_PROPOSAL_IMAGE);
-
- kbProposals.add(proposal);
- }
- }
- Set<String> propertyPresentations =
- infos.getPropertyPresentationStrings(status.getUnpairedGettersOrSetters());
- if (propertyPresentations != null) {
- for (String presentation : propertyPresentations) {
- TextProposal proposal = new TextProposal();
- proposal.setReplacementString(presentation);
- proposal.setImage(SEAM_EL_PROPOSAL_IMAGE);
-
- kbProposals.add(proposal);
- }
- }
- }
- } else
- if(expr.getType() != ELObjectType.EL_ARGUMENT_INVOCATION)
- //actually any case
-// if (token.getType() == ELOperandToken.EL_VARIABLE_NAME_TOKEN ||
-// token.getType() == ELOperandToken.EL_PROPERTY_NAME_TOKEN ||
-// token.getType() == ELOperandToken.EL_METHOD_TOKEN)
- {
- // return filtered methods + properties
- Set<TypeInfoCollector.MemberPresentation> proposalsToFilter = new TreeSet<TypeInfoCollector.MemberPresentation>(TypeInfoCollector.MEMBER_PRESENTATION_COMPARATOR);
- for (TypeInfoCollector.MemberInfo mbr : members) {
- if (mbr instanceof MessagesInfo) {
- Collection<String> keys = ((MessagesInfo)mbr).getKeys();
- for (String key : keys) {
- proposalsToFilter.add(new TypeInfoCollector.MemberPresentation(key, mbr));
- }
- continue;
- }
- if (mbr.getMemberType() == null) continue;
- TypeInfoCollector infos = mbr.getTypeCollector();
- if (TypeInfoCollector.isNotParameterizedCollection(mbr) || TypeInfoCollector.isResourceBundle(mbr.getMemberType())) {
- status.setMapOrCollectionOrBundleAmoungTheTokens();
- }
- proposalsToFilter.addAll(infos.getMethodPresentations());
- proposalsToFilter.addAll(infos.getPropertyPresentations(status.getUnpairedGettersOrSetters()));
- status.setMemberOfResolvedOperand(mbr);
- }
- for (TypeInfoCollector.MemberPresentation proposal : proposalsToFilter) {
- // We do expect nothing but name for method tokens (No round brackets)
- String filter = expr.getMemberName();
- if(filter == null) filter = "";
- if(returnEqualedVariablesOnly) {
- // This is used for validation.
- if (proposal.getPresentation().equals(filter)) {
- TextProposal kbProposal = new TextProposal();
- kbProposal.setReplacementString(proposal.getPresentation());
-
- if (proposal.getMember() instanceof MessagesInfo) {
- kbProposal.setImage(SEAM_MESSAGES_PROPOSAL_IMAGE);
- } else {
- kbProposal.setImage(SEAM_EL_PROPOSAL_IMAGE);
- }
-
- kbProposals.add(kbProposal);
-
- status.setMemberOfResolvedOperand(proposal.getMember());
- if(status.getUnpairedGettersOrSetters()!=null) {
- TypeInfoCollector.MethodInfo unpirMethod = status.getUnpairedGettersOrSetters().get(filter);
- status.clearUnpairedGettersOrSetters();
- if(unpirMethod!=null) {
- status.getUnpairedGettersOrSetters().put(filter, unpirMethod);
- }
- }
- break;
- }
- } else if (proposal.getPresentation().startsWith(filter)) {
- // This is used for CA.
- TextProposal kbProposal = new TextProposal();
- kbProposal.setReplacementString(proposal.getPresentation().substring(filter.length()));
- kbProposal.setImage(SEAM_EL_PROPOSAL_IMAGE);
+ if (key.indexOf('.') != -1) {
+ TextProposal proposal = new TextProposal();
+ proposal.setReplacementString("['" + key + "']");
+ proposal.setImage(SEAM_MESSAGES_PROPOSAL_IMAGE);
- kbProposals.add(kbProposal);
- }
- }
- } else if(expr.getType() == ELObjectType.EL_ARGUMENT_INVOCATION) {
- Set<TypeInfoCollector.MemberPresentation> proposalsToFilter = new TreeSet<TypeInfoCollector.MemberPresentation>(TypeInfoCollector.MEMBER_PRESENTATION_COMPARATOR);
- boolean isMessages = false;
- for (TypeInfoCollector.MemberInfo mbr : members) {
- if (mbr instanceof MessagesInfo) {
- isMessages = true;
- Collection<String> keys = ((MessagesInfo)mbr).getKeys();
- for (String key : keys) {
- proposalsToFilter.add(new TypeInfoCollector.MemberPresentation(key, mbr));
- }
- continue;
- }
- if (mbr.getMemberType() == null) continue;
- try {
- if(TypeInfoCollector.isInstanceofType(mbr.getMemberType(), "java.util.Map")) {
- status.setMapOrCollectionOrBundleAmoungTheTokens();
- //if map/collection is parameterized, we might return member info for value type.
- return;
- }
- } catch (JavaModelException jme) {
- //ignore
- }
- status.setMemberOfResolvedOperand(mbr);
- }
-
- String filter = expr.getMemberName();
- boolean bSurroundWithQuotes = false;
- if(filter == null) {
- filter = "";
- bSurroundWithQuotes = true;
- } else {
- if((filter.startsWith("'") || filter.startsWith("\""))
- && (filter.endsWith("'") || filter.endsWith("\""))) {
- filter = filter.substring(1, filter.length() - 1);
+ kbProposals.add(proposal);
} else {
- //Value is set as expression itself, we cannot compute it
- if(isMessages) status.setMapOrCollectionOrBundleAmoungTheTokens();
- return;
- }
- }
-
- for (TypeInfoCollector.MemberPresentation proposal : proposalsToFilter) {
- if(returnEqualedVariablesOnly) {
- // This is used for validation.
- if (proposal.getPresentation().equals(filter)) {
- TextProposal kbProposal = new TextProposal();
- kbProposal.setReplacementString(proposal.getPresentation());
-
- if (proposal.getMember() instanceof MessagesInfo) {
- kbProposal.setImage(SEAM_MESSAGES_PROPOSAL_IMAGE);
- } else {
- kbProposal.setImage(SEAM_EL_PROPOSAL_IMAGE);
- }
-
- kbProposals.add(kbProposal);
-
- status.setMemberOfResolvedOperand(proposal.getMember());
- if(status.getUnpairedGettersOrSetters()!=null) {
- TypeInfoCollector.MethodInfo unpirMethod = status.getUnpairedGettersOrSetters().get(filter);
- status.clearUnpairedGettersOrSetters();
- if(unpirMethod!=null) {
- status.getUnpairedGettersOrSetters().put(filter, unpirMethod);
- }
- }
- break;
- }
- } else if (proposal.getPresentation().startsWith(filter)) {
- // This is used for CA.
- TextProposal kbProposal = new TextProposal();
+ TextProposal proposal = new TextProposal();
+ proposal.setReplacementString(key);
+ proposal.setImage(SEAM_MESSAGES_PROPOSAL_IMAGE);
- String replacementString = proposal.getPresentation().substring(filter.length());
- if (bSurroundWithQuotes) {
- replacementString = "'" + replacementString + "']";
- }
-
- kbProposal.setReplacementString(replacementString);
- kbProposal.setImage(SEAM_EL_PROPOSAL_IMAGE);
-
- kbProposals.add(kbProposal);
+ kbProposals.add(proposal);
}
}
}
- status.setProposals(kbProposals);
- if (status.isOK()){
- status.setLastResolvedToken(expr);
+ }
+
+ protected void filterSingularMember(TypeInfoCollector.MemberInfo mbr, Set<TypeInfoCollector.MemberPresentation> proposalsToFilter) {
+ Collection<String> keys = ((MessagesInfo)mbr).getKeys();
+ for (String key : keys) {
+ proposalsToFilter.add(new TypeInfoCollector.MemberPresentation(key, mbr));
}
}
Modified: trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/el/SeamExpressionResolver.java
===================================================================
--- trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/el/SeamExpressionResolver.java 2009-06-22 17:08:10 UTC (rev 16121)
+++ trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/el/SeamExpressionResolver.java 2009-06-22 17:10:32 UTC (rev 16122)
@@ -352,7 +352,7 @@
if(ex instanceof ELInvocationExpression) {
ELInvocationExpression expr = (ELInvocationExpression)ex;
try {
- member = engine.resolveSeamEL(null, expr, false);
+ member = engine.resolveEL(null, expr, false);
} catch (StringIndexOutOfBoundsException e) {
e.printStackTrace();
} catch (BadLocationException e) {
Modified: trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/validation/SeamELValidator.java
===================================================================
--- trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/validation/SeamELValidator.java 2009-06-22 17:08:10 UTC (rev 16121)
+++ trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/validation/SeamELValidator.java 2009-06-22 17:10:32 UTC (rev 16122)
@@ -382,7 +382,7 @@
int offset = operand.length();
if (!operand.endsWith(".")) { //$NON-NLS-1$
SeamELOperandResolveStatus status =
- engine.resolveELOperand(file, operandToken, true, varListForCurentValidatedNode, elVarSearcher);
+ (SeamELOperandResolveStatus)engine.resolveELOperand(file, operandToken, true, varListForCurentValidatedNode, elVarSearcher);
if(status.isError()) {
if(revalidateUnresolvedELs) {
15 years, 6 months
JBoss Tools SVN: r16121 - trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb.
by jbosstools-commits@lists.jboss.org
Author: scabanovich
Date: 2009-06-22 13:08:10 -0400 (Mon, 22 Jun 2009)
New Revision: 16121
Added:
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/AbstractELCompletionEngine.java
Log:
https://jira.jboss.org/jira/browse/JBIDE-2808
AbstractELCompletionEngine
Added: trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/AbstractELCompletionEngine.java
===================================================================
--- trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/AbstractELCompletionEngine.java (rev 0)
+++ trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/AbstractELCompletionEngine.java 2009-06-22 17:08:10 UTC (rev 16121)
@@ -0,0 +1,671 @@
+package org.jboss.tools.jst.web.kb;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+import java.util.TreeSet;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.jdt.core.IType;
+import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.swt.graphics.Image;
+import org.jboss.tools.common.el.core.model.ELArgumentInvocation;
+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.ELMethodInvocation;
+import org.jboss.tools.common.el.core.model.ELModel;
+import org.jboss.tools.common.el.core.model.ELObjectType;
+import org.jboss.tools.common.el.core.model.ELPropertyInvocation;
+import org.jboss.tools.common.el.core.parser.ELParser;
+import org.jboss.tools.common.el.core.parser.LexicalToken;
+import org.jboss.tools.common.el.core.resolver.ELCompletionEngine;
+import org.jboss.tools.common.el.core.resolver.ELContext;
+import org.jboss.tools.common.el.core.resolver.ELOperandResolveStatus;
+import org.jboss.tools.common.el.core.resolver.ELResolver;
+import org.jboss.tools.common.el.core.resolver.ElVarSearcher;
+import org.jboss.tools.common.el.core.resolver.TypeInfoCollector;
+import org.jboss.tools.common.el.core.resolver.Var;
+import org.jboss.tools.common.text.TextProposal;
+
+public abstract class AbstractELCompletionEngine<V extends AbstractELCompletionEngine.IVariable> implements ELResolver, ELCompletionEngine {
+
+ public static interface IVariable {
+ public String getName();
+ }
+
+ public AbstractELCompletionEngine() {}
+
+ public abstract Image getELProposalImage();
+
+ protected abstract void log(Exception e);
+
+ /*
+ * (non-Javadoc)
+ * @see org.jboss.tools.common.el.core.resolver.ELResolver#getCompletions(java.lang.String, boolean, int, org.jboss.tools.common.el.core.resolver.ELContext)
+ */
+ public List<TextProposal> getCompletions(String elString, boolean returnEqualedVariablesOnly, int position, ELContext context) {
+ IDocument document = null;
+ if(context instanceof IPageContext) {
+ IPageContext pageContext = (IPageContext)context;
+ document = pageContext.getDocument();
+ }
+ List<Var> vars = new ArrayList<Var>();
+ Var[] array = context.getVars();
+ for (int i = 0; i < array.length; i++) {
+ vars.add(array[i]);
+ }
+ List<TextProposal> proposals = null;
+ try {
+ proposals = getCompletions(context.getResource(), document, elString.subSequence(0, elString.length()), position, returnEqualedVariablesOnly, vars);
+ } catch (StringIndexOutOfBoundsException e) {
+ log(e);
+ } catch (BadLocationException e) {
+ log(e);
+ }
+ return proposals;
+ }
+
+ /**
+ * Create the list of suggestions.
+ * @param seamProject Seam project
+ * @param file File
+ * @param documentContent
+ * @param prefix the prefix to search for
+ * @param position Offset of the prefix
+ * @param vars - 'var' attributes which can be used in this EL. Can be null.
+ * @param returnEqualedVariablesOnly 'false' if we get proposals for mask
+ * for example:
+ * we have 'variableName.variableProperty', 'variableName.variableProperty1', 'variableName.variableProperty2'
+ * prefix is 'variableName.variableProperty'
+ * Result is {'variableProperty'}
+ * if 'false' then returns ends of variables that starts with prefix. It's useful for CA.
+ * for example:
+ * we have 'variableName.variableProperty', 'variableName.variableProperty1', 'variableName.variableProperty2'
+ * prefix is 'variableName.variableProperty'
+ * Result is {'1','2'}
+ * @return the list of all possible suggestions
+ * @throws BadLocationException if accessing the current document fails
+ * @throws StringIndexOutOfBoundsException
+ */
+ public List<TextProposal> getCompletions(IFile file, IDocument document, CharSequence prefix,
+ int position, boolean returnEqualedVariablesOnly, List<Var> vars) throws BadLocationException, StringIndexOutOfBoundsException {
+ List<TextProposal> completions = new ArrayList<TextProposal>();
+
+ ELOperandResolveStatus status = resolveELOperand(file, parseOperand("" + prefix), returnEqualedVariablesOnly, vars, new ElVarSearcher(file, this));
+ if (status.isOK()) {
+ completions.addAll(status.getProposals());
+ }
+
+ return completions;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.jboss.tools.common.el.core.resolver.ELResolver#resolveELOperand(org.jboss.tools.common.el.core.model.ELExpression, org.jboss.tools.common.el.core.resolver.ELContext, boolean)
+ */
+ public ELOperandResolveStatus resolveELOperand(ELExpression operand, ELContext context, boolean returnEqualedVariablesOnly) {
+ List<Var> vars = new ArrayList<Var>();
+ Var[] array = context.getVars();
+ for (int i = 0; i < array.length; i++) {
+ vars.add(array[i]);
+ }
+ ELOperandResolveStatus status = null;
+ try {
+ status = resolveELOperand(context.getResource(), operand, returnEqualedVariablesOnly, vars, new ElVarSearcher(context.getResource(), this));
+ } catch (StringIndexOutOfBoundsException e) {
+ log(e);
+ } catch (BadLocationException e) {
+ log(e);
+ }
+ return status;
+ }
+
+ public ELExpression parseOperand(String operand) {
+ if(operand == null) return null;
+ String el = (operand.indexOf("#{") < 0 && operand.indexOf("${") < 0) ? "#{" + operand + "}" : operand;
+ ELParser p = getParserFactory().createParser();
+ ELModel model = p.parse(el);
+ List<ELInstance> is = model.getInstances();
+ if(is.isEmpty()) return null;
+ return is.get(0).getExpression();
+ }
+
+ protected static final String collectionAdditionForCollectionDataModel = ".iterator().next()";
+ protected static final String collectionAdditionForMapDataModel = ".entrySet().iterator().next()";
+
+ protected List<String> getVarNameProposals(List <Var> vars, String prefix) {
+ List<String> proposals = new ArrayList<String>();
+ for (Var var : vars) {
+ if(var.getName().startsWith(prefix)) {
+ String proposal = var.getName().substring(prefix.length());
+ proposals.add(proposal);
+ }
+ }
+ return proposals;
+ }
+
+ protected ELOperandResolveStatus newELOperandResolveStatus(ELInvocationExpression tokens) {
+ return new ELOperandResolveStatus(tokens);
+ }
+
+ public ELOperandResolveStatus resolveELOperand(IFile file,
+ ELExpression operand, boolean returnEqualedVariablesOnly,
+ List<Var> vars, ElVarSearcher varSearcher)
+ throws BadLocationException, StringIndexOutOfBoundsException {
+ if(operand == null) {
+ //TODO
+ return newELOperandResolveStatus(null);
+ }
+ String oldEl = operand.getText();
+ Var var = varSearcher.findVarForEl(oldEl, vars, true);
+ String suffix = "";
+ String newEl = oldEl;
+ TypeInfoCollector.MemberInfo member = null;
+ boolean isArray = false;
+ if(var!=null) {
+ member = resolveEL(file, var.getElToken(), true);
+ if(member!=null) {
+ if(!member.getType().isArray()) {
+ IType type = member.getMemberType();
+ if(type!=null) {
+ try {
+ if(TypeInfoCollector.isInstanceofType(type, "java.util.Map")) {
+ suffix = collectionAdditionForMapDataModel;
+ } else if(TypeInfoCollector.isInstanceofType(type, "java.util.Collection")) {
+ suffix = collectionAdditionForCollectionDataModel;
+ }
+ } catch (JavaModelException e) {
+ log(e);
+ }
+ }
+ } else {
+ isArray = true;
+ }
+ }
+ if(var.getElToken() != null) {
+ newEl = var.getElToken().getText() + suffix + oldEl.substring(var.getName().length());
+ }
+ }
+ boolean prefixWasChanged = !oldEl.equals(newEl);
+ if(prefixWasChanged && isArray) {
+ member.setDataModel(true);
+ }
+ ELExpression newOperand = (prefixWasChanged) ? parseOperand(newEl) : operand;
+
+ ELOperandResolveStatus status = resolveELOperand(file, newOperand, returnEqualedVariablesOnly, prefixWasChanged);
+
+ if(prefixWasChanged) {
+ ELInvocationExpression newLastResolvedToken = status.getLastResolvedToken();
+ status.setTokens((ELInvocationExpression)operand);
+ if(newLastResolvedToken != null) {
+ if(status.getUnresolvedTokens() != null
+ && status.getUnresolvedTokens().getInvocationStartPosition() - status.getUnresolvedTokens().getStartPosition() < var.getElToken().getLength() + suffix.length()) {
+ // Last resolved token is token from "var". Set first token of original EL as last resolved one.
+ status.setLastResolvedToken(null);
+ } else {
+ // Last resolved token is token outside "var" prefix. Correct last resolved token.
+ int oldLastResolvedTokenStart = newLastResolvedToken.getInvocationStartPosition() - var.getElToken().getText().length() - suffix.length() + var.getName().length();
+ if(newLastResolvedToken.getLeft() == null) {
+ //In this case we do not need to take into account difference in length of var and its expression.
+ oldLastResolvedTokenStart = newLastResolvedToken.getInvocationStartPosition();
+ }
+ ELInvocationExpression l = (ELInvocationExpression)operand;
+ while(l != null) {
+ if(l.getInvocationStartPosition() - l.getStartPosition() <= oldLastResolvedTokenStart) {
+ status.setLastResolvedToken(l);
+ break;
+ }
+ l = l.getLeft();
+ }
+ }
+ }
+ }
+
+ if(prefixWasChanged) {
+ var.resolveValue("#{" + var.getElToken().getText() + suffix + "}");
+ }
+
+ if(!returnEqualedVariablesOnly && vars!=null) {
+ List<String> varNameProposals = getVarNameProposals(vars, operand.toString());
+ if (varNameProposals != null) {
+ for (String varNameProposal : varNameProposals) {
+ TextProposal proposal = new TextProposal();
+ proposal.setReplacementString(varNameProposal);
+ proposal.setImage(getELProposalImage());
+ status.getProposals().add(proposal);
+ }
+ }
+ }
+ return status;
+ }
+
+
+ /**
+ * Returns MemberInfo for last segment of EL. Null if El is not resolved.
+ * @param seamProject
+ * @param file
+ * @param operand EL without #{}
+ * @return MemberInfo for last segment of EL. Null if El is not resolved.
+ * @throws BadLocationException
+ * @throws StringIndexOutOfBoundsException
+ */
+ public TypeInfoCollector.MemberInfo resolveEL(IFile file, ELExpression operand, boolean varIsUsed) throws BadLocationException, StringIndexOutOfBoundsException {
+ if(!(operand instanceof ELInvocationExpression)) return null;
+ ELOperandResolveStatus status = resolveELOperand(file, operand, true, varIsUsed);
+ return status.getMemberOfResolvedOperand();
+ }
+
+ public ELOperandResolveStatus resolveELOperand(IFile file, ELExpression operand,
+ boolean returnEqualedVariablesOnly, boolean varIsUsed) throws BadLocationException, StringIndexOutOfBoundsException {
+ if(!(operand instanceof ELInvocationExpression) || file == null) {
+ return newELOperandResolveStatus(null);
+ }
+
+ ELInvocationExpression expr = (ELInvocationExpression)operand;
+ boolean isIncomplete = expr.getType() == ELObjectType.EL_PROPERTY_INVOCATION
+ && ((ELPropertyInvocation)expr).getName() == null;
+ boolean isArgument = expr.getType() == ELObjectType.EL_ARGUMENT_INVOCATION;
+
+ ELOperandResolveStatus status = newELOperandResolveStatus(expr);
+ ELInvocationExpression left = expr;
+
+ List<V> resolvedVariables = new ArrayList<V>();
+
+ if (expr.getLeft() != null && isArgument) {
+ left = expr.getLeft();
+ resolvedVariables = resolveVariables(file, left, false,
+ true); // is Final and equal names are because of
+ // we have no more to resolve the parts of expression,
+ // but we have to resolve arguments of probably a message component
+ } else if (expr.getLeft() == null && isIncomplete) {
+ resolvedVariables = resolveVariables(file, expr, true,
+ returnEqualedVariablesOnly);
+ } else {
+ while(left != null) {
+ List<V>resolvedVars = new ArrayList<V>();
+ resolvedVars = resolveVariables(file,
+ left, left == expr,
+ returnEqualedVariablesOnly);
+ if (resolvedVars != null && !resolvedVars.isEmpty()) {
+ resolvedVariables = resolvedVars;
+ status.setLastResolvedToken(left);
+ break;
+ }
+ left = (ELInvocationExpression)left.getLeft();
+ }
+ }
+
+ // Save all resolved variables. It's useful for incremental validation.
+ if(resolvedVariables != null && !resolvedVariables.isEmpty()) {
+ setUsedVariables(status, resolvedVariables);
+ }
+
+ if (status.getResolvedTokens() == null &&
+ !returnEqualedVariablesOnly &&
+ expr != null &&
+ isIncomplete) {
+ // no vars are resolved
+ // the tokens are the part of var name ended with a separator (.)
+ resolvedVariables = resolveVariables(file, expr, true, returnEqualedVariablesOnly);
+ Set<TextProposal> proposals = new TreeSet<TextProposal>(TextProposal.KB_PROPOSAL_ORDER);
+ for (V var : resolvedVariables) {
+ String varName = var.getName();
+ if(varName.startsWith(operand.getText())) {
+ TextProposal proposal = new TextProposal();
+ proposal.setReplacementString(varName.substring(operand.getLength()));
+ setImage(proposal, var);
+ proposals.add(proposal);
+ }
+ }
+ status.setProposals(proposals);
+ return status;
+ }
+
+ // Here we have a list of vars for some part of expression
+ // OK. we'll proceed with members of these vars
+ if (status.getResolvedTokens() == status.getTokens()) {
+ // First segment is the last one
+ Set<TextProposal> proposals = new TreeSet<TextProposal>(TextProposal.KB_PROPOSAL_ORDER);
+ // In some cases there may be a few references to the same variable name.
+ // For example @Factory and @DataModel. We should use @DataModel instead of @Factory
+ // method which returns null.
+ // See https://jira.jboss.org/jira/browse/JBIDE-3694
+ TypeInfoCollector.MemberInfo bijectedAttribute = null;
+ for (V var : resolvedVariables) {
+ if(isSingularAttribute(var)) {
+ bijectedAttribute = getMemberInfoByVariable(var, true);
+ }
+ String varName = var.getName();
+ if(operand.getLength()<=varName.length()) {
+ TextProposal proposal = new TextProposal();
+ proposal.setReplacementString(varName.substring(operand.getLength()));
+ setImage(proposal, var);
+ proposals.add(proposal);
+ } else if(returnEqualedVariablesOnly) {
+ TextProposal proposal = new TextProposal();
+ proposal.setReplacementString(varName);
+ setImage(proposal, var);
+ proposals.add(proposal);
+ }
+ status.setMemberOfResolvedOperand(bijectedAttribute!=null?bijectedAttribute:getMemberInfoByVariable(var, true));
+ }
+ status.setLastResolvedToken(expr);
+ status.setProposals(proposals);
+ return status;
+ }
+
+ // First segment is found - proceed with next tokens
+ List<TypeInfoCollector.MemberInfo> members = new ArrayList<TypeInfoCollector.MemberInfo>();
+ for (V var : resolvedVariables) {
+ TypeInfoCollector.MemberInfo member = getMemberInfoByVariable(var, returnEqualedVariablesOnly);
+ if (member != null && !members.contains(member))
+ members.add(member);
+ }
+ //process segments one by one
+ if(left != null) while(left != expr) {
+ left = (ELInvocationExpression)left.getParent();
+ if (left != expr) { // inside expression
+ if(left instanceof ELArgumentInvocation) {
+ String s = "#{" + left.getLeft().toString() + collectionAdditionForCollectionDataModel + "}";
+ ELParser p = getParserFactory().createParser();
+ ELInvocationExpression expr1 = (ELInvocationExpression)p.parse(s).getInstances().get(0).getExpression();
+ members = resolveSegment(expr1.getLeft(), members, status, returnEqualedVariablesOnly, varIsUsed);
+ members = resolveSegment(expr1, members, status, returnEqualedVariablesOnly, varIsUsed);
+ if(status.getLastResolvedToken() == expr1) {
+ status.setLastResolvedToken(left);
+ }
+ } else {
+ members = resolveSegment(left, members, status, returnEqualedVariablesOnly, varIsUsed);
+ }
+ } else { // Last segment
+ resolveLastSegment((ELInvocationExpression)operand, members, status, returnEqualedVariablesOnly, varIsUsed);
+ break;
+ }
+ }
+
+ if(status.getProposals().isEmpty() && status.getUnpairedGettersOrSetters()!=null) {
+ status.clearUnpairedGettersOrSetters();
+ }
+ return status;
+ }
+
+ public List<V> resolveVariables(IFile file, ELInvocationExpression expr, boolean isFinal, boolean onlyEqualNames) {
+ return new ArrayList<V>();
+ }
+
+ protected TypeInfoCollector.MemberInfo getMemberInfoByVariable(V var, boolean onlyEqualNames) {
+ return null;
+ }
+
+ protected void setUsedVariables(ELOperandResolveStatus status, List<V> resolvedVariables) {
+ }
+
+ protected boolean isSingularAttribute(V var) {
+ return false;
+ }
+
+
+ protected List<TypeInfoCollector.MemberInfo> resolveSegment(ELInvocationExpression expr,
+ List<TypeInfoCollector.MemberInfo> members,
+ ELOperandResolveStatus status,
+ boolean returnEqualedVariablesOnly, boolean varIsUsed) {
+ LexicalToken lt = (expr instanceof ELPropertyInvocation)
+ ? ((ELPropertyInvocation)expr).getName()
+ : (expr instanceof ELMethodInvocation)
+ ? ((ELMethodInvocation)expr).getName()
+ : null;
+ String name = lt != null ? lt.getText() : ""; // token.getText();
+ if (expr.getType() == ELObjectType.EL_PROPERTY_INVOCATION) {
+ // Find properties for the token
+ List<TypeInfoCollector.MemberInfo> newMembers = new ArrayList<TypeInfoCollector.MemberInfo>();
+ for (TypeInfoCollector.MemberInfo mbr : members) {
+ if (mbr.getMemberType() == null) continue;
+ TypeInfoCollector infos = mbr.getTypeCollector(varIsUsed);
+ if (TypeInfoCollector.isNotParameterizedCollection(mbr) || TypeInfoCollector.isResourceBundle(mbr.getMemberType())) {
+ status.setMapOrCollectionOrBundleAmoungTheTokens();
+ }
+ List<TypeInfoCollector.MemberInfo> properties = infos.getProperties();
+ for (TypeInfoCollector.MemberInfo property : properties) {
+ StringBuffer propertyName = new StringBuffer(property.getName());
+ if (property instanceof TypeInfoCollector.MethodInfo) { // Setter or getter
+ propertyName.delete(0, (propertyName.charAt(0) == 'i' ? 2 : 3));
+ propertyName.setCharAt(0, Character.toLowerCase(propertyName.charAt(0)));
+ }
+ if (name.equals(propertyName.toString())) {
+ newMembers.add(property);
+ }
+ }
+ }
+ members = newMembers;
+ if (members != null && !members.isEmpty())
+ status.setLastResolvedToken(expr);
+ }
+ if (expr.getType() == ELObjectType.EL_METHOD_INVOCATION) {
+ // Find methods for the token
+ if (name.indexOf('(') != -1) {
+ name = name.substring(0, name.indexOf('('));
+ }
+ List<TypeInfoCollector.MemberInfo> newMembers = new ArrayList<TypeInfoCollector.MemberInfo>();
+ for (TypeInfoCollector.MemberInfo mbr : members) {
+ if (mbr.getMemberType() == null) continue;
+ TypeInfoCollector infos = mbr.getTypeCollector();
+ if (TypeInfoCollector.isNotParameterizedCollection(mbr) || TypeInfoCollector.isResourceBundle(mbr.getMemberType())) {
+ status.setMapOrCollectionOrBundleAmoungTheTokens();
+ }
+ List<TypeInfoCollector.MemberInfo> methods = infos.getMethods();
+ for (TypeInfoCollector.MemberInfo method : methods) {
+ if (name.equals(method.getName())) {
+ newMembers.add(method);
+ }
+ }
+ }
+ members = newMembers;
+ if (members != null && !members.isEmpty())
+ status.setLastResolvedToken(expr);
+ }
+ return members;
+ }
+
+ protected void resolveLastSegment(ELInvocationExpression expr,
+ List<TypeInfoCollector.MemberInfo> members,
+ ELOperandResolveStatus status,
+ boolean returnEqualedVariablesOnly, boolean varIsUsed) {
+ Set<TextProposal> kbProposals = new TreeSet<TextProposal>(TextProposal.KB_PROPOSAL_ORDER);
+
+ if (expr.getType() == ELObjectType.EL_PROPERTY_INVOCATION && ((ELPropertyInvocation)expr).getName() == null) {
+ // return all the methods + properties
+ for (TypeInfoCollector.MemberInfo mbr : members) {
+ if(isSingularMember(mbr)) {
+ processSingularMember(mbr, kbProposals);
+ continue;
+ }
+ if (mbr.getMemberType() == null) {
+ continue;
+ }
+ TypeInfoCollector infos = mbr.getTypeCollector(varIsUsed);
+ if (TypeInfoCollector.isNotParameterizedCollection(mbr) || TypeInfoCollector.isResourceBundle(mbr.getMemberType())) {
+ status.setMapOrCollectionOrBundleAmoungTheTokens();
+ }
+
+ Set<String> methodPresentations =
+ infos.getMethodPresentationStrings();
+ if (methodPresentations != null) {
+ for (String presentation : methodPresentations) {
+ TextProposal proposal = new TextProposal();
+ proposal.setReplacementString(presentation);
+ proposal.setImage(getELProposalImage());
+
+ kbProposals.add(proposal);
+ }
+ }
+ Set<String> propertyPresentations =
+ infos.getPropertyPresentationStrings(status.getUnpairedGettersOrSetters());
+ if (propertyPresentations != null) {
+ for (String presentation : propertyPresentations) {
+ TextProposal proposal = new TextProposal();
+ proposal.setReplacementString(presentation);
+ proposal.setImage(getELProposalImage());
+
+ kbProposals.add(proposal);
+ }
+ }
+ }
+ } else
+ if(expr.getType() != ELObjectType.EL_ARGUMENT_INVOCATION)
+ //actually any case
+// if (token.getType() == ELOperandToken.EL_VARIABLE_NAME_TOKEN ||
+// token.getType() == ELOperandToken.EL_PROPERTY_NAME_TOKEN ||
+// token.getType() == ELOperandToken.EL_METHOD_TOKEN)
+ {
+ // return filtered methods + properties
+ Set<TypeInfoCollector.MemberPresentation> proposalsToFilter = new TreeSet<TypeInfoCollector.MemberPresentation>(TypeInfoCollector.MEMBER_PRESENTATION_COMPARATOR);
+ for (TypeInfoCollector.MemberInfo mbr : members) {
+ if(isSingularMember(mbr)) {
+ filterSingularMember(mbr, proposalsToFilter);
+ continue;
+ }
+ if (mbr.getMemberType() == null) continue;
+ TypeInfoCollector infos = mbr.getTypeCollector();
+ if (TypeInfoCollector.isNotParameterizedCollection(mbr) || TypeInfoCollector.isResourceBundle(mbr.getMemberType())) {
+ status.setMapOrCollectionOrBundleAmoungTheTokens();
+ }
+ proposalsToFilter.addAll(infos.getMethodPresentations());
+ proposalsToFilter.addAll(infos.getPropertyPresentations(status.getUnpairedGettersOrSetters()));
+ status.setMemberOfResolvedOperand(mbr);
+ }
+ for (TypeInfoCollector.MemberPresentation proposal : proposalsToFilter) {
+ // We do expect nothing but name for method tokens (No round brackets)
+ String filter = expr.getMemberName();
+ if(filter == null) filter = "";
+ if(returnEqualedVariablesOnly) {
+ // This is used for validation.
+ if (proposal.getPresentation().equals(filter)) {
+ TextProposal kbProposal = new TextProposal();
+ kbProposal.setReplacementString(proposal.getPresentation());
+
+ setImage(kbProposal, proposal);
+
+ kbProposals.add(kbProposal);
+
+ status.setMemberOfResolvedOperand(proposal.getMember());
+ if(status.getUnpairedGettersOrSetters()!=null) {
+ TypeInfoCollector.MethodInfo unpirMethod = status.getUnpairedGettersOrSetters().get(filter);
+ status.clearUnpairedGettersOrSetters();
+ if(unpirMethod!=null) {
+ status.getUnpairedGettersOrSetters().put(filter, unpirMethod);
+ }
+ }
+ break;
+ }
+ } else if (proposal.getPresentation().startsWith(filter)) {
+ // This is used for CA.
+ TextProposal kbProposal = new TextProposal();
+ kbProposal.setReplacementString(proposal.getPresentation().substring(filter.length()));
+ kbProposal.setImage(getELProposalImage());
+
+ kbProposals.add(kbProposal);
+ }
+ }
+ } else if(expr.getType() == ELObjectType.EL_ARGUMENT_INVOCATION) {
+ Set<TypeInfoCollector.MemberPresentation> proposalsToFilter = new TreeSet<TypeInfoCollector.MemberPresentation>(TypeInfoCollector.MEMBER_PRESENTATION_COMPARATOR);
+ boolean isMessages = false;
+ for (TypeInfoCollector.MemberInfo mbr : members) {
+ if(isSingularMember(mbr)) {
+ isMessages = true;
+ filterSingularMember(mbr, proposalsToFilter);
+ continue;
+ }
+ if (mbr.getMemberType() == null) continue;
+ try {
+ if(TypeInfoCollector.isInstanceofType(mbr.getMemberType(), "java.util.Map")) {
+ status.setMapOrCollectionOrBundleAmoungTheTokens();
+ //if map/collection is parameterized, we might return member info for value type.
+ return;
+ }
+ } catch (JavaModelException jme) {
+ //ignore
+ }
+ status.setMemberOfResolvedOperand(mbr);
+ }
+
+ String filter = expr.getMemberName();
+ boolean bSurroundWithQuotes = false;
+ if(filter == null) {
+ filter = "";
+ bSurroundWithQuotes = true;
+ } else {
+ if((filter.startsWith("'") || filter.startsWith("\""))
+ && (filter.endsWith("'") || filter.endsWith("\""))) {
+ filter = filter.substring(1, filter.length() - 1);
+ } else {
+ //Value is set as expression itself, we cannot compute it
+ if(isMessages) status.setMapOrCollectionOrBundleAmoungTheTokens();
+ return;
+ }
+ }
+
+ for (TypeInfoCollector.MemberPresentation proposal : proposalsToFilter) {
+ if(returnEqualedVariablesOnly) {
+ // This is used for validation.
+ if (proposal.getPresentation().equals(filter)) {
+ TextProposal kbProposal = new TextProposal();
+ kbProposal.setReplacementString(proposal.getPresentation());
+
+ setImage(kbProposal, proposal);
+
+ kbProposals.add(kbProposal);
+
+ status.setMemberOfResolvedOperand(proposal.getMember());
+ if(status.getUnpairedGettersOrSetters()!=null) {
+ TypeInfoCollector.MethodInfo unpirMethod = status.getUnpairedGettersOrSetters().get(filter);
+ status.clearUnpairedGettersOrSetters();
+ if(unpirMethod!=null) {
+ status.getUnpairedGettersOrSetters().put(filter, unpirMethod);
+ }
+ }
+ break;
+ }
+ } else if (proposal.getPresentation().startsWith(filter)) {
+ // This is used for CA.
+ TextProposal kbProposal = new TextProposal();
+
+ String replacementString = proposal.getPresentation().substring(filter.length());
+ if (bSurroundWithQuotes) {
+ replacementString = "'" + replacementString + "']";
+ }
+
+ kbProposal.setReplacementString(replacementString);
+ kbProposal.setImage(getELProposalImage());
+
+ kbProposals.add(kbProposal);
+ }
+ }
+ }
+ status.setProposals(kbProposals);
+ if (status.isOK()){
+ status.setLastResolvedToken(expr);
+ }
+ }
+
+ protected boolean isSingularMember(TypeInfoCollector.MemberInfo mbr) {
+ return false;
+ }
+
+ protected void processSingularMember(TypeInfoCollector.MemberInfo mbr, Set<TextProposal> kbProposals) {
+ }
+
+ protected void filterSingularMember(TypeInfoCollector.MemberInfo mbr, Set<TypeInfoCollector.MemberPresentation> proposalsToFilter) {
+ }
+
+ protected void setImage(TextProposal kbProposal, TypeInfoCollector.MemberPresentation proposal) {
+ kbProposal.setImage(getELProposalImage());
+ }
+
+ protected void setImage(TextProposal kbProposal, V var) {
+ kbProposal.setImage(getELProposalImage());
+ }
+
+}
Property changes on: trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/AbstractELCompletionEngine.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
15 years, 6 months
JBoss Tools SVN: r16120 - trunk/smooks/docs/reference/en/images/config_page.
by jbosstools-commits@lists.jboss.org
Author: chukhutsina
Date: 2009-06-22 12:49:18 -0400 (Mon, 22 Jun 2009)
New Revision: 16120
Added:
trunk/smooks/docs/reference/en/images/config_page/config_page2a.png
trunk/smooks/docs/reference/en/images/config_page/config_page2b.png
Log:
<html><head><meta name="qrichtext" content="1" /></head><body style="font-size:9pt;font-family:Sans Serif">
<p>https://jira.jboss.org/jira/browse/JBDS-755 -Added the describtion of selector generate dialog to the guide.</p>
</body></html>
Added: trunk/smooks/docs/reference/en/images/config_page/config_page2a.png
===================================================================
(Binary files differ)
Property changes on: trunk/smooks/docs/reference/en/images/config_page/config_page2a.png
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: trunk/smooks/docs/reference/en/images/config_page/config_page2b.png
===================================================================
(Binary files differ)
Property changes on: trunk/smooks/docs/reference/en/images/config_page/config_page2b.png
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
15 years, 6 months
JBoss Tools SVN: r16119 - trunk/smooks/docs/reference/en/modules.
by jbosstools-commits@lists.jboss.org
Author: chukhutsina
Date: 2009-06-22 12:45:57 -0400 (Mon, 22 Jun 2009)
New Revision: 16119
Modified:
trunk/smooks/docs/reference/en/modules/smooksformeditor_configurationpage.xml
Log:
<html><head><meta name="qrichtext" content="1" /></head><body style="font-size:9pt;font-family:Sans Serif">
<p>https://jira.jboss.org/jira/browse/JBDS-755 -Added the describtion of Selector generate dialog to the Smooks-guide</p>
</body></html>
Modified: trunk/smooks/docs/reference/en/modules/smooksformeditor_configurationpage.xml
===================================================================
--- trunk/smooks/docs/reference/en/modules/smooksformeditor_configurationpage.xml 2009-06-22 15:53:38 UTC (rev 16118)
+++ trunk/smooks/docs/reference/en/modules/smooksformeditor_configurationpage.xml 2009-06-22 16:45:57 UTC (rev 16119)
@@ -40,7 +40,36 @@
<para> The configuration editor also edits the <link linkend="configurationpage_parsetype">Smooks parse
type</link> and manages the <link linkend="configurationpage_importfile">Import
Files</link>.</para>
-
+ <section id="selector-dialog">
+ <title>Selector generate dialog</title>
+ <para>Using <emphasis>
+ <property>Selector generate dialog</property></emphasis> you can allow the user to select a node for generation <property>"selector"</property> for smooks-config file.
+ To open the dialog you should left click <property>Browse</property> button in <emphasis>
+ <property>Default Selector</property></emphasis> section.
+ </para>
+ <figure>
+ <title>Selector generate dialog</title>
+ <mediaobject>
+ <imageobject>
+ <imagedata fileref="images/config_page/config_page2a.png" scale="90"/>
+ </imageobject>
+ </mediaobject>
+ </figure>
+ <para> When the dialog is opened you should click <property>"Click to add input data"</property>to set the selector.
+ In the opened <emphasis>
+ <property>Data Type Selection</property></emphasis> Wizard you should choose the type of the file and the file itself you want to load to the <emphasis>
+ <property>Selector generate dialog</property></emphasis>.After that your dialog should look nearly like that:</para>
+ <figure>
+ <title>Selector generate dialog</title>
+ <mediaobject>
+ <imageobject>
+ <imagedata fileref="images/config_page/config_page2b.png" scale="90"/>
+ </imageobject>
+ </mediaobject>
+ </figure>
+ <para>The final step is to choose the node you want to make a selector for <emphasis>
+ <property>smooks-config.xml</property></emphasis>.</para>
+ </section>
<section id="configurationpage_parsetype">
<title>Smooks Parse Type</title>
15 years, 6 months
JBoss Tools SVN: r16118 - trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/model.
by jbosstools-commits@lists.jboss.org
Author: vyemialyanchyk
Date: 2009-06-22 11:53:38 -0400 (Mon, 22 Jun 2009)
New Revision: 16118
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/model/Shape.java
Log:
https://jira.jboss.org/jira/browse/JBIDE-4499 - exception fix
Modified: trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/model/Shape.java
===================================================================
--- trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/model/Shape.java 2009-06-22 15:53:30 UTC (rev 16117)
+++ trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/model/Shape.java 2009-06-22 15:53:38 UTC (rev 16118)
@@ -221,109 +221,130 @@
* @see #getPropertyDescriptors()
*/
public Object getPropertyValue(Object propertyId) {
+ Object res = null;
+ Column col = null;
+ if (getOrmElement() instanceof Column) {
+ col = (Column)getOrmElement();
+ }
+ Property prop = null;
+ if (getOrmElement() instanceof Property) {
+ prop = (Property)getOrmElement();
+ }
if (PROPERTY_NAME.equals(propertyId)) {
- if (getOrmElement() instanceof Property) {
- return ((Property) getOrmElement()).getName();
+ if (prop != null) {
+ res = prop.getName();
}
- else if (getOrmElement() instanceof Column) {
- return ((Column) getOrmElement()).getName();
+ else if (col != null) {
+ res = col.getName();
}
}
else if (PROPERTY_TYPE.equals(propertyId)) {
- if (getOrmElement() instanceof Property) {
- Value value = ((Property) getOrmElement()).getValue();
- if (value instanceof Component) return ((Property) getOrmElement()).getValue().toString();
- return ((Property) getOrmElement()).getType().getReturnedClass().getName();
+ if (prop != null) {
+ Value value = prop.getValue();
+ if (value instanceof Component) {
+ res = prop.getValue().toString();
+ }
+ else {
+ res = prop.getType().getReturnedClass().getName();
+ }
}
- else if (getOrmElement() instanceof Column) {
- String type = ormModelNameVisitor.getColumnSqlType((Column) getOrmElement(), getOrmDiagram().getConsoleConfig());
- Column column = (Column) getOrmElement();
+ else if (col != null) {
+ String type = ormModelNameVisitor.getColumnSqlType(col, getOrmDiagram().getConsoleConfig());
StringBuffer name = new StringBuffer();
if (type != null) {
name.append(type.toUpperCase());
- name.append(HibernateUtils.getTable(column) != null
- && HibernateUtils.isPrimaryKey(column) ? " PK" : ""); //$NON-NLS-1$ //$NON-NLS-2$
- name.append(HibernateUtils.getTable(column) != null
- && HibernateUtils.isForeignKey(column) ? " FK" : ""); //$NON-NLS-1$ //$NON-NLS-2$
+ name.append(HibernateUtils.getTable(col) != null
+ && HibernateUtils.isPrimaryKey(col) ? " PK" : ""); //$NON-NLS-1$ //$NON-NLS-2$
+ name.append(HibernateUtils.getTable(col) != null
+ && HibernateUtils.isForeignKey(col) ? " FK" : ""); //$NON-NLS-1$ //$NON-NLS-2$
}
- return name.toString();
+ res = name.toString();
}
}
else if (PROPERTY_VALUE.equals(propertyId)) {
- if (getOrmElement() instanceof Property) {
- return ((Property) getOrmElement()).getValue().toString();
+ if (prop != null) {
+ res = prop.getValue().toString();
}
else if (getOrmElement() instanceof Column) {
- return ((Column) getOrmElement()).getValue().toString();
+ res = col.getValue().toString();
}
}
else if (PROPERTY_CLASS.equals(propertyId)) {
- if (getOrmElement() instanceof Property) {
- if (((Property) getOrmElement()).getPersistentClass() != null)
- return ((Property) getOrmElement()).getPersistentClass().getClassName();
- else
- return null;
+ if (prop != null) {
+ if (prop.getPersistentClass() != null) {
+ res = prop.getPersistentClass().getClassName();
+ }
}
}
else if (PROPERTY_SELECT.equals(propertyId)) {
- if (getOrmElement() instanceof Property) {
- return Boolean.valueOf(((Property) getOrmElement()).isSelectable()).toString();
+ if (prop != null) {
+ res = Boolean.valueOf(prop.isSelectable()).toString();
}
}
else if (PROPERTY_INSERT.equals(propertyId)) {
- if (getOrmElement() instanceof Property) {
- return Boolean.valueOf(((Property) getOrmElement()).isInsertable()).toString();
+ if (prop != null) {
+ res = Boolean.valueOf(prop.isInsertable()).toString();
}
}
else if (PROPERTY_UPDATE.equals(propertyId)) {
- if (getOrmElement() instanceof Property) {
- return Boolean.valueOf(((Property) getOrmElement()).isUpdateable()).toString();
+ if (prop != null) {
+ res = Boolean.valueOf(prop.isUpdateable()).toString();
}
}
else if (PROPERTY_CASCADE.equals(propertyId)) {
- if (getOrmElement() instanceof Property) {
- return ((Property) getOrmElement()).getCascade();
+ if (prop != null) {
+ res = prop.getCascade();
}
}
else if (PROPERTY_LAZY.equals(propertyId)) {
- if (getOrmElement() instanceof Property) {
- return Boolean.valueOf(((Property) getOrmElement()).isLazy()).toString();
+ if (prop != null) {
+ res = Boolean.valueOf(prop.isLazy()).toString();
}
}
else if (PROPERTY_OPTIONAL.equals(propertyId)) {
- if (getOrmElement() instanceof Property) {
- return Boolean.valueOf(((Property) getOrmElement()).isOptional()).toString();
+ if (prop != null) {
+ res = Boolean.valueOf(prop.isOptional()).toString();
}
}
else if (PROPERTY_NATURAL_IDENTIFIER.equals(propertyId)) {
- if (getOrmElement() instanceof Property) {
- return Boolean.valueOf(((Property) getOrmElement()).isNaturalIdentifier()).toString();
+ if (prop != null) {
+ res = Boolean.valueOf(prop.isNaturalIdentifier()).toString();
}
}
else if (PROPERTY_NODE_NAME.equals(propertyId)) {
- if (getOrmElement() instanceof Property) {
- return ((Property) getOrmElement()).getNodeName();
+ if (prop != null) {
+ res = prop.getNodeName();
}
}
else if (PROPERTY_OPTIMISTIC_LOCKED.equals(propertyId)) {
- if (getOrmElement() instanceof Property) {
- return Boolean.valueOf(((Property) getOrmElement()).isOptimisticLocked()).toString();
+ if (prop != null) {
+ res = Boolean.valueOf(prop.isOptimisticLocked()).toString();
}
}
else if (PROPERTY_NULLABLE.equals(propertyId)) {
- if (getOrmElement() instanceof Column) {
- return Boolean.valueOf(((Column) getOrmElement()).isNullable()).toString();
+ if (col != null) {
+ res = Boolean.valueOf(col.isNullable()).toString();
}
}
else if (PROPERTY_UNIQUE.equals(propertyId)) {
- if (getOrmElement() instanceof Column) {
- return Boolean.valueOf(((Column) getOrmElement()).isUnique()).toString();
+ if (col != null) {
+ res = Boolean.valueOf(col.isUnique()).toString();
}
}
- return super.getPropertyValue(propertyId);
+ if (res == null) {
+ res = super.getPropertyValue(propertyId);
+ }
+ return toEmptyStr(res);
}
+
+ protected Object toEmptyStr(Object obj) {
+ if (obj == null) {
+ return ""; //$NON-NLS-1$
+ }
+ return obj;
+ }
}
15 years, 6 months
JBoss Tools SVN: r16117 - in trunk/freemarker/plugins/org.jboss.ide.eclipse.freemarker: META-INF and 1 other directory.
by jbosstools-commits@lists.jboss.org
Author: nickboldt
Date: 2009-06-22 11:53:30 -0400 (Mon, 22 Jun 2009)
New Revision: 16117
Modified:
trunk/freemarker/plugins/org.jboss.ide.eclipse.freemarker/META-INF/MANIFEST.MF
trunk/freemarker/plugins/org.jboss.ide.eclipse.freemarker/build.properties
Log:
revert: put back nested jar due to test failures
Modified: trunk/freemarker/plugins/org.jboss.ide.eclipse.freemarker/META-INF/MANIFEST.MF
===================================================================
--- trunk/freemarker/plugins/org.jboss.ide.eclipse.freemarker/META-INF/MANIFEST.MF 2009-06-22 15:03:51 UTC (rev 16116)
+++ trunk/freemarker/plugins/org.jboss.ide.eclipse.freemarker/META-INF/MANIFEST.MF 2009-06-22 15:53:30 UTC (rev 16117)
@@ -12,6 +12,7 @@
org.eclipse.ui.workbench.texteditor,
org.eclipse.core.resources,
org.apache.ant,
+ org.junit,
org.eclipse.ui.views,
org.eclipse.ui.ide,
org.eclipse.ui.console,
@@ -19,7 +20,7 @@
org.eclipse.jdt.core,
org.eclipse.jdt.ui
Eclipse-AutoStart: true
-Bundle-ClassPath: .,
+Bundle-ClassPath: freemarker-ide.jar,
freemarker-2.3.8.jar
Bundle-Vendor: %providerName
Export-Package: freemarker.core,
Modified: trunk/freemarker/plugins/org.jboss.ide.eclipse.freemarker/build.properties
===================================================================
--- trunk/freemarker/plugins/org.jboss.ide.eclipse.freemarker/build.properties 2009-06-22 15:03:51 UTC (rev 16116)
+++ trunk/freemarker/plugins/org.jboss.ide.eclipse.freemarker/build.properties 2009-06-22 15:53:30 UTC (rev 16117)
@@ -1,3 +1,6 @@
+source.freemarker-ide.jar = src/
+output.freemarker-ide.jar = bin/
+jars.compile.order = freemarker-ide.jar
bin.includes = plugin.*,\
freemarker-ide.jar,\
META-INF/,\
15 years, 6 months
JBoss Tools SVN: r16116 - trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console.
by jbosstools-commits@lists.jboss.org
Author: dgeraskov
Date: 2009-06-22 11:03:51 -0400 (Mon, 22 Jun 2009)
New Revision: 16116
Modified:
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/HibernateConsoleMessages.properties
Log:
https://jira.jboss.org/jira/browse/JBIDE-3457
message updated
Modified: trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/HibernateConsoleMessages.properties
===================================================================
--- trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/HibernateConsoleMessages.properties 2009-06-22 15:03:42 UTC (rev 16115)
+++ trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/HibernateConsoleMessages.properties 2009-06-22 15:03:51 UTC (rev 16116)
@@ -215,7 +215,7 @@
NewHibernateMappingFileWizard_create_new_xml_mapping_file=Create new XML Mapping files.
NewHibernateMappingFileWizard_creating=Creating
NewHibernateMappingFileWizard_error=Must use WizardDialog implementation as WizardContainer
-NewHibernateMappingFileWizard_finding_dependent_cu=Finding dependent compilation units...
+NewHibernateMappingFileWizard_finding_dependent_cu=Search for dependent compilation units...
NewHibernateMappingFileWizard_opening_file_for_editing=Opening file for editing...
NewHibernateMappingFileWizard_selection_cant_be_empty=Selection can't be empty
NewReverseEngineeringFileWizard_create_hibernate_reverse_engineering_file=Create Hibernate Reverse Engineering file (reveng.xml)
15 years, 6 months
JBoss Tools SVN: r16115 - trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/model.
by jbosstools-commits@lists.jboss.org
Author: vyemialyanchyk
Date: 2009-06-22 11:03:42 -0400 (Mon, 22 Jun 2009)
New Revision: 16115
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/model/OrmDiagram.java
Log:
https://jira.jboss.org/jira/browse/JBIDE-4506 - use sort order for ormElements
Modified: trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/model/OrmDiagram.java
===================================================================
--- trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/model/OrmDiagram.java 2009-06-22 14:31:07 UTC (rev 16114)
+++ trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/model/OrmDiagram.java 2009-06-22 15:03:42 UTC (rev 16115)
@@ -51,6 +51,9 @@
import org.jboss.tools.hibernate.ui.veditor.VisualEditorPlugin;
import org.jboss.tools.hibernate.ui.view.views.HibernateUtils;
+import sun.misc.Compare;
+import sun.misc.Sort;
+
public class OrmDiagram extends ModelElement {
public static final String REFRESH = "refresh"; //$NON-NLS-1$
@@ -82,6 +85,9 @@
this.consoleConfig = consoleConfig;
ormElements = new RootClass[ioe.length];
System.arraycopy(ioe, 0, ormElements, 0, ioe.length);
+ // should sort elements - cause different sort order gives different file name
+ // for the same thing
+ Sort.quicksort(ormElements, new OrmElCompare());
entityNames = new String[ioe.length];
for (int i = 0; i < ormElements.length; i++) {
entityNames[i] = ormElements[i].getEntityName();
@@ -94,7 +100,17 @@
load();
setDirty(false);
}
+
+ protected class OrmElCompare implements Compare {
+ public int doCompare(Object arg0, Object arg1) {
+ RootClass rc0 = (RootClass)arg0;
+ RootClass rc1 = (RootClass)arg1;
+ return rc0.getNodeName().compareTo(rc1.getNodeName());
+ }
+
+ }
+
/**
* It has no parent
*/
15 years, 6 months
JBoss Tools SVN: r16114 - in trunk/jsf/plugins/org.jboss.tools.jsf: META-INF and 5 other directories.
by jbosstools-commits@lists.jboss.org
Author: scabanovich
Date: 2009-06-22 10:31:07 -0400 (Mon, 22 Jun 2009)
New Revision: 16114
Added:
trunk/jsf/plugins/org.jboss.tools.jsf/images/
trunk/jsf/plugins/org.jboss.tools.jsf/images/ca/
trunk/jsf/plugins/org.jboss.tools.jsf/images/ca/icons_JSF_EL.gif
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/model/JSFELCompletionEngine.java
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf/META-INF/MANIFEST.MF
trunk/jsf/plugins/org.jboss.tools.jsf/build.properties
trunk/jsf/plugins/org.jboss.tools.jsf/plugin.xml
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/JSFModelPlugin.java
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/model/pv/JSFProjectBean.java
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/model/pv/JSFPromptingProvider.java
Log:
https://jira.jboss.org/jira/browse/JBIDE-2808
Initial implementation of ELResolver for JSF
Modified: trunk/jsf/plugins/org.jboss.tools.jsf/META-INF/MANIFEST.MF
===================================================================
--- trunk/jsf/plugins/org.jboss.tools.jsf/META-INF/MANIFEST.MF 2009-06-22 14:03:41 UTC (rev 16113)
+++ trunk/jsf/plugins/org.jboss.tools.jsf/META-INF/MANIFEST.MF 2009-06-22 14:31:07 UTC (rev 16114)
@@ -30,6 +30,7 @@
org.jboss.tools.jsf.web.pattern
Require-Bundle: org.jboss.tools.jst.web;visibility:=reexport,
org.jboss.tools.jst.web.kb;visibility:=reexport,
+ org.jboss.tools.common.el.core,
org.eclipse.ui.ide,
org.eclipse.ui.views,
org.eclipse.jface.text,
Modified: trunk/jsf/plugins/org.jboss.tools.jsf/build.properties
===================================================================
--- trunk/jsf/plugins/org.jboss.tools.jsf/build.properties 2009-06-22 14:03:41 UTC (rev 16113)
+++ trunk/jsf/plugins/org.jboss.tools.jsf/build.properties 2009-06-22 14:31:07 UTC (rev 16114)
@@ -5,5 +5,6 @@
plugin.properties,\
about.html,\
dtds/,\
- jsf.jar
+ jsf.jar,\
+ images/
jars.compile.order = jsf.jar
Added: trunk/jsf/plugins/org.jboss.tools.jsf/images/ca/icons_JSF_EL.gif
===================================================================
(Binary files differ)
Property changes on: trunk/jsf/plugins/org.jboss.tools.jsf/images/ca/icons_JSF_EL.gif
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Modified: trunk/jsf/plugins/org.jboss.tools.jsf/plugin.xml
===================================================================
--- trunk/jsf/plugins/org.jboss.tools.jsf/plugin.xml 2009-06-22 14:03:41 UTC (rev 16113)
+++ trunk/jsf/plugins/org.jboss.tools.jsf/plugin.xml 2009-06-22 14:31:07 UTC (rev 16114)
@@ -423,4 +423,11 @@
</catalogContribution>
</extension>
+ <extension
+ point="org.jboss.tools.common.el.core.elResolver">
+ <el-resolver id="jsfELResolver">
+ <project-nature id="org.jboss.tools.jsf.jsfnature"
+ resolver-class="org.jboss.tools.jsf.model.JSFELCompletionEngine"/>
+ </el-resolver>
+ </extension>
</plugin>
Modified: trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/JSFModelPlugin.java
===================================================================
--- trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/JSFModelPlugin.java 2009-06-22 14:03:41 UTC (rev 16113)
+++ trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/JSFModelPlugin.java 2009-06-22 14:31:07 UTC (rev 16114)
@@ -6,10 +6,14 @@
*/
package org.jboss.tools.jsf;
+import java.util.HashMap;
import java.util.Properties;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.jboss.tools.common.log.BaseUIPlugin;
import org.jboss.tools.common.log.IPluginLog;
import org.jboss.tools.common.model.XModel;
@@ -27,6 +31,11 @@
public class JSFModelPlugin extends BaseUIPlugin {
public static final String PLUGIN_ID = "org.jboss.tools.jsf";
+ public static final String CA_JSF_EL_IMAGE_PATH = "images/ca/icons_JSF_EL.gif";
+
+ // A Map to save a descriptor for each image
+ private HashMap fImageDescRegistry = null;
+
public JSFModelPlugin() {
super();
INSTANCE = this;
@@ -88,4 +97,104 @@
return getDefault();
}
+ /**
+ * Creates an image from the given resource and adds the image to the
+ * image registry.
+ *
+ * @param resource
+ * @return Image
+ */
+ private Image createImage(String resource) {
+ ImageDescriptor desc = getImageDescriptorFromRegistry(resource);
+ Image image = null;
+
+ if (desc != null) {
+ image = desc.createImage();
+ // dont add the missing image descriptor image to the image
+ // registry
+ if (!desc.equals(ImageDescriptor.getMissingImageDescriptor())) {
+ getImageRegistry().put(resource, image);
+ }
+ }
+ return image;
+ }
+
+ /**
+ * Creates an image descriptor from the given imageFilePath and adds the
+ * image descriptor to the image descriptor registry. If an image
+ * descriptor could not be created, the default "missing" image descriptor
+ * is returned but not added to the image descriptor registry.
+ *
+ * @param imageFilePath
+ * @return ImageDescriptor image descriptor for imageFilePath or default
+ * "missing" image descriptor if resource could not be found
+ */
+ private ImageDescriptor createImageDescriptor(String imageFilePath) {
+ ImageDescriptor imageDescriptor = AbstractUIPlugin.imageDescriptorFromPlugin(PLUGIN_ID, imageFilePath);
+ if (imageDescriptor != null) {
+ getImageDescriptorRegistry().put(imageFilePath, imageDescriptor);
+ }
+ else {
+ imageDescriptor = ImageDescriptor.getMissingImageDescriptor();
+ }
+
+ return imageDescriptor;
+ }
+
+ /**
+ * Retrieves the image associated with resource from the image registry.
+ * If the image cannot be retrieved, attempt to find and load the image at
+ * the location specified in resource.
+ *
+ * @param resource
+ * the image to retrieve
+ * @return Image the image associated with resource or null if one could
+ * not be found
+ */
+ public Image getImage(String resource) {
+ Image image = getImageRegistry().get(resource);
+ if (image == null) {
+ // create an image
+ image = createImage(resource);
+ }
+ return image;
+ }
+
+ /**
+ * Retrieves the image descriptor associated with resource from the image
+ * descriptor registry. If the image descriptor cannot be retrieved,
+ * attempt to find and load the image descriptor at the location specified
+ * in resource.
+ *
+ * @param resource
+ * the image descriptor to retrieve
+ * @return ImageDescriptor the image descriptor assocated with resource or
+ * the default "missing" image descriptor if one could not be
+ * found
+ */
+ public ImageDescriptor getImageDescriptorFromRegistry(String resource) {
+ ImageDescriptor imageDescriptor = null;
+ Object o = getImageDescriptorRegistry().get(resource);
+ if (o == null) {
+ // create a descriptor
+ imageDescriptor = createImageDescriptor(resource);
+ }
+ else {
+ imageDescriptor = (ImageDescriptor) o;
+ }
+ return imageDescriptor;
+ }
+
+ /**
+ * Returns the image descriptor registry for this plugin.
+ *
+ * @return HashMap - image descriptor registry for this plugin
+ */
+ private HashMap getImageDescriptorRegistry() {
+ if (fImageDescRegistry == null) {
+ fImageDescRegistry = new HashMap();
+ }
+ return fImageDescRegistry;
+ }
+
}
Added: trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/model/JSFELCompletionEngine.java
===================================================================
--- trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/model/JSFELCompletionEngine.java (rev 0)
+++ trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/model/JSFELCompletionEngine.java 2009-06-22 14:31:07 UTC (rev 16114)
@@ -0,0 +1,684 @@
+/*******************************************************************************
+ * 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.jsf.model;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+import java.util.TreeSet;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.jdt.core.IMember;
+import org.eclipse.jdt.core.IType;
+import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.swt.graphics.Image;
+import org.jboss.tools.common.el.core.model.ELArgumentInvocation;
+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.ELMethodInvocation;
+import org.jboss.tools.common.el.core.model.ELModel;
+import org.jboss.tools.common.el.core.model.ELObjectType;
+import org.jboss.tools.common.el.core.model.ELPropertyInvocation;
+import org.jboss.tools.common.el.core.parser.ELParser;
+import org.jboss.tools.common.el.core.parser.ELParserFactory;
+import org.jboss.tools.common.el.core.parser.ELParserUtil;
+import org.jboss.tools.common.el.core.parser.LexicalToken;
+import org.jboss.tools.common.el.core.resolver.ELCompletionEngine;
+import org.jboss.tools.common.el.core.resolver.ELContext;
+import org.jboss.tools.common.el.core.resolver.ELOperandResolveStatus;
+import org.jboss.tools.common.el.core.resolver.ELResolver;
+import org.jboss.tools.common.el.core.resolver.ElVarSearcher;
+import org.jboss.tools.common.el.core.resolver.TypeInfoCollector;
+import org.jboss.tools.common.el.core.resolver.Var;
+import org.jboss.tools.common.model.project.IModelNature;
+import org.jboss.tools.common.model.util.EclipseResourceUtil;
+import org.jboss.tools.common.text.TextProposal;
+import org.jboss.tools.jsf.JSFModelPlugin;
+import org.jboss.tools.jsf.model.pv.JSFPromptingProvider;
+import org.jboss.tools.jst.web.kb.IPageContext;
+
+/**
+ * Utility class used to collect info for EL
+ *
+ * @author Viacheslav Kabanovich
+ */
+public class JSFELCompletionEngine implements ELResolver, ELCompletionEngine {
+ private static final Image JSF_EL_PROPOSAL_IMAGE = JSFModelPlugin.getDefault().getImage(JSFModelPlugin.CA_JSF_EL_IMAGE_PATH);
+
+ public Image getELProposalImage() {
+ return JSF_EL_PROPOSAL_IMAGE;
+ }
+
+ private static ELParserFactory factory = ELParserUtil.getDefaultFactory();
+
+ //copied
+ public List<TextProposal> getCompletions(String elString,
+ boolean returnEqualedVariablesOnly, int position, ELContext context) {
+ IDocument document = null;
+ if(context instanceof IPageContext) {
+ IPageContext pageContext = (IPageContext)context;
+ document = pageContext.getDocument();
+ }
+ List<Var> vars = new ArrayList<Var>();
+ Var[] array = context.getVars();
+ for (int i = 0; i < array.length; i++) {
+ vars.add(array[i]);
+ }
+ List<TextProposal> proposals = null;
+ try {
+ proposals = getCompletions(context.getResource(), document, elString.subSequence(0, elString.length()), position, returnEqualedVariablesOnly, vars);
+ } catch (StringIndexOutOfBoundsException e) {
+ JSFModelPlugin.getPluginLog().logError(e);
+ } catch (BadLocationException e) {
+ JSFModelPlugin.getPluginLog().logError(e);
+ }
+ return proposals;
+ }
+
+ //copied
+ public List<TextProposal> getCompletions(IFile file, IDocument document, CharSequence prefix,
+ int position, boolean returnEqualedVariablesOnly, List<Var> vars) throws BadLocationException, StringIndexOutOfBoundsException {
+ List<TextProposal> completions = new ArrayList<TextProposal>();
+
+ ELOperandResolveStatus status = resolveELOperand(file, parseOperand("" + prefix), returnEqualedVariablesOnly, vars, new ElVarSearcher(file, this));
+ if (status.isOK()) {
+ completions.addAll(status.getProposals());
+ }
+
+ return completions;
+ }
+
+ //copied
+ public ELExpression parseOperand(String operand) {
+ if(operand == null) return null;
+ String el = (operand.indexOf("#{") < 0 && operand.indexOf("${") < 0) ? "#{" + operand + "}" : operand;
+ ELParser p = factory.createParser();
+ ELModel model = p.parse(el);
+ List<ELInstance> is = model.getInstances();
+ if(is.isEmpty()) return null;
+ return is.get(0).getExpression();
+ }
+
+ public ELOperandResolveStatus resolveELOperand(ELExpression operand,
+ ELContext context, boolean returnEqualedVariablesOnly) {
+ return null;
+ }
+
+ public ELParserFactory getParserFactory() {
+ return factory;
+ }
+
+ //copied
+ private static final String collectionAdditionForCollectionDataModel = ".iterator().next()";
+ private static final String collectionAdditionForMapDataModel = ".entrySet().iterator().next()";
+
+ //copied
+ public ELOperandResolveStatus resolveELOperand(IFile file,
+ ELExpression operand, boolean returnEqualedVariablesOnly,
+ List<Var> vars, ElVarSearcher varSearcher)
+ throws BadLocationException, StringIndexOutOfBoundsException {
+ if(operand == null) {
+ //TODO
+ return new ELOperandResolveStatus(null);
+ }
+ String oldEl = operand.getText();
+ Var var = varSearcher.findVarForEl(oldEl, vars, true);
+ String suffix = "";
+ String newEl = oldEl;
+ TypeInfoCollector.MemberInfo member = null;
+ boolean isArray = false;
+ if(var!=null) {
+ member = resolveJSFEL(file, var.getElToken(), true);
+ if(member!=null) {
+ if(!member.getType().isArray()) {
+ IType type = member.getMemberType();
+ if(type!=null) {
+ try {
+ if(TypeInfoCollector.isInstanceofType(type, "java.util.Map")) {
+ suffix = collectionAdditionForMapDataModel;
+ } else if(TypeInfoCollector.isInstanceofType(type, "java.util.Collection")) {
+ suffix = collectionAdditionForCollectionDataModel;
+ }
+ } catch (JavaModelException e) {
+ JSFModelPlugin.getPluginLog().logError(e);
+ }
+ }
+ } else {
+ isArray = true;
+ }
+ }
+ if(var.getElToken() != null) {
+ newEl = var.getElToken().getText() + suffix + oldEl.substring(var.getName().length());
+ }
+ }
+ boolean prefixWasChanged = !oldEl.equals(newEl);
+ if(prefixWasChanged && isArray) {
+ member.setDataModel(true);
+ }
+ ELExpression newOperand = (prefixWasChanged) ? parseOperand(newEl) : operand;
+
+ ELOperandResolveStatus status = resolveELOperand(file, newOperand, returnEqualedVariablesOnly, prefixWasChanged);
+
+ if(prefixWasChanged) {
+ ELInvocationExpression newLastResolvedToken = status.getLastResolvedToken();
+ status.setTokens((ELInvocationExpression)operand);
+ if(newLastResolvedToken != null) {
+ if(status.getUnresolvedTokens() != null
+ && status.getUnresolvedTokens().getInvocationStartPosition() - status.getUnresolvedTokens().getStartPosition() < var.getElToken().getLength() + suffix.length()) {
+ // Last resolved token is token from "var". Set first token of original EL as last resolved one.
+ status.setLastResolvedToken(null);
+ } else {
+ // Last resolved token is token outside "var" prefix. Correct last resolved token.
+ int oldLastResolvedTokenStart = newLastResolvedToken.getInvocationStartPosition() - var.getElToken().getText().length() - suffix.length() + var.getName().length();
+ if(newLastResolvedToken.getLeft() == null) {
+ //In this case we do not need to take into account difference in length of var and its expression.
+ oldLastResolvedTokenStart = newLastResolvedToken.getInvocationStartPosition();
+ }
+ ELInvocationExpression l = (ELInvocationExpression)operand;
+ while(l != null) {
+ if(l.getInvocationStartPosition() - l.getStartPosition() <= oldLastResolvedTokenStart) {
+ status.setLastResolvedToken(l);
+ break;
+ }
+ l = l.getLeft();
+ }
+ }
+ }
+ }
+
+ if(prefixWasChanged) {
+ var.resolveValue("#{" + var.getElToken().getText() + suffix + "}");
+ }
+
+ if(!returnEqualedVariablesOnly && vars!=null) {
+ List<String> varNameProposals = getVarNameProposals(vars, operand.toString());
+ if (varNameProposals != null) {
+ for (String varNameProposal : varNameProposals) {
+ TextProposal proposal = new TextProposal();
+ proposal.setReplacementString(varNameProposal);
+ proposal.setImage(getELProposalImage());
+ status.getProposals().add(proposal);
+ }
+ }
+ }
+ return status;
+ }
+
+ //copied - JSF
+ public TypeInfoCollector.MemberInfo resolveJSFEL(IFile file, ELExpression operand, boolean varIsUsed) throws BadLocationException, StringIndexOutOfBoundsException {
+ if(!(operand instanceof ELInvocationExpression)) return null;
+ ELOperandResolveStatus status = resolveELOperand(file, operand, true, varIsUsed);
+ return status.getMemberOfResolvedOperand();
+ }
+
+ //copied
+ private List<String> getVarNameProposals(List <Var> vars, String prefix) {
+ List<String> proposals = new ArrayList<String>();
+ for (Var var : vars) {
+ if(var.getName().startsWith(prefix)) {
+ String proposal = var.getName().substring(prefix.length());
+ proposals.add(proposal);
+ }
+ }
+ return proposals;
+ }
+
+
+
+
+
+ public ELOperandResolveStatus resolveELOperand(IFile file, ELExpression operand,
+ boolean returnEqualedVariablesOnly, boolean varIsUsed) throws BadLocationException, StringIndexOutOfBoundsException {
+ if(!(operand instanceof ELInvocationExpression) || file == null) {
+ return new ELOperandResolveStatus(null);
+ }
+
+ ELInvocationExpression expr = (ELInvocationExpression)operand;
+ boolean isIncomplete = expr.getType() == ELObjectType.EL_PROPERTY_INVOCATION
+ && ((ELPropertyInvocation)expr).getName() == null;
+ boolean isArgument = expr.getType() == ELObjectType.EL_ARGUMENT_INVOCATION;
+
+ ELOperandResolveStatus status = new ELOperandResolveStatus(expr);
+ ELInvocationExpression left = expr;
+
+ List<IJSFVariable> resolvedVariables = new ArrayList<IJSFVariable>();
+ IModelNature project = EclipseResourceUtil.getModelNature(file.getProject());
+
+ if (expr.getLeft() != null && isArgument) {
+ left = expr.getLeft();
+ resolvedVariables = resolveVariables(project, left, false,
+ true); // is Final and equal names are because of
+ // we have no more to resolve the parts of expression,
+ // but we have to resolve arguments of probably a message component
+ } else if (expr.getLeft() == null && isIncomplete) {
+ resolvedVariables = resolveVariables(project, expr, true,
+ returnEqualedVariablesOnly);
+ } else {
+ while(left != null) {
+ List<IJSFVariable>resolvedVars = new ArrayList<IJSFVariable>();
+ resolvedVars = resolveVariables(project,
+ left, left == expr,
+ returnEqualedVariablesOnly);
+ if (resolvedVars != null && !resolvedVars.isEmpty()) {
+ resolvedVariables = resolvedVars;
+ status.setLastResolvedToken(left);
+ break;
+ }
+ left = (ELInvocationExpression)left.getLeft();
+ }
+ }
+
+ // Save all resolved variables. It's useful for incremental validation.
+ if(resolvedVariables != null && !resolvedVariables.isEmpty()) {
+// status.setUsedVariables(resolvedVariables);
+ }
+
+ if (status.getResolvedTokens() == null &&
+ !returnEqualedVariablesOnly &&
+ expr != null &&
+ isIncomplete) {
+ // no vars are resolved
+ // the tokens are the part of var name ended with a separator (.)
+ resolvedVariables = resolveVariables(project, expr, true, returnEqualedVariablesOnly);
+ Set<TextProposal> proposals = new TreeSet<TextProposal>(TextProposal.KB_PROPOSAL_ORDER);
+ for (IJSFVariable var : resolvedVariables) {
+ String varName = var.getName();
+ if(varName.startsWith(operand.getText())) {
+ TextProposal proposal = new TextProposal();
+ proposal.setReplacementString(varName.substring(operand.getLength()));
+ {
+ proposal.setImage(getELProposalImage());
+ }
+ proposals.add(proposal);
+ }
+ }
+ status.setProposals(proposals);
+ return status;
+ }
+
+ // Here we have a list of vars for some part of expression
+ // OK. we'll proceed with members of these vars
+ if (status.getResolvedTokens() == status.getTokens()) {
+ // First segment is the last one
+ Set<TextProposal> proposals = new TreeSet<TextProposal>(TextProposal.KB_PROPOSAL_ORDER);
+ // In some cases there may be a few references to the same variable name.
+ // For example @Factory and @DataModel. We should use @DataModel instead of @Factory
+ // method which returns null.
+ // See https://jira.jboss.org/jira/browse/JBIDE-3694
+ for (IJSFVariable var : resolvedVariables) {
+ String varName = var.getName();
+ if(operand.getLength()<=varName.length()) {
+ TextProposal proposal = new TextProposal();
+ proposal.setReplacementString(varName.substring(operand.getLength()));
+ {
+ proposal.setImage(getELProposalImage());
+ }
+ proposals.add(proposal);
+ } else if(returnEqualedVariablesOnly) {
+ TextProposal proposal = new TextProposal();
+ proposal.setReplacementString(varName);
+ proposal.setImage(getELProposalImage());
+ proposals.add(proposal);
+ }
+ status.setMemberOfResolvedOperand(getMemberInfoByVariable(var, true));
+ }
+ status.setLastResolvedToken(expr);
+ status.setProposals(proposals);
+ return status;
+ }
+
+ // First segment is found - proceed with next tokens
+ List<TypeInfoCollector.MemberInfo> members = new ArrayList<TypeInfoCollector.MemberInfo>();
+ for (IJSFVariable var : resolvedVariables) {
+ TypeInfoCollector.MemberInfo member = getMemberInfoByVariable(var, returnEqualedVariablesOnly);
+ if (member != null && !members.contains(member))
+ members.add(member);
+ }
+ //process segments one by one
+ if(left != null) while(left != expr) {
+ left = (ELInvocationExpression)left.getParent();
+ if (left != expr) { // inside expression
+ if(left instanceof ELArgumentInvocation) {
+ String s = "#{" + left.getLeft().toString() + collectionAdditionForCollectionDataModel + "}";
+ ELParser p = factory.createParser();
+ ELInvocationExpression expr1 = (ELInvocationExpression)p.parse(s).getInstances().get(0).getExpression();
+ members = resolveSegment(expr1.getLeft(), members, status, returnEqualedVariablesOnly, varIsUsed);
+ members = resolveSegment(expr1, members, status, returnEqualedVariablesOnly, varIsUsed);
+ if(status.getLastResolvedToken() == expr1) {
+ status.setLastResolvedToken(left);
+ }
+ } else {
+ members = resolveSegment(left, members, status, returnEqualedVariablesOnly, varIsUsed);
+ }
+ } else { // Last segment
+ resolveLastSegment((ELInvocationExpression)operand, members, status, returnEqualedVariablesOnly, varIsUsed);
+ break;
+ }
+ }
+
+ if(status.getProposals().isEmpty() && status.getUnpairedGettersOrSetters()!=null) {
+ status.clearUnpairedGettersOrSetters();
+ }
+ return status;
+ }
+
+
+
+
+
+
+
+
+
+
+
+
+//resolving segments
+ //copied , removed MessagesInfo case
+ private List<TypeInfoCollector.MemberInfo> resolveSegment(ELInvocationExpression expr,
+ List<TypeInfoCollector.MemberInfo> members,
+ ELOperandResolveStatus status,
+ boolean returnEqualedVariablesOnly, boolean varIsUsed) {
+ LexicalToken lt = (expr instanceof ELPropertyInvocation)
+ ? ((ELPropertyInvocation)expr).getName()
+ : (expr instanceof ELMethodInvocation)
+ ? ((ELMethodInvocation)expr).getName()
+ : null;
+ String name = lt != null ? lt.getText() : ""; // token.getText();
+ if (expr.getType() == ELObjectType.EL_PROPERTY_INVOCATION) {
+ // Find properties for the token
+ List<TypeInfoCollector.MemberInfo> newMembers = new ArrayList<TypeInfoCollector.MemberInfo>();
+ for (TypeInfoCollector.MemberInfo mbr : members) {
+ if (mbr.getMemberType() == null) continue;
+ TypeInfoCollector infos = mbr.getTypeCollector(varIsUsed);
+ if (TypeInfoCollector.isNotParameterizedCollection(mbr) || TypeInfoCollector.isResourceBundle(mbr.getMemberType())) {
+ status.setMapOrCollectionOrBundleAmoungTheTokens();
+ }
+ List<TypeInfoCollector.MemberInfo> properties = infos.getProperties();
+ for (TypeInfoCollector.MemberInfo property : properties) {
+ StringBuffer propertyName = new StringBuffer(property.getName());
+ if (property instanceof TypeInfoCollector.MethodInfo) { // Setter or getter
+ propertyName.delete(0, (propertyName.charAt(0) == 'i' ? 2 : 3));
+ propertyName.setCharAt(0, Character.toLowerCase(propertyName.charAt(0)));
+ }
+ if (name.equals(propertyName.toString())) {
+ newMembers.add(property);
+ }
+ }
+ }
+ members = newMembers;
+ if (members != null && !members.isEmpty())
+ status.setLastResolvedToken(expr);
+ }
+ if (expr.getType() == ELObjectType.EL_METHOD_INVOCATION) {
+ // Find methods for the token
+ if (name.indexOf('(') != -1) {
+ name = name.substring(0, name.indexOf('('));
+ }
+ List<TypeInfoCollector.MemberInfo> newMembers = new ArrayList<TypeInfoCollector.MemberInfo>();
+ for (TypeInfoCollector.MemberInfo mbr : members) {
+ if (mbr.getMemberType() == null) continue;
+ TypeInfoCollector infos = mbr.getTypeCollector();
+ if (TypeInfoCollector.isNotParameterizedCollection(mbr) || TypeInfoCollector.isResourceBundle(mbr.getMemberType())) {
+ status.setMapOrCollectionOrBundleAmoungTheTokens();
+ }
+ List<TypeInfoCollector.MemberInfo> methods = infos.getMethods();
+ for (TypeInfoCollector.MemberInfo method : methods) {
+ if (name.equals(method.getName())) {
+ newMembers.add(method);
+ }
+ }
+ }
+ members = newMembers;
+ if (members != null && !members.isEmpty())
+ status.setLastResolvedToken(expr);
+ }
+ return members;
+ }
+
+ private void resolveLastSegment(ELInvocationExpression expr,
+ List<TypeInfoCollector.MemberInfo> members,
+ ELOperandResolveStatus status,
+ boolean returnEqualedVariablesOnly, boolean varIsUsed) {
+ Set<TextProposal> kbProposals = new TreeSet<TextProposal>(TextProposal.KB_PROPOSAL_ORDER);
+
+ if (expr.getType() == ELObjectType.EL_PROPERTY_INVOCATION && ((ELPropertyInvocation)expr).getName() == null) {
+ // return all the methods + properties
+ for (TypeInfoCollector.MemberInfo mbr : members) {
+ //removed MessagesInfo case
+ if (mbr.getMemberType() == null) {
+ continue;
+ }
+ TypeInfoCollector infos = mbr.getTypeCollector(varIsUsed);
+ if (TypeInfoCollector.isNotParameterizedCollection(mbr) || TypeInfoCollector.isResourceBundle(mbr.getMemberType())) {
+ status.setMapOrCollectionOrBundleAmoungTheTokens();
+ }
+
+ Set<String> methodPresentations =
+ infos.getMethodPresentationStrings();
+ if (methodPresentations != null) {
+ for (String presentation : methodPresentations) {
+ TextProposal proposal = new TextProposal();
+ proposal.setReplacementString(presentation);
+ proposal.setImage(getELProposalImage());
+
+ kbProposals.add(proposal);
+ }
+ }
+ Set<String> propertyPresentations =
+ infos.getPropertyPresentationStrings(status.getUnpairedGettersOrSetters());
+ if (propertyPresentations != null) {
+ for (String presentation : propertyPresentations) {
+ TextProposal proposal = new TextProposal();
+ proposal.setReplacementString(presentation);
+ proposal.setImage(getELProposalImage());
+
+ kbProposals.add(proposal);
+ }
+ }
+ }
+ } else
+ if(expr.getType() != ELObjectType.EL_ARGUMENT_INVOCATION)
+ //actually any case
+// if (token.getType() == ELOperandToken.EL_VARIABLE_NAME_TOKEN ||
+// token.getType() == ELOperandToken.EL_PROPERTY_NAME_TOKEN ||
+// token.getType() == ELOperandToken.EL_METHOD_TOKEN)
+ {
+ // return filtered methods + properties
+ Set<TypeInfoCollector.MemberPresentation> proposalsToFilter = new TreeSet<TypeInfoCollector.MemberPresentation>(TypeInfoCollector.MEMBER_PRESENTATION_COMPARATOR);
+ for (TypeInfoCollector.MemberInfo mbr : members) {
+ //removed MessagesInfo case
+ if (mbr.getMemberType() == null) continue;
+ TypeInfoCollector infos = mbr.getTypeCollector();
+ if (TypeInfoCollector.isNotParameterizedCollection(mbr) || TypeInfoCollector.isResourceBundle(mbr.getMemberType())) {
+ status.setMapOrCollectionOrBundleAmoungTheTokens();
+ }
+ proposalsToFilter.addAll(infos.getMethodPresentations());
+ proposalsToFilter.addAll(infos.getPropertyPresentations(status.getUnpairedGettersOrSetters()));
+ status.setMemberOfResolvedOperand(mbr);
+ }
+ for (TypeInfoCollector.MemberPresentation proposal : proposalsToFilter) {
+ // We do expect nothing but name for method tokens (No round brackets)
+ String filter = expr.getMemberName();
+ if(filter == null) filter = "";
+ if(returnEqualedVariablesOnly) {
+ // This is used for validation.
+ if (proposal.getPresentation().equals(filter)) {
+ TextProposal kbProposal = new TextProposal();
+ kbProposal.setReplacementString(proposal.getPresentation());
+
+ //removed MessagesInfo case
+ {
+ kbProposal.setImage(getELProposalImage());
+ }
+
+ kbProposals.add(kbProposal);
+
+ status.setMemberOfResolvedOperand(proposal.getMember());
+ if(status.getUnpairedGettersOrSetters()!=null) {
+ TypeInfoCollector.MethodInfo unpirMethod = status.getUnpairedGettersOrSetters().get(filter);
+ status.clearUnpairedGettersOrSetters();
+ if(unpirMethod!=null) {
+ status.getUnpairedGettersOrSetters().put(filter, unpirMethod);
+ }
+ }
+ break;
+ }
+ } else if (proposal.getPresentation().startsWith(filter)) {
+ // This is used for CA.
+ TextProposal kbProposal = new TextProposal();
+ kbProposal.setReplacementString(proposal.getPresentation().substring(filter.length()));
+ kbProposal.setImage(getELProposalImage());
+
+ kbProposals.add(kbProposal);
+ }
+ }
+ } else if(expr.getType() == ELObjectType.EL_ARGUMENT_INVOCATION) {
+ Set<TypeInfoCollector.MemberPresentation> proposalsToFilter = new TreeSet<TypeInfoCollector.MemberPresentation>(TypeInfoCollector.MEMBER_PRESENTATION_COMPARATOR);
+ boolean isMessages = false;
+ for (TypeInfoCollector.MemberInfo mbr : members) {
+ //removed MessagesInfo case
+ if (mbr.getMemberType() == null) continue;
+ try {
+ if(TypeInfoCollector.isInstanceofType(mbr.getMemberType(), "java.util.Map")) {
+ status.setMapOrCollectionOrBundleAmoungTheTokens();
+ //if map/collection is parameterized, we might return member info for value type.
+ return;
+ }
+ } catch (JavaModelException jme) {
+ //ignore
+ }
+ status.setMemberOfResolvedOperand(mbr);
+ }
+
+ String filter = expr.getMemberName();
+ boolean bSurroundWithQuotes = false;
+ if(filter == null) {
+ filter = "";
+ bSurroundWithQuotes = true;
+ } else {
+ if((filter.startsWith("'") || filter.startsWith("\""))
+ && (filter.endsWith("'") || filter.endsWith("\""))) {
+ filter = filter.substring(1, filter.length() - 1);
+ } else {
+ //Value is set as expression itself, we cannot compute it
+ if(isMessages) status.setMapOrCollectionOrBundleAmoungTheTokens();
+ return;
+ }
+ }
+
+ for (TypeInfoCollector.MemberPresentation proposal : proposalsToFilter) {
+ if(returnEqualedVariablesOnly) {
+ // This is used for validation.
+ if (proposal.getPresentation().equals(filter)) {
+ TextProposal kbProposal = new TextProposal();
+ kbProposal.setReplacementString(proposal.getPresentation());
+
+ //removed MessagesInfo case
+ {
+ kbProposal.setImage(getELProposalImage());
+ }
+
+ kbProposals.add(kbProposal);
+
+ status.setMemberOfResolvedOperand(proposal.getMember());
+ if(status.getUnpairedGettersOrSetters()!=null) {
+ TypeInfoCollector.MethodInfo unpirMethod = status.getUnpairedGettersOrSetters().get(filter);
+ status.clearUnpairedGettersOrSetters();
+ if(unpirMethod!=null) {
+ status.getUnpairedGettersOrSetters().put(filter, unpirMethod);
+ }
+ }
+ break;
+ }
+ } else if (proposal.getPresentation().startsWith(filter)) {
+ // This is used for CA.
+ TextProposal kbProposal = new TextProposal();
+
+ String replacementString = proposal.getPresentation().substring(filter.length());
+ if (bSurroundWithQuotes) {
+ replacementString = "'" + replacementString + "']";
+ }
+
+ kbProposal.setReplacementString(replacementString);
+ kbProposal.setImage(getELProposalImage());
+
+ kbProposals.add(kbProposal);
+ }
+ }
+ }
+ status.setProposals(kbProposals);
+ if (status.isOK()){
+ status.setLastResolvedToken(expr);
+ }
+ }
+
+ public List<IJSFVariable> resolveVariables(IModelNature project, ELInvocationExpression expr, boolean isFinal, boolean onlyEqualNames) {
+ List<IJSFVariable>resolvedVars = new ArrayList<IJSFVariable>();
+
+ if (project == null)
+ return new ArrayList<IJSFVariable>();
+
+ String varName = expr.toString();
+
+ if (varName != null) {
+ resolvedVars = resolveVariables(project, varName, onlyEqualNames);
+ }
+ if (resolvedVars != null && !resolvedVars.isEmpty()) {
+ List<IJSFVariable> newResolvedVars = new ArrayList<IJSFVariable>();
+ for (IJSFVariable var : resolvedVars) {
+ if(!isFinal) {
+ // Do filter by equals (name)
+ // In case of the last pass - do not filter by startsWith(name) instead of equals
+ if (varName.equals(var.getName())) {
+ newResolvedVars.add(var);
+ }
+ } else {
+ newResolvedVars.add(var);
+ }
+ }
+ return newResolvedVars;
+ }
+ return new ArrayList<IJSFVariable>();
+ }
+
+ List<IJSFVariable> resolveVariables(IModelNature project, String varName, boolean onlyEqualNames) {
+ if(project == null) return null;
+ List<IJSFVariable> beans = new JSFPromptingProvider().getVariables(project.getModel());
+ List<IJSFVariable> resolvedVariables = new ArrayList<IJSFVariable>();
+ for (IJSFVariable variable: beans) {
+ String n = variable.getName();
+ if(onlyEqualNames) {
+ if (n.equals(varName)) {
+ resolvedVariables.add(variable);
+ }
+ } else {
+ if (n.startsWith(varName)) {
+ resolvedVariables.add(variable);
+ }
+ }
+ }
+ return resolvedVariables;
+ }
+
+ public static interface IJSFVariable {
+ public String getName();
+ public IMember getSourceMember();
+ }
+
+ TypeInfoCollector.MemberInfo getMemberInfoByVariable(IJSFVariable var, boolean onlyEqualNames) {
+ return TypeInfoCollector.createMemberInfo(var.getSourceMember());
+ }
+
+}
Property changes on: trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/model/JSFELCompletionEngine.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/model/pv/JSFProjectBean.java
===================================================================
--- trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/model/pv/JSFProjectBean.java 2009-06-22 14:03:41 UTC (rev 16113)
+++ trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/model/pv/JSFProjectBean.java 2009-06-22 14:31:07 UTC (rev 16114)
@@ -66,6 +66,10 @@
}
}
}
+
+ public IType getType() {
+ return type;
+ }
protected void loadChildren() {
if(loaded) return;
Modified: trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/model/pv/JSFPromptingProvider.java
===================================================================
--- trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/model/pv/JSFPromptingProvider.java 2009-06-22 14:03:41 UTC (rev 16113)
+++ trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/model/pv/JSFPromptingProvider.java 2009-06-22 14:31:07 UTC (rev 16114)
@@ -16,6 +16,7 @@
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.jboss.tools.common.model.java.handlers.OpenJavaSourceHandler;
+import org.eclipse.jdt.core.IMember;
import org.eclipse.jdt.core.IType;
import org.jboss.tools.common.meta.action.XActionInvoker;
@@ -24,6 +25,7 @@
import org.jboss.tools.common.model.util.EclipseResourceUtil;
import org.jboss.tools.common.model.util.XModelObjectLoaderUtil;
import org.jboss.tools.jsf.model.JSFConstants;
+import org.jboss.tools.jsf.model.JSFELCompletionEngine;
import org.jboss.tools.jsf.model.helpers.converter.*;
import org.jboss.tools.jsf.model.helpers.pages.OpenCaseHelper;
import org.jboss.tools.jsf.model.helpers.pages.ResourceBundleHelper;
@@ -221,6 +223,47 @@
}
}
+ public List<JSFELCompletionEngine.IJSFVariable> getVariables(XModel model) {
+ List<JSFELCompletionEngine.IJSFVariable> result = new ArrayList<JSFELCompletionEngine.IJSFVariable>();
+ JSFProjectsRoot root = JSFProjectsTree.getProjectsRoot(model);
+ if(root == null) return result;
+ WebProjectNode n = (WebProjectNode)root.getChildByPath("Configuration");
+ WebProjectNode beans = (WebProjectNode)root.getChildByPath("Beans");
+ XModelObject[] os = n.getTreeChildren();
+ for (int i = 0; i < os.length; i++) {
+ if(!os[i].getModelEntity().getName().startsWith(JSFConstants.ENT_FACESCONFIG)) continue;
+ getVariables(os[i], BeanConstants.MANAGED_BEAN_CONSTANTS, beans, result);
+ getVariables(os[i], BeanConstants.REFERENCED_BEAN_CONSTANTS, beans, result);
+ }
+
+ return result;
+ }
+
+ private void getVariables(XModelObject o, BeanConstants constants, WebProjectNode beans, List<JSFELCompletionEngine.IJSFVariable> list) {
+ XModelObject mb = o.getChildByPath(constants.folder);
+ if(mb == null) return;
+ XModelObject[] bs = mb.getChildren();
+ for (XModelObject q : bs) {
+ final String name = q.getAttributeValue(constants.nameAttribute);
+ String className = q.getAttributeValue(constants.classAttribute);
+ XModelObject c = findBeanClassByClassName(beans, className);
+ if (c instanceof JSFProjectBean) {
+ JSFProjectBean b = (JSFProjectBean) c;
+ final IType type = b.getType();
+ JSFELCompletionEngine.IJSFVariable var = new JSFELCompletionEngine.IJSFVariable() {
+ public IMember getSourceMember() {
+ return type;
+ }
+
+ public String getName() {
+ return name;
+ }
+ };
+ list.add(var);
+ }
+ }
+ }
+
public List<Object> getBeanProperties(XModel model, String prefix, String type, boolean beanOnly) {
if(prefix.length() == 0) return EMPTY_LIST;
JSFProjectsRoot root = JSFProjectsTree.getProjectsRoot(model);
15 years, 6 months
JBoss Tools SVN: r16113 - trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/model.
by jbosstools-commits@lists.jboss.org
Author: vyemialyanchyk
Date: 2009-06-22 10:03:41 -0400 (Mon, 22 Jun 2009)
New Revision: 16113
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/model/OrmDiagram.java
Log:
https://jira.jboss.org/jira/browse/JBIDE-4506 - workaround for too long generated file name
Modified: trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/model/OrmDiagram.java
===================================================================
--- trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/model/OrmDiagram.java 2009-06-22 13:18:38 UTC (rev 16112)
+++ trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/model/OrmDiagram.java 2009-06-22 14:03:41 UTC (rev 16113)
@@ -15,7 +15,8 @@
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
-import java.util.ArrayList;
+import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
@@ -118,14 +119,53 @@
return getStoreFolderPath().append(getStoreFileName());
}
+ /**
+ * Generate file name to store diagram. File name consist of elements names,
+ * in case if result of elements names is too long md5sum calculated for generated name.
+ * @return
+ */
public String getStoreFileName() {
- String name = ormElements.length > 0 ? ormElements[0].getClassName() : ""; //$NON-NLS-1$
- for (int i = 1; i < ormElements.length; i++) {
- name += "_" + ormElements[i].getClassName(); //$NON-NLS-1$
+ StringBuilder name = new StringBuilder();
+ for (int i = 0; i < ormElements.length; i++) {
+ name.append("_"); //$NON-NLS-1$
+ name.append(ormElements[i].getNodeName());
}
- return consoleConfig.getName() + "_" + name; //$NON-NLS-1$
+ String res = consoleConfig.getName() + name.toString();
+ if (res.length() > 64) {
+ res = consoleConfig.getName() + "_" + md5sum(name.toString()); //$NON-NLS-1$
+ }
+ return res;
}
+
+ public static final String md5sum(String input) {
+ MessageDigest md = null;
+ try {
+ md = MessageDigest.getInstance("MD5"); //$NON-NLS-1$
+ } catch (NoSuchAlgorithmException e) {
+ }
+ if (md == null || input == null) {
+ return input;
+ }
+ StringBuffer sbuf = new StringBuffer();
+ byte [] raw = md.digest(input.getBytes());
+ for (int i = 0; i < raw.length; i++) {
+ int c = (int)raw[i];
+ if (c < 0) {
+ c = (Math.abs(c) - 1) ^ 255;
+ }
+ final String block = toHex(c >>> 4) + toHex(c & 15);
+ sbuf.append(block);
+ }
+ return sbuf.toString();
+ }
+ private static final String toHex(int s) {
+ if (s < 10) {
+ return String.valueOf((char)('0' + s));
+ }
+ return String.valueOf((char)('a' + (s - 10)));
+ }
+
@SuppressWarnings("unchecked")
public HashMap<String,OrmShape> getCloneElements() {
return (HashMap<String,OrmShape>)elements.clone();
15 years, 6 months