Author: vrubezhny
Date: 2011-11-14 13:18:51 -0500 (Mon, 14 Nov 2011)
New Revision: 36327
Added:
trunk/jst/tests/org.jboss.tools.jst.text.ext.test/projects/OpenOnTest/WebContent/indexWithSecondClassInRule.html
trunk/jst/tests/org.jboss.tools.jst.text.ext.test/projects/OpenOnTest/WebContent/secondClassName.css
Modified:
trunk/jst/plugins/org.jboss.tools.jst.text.ext/src/org/jboss/tools/jst/text/ext/hyperlink/CSSClassHyperlink.java
trunk/jst/tests/org.jboss.tools.jst.text.ext.test/src/org/jboss/tools/jst/text/ext/test/CSSStylesheetOpenOnTest.java
Log:
JBIDE-10104 VPE does not open css file if the style is not on the first place
Issue is fixed. JUnit Test case is added to
org.jboss.tools.jst.text.ext.test.CSSStylesheetOpenOnTest Test
Modified:
trunk/jst/plugins/org.jboss.tools.jst.text.ext/src/org/jboss/tools/jst/text/ext/hyperlink/CSSClassHyperlink.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.text.ext/src/org/jboss/tools/jst/text/ext/hyperlink/CSSClassHyperlink.java 2011-11-14
16:32:13 UTC (rev 36326)
+++
trunk/jst/plugins/org.jboss.tools.jst.text.ext/src/org/jboss/tools/jst/text/ext/hyperlink/CSSClassHyperlink.java 2011-11-14
18:18:51 UTC (rev 36327)
@@ -11,11 +11,7 @@
package org.jboss.tools.jst.text.ext.hyperlink;
import java.text.MessageFormat;
-import java.util.Arrays;
-import java.util.Comparator;
import java.util.List;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IFile;
@@ -59,7 +55,6 @@
public static final String[] STYLE_TAGS = new String[] { "style",
"link" }; //$NON-NLS-1$//$NON-NLS-2$
public static final String LINK_TAG = "link"; //$NON-NLS-1$
public static final String HREF_ATTRIBUTE = "href"; //$NON-NLS-1$
- public static final String COMPARE_CLASS_REGEX_PREFIX =
"([A-Za-z_][A-Za-z_0-9\\-]*)*[\\.]?"; //$NON-NLS-1$
public static final String CONTEXT_PATH_EXPRESSION =
"^\\s*(\\#|\\$)\\{facesContext.externalContext.requestContextPath\\}";
//$NON-NLS-1$
@Override
@@ -168,24 +163,15 @@
String selectorText = ((CSSStyleRule) cssRule).getSelectorText();
if (selectorText != null) {
- String styles[] = selectorText.trim().split(","); //$NON-NLS-1$
+ String styleNameToSearch = '.' + styleName.toLowerCase();
+ String styles[] = selectorText.trim().toLowerCase().split(",");
//$NON-NLS-1$
for (String styleText : styles) {
String[] styleWords = styleText.trim().split(" "); //$NON-NLS-1$
if (styleWords != null) {
- int searchIndex = Arrays.binarySearch(styleWords, styleName,
- new Comparator<String>() {
-
- public int compare(String o1, String o2) {
- Matcher matcher = Pattern.compile(
- COMPARE_CLASS_REGEX_PREFIX + o2)
- .matcher(o1);
-
- return matcher.matches() ? 0 : 1;
- }
-
- });
- if (searchIndex >= 0)
- return cssRule;
+ for (String word : styleWords) {
+ if (word.trim().toLowerCase().endsWith(styleNameToSearch))
+ return cssRule;
+ }
}
}
}
@@ -243,7 +229,6 @@
}
/**
- * TODO research method
*
* @param offset
* @return
Added:
trunk/jst/tests/org.jboss.tools.jst.text.ext.test/projects/OpenOnTest/WebContent/indexWithSecondClassInRule.html
===================================================================
---
trunk/jst/tests/org.jboss.tools.jst.text.ext.test/projects/OpenOnTest/WebContent/indexWithSecondClassInRule.html
(rev 0)
+++
trunk/jst/tests/org.jboss.tools.jst.text.ext.test/projects/OpenOnTest/WebContent/indexWithSecondClassInRule.html 2011-11-14
18:18:51 UTC (rev 36327)
@@ -0,0 +1,12 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html
xmlns="http://www.w3.org/1999/xhtml"
+
xmlns:h="http://java.sun.com/jsf/html">
+<head>
+ <link rel="stylesheet" href="secondClassName.css" />
+</head>
+<body>
+ <div class="event">aaa</div>
+ <div class="evt_sub">bbb</div>
+ <div class="style2">ccc</div>
+</body>
+</html>
Property changes on:
trunk/jst/tests/org.jboss.tools.jst.text.ext.test/projects/OpenOnTest/WebContent/indexWithSecondClassInRule.html
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added:
trunk/jst/tests/org.jboss.tools.jst.text.ext.test/projects/OpenOnTest/WebContent/secondClassName.css
===================================================================
---
trunk/jst/tests/org.jboss.tools.jst.text.ext.test/projects/OpenOnTest/WebContent/secondClassName.css
(rev 0)
+++
trunk/jst/tests/org.jboss.tools.jst.text.ext.test/projects/OpenOnTest/WebContent/secondClassName.css 2011-11-14
18:18:51 UTC (rev 36327)
@@ -0,0 +1,3 @@
+.event .evt_sub .style2 {float:left; margin-right:10px}
+.event .evt_sub .style2 strong{display: inline-block; width: 51px;}
+.event .evt_sub .style2 span{border-right:1px solid
#ccc;padding-right:7px;margin-right:7px}
\ No newline at end of file
Property changes on:
trunk/jst/tests/org.jboss.tools.jst.text.ext.test/projects/OpenOnTest/WebContent/secondClassName.css
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Modified:
trunk/jst/tests/org.jboss.tools.jst.text.ext.test/src/org/jboss/tools/jst/text/ext/test/CSSStylesheetOpenOnTest.java
===================================================================
---
trunk/jst/tests/org.jboss.tools.jst.text.ext.test/src/org/jboss/tools/jst/text/ext/test/CSSStylesheetOpenOnTest.java 2011-11-14
16:32:13 UTC (rev 36326)
+++
trunk/jst/tests/org.jboss.tools.jst.text.ext.test/src/org/jboss/tools/jst/text/ext/test/CSSStylesheetOpenOnTest.java 2011-11-14
18:18:51 UTC (rev 36327)
@@ -36,7 +36,9 @@
private static final String PROJECT_NAME = "OpenOnTest";
private static final String PAGE_NAME =
PROJECT_NAME+"/WebContent/index.html";
private static final String MEDIA_PAGE_NAME =
PROJECT_NAME+"/WebContent/indexWithMediaRules.html";
+ private static final String SECOND_IN_A_ROW_PAGE_NAME =
PROJECT_NAME+"/WebContent/indexWithSecondClassInRule.html";
+
public IProject project = null;
protected void setUp() {
@@ -212,6 +214,77 @@
}
}
+ /*
+ * The test case for JBIDE-10104
+ */
+ public void testCSSClassOpenOnWithASecondRuleNameInARow() throws PartInitException,
BadLocationException {
+ HashSet<IEditorPart> openedEditors = new HashSet<IEditorPart>();
+ final String tagName = "<div";
+ final String[] valuesToFind = {
+ "event", "evt_sub", "style2"};
+ final String[] editorNames = {
+ "secondClassName.css", "secondClassName.css",
"secondClassName.css"};
+ final int[] editorSelectionOffsets = {
+ 0, 0, 0};
+ final int[] editorSelectionLengths = {
+ 55, 55, 55};
+
+ IEditorPart editor = WorkbenchUtils.openEditor(SECOND_IN_A_ROW_PAGE_NAME);
+ if (editor != null) openedEditors.add(editor);
+ try {
+ assertTrue(editor instanceof JSPMultiPageEditor);
+ JSPMultiPageEditor jspMultyPageEditor = (JSPMultiPageEditor) editor;
+ ISourceViewer viewer = jspMultyPageEditor.getSourceEditor().getTextViewer();
+
+ IDocument document = viewer.getDocument();
+ for (int i = 0; i < valuesToFind.length; i++) {
+ IRegion reg = new FindReplaceDocumentAdapter(document).find(0,
+ tagName, true, true, false, false);
+ assertNotNull("Tag:"+tagName+" not found",reg);
+
+ reg = new FindReplaceDocumentAdapter(document).find(reg.getOffset(),
+ valuesToFind[i], true, true, false, false);
+ assertNotNull("Value to find '"+valuesToFind[i]+"' not
found",reg);
+
+ IHyperlink[] links = HyperlinkDetector.getInstance().detectHyperlinks(viewer, reg,
true); // new Region(reg.getOffset() + reg.getLength(), 0)
+
+ assertTrue("Hyperlinks for value '"+valuesToFind[i]+"' are not
found",(links != null && links.length > 0));
+
+ boolean found = false;
+ for(IHyperlink link : links){
+ assertNotNull(link.toString());
+
+ link.open();
+
+ IEditorPart resultEditor =
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
+ if (resultEditor != null) openedEditors.add(resultEditor);
+ if(editorNames[i].equals(resultEditor.getTitle())){
+ StructuredTextEditor stEditor = null;
+ if (resultEditor instanceof StructuredTextEditor) {
+ stEditor = (StructuredTextEditor)resultEditor;
+ } else if (resultEditor instanceof JSPMultiPageEditor) {
+ stEditor = ((JSPMultiPageEditor)resultEditor).getSourceEditor();
+ }
+ assertNotNull("Unexpected Editor is openned: " + resultEditor.getTitle()
+ " [" + resultEditor.getClass().getName() + "]", stEditor);
+ ISelection selection = stEditor.getSelectionProvider().getSelection();
+ assertFalse("Required CSS Rule is not selected", selection.isEmpty());
+ if (selection instanceof TextSelection) {
+ TextSelection textSelection = (TextSelection)selection;
+ assertTrue("Required CSS Rule is not selected",
+ (textSelection.getOffset() == editorSelectionOffsets[i] &&
textSelection.getLength() == editorSelectionLengths[i]));
+ found = true;
+ break;
+ }
+ }
+ }
+ assertTrue("OpenOn have not opened "+editorNames[i]+"
editor",found);
+ }
+ } finally {
+ closeEditors(openedEditors);
+ }
+ }
+
+
protected void closeEditors (HashSet<IEditorPart> editors) {
if (editors == null || editors.isEmpty())
return;