Author: vrubezhny
Date: 2009-11-14 06:59:14 -0500 (Sat, 14 Nov 2009)
New Revision: 18687
Modified:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/contentassist/AutoContentAssistantProposal.java
Log:
JBIDE-5125: EL Component Suggest does not filter
Issue is fixed
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 2009-11-13
21:18:33 UTC (rev 18686)
+++
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/contentassist/AutoContentAssistantProposal.java 2009-11-14
11:59:14 UTC (rev 18687)
@@ -10,6 +10,9 @@
******************************************************************************/
package org.jboss.tools.jst.jsp.contentassist;
+import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.jface.text.DocumentEvent;
+import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.ITextOperationTarget;
import org.eclipse.jface.text.ITextViewer;
import org.eclipse.jface.text.contentassist.ICompletionProposalExtension6;
@@ -24,29 +27,26 @@
/**
* @author Igels
*/
-public class AutoContentAssistantProposal extends CustomCompletionProposal implements
ICompletionProposalExtension6
-
-{
-
+@SuppressWarnings("restriction")
+public class AutoContentAssistantProposal extends CustomCompletionProposal implements
ICompletionProposalExtension6 {
private boolean autoContentAssistant = false;
public AutoContentAssistantProposal(String replacementString, int replacementOffset, int
replacementLength, int cursorPosition, Image image, String displayString,
IContextInformation contextInformation, String additionalProposalInfo) {
super(replacementString, replacementOffset, replacementLength, cursorPosition, image,
displayString, contextInformation, additionalProposalInfo, IRelevanceConstants.R_NONE);
+ 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;
}
public AutoContentAssistantProposal(boolean autoContentAssistant, 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.autoContentAssistant = autoContentAssistant;
+ this.fOriginalReplacementLength = replacementLength;
}
- public AutoContentAssistantProposal(String replacementString, int replacementOffset, int
replacementLength, int cursorPosition, Image image, String displayString,
IContextInformation contextInformation, String additionalProposalInfo, int relevance,
boolean updateReplacementLengthOnValidate) {
- super(replacementString, replacementOffset, replacementLength, cursorPosition,
image, displayString, contextInformation, additionalProposalInfo, relevance,
updateReplacementLengthOnValidate);
- }
-
public void apply(ITextViewer viewer, char trigger, int stateMask, int offset) {
super.apply(viewer, trigger, stateMask, offset);
if(autoContentAssistant) {
@@ -61,12 +61,11 @@
/**
* Return cursor position of proposal replacement string.
*/
- @SuppressWarnings("nls")
public int getCursorPosition() {
int cursorPosition = -1;
- int firstAttributeEndPosition = getReplacementString().indexOf("=");
- int openEndTagPosition = getReplacementString().indexOf("</");
- int closeStartAndEndTagPosition = getReplacementString().indexOf("/>");
+ int firstAttributeEndPosition = getReplacementString().indexOf("=");
//$NON-NLS-1$
+ int openEndTagPosition = getReplacementString().indexOf("</");
//$NON-NLS-1$
+ int closeStartAndEndTagPosition = getReplacementString().indexOf("/>");
//$NON-NLS-1$
if(firstAttributeEndPosition>-1) {
cursorPosition = firstAttributeEndPosition + 2;
} else if(openEndTagPosition>-1) {
@@ -99,7 +98,7 @@
boolean hasRetType = isJavaWordPart && string.indexOf(':') > 0;
boolean hasDeclType = isJavaWordPart && string.lastIndexOf('-') >
0;
- int p1i = string.indexOf(':');
+// int p1i = string.indexOf(':');
int p2i = string.lastIndexOf('-');
String p1 = hasRetType && hasDeclType ? string.substring(0, p2i) : string;
@@ -125,6 +124,42 @@
public void setStyledDisplayString(StyledString text) {
fStyledDisplayString = text;
- super.setDisplayString(fStyledDisplayString == null ? "" :
fStyledDisplayString.getString());
+ super.setDisplayString(fStyledDisplayString == null ? "" :
fStyledDisplayString.getString()); //$NON-NLS-1$
}
+
+ private int fOriginalReplacementLength;
+
+
+ // Fix for JBIDE-5125 >>>
+ @Override
+ public boolean validate(IDocument document, int offset, DocumentEvent event) {
+ int fReplacementOffset = getReplacementOffset();
+
+ if (offset < fReplacementOffset)
+ return false;
+ boolean validated = startsWith(document, offset, getReplacementString());
+
+ // it would be better to use "originalCursorPosition" instead of
+ // getReplacementOffset(), but we don't have that info.
+ int newLength = offset - getReplacementOffset();
+ int delta = newLength - fOriginalReplacementLength;
+ int newReplacementLength = delta + fOriginalReplacementLength;
+ setReplacementLength(newReplacementLength);
+
+ // if it's an attribute value, replacement offset is
+ // going to be one off from the actual cursor offset...
+ try {
+ char firstChar = document.getChar(getReplacementOffset());
+ if (firstChar == '"' || firstChar == '\'') {
+ setReplacementLength(getReplacementLength() + 1);
+ }
+ }
+ catch (BadLocationException e) {
+ // just don't increment
+ }
+ return validated;
+ }
+ // Fix for JBIDE-5125 <<<
+
+
}
\ No newline at end of file