Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNitin Dahyabhai2020-04-29 04:07:08 +0000
committerNitin Dahyabhai2020-04-29 04:13:42 +0000
commitf0ce6f744cd190bcac0e4bfbe59939de96d56ae6 (patch)
tree61efc744ca140055b29d667bdb509f3d86ca6356
parent00d147db5fb7fdf7a445bca69c5bd1b000903231 (diff)
downloadwebtools.sourceediting-f0ce6f744cd190bcac0e4bfbe59939de96d56ae6.tar.gz
webtools.sourceediting-f0ce6f744cd190bcac0e4bfbe59939de96d56ae6.tar.xz
webtools.sourceediting-f0ce6f744cd190bcac0e4bfbe59939de96d56ae6.zip
[81634] content assist does not recognize preceding chars
-rw-r--r--web/tests/org.eclipse.wst.css.ui.tests/src/org/eclipse/wst/css/ui/tests/contentassist/TestCSSContentAssistComputers.java18
-rw-r--r--xml/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentassist/AbstractXMLCompletionProposalComputer.java20
-rw-r--r--xml/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentassist/AbstractXMLModelQueryCompletionProposalComputer.java6
-rw-r--r--xml/tests/org.eclipse.wst.xml.ui.tests/src/org/eclipse/wst/xml/ui/tests/contentassist/TestXMLContentAssistComputers.java83
-rw-r--r--xml/tests/org.eclipse.wst.xml.ui.tests/testresources/contentassist/test3.xml6
-rw-r--r--xml/tests/org.eclipse.wst.xml.ui.tests/testresources/contentassist/test3after.xml6
6 files changed, 113 insertions, 26 deletions
diff --git a/web/tests/org.eclipse.wst.css.ui.tests/src/org/eclipse/wst/css/ui/tests/contentassist/TestCSSContentAssistComputers.java b/web/tests/org.eclipse.wst.css.ui.tests/src/org/eclipse/wst/css/ui/tests/contentassist/TestCSSContentAssistComputers.java
index ba361e4931..c2a79282dd 100644
--- a/web/tests/org.eclipse.wst.css.ui.tests/src/org/eclipse/wst/css/ui/tests/contentassist/TestCSSContentAssistComputers.java
+++ b/web/tests/org.eclipse.wst.css.ui.tests/src/org/eclipse/wst/css/ui/tests/contentassist/TestCSSContentAssistComputers.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2010, 2018 IBM Corporation and others.
+ * Copyright (c) 2010, 2020 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
@@ -19,7 +19,7 @@ import java.util.Iterator;
import java.util.Map;
import junit.extensions.TestSetup;
-import junit.framework.Assert;
+import org.junit.Assert;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
@@ -54,13 +54,13 @@ public class TestCSSContentAssistComputers extends TestCase {
private static final String PROJECT_FILES = "/testresources/contentassist";
/** The project that all of the tests use */
- private static IProject fProject;
+ static IProject fProject;
/**
* Used to keep track of the already open editors so that the tests don't go through
* the trouble of opening the same editors over and over again
*/
- private static Map fFileToEditorMap = new HashMap();
+ static Map<IFile, StructuredTextEditor> fFileToEditorMap = new HashMap<>();
/**
* <p>Default constructor<p>
@@ -219,9 +219,9 @@ public class TestCSSContentAssistComputers extends TestCase {
//fire content assist session ending
Method privateFireSessionEndEventMethod = ContentAssistant.class.
- getDeclaredMethod("fireSessionEndEvent", null);
+ getDeclaredMethod("fireSessionEndEvent");
privateFireSessionEndEventMethod.setAccessible(true);
- privateFireSessionEndEventMethod.invoke(contentAssistant, null);
+ privateFireSessionEndEventMethod.invoke(contentAssistant);
return pages;
}
@@ -274,7 +274,7 @@ public class TestCSSContentAssistComputers extends TestCase {
* @return <code>StructuredTextEditor</code> opened from the given <code>file</code>
*/
private static StructuredTextEditor getEditor(IFile file) {
- StructuredTextEditor editor = (StructuredTextEditor)fFileToEditorMap.get(file);
+ StructuredTextEditor editor = fFileToEditorMap.get(file);
if(editor == null) {
try {
@@ -363,9 +363,9 @@ public class TestCSSContentAssistComputers extends TestCase {
*/
public void tearDown() throws Exception {
//close out the editors
- Iterator iter = fFileToEditorMap.values().iterator();
+ Iterator<StructuredTextEditor> iter = fFileToEditorMap.values().iterator();
while(iter.hasNext()) {
- StructuredTextEditor editor = (StructuredTextEditor)iter.next();
+ StructuredTextEditor editor = iter.next();
editor.doSave(null);
editor.close(false);
}
diff --git a/xml/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentassist/AbstractXMLCompletionProposalComputer.java b/xml/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentassist/AbstractXMLCompletionProposalComputer.java
index 2b3c0217cc..66038ffd79 100644
--- a/xml/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentassist/AbstractXMLCompletionProposalComputer.java
+++ b/xml/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentassist/AbstractXMLCompletionProposalComputer.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2010, 2012 IBM Corporation and others.
+ * Copyright (c) 2010, 2010 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
@@ -22,6 +22,8 @@ import java.util.Properties;
import java.util.Vector;
import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.ITextViewer;
import org.eclipse.jface.text.contentassist.ICompletionProposal;
import org.eclipse.wst.sse.core.StructuredModelManager;
@@ -131,7 +133,7 @@ public abstract class AbstractXMLCompletionProposalComputer implements ICompleti
}
if (sModel != null) {
IDOMDocument docNode = ((IDOMModel) sModel).getDocument();
- contentAssistRequest = new ContentAssistRequest(docNode, docNode, sdRegion, completionRegion, documentPosition, 0, null);
+ contentAssistRequest = new ContentAssistRequest(docNode, docNode, sdRegion, completionRegion, documentPosition - matchString.length(), matchString.length(), null);
addEmptyDocumentProposals(contentAssistRequest, context);
}
}
@@ -606,7 +608,7 @@ public abstract class AbstractXMLCompletionProposalComputer implements ICompleti
ContentAssistRequest contentAssistRequest = null;
// setup to add children at the content node's position
- contentAssistRequest = new ContentAssistRequest(nodeAtOffset, node, getStructuredDocumentRegion(documentPosition), completionRegion, documentPosition, 0, matchString);
+ contentAssistRequest = new ContentAssistRequest(nodeAtOffset, node, getStructuredDocumentRegion(documentPosition), completionRegion, documentPosition - matchString.length(), matchString.length(), matchString);
if ((node != null) && (node.getNodeType() == Node.DOCUMENT_NODE) && (((Document) node).getDoctype() == null)) {
addStartDocumentProposals(contentAssistRequest, context);
}
@@ -1051,8 +1053,20 @@ public abstract class AbstractXMLCompletionProposalComputer implements ICompleti
matchString = ""; //$NON-NLS-1$
}
else if (regionType == DOMRegionContext.XML_CONTENT) {
+ int start = offset;
+ int end = offset;
+ IDocument document = parent.getParentDocument();
+ try {
+ while (start >= 0 && !Character.isWhitespace(document.getChar(start - 1))) {
+ start--;
+ }
+ matchString = document.get(start, end - start);
+ }
+ catch (BadLocationException e) {
+ Logger.logException(e);
matchString = ""; //$NON-NLS-1$
}
+ }
else {
if ((parent.getText(aRegion).length() > 0) && (parent.getStartOffset(aRegion) < offset)) {
matchString = parent.getText(aRegion).substring(0, offset - parent.getStartOffset(aRegion));
diff --git a/xml/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentassist/AbstractXMLModelQueryCompletionProposalComputer.java b/xml/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentassist/AbstractXMLModelQueryCompletionProposalComputer.java
index 6a789e4424..eb147d44e8 100644
--- a/xml/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentassist/AbstractXMLModelQueryCompletionProposalComputer.java
+++ b/xml/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentassist/AbstractXMLModelQueryCompletionProposalComputer.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2010, 2012 IBM Corporation and others.
+ * Copyright (c) 2010, 2020 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
@@ -1010,6 +1010,10 @@ public abstract class AbstractXMLModelQueryCompletionProposalComputer extends Ab
}
String proposedText = getRequiredText(parent, ed);
String tagname = getRequiredName(parent, ed);
+ // check against match string
+ if (!tagname.toLowerCase(Locale.ENGLISH).contains(contentAssistRequest.getMatchString().toLowerCase(Locale.ENGLISH)))
+ continue;
+
// account for the &lt; and &gt;
int markupAdjustment = getContentGenerator().getMinimalStartTagLength(parent, ed);
String proposedInfo = getAdditionalInfo(null, ed);
diff --git a/xml/tests/org.eclipse.wst.xml.ui.tests/src/org/eclipse/wst/xml/ui/tests/contentassist/TestXMLContentAssistComputers.java b/xml/tests/org.eclipse.wst.xml.ui.tests/src/org/eclipse/wst/xml/ui/tests/contentassist/TestXMLContentAssistComputers.java
index a4132619f1..59156b8349 100644
--- a/xml/tests/org.eclipse.wst.xml.ui.tests/src/org/eclipse/wst/xml/ui/tests/contentassist/TestXMLContentAssistComputers.java
+++ b/xml/tests/org.eclipse.wst.xml.ui.tests/src/org/eclipse/wst/xml/ui/tests/contentassist/TestXMLContentAssistComputers.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2010, 2017 IBM Corporation and others.
+ * Copyright (c) 2010, 2020 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
@@ -9,7 +9,7 @@
*
* Contributors:
* IBM Corporation - initial API and implementation
- *
+ *
*******************************************************************************/
package org.eclipse.wst.xml.ui.tests.contentassist;
@@ -18,12 +18,9 @@ import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
-import junit.extensions.TestSetup;
-import junit.framework.Assert;
-import junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
-
+import org.eclipse.core.filebuffers.FileBuffers;
+import org.eclipse.core.filebuffers.ITextFileBuffer;
+import org.eclipse.core.filebuffers.LocationKind;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.NullProgressMonitor;
@@ -44,6 +41,12 @@ import org.eclipse.wst.xml.ui.StructuredTextViewerConfigurationXML;
import org.eclipse.wst.xml.ui.internal.tabletree.XMLMultiPageEditorPart;
import org.eclipse.wst.xml.ui.tests.ProjectUtil;
+import junit.extensions.TestSetup;
+import junit.framework.Assert;
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
public class TestXMLContentAssistComputers extends TestCase {
/** The name of the project that all of these tests will use */
private static final String PROJECT_NAME = "TestXMLContentAssistComputers";
@@ -105,6 +108,18 @@ public class TestXMLContentAssistComputers extends TestCase {
runProposalTest("test1.xml", 24, 6, expectedProposalCounts);
}
+ public void testChildElementProposals3() throws Exception {
+ // default page, templates page, tags page, default page again
+ int[] expectedProposalCounts = new int[] {3, 2, 1};
+ runProposalTest("test3.xml", 3, 3, expectedProposalCounts);
+ }
+
+ public void testChildElementAcceptance1() throws Exception {
+ // default page, templates page, tags page, default page again
+ int[] expectedProposalCounts = new int[] {3,2,1};
+ runProposalAcceptanceTest("test3.xml", "test3after.xml", 3, 3, expectedProposalCounts, 0, 0, 258);
+ }
+
public void testAttributeProposals() throws Exception {
// default page, templates page, tags page, default page again
int[] expectedProposalCounts = new int[] {5, 4, 1};
@@ -162,7 +177,7 @@ public class TestXMLContentAssistComputers extends TestCase {
* expected number of proposals.</p>
*
* @param fileName
- * @param lineNum
+ * @param lineNum (0 based)
* @param lineRelativeCharOffset
* @param expectedProposalCounts
* @throws Exception
@@ -182,6 +197,44 @@ public class TestXMLContentAssistComputers extends TestCase {
}
/**
+ * <p>Run a proposal test by opening the given file and invoking content assist for
+ * each expected proposal count at the given line number and line character
+ * offset and then compare the number of proposals for each invocation (pages) to the
+ * expected number of proposals.</p>
+ *
+ * @param beforeFileName
+ * @param lineNum (0 based)
+ * @param lineRelativeCharOffset
+ * @param expectedProposalCounts
+ * @param proposalPage
+ * @param proposalExt2ToAccept
+ * @throws Exception
+ */
+ private static void runProposalAcceptanceTest(String beforeFileName, String afterFileName,
+ int lineNum, int lineRelativeCharOffset,
+ int[] expectedProposalCounts,
+ int proposalPage,
+ int proposalExt2ToAccept,
+ int proposalOffset) throws Exception{
+
+ IFile file = getFile(beforeFileName);
+ StructuredTextEditor editor = getEditor(file);
+ StructuredTextViewer viewer = editor.getTextViewer();
+ int offset = viewer.getDocument().getLineOffset(lineNum) + lineRelativeCharOffset;
+
+ ICompletionProposal[][] pages = getProposals(viewer, offset, expectedProposalCounts.length);
+
+ verifyProposalCounts(pages, expectedProposalCounts);
+
+ ((ICompletionProposalExtension2) pages[proposalPage][proposalExt2ToAccept]).apply(viewer, (char) 0, 0, proposalOffset);
+ FileBuffers.getTextFileBufferManager().connect(getFile(afterFileName).getFullPath(), LocationKind.IFILE, null);
+ ITextFileBuffer buffer = FileBuffers.getTextFileBufferManager().getTextFileBuffer(getFile(afterFileName).getFullPath(), LocationKind.IFILE);
+ String after = buffer.getDocument().get().replace("\r\n", "\n".replace("\r", "\n"));
+ FileBuffers.getTextFileBufferManager().disconnect(getFile(afterFileName).getFullPath(), LocationKind.IFILE, null);
+ assertEquals(after, viewer.getDocument().get().replace("\r\n", "\n").replace("\r", "\n"));
+ }
+
+ /**
* <p>Invoke content assist on the given viewer at the given offset, for the given number of pages
* and return the results of each page</p>
*
@@ -232,10 +285,14 @@ public class TestXMLContentAssistComputers extends TestCase {
*/
private static void verifyProposalCounts(ICompletionProposal[][] pages, int[] expectedProposalCounts) {
StringBuffer error = new StringBuffer();
- for(int page = 0; page < expectedProposalCounts.length; ++page) {
- if(expectedProposalCounts[page] != pages[page].length) {
+ for (int page = 0; page < expectedProposalCounts.length; ++page) {
+ if (expectedProposalCounts[page] != pages[page].length) {
+ String[] displayNames = new String[pages[page].length];
+ for (int i = 0; i < displayNames.length; i++) {
+ displayNames[i] = pages[page][i].getDisplayString();
+ }
error.append("\nProposal page " + page + " did not have the expected number of proposals: was " +
- pages[page].length + " expected " + expectedProposalCounts[page]);
+ pages[page].length + " expected " + expectedProposalCounts[page] + "[" + StringUtils.pack(displayNames) + "]");
}
}
@@ -280,7 +337,7 @@ public class TestXMLContentAssistComputers extends TestCase {
IEditorPart editorPart = IDE.openEditor(page, file, true, true);
if(editorPart instanceof XMLMultiPageEditorPart) {
XMLMultiPageEditorPart xmlEditorPart = (XMLMultiPageEditorPart)editorPart;
- editor = (StructuredTextEditor)xmlEditorPart.getAdapter(StructuredTextEditor.class);
+ editor = xmlEditorPart.getAdapter(StructuredTextEditor.class);
} else if(editorPart instanceof StructuredTextEditor) {
editor = ((StructuredTextEditor)editorPart);
} else {
diff --git a/xml/tests/org.eclipse.wst.xml.ui.tests/testresources/contentassist/test3.xml b/xml/tests/org.eclipse.wst.xml.ui.tests/testresources/contentassist/test3.xml
new file mode 100644
index 0000000000..ab86b284f0
--- /dev/null
+++ b/xml/tests/org.eclipse.wst.xml.ui.tests/testresources/contentassist/test3.xml
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<tns:GolfCountryClub xmlns:tns="http://www.example.org/GolfCountryClub" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.example.org/GolfCountryClub Schema1.xsd ">
+<GolfCourse>
+nam
+</GolfCourse>
+</tns:GolfCountryClub> \ No newline at end of file
diff --git a/xml/tests/org.eclipse.wst.xml.ui.tests/testresources/contentassist/test3after.xml b/xml/tests/org.eclipse.wst.xml.ui.tests/testresources/contentassist/test3after.xml
new file mode 100644
index 0000000000..52eb251b76
--- /dev/null
+++ b/xml/tests/org.eclipse.wst.xml.ui.tests/testresources/contentassist/test3after.xml
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<tns:GolfCountryClub xmlns:tns="http://www.example.org/GolfCountryClub" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.example.org/GolfCountryClub Schema1.xsd ">
+<GolfCourse>
+<Name></Name>
+</GolfCourse>
+</tns:GolfCountryClub> \ No newline at end of file

Back to the top