Author: vrubezhny
Date: 2012-07-02 12:57:17 -0400 (Mon, 02 Jul 2012)
New Revision: 42333
Added:
trunk/jst/tests/org.jboss.tools.jst.text.ext.test/projects/OpenOnTest/WebContent/indexParentToChildRestrictions.html
trunk/jst/tests/org.jboss.tools.jst.text.ext.test/projects/OpenOnTest/WebContent/styleParentToChildRestrictions.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-10127
Resolve selector in open-on of style class in VPE
Parent node restrictions are separated from the child node ones.
JUnit Test case is added.
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 2012-07-02
11:03:44 UTC (rev 42332)
+++
trunk/jst/plugins/org.jboss.tools.jst.text.ext/src/org/jboss/tools/jst/text/ext/hyperlink/CSSClassHyperlink.java 2012-07-02
16:57:17 UTC (rev 42333)
@@ -394,13 +394,13 @@
attrFound = allValuesAreOK;
}
+ // proceed with parent node
+ node = node.getParentNode();
+
if (classFound && nodeFound && attrFound) {
// Proceed with next Axis
break;
}
-
- // proceed with parent node
- node = node.getParentNode();
} while (node instanceof Element);
Added:
trunk/jst/tests/org.jboss.tools.jst.text.ext.test/projects/OpenOnTest/WebContent/indexParentToChildRestrictions.html
===================================================================
---
trunk/jst/tests/org.jboss.tools.jst.text.ext.test/projects/OpenOnTest/WebContent/indexParentToChildRestrictions.html
(rev 0)
+++
trunk/jst/tests/org.jboss.tools.jst.text.ext.test/projects/OpenOnTest/WebContent/indexParentToChildRestrictions.html 2012-07-02
16:57:17 UTC (rev 42333)
@@ -0,0 +1,22 @@
+<html>
+ <head>
+ <link href="styleParentToChildRestrictions.css"
rel="stylesheet" type="text/css"></link>
+ </head>
+
+ <body>
+
+ <div title="a" class="bc">
+ 1. This matches ([title="a"].bc).
+ <i> 2. This matches (.bc i).</i>
+ <i class="bc"> 3. This matches ([title="a"] .bc).</i>
+ </div>
+
+ <div> <p class="s1">
+ 4. This should not match (div * .s1).
+ <b class="s1"> 5. This matches (div * .s1).</b>
</p></div>
+
+ <div> <p class="s2">
+ 6. This matches (div p.s2).
+ </p></div>
+ </body>
+</html>
\ No newline at end of file
Property changes on:
trunk/jst/tests/org.jboss.tools.jst.text.ext.test/projects/OpenOnTest/WebContent/indexParentToChildRestrictions.html
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added:
trunk/jst/tests/org.jboss.tools.jst.text.ext.test/projects/OpenOnTest/WebContent/styleParentToChildRestrictions.css
===================================================================
---
trunk/jst/tests/org.jboss.tools.jst.text.ext.test/projects/OpenOnTest/WebContent/styleParentToChildRestrictions.css
(rev 0)
+++
trunk/jst/tests/org.jboss.tools.jst.text.ext.test/projects/OpenOnTest/WebContent/styleParentToChildRestrictions.css 2012-07-02
16:57:17 UTC (rev 42333)
@@ -0,0 +1,11 @@
+.bb {background-color: red;}
+
+[title="a"].bc {background-color: aqua;}
+
+[title="a"] .bc {background-color: green;}
+
+.bc i {background-color: blue;}
+
+div * .s1 {background-color: yellow;}
+
+div p.s2 {background-color: brown;}
\ No newline at end of file
Property changes on:
trunk/jst/tests/org.jboss.tools.jst.text.ext.test/projects/OpenOnTest/WebContent/styleParentToChildRestrictions.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 2012-07-02
11:03:44 UTC (rev 42332)
+++
trunk/jst/tests/org.jboss.tools.jst.text.ext.test/src/org/jboss/tools/jst/text/ext/test/CSSStylesheetOpenOnTest.java 2012-07-02
16:57:17 UTC (rev 42333)
@@ -39,6 +39,7 @@
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";
private static final String RESOLVE_SELECTOR_PAGE_NAME =
PROJECT_NAME+"/WebContent/indexResolveSelector.html";
+ private static final String PARENT_TO_CHILD_RESTRICTIONS_RESOLVE_SELECTOR_PAGE_NAME =
PROJECT_NAME+"/WebContent/indexParentToChildRestrictions.html";
public IProject project = null;
@@ -368,7 +369,86 @@
}
}
}
+
+ public void testCSSClassParentToChildResolveRestrictions() throws PartInitException,
BadLocationException {
+ HashSet<IEditorPart> openedEditors = new HashSet<IEditorPart>();
+ // CSS class names to be tested are placed one by one,
+ // so, for each next test we'll continue to search in document
+ // (We'll not search from beginning each time)
+ //
+ // Position to continue the search from
+ int startFrom = 0;
+
+ // 'class="' - is the string to search
+ final String TEXT_TO_SEARCH = "class=\"";
+
+ // Valid values for Text Selection after the open on is performed
+ final String[][] VALID_TEXT_SELECTIONS = {
+ {"styleParentToChildRestrictions.css", "[title=\"a\"].bc
{background-color: aqua;}"},
+ {"styleParentToChildRestrictions.css", "[title=\"a\"] .bc
{background-color: green;}"},
+ {"indexParentToChildRestrictions.html", ""},
+ {"styleParentToChildRestrictions.css", "div * .s1 {background-color:
yellow;}"},
+ {"styleParentToChildRestrictions.css", "div p.s2 {background-color:
brown;}"}
+ };
+
+ for (int i = 0; i < VALID_TEXT_SELECTIONS.length; i++) {
+ String validEditorName = VALID_TEXT_SELECTIONS[i][0];
+ String validSelection = VALID_TEXT_SELECTIONS[i][1];
+
+ IEditorPart editor =
WorkbenchUtils.openEditor(PARENT_TO_CHILD_RESTRICTIONS_RESOLVE_SELECTOR_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();
+ IRegion reg = new FindReplaceDocumentAdapter(document).find(startFrom,
+ TEXT_TO_SEARCH, true, true, false, false);
+ assertNotNull("Attribute :" + TEXT_TO_SEARCH + " not found whyle
search starting from " + startFrom, reg);
+
+ startFrom = reg.getOffset() + reg.getLength();
+
+ IHyperlink[] links = HyperlinkDetector.getInstance().detectHyperlinks(viewer, new
Region(startFrom, 0), true); // new Region(reg.getOffset() + reg.getLength(), 0)
+
+ assertTrue("Hyperlinks not found for position " + startFrom,(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(validEditorName.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;
+ String selectionText =
stEditor.getTextViewer().getDocument().get(textSelection.getOffset(),
textSelection.getLength());
+ assertTrue("Required CSS Rule is not selected",
+ (validSelection.equalsIgnoreCase(selectionText)));
+ found = true;
+ break;
+ }
+ }
+ }
+ assertTrue("OpenOn have not opened a valid selection [" + validSelection +
"] in " + validEditorName + " editor",found);
+ } finally {
+ closeEditors(openedEditors);
+ }
+ }
+ }
+
protected void closeEditors (HashSet<IEditorPart> editors) {
if (editors == null || editors.isEmpty())
return;
Show replies by date