Author: scabanovich
Date: 2011-05-04 19:26:11 -0400 (Wed, 04 May 2011)
New Revision: 31075
Added:
trunk/jsf/plugins/org.jboss.tools.jsf.text.ext/src/org/jboss/tools/jsf/text/ext/hyperlink/TLDAttributeHyperlink.java
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/TLDTagHyperlink.java
Log:
JBIDE-8845
https://issues.jboss.org/browse/JBIDE-8845
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-05-04
20:39:50 UTC (rev 31074)
+++
trunk/jsf/plugins/org.jboss.tools.jsf.text.ext/src/org/jboss/tools/jsf/text/ext/hyperlink/JsfJSPTagNameHyperlinkDetector.java 2011-05-04
23:26:11 UTC (rev 31075)
@@ -19,7 +19,9 @@
import org.eclipse.jface.text.Region;
import org.eclipse.jface.text.hyperlink.AbstractHyperlinkDetector;
import org.eclipse.jface.text.hyperlink.IHyperlink;
+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;
@@ -27,15 +29,20 @@
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;
import org.jboss.tools.jst.web.kb.KbQuery;
import org.jboss.tools.jst.web.kb.PageContextFactory;
import org.jboss.tools.jst.web.kb.PageProcessor;
+import org.jboss.tools.jst.web.kb.internal.taglib.AbstractAttribute;
import org.jboss.tools.jst.web.kb.internal.taglib.AbstractComponent;
import org.jboss.tools.jst.web.kb.internal.taglib.FaceletTag;
import org.jboss.tools.jst.web.kb.internal.taglib.TLDTag;
+import org.jboss.tools.jst.web.kb.taglib.IAttribute;
import org.jboss.tools.jst.web.kb.taglib.IComponent;
+import org.w3c.dom.Attr;
import org.w3c.dom.Document;
+import org.w3c.dom.Element;
import org.w3c.dom.Node;
public class JsfJSPTagNameHyperlinkDetector extends AbstractHyperlinkDetector {
@@ -65,12 +72,15 @@
IRegion reg = getRegion(n, region.getOffset());
- if(reg != null){
+ 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));
query.setOffset(reg.getOffset());
- query.setValue(n.getNodeName());
+ query.setValue(tagName);
+ query.setUri(getURI(region, textViewer.getDocument()));
query.setMask(false);
ELContext context = PageContextFactory.createPageContext(file);
@@ -89,6 +99,35 @@
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));
+ 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[] components = PageProcessor.getInstance().getAttributes(query,
(IPageContext)context);
+ ArrayList<IHyperlink> hyperlinks = new ArrayList<IHyperlink>();
+ for(IAttribute attribute : components){
+ if(validateComponent(attribute.getComponent())){
+ 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()]);
+ }
}
return parse(textViewer.getDocument(), xmlDocument, region);
@@ -136,23 +175,68 @@
}
private IRegion getRegion(Node n, int offset) {
- if (n == null || !(n instanceof IDOMElement)) return null;
+ if (n == null || !(n instanceof IDOMNode)) return null;
- IDOMElement elem = (IDOMElement)n;
-
- String tagName = elem.getTagName();
-
- int start = elem.getStartOffset();
- int nameStart = start + "<".length(); //$NON-NLS-1$
- int nameEnd = nameStart + tagName.length();
+ int start = 0;
+ int nameStart;
+ int nameEnd;
- if(offset > nameEnd){
- start = elem.getEndStartOffset();
- nameStart = start + "</".length(); //$NON-NLS-1$
+ if(n instanceof IDOMAttr) {
+ IDOMAttr attr = (IDOMAttr)n;
+ String attrName = attr.getName();
+ start = attr.getStartOffset();
+ nameStart = start;
+ nameEnd = nameStart + attrName.length();
+ } else if(n instanceof IDOMElement) {
+ IDOMElement elem = (IDOMElement)n;
+ String tagName = elem.getTagName();
+ start = elem.getStartOffset();
+ nameStart = start + "<".length(); //$NON-NLS-1$
nameEnd = nameStart + tagName.length();
+ if(offset > nameEnd) {
+ start = elem.getEndStartOffset();
+ nameStart = start + "</".length(); //$NON-NLS-1$
+ nameEnd = nameStart + tagName.length();
+ }
+ } else {
+ return null;
}
return new Region(nameStart,nameEnd - nameStart);
}
+ private String getURI(IRegion region, IDocument document) {
+ StructuredModelWrapper smw = new StructuredModelWrapper();
+ smw.init(document);
+ try {
+ Document xmlDocument = smw.getDocument();
+ if (xmlDocument == null) return null;
+
+ Node n = Utils.findNodeForOffset(xmlDocument, region.getOffset());
+
+ Node node = null;
+ if (n instanceof Attr) {
+ node = ((Attr)n).getOwnerElement();
+ } else {
+ node = n;
+ }
+ if (!(node instanceof Element)) return null;
+
+ String nodeName = node.getNodeName();
+ if (nodeName.indexOf(':') == -1) return null;
+
+ String nodePrefix = nodeName.substring(0, nodeName.indexOf(":"));
//$NON-NLS-1$
+ if (nodePrefix == null || nodePrefix.length() == 0) return null;
+
+ TaglibManagerWrapper tmw = new TaglibManagerWrapper();
+ tmw.init(document, region.getOffset());
+
+ if (!tmw.exists()) return null;
+
+ return tmw.getUri(nodePrefix);
+ } finally {
+ smw.dispose();
+ }
+ }
+
}
Added:
trunk/jsf/plugins/org.jboss.tools.jsf.text.ext/src/org/jboss/tools/jsf/text/ext/hyperlink/TLDAttributeHyperlink.java
===================================================================
---
trunk/jsf/plugins/org.jboss.tools.jsf.text.ext/src/org/jboss/tools/jsf/text/ext/hyperlink/TLDAttributeHyperlink.java
(rev 0)
+++
trunk/jsf/plugins/org.jboss.tools.jsf.text.ext/src/org/jboss/tools/jsf/text/ext/hyperlink/TLDAttributeHyperlink.java 2011-05-04
23:26:11 UTC (rev 31075)
@@ -0,0 +1,47 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Exadel, Inc. and 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
+ ******************************************************************************/
+package org.jboss.tools.jsf.text.ext.hyperlink;
+
+import org.eclipse.jface.text.IRegion;
+import org.jboss.tools.common.model.XModelObject;
+import org.jboss.tools.common.model.XModelObjectConstants;
+import org.jboss.tools.jst.web.kb.internal.taglib.AbstractAttribute;
+import org.jboss.tools.jst.web.kb.internal.taglib.AbstractComponent;
+
+public class TLDAttributeHyperlink extends TLDTagHyperlink {
+ protected AbstractAttribute attr;
+
+ public TLDAttributeHyperlink(AbstractAttribute attr, IRegion region) {
+ super((AbstractComponent)attr.getComponent(), region);
+ this.attr = attr;
+
+ XModelObject attrObject = TLDTagHyperlink.getXModelObject(attr);
+ if(attrObject != null) {
+ xmodelObject = attrObject;
+ if(xmodelObject != null && file != null) {
+ String fileName = file.getName();
+ String libraryName = getFileName(xmodelObject);
+ String objectName = xmodelObject.getAttributeValue(XModelObjectConstants.ATTR_NAME);
+ if(objectName == null) {
+ objectName = xmodelObject.getAttributeValue("attribute-name");
+ }
+ xmodelObjectName = fileName;
+ if(libraryName != null && !libraryName.equals(fileName)) {
+ xmodelObjectName += " : " + libraryName;
+ }
+ if(objectName != null && !objectName.equals(libraryName)) {
+ xmodelObjectName += " : " + objectName;
+ }
+ }
+ }
+ }
+
+}
Property changes on:
trunk/jsf/plugins/org.jboss.tools.jsf.text.ext/src/org/jboss/tools/jsf/text/ext/hyperlink/TLDAttributeHyperlink.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf.text.ext/src/org/jboss/tools/jsf/text/ext/hyperlink/TLDTagHyperlink.java
===================================================================
---
trunk/jsf/plugins/org.jboss.tools.jsf.text.ext/src/org/jboss/tools/jsf/text/ext/hyperlink/TLDTagHyperlink.java 2011-05-04
20:39:50 UTC (rev 31074)
+++
trunk/jsf/plugins/org.jboss.tools.jsf.text.ext/src/org/jboss/tools/jsf/text/ext/hyperlink/TLDTagHyperlink.java 2011-05-04
23:26:11 UTC (rev 31075)
@@ -16,32 +16,49 @@
import org.eclipse.osgi.util.NLS;
import org.eclipse.ui.IEditorPart;
import org.jboss.tools.common.model.XModelObject;
+import org.jboss.tools.common.model.XModelObjectConstants;
import org.jboss.tools.common.model.filesystems.impl.FileAnyImpl;
import org.jboss.tools.common.model.util.FindObjectHelper;
import org.jboss.tools.common.text.ext.hyperlink.AbstractHyperlink;
import org.jboss.tools.jsf.text.ext.JSFTextExtMessages;
+import org.jboss.tools.jst.web.kb.internal.KbObject;
import org.jboss.tools.jst.web.kb.internal.taglib.AbstractComponent;
import org.jboss.tools.jst.web.kb.taglib.ITagLibrary;
public class TLDTagHyperlink extends AbstractHyperlink {
- private AbstractComponent tag;
- private XModelObject xmodelObject;
- private String xmodelObjectName = null;
- private IFile file = null;
- private IRegion region;
+ protected AbstractComponent tag;
+ protected XModelObject xmodelObject;
+ protected String xmodelObjectName = null;
+ protected IFile file = null;
+ protected IRegion region;
public TLDTagHyperlink(AbstractComponent tag, IRegion region){
this.tag = tag;
this.region = region;
- IFile file = getFile(tag);
+ file = getFile(tag);
- if(file != null && file.getFullPath() != null &&
file.getFullPath().toString().endsWith(".jar")) {
- xmodelObject = getXModelObject(tag);
- if(xmodelObject != null)
- xmodelObjectName = file.getName()+" : "+getFileName(xmodelObject);
+ xmodelObject = getXModelObject(tag);
+ if(xmodelObject != null && file != null) {
+ String fileName = file.getName();
+ String libraryName = getFileName(xmodelObject);
+ String objectName = xmodelObject.getAttributeValue(XModelObjectConstants.ATTR_NAME);
+ if(objectName == null) {
+ objectName = xmodelObject.getAttributeValue("tag-name");
+ }
+ xmodelObjectName = fileName;
+ if(libraryName != null && !libraryName.equals(fileName)) {
+ xmodelObjectName += " : " + libraryName;
+ }
+ if(objectName != null && !objectName.equals(libraryName)) {
+ xmodelObjectName += " : " + objectName;
+ }
}
}
+
+ public String getObjectName() {
+ return xmodelObjectName;
+ }
public static IFile getFile(AbstractComponent tag){
ITagLibrary tagLib = tag.getTagLib();
@@ -52,7 +69,7 @@
return null;
}
- public static XModelObject getXModelObject(AbstractComponent tag){
+ public static XModelObject getXModelObject(KbObject tag){
Object id = tag.getId();
if(id instanceof XModelObject)
return (XModelObject)id;