Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnton Leherbauer2008-03-27 14:10:57 +0000
committerAnton Leherbauer2008-03-27 14:10:57 +0000
commitbfd296013fa98c7dd7f36dd744d3d3434e788031 (patch)
tree408d31b63ef29765604641562ce7bd2d002f567c /core/org.eclipse.cdt.ui.tests
parent2d526547f26d4d85909a87bd71f9f084c0a25c59 (diff)
downloadorg.eclipse.cdt-bfd296013fa98c7dd7f36dd744d3d3434e788031.tar.gz
org.eclipse.cdt-bfd296013fa98c7dd7f36dd744d3d3434e788031.tar.xz
org.eclipse.cdt-bfd296013fa98c7dd7f36dd744d3d3434e788031.zip
113568: [Content Assist] proposals for include directives
Diffstat (limited to 'core/org.eclipse.cdt.ui.tests')
-rw-r--r--core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/contentassist2/AbstractContentAssistTest.java60
-rw-r--r--core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/contentassist2/CompletionTests.java77
2 files changed, 113 insertions, 24 deletions
diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/contentassist2/AbstractContentAssistTest.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/contentassist2/AbstractContentAssistTest.java
index f201f0da458..15d0bb59038 100644
--- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/contentassist2/AbstractContentAssistTest.java
+++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/contentassist2/AbstractContentAssistTest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2004, 2007 IBM Corporation and others.
+ * Copyright (c) 2004, 2008 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -15,14 +15,13 @@ package org.eclipse.cdt.ui.tests.text.contentassist2;
import java.util.ArrayList;
import java.util.Arrays;
-import java.util.HashSet;
import java.util.List;
-import java.util.Set;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.TextUtilities;
import org.eclipse.jface.text.contentassist.ContentAssistant;
import org.eclipse.jface.text.contentassist.ICompletionProposal;
import org.eclipse.jface.text.contentassist.IContextInformation;
@@ -34,17 +33,16 @@ import org.eclipse.ui.texteditor.ITextEditor;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.dom.IPDOMManager;
import org.eclipse.cdt.core.model.ICProject;
-import org.eclipse.cdt.core.parser.KeywordSetKey;
-import org.eclipse.cdt.core.parser.ParserFactory;
-import org.eclipse.cdt.core.parser.ParserLanguage;
import org.eclipse.cdt.core.testplugin.CProjectHelper;
import org.eclipse.cdt.ui.testplugin.CTestPlugin;
import org.eclipse.cdt.ui.tests.BaseUITestCase;
import org.eclipse.cdt.ui.tests.text.EditorTestHelper;
import org.eclipse.cdt.ui.text.ICCompletionProposal;
+import org.eclipse.cdt.ui.text.ICPartitions;
import org.eclipse.cdt.internal.ui.text.contentassist.CCompletionProposal;
import org.eclipse.cdt.internal.ui.text.contentassist.CContentAssistProcessor;
+import org.eclipse.cdt.internal.ui.text.contentassist.RelevanceConstants;
public abstract class AbstractContentAssistTest extends BaseUITestCase {
@@ -57,14 +55,6 @@ public abstract class AbstractContentAssistTest extends BaseUITestCase {
protected ITextEditor fEditor;
private boolean fIsCpp;
- private final static Set fgAllKeywords= new HashSet();
-
- static {
- fgAllKeywords.addAll(ParserFactory.getKeywordSet(KeywordSetKey.KEYWORDS, ParserLanguage.C));
- fgAllKeywords.addAll(ParserFactory.getKeywordSet(KeywordSetKey.TYPES, ParserLanguage.C));
- fgAllKeywords.addAll(ParserFactory.getKeywordSet(KeywordSetKey.KEYWORDS, ParserLanguage.CPP));
- fgAllKeywords.addAll(ParserFactory.getKeywordSet(KeywordSetKey.TYPES, ParserLanguage.CPP));
- }
public AbstractContentAssistTest(String name, boolean isCpp) {
super(name);
fIsCpp= isCpp;
@@ -111,7 +101,8 @@ public abstract class AbstractContentAssistTest extends BaseUITestCase {
//Call the CContentAssistProcessor
ISourceViewer sourceViewer= EditorTestHelper.getSourceViewer((AbstractTextEditor)fEditor);
- String contentType = sourceViewer.getDocument().getContentType(offset);
+ String contentType= TextUtilities.getContentType(sourceViewer.getDocument(), ICPartitions.C_PARTITIONING, offset, true);
+ boolean isCode= IDocument.DEFAULT_CONTENT_TYPE.equals(contentType);
ContentAssistant assistant = new ContentAssistant();
CContentAssistProcessor processor = new CContentAssistProcessor(fEditor, assistant, contentType);
long startTime= System.currentTimeMillis();
@@ -121,7 +112,7 @@ public abstract class AbstractContentAssistTest extends BaseUITestCase {
long endTime= System.currentTimeMillis();
assertTrue(results != null);
- results= filterResults(results);
+ results= filterResults(results, isCode);
String[] resultStrings= toStringArray(results, compareType);
Arrays.sort(expected);
Arrays.sort(resultStrings);
@@ -167,22 +158,31 @@ public abstract class AbstractContentAssistTest extends BaseUITestCase {
/**
* Filter out template and keyword proposals.
* @param results
+ * @param isCodeCompletion completion is in code, not preprocessor, etc.
* @return filtered proposals
*/
- private Object[] filterResults(Object[] results) {
- List filtered= new ArrayList();
+ private Object[] filterResults(Object[] results, boolean isCodeCompletion) {
+ List<Object> filtered= new ArrayList<Object>();
for (int i = 0; i < results.length; i++) {
Object result = results[i];
if (result instanceof TemplateProposal) {
continue;
}
if (result instanceof ICCompletionProposal) {
- // check for keywords proposal
- if (fgAllKeywords.contains(((ICCompletionProposal)result).getDisplayString())) {
- continue;
+ if (isCodeCompletion) {
+ // check for keywords proposal
+ int relevance = ((ICCompletionProposal)result).getRelevance();
+ if (relevance >= RelevanceConstants.CASE_MATCH_RELEVANCE) {
+ relevance -= RelevanceConstants.CASE_MATCH_RELEVANCE;
+ }
+ if (relevance <= RelevanceConstants.KEYWORD_TYPE_RELEVANCE) {
+ continue;
+ }
}
+ filtered.add(result);
+ } else if (result instanceof IContextInformation) {
+ filtered.add(result);
}
- filtered.add(result);
}
return filtered.toArray();
}
@@ -191,7 +191,7 @@ public abstract class AbstractContentAssistTest extends BaseUITestCase {
String[] strings= new String[results.length];
for(int i=0; i< results.length; i++){
Object result = results[i];
- if (result instanceof ICompletionProposal) {
+ if (result instanceof CCompletionProposal) {
if (compareType == COMPARE_ID_STRINGS) {
strings[i]= ((CCompletionProposal)result).getIdString();
} else if (compareType == COMPARE_DISP_STRINGS) {
@@ -199,8 +199,20 @@ public abstract class AbstractContentAssistTest extends BaseUITestCase {
} else {
strings[i]= ((CCompletionProposal)result).getReplacementString();
}
- } else {
+ } else if (result instanceof ICCompletionProposal) {
+ if (compareType == COMPARE_ID_STRINGS) {
+ strings[i]= ((ICCompletionProposal)result).getIdString();
+ } else if (compareType == COMPARE_DISP_STRINGS) {
+ strings[i]= ((ICCompletionProposal)result).getDisplayString();
+ } else {
+ strings[i]= ((ICCompletionProposal)result).getDisplayString();
+ }
+ } else if (result instanceof ICompletionProposal) {
+ strings[i]= ((ICompletionProposal)result).getDisplayString();
+ } else if (result instanceof IContextInformation) {
strings[i]= ((IContextInformation)result).getContextDisplayString();
+ } else {
+ strings[i]= result.toString();
}
}
return strings;
diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/contentassist2/CompletionTests.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/contentassist2/CompletionTests.java
index 8563fe7fc3d..87528ed007a 100644
--- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/contentassist2/CompletionTests.java
+++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/contentassist2/CompletionTests.java
@@ -13,6 +13,11 @@
*******************************************************************************/
package org.eclipse.cdt.ui.tests.text.contentassist2;
+import java.io.File;
+import java.io.IOException;
+import java.util.HashSet;
+import java.util.Set;
+
import junit.framework.Test;
import org.eclipse.core.resources.IFile;
@@ -20,6 +25,7 @@ import org.eclipse.core.resources.IProject;
import org.eclipse.jface.text.IDocument;
import org.eclipse.cdt.core.CCorePlugin;
+import org.eclipse.cdt.core.testplugin.TestScannerProvider;
import org.eclipse.cdt.core.testplugin.util.BaseTestCase;
import org.eclipse.cdt.core.testplugin.util.TestSourceReader;
@@ -951,4 +957,75 @@ public class CompletionTests extends AbstractContentAssistTest {
};
assertCompletionResults(fCursorOffset, expected, AbstractContentAssistTest.COMPARE_REP_STRINGS);
}
+
+ //#include "/*cursor*/
+ public void testInclusionProposals_bug113568() throws Exception {
+ File tempRoot= new File(System.getProperty("java.io.tmpdir"));
+ File tempDir= new File(tempRoot, "cdttest_113568");
+ tempDir.mkdir();
+ try {
+ createIncludeFiles(tempDir, new String[] {
+ "h1/inc1.h",
+ "h1/sub1/inc11.h",
+ "h2/inc2.h"
+ });
+ String[] expected= {
+ "\"inc1.h\"",
+ "\"sub1/\"",
+ "\"inc2.h\""
+ };
+ assertCompletionResults(fCursorOffset, expected, AbstractContentAssistTest.COMPARE_REP_STRINGS);
+
+ getDocument().replace(fCursorOffset++, 0, "i");
+ expected= new String[] {
+ "\"inc1.h\"",
+ "\"inc2.h\""
+ };
+ assertCompletionResults(fCursorOffset, expected, AbstractContentAssistTest.COMPARE_REP_STRINGS);
+
+ getDocument().replace(fCursorOffset, 0, "\"");
+ expected= new String[] {
+ "\"inc1.h",
+ "\"inc2.h"
+ };
+ assertCompletionResults(fCursorOffset, expected, AbstractContentAssistTest.COMPARE_REP_STRINGS);
+
+ getDocument().replace(fCursorOffset-1, 1, "sub1/");
+ expected= new String[] {
+ "\"sub1/inc11.h"
+ };
+ assertCompletionResults(fCursorOffset+=4, expected, AbstractContentAssistTest.COMPARE_REP_STRINGS);
+ } finally {
+ deleteDir(tempDir);
+ }
+ }
+
+ public static void deleteDir(File dir) {
+ File[] files = dir.listFiles();
+ for (int i = 0; i < files.length; i++) {
+ if (files[i].isDirectory()) {
+ deleteDir(files[i]);
+ } else {
+ files[i].delete();
+ }
+ }
+ dir.delete();
+ }
+
+ private static void createIncludeFiles(File dir, String[] files) throws IOException {
+ Set<String> includeDirs= new HashSet<String>();
+ for (int i = 0; i < files.length; i++) {
+ File file = new File(dir, files[i]);
+ final File parentFile= file.getParentFile();
+ if (parentFile.getName().startsWith("sub")) {
+ if (!parentFile.exists()) {
+ parentFile.mkdirs();
+ }
+ } else if (includeDirs.add(parentFile.getAbsolutePath())) {
+ parentFile.mkdirs();
+ }
+ file.createNewFile();
+ }
+ TestScannerProvider.sIncludes= (String[]) includeDirs.toArray(new String[includeDirs.size()]);
+ }
}

Back to the top