Author: vrubezhny
Date: 2011-11-25 09:49:34 -0500 (Fri, 25 Nov 2011)
New Revision: 36663
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf.text.ext/src/org/jboss/tools/jsf/text/ext/hyperlink/JsfJSPTagNameHyperlinkDetector.java
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/contentassist/computers/FaceletsELCompletionProposalComputer.java
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/contentassist/computers/FaceletsTagCompletionProposalComputer.java
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/contentassist/computers/JspELCompletionProposalComputer.java
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/contentassist/computers/JspTagCompletionProposalComputer.java
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/contentassist/computers/XmlELCompletionProposalComputer.java
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/contentassist/computers/XmlTagCompletionProposalComputer.java
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/jspeditor/info/FaceletTagInfoHoverProcessor.java
trunk/jst/plugins/org.jboss.tools.jst.text.ext/src/org/jboss/tools/jst/text/ext/hyperlink/CSSClassHyperlink.java
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/PageContextFactory.java
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/XmlContextImpl.java
Log:
JBIDE-10090 NPE in VPE
NPE is fixed, PageContextFactory is made to return non-null context for any valid document
regarding on its type even IFile couldn't be obtained for the document (f. i., if the
document is packed in a jar). Context Type detection is improved. Dealing with Structured
model is fixed in JsfJSPTagNameHyperlinkDetector.
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf.text.ext/src/org/jboss/tools/jsf/text/ext/hyperlink/JsfJSPTagNameHyperlinkDetector.java
===================================================================
---
trunk/jsf/plugins/org.jboss.tools.jsf.text.ext/src/org/jboss/tools/jsf/text/ext/hyperlink/JsfJSPTagNameHyperlinkDetector.java 2011-11-25
14:45:18 UTC (rev 36662)
+++
trunk/jsf/plugins/org.jboss.tools.jsf.text.ext/src/org/jboss/tools/jsf/text/ext/hyperlink/JsfJSPTagNameHyperlinkDetector.java 2011-11-25
14:49:34 UTC (rev 36663)
@@ -1,12 +1,12 @@
/*******************************************************************************
- * Copyright (c) 2011 Exadel, Inc. and Red Hat, Inc.
+ * Copyright (c) 2011 Red Hat, Inc.
* Distributed under license by Red Hat, Inc. All rights reserved.
* This program is made available under the terms of the
* Eclipse Public License v1.0 which accompanies this distribution,
* and is available at
http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
- * Exadel, Inc. and Red Hat, Inc. - initial API and implementation
+ * Red Hat, Inc. - initial API and implementation
******************************************************************************/
package org.jboss.tools.jsf.text.ext.hyperlink;
@@ -24,12 +24,10 @@
import org.eclipse.wst.xml.core.internal.provisional.document.IDOMAttr;
import org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement;
import org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode;
-import org.jboss.tools.common.core.resources.XModelObjectEditorInput;
import org.jboss.tools.common.el.core.resolver.ELContext;
import org.jboss.tools.common.model.XModelObject;
import org.jboss.tools.common.text.ext.util.StructuredModelWrapper;
import org.jboss.tools.common.text.ext.util.Utils;
-import org.jboss.tools.jst.jsp.jspeditor.JSPTextEditor;
import org.jboss.tools.jst.jsp.jspeditor.JSPTextEditor.JSPStructuredTextViewer;
import org.jboss.tools.jst.text.ext.util.TaglibManagerWrapper;
import org.jboss.tools.jst.web.kb.IPageContext;
@@ -47,6 +45,7 @@
import org.w3c.dom.Element;
import org.w3c.dom.Node;
+@SuppressWarnings("restriction")
public class JsfJSPTagNameHyperlinkDetector extends AbstractHyperlinkDetector {
public IHyperlink[] detectHyperlinks(ITextViewer textViewer,
@@ -55,90 +54,85 @@
if(!(textViewer instanceof JSPStructuredTextViewer))
return null;
- JSPStructuredTextViewer viewer = (JSPStructuredTextViewer) textViewer;
-
- JSPTextEditor editor = viewer.getEditor();
-
- XModelObjectEditorInput xInput = (XModelObjectEditorInput) editor.getEditorInput();
-
- IFile file = xInput.getFile();
-
StructuredModelWrapper smw = new StructuredModelWrapper();
smw.init(textViewer.getDocument());
-
- Document xmlDocument = smw.getDocument();
- if (xmlDocument == null)
- return null;
-
- Node n = Utils.findNodeForOffset(xmlDocument, region.getOffset());
-
- IRegion reg = getRegion(n, region.getOffset());
-
- if(reg != null && n instanceof IDOMElement) {
- String tagName = n.getNodeName();
- int i = tagName.indexOf(":");
- KbQuery query = new KbQuery();
- query.setType(KbQuery.Type.TAG_NAME);
+ try {
+ Document xmlDocument = smw.getDocument();
+ if (xmlDocument == null)
+ return null;
- if(i > 0) query.setPrefix(tagName.substring(0, i));
- else query.setPrefix("");
+ Node n = Utils.findNodeForOffset(xmlDocument, region.getOffset());
- query.setOffset(reg.getOffset());
- query.setValue(tagName);
- query.setUri(getURI(region, textViewer.getDocument()));
- query.setMask(false);
+ IRegion reg = getRegion(n, region.getOffset());
- ELContext context = PageContextFactory.createPageContext(file);
-
- if(context instanceof IPageContext){
- IComponent[] components = PageProcessor.getInstance().getComponents(query,
(IPageContext)context);
- ArrayList<IHyperlink> hyperlinks = new ArrayList<IHyperlink>();
- for(IComponent component : components){
- if(!component.isExtended() && validateComponent(component,
((IPageContext)context).getNameSpaces(reg.getOffset()), query.getPrefix())){
- TLDTagHyperlink link = new TLDTagHyperlink((AbstractComponent)component, reg);
- link.setDocument(textViewer.getDocument());
- hyperlinks.add(link);
+ if(reg != null && n instanceof IDOMElement) {
+ String tagName = n.getNodeName();
+ int i = tagName.indexOf(":");
+ KbQuery query = new KbQuery();
+ query.setType(KbQuery.Type.TAG_NAME);
+
+ if(i > 0) query.setPrefix(tagName.substring(0, i));
+ else query.setPrefix("");
+
+ query.setOffset(reg.getOffset());
+ query.setValue(tagName);
+ query.setUri(getURI(region, textViewer.getDocument()));
+ query.setMask(false);
+
+ ELContext context = PageContextFactory.createPageContext(textViewer.getDocument());
+
+ if(context instanceof IPageContext){
+ IComponent[] components = PageProcessor.getInstance().getComponents(query,
(IPageContext)context);
+ ArrayList<IHyperlink> hyperlinks = new ArrayList<IHyperlink>();
+ for(IComponent component : components){
+ if(!component.isExtended() && validateComponent(component,
((IPageContext)context).getNameSpaces(reg.getOffset()), query.getPrefix())){
+ TLDTagHyperlink link = new TLDTagHyperlink((AbstractComponent)component, reg);
+ link.setDocument(textViewer.getDocument());
+ hyperlinks.add(link);
+ }
}
+ sortHyperlinks(hyperlinks);
+ if(hyperlinks.size() > 0)
+ return (IHyperlink[]) hyperlinks.toArray(new IHyperlink[hyperlinks.size()]);
}
- sortHyperlinks(hyperlinks);
- if(hyperlinks.size() > 0)
- return (IHyperlink[]) hyperlinks.toArray(new IHyperlink[hyperlinks.size()]);
- }
- } else if(reg != null && n instanceof IDOMAttr) {
- String tagName = ((IDOMAttr)n).getOwnerElement().getNodeName();
- int i = tagName.indexOf(":");
- KbQuery query = new KbQuery();
- query.setType(KbQuery.Type.ATTRIBUTE_NAME);
-
- if(i > 0) query.setPrefix(tagName.substring(0, i));
- else query.setPrefix("");
-
- query.setUri(getURI(region, textViewer.getDocument()));
- query.setParentTags(new String[]{tagName});
- query.setParent(tagName);
- query.setOffset(reg.getOffset());
- query.setValue(n.getNodeName());
- query.setMask(false);
-
- ELContext context = PageContextFactory.createPageContext(file);
-
- if(context instanceof IPageContext){
- IAttribute[] attributes = PageProcessor.getInstance().getAttributes(query,
(IPageContext)context);
- ArrayList<IHyperlink> hyperlinks = new ArrayList<IHyperlink>();
- for(IAttribute attribute : attributes){
- if(!attribute.isExtended() && validateComponent(attribute.getComponent(),
((IPageContext)context).getNameSpaces(reg.getOffset()), query.getPrefix()) &&
attribute instanceof AbstractAttribute){
- TLDAttributeHyperlink link = new
TLDAttributeHyperlink((AbstractAttribute)attribute, reg);
- link.setDocument(textViewer.getDocument());
- hyperlinks.add(link);
+ } else if(reg != null && n instanceof IDOMAttr) {
+ String tagName = ((IDOMAttr)n).getOwnerElement().getNodeName();
+ int i = tagName.indexOf(":");
+ KbQuery query = new KbQuery();
+ query.setType(KbQuery.Type.ATTRIBUTE_NAME);
+
+ if(i > 0) query.setPrefix(tagName.substring(0, i));
+ else query.setPrefix("");
+
+ query.setUri(getURI(region, textViewer.getDocument()));
+ query.setParentTags(new String[]{tagName});
+ query.setParent(tagName);
+ query.setOffset(reg.getOffset());
+ query.setValue(n.getNodeName());
+ query.setMask(false);
+
+ ELContext context = PageContextFactory.createPageContext(textViewer.getDocument());
+
+ if(context instanceof IPageContext){
+ IAttribute[] attributes = PageProcessor.getInstance().getAttributes(query,
(IPageContext)context);
+ ArrayList<IHyperlink> hyperlinks = new ArrayList<IHyperlink>();
+ for(IAttribute attribute : attributes){
+ if(!attribute.isExtended() && validateComponent(attribute.getComponent(),
((IPageContext)context).getNameSpaces(reg.getOffset()), query.getPrefix()) &&
attribute instanceof AbstractAttribute){
+ TLDAttributeHyperlink link = new
TLDAttributeHyperlink((AbstractAttribute)attribute, reg);
+ link.setDocument(textViewer.getDocument());
+ hyperlinks.add(link);
+ }
}
+ sortHyperlinks(hyperlinks);
+ if(hyperlinks.size() > 0)
+ return (IHyperlink[]) hyperlinks.toArray(new IHyperlink[hyperlinks.size()]);
}
- sortHyperlinks(hyperlinks);
- if(hyperlinks.size() > 0)
- return (IHyperlink[]) hyperlinks.toArray(new IHyperlink[hyperlinks.size()]);
}
+
+ return parse(textViewer.getDocument(), xmlDocument, region);
+ } finally {
+ smw.dispose();
}
-
- return parse(textViewer.getDocument(), xmlDocument, region);
}
private boolean validateComponent(IComponent component, Map<String,
List<INameSpace>> nameSpaces, String prefix){
Modified:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/contentassist/computers/FaceletsELCompletionProposalComputer.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/contentassist/computers/FaceletsELCompletionProposalComputer.java 2011-11-25
14:45:18 UTC (rev 36662)
+++
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/contentassist/computers/FaceletsELCompletionProposalComputer.java 2011-11-25
14:49:34 UTC (rev 36663)
@@ -124,7 +124,7 @@
*/
@Override
protected ELContext createContext() {
- return PageContextFactory.createPageContext(getResource(),
PageContextFactory.FACELETS_PAGE_CONTEXT_TYPE);
+ return PageContextFactory.createPageContext(getDocument(),
PageContextFactory.FACELETS_PAGE_CONTEXT_TYPE);
}
/*
Modified:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/contentassist/computers/FaceletsTagCompletionProposalComputer.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/contentassist/computers/FaceletsTagCompletionProposalComputer.java 2011-11-25
14:45:18 UTC (rev 36662)
+++
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/contentassist/computers/FaceletsTagCompletionProposalComputer.java 2011-11-25
14:49:34 UTC (rev 36663)
@@ -124,7 +124,7 @@
*/
@Override
protected ELContext createContext() {
- return PageContextFactory.createPageContext(getResource(),
PageContextFactory.FACELETS_PAGE_CONTEXT_TYPE);
+ return PageContextFactory.createPageContext(getDocument(),
PageContextFactory.FACELETS_PAGE_CONTEXT_TYPE);
}
/*
Modified:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/contentassist/computers/JspELCompletionProposalComputer.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/contentassist/computers/JspELCompletionProposalComputer.java 2011-11-25
14:45:18 UTC (rev 36662)
+++
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/contentassist/computers/JspELCompletionProposalComputer.java 2011-11-25
14:49:34 UTC (rev 36663)
@@ -18,8 +18,6 @@
import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.Region;
-import org.eclipse.wst.sse.ui.contentassist.CompletionProposalInvocationContext;
-import org.eclipse.wst.xml.ui.internal.contentassist.ContentAssistRequest;
import org.jboss.tools.common.el.core.model.ELExpression;
import org.jboss.tools.common.el.core.parser.ELParserFactory;
import org.jboss.tools.common.el.core.parser.ELParserUtil;
@@ -42,7 +40,6 @@
* @author Jeremy
*
*/
-@SuppressWarnings("restriction")
public class JspELCompletionProposalComputer extends XmlELCompletionProposalComputer {
/*
@@ -51,7 +48,7 @@
*/
@Override
protected ELContext createContext() {
- return PageContextFactory.createPageContext(getResource(),
PageContextFactory.JSP_PAGE_CONTEXT_TYPE);
+ return PageContextFactory.createPageContext(getDocument(),
PageContextFactory.JSP_PAGE_CONTEXT_TYPE);
}
/*
Modified:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/contentassist/computers/JspTagCompletionProposalComputer.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/contentassist/computers/JspTagCompletionProposalComputer.java 2011-11-25
14:45:18 UTC (rev 36662)
+++
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/contentassist/computers/JspTagCompletionProposalComputer.java 2011-11-25
14:49:34 UTC (rev 36663)
@@ -50,7 +50,7 @@
*/
@Override
protected ELContext createContext() {
- return PageContextFactory.createPageContext(getResource(),
PageContextFactory.JSP_PAGE_CONTEXT_TYPE);
+ return PageContextFactory.createPageContext(getDocument(),
PageContextFactory.JSP_PAGE_CONTEXT_TYPE);
}
/*
Modified:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/contentassist/computers/XmlELCompletionProposalComputer.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/contentassist/computers/XmlELCompletionProposalComputer.java 2011-11-25
14:45:18 UTC (rev 36662)
+++
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/contentassist/computers/XmlELCompletionProposalComputer.java 2011-11-25
14:49:34 UTC (rev 36663)
@@ -161,7 +161,6 @@
CompletionProposalInvocationContext context) {
}
- @SuppressWarnings("unused")
@Override
protected void addAttributeValueELProposals(ContentAssistRequest contentAssistRequest,
CompletionProposalInvocationContext context) {
@@ -357,10 +356,10 @@
int quoteIndex = restOfValue.indexOf('\'');
if (quoteIndex == -1 || paraIndex == -1 || (paraIndex != -1 && quoteIndex
> paraIndex)) {
// Need to insert closing single-quote if there is no quote inserted
- if (!replacementString.endsWith("\'"))
+ if (!replacementString.endsWith("\'")) //$NON-NLS-1$
replacementString += '\'';
} else {
- if (quoteIndex != -1 && replacementString.endsWith("\'"))
+ if (quoteIndex != -1 && replacementString.endsWith("\'"))
//$NON-NLS-1$
replacementString = replacementString.substring(0, replacementString.length() -
1);
}
if (paraIndex == -1) {
@@ -368,7 +367,7 @@
replacementString += ']';
}
} else {
- if (replacementString.endsWith("]") &&
restOfValue.indexOf(']') != -1) {
+ if (replacementString.endsWith("]") &&
restOfValue.indexOf(']') != -1) { //$NON-NLS-1$
replacementString = replacementString.substring(0, replacementString.length() -1);
}
}
@@ -440,7 +439,6 @@
*
* @param contentAssistRequest
*/
- @SuppressWarnings("unused")
protected void addELPredicateProposals(ContentAssistRequest contentAssistRequest, int
baseRelevance, boolean shiftRelevanceAgainstTagNameProposals) {
if (!isELCAToBeShown())
return;
@@ -528,7 +526,7 @@
}
protected ELContext createContext() {
- return PageContextFactory.createPageContext(getResource(),
PageContextFactory.XML_PAGE_CONTEXT_TYPE);
+ return PageContextFactory.createPageContext(getDocument(),
PageContextFactory.XML_PAGE_CONTEXT_TYPE);
}
protected KbQuery createKbQuery(Type type, String query, String stringQuery) {
@@ -926,7 +924,7 @@
ELInstance is = ELUtil.findInstance(model, inValueOffset);// ELInstance
ELInvocationExpression ie = ELUtil.findExpression(model, inValueOffset);//
ELExpression
- boolean isELStarted = (model != null && is != null &&
(startsWithELBeginning(model.toString()))); //$NON-NLS-1$
+ boolean isELStarted = (model != null && is != null &&
(startsWithELBeginning(model.toString())));
boolean isELClosed = (model != null && is != null &&
model.toString().endsWith("}")); //$NON-NLS-1$
// boolean insideEL = startOffset + model.toString().length()
Modified:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/contentassist/computers/XmlTagCompletionProposalComputer.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/contentassist/computers/XmlTagCompletionProposalComputer.java 2011-11-25
14:45:18 UTC (rev 36662)
+++
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/contentassist/computers/XmlTagCompletionProposalComputer.java 2011-11-25
14:49:34 UTC (rev 36663)
@@ -321,7 +321,6 @@
String mainPrefix = getTagPrefix();
String mainURI = getTagUri();
- // TODO: Insert here: processing for the tag ending start region due to
// - calculate correct replacenemt begin position
// - calculate correct replacenment length
// - calculate correct match string
@@ -331,7 +330,6 @@
/*
* Jeremy: Add attribute name proposals before empty tag close
*/
- // TODO: calculate those values hereafter
IStructuredDocumentRegion sdRegion = getStructuredDocumentRegion(getOffset());
ITextRegion completionRegion = getCompletionRegion(getOffset(),
contentAssistRequest.getNode());
@@ -443,7 +441,7 @@
}
protected ELContext createContext() {
- return PageContextFactory.createPageContext(getResource(),
PageContextFactory.XML_PAGE_CONTEXT_TYPE);
+ return PageContextFactory.createPageContext(getDocument(),
PageContextFactory.XML_PAGE_CONTEXT_TYPE);
}
protected KbQuery createKbQuery(Type type, String query, String stringQuery) {
Modified:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/jspeditor/info/FaceletTagInfoHoverProcessor.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/jspeditor/info/FaceletTagInfoHoverProcessor.java 2011-11-25
14:45:18 UTC (rev 36662)
+++
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/jspeditor/info/FaceletTagInfoHoverProcessor.java 2011-11-25
14:49:34 UTC (rev 36663)
@@ -88,11 +88,7 @@
this.fDocumentPosition = documentPosition;
this.fContext = null;
- IFile file = getResource(textViewer.getDocument());
- if (file == null)
- return null;
-
- fContext = PageContextFactory.createPageContext(file);
+ fContext = PageContextFactory.createPageContext(textViewer.getDocument());
if (fContext == null)
return null;
Modified:
trunk/jst/plugins/org.jboss.tools.jst.text.ext/src/org/jboss/tools/jst/text/ext/hyperlink/CSSClassHyperlink.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.text.ext/src/org/jboss/tools/jst/text/ext/hyperlink/CSSClassHyperlink.java 2011-11-25
14:45:18 UTC (rev 36662)
+++
trunk/jst/plugins/org.jboss.tools.jst.text.ext/src/org/jboss/tools/jst/text/ext/hyperlink/CSSClassHyperlink.java 2011-11-25
14:49:34 UTC (rev 36663)
@@ -60,7 +60,7 @@
@Override
protected void doHyperlink(IRegion region) {
ICSSContainerSupport cssContainerSupport = null;
- ELContext context = PageContextFactory.createPageContext(getFile());
+ ELContext context = PageContextFactory.createPageContext(getDocument());
if (!(context instanceof ICSSContainerSupport)) {
openFileFailed();
return;
Modified:
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/PageContextFactory.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/PageContextFactory.java 2011-11-25
14:45:18 UTC (rev 36662)
+++
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/PageContextFactory.java 2011-11-25
14:49:34 UTC (rev 36663)
@@ -21,6 +21,7 @@
import java.util.Map;
import java.util.Set;
+import org.eclipse.core.filebuffers.FileBuffers;
import org.eclipse.core.internal.resources.ICoreConstants;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
@@ -28,13 +29,16 @@
import org.eclipse.core.resources.IResourceChangeEvent;
import org.eclipse.core.resources.IResourceChangeListener;
import org.eclipse.core.resources.IResourceDelta;
+import org.eclipse.core.resources.IStorage;
import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.content.IContentType;
+import org.eclipse.jdt.core.IJarEntryResource;
import org.eclipse.jdt.core.JavaCore;
+import org.eclipse.jdt.internal.core.JarPackageFragmentRoot;
import org.eclipse.jdt.internal.ui.text.FastJavaPartitionScanner;
import org.eclipse.jdt.ui.text.IJavaPartitions;
import org.eclipse.jface.text.BadLocationException;
@@ -47,7 +51,11 @@
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.ui.IEditorInput;
+import org.eclipse.ui.IFileEditorInput;
+import org.eclipse.ui.IStorageEditorInput;
import org.eclipse.ui.ide.IDE;
+import org.eclipse.ui.texteditor.ITextEditor;
import org.eclipse.wst.common.componentcore.internal.ComponentResource;
import org.eclipse.wst.common.componentcore.internal.StructureEdit;
import org.eclipse.wst.common.componentcore.internal.WorkbenchComponent;
@@ -158,6 +166,28 @@
}
/**
+ * Creates a page context for the specified context document
+ *
+ * @param file
+ * @param contentType
+ * @return
+ */
+ public static ELContext createPageContext(IDocument document) {
+ return createPageContext(document, null);
+ }
+
+ /**
+ * Creates a page context for the specified context document
+ *
+ * @param file
+ * @param contentType
+ * @return
+ */
+ public static ELContext createPageContext(IDocument document, String contextType) {
+ return createPageContext(document, null, contextType);
+ }
+
+ /**
* Creates a page context for the specified context file
*
* @param file
@@ -169,17 +199,28 @@
}
/**
- * Creates a page context for the specified context type
+ * Creates a page context for the specified context file
*
* @param file
* @param contentType
* @return
*/
public static ELContext createPageContext(IFile file, String contextType) {
- return getInstance().createPageContext(file, new ArrayList<String>(),
contextType);
+ return createPageContext(null, file, null);
}
/**
+ * Creates a page context for the specified context type
+ *
+ * @param file
+ * @param contentType
+ * @return
+ */
+ public static ELContext createPageContext(IDocument document, IFile file, String
contextType) {
+ return getInstance().createPageContext(document, file, new ArrayList<String>(),
contextType);
+ }
+
+ /**
* Cleans up the context for the file specified
*
* @param file
@@ -323,12 +364,14 @@
* @param parents List of parent contexts
* @return
*/
- private ELContext createPageContext(IFile file, List<String> parents, String
defaultContextType) {
+ private ELContext createPageContext(IDocument document, IFile file, List<String>
parents, String defaultContextType) {
+ if (file == null)
+ file = getResource(document);
+
boolean isContextCachingAllowed = !EclipseUIUtil.isOpenInActiveEditor(file);
ELContext context = isContextCachingAllowed ? getSavedContext(file) : null;
- if (context == null && file != null) {
- IContentType type = IDE.getContentType(file);
- String typeId = (type == null ? null : type.getId());
+ if (context == null) {
+ String typeId = getContentTypeIdentifier(file == null ? document : file);
if(JavaCore.JAVA_SOURCE_CONTENT_TYPE.equalsIgnoreCase(typeId)) {
context = createJavaContext(file);
@@ -342,23 +385,32 @@
if(manager != null) {
IStructuredModel model = null;
try {
- model = manager.getModelForRead(file);
+ model = file != null ?
+ manager.getModelForRead(file) :
+ manager.getExistingModelForRead(document);
if (model instanceof IDOMModel) {
IDOMModel domModel = (IDOMModel) model;
context = defaultContextType == null ?
createPageContextInstance(domModel.getContentTypeIdentifier()) :
createContextInstanceOfType(defaultContextType);
if (context != null) {
- IDOMDocument document = domModel.getDocument();
+ IDOMDocument domDocument = domModel.getDocument();
context.setResource(file);
- context.setElResolvers(ELResolverFactoryManager.getInstance().getResolvers(file));
+ if (document != null && context instanceof XmlContextImpl) {
+ // Renew the document in context, since it might be cleared by
context.setResource() call
+ ((XmlContextImpl)context).setDocument(document);
+ }
+
+ IProject project = file != null ? file.getProject() : getActiveProject();
+
+ context.setElResolvers(ELResolverFactoryManager.getInstance().getResolvers(project));
if (context instanceof JspContextImpl && !(context instanceof
FaceletPageContextImpl)) {
// Fill JSP namespaces defined in TLDCMDocumentManager
fillJSPNameSpaces((JspContextImpl)context);
}
// The subsequently called functions may use the file and document
// already stored in context for their needs
- fillContextForChildNodes(model.getStructuredDocument(), document, context,
parents);
+ fillContextForChildNodes(model.getStructuredDocument(), domDocument, context,
parents);
}
}
} catch (CoreException e) {
@@ -379,9 +431,86 @@
}
return context;
}
-
+
+ private IProject getActiveProject() {
+ ITextEditor editor = EclipseUIUtil.getActiveEditor();
+ if (editor == null) return null;
+
+ IEditorInput editorInput = editor.getEditorInput();
+ if (editorInput instanceof IFileEditorInput) {
+ IFile file = ((IFileEditorInput)editorInput).getFile();
+ return file == null ? null : file.getProject();
+ } else if (editorInput instanceof IStorageEditorInput) {
+ IStorage storage;
+ try {
+ storage = ((IStorageEditorInput)editorInput).getStorage();
+ } catch (CoreException e) {
+ return null;
+ }
+ if (storage instanceof IJarEntryResource) {
+ Object parent = ((IJarEntryResource)storage).getParent();
+ while (parent instanceof IJarEntryResource && !(parent instanceof IProject))
{
+ parent = ((IJarEntryResource)parent).getParent();
+ }
+ if (parent instanceof JarPackageFragmentRoot) {
+ return ((JarPackageFragmentRoot)parent).getJavaProject().getProject();
+ }
+ return null;
+ }
+ }
+ return null;
+ }
+
+ protected String getContentTypeIdentifier(Object source) {
+ if (source instanceof IFile) {
+ IContentType type = IDE.getContentType((IFile)source);
+ if (type != null) return type.getId();
+ } else if (source instanceof IDocument) {
+ IStructuredModel sModel =
StructuredModelManager.getModelManager().getExistingModelForRead((IDocument)source);
+ try {
+ if (sModel != null) return sModel.getContentTypeIdentifier();
+ } finally {
+ if (sModel != null) sModel.releaseFromRead();
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Returns IFile resource of the document
+ *
+ * @return
+ */
+ public static IFile getResource(IDocument document) {
+ if (document == null) return null;
+ IStructuredModel sModel =
StructuredModelManager.getModelManager().getExistingModelForRead(document);
+ try {
+ if (sModel != null) {
+ String baseLocation = sModel.getBaseLocation();
+ IPath location = new Path(baseLocation).makeAbsolute();
+ return FileBuffers.getWorkspaceFileAtLocation(location);
+ }
+ }
+ finally {
+ if (sModel != null) {
+ sModel.releaseFromRead();
+ }
+ }
+ return null;
+ }
+
private static ELContext createPageContextInstance(String contentType) {
String contextType = IncludeContextBuilder.getContextType(contentType);
+ if (contextType == null && contentType != null) {
+ IContentType baseContentType =
Platform.getContentTypeManager().getContentType(contentType);
+ baseContentType = baseContentType == null ? null : baseContentType.getBaseType();
+
+ while (contextType == null && baseContentType != null) {
+ contextType = IncludeContextBuilder.getContextType(baseContentType.getId());
+ baseContentType = baseContentType.getBaseType();
+ }
+ }
+
return createContextInstanceOfType(contextType);
}
@@ -556,7 +685,7 @@
if (fileName != null && !fileName.trim().isEmpty()) {
IFile file = getFileFromProject(fileName, context.getResource());
if (file != null && checkCycling(parents, file)) { // checkCycling is to
fix for JBIDE-5083
- ELContext includedContext = createPageContext(file, newParentList, null);
+ ELContext includedContext = createPageContext(null, file, newParentList, null);
if (includedContext != null)
((IIncludedContextSupport)context).addIncludedContext(includedContext);
}
Modified:
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/XmlContextImpl.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/XmlContextImpl.java 2011-11-25
14:45:18 UTC (rev 36662)
+++
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/XmlContextImpl.java 2011-11-25
14:49:34 UTC (rev 36663)
@@ -1,3 +1,13 @@
+/*******************************************************************************
+ * Copyright (c) 2010-2011 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
package org.jboss.tools.jst.web.kb.internal;
import java.util.ArrayList;
@@ -20,6 +30,11 @@
import org.jboss.tools.jst.web.kb.WebKbPlugin;
import org.jboss.tools.jst.web.kb.taglib.INameSpace;
+/**
+ *
+ * @author Victor V. Rubezhny
+ *
+ */
public class XmlContextImpl extends ELContextImpl implements IXmlContext {
protected IDocument document;
@@ -33,13 +48,16 @@
@Override
public void setResource(IFile resource) {
super.setResource(resource);
-
- FileEditorInput editorInput = null;
- try {
- editorInput = new FileEditorInput(resource);
- document = getConnectedDocument(editorInput);
- } finally {
- releaseConnectedDocument(editorInput);
+
+ document = null;
+ if (resource != null) {
+ FileEditorInput editorInput = null;
+ try {
+ editorInput = new FileEditorInput(resource);
+ document = getConnectedDocument(editorInput);
+ } finally {
+ releaseConnectedDocument(editorInput);
+ }
}
}
@@ -51,6 +69,14 @@
return document;
}
+ /*
+ * (non-Javadoc)
+ * @see org.jboss.tools.jst.web.kb.PageContext#getDocument()
+ */
+ public void setDocument(IDocument document) {
+ this.document = document;
+ }
+
/*
* TODO: the visibility must differ between 'include'-like and
'template'-like inclusion
*