Author: vrubezhny
Date: 2008-06-30 15:37:26 -0400 (Mon, 30 Jun 2008)
New Revision: 9033
Modified:
branches/jbosstools-2.1.x/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/contentassist/JSPActiveContentAssistProcessor.java
branches/jbosstools-2.1.x/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/contentassist/xpl/JSPBaseContentAssistProcessor.java
branches/jbosstools-2.1.x/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-2437 CA suggests only proposals for EL.
Issue is fixed for 2.1.3
Modified:
branches/jbosstools-2.1.x/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/contentassist/JSPActiveContentAssistProcessor.java
===================================================================
---
branches/jbosstools-2.1.x/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/contentassist/JSPActiveContentAssistProcessor.java 2008-06-30
19:28:31 UTC (rev 9032)
+++
branches/jbosstools-2.1.x/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/contentassist/JSPActiveContentAssistProcessor.java 2008-06-30
19:37:26 UTC (rev 9033)
@@ -78,89 +78,151 @@
return;
}
- String matchStringForQuery = matchString;
- String strippedValueForQuery = strippedValue;
int elStartPosition = getELStartPosition(matchString);
int delta = 0;
- String proposalPrefix = "";
- String proposalSufix = "";
+ String elProposalPrefix = "";
+ String elQueryString = null;
+ String queryString = null;
if (elStartPosition == -1) {
+ queryString = matchString;
+ elQueryString = "#{";
+ delta = matchString.length();
if(isCharSharp(matchString, offset-1)) {
- proposalPrefix = "{"; //$NON-NLS-1$
+ elProposalPrefix = "{"; //$NON-NLS-1$
+ queryString = null; // Do not request for ordinar attr-value proposals
+ // in case of starting EL-expression
} else {
- proposalPrefix = "#{"; //$NON-NLS-1$
+ elProposalPrefix = "#{"; //$NON-NLS-1$
}
- }
-
- if (elStartPosition == -1) {
- matchStringForQuery = "#{";
- strippedValueForQuery = "";
- delta = matchString.length();
+ if (matchString.startsWith("\"") ||
matchString.startsWith("'")) {
+ queryString = matchString.substring(1);
+ }
} else {
- matchStringForQuery = matchString.substring(elStartPosition);
- strippedValueForQuery = matchStringForQuery;
- delta = matchString.length() - matchStringForQuery.length();
+ // // Do not request for ordinar attr-value proposals
+ // in case of EL-expression
+ queryString = null;
+ elQueryString = matchString.substring(elStartPosition);
+ delta = matchString.length() - elQueryString.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) {
- proposals = wtpKbConnector.getProposals(htmlQuery);
- }
- for (Iterator iter = proposals.iterator(); iter.hasNext();) {
- KbProposal kbProposal = cleanFaceletProposal((KbProposal)iter.next());
- kbProposal.postProcess(strippedValueForQuery, offset - delta);
- int relevance = kbProposal.getRelevance();
- if(relevance==KbProposal.R_NONE) {
- relevance = XMLRelevanceConstants.R_XML_ATTRIBUTE_VALUE;
- }
-
- if(kbProposal.getStart() >= 0) {
- String replacementString = kbProposal.getReplacementString();
- int replacementBeginPosition =
contentAssistRequest.getReplacementBeginPosition() + kbProposal.getStart() + delta;
- int replacementLength = kbProposal.getEnd() - kbProposal.getStart();
- int cursorPositionDelta = 0;
-
- // 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 {
- if(elStartPosition == -1 &&
!currentValue.endsWith("}")) {
- replacementString += "}";
- }
-// replacementString += ("\"");
- }
- int cursorPosition = kbProposal.getPosition() + cursorPositionDelta;
- 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);
- }
- }
- } catch (KbException e) {
- JspEditorPlugin.getPluginLog().logError(e);
- }
+
+ Collection proposals = null;
+ if (queryString != null) {
+ // Query to request for ordinar proposals
+ try {
+ String query = new
StringBuffer(KbQuery.TAG_SEPARATOR).append(tagName).append(KbQuery.ATTRIBUTE_SEPARATOR).append(attributeName).append(KbQuery.ENUMERATION_SEPARATOR).append(queryString).toString();
+ proposals = wtpKbConnector.getProposals(query);
+ if(proposals.size()==0 && htmlQuery!=null) {
+ proposals = wtpKbConnector.getProposals(htmlQuery);
+ }
+ if(proposals != null) {
+ for (Iterator iter = proposals.iterator(); iter.hasNext();) {
+ KbProposal kbProposal = cleanFaceletProposal((KbProposal)iter.next());
+ kbProposal.postProcess(queryString, offset - delta);
+ if (kbProposal.getReplacementString().startsWith("#{"))
+ continue; // Do not process EL-proposals here!!!
+
+ int relevance = kbProposal.getRelevance();
+ if(relevance==KbProposal.R_NONE) {
+ relevance = XMLRelevanceConstants.R_XML_ATTRIBUTE_VALUE;
+ }
+
+ if(kbProposal.getStart() < 0) {
+ 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("'")) &&
+ strippedValue.length() < currentValue.length() ) {
+ replacementLength--;
+ }
+
+ 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);
+ }
+ }
+
+ Collection elProposals = null;
+ if (elQueryString != null) {
+ // Query to request for EL-proposals
+ try {
+ String query = new
StringBuffer(KbQuery.TAG_SEPARATOR).append(tagName).append(KbQuery.ATTRIBUTE_SEPARATOR).append(attributeName).append(KbQuery.ENUMERATION_SEPARATOR).append(elQueryString).toString();
+ elProposals = wtpKbConnector.getProposals(query);
+ } catch (KbException e) {
+ JspEditorPlugin.getPluginLog().logError(e);
+ }
+ if(elProposals != null) {
+ for (Iterator iter = elProposals.iterator(); iter.hasNext();) {
+ KbProposal kbProposal = cleanFaceletProposal((KbProposal)iter.next());
+ kbProposal.postProcess("\"" + elQueryString, offset -
delta);
+ if (!kbProposal.getReplacementString().startsWith("#{"))
+ continue; // Process the only EL-proposals here!!!
+ int relevance = kbProposal.getRelevance();
+ if(relevance==KbProposal.R_NONE) {
+ relevance = XMLRelevanceConstants.R_XML_ATTRIBUTE_VALUE;
+ }
+
+ if(kbProposal.getStart() >= 0) {
+ String replacementString =
kbProposal.getReplacementString().substring(2,kbProposal.getReplacementString().length() -
1);
+ int replacementBeginPosition =
contentAssistRequest.getReplacementBeginPosition() + kbProposal.getStart() + delta;
+ int replacementLength = kbProposal.getEnd() -
kbProposal.getStart();
+ int cursorPositionDelta = 0;
+
+ // Add an EL-starting quotation characters if needed
+ if (elStartPosition == -1) {
+ replacementString = elProposalPrefix + replacementString;
+ cursorPositionDelta += elProposalPrefix.length();
+ }
+
+ if((currentValue.length() >
StringUtils.strip(currentValue).length()) &&
+ (currentValue.endsWith("\"") ||
currentValue.endsWith("'")) ) {
+ String restOfCurrentValue =
currentValue.substring(matchString.length());
+
+ if(getELEndPosition(matchString, currentValue) == -1) {
+ replacementString += "}";
+ }
+ } else {
+ if(elStartPosition == -1 &&
!currentValue.endsWith("}")) {
+ replacementString += "}";
+ }
+ // replacementString += ("\"");
+ }
+ int cursorPosition = kbProposal.getPosition() + cursorPositionDelta;
+ String displayString = elProposalPrefix == null ||
elProposalPrefix.length() == 0 ?
+
kbProposal.getReplacementString().substring(2,kbProposal.getReplacementString().length()
- 1) :
+ elProposalPrefix +
kbProposal.getReplacementString().substring(2,kbProposal.getReplacementString().length() -
1) + "}" ;
+ AutoContentAssistantProposal proposal = new
AutoContentAssistantProposal(
+ kbProposal.autoActivationContentAssistantAfterApplication(),
+ replacementString,
+ replacementBeginPosition, replacementLength, cursorPosition,
+
SharedXMLEditorPluginImageHelper.getImage(SharedXMLEditorPluginImageHelper.IMG_OBJ_ATTRIBUTE),
+ displayString, null, kbProposal.getContextInfo(), relevance);
+ contentAssistRequest.addProposal(proposal);
+ }
+ }
+ }
+ }
}
private KbProposal cleanFaceletProposal(KbProposal proposal) {
@@ -191,7 +253,7 @@
}
/*
- * Checks if the EL start starting characters are present
+ * Checks if the EL operand starting characters are present
* @return
*/
private int getELStartPosition(String matchString) {
@@ -234,4 +296,78 @@
return '#' == matchString.charAt(offset);
}
+ /*
+ * Checks if the EL operand ending character is present
+ * @return
+ */
+ private int getELEndPosition(String matchString, String currentValue) {
+ if (matchString == null || matchString.length() == 0 ||
+ currentValue == null || currentValue.length() == 0 ||
+ currentValue.length() < matchString.length())
+ return -1;
+
+ String restOfCurrentValue = currentValue.substring(matchString.length());
+ int offset = -1;
+
+ char inQuotesChar = 0;
+ while (++offset < restOfCurrentValue.length()) {
+ if (inQuotesChar == 0) {
+ if ('}' == restOfCurrentValue.charAt(offset))
+ return matchString.length() + offset;
+
+ if ('#' == restOfCurrentValue.charAt(offset))
+ return -1;
+
+ if ('"' == restOfCurrentValue.charAt(offset) ||
+ '\'' == restOfCurrentValue.charAt(offset)) {
+ inQuotesChar = restOfCurrentValue.charAt(offset);
+ }
+
+ if ('\\' == restOfCurrentValue.charAt(offset)) {
+ int backslashCount = 1;
+
+ while ((offset + backslashCount) < restOfCurrentValue.length()
&&
+ restOfCurrentValue.charAt(offset + backslashCount) == '\\') {
+ backslashCount++;
+ }
+
+ if (offset + backslashCount >= restOfCurrentValue.length())
+ return -1;
+
+ if (backslashCount % 2 == 1 &&
+ ('"' == restOfCurrentValue.charAt(offset +
backslashCount) ||
+ '\'' == restOfCurrentValue.charAt(offset +
backslashCount))) {
+ inQuotesChar = restOfCurrentValue.charAt(offset + backslashCount);
+ offset += backslashCount;
+ }
+ }
+ } else {
+ if ('"' == restOfCurrentValue.charAt(offset) ||
+ '\'' == restOfCurrentValue.charAt(offset)) {
+ inQuotesChar = 0;
+ }
+
+ if ('\\' == restOfCurrentValue.charAt(offset)) {
+ int backslashCount = 1;
+
+ while ((offset + backslashCount) < restOfCurrentValue.length()
&&
+ restOfCurrentValue.charAt(offset + backslashCount) == '\\') {
+ backslashCount++;
+ }
+
+ if (offset + backslashCount >= restOfCurrentValue.length())
+ return -1;
+
+ if (backslashCount % 2 == 1 &&
+ ('"' == restOfCurrentValue.charAt(offset +
backslashCount) ||
+ '\'' == restOfCurrentValue.charAt(offset +
backslashCount))) {
+ inQuotesChar = 0;
+ offset += backslashCount;
+ }
+ }
+ }
+ }
+ return -1;
+ }
+
}
\ No newline at end of file
Modified:
branches/jbosstools-2.1.x/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/contentassist/xpl/JSPBaseContentAssistProcessor.java
===================================================================
---
branches/jbosstools-2.1.x/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/contentassist/xpl/JSPBaseContentAssistProcessor.java 2008-06-30
19:28:31 UTC (rev 9032)
+++
branches/jbosstools-2.1.x/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/contentassist/xpl/JSPBaseContentAssistProcessor.java 2008-06-30
19:37:26 UTC (rev 9033)
@@ -77,7 +77,7 @@
// offset = contentAssistRequest.getMatchString().length();
// } else {
matchString = currentValue.substring(0,
contentAssistRequest.getMatchString().length());
- strippedValue = currentValue;
+ strippedValue = StringUtils.strip(currentValue);
offset = contentAssistRequest.getMatchString().length();
// }
addFaceletAttributeValueProposals(
Modified:
branches/jbosstools-2.1.x/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/support/kb/WTPKbdBeanPropertyResource.java
===================================================================
---
branches/jbosstools-2.1.x/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/support/kb/WTPKbdBeanPropertyResource.java 2008-06-30
19:28:31 UTC (rev 9032)
+++
branches/jbosstools-2.1.x/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/support/kb/WTPKbdBeanPropertyResource.java 2008-06-30
19:37:26 UTC (rev 9033)
@@ -202,6 +202,12 @@
if(callEnd != null && callEnd.end >= offset) proposal.setEnd(callEnd.end);
else proposal.setEnd(offset);
int pos = proposal.getReplacementString().length();
+ // JBIDE-2437: Because of the issue add EL open/close brackets to the proposal
replacement string
+ // This will allow us to separate EL-proposals from all the others.
+ proposal.setReplacementString("#{" + proposal.getReplacementString() +
"}");
+ proposal.setLabel("#{" + proposal.getLabel() + "}");
+
+
// JBIDE-2334: JSPAciveContentAssistProcessor (a class which calls this method)
// is to process opening and closing EL charachers
/*