Author: vrubezhny
Date: 2009-05-22 14:10:43 -0400 (Fri, 22 May 2009)
New Revision: 15453
Added:
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
Modified:
trunk/jst/plugins/org.jboss.tools.jst.jsp/META-INF/MANIFEST.MF
Log:
JBIDE-2808: Improve/refactor org.jboss.tools.common.kb plugin.
The skeleton for initial implementation of new-style ContentAssistProcessors
Modified: trunk/jst/plugins/org.jboss.tools.jst.jsp/META-INF/MANIFEST.MF
===================================================================
--- trunk/jst/plugins/org.jboss.tools.jst.jsp/META-INF/MANIFEST.MF 2009-05-22 18:04:25 UTC
(rev 15452)
+++ trunk/jst/plugins/org.jboss.tools.jst.jsp/META-INF/MANIFEST.MF 2009-05-22 18:10:43 UTC
(rev 15453)
@@ -57,7 +57,8 @@
org.eclipse.wst.common.uriresolver,
org.eclipse.core.resources,
org.eclipse.core.runtime,
- org.eclipse.ui.views
+ org.eclipse.ui.views,
+ org.jboss.tools.jst.web.kb;bundle-version="1.0.0"
Bundle-Version: 2.0.0
Export-Package: org.jboss.tools.jst.jsp.outline.cssdialog.common,
org.jboss.tools.jst.jsp.outline.cssdialog.events,
Added:
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
(rev 0)
+++
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/contentassist/AbstractXMLContentAssistProcessor.java 2009-05-22
18:10:43 UTC (rev 15453)
@@ -0,0 +1,225 @@
+package org.jboss.tools.jst.jsp.contentassist;
+
+import org.eclipse.core.filebuffers.FileBuffers;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.ITextViewer;
+import org.eclipse.jface.text.contentassist.ICompletionProposal;
+import org.eclipse.jface.text.contentassist.IContextInformation;
+import org.eclipse.jface.text.contentassist.IContextInformationValidator;
+import org.eclipse.wst.sse.core.StructuredModelManager;
+import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel;
+import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion;
+import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion;
+import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList;
+import org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration;
+import org.eclipse.wst.xml.core.internal.provisional.document.IDOMAttr;
+import org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode;
+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.resolver.ELContext;
+import org.jboss.tools.common.el.core.resolver.ELResolver;
+import org.jboss.tools.common.el.core.resolver.ELResolverFactoryManager;
+import org.w3c.dom.Node;
+
+abstract public class AbstractXMLContentAssistProcessor extends
AbstractContentAssistProcessor {
+ private static final char[] PROPOSAL_AUTO_ACTIVATION_CHARS = new char[] {
+ '<', '=', '"', '\'', '.'
+ };
+
+ private IDocument fDocument;
+ private int fDocumentPosition;
+
+ public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer,
+ int offset) {
+ this.fDocument = (viewer == null ? null : viewer.getDocument());
+ this.fDocumentPosition = offset;
+
+ System.out.println("AbstractXMLContentAssistProcessor:
computeCompletionProposals() invoked");
+ try {
+ return super.computeCompletionProposals(viewer, offset);
+ } finally {
+ System.out.println("AbstractXMLContentAssistProcessor:
computeCompletionProposals() exited");
+ }
+ }
+
+ public IContextInformation[] computeContextInformation(ITextViewer viewer,
+ int offset) {
+ this.fDocumentPosition = offset;
+
+ return super.computeContextInformation(viewer, offset);
+ }
+
+ public char[] getCompletionProposalAutoActivationCharacters() {
+ return PROPOSAL_AUTO_ACTIVATION_CHARS;
+ }
+
+ public char[] getContextInformationAutoActivationCharacters() {
+ return super.getContextInformationAutoActivationCharacters();
+ }
+
+ public IContextInformationValidator getContextInformationValidator() {
+ return super.getContextInformationValidator();
+ }
+
+ public String getErrorMessage() {
+ return super.getErrorMessage();
+ }
+
+
+
+ /* the methods to be overriden in derived classes */
+
+ protected void addAttributeNameProposals(ContentAssistRequest contentAssistRequest) {
+ System.out.println("AbstractXMLContentAssistProcessor: addAttributeNameProposals()
invoked");
+ }
+
+ protected void addAttributeValueProposals(ContentAssistRequest contentAssistRequest) {
+
+ IDOMNode node = (IDOMNode) contentAssistRequest.getNode();
+
+ // Find the attribute region and name for which this position should
+ // have a value proposed
+ IStructuredDocumentRegion open = node.getFirstStructuredDocumentRegion();
+ ITextRegionList openRegions = open.getRegions();
+ int i = openRegions.indexOf(contentAssistRequest.getRegion());
+ if (i < 0) {
+ return;
+ }
+ ITextRegion nameRegion = null;
+ while (i >= 0) {
+ nameRegion = openRegions.get(i--);
+ if (nameRegion.getType() == DOMRegionContext.XML_TAG_ATTRIBUTE_NAME) {
+ break;
+ }
+ }
+
+ // the name region is REQUIRED to do anything useful
+ if (nameRegion != null) {
+ // Retrieve the declaration
+ CMElementDeclaration elementDecl = getCMElementDeclaration(node);
+
+ // String attributeName = nameRegion.getText();
+ String attributeName = open.getText(nameRegion);
+ String currentValue =
node.getAttributes().getNamedItem(attributeName).getNodeValue();
+ String currentValueText =
((IDOMAttr)node.getAttributes().getNamedItem(attributeName)).getValueRegionText();
+ ITextRegion currentValueRegion =
((IDOMAttr)node.getAttributes().getNamedItem(attributeName)).getValueRegion();
+
+
+
+ ITextRegion invokeRegion = contentAssistRequest.getRegion();
+ int pos = contentAssistRequest.getRegion().getStart();
+ int replBegin = contentAssistRequest.getReplacementBeginPosition();
+ int invokeRegionEnd = invokeRegion.getStart() + invokeRegion.getLength();
+ IDOMAttr attrNode = (IDOMAttr)node.getAttributes().getNamedItem(attributeName);
+ int valueRegionStartOffset = attrNode.getValueRegionStartOffset();
+ ITextRegion eqRegion = attrNode.getEqualRegion();
+ int eqRegionEnd= eqRegion.getStart() + eqRegion.getLength();
+ int attrValueEnd=eqRegionEnd + currentValueText.length();
+ int attrTextEnd = invokeRegion.getTextEnd();
+ // attrNode.getValueRegionText()
+ System.out.println("AbstractXMLContentAssistProcessor:
addAttributeValueProposals() invoked");
+ }
+ else {
+ setErrorMessage(UNKNOWN_CONTEXT);
+ }
+ }
+
+ protected void addCommentProposal(ContentAssistRequest contentAssistRequest) {
+ System.out.println("AbstractXMLContentAssistProcessor: addCommentProposal()
invoked");
+ }
+
+ protected void addDocTypeProposal(ContentAssistRequest contentAssistRequest) {
+ System.out.println("AbstractXMLContentAssistProcessor: addDocTypeProposal()
invoked");
+ }
+
+ protected void addEmptyDocumentProposals(ContentAssistRequest contentAssistRequest) {
+ System.out.println("AbstractXMLContentAssistProcessor: addEmptyDocumentProposals()
invoked");
+ }
+
+ protected void addEndTagNameProposals(ContentAssistRequest contentAssistRequest) {
+ System.out.println("AbstractXMLContentAssistProcessor: addEndTagNameProposals()
invoked");
+ }
+
+ protected void addEndTagProposals(ContentAssistRequest contentAssistRequest) {
+ System.out.println("AbstractXMLContentAssistProcessor: addEndTagProposals()
invoked");
+ }
+
+ protected void addEntityProposals(ContentAssistRequest contentAssistRequest, int
documentPosition, ITextRegion completionRegion, IDOMNode treeNode) {
+ System.out.println("AbstractXMLContentAssistProcessor: addEntityProposals()
invoked");
+ }
+
+ protected void addPCDATAProposal(String nodeName, ContentAssistRequest
contentAssistRequest) {
+ System.out.println("AbstractXMLContentAssistProcessor: addPCDATAProposal()
invoked");
+ }
+
+ protected void addStartDocumentProposals(ContentAssistRequest contentAssistRequest) {
+ System.out.println("AbstractXMLContentAssistProcessor: addStartDocumentProposals()
invoked");
+ }
+
+ protected void addTagCloseProposals(ContentAssistRequest contentAssistRequest) {
+ System.out.println("AbstractXMLContentAssistProcessor: addTagCloseProposals()
invoked");
+ }
+
+ protected void addTagInsertionProposals(ContentAssistRequest contentAssistRequest, int
childPosition) {
+ System.out.println("AbstractXMLContentAssistProcessor: addTagInsertionProposals()
invoked");
+ }
+
+ protected void addTagNameProposals(ContentAssistRequest contentAssistRequest, int
childPosition) {
+ System.out.println("AbstractXMLContentAssistProcessor: addTagNameProposals()
invoked");
+ }
+
+ protected ContentAssistRequest computeCompletionProposals(int documentPosition, String
matchString, ITextRegion completionRegion, IDOMNode treeNode, IDOMNode xmlnode) {
+ ContentAssistRequest contentAssistRequest =
super.computeCompletionProposals(documentPosition, matchString, completionRegion,
treeNode, xmlnode);
+
+ String regionType = completionRegion.getType();
+ IStructuredDocumentRegion sdRegion = getStructuredDocumentRegion(documentPosition);
+
+ /*
+ * Jeremy: Add attribute name proposals before empty tag close
+ */
+ if ((xmlnode.getNodeType() == Node.ELEMENT_NODE) || (xmlnode.getNodeType() ==
Node.DOCUMENT_NODE)) {
+ if (regionType == DOMRegionContext.XML_EMPTY_TAG_CLOSE) {
+ addAttributeNameProposals(contentAssistRequest);
+ }
+ }
+ return contentAssistRequest;
+ }
+
+ abstract protected ELContext getContext();
+
+ protected int getOffset() {
+ return this.fDocumentPosition;
+ }
+
+ protected IDocument getDocument() {
+ return this.fDocument;
+ }
+
+ protected IFile getResource() {
+ IStructuredModel sModel =
StructuredModelManager.getModelManager().getExistingModelForRead(fTextViewer.getDocument());
+ try {
+ if (sModel != null) {
+ String baseLocation = sModel.getBaseLocation();
+ IPath location = new Path(baseLocation).makeAbsolute();
+ IFile resource = FileBuffers.getWorkspaceFileAtLocation(location);
+ return resource;
+ }
+ }
+ finally {
+ if (sModel != null) {
+ sModel.releaseFromRead();
+ }
+ }
+ return null;
+ }
+
+ ELResolver[] getELResolvers(IResource resource) {
+ ELResolverFactoryManager elrfm = ELResolverFactoryManager.getInstance();
+ return elrfm.getResolvers(resource);
+ }
+}
Property changes on:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/contentassist/AbstractXMLContentAssistProcessor.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
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
(rev 0)
+++
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/contentassist/FaceletPageContectAssistProcessor.java 2009-05-22
18:10:43 UTC (rev 15453)
@@ -0,0 +1,33 @@
+package org.jboss.tools.jst.jsp.contentassist;
+
+import org.jboss.tools.jst.web.kb.IPageContext;
+import org.jboss.tools.jst.web.kb.internal.FaceletPageContextImpl;
+
+public class FaceletPageContectAssistProcessor extends JspContentAssistProcessor {
+
+ @Override
+ protected IPageContext getContext() {
+ IPageContext superContext = super.getContext();
+
+
+ FaceletPageContextImpl context = new FaceletPageContextImpl();
+ context.setResource(superContext.getResource());
+ context.setVarSearcher(superContext.getVarSearcher());
+ context.setElResolvers(superContext.getElResolvers());
+ setVars(context);
+
+ context.setResourceBundles(superContext.getResourceBundles());
+ context.setDocument(getDocument());
+ setNameSpaces(superContext, context);
+ context.setLibraries(getTagLibraries(context));
+
+// IFaceletPageContext getParentContext();
+// Map<String, String> getParams();
+
+ return context;
+ }
+
+ protected void setNameSpaces(IPageContext superContext, FaceletPageContextImpl context)
{
+ // TODO
+ }
+}
Property changes on:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/contentassist/FaceletPageContectAssistProcessor.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
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
(rev 0)
+++
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/contentassist/JspContentAssistProcessor.java 2009-05-22
18:10:43 UTC (rev 15453)
@@ -0,0 +1,104 @@
+package org.jboss.tools.jst.jsp.contentassist;
+
+import java.util.List;
+import java.util.Map;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.jface.text.IRegion;
+import org.eclipse.jface.text.Region;
+import org.eclipse.jst.jsp.core.internal.contentmodel.TaglibController;
+import org.eclipse.jst.jsp.core.internal.contentmodel.tld.TLDCMDocumentManager;
+import org.eclipse.jst.jsp.core.internal.contentmodel.tld.TaglibTracker;
+import org.eclipse.wst.sse.core.StructuredModelManager;
+import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel;
+import org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel;
+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.ElVarSearcher;
+import org.jboss.tools.common.el.core.resolver.Var;
+import org.jboss.tools.jst.web.kb.IPageContext;
+import org.jboss.tools.jst.web.kb.IResourceBundle;
+import org.jboss.tools.jst.web.kb.internal.JspContextImpl;
+import org.jboss.tools.jst.web.kb.taglib.INameSpace;
+import org.jboss.tools.jst.web.kb.taglib.ITagLibrary;
+import org.w3c.dom.Document;
+
+public class JspContentAssistProcessor extends XmlContentAssistProcessor {
+
+ @Override
+ protected IPageContext getContext() {
+ ELContext superContext = super.getContext();
+
+ IFile file = getResource();
+
+ JspContextImpl context = new JspContextImpl();
+ context.setResource(superContext.getResource());
+ context.setVarSearcher(superContext.getVarSearcher());
+ context.setElResolvers(superContext.getElResolvers());
+ setVars(context);
+ context.setResourceBundles(getResourceBundles());
+ context.setDocument(getDocument());
+ setNameSpaces(context);
+ context.setLibraries(getTagLibraries(context));
+
+ return context;
+ }
+
+ protected void setNameSpaces(JspContextImpl context) {
+ IStructuredModel sModel = StructuredModelManager
+ .getModelManager()
+ .getExistingModelForRead(getDocument());
+ try {
+ if (sModel == null)
+ return;
+
+ Document xmlDocument = (sModel instanceof IDOMModel) ?
+ ((IDOMModel) sModel).getDocument() :
+ null;
+
+ if (xmlDocument == null)
+ return;
+
+ TLDCMDocumentManager manager =
TaglibController.getTLDCMDocumentManager(getDocument());
+ List trackers = (manager == null? null : manager.getCMDocumentTrackers(getOffset()));
+ for (int i = 0; trackers != null && i < trackers.size(); i++) {
+ TaglibTracker tt = (TaglibTracker)trackers.get(i);
+ final String prefix = tt.getPrefix();
+ final String uri = tt.getURI();
+ if (prefix != null && prefix.trim().length() > 0 &&
+ uri != null && uri.trim().length() > 0) {
+
+ IRegion region = new Region(0, getDocument().getLength());
+ INameSpace nameSpace = new INameSpace(){
+
+ public String getURI() {
+ return uri.trim();
+ }
+
+ public String getPrefix() {
+ return prefix.trim();
+ }
+ };
+ context.addNameSpace(region, nameSpace);
+ }
+ }
+
+ return;
+ }
+ finally {
+ if (sModel != null) {
+ sModel.releaseFromRead();
+ }
+ }
+ }
+
+ protected ITagLibrary[] getTagLibraries(IPageContext context) {
+ // TODO
+ return null;
+ }
+
+ protected IResourceBundle[] getResourceBundles() {
+ // TODO
+ return null;
+ }
+}
Property changes on:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/contentassist/JspContentAssistProcessor.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
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
(rev 0)
+++
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/contentassist/XmlContentAssistProcessor.java 2009-05-22
18:10:43 UTC (rev 15453)
@@ -0,0 +1,30 @@
+package org.jboss.tools.jst.jsp.contentassist;
+
+import org.eclipse.core.resources.IFile;
+import org.jboss.tools.common.el.core.resolver.ELContext;
+import org.jboss.tools.common.el.core.resolver.ELContextImpl;
+import org.jboss.tools.common.el.core.resolver.ELResolver;
+import org.jboss.tools.common.el.core.resolver.ElVarSearcher;
+
+public class XmlContentAssistProcessor extends AbstractXMLContentAssistProcessor {
+
+ @Override
+ protected ELContext getContext() {
+ IFile file = getResource();
+ ElVarSearcher varSearcher = null; // TODO
+ ELResolver[] elResolvers = getELResolvers(file);
+
+ ELContextImpl context = new ELContextImpl();
+ context.setResource(getResource());
+ context.setVarSearcher(varSearcher);
+ context.setElResolvers(elResolvers);
+ setVars(context);
+
+ return context;
+ }
+
+ protected void setVars(ELContext context) {
+ // TODO
+ }
+
+}
Property changes on:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/contentassist/XmlContentAssistProcessor.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Show replies by date