Author: vrubezhny
Date: 2008-06-19 09:29:07 -0400 (Thu, 19 Jun 2008)
New Revision: 8850
Modified:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/contentassist/JSPActiveContentAssistProcessor.java
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/contentassist/xpl/JSPBaseContentAssistProcessor.java
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/support/kb/WTPKbdBeanPropertyResource.java
Log:
http://jira.jboss.com/jira/browse/JBIDE-2317 Problems with code complete in JSF editor
http://jira.jboss.com/jira/browse/JBIDE-2334 JSF EL Code assist should add EL to attribute
value but not replace whole not-EL value.
Issues are fixed
Modified:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/contentassist/JSPActiveContentAssistProcessor.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/contentassist/JSPActiveContentAssistProcessor.java 2008-06-19
10:49:46 UTC (rev 8849)
+++
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/contentassist/JSPActiveContentAssistProcessor.java 2008-06-19
13:29:07 UTC (rev 8850)
@@ -13,6 +13,10 @@
import java.util.Collection;
import java.util.Iterator;
+import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.ITextViewer;
+import org.eclipse.wst.sse.core.utils.StringUtils;
import org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode;
import org.eclipse.wst.xml.ui.internal.contentassist.ContentAssistRequest;
import org.eclipse.wst.xml.ui.internal.contentassist.XMLRelevanceConstants;
@@ -73,7 +77,42 @@
tagName = FaceletsHtmlContentAssistProcessor.faceletHtmlPrefixStart + tagName;
}
- String query = new
StringBuffer(KbQuery.TAG_SEPARATOR).append(tagName).append(KbQuery.ATTRIBUTE_SEPARATOR).append(attributeName).append(KbQuery.ENUMERATION_SEPARATOR).append(matchString).toString();
+ if(!currentValue.startsWith("\"") &&
!currentValue.startsWith("'")) {
+ // Do not show any value proposals if the attribute value is not started with a
quote/double-quote character
+ return;
+ }
+
+ String matchStringForQuery = matchString;
+ String strippedValueForQuery = strippedValue;
+ int elStartPosition = getELStartPosition(matchString);
+ int delta = 0;
+ String proposalPrefix = "";
+ String proposalSufix = "";
+ if (elStartPosition == -1) {
+ if(isCharSharp(matchString, offset-1)) {
+ proposalPrefix = "{"; //$NON-NLS-1$
+ } else {
+ proposalPrefix = "#{"; //$NON-NLS-1$
+ }
+ }
+
+ if (elStartPosition == -1) {
+ matchStringForQuery = "#{";
+ strippedValueForQuery = "";
+ delta = matchString.length();
+ } else {
+ matchStringForQuery = matchString.substring(elStartPosition);
+ strippedValueForQuery = matchStringForQuery;
+ delta = matchString.length() - matchStringForQuery.length();
+ }
+
+ // Correct delta if matchString starts with a quote (exclude that quote)
+ if (matchString.startsWith("\"") ||
matchString.startsWith("'")) {
+ strippedValueForQuery = matchString.substring(0,1) + strippedValueForQuery;
+ delta--;
+ }
+
+ String query = new
StringBuffer(KbQuery.TAG_SEPARATOR).append(tagName).append(KbQuery.ATTRIBUTE_SEPARATOR).append(attributeName).append(KbQuery.ENUMERATION_SEPARATOR).append(matchStringForQuery).toString();
try {
Collection proposals = wtpKbConnector.getProposals(query);
if(proposals.size()==0 && htmlQuery!=null) {
@@ -81,7 +120,7 @@
}
for (Iterator iter = proposals.iterator(); iter.hasNext();) {
KbProposal kbProposal = cleanFaceletProposal((KbProposal)iter.next());
- kbProposal.postProcess(strippedValue, offset);
+ kbProposal.postProcess(strippedValueForQuery, offset - delta);
int relevance = kbProposal.getRelevance();
if(relevance==KbProposal.R_NONE) {
relevance = XMLRelevanceConstants.R_XML_ATTRIBUTE_VALUE;
@@ -89,59 +128,39 @@
if(kbProposal.getStart() >= 0) {
String replacementString = kbProposal.getReplacementString();
- int replacementBeginPosition =
contentAssistRequest.getReplacementBeginPosition() + kbProposal.getStart();
+ int replacementBeginPosition =
contentAssistRequest.getReplacementBeginPosition() + kbProposal.getStart() + delta;
int replacementLength = kbProposal.getEnd() - kbProposal.getStart();
int cursorPositionDelta = 0;
- if(currentValue.startsWith("\"") ||
currentValue.startsWith("'")) {
- replacementBeginPosition = replacementBeginPosition +1;
+
+ // Add an EL-starting quotation characters if needed
+ if (elStartPosition == -1) {
+ replacementString = proposalPrefix + replacementString;
+ cursorPositionDelta += proposalPrefix.length();
+ }
+
+ if((currentValue.length() > StringUtils.strip(currentValue).length())
&&
+ (currentValue.endsWith("\"") ||
currentValue.endsWith("'")) ) {
+ if(!currentValue.endsWith("}\"")) {
+ replacementString += "}";
+ }
} else {
- cursorPositionDelta++;
- replacementString = "\"" + replacementString;
- }
- if(currentValue.endsWith("\"") ||
currentValue.endsWith("'")) {
- if(currentValue.endsWith(".}\"") &&
replacementString.endsWith("}")) {
- replacementLength--;
- replacementString = replacementString.substring(0,
replacementString.length()-1);
+ if(elStartPosition == -1 &&
!currentValue.endsWith("}")) {
+ replacementString += "}";
}
- } else {
- replacementString += ("\"");
+// replacementString += ("\"");
}
int cursorPosition = kbProposal.getPosition() + cursorPositionDelta;
- AutoContentAssistantProposal proposal = new
AutoContentAssistantProposal(kbProposal.autoActivationContentAssistantAfterApplication(),
replacementString,
- replacementBeginPosition, replacementLength, cursorPosition,
SharedXMLEditorPluginImageHelper.getImage(SharedXMLEditorPluginImageHelper.IMG_OBJ_ATTRIBUTE),
- kbProposal.getLabel(), null, kbProposal.getContextInfo(), relevance);
+ String displayString = elStartPosition == -1 ?
+ proposalPrefix + kbProposal.getReplacementString() + "}" :
+ kbProposal.getReplacementString();
+ AutoContentAssistantProposal proposal = new
AutoContentAssistantProposal(
+ kbProposal.autoActivationContentAssistantAfterApplication(),
+ replacementString,
+ replacementBeginPosition, replacementLength, cursorPosition,
+
SharedXMLEditorPluginImageHelper.getImage(SharedXMLEditorPluginImageHelper.IMG_OBJ_ATTRIBUTE),
+ displayString, null, kbProposal.getContextInfo(), relevance);
contentAssistRequest.addProposal(proposal);
-
- continue;
}
-
-
- StringBuffer replacementStringBuffer = new
StringBuffer(kbProposal.getReplacementString());
- int replacementBeginPosition =
contentAssistRequest.getReplacementBeginPosition();
- int replacementLength = contentAssistRequest.getReplacementLength();
- int cursorPositionDelta = 0;
- if(currentValue.startsWith("\"") ||
currentValue.startsWith("'")) {
- replacementBeginPosition = replacementBeginPosition +1;
- replacementLength--;
- } else {
- cursorPositionDelta++;
- replacementStringBuffer.insert(0, "\"");
- }
- if(currentValue.endsWith("\"") ||
currentValue.endsWith("'")) {
- replacementLength--;
- if(currentValue.endsWith(".}\"") &&
replacementStringBuffer.toString().endsWith("}")) {
- replacementLength--;
- replacementStringBuffer = new
StringBuffer(replacementStringBuffer.toString().substring(0,
replacementStringBuffer.length()-1));
- }
- } else {
- replacementStringBuffer.append("\"");
- }
- String replacementString = replacementStringBuffer.toString();
- int cursorPosition = kbProposal.getPosition() + cursorPositionDelta;
- AutoContentAssistantProposal proposal = new
AutoContentAssistantProposal(kbProposal.autoActivationContentAssistantAfterApplication(),
replacementString,
- replacementBeginPosition, replacementLength, cursorPosition,
SharedXMLEditorPluginImageHelper.getImage(SharedXMLEditorPluginImageHelper.IMG_OBJ_ATTRIBUTE),
- kbProposal.getLabel(), null, kbProposal.getContextInfo(), relevance);
- contentAssistRequest.addProposal(proposal);
}
} catch (KbException e) {
JspEditorPlugin.getPluginLog().logError(e);
@@ -174,4 +193,49 @@
public void setFacelets(boolean isFacelets) {
this.isFacelets = isFacelets;
}
+
+ /*
+ * Checks if the EL start starting characters are present
+ * @return
+ */
+ private int getELStartPosition(String matchString) {
+ if (matchString == null || matchString.length() == 0)
+ return -1;
+
+ int offset = matchString.length();
+
+ while (--offset >= 0) {
+ if ('}' == matchString.charAt(offset))
+ return -1;
+
+ if ('"' == matchString.charAt(offset) || '\'' ==
matchString.charAt(offset)) {
+ int backslashCount = 0;
+ while ((offset - 1 - backslashCount) >= 0 &&
matchString.charAt(offset - 1 - backslashCount) == '\\') {
+ backslashCount++;
+ }
+
+ if (backslashCount % 2 == 0)
+ return -1;
+ }
+
+ if ('{' == matchString.charAt(offset) &&
+ (offset - 1) >= 0 &&
+ ('#' == matchString.charAt(offset - 1) ||
+ '$' == matchString.charAt(offset - 1))) {
+ return (offset - 1);
+ }
+ }
+ return -1;
+ }
+
+ /* Checks if the preceding character is a Sharp-character
+ */
+ private boolean isCharSharp(String matchString, int offset) {
+ if (matchString == null || offset > matchString.length() || offset < 0) {
+ return false;
+ }
+
+ return '#' == matchString.charAt(offset);
+ }
+
}
\ No newline at end of file
Modified:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/contentassist/xpl/JSPBaseContentAssistProcessor.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/contentassist/xpl/JSPBaseContentAssistProcessor.java 2008-06-19
10:49:46 UTC (rev 8849)
+++
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/contentassist/xpl/JSPBaseContentAssistProcessor.java 2008-06-19
13:29:07 UTC (rev 8850)
@@ -67,16 +67,19 @@
}
String matchString = null;
+
+ // JBIDE-2334: Do not need any fix-ups here
+
// fixups
- if (currentValue.length() > StringUtils.strip(currentValue).length() &&
(currentValue.startsWith("\"") ||
currentValue.startsWith("'")) &&
contentAssistRequest.getMatchString().length() > 0) {
- matchString = currentValue.substring(1,
contentAssistRequest.getMatchString().length());
- strippedValue = currentValue.substring(1);
- offset = contentAssistRequest.getMatchString().length() - 1;
- } else {
+// if (currentValue.length() > StringUtils.strip(currentValue).length() &&
(currentValue.startsWith("\"") ||
currentValue.startsWith("'")) &&
contentAssistRequest.getMatchString().length() > 0) {
+// matchString = currentValue.substring(0,
contentAssistRequest.getMatchString().length());
+// strippedValue = currentValue;
+// offset = contentAssistRequest.getMatchString().length();
+// } else {
matchString = currentValue.substring(0,
contentAssistRequest.getMatchString().length());
strippedValue = currentValue;
offset = contentAssistRequest.getMatchString().length();
- }
+// }
addFaceletAttributeValueProposals(
contentAssistRequest,tagName,node,
attributeName,matchString,strippedValue,offset,currentValue);
}
Modified:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/support/kb/WTPKbdBeanPropertyResource.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/support/kb/WTPKbdBeanPropertyResource.java 2008-06-19
10:49:46 UTC (rev 8849)
+++
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/support/kb/WTPKbdBeanPropertyResource.java 2008-06-19
13:29:07 UTC (rev 8850)
@@ -200,18 +200,22 @@
if(callStart != null) proposal.setStart(callStart.start); else
proposal.setStart(offset);
ELParser.Token callEnd = ELParser.getCallEnd(c);
if(callEnd != null && callEnd.end >= offset) proposal.setEnd(callEnd.end);
else proposal.setEnd(offset);
+ int pos = proposal.getReplacementString().length();
+
+ // JBIDE-2334: JSPAciveContentAssistProcessor (a class which calls this method)
+ // is to process opening and closing EL charachers
+/*
String[][] ws = getWrappers();
- int pos = proposal.getReplacementString().length();
if(ws.length > 0 && ws[0][0].length() > 0) {
ELParser.Token open = ELParser.getPrecedingOpen(c, offset);
if(open == null && !proposal.getReplacementString().startsWith(ws[0][0])) {
- pos += ws[0][0].length();
- proposal.setReplacementString(ws[0][0] + proposal.getReplacementString());
- proposal.setLabel(ws[0][0] + proposal.getLabel() + ws[0][1]);
+// pos += ws[0][0].length();
+// proposal.setReplacementString(ws[0][0] + proposal.getReplacementString());
+// proposal.setLabel(ws[0][0] + proposal.getLabel() + ws[0][1]);
} else if(open != null &&
!proposal.getReplacementString().startsWith(ws[0][0]) && open.end - open.start ==
1) {
if(ws[0][0].endsWith("{")) {
- pos += 1;
- proposal.setReplacementString("{" + proposal.getReplacementString());
+// pos += 1;
+// proposal.setReplacementString("{" + proposal.getReplacementString());
}
} else if(open != null && open.end - open.start == 2 && offset <
open.end && offset > open.start) {
proposal.setStart(proposal.getStart() + 1);
@@ -219,9 +223,10 @@
proposal.setPosition(proposal.getStart());
}
if(!ELParser.isFollowedByClose(c, offset) &&
!proposal.getReplacementString().endsWith(ws[0][1])) {
- proposal.setReplacementString(proposal.getReplacementString() + ws[0][1]);
+// proposal.setReplacementString(proposal.getReplacementString() + ws[0][1]);
}
}
+*/
proposal.setPosition(pos);
}
}