Author: dazarov
Date: 2009-12-20 06:06:37 -0500 (Sun, 20 Dec 2009)
New Revision: 19486
Added:
trunk/jsf/plugins/org.jboss.tools.jsf.text.ext/src/org/jboss/tools/jsf/text/ext/hyperlink/JSPExprHyperlink.java
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf.text.ext/src/org/jboss/tools/jsf/text/ext/hyperlink/JSPExprHyperlinkPartitioner.java
Log:
https://jira.jboss.org/jira/browse/JBIDE-4758
Added:
trunk/jsf/plugins/org.jboss.tools.jsf.text.ext/src/org/jboss/tools/jsf/text/ext/hyperlink/JSPExprHyperlink.java
===================================================================
---
trunk/jsf/plugins/org.jboss.tools.jsf.text.ext/src/org/jboss/tools/jsf/text/ext/hyperlink/JSPExprHyperlink.java
(rev 0)
+++
trunk/jsf/plugins/org.jboss.tools.jsf.text.ext/src/org/jboss/tools/jsf/text/ext/hyperlink/JSPExprHyperlink.java 2009-12-20
11:06:37 UTC (rev 19486)
@@ -0,0 +1,106 @@
+/*******************************************************************************
+ * Copyright (c) 2009 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.core.resources.IFile;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.IRegion;
+import org.eclipse.jface.text.Region;
+import org.eclipse.ui.IEditorPart;
+import org.jboss.tools.common.el.core.model.ELExpression;
+import org.jboss.tools.common.el.core.model.ELInvocationExpression;
+import org.jboss.tools.common.el.core.resolver.ELContext;
+import org.jboss.tools.common.el.core.resolver.ELResolution;
+import org.jboss.tools.common.el.core.resolver.ELResolver;
+import org.jboss.tools.common.el.core.resolver.ELSegment;
+import org.jboss.tools.common.el.core.resolver.JavaMemberELSegment;
+import org.jboss.tools.common.text.ext.ExtensionsPlugin;
+import org.jboss.tools.common.text.ext.hyperlink.AbstractHyperlink;
+import org.jboss.tools.jsf.text.ext.JSFExtensionsPlugin;
+import org.jboss.tools.jst.web.kb.PageContextFactory;
+
+/**
+ * @author Daniel
+ */
+public class JSPExprHyperlink extends AbstractHyperlink{
+ private String hyperlinkText = ""; //$NON-NLS-1$
+ private ELExpression expression;
+ ELInvocationExpression invocationExpression;
+
+ protected IRegion doGetHyperlinkRegion(int offset) {
+ expression = JSPExprHyperlinkPartitioner.getExpression(getDocument(), offset);
+ invocationExpression = getInvocationExpression(expression, offset);
+ if(invocationExpression != null){
+ Region region = new Region(invocationExpression.getStartPosition(),
invocationExpression.getLength());
+ return region;
+ }
+ return null;
+ }
+
+ private ELInvocationExpression getInvocationExpression(ELExpression expression, int
offset){
+ if(expression == null)
+ return null;
+
+ for(ELInvocationExpression ie : expression.getInvocations()){
+ if (expression.getStartPosition()+ie.getStartPosition() <= offset &&
expression.getStartPosition()+ie.getEndPosition() >= offset) {
+ return ie;
+ }
+ }
+ return null;
+ }
+
+ protected void doHyperlink(IRegion region) {
+ IEditorPart part = null;
+ if (region == null)
+ return;
+
+ try {
+ IDocument document = getDocument();
+ hyperlinkText = document
+ .get(region.getOffset(), region.getLength());
+ } catch (BadLocationException ex) {
+ ExtensionsPlugin.getPluginLog().logError(ex);
+ }
+ if(invocationExpression != null){
+ ELContext context = PageContextFactory.getInstance().createPageContext(getFile());
+ if(context != null){
+ for(ELResolver resolver : context.getElResolvers()){
+ ELResolution resolution = resolver.resolve(context, expression,
invocationExpression.getStartPosition());
+ ELSegment segment =
resolution.findSegmentByOffset(invocationExpression.getStartPosition());
+ if(segment != null){
+ if(segment instanceof JavaMemberELSegment){
+ JavaMemberELSegment javaSegment = (JavaMemberELSegment)segment;
+ if(javaSegment.getJavaElement() != null){
+ try{
+ IResource resource = javaSegment.getJavaElement().getCorrespondingResource();
+ if(resource != null && resource instanceof IFile)
+ part =
openFileInEditor((IFile)javaSegment.getJavaElement().getCorrespondingResource());
+ }catch(JavaModelException ex){
+ JSFExtensionsPlugin.log(ex);
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ if (part == null)
+ openFileFailed();
+ }
+
+ public String getHyperlinkText() {
+ return hyperlinkText;
+ }
+
+}
Property changes on:
trunk/jsf/plugins/org.jboss.tools.jsf.text.ext/src/org/jboss/tools/jsf/text/ext/hyperlink/JSPExprHyperlink.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf.text.ext/src/org/jboss/tools/jsf/text/ext/hyperlink/JSPExprHyperlinkPartitioner.java
===================================================================
---
trunk/jsf/plugins/org.jboss.tools.jsf.text.ext/src/org/jboss/tools/jsf/text/ext/hyperlink/JSPExprHyperlinkPartitioner.java 2009-12-19
18:52:53 UTC (rev 19485)
+++
trunk/jsf/plugins/org.jboss.tools.jsf.text.ext/src/org/jboss/tools/jsf/text/ext/hyperlink/JSPExprHyperlinkPartitioner.java 2009-12-20
11:06:37 UTC (rev 19486)
@@ -10,22 +10,22 @@
******************************************************************************/
package org.jboss.tools.jsf.text.ext.hyperlink;
+import org.eclipse.core.resources.IFile;
import org.eclipse.jface.text.IDocument;
-import org.eclipse.wst.xml.core.internal.provisional.document.IDOMAttr;
-import org.eclipse.wst.xml.core.internal.provisional.document.IDOMText;
+import org.jboss.tools.common.el.core.ELReference;
+import org.jboss.tools.common.el.core.model.ELExpression;
+import org.jboss.tools.common.el.core.resolver.ELContext;
import org.jboss.tools.common.text.ext.hyperlink.AbstractHyperlinkPartitioner;
import org.jboss.tools.common.text.ext.hyperlink.HyperlinkRegion;
import org.jboss.tools.common.text.ext.hyperlink.IExclusiblePartitionerRecognition;
import org.jboss.tools.common.text.ext.hyperlink.IHyperlinkPartitionRecognizer;
import org.jboss.tools.common.text.ext.hyperlink.IHyperlinkRegion;
import org.jboss.tools.common.text.ext.util.StructuredModelWrapper;
-import org.jboss.tools.common.text.ext.util.Utils;
import org.jboss.tools.jst.text.ext.hyperlink.jsp.JSPRootHyperlinkPartitioner;
-import org.w3c.dom.Document;
-import org.w3c.dom.Node;
+import org.jboss.tools.jst.web.kb.PageContextFactory;
/**
- * @author Jeremy
+ * @author Jeremy and Daniel
*/
@SuppressWarnings("restriction")
public class JSPExprHyperlinkPartitioner extends AbstractHyperlinkPartitioner implements
IHyperlinkPartitionRecognizer, IExclusiblePartitionerRecognition {
@@ -39,28 +39,17 @@
* @see
com.ibm.sse.editor.hyperlink.AbstractHyperlinkPartitioner#parse(org.eclipse.jface.text.IDocument,
com.ibm.sse.editor.extensions.hyperlink.IHyperlinkRegion)
*/
protected IHyperlinkRegion parse(IDocument document, IHyperlinkRegion superRegion) {
- StructuredModelWrapper smw = new StructuredModelWrapper();
- smw.init(document);
- try {
- Document xmlDocument = smw.getDocument();
- if (xmlDocument == null) return null;
-
- Utils.findNodeForOffset(xmlDocument, superRegion.getOffset());
-
- IHyperlinkRegion r = getRegion(document, superRegion.getOffset());
- if (r == null) return null;
+ IHyperlinkRegion r = getRegion(document, superRegion.getOffset());
+ if (r == null) return null;
- String axis = getAxis(document, superRegion);
- String contentType = superRegion.getContentType();
- String type = getPartitionType();
- int length = r.getLength() - (superRegion.getOffset() - r.getOffset());
- int offset = superRegion.getOffset();
-
- IHyperlinkRegion region = new HyperlinkRegion(offset, length, axis, contentType,
type);
- return region;
- } finally {
- smw.dispose();
- }
+ String axis = getAxis(document, superRegion);
+ String contentType = superRegion.getContentType();
+ String type = getPartitionType();
+ int length = r.getLength() - (superRegion.getOffset() - r.getOffset());
+ int offset = superRegion.getOffset();
+
+ IHyperlinkRegion region = new HyperlinkRegion(offset, length, axis, contentType,
type);
+ return region;
}
protected String getAxis(IDocument document, IHyperlinkRegion superRegion) {
@@ -70,81 +59,45 @@
return superRegion.getAxis();
}
-
private IHyperlinkRegion getRegion(IDocument document, final int offset) {
+ ELExpression expression = getExpression(document, offset);
+ if(expression != null){
+ IHyperlinkRegion region = new HyperlinkRegion(expression.getStartPosition(),
expression.getLength(), null, null, null);
+ return region;
+ }
+ return null;
+ }
+
+ public static ELExpression getExpression(IDocument document, final int offset){
StructuredModelWrapper smw = new StructuredModelWrapper();
smw.init(document);
try {
- Document xmlDocument = smw.getDocument();
- if (xmlDocument == null) return null;
-
- Node n = Utils.findNodeForOffset(xmlDocument, offset);
-
- if (n == null || !(n instanceof IDOMAttr || n instanceof IDOMText)) return null;
-
- int valStart = Utils.getValueStart(n);
- int valEnd = Utils.getValueEnd(n);
- if(valStart < 0 || valStart > offset) return null;
-
- String valText = (n instanceof IDOMAttr)?
- ((IDOMAttr)n).getValueRegionText():
- ((IDOMText)n).getData();
- if (valText == null)
- return null;
-
- int startBracket = 0;
- int exprStart = 0;
- int exprLength = 0;
- while (startBracket != -1) {
- int v = valText.indexOf("#{", startBracket + exprLength); //$NON-NLS-1$
- if (v == -1) v = valText.indexOf("${", startBracket + exprLength);
//$NON-NLS-1$
- if (v == -1) return null;
- startBracket = v;
-
- int endBracket = valText.indexOf("}", startBracket + 2); //$NON-NLS-1$
- exprStart = valStart + startBracket + 2;
- int exprEnd = (endBracket == -1 ? valEnd - 1: valStart + endBracket);
- int lineBreaker = valText.indexOf('\n', startBracket + 2);
- int lineBreaker1 = valText.indexOf('\r', startBracket + 2);
- if (lineBreaker != -1 && lineBreaker + valStart < exprEnd) exprEnd =
valStart + lineBreaker;
- if (lineBreaker1 != -1 && lineBreaker1 + valStart < exprEnd) exprEnd =
valStart + lineBreaker1;
- exprLength = exprEnd - exprStart;
+ IFile file = smw.getFile();
+ ELContext context = PageContextFactory.getInstance().createPageContext(file);
+ if(context != null){
- if(exprLength<=0) {
- return null;
- } else if (exprStart <= offset && exprEnd >= offset) {
- int start = exprStart;
- int length = exprLength;
-
- IHyperlinkRegion region = new HyperlinkRegion(start, length, null, null, null);
- return region;
+ ELReference[] references = context.getELReferences();
+
+ for(ELReference reference : references){
+ for(ELExpression expression : reference.getEl()){
+ if (reference.getStartPosition()+expression.getStartPosition() <= offset
&& reference.getStartPosition()+expression.getEndPosition() >= offset)
+ return expression;
+ }
}
}
return null;
} finally {
smw.dispose();
}
-
}
-
/**
* @see
com.ibm.sse.editor.extensions.hyperlink.IHyperlinkPartitionRecognizer#recognize(org.eclipse.jface.text.IDocument,
com.ibm.sse.editor.extensions.hyperlink.IHyperlinkRegion)
*/
public boolean recognize(IDocument document, IHyperlinkRegion region) {
if(document == null || region == null) return false;
- StructuredModelWrapper smw = new StructuredModelWrapper();
- smw.init(document);
- try {
- Document xmlDocument = smw.getDocument();
- if (xmlDocument == null) return false;
-
- Utils.findNodeForOffset(xmlDocument, region.getOffset());
-
- return (getRegion(document, region.getOffset()) != null);
- } finally {
- smw.dispose();
- }
+
+ return (getRegion(document, region.getOffset()) != null);
}
public boolean excludes(String partitionType, IDocument document, IHyperlinkRegion
superRegion) {