Author: dazarov
Date: 2009-12-23 12:01:43 -0500 (Wed, 23 Dec 2009)
New Revision: 19562
Added:
trunk/jsf/plugins/org.jboss.tools.jsf.text.ext/src/org/jboss/tools/jsf/text/ext/hyperlink/ExpressionHyperlink.java
Removed:
trunk/jsf/plugins/org.jboss.tools.jsf.text.ext/src/org/jboss/tools/jsf/text/ext/hyperlink/JSPExprHyperlink.java
Modified:
trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/core/resolver/ELResolutionImpl.java
trunk/jsf/plugins/org.jboss.tools.jsf.text.ext/META-INF/MANIFEST.MF
trunk/jsf/plugins/org.jboss.tools.jsf.text.ext/plugin.xml
trunk/jsf/plugins/org.jboss.tools.jsf.text.ext/src/org/jboss/tools/jsf/text/ext/JSFTextExtMessages.java
trunk/jsf/plugins/org.jboss.tools.jsf.text.ext/src/org/jboss/tools/jsf/text/ext/JSFTextExtMessages.properties
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
Modified:
trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/core/resolver/ELResolutionImpl.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/core/resolver/ELResolutionImpl.java 2009-12-23
16:56:39 UTC (rev 19561)
+++
trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/core/resolver/ELResolutionImpl.java 2009-12-23
17:01:43 UTC (rev 19562)
@@ -76,7 +76,9 @@
*/
public ELSegment findSegmentByOffset(int offset) {
for(ELSegment segment : segments){
- if(segment.getSourceReference() != null &&
segment.getSourceReference().getStartPosition() == offset)
+ if(segment.getSourceReference() != null &&
+ segment.getSourceReference().getStartPosition() <= offset &&
+ segment.getSourceReference().getStartPosition()+segment.getSourceReference().getLength()
>= offset)
return segment;
}
return null;
Modified: trunk/jsf/plugins/org.jboss.tools.jsf.text.ext/META-INF/MANIFEST.MF
===================================================================
--- trunk/jsf/plugins/org.jboss.tools.jsf.text.ext/META-INF/MANIFEST.MF 2009-12-23
16:56:39 UTC (rev 19561)
+++ trunk/jsf/plugins/org.jboss.tools.jsf.text.ext/META-INF/MANIFEST.MF 2009-12-23
17:01:43 UTC (rev 19562)
@@ -12,7 +12,8 @@
org.jboss.tools.common.text.ext,
org.jboss.tools.jst.text.ext,
org.jboss.tools.jsf,
- org.jboss.tools.common.el.core
+ org.jboss.tools.common.el.core,
+ org.eclipse.jdt.ui;bundle-version="3.5.0"
Export-Package: org.jboss.tools.jsf.text.ext,
org.jboss.tools.jsf.text.ext.hyperlink
Bundle-Version: 2.0.0
Modified: trunk/jsf/plugins/org.jboss.tools.jsf.text.ext/plugin.xml
===================================================================
--- trunk/jsf/plugins/org.jboss.tools.jsf.text.ext/plugin.xml 2009-12-23 16:56:39 UTC (rev
19561)
+++ trunk/jsf/plugins/org.jboss.tools.jsf.text.ext/plugin.xml 2009-12-23 17:01:43 UTC (rev
19562)
@@ -1019,6 +1019,41 @@
<partitiontype id="org.jboss.tools.common.text.ext.jsp.JSF_JSP_TAG_NAME"
/>
</contenttypeidentifier>
</hyperlink>
+
+ <hyperlink
+ class="org.jboss.tools.jsf.text.ext.hyperlink.ExpressionHyperlink"
+ id="org.jboss.tools.jsf.text.ext.hyperlink.ExpressionHyperlink">
+ <contenttypeidentifier id="org.eclipse.jst.jsp.core.jspsource">
+ <partitiontype id="org.jboss.tools.common.text.ext.jsp.EXPRESSION"
/>
+ </contenttypeidentifier>
+ <contenttypeidentifier id="org.eclipse.wst.html.core.htmlsource">
+ <partitiontype id="org.jboss.tools.common.text.ext.jsp.EXPRESSION"
/>
+ </contenttypeidentifier>
+ <contenttypeidentifier id="org.eclipse.core.runtime.xml">
+ <partitiontype id="org.jboss.tools.common.text.ext.jsp.EXPRESSION"
/>
+ </contenttypeidentifier>
+ <contenttypeidentifier id="org.jboss.tools.common.model.ui.xml">
+ <partitiontype id="org.jboss.tools.common.text.ext.jsp.EXPRESSION"
/>
+ </contenttypeidentifier>
+ <contenttypeidentifier
id="org.jboss.tools.seam.xml.ui.pages12xmlsource">
+ <partitiontype id="org.jboss.tools.common.text.ext.jsp.EXPRESSION"
/>
+ </contenttypeidentifier>
+ <contenttypeidentifier
id="org.jboss.tools.seam.xml.ui.page12xmlsource">
+ <partitiontype id="org.jboss.tools.common.text.ext.jsp.EXPRESSION"
/>
+ </contenttypeidentifier>
+ <contenttypeidentifier
id="org.jboss.tools.seam.xml.ui.pages20xmlsource">
+ <partitiontype id="org.jboss.tools.common.text.ext.jsp.EXPRESSION"
/>
+ </contenttypeidentifier>
+ <contenttypeidentifier
id="org.jboss.tools.seam.xml.ui.page20xmlsource">
+ <partitiontype id="org.jboss.tools.common.text.ext.jsp.EXPRESSION"
/>
+ </contenttypeidentifier>
+ <contenttypeidentifier
id="org.jboss.tools.seam.xml.ui.pages21xmlsource">
+ <partitiontype id="org.jboss.tools.common.text.ext.jsp.EXPRESSION"
/>
+ </contenttypeidentifier>
+ <contenttypeidentifier
id="org.jboss.tools.seam.xml.ui.page21xmlsource">
+ <partitiontype id="org.jboss.tools.common.text.ext.jsp.EXPRESSION"
/>
+ </contenttypeidentifier>
+ </hyperlink>
</extension>
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf.text.ext/src/org/jboss/tools/jsf/text/ext/JSFTextExtMessages.java
===================================================================
---
trunk/jsf/plugins/org.jboss.tools.jsf.text.ext/src/org/jboss/tools/jsf/text/ext/JSFTextExtMessages.java 2009-12-23
16:56:39 UTC (rev 19561)
+++
trunk/jsf/plugins/org.jboss.tools.jsf.text.ext/src/org/jboss/tools/jsf/text/ext/JSFTextExtMessages.java 2009-12-23
17:01:43 UTC (rev 19562)
@@ -40,4 +40,5 @@
public static String OpenRenderKit;
public static String Validator;
public static String OpenValidatorForId;
+ public static String OpenJavaElement;
}
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf.text.ext/src/org/jboss/tools/jsf/text/ext/JSFTextExtMessages.properties
===================================================================
---
trunk/jsf/plugins/org.jboss.tools.jsf.text.ext/src/org/jboss/tools/jsf/text/ext/JSFTextExtMessages.properties 2009-12-23
16:56:39 UTC (rev 19561)
+++
trunk/jsf/plugins/org.jboss.tools.jsf.text.ext/src/org/jboss/tools/jsf/text/ext/JSFTextExtMessages.properties 2009-12-23
17:01:43 UTC (rev 19562)
@@ -23,3 +23,4 @@
OpenRenderKit=Open Render Kit ''{0}''
Validator=validator
OpenValidatorForId=Open a validator for ID ''{1}''
+OpenJavaElement=Open Java Element
Copied:
trunk/jsf/plugins/org.jboss.tools.jsf.text.ext/src/org/jboss/tools/jsf/text/ext/hyperlink/ExpressionHyperlink.java
(from rev 19486,
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/ExpressionHyperlink.java
(rev 0)
+++
trunk/jsf/plugins/org.jboss.tools.jsf.text.ext/src/org/jboss/tools/jsf/text/ext/hyperlink/ExpressionHyperlink.java 2009-12-23
17:01:43 UTC (rev 19562)
@@ -0,0 +1,79 @@
+/*******************************************************************************
+ * 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.ui.JavaUI;
+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.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.hyperlink.AbstractHyperlink;
+import org.jboss.tools.jsf.text.ext.JSFTextExtMessages;
+import
org.jboss.tools.jsf.text.ext.hyperlink.JSPExprHyperlinkPartitioner.ExpressionStructure;
+
+/**
+ * @author Daniel
+ */
+public class ExpressionHyperlink extends AbstractHyperlink{
+ private JavaMemberELSegment javaSegment=null;
+
+ protected IRegion doGetHyperlinkRegion(int offset) {
+ javaSegment = null;
+ ELContext context = JSPExprHyperlinkPartitioner.getELContext(getDocument());
+ ExpressionStructure eStructure = JSPExprHyperlinkPartitioner.getExpression(context,
offset);
+ ELInvocationExpression invocationExpression =
JSPExprHyperlinkPartitioner.getInvocationExpression(eStructure.reference,
eStructure.expression, offset);
+ if(invocationExpression != null){
+ for(ELResolver resolver : context.getElResolvers()){
+ ELResolution resolution = resolver.resolve(context, eStructure.expression,
invocationExpression.getStartPosition());
+ ELSegment segment =
resolution.findSegmentByOffset(offset-eStructure.reference.getStartPosition());
+ if(segment != null){
+ if(segment instanceof JavaMemberELSegment){
+ javaSegment = (JavaMemberELSegment)segment;
+ if(javaSegment.getJavaElement() != null){
+ Region region = new
Region(eStructure.reference.getStartPosition()+segment.getSourceReference().getStartPosition(),
segment.getSourceReference().getLength());
+
+ return region;
+ }
+ }
+ }
+ }
+ }
+ return null;
+ }
+
+ protected void doHyperlink(IRegion region) {
+ IEditorPart part = null;
+
+ if(javaSegment != null){
+ IResource resource = javaSegment.getJavaElement().getResource();
+ if(resource != null && resource instanceof IFile)
+ part = openFileInEditor((IFile)javaSegment.getJavaElement().getResource());
+ if (part != null) {
+ if (javaSegment.getJavaElement() != null)
+ JavaUI.revealInEditor(part, javaSegment.getJavaElement());
+ }
+ }
+ if (part == null)
+ openFileFailed();
+ }
+
+ public String getHyperlinkText() {
+ return JSFTextExtMessages.OpenJavaElement;
+ }
+
+}
Property changes on:
trunk/jsf/plugins/org.jboss.tools.jsf.text.ext/src/org/jboss/tools/jsf/text/ext/hyperlink/ExpressionHyperlink.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Deleted:
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 2009-12-23
16:56:39 UTC (rev 19561)
+++
trunk/jsf/plugins/org.jboss.tools.jsf.text.ext/src/org/jboss/tools/jsf/text/ext/hyperlink/JSPExprHyperlink.java 2009-12-23
17:01:43 UTC (rev 19562)
@@ -1,106 +0,0 @@
-/*******************************************************************************
- * 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;
- }
-
-}
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-23
16:56:39 UTC (rev 19561)
+++
trunk/jsf/plugins/org.jboss.tools.jsf.text.ext/src/org/jboss/tools/jsf/text/ext/hyperlink/JSPExprHyperlinkPartitioner.java 2009-12-23
17:01:43 UTC (rev 19562)
@@ -11,16 +11,24 @@
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.IDocument;
import org.jboss.tools.common.el.core.ELReference;
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.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.jsf.text.ext.JSFExtensionsPlugin;
import org.jboss.tools.jst.text.ext.hyperlink.jsp.JSPRootHyperlinkPartitioner;
import org.jboss.tools.jst.web.kb.PageContextFactory;
@@ -30,9 +38,15 @@
@SuppressWarnings("restriction")
public class JSPExprHyperlinkPartitioner extends AbstractHyperlinkPartitioner implements
IHyperlinkPartitionRecognizer, IExclusiblePartitionerRecognition {
public static final String JSP_EXPRESSION_PARTITION =
"org.jboss.tools.common.text.ext.jsp.JSP_EXPRESSION"; //$NON-NLS-1$
+ public static final String EXPRESSION_PARTITION =
"org.jboss.tools.common.text.ext.jsp.EXPRESSION"; //$NON-NLS-1$
+
+ private boolean jspExpression = false;
protected String getPartitionType() {
- return JSP_EXPRESSION_PARTITION;
+ if(jspExpression)
+ return EXPRESSION_PARTITION;
+ else
+ return JSP_EXPRESSION_PARTITION;
}
/**
@@ -60,35 +74,76 @@
}
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;
+ jspExpression = false;
+ ELContext context = getELContext(document);
+ if(context != null){
+ ExpressionStructure eStructure = getExpression(context, offset);
+ if(eStructure != null){
+ ELInvocationExpression invocationExpression =
getInvocationExpression(eStructure.reference, eStructure.expression, offset);
+ if(invocationExpression != null){
+ jspExpression = decide(context, eStructure.expression, invocationExpression,
offset-eStructure.reference.getStartPosition());
+ if(jspExpression){
+ IHyperlinkRegion region = new
HyperlinkRegion(invocationExpression.getStartPosition(), invocationExpression.getLength(),
null, null, null);
+ return region;
+ }
+ }
+ IHyperlinkRegion region = new
HyperlinkRegion(eStructure.expression.getStartPosition(),
eStructure.expression.getLength(), null, null, null);
+ return region;
+ }
}
return null;
}
- public static ELExpression getExpression(IDocument document, final int offset){
+ public static ExpressionStructure getExpression(ELContext context, final int offset){
+ 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 new ExpressionStructure(reference, expression);
+ }
+ }
+ return null;
+ }
+
+ public static ELContext getELContext(IDocument document){
StructuredModelWrapper smw = new StructuredModelWrapper();
smw.init(document);
try {
IFile file = smw.getFile();
ELContext context = PageContextFactory.getInstance().createPageContext(file);
- if(context != null){
-
- 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 context;
+ } finally {
+ smw.dispose();
+ }
+ }
+
+ public static ELInvocationExpression getInvocationExpression(ELReference reference,
ELExpression expression, int offset){
+ if(expression == null || reference == null)
+ return null;
+
+ for(ELInvocationExpression ie : expression.getInvocations()){
+ if (reference.getStartPosition()+ie.getStartPosition() <= offset &&
reference.getStartPosition()+ie.getEndPosition() >= offset) {
+ return ie;
+ }
+ }
+ return null;
+ }
+
+ public boolean decide(ELContext context, ELExpression expression, ELInvocationExpression
invocationExpression, int offset){
+ for(ELResolver resolver : context.getElResolvers()){
+ ELResolution resolution = resolver.resolve(context, expression,
invocationExpression.getStartPosition());
+ ELSegment segment = resolution.findSegmentByOffset(offset);
+ if(segment != null){
+ if(segment instanceof JavaMemberELSegment){
+ JavaMemberELSegment javaSegment = (JavaMemberELSegment)segment;
+ if(javaSegment.getJavaElement() != null){
+ return true;
}
}
}
- return null;
- } finally {
- smw.dispose();
}
+ return false;
}
/**
@@ -107,5 +162,16 @@
public String getExclusionPartitionType() {
return getPartitionType();
}
+
+ public static class ExpressionStructure{
+ public ELReference reference;
+ public ELExpression expression;
+
+ public ExpressionStructure(ELReference reference, ELExpression expression){
+ this.reference = reference;
+ this.expression = expression;
+ }
+
+ }
}