Author: vrubezhny
Date: 2011-11-10 10:14:12 -0500 (Thu, 10 Nov 2011)
New Revision: 36278
Added:
trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/util/StringUtil.java
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.seam.core/src/org/jboss/tools/cdi/seam/core/international/el/CDIInternationalMessagesELResolver.java
trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/core/ca/AbstractELCompletionEngine.java
trunk/common/plugins/org.jboss.tools.common.el.ui/src/org/jboss/tools/common/el/ui/ca/ELProposalProcessor.java
trunk/common/plugins/org.jboss.tools.common.el.ui/src/org/jboss/tools/common/el/ui/ca/Messages.java
trunk/common/plugins/org.jboss.tools.common.el.ui/src/org/jboss/tools/common/el/ui/ca/messages.properties
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/hyperlink/HyperlinkPartitionerBuilder.java
trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/text/TextProposal.java
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/model/JSFMessageELCompletionEngine.java
trunk/jsf/tests/org.jboss.tools.jsf.ui.test/src/org/jboss/tools/jsf/jsp/ca/test/CAELInsideTagBodyInJspFileTest.java
trunk/jst/plugins/org.jboss.tools.jst.jsp/META-INF/MANIFEST.MF
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/contentassist/AutoContentAssistantProposal.java
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/contentassist/AutoELContentAssistantProposal.java
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/contentassist/computers/XmlELCompletionProposalComputer.java
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/jspeditor/info/ELInfoHoverMessages.properties
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/jspeditor/info/FaceletTagInfoHoverProcessor.java
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/jspeditor/info/JavaStringELInfoHover.java
trunk/jst/plugins/org.jboss.tools.jst.text.ext/src/org/jboss/tools/jst/text/ext/hyperlink/ELHyperlink.java
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/el/MessagePropertyELSegmentImpl.java
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/el/SeamELCompletionEngine.java
Log:
JBIDE-9910 Proposal info for message bundles in code completion for EL
Additional Info is added for Resource Bundles/Properties in Content Assistant
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.seam.core/src/org/jboss/tools/cdi/seam/core/international/el/CDIInternationalMessagesELResolver.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.seam.core/src/org/jboss/tools/cdi/seam/core/international/el/CDIInternationalMessagesELResolver.java 2011-11-10
14:56:30 UTC (rev 36277)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.seam.core/src/org/jboss/tools/cdi/seam/core/international/el/CDIInternationalMessagesELResolver.java 2011-11-10
15:14:12 UTC (rev 36278)
@@ -36,6 +36,7 @@
import org.jboss.tools.cdi.seam.core.international.impl.LocalizedValue;
import org.jboss.tools.cdi.seam.core.international.impl.PropertyImpl;
import org.jboss.tools.common.el.core.ca.AbstractELCompletionEngine;
+import org.jboss.tools.common.el.core.ca.MessagesELTextProposal;
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;
@@ -57,6 +58,7 @@
import org.jboss.tools.common.model.XModelObject;
import org.jboss.tools.common.model.util.PositionHolder;
import org.jboss.tools.common.text.TextProposal;
+import org.jboss.tools.common.util.StringUtil;
import org.jboss.tools.jst.web.kb.IResourceBundle;
import org.jboss.tools.jst.web.kb.el.MessagePropertyELSegmentImpl;
import org.jboss.tools.jst.web.kb.internal.ResourceBundle;
@@ -398,94 +400,73 @@
for (Variable mbr : members) {
processSingularMember(mbr, kbProposals);
}
- } else
- if(expr.getType() != ELObjectType.EL_ARGUMENT_INVOCATION) {
- Set<String> proposalsToFilter = new TreeSet<String>();
+ } else if(expr.getType() != ELObjectType.EL_ARGUMENT_INVOCATION) {
+ String filter = (expr.getMemberName() == null ? "" : expr.getMemberName());
+
for (Variable mbr : members) {
- filterSingularMember(mbr, proposalsToFilter);
- }
- for (String proposal : proposalsToFilter) {
- // We do expect nothing but name for method tokens (No round brackets)
- String filter = expr.getMemberName();
- if(filter == null) filter = ""; //$NON-NLS-1$
- if(returnEqualedVariablesOnly) {
- // This is used for validation.
- if (proposal.equals(filter)) {
- TextProposal kbProposal = new TextProposal();
- kbProposal.setReplacementString(proposal);
- kbProposal.setLabel(proposal);
+ Collection<String> keys = mbr.getKeys();
+ for (String key : keys) {
+ if(returnEqualedVariablesOnly) {
+ // This is used for validation.
+ if (key.equals(filter)) {
+ TextProposal kbProposal = createProposal(mbr, key);
+ kbProposals.add(kbProposal);
+ break;
+ }
+ } else if (key.startsWith(filter)) {
+ // This is used for CA.
+ MessagesELTextProposal kbProposal = createProposal(mbr, key);
+ if (key.indexOf('.') ==
-1) kbProposal.setReplacementString(key.substring(filter.length()));
+ else kbProposal.setReplacementString('[' +
kbProposal.getReplacementString());
kbProposal.setImage(getELProposalImageForMember(null));
-
kbProposals.add(kbProposal);
-
- break;
}
- } else if (proposal.startsWith(filter)) {
- // This is used for CA.
- TextProposal kbProposal = new TextProposal();
- kbProposal.setReplacementString(proposal.substring(filter.length()));
- kbProposal.setLabel(proposal);
- kbProposal.setImage(getELProposalImageForMember(null));
-
- kbProposals.add(kbProposal);
}
}
} else if(expr.getType() == ELObjectType.EL_ARGUMENT_INVOCATION) {
- Set<String> proposalsToFilter = new TreeSet<String>();
- boolean isMessages = false;
+// Set<String> proposalsToFilter = new TreeSet<String>();
+// boolean isMessages = false;
+ String filter = expr.getMemberName() == null ? "" : expr.getMemberName();
+ boolean b = filter.startsWith("'") ||
filter.startsWith("\""); //$NON-NLS-1$ //$NON-NLS-2$
+ filter = StringUtil.trimQuotes(filter);
+
for (Variable mbr : members) {
- isMessages = true;
- filterSingularMember(mbr, proposalsToFilter);
- }
-
- String filter = expr.getMemberName();
- boolean bSurroundWithQuotes = false;
- if(filter == null) {
- filter = ""; //$NON-NLS-1$
- bSurroundWithQuotes = true;
- } else {
- boolean b = filter.startsWith("'") ||
filter.startsWith("\""); //$NON-NLS-1$ //$NON-NLS-2$
- boolean e = filter.endsWith("'") ||
filter.endsWith("\""); //$NON-NLS-1$ //$NON-NLS-2$
- if((b) && (e)) {
- filter = filter.length() == 1 ? "" : filter.substring(1, filter.length() -
1); //$NON-NLS-1$
- } else if(b && !returnEqualedVariablesOnly) {
- filter = filter.substring(1);
- } else {
+ if (!b && filter.length() > 0) {
//Value is set as expression itself, we cannot compute it
- if(isMessages) {
- resolution.setMapOrCollectionOrBundleAmoungTheTokens(true);
- }
+ resolution.setMapOrCollectionOrBundleAmoungTheTokens(true);
return;
}
- }
- for (String proposal : proposalsToFilter) {
- if(returnEqualedVariablesOnly) {
- // This is used for validation.
- if (proposal.equals(filter)) {
- TextProposal kbProposal = new TextProposal();
- kbProposal.setReplacementString(proposal);
- kbProposal.setLabel(proposal);
- kbProposal.setImage(getELProposalImageForMember(null));
+// isMessages = true;
+// filterSingularMember(mbr, proposalsToFilter);
+ Collection<String> keys = mbr.getKeys();
+ for (String key : keys) {
+ if(returnEqualedVariablesOnly) {
+ // This is used for validation.
+ if (key.equals(filter)) {
+ MessagesELTextProposal kbProposal = createProposal(mbr, key);
+ kbProposals.add(kbProposal);
+ break;
+ }
+ } else if (key.startsWith(filter)) {
+ // This is used for CA.
+ MessagesELTextProposal kbProposal = createProposal(mbr, key);
- kbProposals.add(kbProposal);
+ String existingString = expr.getMemberName() == null ? "" :
expr.getMemberName();
+ // Because we're in argument invocation we should fix the proposal by
surrounding it with quotes as needed
+ String replacement = kbProposal.getReplacementString();
+ String label = kbProposal.getLabel();
+ if (!replacement.startsWith("'")) {
+ replacement = '\'' + key + '\'';
+ label = "['" + key + "']";
+ }
+ replacement = replacement.substring(existingString.length());
- break;
- }
- } else if (proposal.startsWith(filter)) {
- // This is used for CA.
- TextProposal kbProposal = new TextProposal();
+ kbProposal.setReplacementString(replacement);
+ kbProposal.setLabel(label);
- String replacementString = proposal.substring(filter.length());
- if (bSurroundWithQuotes) {
- replacementString = "'" + replacementString + "']";
//$NON-NLS-1$ //$NON-NLS-2$
+ kbProposals.add(kbProposal);
}
-
- kbProposal.setReplacementString(replacementString);
- kbProposal.setLabel(proposal);
- kbProposal.setImage(getELProposalImageForMember(null));
-
- kbProposals.add(kbProposal);
}
}
}
@@ -547,7 +528,7 @@
String propertyName = segment.getToken().getText();
- IProperty prop = bundle.getProperty(trimQuotes(propertyName));
+ IProperty prop = bundle.getProperty(StringUtil.trimQuotes(propertyName));
if(prop == null) continue;
Map<String, LocalizedValue> values = ((PropertyImpl)prop).getValues();
for (LocalizedValue value: values.values()) {
@@ -577,6 +558,41 @@
return true;
}
+ private MessagesELTextProposal createProposal(Variable mbr, String proposal) {
+ MessagesELTextProposal kbProposal = new MessagesELTextProposal();
+ if (proposal.indexOf('.') != -1) {
+ kbProposal.setReplacementString('\'' + proposal + '\'');
+ kbProposal.setLabel("['" + proposal + "']");
+ } else {
+ kbProposal.setReplacementString(proposal);
+ kbProposal.setLabel(proposal);
+ }
+ kbProposal.setAlternateMatch(proposal);
+ kbProposal.setImage(getELProposalImageForMember(null));
+
+ List<XModelObject> objects = new ArrayList<XModelObject>();
+ IBundleModel bundleModel = BundleModelFactory.getBundleModel(mbr.f.getProject());
+ if(bundleModel != null) {
+ IBundle bundle = bundleModel.getBundle(mbr.basename);
+ if(bundle != null) {
+ IProperty prop = bundle.getProperty(proposal);
+ if(prop != null) {
+ Map<String, LocalizedValue> values = ((PropertyImpl)prop).getValues();
+ for (LocalizedValue value: values.values()) {
+ XModelObject p = value.getObject();
+ if (p != null) objects.add(p);
+ }
+ }
+ }
+ }
+
+ kbProposal.setBaseName(mbr.basename);
+ kbProposal.setPropertyName(proposal);
+ kbProposal.setObjects(objects);
+
+ return kbProposal;
+ }
+
protected void processSingularMember(Variable mbr, Set<TextProposal> kbProposals)
{
// Surround the "long" keys containing the dots with [' ']
TreeSet<String> keys = new TreeSet<String>(String.CASE_INSENSITIVE_ORDER);
@@ -586,31 +602,19 @@
String key = sortedKeys.next();
if (key == null || key.length() == 0)
continue;
+
+ MessagesELTextProposal proposal = createProposal(mbr, key);
if (key.indexOf('.') != -1) {
- TextProposal proposal = new TextProposal();
proposal.setReplacementString("['" + key + "']");
//$NON-NLS-1$ //$NON-NLS-2$
proposal.setLabel("['" + key + "']");
- proposal.setImage(getELProposalImageForMember(null));
-
- kbProposals.add(proposal);
} else {
- TextProposal proposal = new TextProposal();
proposal.setReplacementString(key);
proposal.setLabel(key);
- proposal.setImage(getELProposalImageForMember(null));
-
- kbProposals.add(proposal);
}
+ kbProposals.add(proposal);
}
}
-
- protected void filterSingularMember(Variable mbr, Set<String> proposalsToFilter)
{
- Collection<String> keys = mbr.getKeys();
- for (String key : keys) {
- proposalsToFilter.add(key);
- }
- }
-
+
static class Variable implements IVariable {
IFile f;
String name;
Modified:
trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/text/TextProposal.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/text/TextProposal.java 2011-11-10
14:56:30 UTC (rev 36277)
+++
trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/text/TextProposal.java 2011-11-10
15:14:12 UTC (rev 36278)
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009 Red Hat, Inc.
+ * Copyright (c) 2009-2011 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,
@@ -42,6 +42,7 @@
private Image image;
private boolean emptyImage = true;
private String replacementString;
+ private String alternateMatch = null;
private boolean emptyContextInfo = true;
private int relevance = R_NONE;
private int position = -1;
@@ -360,6 +361,14 @@
this.source = source;
}
+ public String getAlternateMatch() {
+ return alternateMatch;
+ }
+
+ public void setAlternateMatch(String alternateMatch) {
+ this.alternateMatch = alternateMatch;
+ }
+
public static final Comparator<TextProposal> KB_PROPOSAL_ORDER = new
TextProposalComparator();
private static class TextProposalComparator implements Comparator<TextProposal>
{
Added:
trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/util/StringUtil.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/util/StringUtil.java
(rev 0)
+++
trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/util/StringUtil.java 2011-11-10
15:14:12 UTC (rev 36278)
@@ -0,0 +1,40 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+
+package org.jboss.tools.common.util;
+
+/**
+ * Miscellaneous String utility functions
+ *
+ * @author Victor V. Rubezhny
+ */
+public class StringUtil {
+/**
+ * Cuts of the starting and ending quotes from a given text value
+ *
+ * @param Quoted text value
+ * @return Non-quoted text value
+ */
+ public static String trimQuotes(String value) {
+ if(value == null)
+ return null;
+
+ if(value.startsWith("'") || value.startsWith("\"")) {
//$NON-NLS-1$ //$NON-NLS-2$
+ value = value.substring(1);
+ }
+
+ if(value.endsWith("'") || value.endsWith("\"")) {
//$NON-NLS-1$ //$NON-NLS-2$
+ value = value.substring(0, value.length() - 1);
+ }
+ return value;
+ }
+
+}
Property changes on:
trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/util/StringUtil.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Modified:
trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/core/ca/AbstractELCompletionEngine.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/core/ca/AbstractELCompletionEngine.java 2011-11-10
14:56:30 UTC (rev 36277)
+++
trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/core/ca/AbstractELCompletionEngine.java 2011-11-10
15:14:12 UTC (rev 36278)
@@ -1128,26 +1128,6 @@
return unique;
}
- /**
- * Cuts of the starting and ending quotes from a given text value
- *
- * @param Quoted text value
- * @return Non-quoted text value
- */
- public static String trimQuotes(String value) {
- if(value == null)
- return null;
-
- if(value.startsWith("'") || value.startsWith("\"")) {
//$NON-NLS-1$ //$NON-NLS-2$
- value = value.substring(1);
- }
-
- if(value.endsWith("'") || value.endsWith("\"")) {
//$NON-NLS-1$ //$NON-NLS-2$
- value = value.substring(0, value.length() - 1);
- }
- return value;
- }
-
public static LexicalToken combineLexicalTokensForExpression(ELInvocationExpression
expr) {
// Create a combined lexical token to store all the variable name (not only the name
before first dot, but all the name including all the words and dots)
int variableTokenType = expr.getFirstToken().getType();
Modified:
trunk/common/plugins/org.jboss.tools.common.el.ui/src/org/jboss/tools/common/el/ui/ca/ELProposalProcessor.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.el.ui/src/org/jboss/tools/common/el/ui/ca/ELProposalProcessor.java 2011-11-10
14:56:30 UTC (rev 36277)
+++
trunk/common/plugins/org.jboss.tools.common.el.ui/src/org/jboss/tools/common/el/ui/ca/ELProposalProcessor.java 2011-11-10
15:14:12 UTC (rev 36278)
@@ -13,12 +13,16 @@
import java.io.Reader;
import java.io.StringReader;
+import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.Path;
import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.IMember;
import org.eclipse.jdt.core.JavaModelException;
@@ -57,11 +61,14 @@
import org.jboss.tools.common.el.core.ELReference;
import org.jboss.tools.common.el.core.ca.AbstractELCompletionEngine;
import org.jboss.tools.common.el.core.ca.ELTextProposal;
+import org.jboss.tools.common.el.core.ca.MessagesELTextProposal;
import org.jboss.tools.common.el.core.model.ELInvocationExpression;
import org.jboss.tools.common.el.core.resolver.ELContext;
import org.jboss.tools.common.el.core.resolver.ELResolver;
import org.jboss.tools.common.el.core.resolver.ELResolverFactoryManager;
import org.jboss.tools.common.el.ui.ElUiPlugin;
+import org.jboss.tools.common.model.XModelObject;
+import org.jboss.tools.common.model.filesystems.impl.JarSystemImpl;
import org.jboss.tools.common.text.TextProposal;
import org.jboss.tools.common.text.ext.util.Utils;
import org.jboss.tools.common.util.EclipseUIUtil;
@@ -91,6 +98,7 @@
private String fDisplayString;
private String fAdditionalProposalInfo;
private IJavaElement[] fJavaElements;
+ private MessagesELTextProposal fPropertySource;
private Image fImage;
@@ -99,18 +107,18 @@
}
public Proposal(String string, String prefix, int offset, int newPosition) {
- this(string, prefix, prefix, offset, offset + string.length(), null, null, null,
null);
+ this(string, prefix, prefix, offset, offset + string.length(), null, null, null, null,
null);
}
- public Proposal(String string, String prefix, int offset, int newPosition, Image image,
String displayString, String additionalProposalInfo, IJavaElement[] javaElements) {
- this(string, prefix, prefix, offset, offset + string.length(), image, displayString,
additionalProposalInfo, javaElements);
+ public Proposal(String string, String prefix, int offset, int newPosition, Image image,
String displayString, String additionalProposalInfo, IJavaElement[] javaElements,
MessagesELTextProposal propertySource) {
+ this(string, prefix, prefix, offset, offset + string.length(), image, displayString,
additionalProposalInfo, javaElements, propertySource);
}
public Proposal(String string, String prefix, String newPrefix, int offset, int
newPosition) {
- this(string, prefix, newPrefix, offset, newPosition, null, null, null, null);
+ this(string, prefix, newPrefix, offset, newPosition, null, null, null, null, null);
}
- public Proposal(String string, String prefix, String newPrefix, int offset, int
newPosition, Image image, String displayString, String additionalProposalInfo,
IJavaElement[] javaElements) {
+ public Proposal(String string, String prefix, String newPrefix, int offset, int
newPosition, Image image, String displayString, String additionalProposalInfo,
IJavaElement[] javaElements, MessagesELTextProposal propertySource) {
fString = string;
fPrefix = prefix;
fNewPrefix = newPrefix;
@@ -122,6 +130,7 @@
fJavaElements = javaElements;
if (fJavaElements != null && fJavaElements.length > 0)
fAdditionalProposalInfo = null; // Drop it due to valculate it later based on java
elements
+ fPropertySource = propertySource;
}
/*
@@ -145,6 +154,8 @@
if (fAdditionalProposalInfo == null) {
if (this.fJavaElements != null && this.fJavaElements.length > 0) {
this.fAdditionalProposalInfo = extractProposalContextInfo(fJavaElements);
+ } else if (fPropertySource != null) {
+ this.fAdditionalProposalInfo = extractProposalContextInfo(fPropertySource);
}
}
if (fAdditionalProposalInfo == null)
@@ -206,6 +217,23 @@
return null;
}
+ /*
+ * Extracts the additional proposal information based on Javadoc for the stored
IJavaElement objects
+ */
+ private String extractProposalContextInfo(MessagesELTextProposal propertySource) {
+ String propertyName = propertySource.getPropertyName();
+ String baseName = propertySource.getBaseName();
+ List<XModelObject> objects =
(List<XModelObject>)propertySource.getAllObjects();
+
+ String info = getELMessagesHoverInternal(baseName, propertyName, objects);
+ if (info == null) return null;
+
+ StringBuffer buffer= new StringBuffer(info);
+ HTMLPrinter.insertPageProlog(buffer, 0, (String)null);
+ HTMLPrinter.addPageEpilog(buffer);
+ return buffer.toString();
+ }
+
private static final long LABEL_FLAGS= JavaElementLabels.ALL_FULLY_QUALIFIED
| JavaElementLabels.M_PRE_RETURNTYPE | JavaElementLabels.M_PARAMETER_TYPES |
JavaElementLabels.M_PARAMETER_NAMES | JavaElementLabels.M_EXCEPTIONS
| JavaElementLabels.F_PRE_TYPE_SIGNATURE | JavaElementLabels.M_PRE_TYPE_PARAMETERS |
JavaElementLabels.T_TYPE_PARAMETERS
@@ -554,19 +582,23 @@
if (string.length() > 0 && ('#' == string.charAt(0) ||
'$' == string.charAt(0)))
string = elStartChar + string.substring(1);
- String additionalProposalInfo = (kbProposal.getContextInfo() == null ? ""
: kbProposal.getContextInfo()); //$NON-NLS-1$
+ String additionalProposalInfo = kbProposal.getContextInfo();
IJavaElement[] javaElements = null;
+ MessagesELTextProposal source = null;
+
if (kbProposal instanceof ELTextProposal) {
javaElements = ((ELTextProposal)kbProposal).getAllJavaElements();
+ } else if (kbProposal instanceof MessagesELTextProposal) {
+ source = (MessagesELTextProposal)kbProposal;
}
if (string.startsWith("['") &&
string.endsWith("']") && prefix != null &&
prefix.endsWith(".")) { //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
String newPrefix = prefix.substring(0, prefix.length() - 1);
resultList.add(new Proposal(string, prefix, newPrefix, offset, offset - 1 +
string.length() - proposalSufix.length(), image,
- kbProposal.getLabel(), additionalProposalInfo, javaElements));
+ kbProposal.getLabel(), additionalProposalInfo, javaElements, source));
} else {
resultList.add(new Proposal(string, prefix, offset, offset + string.length() -
proposalSufix.length(), image,
- kbProposal.getLabel(), additionalProposalInfo, javaElements));
+ kbProposal.getLabel(), additionalProposalInfo, javaElements, source));
}
}
}
@@ -760,4 +792,78 @@
public String getErrorMessage() {
return null; // no custom error message
}
+
+ public static String getELMessagesHoverInternal(String baseName, String propertyName,
List<XModelObject> objects) {
+ StringBuffer buffer= new StringBuffer();
+
+ if (propertyName != null && propertyName.length() > 0)
+ buffer.append(MessageFormat.format(Messages.ELInfoHover_propertyName,
+ propertyName));
+
+ if (baseName != null && baseName.length() > 0)
+ buffer.append(MessageFormat.format(Messages.ELInfoHover_baseName,
+ baseName));
+
+ if (objects != null) {
+ boolean firstValue = true;
+ for (XModelObject o : objects) {
+ IFile propFile = (IFile)o.getAdapter(IFile.class);
+ String propFilePath = null;
+ if (propFile != null) {
+ propFilePath = propFile.getFullPath().toString();
+ } else {
+ XModelObject parent = o.getFileType() == XModelObject.FILE ? o : o.getParent();
+ String path = parent.getPath();
+ while (parent != null && parent.getFileType() != XModelObject.SYSTEM) {
+ parent = parent.getParent();
+ }
+ if (parent instanceof JarSystemImpl) {
+ String sysPath = parent.getPath();
+ path = path.substring(sysPath.length());
+
+ String jarPath = ((JarSystemImpl) parent).getLocation();
+
+ IResource jar = ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(new
Path(jarPath));
+
+ if (jar != null) {
+ jarPath = jar.getFullPath().toString();
+ }
+
+ propFilePath = jarPath + "!" + path; //$NON-NLS-1$
+ }
+ }
+ buffer.append(Messages.ELInfoHover_newLine);
+ if (!firstValue) buffer.append(Messages.ELInfoHover_newLine);
+ else firstValue = false;
+
+ buffer.append(MessageFormat.format(Messages.ELInfoHover_resourceBundle,
+ propFilePath != null ? propFilePath :
Messages.ELInfoHover_resourceBundleNotDefined));
+
+ if (propertyName != null) {
+ String value = o.get("VALUE"); //$NON-NLS-1$
+ boolean addCut = false;
+ if (value != null) {
+ if (value.length() > 100) {
+ // Get first words of value
+ int lastSpace = value.lastIndexOf(' ', 99);
+ if (lastSpace != -1) {
+ value = value.substring(0, lastSpace);
+ } else { // cut as is
+ value = value.substring(0, 100);
+ }
+ addCut = true;
+ }
+ }
+ buffer.append(Messages.ELInfoHover_newLine);
+ buffer.append(MessageFormat.format(Messages.ELInfoHover_resourceBundlePropertyValue,
+ value != null ? value :
Messages.ELInfoHover_resourceBundlePropertyValueNotDefined,
+ addCut ? Messages.ELInfoHover_treeDots : "")); //$NON-NLS-1$
+// sb.append(Messages.ELInfoHover_newLine);
+ }
+ }
+ }
+
+ return buffer.length() == 0 ? null : buffer.toString();
+ }
+
}
\ No newline at end of file
Modified:
trunk/common/plugins/org.jboss.tools.common.el.ui/src/org/jboss/tools/common/el/ui/ca/Messages.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.el.ui/src/org/jboss/tools/common/el/ui/ca/Messages.java 2011-11-10
14:56:30 UTC (rev 36277)
+++
trunk/common/plugins/org.jboss.tools.common.el.ui/src/org/jboss/tools/common/el/ui/ca/Messages.java 2011-11-10
15:14:12 UTC (rev 36278)
@@ -30,4 +30,14 @@
}
public static String NO_JAVADOC;
+
+ public static String ELInfoHover_baseName;
+ public static String ELInfoHover_propertyName;
+ public static String ELInfoHover_resourceBundle;
+ public static String ELInfoHover_resourceBundlePropertyValue;
+ public static String ELInfoHover_resourceBundlePropertyValueNotDefined;
+ public static String ELInfoHover_resourceBundleNotDefined;
+ public static String ELInfoHover_newLine;
+ public static String ELInfoHover_treeDots;
+
}
\ No newline at end of file
Modified:
trunk/common/plugins/org.jboss.tools.common.el.ui/src/org/jboss/tools/common/el/ui/ca/messages.properties
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.el.ui/src/org/jboss/tools/common/el/ui/ca/messages.properties 2011-11-10
14:56:30 UTC (rev 36277)
+++
trunk/common/plugins/org.jboss.tools.common.el.ui/src/org/jboss/tools/common/el/ui/ca/messages.properties 2011-11-10
15:14:12 UTC (rev 36278)
@@ -1 +1,10 @@
-NO_JAVADOC=No Javadoc could be found<br>
\ No newline at end of file
+NO_JAVADOC=No Javadoc could be found<br>
+
+ELInfoHover_baseName=<b>Base Name:</b> {0}<br>
+ELInfoHover_propertyName=<b>Property:</b> {0}<br>
+ELInfoHover_resourceBundle=<b>Resource Bundle:</b> {0}
+ELInfoHover_resourceBundlePropertyValue=<b>Value:</b> {0}{1}
+ELInfoHover_resourceBundlePropertyValueNotDefined=[Value not defined]
+ELInfoHover_resourceBundleNotDefined=[Resource Bundle not defined]
+ELInfoHover_newLine=<br>
+ELInfoHover_treeDots=...
Modified:
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/hyperlink/HyperlinkPartitionerBuilder.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/hyperlink/HyperlinkPartitionerBuilder.java 2011-11-10
14:56:30 UTC (rev 36277)
+++
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/hyperlink/HyperlinkPartitionerBuilder.java 2011-11-10
15:14:12 UTC (rev 36278)
@@ -302,7 +302,8 @@
return (HyperlinkPartitionerDefinition[])fPartitionerDefs.toArray(new
HyperlinkPartitionerDefinition[fPartitionerDefs.size()]);
}
- private String getBaseContentType(String contentType) {
+ public String getBaseContentType(String contentType) {
+ initCache();
if (contentType == null)
return null;
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/model/JSFMessageELCompletionEngine.java
===================================================================
---
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/model/JSFMessageELCompletionEngine.java 2011-11-10
14:56:30 UTC (rev 36277)
+++
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/model/JSFMessageELCompletionEngine.java 2011-11-10
15:14:12 UTC (rev 36278)
@@ -24,6 +24,7 @@
import org.eclipse.jface.text.IDocument;
import org.eclipse.swt.graphics.Image;
import org.jboss.tools.common.el.core.ca.AbstractELCompletionEngine;
+import org.jboss.tools.common.el.core.ca.MessagesELTextProposal;
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;
@@ -49,6 +50,7 @@
import org.jboss.tools.common.text.TextProposal;
import org.jboss.tools.common.text.ext.util.StructuredModelWrapper;
import org.jboss.tools.common.text.ext.util.Utils;
+import org.jboss.tools.common.util.StringUtil;
import org.jboss.tools.jsf.JSFModelPlugin;
import org.jboss.tools.jsf.model.helpers.converter.OpenKeyHelper;
import org.jboss.tools.jst.web.kb.IPageContext;
@@ -258,9 +260,32 @@
for (Variable var : resolvedVariables) {
String varName = var.getName();
if(varName.startsWith(operand.getText())) {
- TextProposal proposal = new TextProposal();
+ MessagesELTextProposal proposal = new MessagesELTextProposal();
proposal.setReplacementString(varName.substring(operand.getLength()));
proposal.setImage(getELProposalImageForMember(null));
+
+ List<XModelObject> objects = new ArrayList<XModelObject>();
+
+ IModelNature n = EclipseResourceUtil.getModelNature(var.f.getProject());
+ XModel model = n != null ? n.getModel() : null;
+ if(model != null) {
+ OpenKeyHelper keyHelper = new OpenKeyHelper();
+ XModelObject[] properties = keyHelper.findBundles(model, var.basename, null);
+ if(properties == null) continue;
+ for (XModelObject p : properties) {
+ objects.add(p);
+ // IFile propFile = (IFile)p.getAdapter(IFile.class);
+ // if(propFile == null)
+ // continue;
+ }
+ }
+
+ proposal.setBaseName(var.basename);
+ proposal.setObjects(objects);
+// if (!lastSegment.isBundle()) {
+// proposal.setPropertyName(lastSegment.getToken().getText());
+// }
+
proposals.add(proposal);
}
}
@@ -279,10 +304,32 @@
for (Variable var : resolvedVariables) {
String varName = var.getName();
if(operand.getLength()<=varName.length()) {
- TextProposal proposal = new TextProposal();
+ MessagesELTextProposal proposal = new MessagesELTextProposal();
proposal.setReplacementString(varName.substring(operand.getLength()));
proposal.setLabel(varName);
proposal.setImage(getELProposalImageForMember(null));
+ List<XModelObject> objects = new ArrayList<XModelObject>();
+ IModelNature n = EclipseResourceUtil.getModelNature(var.f.getProject());
+ XModel model = n != null ? n.getModel() : null;
+ if(model != null) {
+ OpenKeyHelper keyHelper = new OpenKeyHelper();
+ XModelObject[] properties = keyHelper.findBundles(model, var.basename, null);
+ if(properties == null) continue;
+ for (XModelObject p : properties) {
+ objects.add(p);
+// IFile propFile = (IFile)p.getAdapter(IFile.class);
+// if(propFile == null)
+// continue;
+ }
+ }
+
+ proposal.setBaseName(var.basename);
+ proposal.setObjects(objects);
+
+// if (!lastSegment.isBundle()) {
+// proposal.setPropertyName(lastSegment.getToken().getText());
+// }
+
proposals.add(proposal);
} else if(returnEqualedVariablesOnly) {
TextProposal proposal = new TextProposal();
@@ -381,94 +428,69 @@
for (Variable mbr : members) {
processSingularMember(mbr, kbProposals);
}
- } else
- if(expr.getType() != ELObjectType.EL_ARGUMENT_INVOCATION) {
- Set<String> proposalsToFilter = new TreeSet<String>();
+ } else if(expr.getType() != ELObjectType.EL_ARGUMENT_INVOCATION) {
+ String filter = (expr.getMemberName() == null ? "" : expr.getMemberName());
+
for (Variable mbr : members) {
- filterSingularMember(mbr, proposalsToFilter);
- }
- for (String proposal : proposalsToFilter) {
- // We do expect nothing but name for method tokens (No round brackets)
- String filter = expr.getMemberName();
- if(filter == null) filter = ""; //$NON-NLS-1$
- if(returnEqualedVariablesOnly) {
- // This is used for validation.
- if (proposal.equals(filter)) {
- TextProposal kbProposal = new TextProposal();
- kbProposal.setReplacementString(proposal);
- kbProposal.setLabel(proposal);
- kbProposal.setImage(getELProposalImageForMember(null));
-
+ Collection<String> keys = mbr.getKeys();
+ for (String key : keys) {
+ // We do expect nothing but name for method tokens (No round brackets)
+ if(returnEqualedVariablesOnly) {
+ // This is used for validation.
+ if (key.equals(filter)) {
+ MessagesELTextProposal kbProposal = createProposal(mbr, key);
+ kbProposals.add(kbProposal);
+ break;
+ }
+ } else if (key.startsWith(filter)) {
+ // This is used for CA.
+ MessagesELTextProposal kbProposal = createProposal(mbr, key);
+ if (key.indexOf('.') ==
-1) kbProposal.setReplacementString(key.substring(filter.length()));
+ else kbProposal.setReplacementString('[' +
kbProposal.getReplacementString());
kbProposals.add(kbProposal);
-
- break;
}
- } else if (proposal.startsWith(filter)) {
- // This is used for CA.
- TextProposal kbProposal = new TextProposal();
- kbProposal.setReplacementString(proposal.substring(filter.length()));
- kbProposal.setLabel(proposal);
- kbProposal.setImage(getELProposalImageForMember(null));
-
- kbProposals.add(kbProposal);
}
}
} else if(expr.getType() == ELObjectType.EL_ARGUMENT_INVOCATION) {
- Set<String> proposalsToFilter = new TreeSet<String>();
- boolean isMessages = false;
+ String filter = expr.getMemberName() == null ? "" : expr.getMemberName();
+ boolean b = filter.startsWith("'") ||
filter.startsWith("\""); //$NON-NLS-1$ //$NON-NLS-2$
+ filter = StringUtil.trimQuotes(filter);
+
for (Variable mbr : members) {
- isMessages = true;
- filterSingularMember(mbr, proposalsToFilter);
- }
-
- String filter = expr.getMemberName();
- boolean bSurroundWithQuotes = false;
- if(filter == null) {
- filter = ""; //$NON-NLS-1$
- bSurroundWithQuotes = true;
- } else {
- boolean b = filter.startsWith("'") ||
filter.startsWith("\""); //$NON-NLS-1$ //$NON-NLS-2$
- boolean e = filter.endsWith("'") ||
filter.endsWith("\""); //$NON-NLS-1$ //$NON-NLS-2$
- if((b) && (e)) {
- filter = filter.length() == 1 ? "" : filter.substring(1, filter.length() -
1); //$NON-NLS-1$
- } else if(b && !returnEqualedVariablesOnly) {
- filter = filter.substring(1);
- } else {
+ if (!b && filter.length() > 0) {
//Value is set as expression itself, we cannot compute it
- if(isMessages) {
- resolution.setMapOrCollectionOrBundleAmoungTheTokens(true);
- }
+ resolution.setMapOrCollectionOrBundleAmoungTheTokens(true);
return;
}
- }
- for (String proposal : proposalsToFilter) {
- if(returnEqualedVariablesOnly) {
- // This is used for validation.
- if (proposal.equals(filter)) {
- TextProposal kbProposal = new TextProposal();
- kbProposal.setReplacementString(proposal);
- kbProposal.setLabel(proposal);
- kbProposal.setImage(getELProposalImageForMember(null));
+ Collection<String> keys = mbr.getKeys();
+ for (String key : keys) {
+ if(returnEqualedVariablesOnly) {
+ // This is used for validation.
+ if (key.equals(filter)) {
+ MessagesELTextProposal kbProposal = createProposal(mbr, key);
+ kbProposals.add(kbProposal);
+ break;
+ }
+ } else if (key.startsWith(filter)) {
+ // This is used for CA.
+ MessagesELTextProposal kbProposal = createProposal(mbr, key);
+
+ String existingString = expr.getMemberName() == null ? "" :
expr.getMemberName();
+ // Because we're in argument invocation we should fix the proposal by
surrounding it with quotes as needed
+ String replacement = kbProposal.getReplacementString();
+ String label = kbProposal.getLabel();
+ if (!replacement.startsWith("'")) {
+ replacement = '\'' + key + '\'';
+ label = "['" + key + "']";
+ }
+ replacement = replacement.substring(existingString.length());
+
+ kbProposal.setReplacementString(replacement);
+ kbProposal.setLabel(label);
kbProposals.add(kbProposal);
-
- break;
}
- } else if (proposal.startsWith(filter)) {
- // This is used for CA.
- TextProposal kbProposal = new TextProposal();
-
- String replacementString = proposal.substring(filter.length());
- if (bSurroundWithQuotes) {
- replacementString = "'" + replacementString + "']";
//$NON-NLS-1$ //$NON-NLS-2$
- }
-
- kbProposal.setReplacementString(replacementString);
- kbProposal.setLabel(proposal);
- kbProposal.setImage(getELProposalImageForMember(null));
-
- kbProposals.add(kbProposal);
}
}
}
@@ -533,7 +555,7 @@
for (XModelObject p : properties) {
String name = segment.getToken().getText();
- XModelObject property = p.getChildByPath(trimQuotes(name));
+ XModelObject property = p.getChildByPath(StringUtil.trimQuotes(name));
if(property == null) continue;
segment.addObject(property);
@@ -604,6 +626,41 @@
return true;
}
+ private MessagesELTextProposal createProposal(Variable mbr, String proposal) {
+ MessagesELTextProposal kbProposal = new MessagesELTextProposal();
+ if (proposal.indexOf('.') != -1) {
+ kbProposal.setReplacementString('\'' + proposal + '\'');
+ kbProposal.setLabel("['" + proposal + "']");
+ } else {
+ kbProposal.setReplacementString(proposal);
+ kbProposal.setLabel(proposal);
+ }
+ kbProposal.setAlternateMatch(proposal);
+ kbProposal.setImage(getELProposalImageForMember(null));
+
+ List<XModelObject> objects = new ArrayList<XModelObject>();
+ String locale = getPageLocale(mbr.f, currentOffset);
+ IModelNature n = EclipseResourceUtil.getModelNature(mbr.f.getProject());
+ XModel model = n != null ? n.getModel() : null;
+ if(model != null) {
+ OpenKeyHelper keyHelper = new OpenKeyHelper();
+ XModelObject[] properties = keyHelper.findBundles(model, mbr.basename, locale);
+
+ if(properties != null) {
+ for (XModelObject p : properties) {
+ XModelObject property = p.getChildByPath(proposal);
+ if(property != null) objects.add(property);
+ }
+ }
+ }
+
+ kbProposal.setBaseName(mbr.basename);
+ kbProposal.setPropertyName(proposal);
+ kbProposal.setObjects(objects);
+
+ return kbProposal;
+ }
+
protected void processSingularMember(Variable mbr, Set<TextProposal> kbProposals)
{
// Surround the "long" keys containing the dots with [' ']
TreeSet<String> keys = new TreeSet<String>(String.CASE_INSENSITIVE_ORDER);
@@ -613,31 +670,19 @@
String key = sortedKeys.next();
if (key == null || key.length() == 0)
continue;
+
+ MessagesELTextProposal proposal = createProposal(mbr, key);
if (key.indexOf('.') != -1) {
- TextProposal proposal = new TextProposal();
proposal.setReplacementString("['" + key + "']");
//$NON-NLS-1$ //$NON-NLS-2$
proposal.setLabel("['" + key + "']");
- proposal.setImage(getELProposalImageForMember(null));
-
- kbProposals.add(proposal);
} else {
- TextProposal proposal = new TextProposal();
proposal.setReplacementString(key);
proposal.setLabel(key);
- proposal.setImage(getELProposalImageForMember(null));
-
- kbProposals.add(proposal);
}
+ kbProposals.add(proposal);
}
}
- protected void filterSingularMember(Variable mbr, Set<String> proposalsToFilter)
{
- Collection<String> keys = mbr.getKeys();
- for (String key : keys) {
- proposalsToFilter.add(key);
- }
- }
-
static class Variable implements IVariable {
IFile f;
String name;
Modified:
trunk/jsf/tests/org.jboss.tools.jsf.ui.test/src/org/jboss/tools/jsf/jsp/ca/test/CAELInsideTagBodyInJspFileTest.java
===================================================================
---
trunk/jsf/tests/org.jboss.tools.jsf.ui.test/src/org/jboss/tools/jsf/jsp/ca/test/CAELInsideTagBodyInJspFileTest.java 2011-11-10
14:56:30 UTC (rev 36277)
+++
trunk/jsf/tests/org.jboss.tools.jsf.ui.test/src/org/jboss/tools/jsf/jsp/ca/test/CAELInsideTagBodyInJspFileTest.java 2011-11-10
15:14:12 UTC (rev 36278)
@@ -69,7 +69,12 @@
continue;
AutoContentAssistantProposal existingProposal = (AutoContentAssistantProposal)p;
String proposalString = existingProposal.getReplacementString();
-
+
+ // We have to compare full proposalString if proposal is not a name (f.e. EL like
"#{}"),
+ // but we have to compare only name in case of proposal is name (f.e. EL like
"user").
+ if (proposal.indexOf('}') == -1 && proposalString.indexOf('}')
!= -1)
+ proposalString = proposalString.substring(0, proposalString.indexOf('}'));
+
if (proposal.equals(proposalString)) {
return true;
}
Modified: trunk/jst/plugins/org.jboss.tools.jst.jsp/META-INF/MANIFEST.MF
===================================================================
--- trunk/jst/plugins/org.jboss.tools.jst.jsp/META-INF/MANIFEST.MF 2011-11-10 14:56:30 UTC
(rev 36277)
+++ trunk/jst/plugins/org.jboss.tools.jst.jsp/META-INF/MANIFEST.MF 2011-11-10 15:14:12 UTC
(rev 36278)
@@ -55,7 +55,8 @@
org.eclipse.wst.validation;bundle-version="1.2.300",
org.eclipse.ui;bundle-version="3.7.0",
org.eclipse.jst.standard.schemas;bundle-version="1.2.0",
- org.eclipse.wst.standard.schemas;bundle-version="1.0.300"
+ org.eclipse.wst.standard.schemas;bundle-version="1.0.300",
+ org.jboss.tools.common.el.ui
Bundle-Version: 3.3.0.qualifier
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Bundle-ClassPath: .
Modified:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/contentassist/AutoContentAssistantProposal.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/contentassist/AutoContentAssistantProposal.java 2011-11-10
14:56:30 UTC (rev 36277)
+++
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/contentassist/AutoContentAssistantProposal.java 2011-11-10
15:14:12 UTC (rev 36278)
@@ -1,12 +1,12 @@
/*******************************************************************************
- * Copyright (c) 2007 Exadel, Inc. and Red Hat, Inc.
+ * Copyright (c) 2007-2011 Red Hat, Inc.
* Distributed under license by Red Hat, Inc. All rights reserved.
* This program is made available under the terms of the
* Eclipse Public License v1.0 which accompanies this distribution,
* and is available at
http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
- * Exadel, Inc. and Red Hat, Inc. - initial API and implementation
+ * Red Hat, Inc. - initial API and implementation
******************************************************************************/
package org.jboss.tools.jst.jsp.contentassist;
@@ -40,6 +40,11 @@
this.fOriginalReplacementLength = replacementLength;
}
+ public AutoContentAssistantProposal(String replacementString, int replacementOffset, int
replacementLength, int cursorPosition, Image image, String displayString, String
alternateMatch, IContextInformation contextInformation, String additionalProposalInfo, int
relevance) {
+ super(replacementString, replacementOffset, replacementLength, cursorPosition,
image, displayString, alternateMatch, contextInformation, additionalProposalInfo,
relevance, true);
+ this.fOriginalReplacementLength = replacementLength;
+ }
+
public AutoContentAssistantProposal(String replacementString, int replacementOffset, int
replacementLength, int cursorPosition, Image image, String displayString,
IContextInformation contextInformation, String additionalProposalInfo, int relevance) {
super(replacementString, replacementOffset, replacementLength, cursorPosition,
image, displayString, contextInformation, additionalProposalInfo, relevance);
this.fOriginalReplacementLength = replacementLength;
Modified:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/contentassist/AutoELContentAssistantProposal.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/contentassist/AutoELContentAssistantProposal.java 2011-11-10
14:56:30 UTC (rev 36277)
+++
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/contentassist/AutoELContentAssistantProposal.java 2011-11-10
15:14:12 UTC (rev 36278)
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2010 Red Hat, Inc.
+ * Copyright (c) 2010-2011 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,
@@ -12,6 +12,7 @@
import java.io.Reader;
import java.io.StringReader;
+import java.util.List;
import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.IMember;
@@ -23,6 +24,9 @@
import org.eclipse.jface.internal.text.html.HTMLPrinter;
import org.eclipse.jface.text.contentassist.IContextInformation;
import org.eclipse.swt.graphics.Image;
+import org.jboss.tools.common.el.core.ca.MessagesELTextProposal;
+import org.jboss.tools.common.el.ui.ca.ELProposalProcessor;
+import org.jboss.tools.common.model.XModelObject;
/**
* Class to provide EL proposals to Content Assistant.
@@ -34,6 +38,7 @@
@SuppressWarnings("restriction")
public class AutoELContentAssistantProposal extends AutoContentAssistantProposal {
private IJavaElement[] fJavaElements;
+ private MessagesELTextProposal fProperySource;
private String fAdditionalProposalInfo;
/**
@@ -49,11 +54,31 @@
* @param elements
* @param relevance
*/
- public AutoELContentAssistantProposal(String replacementString, int replacementOffset,
int replacementLength, int cursorPosition, Image image, String displayString,
IContextInformation contextInformation, IJavaElement[] elements, int relevance) {
- super(replacementString, replacementOffset, replacementLength, cursorPosition,
image, displayString, contextInformation, null, relevance);
+ public AutoELContentAssistantProposal(String replacementString, int replacementOffset,
int replacementLength, int cursorPosition, Image image, String displayString, String
alternateMatch, IContextInformation contextInformation, IJavaElement[] elements, int
relevance) {
+ super(replacementString, replacementOffset, replacementLength, cursorPosition,
image, displayString, alternateMatch, contextInformation, null, relevance);
this.fJavaElements = elements;
+ this.fProperySource = null;
}
+ /**
+ * Constructs the proposal object
+ *
+ * @param replacementString
+ * @param replacementOffset
+ * @param replacementLength
+ * @param cursorPosition
+ * @param image
+ * @param displayString
+ * @param contextInformation
+ * @param properySource
+ * @param relevance
+ */
+ public AutoELContentAssistantProposal(String replacementString, int replacementOffset,
int replacementLength, int cursorPosition, Image image, String displayString, String
alternateMatch, IContextInformation contextInformation, MessagesELTextProposal
propertySource, int relevance) {
+ super(replacementString, replacementOffset, replacementLength, cursorPosition,
image, displayString, alternateMatch, contextInformation, null, relevance);
+ this.fJavaElements = null;
+ this.fProperySource = propertySource;
+ }
+
/*
* (non-Javadoc)
* @see
org.eclipse.wst.sse.ui.internal.contentassist.CustomCompletionProposal#getAdditionalProposalInfo()
@@ -62,6 +87,8 @@
if (fAdditionalProposalInfo == null) {
if (this.fJavaElements != null && this.fJavaElements.length > 0) {
this.fAdditionalProposalInfo = extractProposalContextInfo(fJavaElements);
+ } else if (fProperySource != null) {
+ this.fAdditionalProposalInfo = extractProposalContextInfo(fProperySource);
}
}
return fAdditionalProposalInfo;
@@ -109,18 +136,31 @@
}
}
- if (!hasContents)
+ if (!hasContents || buffer.length() == 0)
return null;
+
+ HTMLPrinter.insertPageProlog(buffer, 0, (String)null);
+ HTMLPrinter.addPageEpilog(buffer);
+ return buffer.toString();
+ }
- if (buffer.length() > 0) {
- HTMLPrinter.insertPageProlog(buffer, 0, (String)null);
- HTMLPrinter.addPageEpilog(buffer);
- return buffer.toString();
- }
+ /*
+ * Extracts the additional proposal information based on Javadoc for the stored
IJavaElement objects
+ */
+ private String extractProposalContextInfo(MessagesELTextProposal propertySource) {
+ StringBuffer buffer= new StringBuffer();
+ buffer.append(ELProposalProcessor.getELMessagesHoverInternal(propertySource.getBaseName(),
+ propertySource.getPropertyName(),
(List<XModelObject>)propertySource.getAllObjects()));
- return null;
+ if (buffer.length() == 0)
+ return null;
+
+ HTMLPrinter.insertPageProlog(buffer, 0, (String)null);
+ HTMLPrinter.addPageEpilog(buffer);
+ return buffer.toString();
}
+
private static final long LABEL_FLAGS= JavaElementLabels.ALL_FULLY_QUALIFIED
| JavaElementLabels.M_PRE_RETURNTYPE | JavaElementLabels.M_PARAMETER_TYPES |
JavaElementLabels.M_PARAMETER_NAMES | JavaElementLabels.M_EXCEPTIONS
| JavaElementLabels.F_PRE_TYPE_SIGNATURE | JavaElementLabels.M_PRE_TYPE_PARAMETERS |
JavaElementLabels.T_TYPE_PARAMETERS
Modified:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/contentassist/computers/XmlELCompletionProposalComputer.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/contentassist/computers/XmlELCompletionProposalComputer.java 2011-11-10
14:56:30 UTC (rev 36277)
+++
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/contentassist/computers/XmlELCompletionProposalComputer.java 2011-11-10
15:14:12 UTC (rev 36278)
@@ -42,6 +42,7 @@
import org.eclipse.wst.xml.ui.internal.contentassist.ContentAssistRequest;
import org.eclipse.wst.xml.ui.internal.contentassist.XMLContentModelGenerator;
import org.jboss.tools.common.el.core.ca.ELTextProposal;
+import org.jboss.tools.common.el.core.ca.MessagesELTextProposal;
import org.jboss.tools.common.el.core.model.ELInstance;
import org.jboss.tools.common.el.core.model.ELInvocationExpression;
import org.jboss.tools.common.el.core.model.ELModel;
@@ -164,14 +165,12 @@
@Override
protected void addAttributeValueELProposals(ContentAssistRequest contentAssistRequest,
CompletionProposalInvocationContext context) {
-
if (!isELCAToBeShown())
return;
TextRegion prefix = getELPrefix(contentAssistRequest);
- if (prefix == null) {
- return;
- }
+ if (prefix == null)
+ return; // Do not return any proposals here (predicate proposals may be created
instead)
if(!prefix.isELStarted()) {
AutoContentAssistantProposal proposal = new AutoContentAssistantProposal(true,
@@ -182,27 +181,27 @@
contentAssistRequest.addProposal(proposal);
return;
}
- String matchString = EL_NUMBER_PREFIX + prefix.getText(); //$NON-NLS-1$
+ String matchString = EL_NUMBER_PREFIX + prefix.getText();
String query = matchString;
- if (query == null)
- query = ""; //$NON-NLS-1$
String stringQuery = matchString;
int beginChangeOffset = prefix.getStartOffset() + prefix.getOffset();
KbQuery kbQuery = createKbQuery(Type.ATTRIBUTE_VALUE, query, stringQuery);
TextProposal[] proposals = PageProcessor.getInstance().getProposals(kbQuery,
getContext());
-
if (proposals == null || proposals.length == 0)
return;
+ String restOfValue = getRestOfEL(context.getDocument(),
context.getInvocationOffset());
for (TextProposal textProposal : proposals) {
int replacementOffset = beginChangeOffset;
int replacementLength = prefix.getLength();
String replacementString = prefix.getText().substring(0, replacementLength);
- if (textProposal.getReplacementString().trim().startsWith("[") &&
replacementString.endsWith(".")) { //$NON-NLS-1$ //$NON-NLS-2$
+ String alternateMatch = null;
+ if (textProposal.getReplacementString().trim().startsWith("[") &&
replacementString.indexOf('.') != -1) { //$NON-NLS-1$
// Need to include last '.' (dot) char into the string to replace
- replacementString = replacementString.substring(0, replacementString.length() - 1);
+ replacementString = replacementString.substring(0,
replacementString.lastIndexOf('.'));
+ alternateMatch = replacementString + '.' + textProposal.getAlternateMatch();
}
replacementString += textProposal.getReplacementString();
@@ -216,27 +215,6 @@
if (replacementString.indexOf('[') != -1) {
// That's it - The long message property
- // Need to get the rest of line from context.getInvocationOffset()
- IDocument doc = context.getDocument();
-
- String restOfLine = ""; //$NON-NLS-1$
- String restOfValue = ""; //$NON-NLS-1$
- int endPosition = -1;
- try {
- int line = doc.getLineOfOffset(context.getInvocationOffset());
- int lineStart = doc.getLineOffset(line);
- int lineLength = doc.getLineLength(line);
- String sDoc = doc.get();
- restOfValue = restOfLine = sDoc.substring(context.getInvocationOffset(), lineStart +
lineLength);
- endPosition = restOfValue.indexOf(quoteChar);
- if (endPosition != -1) {
- // Use end of line
- restOfValue = restOfValue.substring(0, endPosition);
- }
- } catch (BadLocationException e) {
- // Ignore it
- }
-
// Check if the replacementString is already configured
if (replacementString.indexOf(']') == -1) {
// Is closing ']' is in it?
@@ -244,8 +222,12 @@
// Is the quotation is in it?
int quoteIndex = restOfValue.indexOf('\'');
if (quoteIndex == -1 || paraIndex == -1 || (paraIndex != -1 && quoteIndex
> paraIndex)) {
- // Need to insert closing single-quote
- replacementString += '\'';
+ // Need to insert closing single-quote if there is no quote inserted
+ if (!replacementString.endsWith("\'")) //$NON-NLS-1$
+ replacementString += '\'';
+ } else {
+ if (quoteIndex != -1 && replacementString.endsWith("\'"))
//$NON-NLS-1$
+ replacementString = replacementString.substring(0, replacementString.length() -
1);
}
if (paraIndex == -1) {
// Closing ']' is to be added
@@ -254,17 +236,22 @@
} else {
if (replacementString.endsWith("]") &&
restOfValue.indexOf(']') != -1) { //$NON-NLS-1$
replacementString = replacementString.substring(0, replacementString.length() -1);
- cursorPosition = replacementString.length(); // Cursor will be put right after the
replacement (not after the closing square bracket in this case)
}
}
-
- if (restOfLine.indexOf('}') == -1) {
+ cursorPosition = replacementString.length(); // Cursor will be put right after the
replacement
+ if (replacementString.indexOf(']') == -1) { // Find closing square bracket in
restOfValue
+ if (restOfValue.indexOf(']') != -1) {
+ cursorPosition += restOfValue.indexOf(']') + 1;
+ }
+ }
+
+ if (restOfValue.indexOf('}') == -1) {
// Add closing }-char
replacementString += '}';
}
} else {
- if (!prefix.isELClosed()) {
- replacementString += '}';
+ if (restOfValue.indexOf('}') == -1) {
+ replacementString += "}"; //$NON-NLS-1$
}
}
@@ -291,13 +278,17 @@
IJavaElement[] javaElements = ((ELTextProposal)textProposal).getAllJavaElements();
proposal = new AutoELContentAssistantProposal(replacementString,
- replacementOffset, replacementLength, cursorPosition, image, displayString,
+ replacementOffset, replacementLength, cursorPosition, image, displayString, null,
null, javaElements, relevance);
+ } else if (textProposal instanceof MessagesELTextProposal) {
+ proposal = new AutoELContentAssistantProposal(replacementString,
+ replacementOffset, replacementLength, cursorPosition, image, displayString,
alternateMatch,
+ null, (MessagesELTextProposal)textProposal, relevance);
} else {
String additionalProposalInfo = (textProposal.getContextInfo() == null ? ""
: textProposal.getContextInfo()); //$NON-NLS-1$
proposal = new AutoContentAssistantProposal(replacementString,
- replacementOffset, replacementLength, cursorPosition, image, displayString,
+ replacementOffset, replacementLength, cursorPosition, image, displayString, null,
null, additionalProposalInfo, relevance);
}
contentAssistRequest.addProposal(proposal);
@@ -329,7 +320,7 @@
return;
}
String matchString = EL_NUMBER_PREFIX + prefix.getText();
- String query = matchString;
+ String query = (matchString == null ? "" : matchString); //$NON-NLS-1$
String stringQuery = matchString;
int beginChangeOffset = prefix.getStartOffset() + prefix.getOffset();
@@ -338,43 +329,26 @@
TextProposal[] proposals = PageProcessor.getInstance().getProposals(kbQuery,
getContext());
if (proposals == null || proposals.length == 0)
return;
-
+
+ String restOfValue = getRestOfEL(context.getDocument(),
context.getInvocationOffset());
for (TextProposal textProposal : proposals) {
int replacementOffset = beginChangeOffset;
int replacementLength = prefix.getLength();
String replacementString = prefix.getText().substring(0, replacementLength);
- if (textProposal.getReplacementString().trim().startsWith("[") &&
replacementString.endsWith(".")) { //$NON-NLS-1$ //$NON-NLS-2$
+ String alternateMatch = null;
+ if (textProposal.getReplacementString().trim().startsWith("[") &&
replacementString.indexOf('.') != -1) { //$NON-NLS-1$
// Need to include last '.' (dot) char into the string to replace
- replacementString = replacementString.substring(0, replacementString.length() - 1);
+ replacementString = replacementString.substring(0,
replacementString.lastIndexOf('.'));
+ alternateMatch = replacementString + '.' + textProposal.getAlternateMatch();
}
replacementString += textProposal.getReplacementString();
int cursorPosition = replacementString.length();
-
+
// Check if it is a long named property to be inserted
if (replacementString.indexOf('[') != -1) {
// That's it - The long message property
- // Need to get the rest of line from context.getInvocationOffset()
- IDocument doc = context.getDocument();
-
- String restOfLine = "";
- String restOfValue = "";
- int endPosition = -1;
- try {
- int line = doc.getLineOfOffset(context.getInvocationOffset());
- int lineStart = doc.getLineOffset(line);
- int lineLength = doc.getLineLength(line);
- String sDoc = doc.get();
- restOfValue = restOfLine = sDoc.substring(context.getInvocationOffset(), lineStart +
lineLength);
- if (endPosition != -1) {
- // Use end of line
- restOfValue = restOfValue.substring(0, endPosition);
- }
- } catch (BadLocationException e) {
- // Ignore it
- }
-
// Check if the replacementString is already configured
if (replacementString.indexOf(']') == -1) {
// Is closing ']' is in it?
@@ -382,8 +356,12 @@
// Is the quotation is in it?
int quoteIndex = restOfValue.indexOf('\'');
if (quoteIndex == -1 || paraIndex == -1 || (paraIndex != -1 && quoteIndex
> paraIndex)) {
- // Need to insert closing single-quote
- replacementString += '\'';
+ // Need to insert closing single-quote if there is no quote inserted
+ if (!replacementString.endsWith("\'"))
+ replacementString += '\'';
+ } else {
+ if (quoteIndex != -1 && replacementString.endsWith("\'"))
+ replacementString = replacementString.substring(0, replacementString.length() -
1);
}
if (paraIndex == -1) {
// Closing ']' is to be added
@@ -392,16 +370,21 @@
} else {
if (replacementString.endsWith("]") &&
restOfValue.indexOf(']') != -1) {
replacementString = replacementString.substring(0, replacementString.length() -1);
- cursorPosition = replacementString.length(); // Cursor will be put right after the
replacement (not after the closing square bracket in this case)
}
}
+ cursorPosition = replacementString.length(); // Cursor will be put right after the
replacement
+ if (replacementString.indexOf(']') == -1) { // Find closing square bracket in
restOfValue
+ if (restOfValue.indexOf(']') != -1) {
+ cursorPosition += restOfValue.indexOf(']') + 1;
+ }
+ }
- if (restOfLine.indexOf('}') == -1) {
+ if (restOfValue.indexOf('}') == -1) {
// Add closing }-char
replacementString += '}';
}
} else {
- if (!prefix.isELClosed()) {
+ if (restOfValue.indexOf('}') == -1) {
replacementString += "}"; //$NON-NLS-1$
}
}
@@ -425,13 +408,17 @@
IJavaElement[] javaElements = ((ELTextProposal)textProposal).getAllJavaElements();
proposal = new AutoELContentAssistantProposal(replacementString,
- replacementOffset, replacementLength, cursorPosition, image, displayString,
+ replacementOffset, replacementLength, cursorPosition, image, displayString, null,
null, javaElements, relevance);
+ } else if (textProposal instanceof MessagesELTextProposal) {
+ proposal = new AutoELContentAssistantProposal(replacementString,
+ replacementOffset, replacementLength, cursorPosition, image, displayString,
alternateMatch,
+ null, (MessagesELTextProposal)textProposal, relevance);
} else {
String additionalProposalInfo = (textProposal.getContextInfo() == null ? ""
: textProposal.getContextInfo()); //$NON-NLS-1$
proposal = new AutoContentAssistantProposal(replacementString,
- replacementOffset, replacementLength, cursorPosition, image, displayString,
+ replacementOffset, replacementLength, cursorPosition, image, displayString, null,
null, additionalProposalInfo, relevance);
}
@@ -440,7 +427,7 @@
if (prefix.isELStarted() && !prefix.isELClosed()) {
AutoContentAssistantProposal proposal = new
AutoContentAssistantProposal("}", //$NON-NLS-1$
- getOffset(), 0, 1, JSF_EL_PROPOSAL_IMAGE,
JstUIMessages.JspContentAssistProcessor_CloseELExpression,
+ getOffset(), 0, 1, JSF_EL_PROPOSAL_IMAGE,
JstUIMessages.JspContentAssistProcessor_CloseELExpression, null,
null, JstUIMessages.JspContentAssistProcessor_CloseELExpressionInfo,
TextProposal.R_XML_ATTRIBUTE_VALUE_TEMPLATE);
contentAssistRequest.addProposal(proposal);
@@ -465,10 +452,9 @@
return;
}
String matchString = EL_NUMBER_PREFIX + prefix.getText();
- String query = matchString;
- if (query == null)
- query = ""; //$NON-NLS-1$
+ String query = (matchString == null ? "" : matchString); //$NON-NLS-1$
String stringQuery = matchString;
+
int relevanceShift = -2; // Fix for JBIDE-5987: Relevance for predicate proposals is
shifted down by default to show EL proposals lower than attr-value proposals
if (shiftRelevanceAgainstTagNameProposals) {
relevanceShift += prefix.getText() != null && prefix.getText().trim().length()
> 0 ? 0 : -2;
@@ -518,13 +504,13 @@
IJavaElement[] javaElements = ((ELTextProposal)textProposal).getAllJavaElements();
proposal = new AutoELContentAssistantProposal(replacementString,
- replacementOffset, replacementLength, cursorPosition, image, displayString,
+ replacementOffset, replacementLength, cursorPosition, image, displayString, null,
null, javaElements, relevance);
} else {
String additionalProposalInfo = (textProposal.getContextInfo() == null ? ""
: textProposal.getContextInfo()); //$NON-NLS-1$
proposal = new AutoContentAssistantProposal(replacementString,
- replacementOffset, replacementLength, cursorPosition, image, displayString,
+ replacementOffset, replacementLength, cursorPosition, image, displayString, null,
null, additionalProposalInfo, relevance);
}
contentAssistRequest.addProposal(proposal);
@@ -783,7 +769,35 @@
}
}
}
+
+ protected String getRestOfEL(IDocument doc, int invokationOffset) {
+ int endPosition = -1;
+ try {
+ int line = doc.getLineOfOffset(invokationOffset);
+ int lineStart = doc.getLineOffset(line);
+ int lineLength = doc.getLineLength(line);
+ String sDoc = doc.get();
+ String restOfValue = sDoc.substring(invokationOffset, lineStart + lineLength);
+
+ int boel = restOfValue.indexOf("#{"); //$NON-NLS-1$
+ boel = (boel == -1 ? restOfValue.indexOf("${") : boel); //$NON-NLS-1$
+ int eoel = restOfValue.indexOf('}');
+ eoel = (eoel == -1 ? -1 : eoel + 1);
+
+ endPosition = boel;
+ if (endPosition == -1 || endPosition > eoel)
+ endPosition = eoel;
+ if (endPosition != -1)
+ restOfValue = restOfValue.substring(0, endPosition);
+
+ return restOfValue;
+ } catch (BadLocationException e) {
+ // Ignore it
+ return ""; //$NON-NLS-1$
+ }
+ }
+
/**
* Returns URI for the current/parent tag
* @return
Modified:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/jspeditor/info/ELInfoHoverMessages.properties
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/jspeditor/info/ELInfoHoverMessages.properties 2011-11-10
14:56:30 UTC (rev 36277)
+++
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/jspeditor/info/ELInfoHoverMessages.properties 2011-11-10
15:14:12 UTC (rev 36278)
@@ -3,11 +3,3 @@
ELInfoHover_noAttachedJavadoc= <em>Note: This element has no attached Javadoc and
the Javadoc could not be found in the attached source.</em>
ELInfoHover_noInformation= <em>Note: The Javadoc for this element could neither be
found in the attached source nor the attached Javadoc.</em>
ELInfoHover_error_gettingJavadoc= <em>Note: An exception occurred while getting the
Javadoc. See log for details.</em>
-ELInfoHover_baseName=<b>Base Name:</b> {0}<br>
-ELInfoHover_propertyName=<b>Property:</b> {0}<br>
-ELInfoHover_resourceBundle=<b>Resource Bundle:</b> {0}<br>
-ELInfoHover_resourceBundlePropertyValue=<b>Value:</b> {0}{1}<br>
-ELInfoHover_resourceBundlePropertyValueNotDefined=[Value not defined]
-ELInfoHover_resourceBundleNotDefined=[Resource Bundle not defined]
-ELInfoHover_newLine=<br>
-ELInfoHover_treeDots=...
Modified:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/jspeditor/info/FaceletTagInfoHoverProcessor.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/jspeditor/info/FaceletTagInfoHoverProcessor.java 2011-11-10
14:56:30 UTC (rev 36277)
+++
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/jspeditor/info/FaceletTagInfoHoverProcessor.java 2011-11-10
15:14:12 UTC (rev 36278)
@@ -13,14 +13,11 @@
import java.io.IOException;
import java.io.Reader;
import java.io.StringReader;
-import java.text.MessageFormat;
import java.util.List;
import java.util.Map;
import org.eclipse.core.filebuffers.FileBuffers;
import org.eclipse.core.resources.IFile;
-import org.eclipse.core.resources.IResource;
-import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
import org.eclipse.jdt.core.IJavaElement;
@@ -56,10 +53,10 @@
import org.jboss.tools.common.el.core.resolver.ELResolver;
import org.jboss.tools.common.el.core.resolver.ELSegment;
import org.jboss.tools.common.el.core.resolver.JavaMemberELSegmentImpl;
-import org.jboss.tools.common.el.core.resolver.MessagePropertyELSegment;
+import org.jboss.tools.common.el.ui.ca.ELProposalProcessor;
import org.jboss.tools.common.model.XModelObject;
-import org.jboss.tools.common.model.filesystems.impl.JarSystemImpl;
import org.jboss.tools.common.text.TextProposal;
+import org.jboss.tools.common.util.StringUtil;
import org.jboss.tools.jst.jsp.contentassist.Utils;
import
org.jboss.tools.jst.jsp.contentassist.computers.AbstractXmlCompletionProposalComputer.TextRegion;
import org.jboss.tools.jst.web.kb.IPageContext;
@@ -224,73 +221,10 @@
return (hover == null ? null : hover.getHtml());
} else if (segment instanceof MessagePropertyELSegmentImpl) {
MessagePropertyELSegmentImpl mpSegment = (MessagePropertyELSegmentImpl)segment;
-
String baseName = mpSegment.getBaseName();
- String propertyName = ((MessagePropertyELSegment)segment).isBundle() ? null :
trimQuotes(segment.getToken().getText());
+ String propertyName = mpSegment.isBundle() ? null :
StringUtil.trimQuotes(segment.getToken().getText());
- StringBuilder sb = new StringBuilder();
- if (propertyName != null && propertyName.length() > 0)
- sb.append(MessageFormat.format(ELInfoHoverMessages.ELInfoHover_propertyName,
- propertyName));
-
- if (baseName != null && baseName.length() > 0)
- sb.append(MessageFormat.format(ELInfoHoverMessages.ELInfoHover_baseName,
- baseName));
- sb.append(ELInfoHoverMessages.ELInfoHover_newLine);
-
- List<XModelObject> objects = (List<XModelObject>)mpSegment.getObjects();
- for (XModelObject o : objects) {
- IFile propFile = (IFile)o.getAdapter(IFile.class);
- String propFilePath = null;
- if (propFile != null) {
- propFilePath = propFile.getFullPath().toString();
- } else {
- XModelObject parent = o.getFileType() == XModelObject.FILE ? o : o.getParent();
- String path = parent.getPath();
- while (parent != null && parent.getFileType() != XModelObject.SYSTEM) {
- parent = parent.getParent();
- }
- if (parent instanceof JarSystemImpl) {
- String sysPath = parent.getPath();
- path = path.substring(sysPath.length());
-
- String jarPath = ((JarSystemImpl) parent).getLocation();
-
- IResource jar = ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(new
Path(jarPath));
-
- if (jar != null) {
- jarPath = jar.getFullPath().toString();
- }
-
- propFilePath = jarPath + "!" + path; //$NON-NLS-1$
- }
- }
- sb.append(MessageFormat.format(ELInfoHoverMessages.ELInfoHover_resourceBundle,
- propFilePath != null ? propFilePath :
ELInfoHoverMessages.ELInfoHover_resourceBundleNotDefined));
-
- if (propertyName != null) {
- String value = o.get("VALUE"); //$NON-NLS-1$
- boolean addCut = false;
- if (value != null) {
- if (value.length() > 100) {
- // Get first words of value
- int lastSpace = value.lastIndexOf(' ', 99);
- if (lastSpace != -1) {
- value = value.substring(0, lastSpace);
- } else { // cut as is
- value = value.substring(0, 100);
- }
- addCut = true;
- }
- }
- sb.append(MessageFormat.format(ELInfoHoverMessages.ELInfoHover_resourceBundlePropertyValue,
- value != null ? value :
ELInfoHoverMessages.ELInfoHover_resourceBundlePropertyValueNotDefined,
- addCut ? ELInfoHoverMessages.ELInfoHover_treeDots : ""));
//$NON-NLS-1$
- sb.append(ELInfoHoverMessages.ELInfoHover_newLine);
- }
- }
-
- return sb.toString();
+ return ELProposalProcessor.getELMessagesHoverInternal(baseName, propertyName,
(List<XModelObject>)mpSegment.getObjects());
}
}
@@ -511,19 +445,4 @@
}
};
}
-
- private String trimQuotes(String value) {
- if(value == null)
- return null;
-
- if(value.startsWith("'") || value.startsWith("\"")) {
//$NON-NLS-1$ //$NON-NLS-2$
- value = value.substring(1);
- }
-
- if(value.endsWith("'") || value.endsWith("\"")) {
//$NON-NLS-1$ //$NON-NLS-2$
- value = value.substring(0, value.length() - 1);
- }
- return value;
- }
-
}
Modified:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/jspeditor/info/JavaStringELInfoHover.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/jspeditor/info/JavaStringELInfoHover.java 2011-11-10
14:56:30 UTC (rev 36277)
+++
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/jspeditor/info/JavaStringELInfoHover.java 2011-11-10
15:14:12 UTC (rev 36278)
@@ -16,6 +16,7 @@
import java.io.Reader;
import java.io.StringReader;
import java.net.URL;
+import java.util.List;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;
@@ -57,13 +58,17 @@
import org.jboss.tools.common.el.core.resolver.ELResolver;
import org.jboss.tools.common.el.core.resolver.ELSegment;
import org.jboss.tools.common.el.core.resolver.JavaMemberELSegmentImpl;
+import org.jboss.tools.common.el.ui.ca.ELProposalProcessor;
+import org.jboss.tools.common.model.XModelObject;
import org.jboss.tools.common.text.TextProposal;
+import org.jboss.tools.common.util.StringUtil;
import org.jboss.tools.jst.jsp.JspEditorPlugin;
import org.jboss.tools.jst.jsp.contentassist.Utils;
import org.jboss.tools.jst.web.kb.KbQuery;
import org.jboss.tools.jst.web.kb.PageContextFactory;
import org.jboss.tools.jst.web.kb.PageProcessor;
import org.jboss.tools.jst.web.kb.KbQuery.Type;
+import org.jboss.tools.jst.web.kb.el.MessagePropertyELSegmentImpl;
import org.osgi.framework.Bundle;
/**
@@ -253,6 +258,8 @@
continue;
ELSegment segment = resolution.getLastSegment();
+ if (!segment.isResolved()) continue;
+
if(segment instanceof JavaMemberELSegmentImpl) {
JavaMemberELSegmentImpl jmSegment = (JavaMemberELSegmentImpl)segment;
@@ -267,6 +274,17 @@
continue;
return JavaStringELInfoHover.getHoverInfo2Internal(javaElements, true);
+ } else if (segment instanceof MessagePropertyELSegmentImpl) {
+ MessagePropertyELSegmentImpl mpSegment = (MessagePropertyELSegmentImpl)segment;
+ String baseName = mpSegment.getBaseName();
+ String propertyName = mpSegment.isBundle() ? null :
StringUtil.trimQuotes(segment.getToken().getText());
+ String hoverText = ELProposalProcessor.getELMessagesHoverInternal(baseName,
propertyName, (List<XModelObject>)mpSegment.getObjects());
+ StringBuffer buffer = new StringBuffer(hoverText);
+
+ HTMLPrinter.insertPageProlog(buffer, 0, getStyleSheet());
+ HTMLPrinter.addPageEpilog(buffer);
+
+ return new ELInfoHoverBrowserInformationControlInput(null, new IJavaElement[0],
buffer.toString(), 0);
}
}
Modified:
trunk/jst/plugins/org.jboss.tools.jst.text.ext/src/org/jboss/tools/jst/text/ext/hyperlink/ELHyperlink.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.text.ext/src/org/jboss/tools/jst/text/ext/hyperlink/ELHyperlink.java 2011-11-10
14:56:30 UTC (rev 36277)
+++
trunk/jst/plugins/org.jboss.tools.jst.text.ext/src/org/jboss/tools/jst/text/ext/hyperlink/ELHyperlink.java 2011-11-10
15:14:12 UTC (rev 36278)
@@ -27,6 +27,7 @@
import org.jboss.tools.common.text.ext.hyperlink.AbstractHyperlink;
import org.jboss.tools.common.text.ext.hyperlink.xpl.Messages;
import org.jboss.tools.common.text.ext.util.StructuredSelectionHelper;
+import org.jboss.tools.common.util.StringUtil;
import org.jboss.tools.jst.text.ext.JSTExtensionsPlugin;
public class ELHyperlink extends AbstractHyperlink{
@@ -80,20 +81,6 @@
}
}
- private String trimQuotes(String value) {
- if(value == null)
- return null;
-
- if(value.startsWith("'") || value.startsWith("\"")) {
//$NON-NLS-1$ //$NON-NLS-2$
- value = value.substring(1);
- }
-
- if(value.endsWith("'") || value.endsWith("\"")) {
//$NON-NLS-1$ //$NON-NLS-2$
- value = value.substring(0, value.length() - 1);
- }
- return value;
- }
-
// private String getRequestMethod(Properties prop) {
// return prop != null && prop.getProperty(WebPromptingProvider.KEY) == null ?
// WebPromptingProvider.JSF_OPEN_BUNDLE : WebPromptingProvider.JSF_OPEN_KEY;
@@ -110,7 +97,7 @@
}else if(segment instanceof MessagePropertyELSegment){
//TODO move to getLabel() in openable in MessagePropertyELSegmentImpl
String baseName = ((MessagePropertyELSegment)segment).getBaseName();
- String propertyName = ((MessagePropertyELSegment)segment).isBundle() ? null :
trimQuotes(((MessagePropertyELSegment)segment).getToken().getText());
+ String propertyName = ((MessagePropertyELSegment)segment).isBundle() ? null :
StringUtil.trimQuotes(((MessagePropertyELSegment)segment).getToken().getText());
if (propertyName == null)
return MessageFormat.format(Messages.Open, baseName);
Modified:
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/el/MessagePropertyELSegmentImpl.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/el/MessagePropertyELSegmentImpl.java 2011-11-10
14:56:30 UTC (rev 36277)
+++
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/el/MessagePropertyELSegmentImpl.java 2011-11-10
15:14:12 UTC (rev 36278)
@@ -18,7 +18,6 @@
import org.eclipse.core.resources.IResource;
import org.eclipse.swt.graphics.Image;
import org.jboss.tools.common.el.core.ElCoreMessages;
-import org.jboss.tools.common.el.core.ca.AbstractELCompletionEngine;
import org.jboss.tools.common.el.core.parser.LexicalToken;
import org.jboss.tools.common.el.core.resolver.ELSegmentImpl;
import org.jboss.tools.common.el.core.resolver.IOpenableReference;
@@ -26,6 +25,7 @@
import org.jboss.tools.common.model.XModelObject;
import org.jboss.tools.common.model.util.FindObjectHelper;
import org.jboss.tools.common.text.ITextSourceReference;
+import org.jboss.tools.common.util.StringUtil;
/**
* @author Daniel Azarov
@@ -123,7 +123,7 @@
// Improve label - add a locale for a resource bundle
String baseName = getBaseName();
- String propertyName = isBundle() ? null :
AbstractELCompletionEngine.trimQuotes(getToken().getText());
+ String propertyName = isBundle() ? null :
StringUtil.trimQuotes(getToken().getText());
if (propertyName == null)
return MessageFormat.format(ElCoreMessages.OpenBundle, baseName);
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 2011-11-10
14:56:30 UTC (rev 36277)
+++
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/el/SeamELCompletionEngine.java 2011-11-10
15:14:12 UTC (rev 36278)
@@ -49,6 +49,7 @@
import org.jboss.tools.common.model.XModelObjectConstants;
import org.jboss.tools.common.model.filesystems.FileSystemsHelper;
import org.jboss.tools.common.text.TextProposal;
+import org.jboss.tools.common.util.StringUtil;
import org.jboss.tools.jst.web.kb.el.MessagePropertyELSegmentImpl;
import org.jboss.tools.seam.core.IBijectedAttribute;
import org.jboss.tools.seam.core.ISeamComponent;
@@ -217,26 +218,26 @@
} else if (expr instanceof ELArgumentInvocation) {
segment = new
MessagePropertyELSegmentImpl(((ELArgumentInvocation)expr).getArgument().getOpenArgumentToken().getNextToken());
}
- if(segment.getToken() == null) {
- return false;
- }
Set<TextProposal> kbProposals = new
TreeSet<TextProposal>(TextProposal.KB_PROPOSAL_ORDER);
- String propertyName = segment.getToken().getText();
- Map<String, List<XModelObject>> properties =
messagesInfo.getPropertiesMap();
- List<XModelObject> os = properties.get(trimQuotes(propertyName));
- if(os != null) {
- for(XModelObject o: os) {
- segment.addObject(o);
+ if (segment.getToken() != null) {
+ String propertyName = segment.getToken().getText();
+ Map<String, List<XModelObject>> properties =
messagesInfo.getPropertiesMap();
+ List<XModelObject> os = properties.get(StringUtil.trimQuotes(propertyName));
+ if(os != null) {
+ for(XModelObject o: os) {
+ segment.addObject(o);
+ }
+
+ // Using 'base name' in seam is not a good idea.
+ // if(!os.isEmpty()) {
+ // segment.setBaseName(getBundle(os.get(0)));
+ // } else {
+ // segment.setBaseName("messages");
+ // }
}
- if(!os.isEmpty()) {
- segment.setBaseName(getBundle(os.get(0)));
- } else {
- segment.setBaseName("messages");
- }
- }
-
+ }
if(segment.getToken()!=null) {
resolution.addSegment(segment);
}
@@ -248,73 +249,66 @@
}
} else
if(expr.getType() != ELObjectType.EL_ARGUMENT_INVOCATION) {
- Set<String> proposalsToFilter = new TreeSet<String>();
+ String filter = (expr.getMemberName() == null ? "" : expr.getMemberName());
+
for (TypeInfoCollector.MemberInfo mbr : members) {
- filterSingularMember((MessagesInfo)mbr, proposalsToFilter);
- }
- for (String proposal : proposalsToFilter) {
- // We do expect nothing but name for method tokens (No round brackets)
- String filter = expr.getMemberName();
- if(filter == null) filter = ""; //$NON-NLS-1$
- if(returnEqualedVariablesOnly) {
- // This is used for validation.
- if (proposal.equals(filter)) {
- MessagesELTextProposal kbProposal = createProposal(messagesInfo, proposal);
+ Collection<String> keys = ((MessagesInfo)mbr).getKeys();
+ for (String key : keys) {
+ if(returnEqualedVariablesOnly) {
+ // This is used for validation.
+ if (key.equals(filter)) {
+ MessagesELTextProposal kbProposal = createProposal(messagesInfo, key);
+ kbProposals.add(kbProposal);
+ break;
+ }
+ } else if (key.startsWith(filter)) {
+ // This is used for CA.
+ MessagesELTextProposal kbProposal = createProposal(messagesInfo, key);
+ if (key.indexOf('.') ==
-1) kbProposal.setReplacementString(key.substring(filter.length()));
+ else kbProposal.setReplacementString('[' +
kbProposal.getReplacementString());
kbProposals.add(kbProposal);
- break;
}
- } else if (proposal.startsWith(filter)) {
- // This is used for CA.
- MessagesELTextProposal kbProposal = createProposal(messagesInfo, proposal);
- kbProposal.setReplacementString(proposal.substring(filter.length()));
- kbProposals.add(kbProposal);
}
}
} else if(expr.getType() == ELObjectType.EL_ARGUMENT_INVOCATION) {
- Set<String> proposalsToFilter = new TreeSet<String>();
- boolean isMessages = false;
+ String filter = expr.getMemberName() == null ? "" : expr.getMemberName();
+ boolean b = filter.startsWith("'") ||
filter.startsWith("\""); //$NON-NLS-1$ //$NON-NLS-2$
+ filter = StringUtil.trimQuotes(filter);
+
for (TypeInfoCollector.MemberInfo mbr : members) {
- isMessages = true;
- filterSingularMember((MessagesInfo)mbr, proposalsToFilter);
- }
- String filter = expr.getMemberName();
- boolean bSurroundWithQuotes = false;
- if(filter == null) {
- filter = ""; //$NON-NLS-1$
- bSurroundWithQuotes = true;
- } else {
- boolean b = filter.startsWith("'") ||
filter.startsWith("\""); //$NON-NLS-1$ //$NON-NLS-2$
- boolean e = filter.endsWith("'") ||
filter.endsWith("\""); //$NON-NLS-1$ //$NON-NLS-2$
- if((b) && (e)) {
- filter = filter.length() == 1 ? "" : filter.substring(1, filter.length() -
1); //$NON-NLS-1$
- } else if(b && !returnEqualedVariablesOnly) {
- filter = filter.substring(1);
- } else {
+ if (!b && filter.length() > 0) {
//Value is set as expression itself, we cannot compute it
- if(isMessages) {
- resolution.setMapOrCollectionOrBundleAmoungTheTokens(true);
- }
+ resolution.setMapOrCollectionOrBundleAmoungTheTokens(true);
return true;
}
- }
- for (String proposal : proposalsToFilter) {
- if(returnEqualedVariablesOnly) {
- // This is used for validation.
- if (proposal.equals(filter)) {
- MessagesELTextProposal kbProposal = createProposal(messagesInfo, proposal);
+ Collection<String> keys = ((MessagesInfo)mbr).getKeys();
+ for (String key : keys) {
+ if(returnEqualedVariablesOnly) {
+ // This is used for validation.
+ if (key.equals(filter)) {
+ MessagesELTextProposal kbProposal = createProposal(messagesInfo, key);
+ kbProposals.add(kbProposal);
+ break;
+ }
+ } else if (key.startsWith(filter)) {
+ // This is used for CA.
+ MessagesELTextProposal kbProposal = createProposal(messagesInfo, key);
+ String existingString = expr.getMemberName() == null ? "" :
expr.getMemberName();
+ // Because we're in argument invocation we should fix the proposal by
surrounding it with quotes as needed
+ String replacement = kbProposal.getReplacementString();
+ String label = kbProposal.getLabel();
+ if (!replacement.startsWith("'")) {
+ replacement = '\'' + key + '\'';
+ label = "['" + key + "']";
+ }
+ replacement = replacement.substring(existingString.length());
+
+ kbProposal.setReplacementString(replacement);
+ kbProposal.setLabel(label);
+
kbProposals.add(kbProposal);
- break;
}
- } else if (proposal.startsWith(filter)) {
- // This is used for CA.
- MessagesELTextProposal kbProposal = createProposal(messagesInfo, proposal);
- String replacementString = proposal.substring(filter.length());
- if (bSurroundWithQuotes) {
- replacementString = "'" + replacementString + "']";
//$NON-NLS-1$ //$NON-NLS-2$
- }
- kbProposal.setReplacementString(replacementString);
- kbProposals.add(kbProposal);
}
}
}
@@ -336,29 +330,40 @@
String key = sortedKeys.next();
if (key == null || key.length() == 0)
continue;
+
MessagesELTextProposal proposal = createProposal((MessagesInfo)mbr, key);
+ if (key.indexOf('.') != -1) {
+ proposal.setReplacementString("['" + key + "']");
//$NON-NLS-1$ //$NON-NLS-2$
+ proposal.setLabel("['" + key + "']");
+ } else {
+ proposal.setReplacementString(key);
+ proposal.setLabel(key);
+ }
kbProposals.add(proposal);
}
}
}
private MessagesELTextProposal createProposal(MessagesInfo mbr, String proposal) {
- Map<String, List<XModelObject>> properties = mbr.getPropertiesMap();
- List<XModelObject> ps = properties.get(proposal);
- String bundle = ps.isEmpty() ? "messages" : getBundle(ps.get(0));
-
MessagesELTextProposal kbProposal = new MessagesELTextProposal();
- kbProposal.setBaseName(bundle);
- kbProposal.setObjects(ps);
-
if (proposal.indexOf('.') != -1) {
- kbProposal.setReplacementString("['" + proposal + "']");
+ kbProposal.setReplacementString('\'' + proposal + '\'');
kbProposal.setLabel("['" + proposal + "']");
} else {
kbProposal.setReplacementString(proposal);
kbProposal.setLabel(proposal);
}
+ kbProposal.setAlternateMatch(proposal);
kbProposal.setImage(SEAM_MESSAGES_PROPOSAL_IMAGE);
+
+ Map<String, List<XModelObject>> properties = mbr.getPropertiesMap();
+ List<XModelObject> ps = properties.get(proposal);
+// String bundle = ps.isEmpty() ? "messages" : getBundle(ps.get(0)); // Using
'base name' in seam is not a good idea.
+
+// kbProposal.setBaseName(bundle); // Using 'base name' in seam is not a good
idea.
+ kbProposal.setPropertyName(proposal);
+ kbProposal.setObjects(ps);
+
return kbProposal;
}
@@ -383,13 +388,6 @@
}
}
- protected void filterSingularMember(MessagesInfo mbr, Set<String>
proposalsToFilter) {
- Collection<String> keys = ((MessagesInfo)mbr).getKeys();
- for (String key : keys) {
- proposalsToFilter.add(key);
- }
- }
-
/**
* Returns scope for the resource
* @param project