Author: vrubezhny
Date: 2009-06-18 13:33:04 -0400 (Thu, 18 Jun 2009)
New Revision: 16050
Modified:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/contentassist/AbstractXMLContentAssistProcessor.java
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/contentassist/FaceletPageContectAssistProcessor.java
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/contentassist/JspContentAssistProcessor.java
Log:
JBIDE-2808: Improve/refactor org.jboss.tools.common.kb plugin.
The skeleton to prompt for the EL in text regions is updated
Modified:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/contentassist/AbstractXMLContentAssistProcessor.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/contentassist/AbstractXMLContentAssistProcessor.java 2009-06-18
16:11:32 UTC (rev 16049)
+++
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/contentassist/AbstractXMLContentAssistProcessor.java 2009-06-18
17:33:04 UTC (rev 16050)
@@ -658,7 +658,7 @@
* Returns URI for the current/parent tag
* @return
*/
- protected String getELPrefix() {
+ protected TextRegion getELPrefix() {
IStructuredModel sModel = StructuredModelManager
.getModelManager()
.getExistingModelForRead(getDocument());
@@ -701,13 +701,13 @@
String matchString = text.substring(0, inValueOffset);
ELParser p = ELParserUtil.getJbossFactory().createParser();
- ELModel model = p.parse(matchString);
- ELInstance is = ELUtil.findInstance(model, inValueOffset);
+ ELModel model = p.parse(text);
+ ELInstance is = ELUtil.findInstance(model, inValueOffset);// ELInstance
+ model.toString(); model.getSyntaxErrors();
+ boolean isELClosed = (model != null &&
model.toString().endsWith("}"));
+ TextRegion tr = new TextRegion(startOffset, is == null ? inValueOffset :
is.getStartPosition(), is == null ? 0 : inValueOffset - is.getStartPosition(), is == null
? "" : is.getText(), isELClosed);
- String elPrefix = is.getText();
-
-
- return elPrefix;
+ return tr;
} finally {
if (sModel != null) {
sModel.releaseFromRead();
@@ -715,6 +715,44 @@
}
}
+ protected class TextRegion {
+ private int startOffset;
+ private int offset;
+ private int length;
+ private String text;
+ private boolean isELClosed;
+
+ TextRegion(int startOffset, int offset, int length, String text, boolean isELClosed) {
+ this.startOffset = startOffset;
+ this.offset = offset;
+ this.length = length;
+ this.text = text;
+ this.isELClosed = isELClosed;
+ }
+
+ public int getStartOffset() {
+ return startOffset;
+ }
+
+ public int getOffset() {
+ return offset;
+ }
+
+ public int getLength() {
+ return length;
+ }
+
+ public String getText() {
+ StringBuffer sb = new StringBuffer(length);
+ sb = sb.append(text.substring(0, length));
+ sb.setLength(length);
+ return sb.toString();
+ }
+
+ public boolean isELClosed() {
+ return isELClosed;
+ }
+ }
/*
* Checks if the EL operand starting characters are present
* @return
Modified:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/contentassist/FaceletPageContectAssistProcessor.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/contentassist/FaceletPageContectAssistProcessor.java 2009-06-18
16:11:32 UTC (rev 16049)
+++
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/contentassist/FaceletPageContectAssistProcessor.java 2009-06-18
17:33:04 UTC (rev 16050)
@@ -19,12 +19,14 @@
import org.eclipse.wst.sse.core.StructuredModelManager;
import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel;
import org.eclipse.wst.sse.core.internal.provisional.IndexedRegion;
+import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion;
import org.eclipse.wst.sse.ui.internal.contentassist.CustomCompletionProposal;
import org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement;
import org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel;
import org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode;
import org.eclipse.wst.xml.ui.internal.contentassist.ContentAssistRequest;
import org.jboss.tools.common.text.TextProposal;
+import
org.jboss.tools.jst.jsp.contentassist.AbstractXMLContentAssistProcessor.TextRegion;
import org.jboss.tools.jst.web.kb.IFaceletPageContext;
import org.jboss.tools.jst.web.kb.IPageContext;
import org.jboss.tools.jst.web.kb.KbQuery;
@@ -163,12 +165,16 @@
// TODO Auto-generated method stub
System.out.println("FaceletPageContectAssistProcessor: addTextELProposals()
invoked");
try {
- String matchString = getELPrefix();
+ TextRegion prefix = getELPrefix();
+ String matchString = prefix.getText();
String query = matchString;
if (query == null)
query = "";
String stringQuery = matchString;
-
+
+ int beginChangeOffset = prefix.getStartOffset() + prefix.getOffset();
+
+
KbQuery kbQuery = createKbQuery(Type.TEXT, query, stringQuery);
TextProposal[] proposals = PageProcessor.getInstance().getProposals(kbQuery,
getContext());
@@ -177,13 +183,13 @@
System.out.println("Tag Text EL proposal [" + (i + 1) + "/" +
proposals.length + "]: " + textProposal.getReplacementString());
- String replacementString = textProposal.getReplacementString();
+ int replacementOffset = beginChangeOffset;
+ int replacementLength = prefix.getLength();
+ String replacementString = prefix.getText().substring(0, replacementLength) +
textProposal.getReplacementString();
+ int cursorPosition = replacementString.length();
+ Image image = textProposal.getImage();
- int replacementOffset = contentAssistRequest.getReplacementBeginPosition();
- int replacementLength = contentAssistRequest.getReplacementLength();
- int cursorPosition = getCursorPositionForProposedText(replacementString);
- Image image = textProposal.getImage();
- String displayString = (textProposal.getLabel() == null ? replacementString :
textProposal.getLabel());
+ String displayString = prefix.getText().substring(0, replacementLength) +
textProposal.getReplacementString() + "}";
IContextInformation contextInformation = null;
String additionalProposalInfo = textProposal.getContextInfo();
int relevance = textProposal.getRelevance() + 10000;
@@ -191,6 +197,14 @@
CustomCompletionProposal proposal = new CustomCompletionProposal(replacementString,
replacementOffset, replacementLength, cursorPosition, image, displayString,
contextInformation, additionalProposalInfo, relevance);
contentAssistRequest.addProposal(proposal);
}
+
+ if (proposals == null || proposals.length == 0) {
+ if (!prefix.isELClosed()) {
+ CustomCompletionProposal proposal = new CustomCompletionProposal("}",
contentAssistRequest.getReplacementBeginPosition(),
+ 0, 1, null, "}", null, "Close EL Expression", 10000);
+ contentAssistRequest.addProposal(proposal);
+ }
+ }
} finally {
System.out.println("FaceletPageContectAssistProcessor: addTextELProposals()
exited");
}
Modified:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/contentassist/JspContentAssistProcessor.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/contentassist/JspContentAssistProcessor.java 2009-06-18
16:11:32 UTC (rev 16049)
+++
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/contentassist/JspContentAssistProcessor.java 2009-06-18
17:33:04 UTC (rev 16050)
@@ -398,7 +398,8 @@
// TODO Auto-generated method stub
System.out.println("JspContentAssistProcessor: addAttributeValueELProposals()
invoked");
try {
- String matchString = getELPrefix();
+ TextRegion prefix = getELPrefix();
+ String matchString = prefix.getText();
String query = matchString;
if (query == null)
query = "";