Author: vrubezhny
Date: 2009-06-19 08:00:16 -0400 (Fri, 19 Jun 2009)
New Revision: 16063
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
Tag and tag name proposal processing 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-19
11:14:14 UTC (rev 16062)
+++
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/contentassist/AbstractXMLContentAssistProcessor.java 2009-06-19
12:00:16 UTC (rev 16063)
@@ -704,8 +704,11 @@
ELModel model = p.parse(text);
ELInstance is = ELUtil.findInstance(model, inValueOffset);// ELInstance
model.toString(); model.getSyntaxErrors();
+
+ boolean isELStarted = (is != null) && (model != null &&
(model.toString().startsWith("#{") ||
+ model.toString().startsWith("${")));
boolean isELClosed = (is == null) || (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);
+ TextRegion tr = new TextRegion(startOffset, is == null ? inValueOffset :
is.getStartPosition(), is == null ? 0 : inValueOffset - is.getStartPosition(), is == null
? "" : is.getText(), isELStarted, isELClosed);
return tr;
} finally {
@@ -720,13 +723,15 @@
private int offset;
private int length;
private String text;
+ private boolean isELStarted;
private boolean isELClosed;
- TextRegion(int startOffset, int offset, int length, String text, boolean isELClosed) {
+ TextRegion(int startOffset, int offset, int length, String text, boolean isELStarted,
boolean isELClosed) {
this.startOffset = startOffset;
this.offset = offset;
this.length = length;
this.text = text;
+ this.isELStarted = isELStarted;
this.isELClosed = isELClosed;
}
@@ -749,6 +754,10 @@
return sb.toString();
}
+ public boolean isELStarted() {
+ return isELStarted;
+ }
+
public boolean isELClosed() {
return isELClosed;
}
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-19
11:14:14 UTC (rev 16062)
+++
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/contentassist/FaceletPageContectAssistProcessor.java 2009-06-19
12:00:16 UTC (rev 16063)
@@ -178,6 +178,12 @@
System.out.println("FaceletPageContectAssistProcessor: addTextELProposals()
invoked");
try {
TextRegion prefix = getELPrefix();
+ if (prefix == null || !prefix.isELStarted()) {
+ CustomCompletionProposal proposal = new CustomCompletionProposal("#{}",
contentAssistRequest.getReplacementBeginPosition(),
+ 0, 2, null, "#{}", null, "New EL Expression", 10000);
+ contentAssistRequest.addProposal(proposal);
+ return;
+ }
String matchString = prefix.getText();
String query = matchString;
if (query == null)
@@ -211,7 +217,7 @@
}
if (proposals == null || proposals.length == 0) {
- if (!prefix.isELClosed()) {
+ if (prefix.isELStarted() && !prefix.isELClosed()) {
CustomCompletionProposal proposal = new CustomCompletionProposal("}",
contentAssistRequest.getReplacementBeginPosition(),
0, 1, null, "}", null, "Close EL Expression", 10000);
contentAssistRequest.addProposal(proposal);
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-19
11:14:14 UTC (rev 16062)
+++
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/contentassist/JspContentAssistProcessor.java 2009-06-19
12:00:16 UTC (rev 16063)
@@ -236,9 +236,66 @@
}
}
+
+ /**
+ * Calculates and adds the tag proposals to the Content Assist Request object
+ *
+ * @param contentAssistRequest Content Assist Request object
+ * @param childPosition the
+ */
+ @Override
+ protected void addTagInsertionProposals(
+ ContentAssistRequest contentAssistRequest, int childPosition) {
+ // TODO Auto-generated method stub
+ System.out.println("JspContentAssistProcessor: addTagInsertionProposals()
invoked");
+ try {
+ String matchString = contentAssistRequest.getMatchString();
+ String query = matchString;
+ if (query == null)
+ query = "";
+ String stringQuery = "<" + matchString;
+
+ KbQuery kbQuery = createKbQuery(Type.TAG_NAME, query, stringQuery);
+ TextProposal[] proposals = PageProcessor.getInstance().getProposals(kbQuery,
getContext());
+
+ for (int i = 0; proposals != null && i < proposals.length; i++) {
+ TextProposal textProposal = proposals[i];
+
+ String replacementString = textProposal.getReplacementString();
+ if (!replacementString.endsWith("/>")) {
+ String closingTag = textProposal.getLabel();
+ if (closingTag != null && closingTag.startsWith("<")) {
+ closingTag = closingTag.substring(1);
+ }
+
+ replacementString += "</" + closingTag + ">";
+ }
+
+ System.out.println("Tag Name proposal [" + (i + 1) + "/" +
proposals.length + "]: " + replacementString);
+
+ int replacementOffset = contentAssistRequest.getReplacementBeginPosition();
+ int replacementLength = contentAssistRequest.getReplacementLength();
+ int cursorPosition = getCursorPositionForProposedText(replacementString);
+ Image image = textProposal.getImage();
+ String displayString = textProposal.getLabel() + ">";
+ IContextInformation contextInformation = null;
+ String additionalProposalInfo = textProposal.getContextInfo();
+ int relevance = textProposal.getRelevance() + 10000;
+
+
+ CustomCompletionProposal proposal = new CustomCompletionProposal(replacementString,
replacementOffset, replacementLength, cursorPosition, image, displayString,
contextInformation, additionalProposalInfo, relevance);
+ contentAssistRequest.addProposal(proposal);
+ }
+ } finally {
+ System.out.println("JspContentAssistProcessor: addTagInsertionProposals()
exited");
+ }
+ return;
+ }
+
+
/**
- * Calculates and adds the attribute name proposals to the Content Assist Request
object
+ * Calculates and adds the tag name proposals to the Content Assist Request object
*
* @param contentAssistRequest Content Assist Request object
* @param childPosition the
@@ -262,18 +319,27 @@
for (int i = 0; proposals != null && i < proposals.length; i++) {
TextProposal textProposal = proposals[i];
- System.out.println("Tag Name proposal [" + (i + 1) + "/" +
proposals.length + "]: " + textProposal.getReplacementString());
-
- String replacementString = textProposal.getReplacementString() + ">";
+ String replacementString = textProposal.getReplacementString();
+ if (replacementString.startsWith("<")) {
+ // Because the tag starting char is already in the text
+ replacementString = replacementString.substring(1);
+ }
if (!replacementString.endsWith("/>")) {
- replacementString += "</" + textProposal.getLabel() +
">";
+ String closingTag = textProposal.getLabel();
+ if (closingTag != null && closingTag.startsWith("<")) {
+ closingTag = closingTag.substring(1);
+ }
+
+ replacementString += "</" + closingTag + ">";
}
+
+ System.out.println("Tag Name proposal [" + (i + 1) + "/" +
proposals.length + "]: " + replacementString);
int replacementOffset = contentAssistRequest.getReplacementBeginPosition();
int replacementLength = contentAssistRequest.getReplacementLength();
int cursorPosition = getCursorPositionForProposedText(replacementString);
Image image = textProposal.getImage();
- String displayString = textProposal.getLabel();
+ String displayString = textProposal.getLabel() + ">";
IContextInformation contextInformation = null;
String additionalProposalInfo = textProposal.getContextInfo();
int relevance = textProposal.getRelevance() + 10000;
@@ -288,6 +354,7 @@
return;
}
+
/**
* Calculates and adds the attribute name proposals to the Content Assist Request
object
*