Author: vrubezhny
Date: 2011-09-20 12:05:43 -0400 (Tue, 20 Sep 2011)
New Revision: 34880
Added:
trunk/jst/tests/org.jboss.tools.jst.web.kb.test/projects/TestKbModel/WebContent/pages/cssMediaRuleTest.html
trunk/jst/tests/org.jboss.tools.jst.web.kb.test/src/org/jboss/tools/jst/web/kb/test/CSSMediaRuleTest.java
Modified:
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/proposal/CSSClassProposalType.java
trunk/jst/tests/org.jboss.tools.jst.web.kb.test/src/org/jboss/tools/jst/web/kb/test/JstWebKbAllTests.java
Log:
JBIDE-9740
Class cast exception in CA on CSS style classes
Issue is fixed. JUnit test is added
Modified:
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/proposal/CSSClassProposalType.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/proposal/CSSClassProposalType.java 2011-09-20
15:44:41 UTC (rev 34879)
+++
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/proposal/CSSClassProposalType.java 2011-09-20
16:05:43 UTC (rev 34880)
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009 Red Hat, Inc.
+ * Copyright (c) 2009-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,
@@ -17,15 +17,16 @@
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.swt.graphics.Image;
-import org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleRule;
import org.jboss.tools.common.text.TextProposal;
import org.jboss.tools.jst.web.kb.ICSSContainerSupport;
import org.jboss.tools.jst.web.kb.IPageContext;
import org.jboss.tools.jst.web.kb.KbQuery;
+import org.jboss.tools.jst.web.kb.PageContextFactory.CSSStyleSheetDescriptor;
import org.jboss.tools.jst.web.kb.WebKbPlugin;
-import org.jboss.tools.jst.web.kb.PageContextFactory.CSSStyleSheetDescriptor;
+import org.w3c.dom.css.CSSMediaRule;
import org.w3c.dom.css.CSSRule;
import org.w3c.dom.css.CSSRuleList;
+import org.w3c.dom.css.CSSStyleRule;
/**
* The CSS Class proposal type. Is used to collect and return the proposals on
@@ -72,9 +73,21 @@
*/
public static Set<String> getClassNamesFromCSSRule(CSSRule cssRule) {
Set<String> styleNames = new
TreeSet<String>(String.CASE_INSENSITIVE_ORDER);
+
+ if (cssRule instanceof CSSMediaRule) {
+ CSSMediaRule cssMediaRule = (CSSMediaRule)cssRule;
+ CSSRuleList rules = cssMediaRule.getCssRules();
+ for (int i = 0; rules != null && i < rules.getLength(); i++) {
+ CSSRule rule = rules.item(i);
+ styleNames.addAll(getClassNamesFromCSSRule(rule));
+ }
+ return styleNames;
+ }
+ if (!(cssRule instanceof CSSStyleRule))
+ return styleNames;
// get selector text
- String selectorText = ((ICSSStyleRule) cssRule).getSelectorText();
+ String selectorText = ((CSSStyleRule) cssRule).getSelectorText();
if (selectorText != null) {
String styles[] = selectorText.trim().split(","); //$NON-NLS-1$
Added:
trunk/jst/tests/org.jboss.tools.jst.web.kb.test/projects/TestKbModel/WebContent/pages/cssMediaRuleTest.html
===================================================================
---
trunk/jst/tests/org.jboss.tools.jst.web.kb.test/projects/TestKbModel/WebContent/pages/cssMediaRuleTest.html
(rev 0)
+++
trunk/jst/tests/org.jboss.tools.jst.web.kb.test/projects/TestKbModel/WebContent/pages/cssMediaRuleTest.html 2011-09-20
16:05:43 UTC (rev 34880)
@@ -0,0 +1,22 @@
+<html>
+<head>
+<style>
+@media screen
+ {
+ p.test {font-family:verdana,sans-serif;font-size:14px;}
+ }
+@media print
+ {
+ p.test {font-family:times,serif;font-size:10px;}
+ }
+@media screen,print
+ {
+ p.test {font-weight:bold;}
+ }
+</style>
+</head>
+
+<body>
+<p class="">p</p>
+</body>
+</html>
\ No newline at end of file
Property changes on:
trunk/jst/tests/org.jboss.tools.jst.web.kb.test/projects/TestKbModel/WebContent/pages/cssMediaRuleTest.html
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added:
trunk/jst/tests/org.jboss.tools.jst.web.kb.test/src/org/jboss/tools/jst/web/kb/test/CSSMediaRuleTest.java
===================================================================
---
trunk/jst/tests/org.jboss.tools.jst.web.kb.test/src/org/jboss/tools/jst/web/kb/test/CSSMediaRuleTest.java
(rev 0)
+++
trunk/jst/tests/org.jboss.tools.jst.web.kb.test/src/org/jboss/tools/jst/web/kb/test/CSSMediaRuleTest.java 2011-09-20
16:05:43 UTC (rev 34880)
@@ -0,0 +1,64 @@
+/*******************************************************************************
+ * Copyright (c) 2009-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.web.kb.test;
+
+import junit.framework.TestCase;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.jboss.tools.common.el.core.resolver.ELContext;
+import org.jboss.tools.common.text.TextProposal;
+import org.jboss.tools.jst.web.kb.KbQuery;
+import org.jboss.tools.jst.web.kb.KbQuery.Type;
+import org.jboss.tools.jst.web.kb.PageContextFactory;
+import org.jboss.tools.jst.web.kb.PageProcessor;
+
+/**
+ * The JUnit test case for JBIDE-9740 issue
+ *
+ * @author Victor V. Rubezhny
+ *
+ */
+public class CSSMediaRuleTest extends TestCase {
+
+ private IProject testProject;
+
+ protected void setUp() throws Exception {
+ if(testProject==null) {
+ testProject =
ResourcesPlugin.getWorkspace().getRoot().getProject("TestKbModel");
+ }
+ }
+
+ public void testCSSMediaRule() {
+ assertNotNull("Can't load TestKbModel", testProject); //$NON-NLS-1$
+
+ IFile file = testProject.getFile("WebContent/pages/cssMediaRuleTest.html");
+ ELContext context = PageContextFactory.createPageContext(file);
+ KbQuery query = new KbQuery();
+ query.setMask(true);
+ query.setOffset(266);
+ query.setType(Type.ATTRIBUTE_VALUE);
+ query.setValue("");
+ query.setStringQuery("\"");
+ query.setParentTags(new String[] {"html", "body", "p"});
+ query.setParent("class");
+
+ TextProposal[] proposals = PageProcessor.getInstance().getProposals(query, context,
true);
+ boolean ok = false;
+ for (TextProposal proposal : proposals) {
+ if("test".equals(proposal.getReplacementString())) {
+ ok = true;
+ }
+ }
+ assertTrue("Can't find 'test' Media CSS Rule proposal.", ok);
+ }
+}
Property changes on:
trunk/jst/tests/org.jboss.tools.jst.web.kb.test/src/org/jboss/tools/jst/web/kb/test/CSSMediaRuleTest.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Modified:
trunk/jst/tests/org.jboss.tools.jst.web.kb.test/src/org/jboss/tools/jst/web/kb/test/JstWebKbAllTests.java
===================================================================
---
trunk/jst/tests/org.jboss.tools.jst.web.kb.test/src/org/jboss/tools/jst/web/kb/test/JstWebKbAllTests.java 2011-09-20
15:44:41 UTC (rev 34879)
+++
trunk/jst/tests/org.jboss.tools.jst.web.kb.test/src/org/jboss/tools/jst/web/kb/test/JstWebKbAllTests.java 2011-09-20
16:05:43 UTC (rev 34880)
@@ -1,12 +1,12 @@
/*******************************************************************************
- * Copyright (c) 2009 Exadel, Inc. and Red Hat, Inc.
+ * Copyright (c) 2009-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:
- * Exadel, Inc. and Red Hat, Inc. - initial API and implementation
+ * Red Hat, Inc. - initial API and implementation
******************************************************************************/
package org.jboss.tools.jst.web.kb.test;
@@ -41,6 +41,7 @@
suite.addTestSuite(WebKbTest.class);
suite.addTestSuite(KbModelWithSeveralJarCopiesTest.class);
suite.addTestSuite(XMLCatalogTest.class);
+ suite.addTestSuite(CSSMediaRuleTest.class);
testSetup = new XProjectImportTestSetUp(suite,
"org.jboss.tools.jst.web.kb.test",
new String[]{"projects/TestKbModel", "projects/MyFaces",
"projects/MyFaces2", "projects/TestKbModel3",
"projects/TestKbModel4"},