Author: vrubezhny
Date: 2011-10-20 11:44:11 -0400 (Thu, 20 Oct 2011)
New Revision: 35850
Added:
trunk/jsf/tests/org.jboss.tools.jsf.text.ext.test/projects/jsfHyperlinkTests/WebContent/JBIDE-9930/
trunk/jsf/tests/org.jboss.tools.jsf.text.ext.test/projects/jsfHyperlinkTests/WebContent/JBIDE-9930/elInTagBody.jsp
trunk/jsf/tests/org.jboss.tools.jsf.text.ext.test/src/org/jboss/tools/jsf/text/ext/test/JSPELHyperlinkTestForELInTagBodyTest.java
Modified:
trunk/jsf/tests/org.jboss.tools.jsf.text.ext.test/src/org/jboss/tools/jsf/text/ext/test/JsfTextExtAllTests.java
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/PageContextFactory.java
Log:
JBIDE-9930 OpenOns for ELs don't work in text nodes of JSP
Issue is fixed. JUnit test is created
Added:
trunk/jsf/tests/org.jboss.tools.jsf.text.ext.test/projects/jsfHyperlinkTests/WebContent/JBIDE-9930/elInTagBody.jsp
===================================================================
---
trunk/jsf/tests/org.jboss.tools.jsf.text.ext.test/projects/jsfHyperlinkTests/WebContent/JBIDE-9930/elInTagBody.jsp
(rev 0)
+++
trunk/jsf/tests/org.jboss.tools.jsf.text.ext.test/projects/jsfHyperlinkTests/WebContent/JBIDE-9930/elInTagBody.jsp 2011-10-20
15:44:11 UTC (rev 35850)
@@ -0,0 +1,13 @@
+<%@ taglib
uri="http://java.sun.com/jsf/html" prefix="h" %>
+<%@ taglib
uri="http://java.sun.com/jsf/core" prefix="f" %>
+
+<html>
+ <head>
+ <title></title>
+ </head>
+ <body>
+ <f:view>
+ #{bean1.property1}
+ </f:view>
+ </body>
+</html>
Property changes on:
trunk/jsf/tests/org.jboss.tools.jsf.text.ext.test/projects/jsfHyperlinkTests/WebContent/JBIDE-9930/elInTagBody.jsp
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added:
trunk/jsf/tests/org.jboss.tools.jsf.text.ext.test/src/org/jboss/tools/jsf/text/ext/test/JSPELHyperlinkTestForELInTagBodyTest.java
===================================================================
---
trunk/jsf/tests/org.jboss.tools.jsf.text.ext.test/src/org/jboss/tools/jsf/text/ext/test/JSPELHyperlinkTestForELInTagBodyTest.java
(rev 0)
+++
trunk/jsf/tests/org.jboss.tools.jsf.text.ext.test/src/org/jboss/tools/jsf/text/ext/test/JSPELHyperlinkTestForELInTagBodyTest.java 2011-10-20
15:44:11 UTC (rev 35850)
@@ -0,0 +1,106 @@
+/*******************************************************************************
+ * 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.jsf.text.ext.test;
+
+import junit.framework.TestCase;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.jface.text.FindReplaceDocumentAdapter;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.IRegion;
+import org.eclipse.jface.text.Region;
+import org.eclipse.jface.text.hyperlink.IHyperlink;
+import org.eclipse.jface.text.source.ISourceViewer;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.PlatformUI;
+import org.jboss.tools.jst.jsp.jspeditor.JSPMultiPageEditor;
+import org.jboss.tools.jst.text.ext.hyperlink.ELHyperlinkDetector;
+import org.jboss.tools.test.util.WorkbenchUtils;
+
+/**
+ * The JUnit test cases for JBIDE-5385 issue
+ *
+ * @author Victor Rubezhny
+ */
+public class JSPELHyperlinkTestForELInTagBodyTest extends TestCase {
+ private static final String PROJECT_NAME = "jsfHyperlinkTests";
+ private static final String PAGE_NAME =
PROJECT_NAME+"/WebContent/JBIDE-9930/elInTagBody.jsp";
+ private static final String[] TEXT_TO_FIND = new String [] {"bean1",
"bean1.property1"};
+ private static final String[] RESULT_EDITORS = new String [] {"Bean1.java",
"Bean1.java"};
+
+ public IProject project = null;
+ public String naturesCheckProperty;
+ private ELHyperlinkDetector elHyperlinkDetector = new ELHyperlinkDetector();
+
+
+ protected void setUp() {
+ naturesCheckProperty =
System.getProperty("org.jboss.tools.vpe.ENABLE_PROJECT_NATURES_CHECKER");
//$NON-NLS-1$ //$NON-NLS-2$
+ System.setProperty("org.jboss.tools.vpe.ENABLE_PROJECT_NATURES_CHECKER",
"false"); //$NON-NLS-1$ //$NON-NLS-2$
+ project = ResourcesPlugin.getWorkspace().getRoot().getProject(
+ PROJECT_NAME);
+ PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().closeAllEditors(false);
+ }
+
+ protected void tearDown() {
+ PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().closeAllEditors(false);
+ System.setProperty("org.jboss.tools.vpe.ENABLE_PROJECT_NATURES_CHECKER",
naturesCheckProperty == null ? "null" : naturesCheckProperty); //$NON-NLS-1$
+ }
+
+ public JSPELHyperlinkTestForELInTagBodyTest() {
+ super("JSP EL In Tag Body OpenOn test");
+ }
+
+
+ public void testJSPELHyperlinkTestForELInTagBody() throws PartInitException,
BadLocationException {
+ try {
+ for (int i = 0; i < TEXT_TO_FIND.length; i++) {
+ doJSPELHyperlinkTestForELInTagBodyTest(TEXT_TO_FIND[i], RESULT_EDITORS[i]);
+ }
+ } finally {
+ WorkbenchUtils.closeAllEditors();
+ }
+ }
+
+ private void doJSPELHyperlinkTestForELInTagBodyTest(String template, String editorName)
throws BadLocationException {
+ IEditorPart editor = WorkbenchUtils.openEditor(PAGE_NAME);
+ assertTrue(editor instanceof JSPMultiPageEditor);
+ JSPMultiPageEditor jspMultyPageEditor = (JSPMultiPageEditor) editor;
+ ISourceViewer viewer = jspMultyPageEditor.getSourceEditor().getTextViewer();
+ assertNotNull("Viewer couldn't be found for " + PAGE_NAME, viewer);
+ IDocument document = viewer.getDocument();
+ IRegion reg = new FindReplaceDocumentAdapter(document).find(0,
+ template, true, true, false, false);
+ assertNotNull("Text: "+ template +" not found",reg);
+
+ IHyperlink[] links = elHyperlinkDetector.detectHyperlinks(viewer, new
Region(reg.getOffset() + reg.getLength() - 1, 0), true);
+
+ assertNotNull("Hyperlinks for EL:#{" + template + "} are not
found",links);
+
+ assertTrue("Hyperlinks for EL: #{" + template + "} are not
found",links.length!=0);
+
+ boolean found = false;
+ for(IHyperlink link : links){
+ assertNotNull(link.toString());
+
+ link.open();
+
+ IEditorPart resultEditor =
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
+ if(editorName.equals(resultEditor.getTitle())){
+ found = true;
+ return;
+ }
+ }
+ assertTrue("OpenOn have not opened "+editorName+" editor",found);
+ }
+}
\ No newline at end of file
Property changes on:
trunk/jsf/tests/org.jboss.tools.jsf.text.ext.test/src/org/jboss/tools/jsf/text/ext/test/JSPELHyperlinkTestForELInTagBodyTest.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Modified:
trunk/jsf/tests/org.jboss.tools.jsf.text.ext.test/src/org/jboss/tools/jsf/text/ext/test/JsfTextExtAllTests.java
===================================================================
---
trunk/jsf/tests/org.jboss.tools.jsf.text.ext.test/src/org/jboss/tools/jsf/text/ext/test/JsfTextExtAllTests.java 2011-10-20
15:23:49 UTC (rev 35849)
+++
trunk/jsf/tests/org.jboss.tools.jsf.text.ext.test/src/org/jboss/tools/jsf/text/ext/test/JsfTextExtAllTests.java 2011-10-20
15:44:11 UTC (rev 35850)
@@ -40,6 +40,12 @@
"org.jboss.tools.jsf.text.ext.test",
new String[]{"projects/jsfHyperlinkTests"},
new String[]{"jsfHyperlinkTests"}));
+
+ suite.addTest(new ProjectImportTestSetup(new TestSuite(
+ JSPELHyperlinkTestForELInTagBodyTest.class),
+ "org.jboss.tools.jsf.text.ext.test",
+ new String[]{"projects/jsfHyperlinkTests"},
+ new String[]{"jsfHyperlinkTests"}));
return suite;
}
Modified:
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/PageContextFactory.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/PageContextFactory.java 2011-10-20
15:23:49 UTC (rev 35849)
+++
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/PageContextFactory.java 2011-10-20
15:44:11 UTC (rev 35850)
@@ -435,11 +435,6 @@
}
private void fillContextForNode(IDocument document, IDOMNode node, ELContext context,
List<String> parents) {
- if (context instanceof JspContextImpl && !(context instanceof
FaceletPageContextImpl) && !(node instanceof IDOMElement)) {
- // There is no any useful info for JSP in text nodes
- return;
- }
-
if (context instanceof XmlContextImpl) {
XmlContextImpl xmlContext = (XmlContextImpl)context;
fillElReferencesForNode(document, node, xmlContext);
@@ -487,39 +482,51 @@
}
private static void fillElReferencesForNode(IDocument document, IDOMNode node,
XmlContextImpl context) {
- if(Node.ELEMENT_NODE == node.getNodeType() || Node.TEXT_NODE == node.getNodeType()) {
- IStructuredDocumentRegion regionNode = node.getFirstStructuredDocumentRegion();
- if (regionNode == null)
- return;
- ITextRegionList regions = regionNode.getRegions();
- for(int i=0; i<regions.size(); i++) {
- ITextRegion region = regions.get(i);
- if(region.getType() == DOMRegionContext.XML_TAG_ATTRIBUTE_VALUE || region.getType()
== DOMRegionContext.XML_CONTENT) {
- String text = regionNode.getFullText(region);
- if(text.indexOf('{')>-1 && (text.indexOf("#{") > -1
|| text.indexOf("${") > -1)) { //$NON-NLS-1$
- int offset = regionNode.getStartOffset() + region.getStart();
- ELParser parser = ELParserUtil.getJbossFactory().createParser();
- ELModel model = parser.parse(text);
- List<ELInstance> is = model.getInstances();
- ELReference elReference = new ValidationELReference();
- elReference.setResource(context.getResource());
- elReference.setEl(is);
- elReference.setLength(text.length());
- elReference.setStartPosition(offset);
- try {
- if(Node.TEXT_NODE == node.getNodeType()) {
- if(is.size()==1) {
- elReference.setLineNumber(document.getLineOfOffset(elReference.getStartPossitionOfFirstEL())
+ 1);
- }
- } else {
- elReference.setLineNumber(document.getLineOfOffset(offset) + 1);
+ if(Node.ELEMENT_NODE != node.getNodeType() && Node.TEXT_NODE !=
node.getNodeType())
+ return;
+
+ IStructuredDocumentRegion regionNode = node.getFirstStructuredDocumentRegion();
+ if (regionNode == null)
+ return;
+
+ IStructuredDocumentRegion lastRegionNode = node.getLastStructuredDocumentRegion();
+ for (; regionNode != null && regionNode != lastRegionNode; regionNode =
regionNode.getNext()) {
+ fillElReferencesForRegionNode(document, node, regionNode, context);
+ }
+ if (lastRegionNode != null) {
+ fillElReferencesForRegionNode(document, node, lastRegionNode, context);
+ }
+ }
+
+ private static void fillElReferencesForRegionNode(IDocument document, IDOMNode node,
IStructuredDocumentRegion regionNode, XmlContextImpl context) {
+ ITextRegionList regions = regionNode.getRegions();
+ for(int i=0; i<regions.size(); i++) {
+ ITextRegion region = regions.get(i);
+ if(region.getType() == DOMRegionContext.XML_TAG_ATTRIBUTE_VALUE || region.getType() ==
DOMRegionContext.XML_CONTENT) {
+ String text = regionNode.getFullText(region);
+ if(text.indexOf('{')>-1 && (text.indexOf("#{") > -1
|| text.indexOf("${") > -1)) { //$NON-NLS-1$
+ int offset = regionNode.getStartOffset() + region.getStart();
+ ELParser parser = ELParserUtil.getJbossFactory().createParser();
+ ELModel model = parser.parse(text);
+ List<ELInstance> is = model.getInstances();
+ ELReference elReference = new ValidationELReference();
+ elReference.setResource(context.getResource());
+ elReference.setEl(is);
+ elReference.setLength(text.length());
+ elReference.setStartPosition(offset);
+ try {
+ if(Node.TEXT_NODE == node.getNodeType()) {
+ if(is.size()==1) {
+ elReference.setLineNumber(document.getLineOfOffset(elReference.getStartPossitionOfFirstEL())
+ 1);
}
- } catch (BadLocationException e) {
- WebKbPlugin.getDefault().logError(e);
+ } else {
+ elReference.setLineNumber(document.getLineOfOffset(offset) + 1);
}
- elReference.setSyntaxErrors(model.getSyntaxErrors());
- context.addELReference(elReference);
+ } catch (BadLocationException e) {
+ WebKbPlugin.getDefault().logError(e);
}
+ elReference.setSyntaxErrors(model.getSyntaxErrors());
+ context.addELReference(elReference);
}
}
}