Author: vrubezhny
Date: 2011-10-13 13:32:25 -0400 (Thu, 13 Oct 2011)
New Revision: 35631
Added:
trunk/jst/tests/org.jboss.tools.jst.jsp.test/src/org/jboss/tools/jst/jsp/test/ca/CAMultipleCSSClassesInsertionTest.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.jsp.test/src/org/jboss/tools/jst/jsp/test/JstJspAllTests.java
Log:
JBIDE-9752 Content Assist for CSS class names doesn't allow to enter more that one CSS
class name (it always replaces the first typed CSS class name)
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-10-13
17:04:25 UTC (rev 35630)
+++
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/proposal/CSSClassProposalType.java 2011-10-13
17:32:25 UTC (rev 35631)
@@ -35,7 +35,6 @@
* @author Victor Rubezhny
*
*/
-@SuppressWarnings("restriction")
public class CSSClassProposalType extends CustomProposalType {
private static final String IMAGE_NAME = "EnumerationProposal.gif";
//$NON-NLS-1$
private static Image ICON;
@@ -127,14 +126,19 @@
@Override
public TextProposal[] getProposals(KbQuery query) {
- String v = query.getValue();
- int offset = v.length();
- int b = v.lastIndexOf(',');
- if(b < 0) b = 0; else b += 1;
- String tail = v.substring(offset);
- int e = tail.indexOf(',');
- if(e < 0) e = v.length(); else e += offset;
- String prefix = v.substring(b).trim();
+ // Do not use getValue() because it trims the string and removes opening quote char,
but all the characters
+ // (including whitespaces and quotes) are valuable here
+ String v = query.getStringQuery(); //query.getValue();
+ int predicateLength = 0;
+ while(predicateLength < v.length() && (v.charAt(predicateLength) ==
'"' || v.charAt(predicateLength) == '\''))
+ predicateLength++;
+
+ int b = v.lastIndexOf(' ');
+ b = (b == -1 ? v.lastIndexOf('\t') : b);
+ b = (b == -1 ? predicateLength : b + 1);
+ int e = v.length();
+
+ String prefix = v.substring(b);
List<TextProposal> proposals = new ArrayList<TextProposal>();
for (String text: idList) {
@@ -142,9 +146,9 @@
TextProposal proposal = new TextProposal();
proposal.setLabel(text);
proposal.setReplacementString(text);
- proposal.setPosition(b + text.length());
- proposal.setStart(b);
- proposal.setEnd(e);
+ proposal.setPosition(b + text.length() - predicateLength);
+ proposal.setStart(b - predicateLength);
+ proposal.setEnd(e - predicateLength);
if(ICON==null) {
ICON = ImageDescriptor.createFromFile(WebKbPlugin.class, IMAGE_NAME).createImage();
}
Modified:
trunk/jst/tests/org.jboss.tools.jst.jsp.test/src/org/jboss/tools/jst/jsp/test/JstJspAllTests.java
===================================================================
---
trunk/jst/tests/org.jboss.tools.jst.jsp.test/src/org/jboss/tools/jst/jsp/test/JstJspAllTests.java 2011-10-13
17:04:25 UTC (rev 35630)
+++
trunk/jst/tests/org.jboss.tools.jst.jsp.test/src/org/jboss/tools/jst/jsp/test/JstJspAllTests.java 2011-10-13
17:32:25 UTC (rev 35631)
@@ -13,6 +13,7 @@
import junit.framework.Test;
import junit.framework.TestSuite;
+import org.jboss.tools.jst.jsp.test.ca.CAMultipleCSSClassesInsertionTest;
import org.jboss.tools.jst.jsp.test.ca.Jbide1791Test;
import org.jboss.tools.jst.jsp.test.ca.Jbide6061Test;
import org.jboss.tools.jst.jsp.test.ca.Jbide9092Test;
@@ -30,8 +31,12 @@
Jbide6061Test.class),
"org.jboss.tools.jst.jsp.test", "projects/Jbide6061Test",
//$NON-NLS-1$ //$NON-NLS-2$
"Jbide6061Test")); //$NON-NLS-1$
+ suite.addTest(new ProjectImportTestSetup(new TestSuite(
+ CAMultipleCSSClassesInsertionTest.class),
+ "org.jboss.tools.jst.jsp.test", "projects/Jbide6061Test",
//$NON-NLS-1$ //$NON-NLS-2$
+ "Jbide6061Test")); //$NON-NLS-1$
- suite.addTestSuite(JstJspJbide1585Test.class);
+ suite.addTestSuite(JstJspJbide1585Test.class);
suite.addTestSuite(JstJspJbide1641Test.class);
suite.addTestSuite(Jbide1791Test.class);
Added:
trunk/jst/tests/org.jboss.tools.jst.jsp.test/src/org/jboss/tools/jst/jsp/test/ca/CAMultipleCSSClassesInsertionTest.java
===================================================================
---
trunk/jst/tests/org.jboss.tools.jst.jsp.test/src/org/jboss/tools/jst/jsp/test/ca/CAMultipleCSSClassesInsertionTest.java
(rev 0)
+++
trunk/jst/tests/org.jboss.tools.jst.jsp.test/src/org/jboss/tools/jst/jsp/test/ca/CAMultipleCSSClassesInsertionTest.java 2011-10-13
17:32:25 UTC (rev 35631)
@@ -0,0 +1,213 @@
+/*******************************************************************************
+ * 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
+ *
+ * Contributor:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.jst.jsp.test.ca;
+
+import java.util.List;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.jface.text.FindReplaceDocumentAdapter;
+import org.eclipse.jface.text.IRegion;
+import org.eclipse.jface.text.contentassist.ICompletionProposal;
+import org.jboss.tools.common.base.test.contentassist.CATestUtil;
+import org.jboss.tools.jst.jsp.contentassist.AutoContentAssistantProposal;
+import org.jboss.tools.test.util.JobUtils;
+
+/**
+ * The JUnit test case for JBIDE-9752 issue
+ *
+ * @author Victor V. Rubezhny
+ *
+ */
+public class CAMultipleCSSClassesInsertionTest extends ContentAssistantTestCase {
+ private static final String PROJECT_NAME = "Jbide6061Test"; //$NON-NLS-1$
+ private static final String PAGE_NAME = "/WebContent/pages/jsp_page.jsp";
//$NON-NLS-1$
+
+ private final String[] CSSCLASS_PROPOSALS = new String[]{
+ "errors", //$NON-NLS-1$
+ "cls1", //$NON-NLS-1$
+ "cls2", //$NON-NLS-1$
+ "cls3", //$NON-NLS-1$
+ "cls4", //$NON-NLS-1$
+ "cls5" //$NON-NLS-1$
+ };
+
+ private static final String STRING_TO_FIND = "class=\"";
+ private static final String FILTERING_INITIAL_VALUE = "errors cls1";
+ private static final String[] FILTERING_CSSCLASS_PROPOSALS = new String[]{
+ "errors", //$NON-NLS-1$
+ "cls1", //$NON-NLS-1$
+ };
+ private static final int FILTER_LENGTH = 3;
+
+ public static Test suite() {
+ return new TestSuite(CAMultipleCSSClassesInsertionTest.class);
+ }
+
+ public void setUp() throws Exception {
+ project = ResourcesPlugin.getWorkspace().getRoot().getProject(PROJECT_NAME);
+ }
+
+ public void testCAMultipleCSSClassesInsertion(){
+ openEditor(PAGE_NAME);
+ try {
+ for (int i = 0; i < CSSCLASS_PROPOSALS.length; i++) {
+ doCAMultipleCSSClassesInsertionTest(CSSCLASS_PROPOSALS[i]);
+ }
+ } finally {
+ closeEditor();
+ }
+ }
+
+ public void testCAMultipleCSSClassesInsertionWithFilter(){
+ openEditor(PAGE_NAME);
+ try {
+ for (int i = 0; i < FILTERING_CSSCLASS_PROPOSALS.length; i++) {
+ doCAMultipleCSSClassesInsertionWithFilterTest(FILTERING_CSSCLASS_PROPOSALS[i]);
+ }
+ } finally {
+ closeEditor();
+ }
+ }
+
+
+ @SuppressWarnings("restriction")
+ protected void doCAMultipleCSSClassesInsertionTest(String proposalToApply) {
+ String documentContent = document.get();
+ assertNotNull("Document must not be null", document);
+
+ IRegion reg=null;
+ try {
+ reg = new FindReplaceDocumentAdapter(this.document).find(0, STRING_TO_FIND, true,
false, false, false); //$NON-NLS-1$
+ } catch (BadLocationException e) {
+ fail("Cannot find start of value text: " + e.getLocalizedMessage());
+ }
+ assertNotNull("Cannot find a text region to test", reg);
+ int start = reg.getOffset() + STRING_TO_FIND.length();
+
+ try {
+ reg = new FindReplaceDocumentAdapter(this.document).find(start, "\"",
true, false, false, false); //$NON-NLS-1$
+ } catch (BadLocationException e) {
+ fail("Cannot find end of value text: " + e.getLocalizedMessage());
+ }
+ assertNotNull("Cannot find a text region to test", reg);
+ int end = reg.getOffset();
+
+ // insert space character if it's not first value
+ if (documentContent.substring(start, end).trim().length() > 0) {
+ documentContent = documentContent.substring(0, end) + ' ' +
+ documentContent.substring(end);
+ document.set(documentContent);
+ end++;
+ JobUtils.waitForIdle();
+ }
+
+ String documentContentToCompare = documentContent.substring(0, end) + proposalToApply
+
+ documentContent.substring(end);
+
+ List<ICompletionProposal> res = CATestUtil.collectProposals(contentAssistant,
viewer, end);
+
+ assertTrue("Content Assistant returned no proposals", (res != null
&& res.size() > 0));
+
+ boolean bPropoosalToApplyFound = false;
+ for (ICompletionProposal p : res) {
+ if (!(p instanceof AutoContentAssistantProposal))
+ continue;
+ AutoContentAssistantProposal proposal = (AutoContentAssistantProposal)p;
+ String proposalString = proposal.getDisplayString();
+
+ if (proposalToApply.equals(proposalString)) {
+ bPropoosalToApplyFound = true;
+ proposal.apply(document);
+ JobUtils.waitForIdle();
+ break;
+ }
+ }
+ assertTrue("The proposal to apply not found.", bPropoosalToApplyFound);
+
+ String documentUpdatedContent = document.get();
+ assertTrue("The proposal replacement is failed.",
documentContentToCompare.equals(documentUpdatedContent));
+ }
+
+ protected void doCAMultipleCSSClassesInsertionWithFilterTest(String proposalToApply){
+ String documentContent = document.get();
+ assertNotNull("Document must not be null", document);
+
+ IRegion reg=null;
+ try {
+ reg = new FindReplaceDocumentAdapter(this.document).find(0, STRING_TO_FIND, true,
false, false, false); //$NON-NLS-1$
+ } catch (BadLocationException e) {
+ fail("Cannot find start of value text: " + e.getLocalizedMessage());
+ }
+ assertNotNull("Cannot find a text region to test", reg);
+ int start = reg.getOffset() + STRING_TO_FIND.length();
+
+ try {
+ reg = new FindReplaceDocumentAdapter(this.document).find(start, "\"",
true, false, false, false); //$NON-NLS-1$
+ } catch (BadLocationException e) {
+ fail("Cannot find end of value text: " + e.getLocalizedMessage());
+ }
+ assertNotNull("Cannot find a text region to test", reg);
+ int end = reg.getOffset();
+
+ // Make initial value of CSS Class attribute
+ documentContent = documentContent.substring(0, start) + FILTERING_INITIAL_VALUE +
+ documentContent.substring(end);
+ document.set(documentContent);
+ JobUtils.waitForIdle();
+
+ // Find end of value again after the document modification
+ try {
+ reg = new FindReplaceDocumentAdapter(this.document).find(start, "\"",
true, false, false, false); //$NON-NLS-1$
+ } catch (BadLocationException e) {
+ fail("Cannot find end of value text: " + e.getLocalizedMessage());
+ }
+ assertNotNull("Cannot find a text region to test", reg);
+ end = reg.getOffset();
+
+ // Find start position in attribute value part which equals to the proposal
+ try {
+ reg = new FindReplaceDocumentAdapter(this.document).find(start, proposalToApply,
true, false, false, false); //$NON-NLS-1$
+ } catch (BadLocationException e) {
+ fail("Cannot find end of value text: " + e.getLocalizedMessage());
+ }
+ int templateStart = reg.getOffset();
+
+ String documentContentToCompare = documentContent.substring(0, templateStart +
FILTER_LENGTH) + proposalToApply.substring(FILTER_LENGTH) +
+ documentContent.substring(templateStart + FILTER_LENGTH);
+
+ List<ICompletionProposal> res = CATestUtil.collectProposals(contentAssistant,
viewer, templateStart + FILTER_LENGTH);
+
+ assertTrue("Content Assistant returned no proposals", (res != null
&& res.size() > 0));
+
+ boolean bPropoosalToApplyFound = false;
+ for (ICompletionProposal p : res) {
+ if (!(p instanceof AutoContentAssistantProposal))
+ continue;
+ AutoContentAssistantProposal proposal = (AutoContentAssistantProposal)p;
+ String proposalString = proposal.getDisplayString();
+
+ if (proposalToApply.equals(proposalString)) {
+ bPropoosalToApplyFound = true;
+ proposal.apply(document);
+ JobUtils.waitForIdle();
+ break;
+ }
+ }
+ assertTrue("The proposal to apply not found.", bPropoosalToApplyFound);
+
+ String documentUpdatedContent = document.get();
+ assertTrue("The proposal replacement is failed.",
documentContentToCompare.equals(documentUpdatedContent));
+ }
+}
\ No newline at end of file
Property changes on:
trunk/jst/tests/org.jboss.tools.jst.jsp.test/src/org/jboss/tools/jst/jsp/test/ca/CAMultipleCSSClassesInsertionTest.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain