Author: yradtsevich
Date: 2013-01-10 14:43:55 -0500 (Thu, 10 Jan 2013)
New Revision: 44655
Added:
branches/jbosstools-3.3.x/vpe/tests/org.jboss.tools.vpe.test/src/org/jboss/tools/vpe/editor/util/
branches/jbosstools-3.3.x/vpe/tests/org.jboss.tools.vpe.test/src/org/jboss/tools/vpe/editor/util/VpeStyleUtilTest.java
Modified:
branches/jbosstools-3.3.x/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/util/VpeStyleUtil.java
branches/jbosstools-3.3.x/vpe/tests/org.jboss.tools.vpe.test/src/org/jboss/tools/vpe/test/VpeAllImportantTests.java
Log:
JBIDE-12847 VPE throws StackOverflowError and visual part is blank
Applied changes from JBIDE-12308 to jbosstools-3.3.x branch.
Modified:
branches/jbosstools-3.3.x/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/util/VpeStyleUtil.java
===================================================================
---
branches/jbosstools-3.3.x/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/util/VpeStyleUtil.java 2013-01-10
18:13:41 UTC (rev 44654)
+++
branches/jbosstools-3.3.x/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/util/VpeStyleUtil.java 2013-01-10
19:43:55 UTC (rev 44655)
@@ -89,7 +89,8 @@
/*
* Pattern "|(//.*)" could be added at the end to remove single line
comments.
*/
- public static final Pattern CSS_COMMENT_PATTERN =
Pattern.compile("(/\\*([^*]|["+LINE_SEPARATOR+"]|(\\*+([^*/]|["+LINE_SEPARATOR+"])))*\\*+/)");
//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ private static final String CSS_COMMENT_END = "*/"; //$NON-NLS-1$
+ private static final String CSS_COMMENT_START = "/*"; //$NON-NLS-1$
public static String ATTR_URL = "url"; //$NON-NLS-1$
public static String OPEN_BRACKET = "("; //$NON-NLS-1$
@@ -949,12 +950,27 @@
}
/**
- * Removes all the CSS comments from the text
+ * Removes all the CSS comments from the text.
*
- * @param cssText the css text
+ * @param css the CSS text
* @return updated string
*/
public static String removeAllCssComments(String cssText) {
- return CSS_COMMENT_PATTERN.matcher(cssText).replaceAll(Constants.EMPTY);
+ // It is too expensive to use regular expressions here, this is why they are not used.
See JBIDE-12308
+
+ StringBuilder cssBuilder = new StringBuilder(cssText);
+ int curIndex = 0;
+ int commentStartIndex;
+ while ((commentStartIndex = cssBuilder.indexOf(CSS_COMMENT_START, curIndex)) >= 0)
{
+ int afterCommentEndIndex = cssBuilder.indexOf(CSS_COMMENT_END, commentStartIndex +
CSS_COMMENT_START.length());
+ if (afterCommentEndIndex >= 0) {
+ afterCommentEndIndex += CSS_COMMENT_END.length();
+ } else {
+ afterCommentEndIndex = cssBuilder.length();
+ }
+ cssBuilder.replace(commentStartIndex, afterCommentEndIndex, " ");
//$NON-NLS-1$
+ curIndex = commentStartIndex + 1;
+ }
+ return cssBuilder.toString();
}
}
\ No newline at end of file
Added:
branches/jbosstools-3.3.x/vpe/tests/org.jboss.tools.vpe.test/src/org/jboss/tools/vpe/editor/util/VpeStyleUtilTest.java
===================================================================
---
branches/jbosstools-3.3.x/vpe/tests/org.jboss.tools.vpe.test/src/org/jboss/tools/vpe/editor/util/VpeStyleUtilTest.java
(rev 0)
+++
branches/jbosstools-3.3.x/vpe/tests/org.jboss.tools.vpe.test/src/org/jboss/tools/vpe/editor/util/VpeStyleUtilTest.java 2013-01-10
19:43:55 UTC (rev 44655)
@@ -0,0 +1,29 @@
+/*******************************************************************************
+ * Copyright (c) 2007-2012 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
+ *
+ * Contributor:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.vpe.editor.util;
+
+import junit.framework.TestCase;
+
+public class VpeStyleUtilTest extends TestCase {
+
+ @SuppressWarnings("nls")
+ public void testRemoveAllCssComments() {
+ assertEquals("", VpeStyleUtil.removeAllCssComments(""));
+ assertEquals(" ", VpeStyleUtil.removeAllCssComments("/*"));
+ assertEquals(" ", VpeStyleUtil.removeAllCssComments("/**/"));
+ assertEquals(" ", VpeStyleUtil.removeAllCssComments("/*/**/"));
+ assertEquals(" ", VpeStyleUtil.removeAllCssComments("/*//**/"));
+ assertEquals(" dddd ",
VpeStyleUtil.removeAllCssComments("/*abcv*/dddd/**/"));
+ assertEquals("bvc dddd ",
VpeStyleUtil.removeAllCssComments("bvc/*abcv*/dddd/**/"));
+ assertEquals("bvc dddd ",
VpeStyleUtil.removeAllCssComments("bvc/*abcv*/dddd/*"));
+ }
+
+}
Modified:
branches/jbosstools-3.3.x/vpe/tests/org.jboss.tools.vpe.test/src/org/jboss/tools/vpe/test/VpeAllImportantTests.java
===================================================================
---
branches/jbosstools-3.3.x/vpe/tests/org.jboss.tools.vpe.test/src/org/jboss/tools/vpe/test/VpeAllImportantTests.java 2013-01-10
18:13:41 UTC (rev 44654)
+++
branches/jbosstools-3.3.x/vpe/tests/org.jboss.tools.vpe.test/src/org/jboss/tools/vpe/test/VpeAllImportantTests.java 2013-01-10
19:43:55 UTC (rev 44655)
@@ -11,6 +11,7 @@
package org.jboss.tools.vpe.test;
import org.jboss.tools.vpe.editor.template.VpeTemplateManagerTest;
+import org.jboss.tools.vpe.editor.util.VpeStyleUtilTest;
import junit.framework.Test;
import junit.framework.TestSuite;
@@ -25,6 +26,7 @@
public static Test suite() {
TestSuite suite = new TestSuite(VpeAllImportantTests.class.getName());
//$JUnit-BEGIN$
+ suite.addTestSuite(VpeStyleUtilTest.class);
suite.addTestSuite(TemplateLoadingTest.class);
suite.addTestSuite(TemplateSchemeValidateTest.class);
suite.addTestSuite(TemplatesExpressionParsingTest.class);