Author: vrubezhny
Date: 2009-06-11 14:46:23 -0400 (Thu, 11 Jun 2009)
New Revision: 15896
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
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/contentassist/XmlContentAssistProcessor.java
Log:
JBIDE-2808: Improve/refactor org.jboss.tools.common.kb plugin.
The skeleton to prompt for the EL is added
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-11
18:44:23 UTC (rev 15895)
+++
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/contentassist/AbstractXMLContentAssistProcessor.java 2009-06-11
18:46:23 UTC (rev 15896)
@@ -36,9 +36,15 @@
import org.eclipse.wst.xml.core.internal.provisional.document.IDOMAttr;
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.core.internal.provisional.document.IDOMText;
import org.eclipse.wst.xml.core.internal.regions.DOMRegionContext;
import org.eclipse.wst.xml.ui.internal.contentassist.AbstractContentAssistProcessor;
import org.eclipse.wst.xml.ui.internal.contentassist.ContentAssistRequest;
+import org.jboss.tools.common.el.core.model.ELInstance;
+import org.jboss.tools.common.el.core.model.ELModel;
+import org.jboss.tools.common.el.core.model.ELUtil;
+import org.jboss.tools.common.el.core.parser.ELParser;
+import org.jboss.tools.common.el.core.parser.ELParserUtil;
import org.jboss.tools.common.el.core.resolver.ELContext;
import org.jboss.tools.common.el.core.resolver.ELResolver;
import org.jboss.tools.common.el.core.resolver.ELResolverFactoryManager;
@@ -247,6 +253,7 @@
*/
protected void addEntityProposals(ContentAssistRequest contentAssistRequest, int
documentPosition, ITextRegion completionRegion, IDOMNode treeNode) {
System.out.println("AbstractXMLContentAssistProcessor: addEntityProposals()
invoked");
+ super.addEntityProposals(contentAssistRequest, documentPosition, completionRegion,
treeNode);
}
/*
@@ -285,6 +292,21 @@
*/
abstract protected void addTagNameProposals(ContentAssistRequest contentAssistRequest,
int childPosition);
+
+ /**
+ * Calculates and adds the EL proposals in attribute value to the Content Assist Request
object
+ *
+ * @param contentAssistRequest
+ */
+ abstract protected void addAttributeValueELProposals(ContentAssistRequest
contentAssistRequest);
+
+ /**
+ * Calculates and adds the EL proposals in text to the Content Assist Request object
+ *
+ * @param contentAssistRequest
+ */
+ abstract protected void addTextELProposals(ContentAssistRequest contentAssistRequest);
+
/*
* (non-Javadoc)
* @see
org.eclipse.wst.xml.ui.internal.contentassist.AbstractContentAssistProcessor#computeCompletionProposals(int,
java.lang.String, org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion,
org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode,
org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode)
@@ -301,11 +323,29 @@
if ((xmlnode.getNodeType() == Node.ELEMENT_NODE) || (xmlnode.getNodeType() ==
Node.DOCUMENT_NODE)) {
if (regionType == DOMRegionContext.XML_EMPTY_TAG_CLOSE) {
addAttributeNameProposals(contentAssistRequest);
+ } else if ((regionType == DOMRegionContext.XML_CONTENT) || (regionType ==
DOMRegionContext.XML_CHAR_REFERENCE) || (regionType ==
DOMRegionContext.XML_ENTITY_REFERENCE) || (regionType ==
DOMRegionContext.XML_PE_REFERENCE)) {
+ addTextELProposals(contentAssistRequest);
}
}
+
return contentAssistRequest;
}
+
+ protected ContentAssistRequest computeAttributeValueProposals(int documentPosition,
String matchString, ITextRegion completionRegion, IDOMNode nodeAtOffset, IDOMNode node) {
+ ContentAssistRequest contentAssistRequest =
super.computeAttributeValueProposals(documentPosition, matchString, completionRegion,
nodeAtOffset, node);
+
+ IStructuredDocumentRegion sdRegion = getStructuredDocumentRegion(documentPosition);
+ if ((documentPosition <= sdRegion.getStartOffset(completionRegion) +
completionRegion.getTextLength()) ||
+ (sdRegion.getStartOffset(completionRegion) + completionRegion.getTextLength() ==
sdRegion.getStartOffset(completionRegion) + completionRegion.getLength())) {
+ // setup to replace the existing value
+ if (nodeAtOffset.getFirstStructuredDocumentRegion().isEnded() || (documentPosition
>= sdRegion.getStartOffset(completionRegion))) {
+ addAttributeValueELProposals(contentAssistRequest);
+ }
+ }
+ return contentAssistRequest;
+ }
+
/**
* Creates and fulfills the
<code>org.jboss.tools.common.el.core.resolver.ELContext</code>
* instance
@@ -613,4 +653,95 @@
return cursorAdjustment;
}
+
+ /**
+ * Returns URI for the current/parent tag
+ * @return
+ */
+ protected String getELPrefix() {
+ IStructuredModel sModel = StructuredModelManager
+ .getModelManager()
+ .getExistingModelForRead(getDocument());
+ try {
+ if (sModel == null)
+ return null;
+
+ Document xmlDocument = (sModel instanceof IDOMModel)
+ ? ((IDOMModel) sModel).getDocument()
+ : null;
+
+ if (xmlDocument == null)
+ return null;
+
+ Node n = findNodeForOffset(xmlDocument, getOffset());
+ if (n == null)
+ return null;
+
+ String text = null;
+ ITextRegion region = null;
+ int startOffset = -1;
+ if (n instanceof IDOMAttr) {
+ text = ((IDOMAttr)n).getValueRegionText();
+ region = ((IDOMAttr)n).getValueRegion();
+ startOffset = ((IndexedRegion)((IDOMAttr)n).getOwnerElement()).getStartOffset();
+ startOffset += region.getStart();
+ } else if (n instanceof IDOMText) {
+ text = ((IDOMText)n).getNodeValue();
+ region = ((IDOMText)n).getFirstStructuredDocumentRegion();
+ startOffset = ((IndexedRegion)((IDOMAttr)n).getOwnerElement()).getStartOffset();
+ } else {
+ // The EL may appear only in TEXT and ATTRIBUTE VALUE types of node
+ return null;
+ }
+
+ int inValueOffset = getOffset() - startOffset;
+ if (text.length() < inValueOffset) // probably, the attribute value ends before the
document position
+ return null;
+
+ String matchString = text.substring(0, inValueOffset);
+
+ ELParser p = ELParserUtil.getJbossFactory().createParser();
+ ELModel model = p.parse(matchString);
+ ELInstance is = ELUtil.findInstance(model, inValueOffset);
+
+ String elPrefix = is.getText();
+
+
+ return elPrefix;
+ } finally {
+ if (sModel != null) {
+ sModel.releaseFromRead();
+ }
+ }
+ }
+
+ /*
+ * Checks if the EL operand starting characters are present
+ * @return
+ */
+ private int getELStartPosition(String matchString) {
+ ELParser p = ELParserUtil.getJbossFactory().createParser();
+ ELModel model = p.parse(matchString);
+ ELInstance is = ELUtil.findInstance(model, matchString.length());
+ return is == null ? -1 : is.getStartPosition();
+ }
+
+ /*
+ * 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;
+
+ ELParser p = ELParserUtil.getJbossFactory().createParser();
+ ELModel model = p.parse(currentValue);
+ ELInstance is = ELUtil.findInstance(model, matchString.length());
+ if(is == null || is.getCloseInstanceToken() == null) return -1;
+
+ return is.getEndPosition();
+ }
+
}
\ No newline at end of file
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-11
18:44:23 UTC (rev 15895)
+++
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/contentassist/FaceletPageContectAssistProcessor.java 2009-06-11
18:46:23 UTC (rev 15896)
@@ -14,14 +14,22 @@
import org.eclipse.jface.text.IRegion;
import org.eclipse.jface.text.Region;
+import org.eclipse.jface.text.contentassist.IContextInformation;
+import org.eclipse.swt.graphics.Image;
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.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.web.kb.IFaceletPageContext;
import org.jboss.tools.jst.web.kb.IPageContext;
+import org.jboss.tools.jst.web.kb.KbQuery;
+import org.jboss.tools.jst.web.kb.PageProcessor;
+import org.jboss.tools.jst.web.kb.KbQuery.Type;
import org.jboss.tools.jst.web.kb.internal.FaceletPageContextImpl;
import org.jboss.tools.jst.web.kb.taglib.INameSpace;
import org.w3c.dom.Attr;
@@ -144,4 +152,48 @@
protected IFaceletPageContext getContext() {
return (IFaceletPageContext)super.getContext();
}
+
+
+
+ /**
+ * Calculates and adds the EL proposals to the Content Assist Request object
+ */
+ @Override
+ protected void addTextELProposals(ContentAssistRequest contentAssistRequest) {
+ // TODO Auto-generated method stub
+ System.out.println("FaceletPageContectAssistProcessor: addTextELProposals()
invoked");
+ try {
+ String matchString = getELPrefix();
+ String query = matchString;
+ if (query == null)
+ query = "";
+ String stringQuery = matchString;
+
+ KbQuery kbQuery = createKbQuery(Type.TEXT, query, stringQuery);
+ TextProposal[] proposals = PageProcessor.getInstance().getProposals(kbQuery,
getContext());
+
+ for (int i = 0; proposals != null && i < proposals.length; i++) {
+ TextProposal textProposal = proposals[i];
+
+ System.out.println("Tag Text EL proposal [" + (i + 1) + "/" +
proposals.length + "]: " + textProposal.getReplacementString());
+
+ String replacementString = textProposal.getReplacementString();
+
+ int replacementOffset = contentAssistRequest.getReplacementBeginPosition();
+ int replacementLength = contentAssistRequest.getReplacementLength();
+ int cursorPosition = getCursorPositionForProposedText(replacementString);
+ Image image = textProposal.getImage();
+ String displayString = (textProposal.getLabel() == null ? replacementString :
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("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-11
18:44:23 UTC (rev 15895)
+++
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/contentassist/JspContentAssistProcessor.java 2009-06-11
18:46:23 UTC (rev 15896)
@@ -198,7 +198,7 @@
*
* @param attrName Name of attribute to check
*/
- private boolean isExistingAttribute(String attrName) {
+ protected boolean isExistingAttribute(String attrName) {
IStructuredModel sModel = StructuredModelManager.getModelManager()
.getExistingModelForRead(getDocument());
try {
@@ -368,7 +368,6 @@
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);
}
@@ -377,4 +376,59 @@
}
}
+ /**
+ * Calculates and adds the EL proposals to the Content Assist Request object
+ */
+ @Override
+ protected void addTextELProposals(ContentAssistRequest contentAssistRequest) {
+ // TODO Auto-generated method stub
+ System.out.println("JspContentAssistProcessor: addTextELProposals()
invoked");
+ try {
+ System.out.println("JspContentAssistProcessor: No EL allowed in TEXT");
+ } finally {
+ System.out.println("JspContentAssistProcessor: addTextELProposals()
exited");
+ }
+ }
+
+ /**
+ * Calculates and adds the EL proposals to the Content Assist Request object
+ */
+ @Override
+ protected void addAttributeValueELProposals(ContentAssistRequest contentAssistRequest)
{
+ // TODO Auto-generated method stub
+ System.out.println("JspContentAssistProcessor: addAttributeValueELProposals()
invoked");
+ try {
+ String matchString = getELPrefix();
+ String query = matchString;
+ if (query == null)
+ query = "";
+ String stringQuery = matchString;
+
+ KbQuery kbQuery = createKbQuery(Type.ATTRIBUTE_VALUE, query, stringQuery);
+ TextProposal[] proposals = PageProcessor.getInstance().getProposals(kbQuery,
getContext());
+
+ for (int i = 0; proposals != null && i < proposals.length; i++) {
+ TextProposal textProposal = proposals[i];
+
+ System.out.println("Tag Attribute Value EL proposal [" + (i + 1) +
"/" + proposals.length + "]: " +
textProposal.getReplacementString());
+
+ String replacementString = textProposal.getReplacementString();
+
+ int replacementOffset = contentAssistRequest.getReplacementBeginPosition();
+ int replacementLength = contentAssistRequest.getReplacementLength();
+ int cursorPosition = getCursorPositionForProposedText(replacementString);
+ Image image = textProposal.getImage();
+ String displayString = (textProposal.getLabel() == null ? replacementString :
textProposal.getLabel());
+ IContextInformation contextInformation = null;
+ String additionalProposalInfo = (textProposal.getContextInfo() == null ? ""
: 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: addAttributeELProposals()
exited");
+ }
+ }
+
}
\ No newline at end of file
Modified:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/contentassist/XmlContentAssistProcessor.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/contentassist/XmlContentAssistProcessor.java 2009-06-11
18:44:23 UTC (rev 15895)
+++
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/contentassist/XmlContentAssistProcessor.java 2009-06-11
18:46:23 UTC (rev 15896)
@@ -85,4 +85,18 @@
// TODO Auto-generated method stub
}
+
+ @Override
+ protected void addAttributeValueELProposals(ContentAssistRequest contentAssistRequest)
{
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ protected void addTextELProposals(ContentAssistRequest contentAssistRequest) {
+ // TODO Auto-generated method stub
+
+ }
+
+
}
\ No newline at end of file