Author: dazarov
Date: 2011-07-14 19:28:08 -0400 (Thu, 14 Jul 2011)
New Revision: 32928
Added:
trunk/jst/plugins/org.jboss.tools.jst.text.ext/src/org/jboss/tools/jst/text/ext/hyperlink/ELHyperlink.java
trunk/jst/plugins/org.jboss.tools.jst.text.ext/src/org/jboss/tools/jst/text/ext/hyperlink/ELHyperlinkDetector.java
trunk/jst/tests/org.jboss.tools.jst.text.ext.test/src/org/jboss/tools/jst/text/ext/test/HyperlinkTestUtil.java
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf.text.ext.facelets/plugin.xml
trunk/jsf/plugins/org.jboss.tools.jsf.text.ext/plugin.xml
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/model/JSFMessageELCompletionEngine.java
trunk/jst/plugins/org.jboss.tools.jst.text.ext/plugin.xml
trunk/jst/tests/org.jboss.tools.jst.text.ext.test/META-INF/MANIFEST.MF
trunk/seam/plugins/org.jboss.tools.seam.text.ext/plugin.xml
trunk/seam/tests/org.jboss.tools.seam.ui.test/META-INF/MANIFEST.MF
trunk/seam/tests/org.jboss.tools.seam.ui.test/src/org/jboss/tools/seam/ui/test/el/ELExprPartitionerTest.java
Log:
https://issues.jboss.org/browse/JBIDE-9307
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/model/JSFMessageELCompletionEngine.java
===================================================================
---
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/model/JSFMessageELCompletionEngine.java 2011-07-14
17:59:26 UTC (rev 32927)
+++
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/model/JSFMessageELCompletionEngine.java 2011-07-14
23:28:08 UTC (rev 32928)
@@ -490,7 +490,15 @@
XModelObject[] properties = keyHelper.findBundles(model, variable.basename, null);
if(properties == null)
return;
-
+
+ for (XModelObject p : properties) {
+ IFile propFile = (IFile)p.getAdapter(IFile.class);
+ if(propFile == null)
+ continue;
+ segment.setMessageBundleResource(propFile);
+
+ }
+
segment.setBaseName(variable.basename);
segment.setBundleOnlySegment(true);
}
Modified: trunk/jsf/plugins/org.jboss.tools.jsf.text.ext/plugin.xml
===================================================================
--- trunk/jsf/plugins/org.jboss.tools.jsf.text.ext/plugin.xml 2011-07-14 17:59:26 UTC (rev
32927)
+++ trunk/jsf/plugins/org.jboss.tools.jsf.text.ext/plugin.xml 2011-07-14 23:28:08 UTC (rev
32928)
@@ -797,7 +797,7 @@
</partitionType>
</contentType>
</hyperlinkPartitioner>
- <hyperlinkPartitioner
+ <!--hyperlinkPartitioner
id="org.jboss.tools.common.text.ext.jsf.hyperlink.JSPExprHyperlinkPartitioner"
class="org.jboss.tools.jsf.text.ext.hyperlink.JSPExprHyperlinkPartitioner">
<contentType id="org.eclipse.jst.jsp.core.jspsource">
@@ -840,7 +840,7 @@
<partitionType id="org.eclipse.jst.jsp.SCRIPT.JSP_EL" />
<partitionType id="org.eclipse.jst.jsp.SCRIPT.JSP_EL2" />
</contentType>
- </hyperlinkPartitioner>
+ </hyperlinkPartitioner-->
<hyperlinkPartitioner
id="org.jboss.tools.common.text.ext.jsf.hyperlink.JSPLoadBundleHyperlinkPartitioner"
@@ -872,13 +872,12 @@
</contentType>
</hyperlinkPartitioner>
- <hyperlinkPartitioner
+ <!--hyperlinkPartitioner
id="org.jboss.tools.common.text.ext.jsf.hyperlink.JSPBundleHyperlinkPartitioner"
class="org.jboss.tools.jsf.text.ext.hyperlink.JSPBundleHyperlinkPartitioner">
<contentType id="org.eclipse.jst.jsp.core.jspsource">
<partitionType
id="org.jboss.tools.common.text.ext.jsp.JSP_EXPRESSION" />
</contentType>
- <!-- these CTs were copied from the JsfJSPBundleHyperlinkPartitioner -->
<contentType id="org.eclipse.wst.html.core.htmlsource">
<partitionType
id="org.jboss.tools.common.text.ext.jsp.JSP_EXPRESSION" />
</contentType>
@@ -891,7 +890,7 @@
<contentType id="org.jboss.tools.jst.jsp.jspincludesource">
<partitionType
id="org.jboss.tools.common.text.ext.jsp.JSP_EXPRESSION" />
</contentType>
- </hyperlinkPartitioner>
+ </hyperlinkPartitioner-->
<!-- hyperlinkPartitioner
id="org.jboss.tools.common.text.ext.jsf.hyperlink.JsfJSPBundleHyperlinkPartitioner"
class="org.jboss.tools.jsf.text.ext.hyperlink.JsfJSPBundleHyperlinkPartitioner">
@@ -906,13 +905,12 @@
</contentType>
</hyperlinkPartitioner -->
- <hyperlinkPartitioner
+ <!--hyperlinkPartitioner
id="org.jboss.tools.jsf.text.ext.hyperlink.JSF2CCAttrsOpenOnPartitioner"
class="org.jboss.tools.jsf.text.ext.hyperlink.JSF2CCAttrsHyperlinkPartitioner">
<contentType id="org.eclipse.jst.jsp.core.jspsource">
<partitionType
id="org.jboss.tools.common.text.ext.jsp.JSP_EXPRESSION" />
</contentType>
- <!-- these CTs were copied from the JsfJSPBundleHyperlinkPartitioner -->
<contentType id="org.eclipse.wst.html.core.htmlsource">
<partitionType
id="org.jboss.tools.common.text.ext.jsp.JSP_EXPRESSION" />
</contentType>
@@ -925,7 +923,7 @@
<contentType id="org.jboss.tools.jst.jsp.jspincludesource">
<partitionType
id="org.jboss.tools.common.text.ext.jsp.JSP_EXPRESSION" />
</contentType>
- </hyperlinkPartitioner>
+ </hyperlinkPartitioner-->
<hyperlinkPartitioner
id="org.jboss.tools.common.text.ext.jsf.hyperlink.JSPClassHyperlinkPartitioner"
@@ -1221,7 +1219,7 @@
</contenttypeidentifier>
</hyperlink>
- <hyperlink
+ <!--hyperlink
class="org.jboss.tools.jsf.text.ext.hyperlink.BundleHyperlink"
id="org.jboss.tools.common.text.ext.jsf.hyperlink.BundleHyperlink">
<contenttypeidentifier id="org.eclipse.jst.jsp.core.jspsource">
@@ -1239,9 +1237,9 @@
<contenttypeidentifier id="org.jboss.tools.jst.jsp.jspincludesource">
<partitiontype
id="org.jboss.tools.common.text.ext.jsp.JSP_BUNDLE" />
</contenttypeidentifier>
- </hyperlink>
+ </hyperlink-->
- <hyperlink
+ <!--hyperlink
class="org.jboss.tools.jsf.text.ext.hyperlink.JSF2CCAttrsHyperlink"
id="org.jboss.tools.jsf.text.ext.hyperlink.JSF2CCAttrsHyperlink">
<contenttypeidentifier id="org.eclipse.jst.jsp.core.jspsource">
@@ -1259,7 +1257,7 @@
<contenttypeidentifier id="org.jboss.tools.jst.jsp.jspincludesource">
<partitiontype
id="org.jboss.tools.common.text.ext.jsp.JSF2_CC_ATTRIBUTE" />
</contenttypeidentifier>
- </hyperlink>
+ </hyperlink-->
<!-- hyperlink
class="org.jboss.tools.jsf.text.ext.hyperlink.JsfBundleHyperlink"
@@ -1556,7 +1554,7 @@
</contenttypeidentifier>
</hyperlink>
- <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">
@@ -1598,7 +1596,7 @@
<contenttypeidentifier
id="org.jboss.tools.seam.xml.ui.page21xmlsource">
<partitiontype id="org.jboss.tools.common.text.ext.jsp.EXPRESSION"
/>
</contenttypeidentifier>
- </hyperlink>
+ </hyperlink-->
</extension>
Modified: trunk/jsf/plugins/org.jboss.tools.jsf.text.ext.facelets/plugin.xml
===================================================================
--- trunk/jsf/plugins/org.jboss.tools.jsf.text.ext.facelets/plugin.xml 2011-07-14 17:59:26
UTC (rev 32927)
+++ trunk/jsf/plugins/org.jboss.tools.jsf.text.ext.facelets/plugin.xml 2011-07-14 23:28:08
UTC (rev 32928)
@@ -7,7 +7,7 @@
id="org.jboss.tools.common.text.ext.jsf.facelets.hyperlinkPartitioner"
name="org.jboss.tools.common.text.ext.jsf.facelets.hyperlinkPartitioner">
- <hyperlinkPartitioner
+ <!--hyperlinkPartitioner
id="org.jboss.tools.common.text.ext.jsf.facelets.hyperlink.FaceletsExprHyperlinkPartitioner"
class="org.jboss.tools.jsf.text.ext.hyperlink.JSPExprHyperlinkPartitioner">
<contentType id="org.eclipse.jst.jsp.core.jspsource">
@@ -25,9 +25,9 @@
<contentType id="org.jboss.tools.jst.jsp.jspincludesource">
<partitionType id="org.jboss.tools.common.text.ext.jsp.JSP_ROOT"
/>
</contentType>
- </hyperlinkPartitioner>
+ </hyperlinkPartitioner-->
- <hyperlinkPartitioner
+ <!--hyperlinkPartitioner
id="org.jboss.tools.common.text.ext.jsf.facelets.hyperlink.ExprHyperlinkPartitioner"
class="org.jboss.tools.jsf.text.ext.hyperlink.JSPExprHyperlinkPartitioner">
<contentType id="org.eclipse.jst.jsp.core.jspsource">
@@ -45,7 +45,7 @@
<contentType id="org.jboss.tools.jst.jsp.jspincludesource">
<partitionType
id="org.jboss.tools.common.text.ext.jsp.FACELETS_ATTRIBUTE_VALUE_WITH_EXPR"
/>
</contentType>
- </hyperlinkPartitioner>
+ </hyperlinkPartitioner-->
<hyperlinkPartitioner
id="org.jboss.tools.common.text.ext.jsf.facelets.hyperlink.FaceletsTemplateHyperlinkPartitioner"
Modified: trunk/jst/plugins/org.jboss.tools.jst.text.ext/plugin.xml
===================================================================
--- trunk/jst/plugins/org.jboss.tools.jst.text.ext/plugin.xml 2011-07-14 17:59:26 UTC (rev
32927)
+++ trunk/jst/plugins/org.jboss.tools.jst.text.ext/plugin.xml 2011-07-14 23:28:08 UTC (rev
32928)
@@ -614,5 +614,15 @@
<!-- JSP -->
</extension>
+ <extension
+ point="org.eclipse.ui.workbench.texteditor.hyperlinkDetectors">
+ <hyperlinkDetector
+ activate="true"
+ class="org.jboss.tools.jst.text.ext.hyperlink.ELHyperlinkDetector"
+ id="org.jboss.tools.jst.text.ext.hyperlink.ELHyperlinkDetector"
+ name="EL Hyperlink Detector"
+ targetId="org.eclipse.ui.DefaultTextEditor">
+ </hyperlinkDetector>
+ </extension>
</plugin>
Added:
trunk/jst/plugins/org.jboss.tools.jst.text.ext/src/org/jboss/tools/jst/text/ext/hyperlink/ELHyperlink.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.text.ext/src/org/jboss/tools/jst/text/ext/hyperlink/ELHyperlink.java
(rev 0)
+++
trunk/jst/plugins/org.jboss.tools.jst.text.ext/src/org/jboss/tools/jst/text/ext/hyperlink/ELHyperlink.java 2011-07-14
23:28:08 UTC (rev 32928)
@@ -0,0 +1,231 @@
+/*******************************************************************************
+ * 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:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.jst.text.ext.hyperlink;
+
+import java.text.MessageFormat;
+import java.util.List;
+import java.util.Properties;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.jdt.core.IField;
+import org.eclipse.jdt.core.IJavaElement;
+import org.eclipse.jdt.core.IMethod;
+import org.eclipse.jdt.core.IType;
+import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.jdt.ui.JavaUI;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.IRegion;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.PartInitException;
+import org.jboss.tools.common.el.core.ELReference;
+import org.jboss.tools.common.el.core.resolver.ELSegment;
+import org.jboss.tools.common.el.core.resolver.JavaMemberELSegment;
+import org.jboss.tools.common.el.core.resolver.MessagePropertyELSegment;
+import org.jboss.tools.common.model.XModel;
+import org.jboss.tools.common.model.project.IPromptingProvider;
+import org.jboss.tools.common.model.project.PromptingProviderFactory;
+import org.jboss.tools.common.text.ext.hyperlink.AbstractHyperlink;
+import org.jboss.tools.common.text.ext.hyperlink.xpl.Messages;
+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.JSTExtensionsPlugin;
+import org.jboss.tools.jst.web.project.list.WebPromptingProvider;
+import org.w3c.dom.Attr;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+
+public class ELHyperlink extends AbstractHyperlink{
+ private static final String VIEW_TAGNAME = "view"; //$NON-NLS-1$
+ private static final String LOCALE_ATTRNAME = "locale"; //$NON-NLS-1$
+ private static final String PREFIX_SEPARATOR = ":"; //$NON-NLS-1$
+
+ private ELReference reference;
+ private ELSegment segment;
+
+ public ELHyperlink(IDocument document, ELReference reference, ELSegment segment){
+ this.reference = reference;
+ this.segment = segment;
+ setDocument(document);
+ }
+
+ @Override
+ protected IRegion doGetHyperlinkRegion(int offset) {
+
+ return new IRegion(){
+ public int getLength() {
+ return segment.getSourceReference().getLength();
+ }
+
+ public int getOffset() {
+ return reference.getStartPosition()+segment.getSourceReference().getStartPosition();
+ }};
+ }
+
+ @Override
+ protected void doHyperlink(IRegion region) {
+ if(segment instanceof JavaMemberELSegment){
+ try {
+ IEditorPart part = JavaUI.openInEditor(((JavaMemberELSegment)
segment).getJavaElement());
+ if(part == null)
+ openFileFailed();
+ } catch (PartInitException e) {
+ JSTExtensionsPlugin.getDefault().logError(e);
+ } catch (JavaModelException e) {
+ JSTExtensionsPlugin.getDefault().logError(e);
+ }
+ }else if(segment instanceof MessagePropertyELSegment){
+ IFile file = (IFile)((MessagePropertyELSegment)segment).getMessageBundleResource();
+ if(file == null)
+ file = (IFile)segment.getResource();
+
+ XModel xModel = getXModel(file);
+ if (xModel == null) {
+ openFileFailed();
+ return;
+ }
+ String bundleBasename = ((MessagePropertyELSegment)segment).getBaseName();
+ String property = ((MessagePropertyELSegment)segment).isBundle() ? null :
trimQuotes(((MessagePropertyELSegment)segment).getToken().getText());
+ String locale = getPageLocale(region);
+
+ Properties p = new Properties();
+ if (bundleBasename != null) {
+ p.put(WebPromptingProvider.BUNDLE, bundleBasename);
+ }
+
+ if (property != null) {
+ p.put(WebPromptingProvider.KEY, property);
+ }
+
+ if (locale != null) {
+ p.setProperty(WebPromptingProvider.LOCALE, locale);
+ }
+
+ IPromptingProvider provider = PromptingProviderFactory.WEB;
+
+ p.put(IPromptingProvider.FILE, file);
+
+ List list = provider.getList(xModel, getRequestMethod(p),
p.getProperty("prefix"), p); //$NON-NLS-1$
+ if (list != null && list.size() >= 1) {
+ openFileInEditor((String)list.get(0));
+ return;
+ }
+ String error = p.getProperty(IPromptingProvider.ERROR);
+ if ( error != null && error.length() > 0) {
+ openFileFailed();
+ }
+ }else
+ openFileFailed();
+ }
+
+ private String getPageLocale(IRegion region) {
+ if(getDocument() == null || region == null) return null;
+
+ StructuredModelWrapper smw = new StructuredModelWrapper();
+ try {
+ smw.init(getDocument());
+ Document xmlDocument = smw.getDocument();
+ if (xmlDocument == null) return null;
+
+ Node n = Utils.findNodeForOffset(xmlDocument, region.getOffset());
+ if (!(n instanceof Attr) ) return null;
+
+ Element el = ((Attr)n).getOwnerElement();
+
+ Element jsfCoreViewTag = null;
+ String nodeToFind = PREFIX_SEPARATOR + VIEW_TAGNAME;
+
+ while (el != null) {
+ if (el.getNodeName() != null && el.getNodeName().endsWith(nodeToFind)) {
+ jsfCoreViewTag = el;
+ break;
+ }
+ Node parent = el.getParentNode();
+ el = (parent instanceof Element ? (Element)parent : null);
+ }
+
+ if (jsfCoreViewTag == null || !jsfCoreViewTag.hasAttribute(LOCALE_ATTRNAME)) return
null;
+
+ String locale =
Utils.trimQuotes((jsfCoreViewTag.getAttributeNode(LOCALE_ATTRNAME)).getValue());
+ if (locale == null || locale.length() == 0) return null;
+ return locale;
+ } finally {
+ smw.dispose();
+ }
+ }
+
+ private String trimQuotes(String value) {
+ if(value == null)
+ return null;
+
+ if(value.startsWith("'") || value.startsWith("\"")) {
//$NON-NLS-1$ //$NON-NLS-2$
+ value = value.substring(1);
+ }
+
+ if(value.endsWith("'") || value.endsWith("\"")) {
//$NON-NLS-1$ //$NON-NLS-2$
+ value = value.substring(0, value.length() - 1);
+ }
+ return value;
+ }
+
+ private String getRequestMethod(Properties prop) {
+ return prop != null && prop.getProperty(WebPromptingProvider.KEY) == null ?
+ WebPromptingProvider.JSF_OPEN_BUNDLE : WebPromptingProvider.JSF_OPEN_KEY;
+ }
+
+ @Override
+ public String getHyperlinkText() {
+ if(segment instanceof JavaMemberELSegment){
+ IJavaElement javaElement = ((JavaMemberELSegment) segment).getJavaElement();
+ String name = ""; //$NON-NLS-1$
+ IType type = null;
+ if(javaElement instanceof IType){
+ name = javaElement.getElementName();
+ type = (IType)javaElement;
+
+ }else if(javaElement instanceof IMethod){
+ type = ((IMethod) javaElement).getDeclaringType();
+ name =
type.getElementName()+"."+javaElement.getElementName()+"()";
//$NON-NLS-1$ //$NON-NLS-2$
+ }else if(javaElement instanceof IField){
+ type = ((IField) javaElement).getDeclaringType();
+ name = type.getElementName()+"."+javaElement.getElementName();
//$NON-NLS-1$
+ }
+ if(type != null)
+ name += " - "+type.getPackageFragment().getElementName(); //$NON-NLS-1$
+ return MessageFormat.format(Messages.Open, name);
+ }else if(segment instanceof MessagePropertyELSegment){
+ String baseName = ((MessagePropertyELSegment)segment).getBaseName();
+ String propertyName = ((MessagePropertyELSegment)segment).isBundle() ? null :
trimQuotes(((MessagePropertyELSegment)segment).getToken().getText());
+ if (propertyName == null)
+ return MessageFormat.format(Messages.Open, baseName);
+
+ return MessageFormat.format(Messages.OpenBundleProperty, propertyName, baseName);
+ }
+ return ""; //$NON-NLS-1$
+ }
+
+ @Override
+ public IFile getReadyToOpenFile() {
+ IFile file = null;
+ if(segment instanceof JavaMemberELSegment){
+
+ try {
+ file = (IFile)((JavaMemberELSegment)
segment).getJavaElement().getUnderlyingResource();
+ } catch (JavaModelException e) {
+ JSTExtensionsPlugin.getDefault().logError(e);
+ }
+ }else if(segment instanceof MessagePropertyELSegment){
+ file = (IFile)((MessagePropertyELSegment)segment).getMessageBundleResource();
+ }
+ return file;
+ }
+
+}
Property changes on:
trunk/jst/plugins/org.jboss.tools.jst.text.ext/src/org/jboss/tools/jst/text/ext/hyperlink/ELHyperlink.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added:
trunk/jst/plugins/org.jboss.tools.jst.text.ext/src/org/jboss/tools/jst/text/ext/hyperlink/ELHyperlinkDetector.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.text.ext/src/org/jboss/tools/jst/text/ext/hyperlink/ELHyperlinkDetector.java
(rev 0)
+++
trunk/jst/plugins/org.jboss.tools.jst.text.ext/src/org/jboss/tools/jst/text/ext/hyperlink/ELHyperlinkDetector.java 2011-07-14
23:28:08 UTC (rev 32928)
@@ -0,0 +1,97 @@
+/*******************************************************************************
+ * 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:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.jst.text.ext.hyperlink;
+
+import java.util.List;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.jface.text.IRegion;
+import org.eclipse.jface.text.ITextViewer;
+import org.eclipse.jface.text.hyperlink.AbstractHyperlinkDetector;
+import org.eclipse.jface.text.hyperlink.IHyperlink;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.part.FileEditorInput;
+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.jst.web.kb.PageContextFactory;
+
+public class ELHyperlinkDetector extends AbstractHyperlinkDetector{
+
+ public IHyperlink[] detectHyperlinks(ITextViewer textViewer,
+ IRegion region, boolean canShowMultipleHyperlinks) {
+
+ IFile file = getFile();
+ if(file == null)
+ return null;
+
+ ELContext context = PageContextFactory.createPageContext(file);
+ if(context == null)
+ return null;
+
+ ELReference reference = context.getELReference(region.getOffset());
+ if(reference != null){
+ ELInvocationExpression expression = findInvocationExpressionByOffset(reference,
region.getOffset());
+ if(expression != null){
+ ELResolver[] resolvers = context.getElResolvers();
+ for(ELResolver resolver : resolvers){
+ ELResolution resolution = resolver.resolve(context, expression,
region.getOffset());
+ if(resolution != null){
+ ELSegment segment =
resolution.findSegmentByOffset(region.getOffset()-reference.getStartPosition());
+
+ if(segment != null && segment.isResolved())
+ return new IHyperlink[]{new ELHyperlink(textViewer.getDocument(), reference,
segment)};
+
+ }
+ }
+ }
+
+ }
+ return null;
+ }
+
+ private ELInvocationExpression findInvocationExpressionByOffset(ELReference reference,
int offset){
+ ELExpression[] expressions = reference.getEl();
+ for(ELExpression expression : expressions){
+ if(reference.getStartPosition()+expression.getStartPosition() <= offset &&
reference.getStartPosition()+expression.getEndPosition() > offset){
+ ELInvocationExpression invocation = findInvocationExpressionByOffset(reference,
expression, offset);
+ if(invocation != null)
+ return invocation;
+ }
+ }
+ return null;
+ }
+
+ private ELInvocationExpression findInvocationExpressionByOffset(ELReference reference,
ELExpression expression, int offset){
+ List<ELInvocationExpression> invocations = expression.getInvocations();
+ for(ELInvocationExpression invocation : invocations){
+ if(reference.getStartPosition()+invocation.getStartPosition() <= offset &&
reference.getStartPosition()+invocation.getEndPosition() > offset)
+ return invocation;
+ }
+ return null;
+ }
+
+ private IFile getFile(){
+ IEditorPart part =
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
+ if(part != null){
+ IEditorInput input = part.getEditorInput();
+ if(input instanceof FileEditorInput)
+ return ((FileEditorInput)input).getFile();
+ }
+ return null;
+ }
+}
Property changes on:
trunk/jst/plugins/org.jboss.tools.jst.text.ext/src/org/jboss/tools/jst/text/ext/hyperlink/ELHyperlinkDetector.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Modified: trunk/jst/tests/org.jboss.tools.jst.text.ext.test/META-INF/MANIFEST.MF
===================================================================
--- trunk/jst/tests/org.jboss.tools.jst.text.ext.test/META-INF/MANIFEST.MF 2011-07-14
17:59:26 UTC (rev 32927)
+++ trunk/jst/tests/org.jboss.tools.jst.text.ext.test/META-INF/MANIFEST.MF 2011-07-14
23:28:08 UTC (rev 32928)
@@ -15,7 +15,10 @@
org.eclipse.jface.text,
org.jboss.tools.common.model.ui,
org.jboss.tools.jst.text.ext,
- org.eclipse.jst.standard.schemas
+ org.eclipse.jst.standard.schemas,
+ org.eclipse.jdt.ui;bundle-version="3.7.0",
+ org.eclipse.wst.xml.ui;bundle-version="1.1.200",
+ org.jboss.tools.jst.web.ui;bundle-version="3.3.0"
Export-Package: org.jboss.tools.jst.text.ext.test
Bundle-Vendor: %Bundle-Vendor.0
Bundle-Localization: plugin
Added:
trunk/jst/tests/org.jboss.tools.jst.text.ext.test/src/org/jboss/tools/jst/text/ext/test/HyperlinkTestUtil.java
===================================================================
---
trunk/jst/tests/org.jboss.tools.jst.text.ext.test/src/org/jboss/tools/jst/text/ext/test/HyperlinkTestUtil.java
(rev 0)
+++
trunk/jst/tests/org.jboss.tools.jst.text.ext.test/src/org/jboss/tools/jst/text/ext/test/HyperlinkTestUtil.java 2011-07-14
23:28:08 UTC (rev 32928)
@@ -0,0 +1,323 @@
+package org.jboss.tools.jst.text.ext.test;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import junit.framework.TestCase;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.jdt.internal.ui.javaeditor.JavaEditor;
+import org.eclipse.jdt.internal.ui.text.JavaWordFinder;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.IRegion;
+import org.eclipse.jface.text.Region;
+import org.eclipse.jface.text.hyperlink.AbstractHyperlinkDetector;
+import org.eclipse.jface.text.hyperlink.IHyperlink;
+import org.eclipse.jface.text.source.ISourceViewer;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.ide.IDE;
+import org.eclipse.ui.part.FileEditorInput;
+import org.eclipse.ui.texteditor.DocumentProviderRegistry;
+import org.eclipse.ui.texteditor.IDocumentProvider;
+import org.eclipse.ui.texteditor.ITextEditor;
+import org.eclipse.wst.sse.core.StructuredModelManager;
+import org.eclipse.wst.sse.core.internal.provisional.IModelManager;
+import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel;
+import org.jboss.tools.common.model.ui.editor.EditorPartWrapper;
+import org.jboss.tools.common.model.ui.texteditors.XMLTextEditorStandAlone;
+import org.jboss.tools.common.text.ext.hyperlink.AbstractHyperlink;
+import org.jboss.tools.common.text.ext.hyperlink.IHyperlinkRegion;
+import org.jboss.tools.common.text.ext.util.AxisUtil;
+import org.jboss.tools.jst.jsp.jspeditor.JSPMultiPageEditor;
+import org.jboss.tools.jst.web.ui.editors.WebCompoundEditor;
+
+public class HyperlinkTestUtil extends TestCase{
+
+ public static void checkRegions(IProject project, String fileName,
List<TestRegion> regionList, AbstractHyperlinkDetector elDetector) throws Exception
{
+ IFile file = project.getFile(fileName);
+
+ assertNotNull("The file \"" + fileName + "\" is not
found", file);
+ assertTrue("The file \"" + fileName + "\" is not found",
file.isAccessible());
+
+ FileEditorInput editorInput = new FileEditorInput(file);
+
+ IDocumentProvider documentProvider = null;
+ try {
+ documentProvider =
DocumentProviderRegistry.getDefault().getDocumentProvider(editorInput);
+ } catch (Exception x) {
+ x.printStackTrace();
+ fail("An exception caught: " + x.getMessage());
+ }
+
+ assertNotNull("The document provider for the file \"" + fileName +
"\" is not loaded", documentProvider);
+
+ try {
+ documentProvider.connect(editorInput);
+ } catch (Exception x) {
+ x.printStackTrace();
+ fail("The document provider is not able to be initialized with the editor
input\nAn exception caught: "+x.getMessage());
+ }
+
+ IDocument document = documentProvider.getDocument(editorInput);
+
+ assertNotNull("The document for the file \"" + fileName + "\"
is not loaded", document);
+
+ int expected = 0;
+ for(TestRegion testRegion : regionList)
+ expected += testRegion.region.getLength()+1;
+
+ IEditorPart part = openFileInEditor(file);
+ ISourceViewer viewer = null;
+ if(part instanceof JavaEditor){
+ viewer = ((JavaEditor)part).getViewer();
+ elDetector.setContext(new TestContext((ITextEditor)part));
+ }else if(part instanceof EditorPartWrapper){
+ if(((EditorPartWrapper)part).getEditor() instanceof WebCompoundEditor){
+ WebCompoundEditor wce = (WebCompoundEditor)((EditorPartWrapper)part).getEditor();
+ viewer = wce.getSourceEditor().getTextViewer();
+ elDetector.setContext(new TestContext(wce.getSourceEditor()));
+ }else if(((EditorPartWrapper)part).getEditor() instanceof XMLTextEditorStandAlone){
+ XMLTextEditorStandAlone xtesa =
(XMLTextEditorStandAlone)((EditorPartWrapper)part).getEditor();
+ viewer = xtesa.getTextViewer();
+ elDetector.setContext(new TestContext(xtesa));
+ }else fail("unsupported editor type -
"+((EditorPartWrapper)part).getEditor().getClass());
+ }else if(part instanceof JSPMultiPageEditor){
+ viewer = ((JSPMultiPageEditor)part).getJspEditor().getTextViewer();
+ elDetector.setContext(new TestContext(((JSPMultiPageEditor)part).getJspEditor()));
+ }else fail("unsupported editor type - "+part.getClass());
+
+
+
+ int counter = 0;
+ for (int i = 0; i < document.getLength(); i++) {
+ TestData testData = new TestData(document, i);
+ IHyperlink[] links = elDetector.detectHyperlinks(viewer,
testData.getHyperlinkRegion(), true);
+
+ boolean recognized = links != null;
+// if(recognized)
+// System.out.println("Recognized - "+i);
+
+ if (recognized) {
+ counter++;
+ TestRegion testRegion = findOffsetInRegions(i, regionList);
+ if(testRegion == null){
+ fail("Wrong detection for offset - "+i);
+ }else{
+ checkTestRegion(links, testRegion);
+ }
+ }
+ else {
+ for(TestRegion testRegion : regionList){
+ if(i >= testRegion.region.getOffset() && i <=
testRegion.region.getOffset()+testRegion.region.getLength()) {
+ int line = document.getLineOfOffset(testRegion.region.getOffset());
+ fail("Wrong detection for region - "+testRegion.region.getOffset()+"
: "+testRegion.region.getLength()+" region - "+i);
+ }
+ }
+ }
+ }
+
+ assertEquals("Wrong recognized region count: ", expected, counter);
+
+ documentProvider.disconnect(editorInput);
+ }
+
+ private static void checkTestRegion(IHyperlink[] links, TestRegion testRegion){
+ for(IHyperlink link : links){
+ TestHyperlink testLink = findTestHyperlink(testRegion.hyperlinks, link);
+ assertNotNull("Unexpected hyperlink - "+link.getHyperlinkText(), testLink);
+ assertEquals("Unexpected hyperlink type", testLink.hyperlink,
link.getClass());
+ if(testLink.fileName != null){
+ assertTrue("HyperLink must be inherited from AbstractHyperlink", link
instanceof AbstractHyperlink);
+
+ IFile f = ((AbstractHyperlink)link).getReadyToOpenFile();
+ assertNotNull("HyperLink must return not null file", f);
+ assertEquals(testLink.fileName, f.getName());
+
+ }
+ }
+
+ for(TestHyperlink testLink : testRegion.hyperlinks){
+ IHyperlink link = findHyperlink(links, testLink);
+ assertNotNull("Hyperlink - "+testLink.name+" not found", link);
+ }
+ }
+
+ private static TestHyperlink findTestHyperlink(List<TestHyperlink> testHyperlinks,
IHyperlink link){
+ for(TestHyperlink testLink : testHyperlinks){
+ if(testLink.name.equals(link.getHyperlinkText()))
+ return testLink;
+ }
+ return null;
+ }
+
+ private static IHyperlink findHyperlink(IHyperlink[] links, TestHyperlink testLink){
+ for(IHyperlink link : links){
+ if(testLink.name.equals(link.getHyperlinkText()))
+ return link;
+ }
+ return null;
+ }
+
+ private static TestRegion findOffsetInRegions(int offset, List<TestRegion>
regionList){
+ for(TestRegion testRegion : regionList){
+ if(offset >= testRegion.region.getOffset() && offset <=
testRegion.region.getOffset()+testRegion.region.getLength())
+ return testRegion;
+ }
+ return null;
+ }
+
+ public static IEditorPart openFileInEditor(IFile input) {
+ return openFileInEditor(input, null);
+ }
+
+ public static IEditorPart openFileInEditor(IFile input, String id) {
+ if (input != null && input.exists()) {
+ try {
+ if(id==null) {
+ IWorkbenchPage page = PlatformUI.getWorkbench()
+ .getActiveWorkbenchWindow().getActivePage();
+ return IDE.openEditor(page, input, true);
+ } else {
+ IWorkbenchPage page = PlatformUI.getWorkbench()
+ .getActiveWorkbenchWindow().getActivePage();
+ return IDE.openEditor(page, input, id, true);
+ }
+ } catch (PartInitException pie) {
+ pie.printStackTrace();
+ fail(pie.getMessage());
+ }
+ }
+ return null;
+ }
+
+ static class TestData {
+ IDocument document;
+ int offset;
+ IRegion region;
+ String contentType;
+ private IHyperlinkRegion hyperlinkRegion = null;
+
+ TestData (IDocument document, int offset) {
+ this.document = document;
+ this.offset = offset;
+ init();
+ }
+
+ private void init() {
+ this.region = getDocumentRegion();
+ this.contentType = getContentType();
+ this.hyperlinkRegion = getHyperlinkRegion();
+ }
+
+ private IRegion getDocumentRegion() {
+ IRegion region = null;
+ try {
+ region = JavaWordFinder.findWord(document, offset);
+ } catch (Exception x) {
+ x.printStackTrace();
+ fail(x.getMessage());
+ }
+
+ return region;
+ }
+
+ public IHyperlinkRegion getHyperlinkRegion() {
+ if (hyperlinkRegion != null)
+ return hyperlinkRegion;
+
+ return new IHyperlinkRegion() {
+ public String getAxis() {
+ return AxisUtil.getAxis(document, region.getOffset());
+ }
+ public String getContentType() {
+ return contentType;
+ }
+ public String getType() {
+ return region.toString();
+ }
+ public int getLength() {
+ return region.getLength();
+ }
+ public int getOffset() {
+ return region.getOffset();
+ }
+ public String toString() {
+ return "[" + getOffset() + "-" + (getOffset() +
getLength() - 1) + ":" + getType() + ":" + getContentType() +
"]";
+ }
+ };
+ }
+
+ /**
+ * Returns the content type of document
+ *
+ * @param document -
+ * assumes document is not null
+ * @return String content type of given document
+ */
+ private String getContentType() {
+ String type = null;
+
+ IModelManager mgr = StructuredModelManager.getModelManager();
+ IStructuredModel model = null;
+ try {
+ model = mgr.getExistingModelForRead(document);
+ if (model != null) {
+ type = model.getContentTypeIdentifier();
+ }
+ } finally {
+ if (model != null) {
+ model.releaseFromRead();
+ }
+ }
+ return type;
+ }
+ }
+
+ static class TestContext implements IAdaptable{
+ ITextEditor editor;
+
+ public TestContext(ITextEditor editor){
+ this.editor = editor;
+ }
+
+ public Object getAdapter(Class adapter) {
+ if(adapter.equals(ITextEditor.class))
+ return editor;
+ return null;
+ }
+ }
+
+ public static class TestRegion{
+ Region region;
+ ArrayList<TestHyperlink> hyperlinks = new ArrayList<TestHyperlink>();
+
+ public TestRegion(int offset, int length, TestHyperlink[] testHyperlinks){
+ region = new Region(offset, length);
+ for(TestHyperlink testHyperlink : testHyperlinks){
+ hyperlinks.add(testHyperlink);
+ }
+ }
+ }
+
+ public static class TestHyperlink{
+ Class<? extends IHyperlink> hyperlink;
+ String name;
+ String fileName=null;
+
+ public TestHyperlink(Class<? extends IHyperlink> hyperlink, String name, String
fileName){
+ this(hyperlink, name);
+ this.fileName = fileName;
+ }
+
+ public TestHyperlink(Class<? extends IHyperlink> hyperlink, String name){
+ this.hyperlink = hyperlink;
+ this.name = name;
+ }
+
+ }
+}
\ No newline at end of file
Property changes on:
trunk/jst/tests/org.jboss.tools.jst.text.ext.test/src/org/jboss/tools/jst/text/ext/test/HyperlinkTestUtil.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Modified: trunk/seam/plugins/org.jboss.tools.seam.text.ext/plugin.xml
===================================================================
--- trunk/seam/plugins/org.jboss.tools.seam.text.ext/plugin.xml 2011-07-14 17:59:26 UTC
(rev 32927)
+++ trunk/seam/plugins/org.jboss.tools.seam.text.ext/plugin.xml 2011-07-14 23:28:08 UTC
(rev 32928)
@@ -135,7 +135,7 @@
</contentType>
</hyperlinkPartitioner>
- <hyperlinkPartitioner
+ <!--hyperlinkPartitioner
id="org.jboss.tools.seam.text.ext.hyperlink.SeamBeanHyperlinkPartitioner"
class="org.jboss.tools.seam.text.ext.hyperlink.SeamBeanHyperlinkPartitioner">
<contentType id="org.eclipse.jst.jsp.core.jspsource">
@@ -177,9 +177,9 @@
<contentType id="org.jboss.tools.seam.xml.ui.page21xmlsource">
<partitionType
id="org.jboss.tools.common.text.ext.jsp.JSP_EXPRESSION"/>
</contentType>
- </hyperlinkPartitioner>
+ </hyperlinkPartitioner-->
- <hyperlinkPartitioner
+ <!--hyperlinkPartitioner
id="org.jboss.tools.common.text.ext.jsf.hyperlink.JSPExprHyperlinkPartitioner1"
class="org.jboss.tools.jsf.text.ext.hyperlink.JSPExprHyperlinkPartitioner">
@@ -215,7 +215,7 @@
<partitionType
id="org.jboss.tools.common.text.ext.xml.XML_ATTRIBUTE_VALUE" />
<partitionType id="org.jboss.tools.common.text.ext.xml.XML_TEXT"
/>
</contentType>
- </hyperlinkPartitioner>
+ </hyperlinkPartitioner-->
<hyperlinkPartitioner
id="org.jboss.tools.seam.text.ext.hyperlink.SeamViewHyperlinkPartitioner"
@@ -340,7 +340,7 @@
id="org.jboss.tools.seam.text.ext.hyperlink"
name="org.jboss.tools.seam.text.ext.hyperlink">
- <hyperlink
+ <!--hyperlink
class="org.jboss.tools.seam.text.ext.hyperlink.SeamMessagesBeanHyperlink"
id="org.jboss.tools.seam.text.ext.hyperlink.SeamBeanHyperlink">
<contenttypeidentifier id="org.eclipse.jst.jsp.core.jspsource">
@@ -382,7 +382,7 @@
<contenttypeidentifier
id="org.jboss.tools.seam.xml.ui.page21xmlsource">
<partitiontype id="org.jboss.tools.seam.text.ext.SEAM_MESSAGES_BEAN"
/>
</contenttypeidentifier>
- </hyperlink>
+ </hyperlink-->
<hyperlink
class="org.jboss.tools.seam.text.ext.hyperlink.SeamViewHyperlink"
@@ -425,12 +425,6 @@
<extension
point="org.eclipse.ui.workbench.texteditor.hyperlinkDetectors">
<hyperlinkDetector
-
class="org.jboss.tools.seam.text.ext.hyperlink.SeamELInJavaStringHyperlinkDetector"
-
id="org.jboss.tools.seam.text.ext.hyperlink.SeamELInJavaStringHyperlinkDetector"
- name="%SeamELInJavaStringHyperlinkDetector"
- targetId="org.eclipse.jdt.ui.javaCode">
- </hyperlinkDetector>
- <hyperlinkDetector
class="org.jboss.tools.seam.text.ext.hyperlink.SeamComponentHyperlinkDetector"
id="org.jboss.tools.seam.text.ext.hyperlink.SeamComponentHyperlinkDetector"
name="Seam Component"
Modified: trunk/seam/tests/org.jboss.tools.seam.ui.test/META-INF/MANIFEST.MF
===================================================================
--- trunk/seam/tests/org.jboss.tools.seam.ui.test/META-INF/MANIFEST.MF 2011-07-14 17:59:26
UTC (rev 32927)
+++ trunk/seam/tests/org.jboss.tools.seam.ui.test/META-INF/MANIFEST.MF 2011-07-14 23:28:08
UTC (rev 32928)
@@ -42,7 +42,8 @@
org.jboss.tools.jst.jsp.base.test;bundle-version="1.0.0",
org.jboss.tools.tests;bundle-version="3.1.0",
org.jboss.tools.jst.web;bundle-version="3.2.0",
- org.eclipse.jst.jee.web
+ org.eclipse.jst.jee.web,
+ org.jboss.tools.jst.text.ext.test;bundle-version="3.3.0"
Export-Package: org.jboss.tools.seam.ui.test,
org.jboss.tools.seam.ui.test.ca,
org.jboss.tools.seam.ui.test.hyperlink,
Modified:
trunk/seam/tests/org.jboss.tools.seam.ui.test/src/org/jboss/tools/seam/ui/test/el/ELExprPartitionerTest.java
===================================================================
---
trunk/seam/tests/org.jboss.tools.seam.ui.test/src/org/jboss/tools/seam/ui/test/el/ELExprPartitionerTest.java 2011-07-14
17:59:26 UTC (rev 32927)
+++
trunk/seam/tests/org.jboss.tools.seam.ui.test/src/org/jboss/tools/seam/ui/test/el/ELExprPartitionerTest.java 2011-07-14
23:28:08 UTC (rev 32928)
@@ -11,31 +11,17 @@
package org.jboss.tools.seam.ui.test.el;
import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Iterator;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
-import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
-import org.eclipse.jface.text.IDocument;
-import org.eclipse.jface.text.IDocumentExtension3;
-import org.eclipse.jface.text.ITypedRegion;
-import org.eclipse.jface.text.Region;
-import org.eclipse.ui.part.FileEditorInput;
-import org.eclipse.ui.texteditor.DocumentProviderRegistry;
-import org.eclipse.ui.texteditor.IDocumentProvider;
-import org.eclipse.wst.sse.core.StructuredModelManager;
-import org.eclipse.wst.sse.core.internal.provisional.IModelManager;
-import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel;
-import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument;
-import org.eclipse.wst.sse.ui.internal.editor.EditorModelUtil;
-import org.jboss.tools.common.text.ext.hyperlink.IHyperlinkRegion;
-import org.jboss.tools.common.text.ext.util.AxisUtil;
-import org.jboss.tools.jsf.text.ext.hyperlink.JSPExprHyperlinkPartitioner;
-import org.jboss.tools.test.util.JobUtils;
+import org.jboss.tools.jst.text.ext.hyperlink.ELHyperlink;
+import org.jboss.tools.jst.text.ext.hyperlink.ELHyperlinkDetector;
+import org.jboss.tools.jst.text.ext.test.HyperlinkTestUtil;
+import org.jboss.tools.jst.text.ext.test.HyperlinkTestUtil.TestHyperlink;
+import org.jboss.tools.jst.text.ext.test.HyperlinkTestUtil.TestRegion;
import org.jboss.tools.test.util.TestProjectProvider;
public class ELExprPartitionerTest extends TestCase {
@@ -55,6 +41,8 @@
Throwable exception = null;
assertNull("An exception caught: " + (exception != null?
exception.getMessage() : ""), exception);
+
+
}
protected void tearDown() throws Exception {
@@ -63,251 +51,38 @@
}
}
- public void testELExprPartitioner() {
- try {
- JobUtils.waitForIdle();
- } catch (Exception e) {
- assertNull("An exception caught: " + e.getMessage(), e);
- }
- assertTrue("Test project \"" + PROJECT_NAME + "\" is not
loaded", (project != null));
+ public void testELExprPartitioner() throws Exception{
- IFile jspFile = project.getFile(PAGE_NAME);
-
- assertTrue("The file \"" + PAGE_NAME + "\" is not found",
(jspFile != null));
- assertTrue("The file \"" + PAGE_NAME + "\" is not found",
(jspFile.exists()));
-
- FileEditorInput editorInput = new FileEditorInput(jspFile);
+ ArrayList<TestRegion> regionList = new ArrayList<TestRegion>();
+ regionList.add(new TestRegion(673, 6, new TestHyperlink[]{new
TestHyperlink(ELHyperlink.class, "Open 'demo.bundle.Messages'",
"Messages.properties")}));
+ regionList.add(new TestRegion(681, 7, new TestHyperlink[]{new
TestHyperlink(ELHyperlink.class, "Open property 'question' of bundle
'demo.bundle.Messages'", "Messages.properties")}));
- IDocumentProvider documentProvider = null;
- Throwable exception = null;
- try {
- documentProvider =
DocumentProviderRegistry.getDefault().getDocumentProvider(editorInput);
- } catch (Exception x) {
- exception = x;
- x.printStackTrace();
- }
- assertNull("An exception caught: " + (exception != null?
exception.getMessage() : ""), exception);
-
- assertNotNull("The document provider for the file \"" + PAGE_NAME +
"\" is not loaded", documentProvider);
-
- try {
- documentProvider.connect(editorInput);
- } catch (Exception x) {
- exception = x;
- x.printStackTrace();
- assertTrue("The document provider is not able to be initialized with the editor
input", false);
- }
- assertNull("An exception caught: " + (exception != null?
exception.getMessage() : ""), exception);
+ regionList.add(new TestRegion(756, 6, new TestHyperlink[]{new
TestHyperlink(ELHyperlink.class, "Open 'demo.bundle.Messages'",
"Messages.properties")}));
+ regionList.add(new TestRegion(764, 7, new TestHyperlink[]{new
TestHyperlink(ELHyperlink.class, "Open property 'question' of bundle
'demo.bundle.Messages'", "Messages.properties")}));
- IDocument document = documentProvider.getDocument(editorInput);
-
- assertNotNull("The document for the file \"" + PAGE_NAME + "\"
is not loaded", document);
+ regionList.add(new TestRegion(863, 6, new TestHyperlink[]{new
TestHyperlink(ELHyperlink.class, "Open 'demo.bundle.Messages'",
"Messages.properties")}));
+ regionList.add(new TestRegion(871, 9, new TestHyperlink[]{new
TestHyperlink(ELHyperlink.class, "Open property 'info_start' of bundle
'demo.bundle.Messages'", "Messages.properties")}));
- IStructuredModel model = null;
- if (document instanceof IStructuredDocument) {
- // corresponding releaseFromEdit occurs in
- // dispose()
- model = StructuredModelManager.getModelManager().getModelForEdit((IStructuredDocument)
document);
- EditorModelUtil.addFactoriesTo(model);
- }
-
- assertNotNull("The document model for the file \"" + PAGE_NAME +
"\" is not loaded", model);
-
- JSPExprHyperlinkPartitioner elPartitioner = new JSPExprHyperlinkPartitioner();
-
- HashMap<Object, ArrayList<Region>> recognitionTest = new HashMap<Object,
ArrayList<Region>>();
+ regionList.add(new TestRegion(909, 10, new TestHyperlink[]{new
TestHyperlink(ELHyperlink.class, "Open 'NumberGuess -
org.jboss.seam.example.numberguess'", "NumberGuess.java")}));
+ regionList.add(new TestRegion(921, 15, new TestHyperlink[]{new
TestHyperlink(ELHyperlink.class, "Open 'NumberGuess.getRemainingGuesses() -
org.jboss.seam.example.numberguess'", "NumberGuess.java")}));
- ArrayList<Region> regionList = new ArrayList<Region>();
- regionList.add(new Region(673, 7));
- regionList.add(new Region(680, 9));
- regionList.add(new Region(756, 7));
- regionList.add(new Region(763, 9));
- regionList.add(new Region(863, 7));
- regionList.add(new Region(870, 11));
- regionList.add(new Region(964, 19));
- regionList.add(new Region(1022, 18));
- regionList.add(new Region(1091, 17));
- recognitionTest.put("org.jboss.tools.common.text.ext.jsp.JSP_BUNDLE",
regionList);
+ regionList.add(new TestRegion(964, 6, new TestHyperlink[]{new
TestHyperlink(ELHyperlink.class, "Open 'demo.bundle.Messages'",
"Messages.properties")}));
+ regionList.add(new TestRegion(972, 10, new TestHyperlink[]{new
TestHyperlink(ELHyperlink.class, "Open property 'info_finish' of bundle
'demo.bundle.Messages'", "Messages.properties")}));
- regionList = new ArrayList<Region>();
- regionList.add(new Region(920, 1));
- regionList.add(new Region(1168, 1));
- regionList.add(new Region(1251, 1));
- recognitionTest.put("org.jboss.tools.common.text.ext.jsp.DOT_EXPRESSION",
regionList);
+ regionList.add(new TestRegion(1022, 6, new TestHyperlink[]{new
TestHyperlink(ELHyperlink.class, "Open 'demo.bundle.Messages'",
"Messages.properties")}));
+ regionList.add(new TestRegion(1030, 9, new TestHyperlink[]{new
TestHyperlink(ELHyperlink.class, "Open property 'button_yes' of bundle
'demo.bundle.Messages'", "Messages.properties")}));
- regionList = new ArrayList<Region>();
- regionList.add(new Region(909, 11));
- regionList.add(new Region(921, 16));
- regionList.add(new Region(1157, 11));
- regionList.add(new Region(1169, 13));
- regionList.add(new Region(1237, 14));
- regionList.add(new Region(1252, 8));
- recognitionTest.put("org.jboss.tools.common.text.ext.jsp.EXPRESSION",
regionList);
-
- regionList = new ArrayList<Region>();
- regionList.add(new Region(680, 1));
- regionList.add(new Region(763, 1));
- regionList.add(new Region(870, 1));
- regionList.add(new Region(920, 1));
- regionList.add(new Region(971, 1));
- regionList.add(new Region(1029, 1));
- regionList.add(new Region(1098, 1));
- recognitionTest.put("org.jboss.tools.common.text.ext.jsp.JSP_EXPRESSION",
regionList);
+ regionList.add(new TestRegion(1091, 6, new TestHyperlink[]{new
TestHyperlink(ELHyperlink.class, "Open 'demo.bundle.Messages'",
"Messages.properties")}));
+ regionList.add(new TestRegion(1099, 8, new TestHyperlink[]{new
TestHyperlink(ELHyperlink.class, "Open property 'button_no' of bundle
'demo.bundle.Messages'", "Messages.properties")}));
- int counter = 0;
- for (int i = 0; i < document.getLength(); i++) {
- TestData testData = new TestData(document, i);
- boolean recognized = elPartitioner.recognize(testData.document,
testData.getHyperlinkRegion());
- if (recognized) {
- String childPartitionType = elPartitioner.getChildPartitionType(testData.document,
testData.getHyperlinkRegion());
- //System.out.println("Type - "+childPartitionType+" offset -
"+i);
- if (childPartitionType != null) {
- ArrayList<Region> test =
(ArrayList<Region>)recognitionTest.get(childPartitionType);
- assertNotNull("There are no regions for partition type -
"+childPartitionType, test);
- boolean testResult = false;
- Iterator<Region> regions = test.iterator();
- Region r = null;
- while (!testResult && regions.hasNext()) {
- r = regions.next();
- if (r.getOffset() <= testData.offset && testData.offset <
(r.getOffset() + r.getLength()))
- testResult = true;
- }
- StringBuffer assertMessage = new StringBuffer();
- assertMessage.append("Wrong recognition for the region #")
- .append(i)
- .append(": ")
- .append(testData.getHyperlinkRegion().toString())
- .append(" doesn't matches the regions for PARTITION_TYPE '")
- .append(childPartitionType)
- .append("' {");
- boolean first = true;
- for (Region reg : test) {
- if (!first) {
- assertMessage.append(", ");
- } else {
- first = false;
- }
- assertMessage.append("[")
- .append(reg.getOffset())
- .append("-")
- .append(reg.getOffset() + reg.getLength())
- .append("]");
- }
- assertMessage.append("}");
-
- assertTrue(assertMessage.toString() , testResult);
- counter++;
- } else {
- recognized = false;
- }
- }
- if (!recognized) {
- boolean testResult = false;
- Iterator keys = recognitionTest.keySet().iterator();
- Region r = null;
- while (keys != null && keys.hasNext()) {
- Object key = keys.next();
- ArrayList test = (ArrayList)recognitionTest.get(key);
- Iterator regions = test.iterator();
- while (!testResult && regions.hasNext()) {
- r = (Region)regions.next();
- if (r.getOffset() <= testData.offset && testData.offset <
(r.getOffset() + r.getLength()))
- testResult = true;
- }
- }
- assertFalse("Wrong recognition for the region: " +
testData.getHyperlinkRegion().toString()
- + " matches the wrong region [" + r.getOffset() + "-" +
(r.getOffset() + r.getLength()) + "]" , testResult);
- }
- }
-
- assertEquals("Wrong recognized region count: ", 180, counter);
+ regionList.add(new TestRegion(1157, 10, new TestHyperlink[]{new
TestHyperlink(ELHyperlink.class, "Open 'NumberGuess -
org.jboss.seam.example.numberguess'", "NumberGuess.java")}));
+ regionList.add(new TestRegion(1169, 12, new TestHyperlink[]{new
TestHyperlink(ELHyperlink.class, "Open 'NumberGuess.getPossibilities() -
org.jboss.seam.example.numberguess'", "NumberGuess.java")}));
- model.releaseFromEdit();
-
- documentProvider.disconnect(editorInput);
- }
-
- class TestData {
- IDocument document;
- int offset;
- ITypedRegion region;
- String contentType;
- private IHyperlinkRegion hyperlinkRegion = null;
-
- TestData (IDocument document, int offset) {
- this.document = document;
- this.offset = offset;
- init();
- }
+ regionList.add(new TestRegion(1237, 13, new TestHyperlink[]{new
TestHyperlink(ELHyperlink.class, "Open 'Iterator.next() -
java.util'")}));
+ regionList.add(new TestRegion(1252, 7, new TestHyperlink[]{new
TestHyperlink(ELHyperlink.class, "Open 'Integer.intValue() -
java.lang'")}));
- private void init() {
- this.region = getDocumentRegion();
- this.contentType = getContentType();
- this.hyperlinkRegion = getHyperlinkRegion();
- }
+ HyperlinkTestUtil.checkRegions(project, PAGE_NAME, regionList, new
ELHyperlinkDetector());
- private ITypedRegion getDocumentRegion() {
- ITypedRegion region = null;
- try {
- region = (document instanceof IDocumentExtension3 ?
- ((IDocumentExtension3)document).getDocumentPartitioner("org.eclipse.wst.sse.core.default_structured_text_partitioning").getPartition(offset)
:
- document.getDocumentPartitioner().getPartition(offset));
- } catch (Exception x) {}
-
- return region;
- }
-
- public IHyperlinkRegion getHyperlinkRegion() {
- if (hyperlinkRegion != null)
- return hyperlinkRegion;
-
- return new IHyperlinkRegion() {
- public String getAxis() {
- return AxisUtil.getAxis(document, region.getOffset());
- }
- public String getContentType() {
- return contentType;
- }
- public String getType() {
- return region.getType();
- }
- public int getLength() {
- return region.getLength();
- }
- public int getOffset() {
- return region.getOffset();
- }
- public String toString() {
- return "[" + getOffset() + "-" + (getOffset() +
getLength() - 1) + ":" + getType() + ":" + getContentType() +
"]";
- }
- };
- }
-
-
- /**
- * Returns the content type of document
- *
- * @param document -
- * assumes document is not null
- * @return String content type of given document
- */
- private String getContentType() {
- String type = null;
-
- IModelManager mgr = StructuredModelManager.getModelManager();
- IStructuredModel model = null;
- try {
- model = mgr.getExistingModelForRead(document);
- if (model != null) {
- type = model.getContentTypeIdentifier();
- }
- } finally {
- if (model != null) {
- model.releaseFromRead();
- }
- }
- return type;
- }
}
-
+
}