1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-08 18:26:01 +02:00

Content Assist Work: More JUnit tests

This commit is contained in:
Hoda Amer 2004-01-29 18:02:12 +00:00
parent 42c82af132
commit 7bccc3314d
11 changed files with 231 additions and 156 deletions

View file

@ -1,3 +1,6 @@
2004-01-29 Hoda Amer
Removed CompletionKind.KEYWORD.
2004-01-29 John Camelon 2004-01-29 John Camelon
Fixed 50642 - Wrong completion kind when declaring an argument type Fixed 50642 - Wrong completion kind when declaring an argument type
Updated using declarations for more accurate keywords and closure. Updated using declarations for more accurate keywords and closure.

View file

@ -58,20 +58,17 @@ public interface IASTCompletionNode {
// any place where constructor parameters are expected // any place where constructor parameters are expected
public static final CompletionKind CONSTRUCTOR_REFERENCE = new CompletionKind( 12 ); public static final CompletionKind CONSTRUCTOR_REFERENCE = new CompletionKind( 12 );
// any place where exclusively a keyword is expected
public static final CompletionKind KEYWORD = new CompletionKind( 13 );
// any place where exclusively a preprocessor directive is expected // any place where exclusively a preprocessor directive is expected
public static final CompletionKind PREPROCESSOR_DIRECTIVE = new CompletionKind( 14 ); public static final CompletionKind PREPROCESSOR_DIRECTIVE = new CompletionKind( 13 );
// any place where a type or variable name is expected to be introduced // any place where a type or variable name is expected to be introduced
public static final CompletionKind USER_SPECIFIED_NAME = new CompletionKind( 15 ); public static final CompletionKind USER_SPECIFIED_NAME = new CompletionKind( 14 );
// any place where function parameters are expected // any place where function parameters are expected
public static final CompletionKind FUNCTION_REFERENCE = new CompletionKind( 16 ); public static final CompletionKind FUNCTION_REFERENCE = new CompletionKind( 15 );
// after a new expression // after a new expression
public static final CompletionKind NEW_TYPE_REFERENCE = new CompletionKind( 17 ); public static final CompletionKind NEW_TYPE_REFERENCE = new CompletionKind( 16 );
// error condition -- a place in the grammar where there is nothing to lookup // error condition -- a place in the grammar where there is nothing to lookup
public static final CompletionKind NO_SUCH_KIND = new CompletionKind( 200 ); public static final CompletionKind NO_SUCH_KIND = new CompletionKind( 200 );

View file

@ -1,3 +1,8 @@
2004-01-29 Hoda Amer
-Added CompletionTest_SingleName_Parameter test to success tests.
-Changed BaseTest to check if the expected values exist in the proposed values
instead of checking that the expected values exactly match the first part of the proposed values
2004-01-29 John Camelon 2004-01-29 John Camelon
Updated CompletionTest_ArgumentType_Prefix_Bug50642, renamed it to CompletionTest_ArgumentType_Prefix and moved to passed test package. Updated CompletionTest_ArgumentType_Prefix_Bug50642, renamed it to CompletionTest_ArgumentType_Prefix and moved to passed test package.
Updated CompletionTest_ArgumentType_Prefix2_Bug50642, renamed it to CompletionTest_ArgumentType_Prefix2 and moved to passed test package. Updated CompletionTest_ArgumentType_Prefix2_Bug50642, renamed it to CompletionTest_ArgumentType_Prefix2 and moved to passed test package.

View file

@ -0,0 +1,7 @@
#include "CompletionTestStart.h"
void aClass::aMethod()
{
int xLocal = 0;
xAClassMethod( x
}

View file

@ -66,6 +66,7 @@ public class AutomatedSuite extends TestSuite {
addTest(CompletionTest_NewTypeReference_Prefix.suite()); addTest(CompletionTest_NewTypeReference_Prefix.suite());
addTest(CompletionTest_ExceptionReference_NoPrefix.suite()); addTest(CompletionTest_ExceptionReference_NoPrefix.suite());
addTest(CompletionTest_ExceptionReference_Prefix.suite()); addTest(CompletionTest_ExceptionReference_Prefix.suite());
addTest(CompletionTest_SingleName_Parameter.suite());
// Failed Tests // Failed Tests
addTest(CompletionFailedTest_ScopedReference_NoPrefix_Bug50152.suite()); addTest(CompletionFailedTest_ScopedReference_NoPrefix_Bug50152.suite());

View file

@ -162,9 +162,18 @@ public abstract class CompletionProposalsBaseTest extends TestCase{
assertTrue(results.length >= expected.length); assertTrue(results.length >= expected.length);
for (int i = 0; i< expected.length; i++){ for (int i = 0; i< expected.length; i++){
ICompletionProposal proposal = results[i]; boolean found = false;
for(int j = 0; j< results.length; j++){
ICompletionProposal proposal = results[j];
String displayString = proposal.getDisplayString(); String displayString = proposal.getDisplayString();
assertEquals(displayString, expected[i]); if(expected[i].equals(displayString)){
found = true;
break;
}
}
if(found == false){
assertTrue(found);
}
} }
} catch(CModelException e){ } catch(CModelException e){

View file

@ -34,6 +34,7 @@ public class CompletionTest_SingleName_Method_NoPrefix extends CompletionPropos
//TODO Hoda - please update this constant with what it is supposed to be //TODO Hoda - please update this constant with what it is supposed to be
private final String[] expectedResults = { private final String[] expectedResults = {
"anotherField : int", "anotherField : int",
"anotherMethod() void"
}; };
public CompletionTest_SingleName_Method_NoPrefix(String name) { public CompletionTest_SingleName_Method_NoPrefix(String name) {

View file

@ -31,40 +31,40 @@ public class CompletionTest_SingleName_NoPrefix extends CompletionProposalsBase
private final CompletionKind expectedKind = CompletionKind.SINGLE_NAME_REFERENCE; private final CompletionKind expectedKind = CompletionKind.SINGLE_NAME_REFERENCE;
private final String expectedPrefix = ""; private final String expectedPrefix = "";
private final String[] expectedResults = { private final String[] expectedResults = {
"x : int", "x : int"
"aVariable : int", // "aVariable : int",
"xVariable : int", // "xVariable : int",
"aFunction() bool", // "aFunction() bool",
"anotherFunction() void", // "anotherFunction() void",
"foo(int) void", // "foo(int) void",
"xFunction() bool", // "xFunction() bool",
"xOtherFunction() void", // "xOtherFunction() void",
"aClass", // "aClass",
"anotherClass", // "anotherClass",
"xOtherClass", // "xOtherClass",
"AStruct", // "AStruct",
"XStruct", // "XStruct",
"aNamespace", // "aNamespace",
"xNamespace", // "xNamespace",
"anEnumeration", // "anEnumeration",
"xEnumeration", // "xEnumeration",
"aFirstEnum", // "aFirstEnum",
"aSecondEnum", // "aSecondEnum",
"aThirdEnum", // "aThirdEnum",
"xFirstEnum", // "xFirstEnum",
"xSecondEnum", // "xSecondEnum",
"xThirdEnum", // "xThirdEnum",
"__cplusplus", // "__cplusplus",
"__DATE__", // "__DATE__",
"__FILE__", // "__FILE__",
"__LINE__", // "__LINE__",
"__STDC__", // "__STDC__",
"__STDC_HOSTED__", // "__STDC_HOSTED__",
"__STDC_VERSION__", // "__STDC_VERSION__",
"__TIME__", // "__TIME__",
"AMacro(x)", // "AMacro(x)",
"DEBUG", // "DEBUG",
"XMacro(x,y)" // "XMacro(x,y)"
}; };
public CompletionTest_SingleName_NoPrefix(String name) { public CompletionTest_SingleName_NoPrefix(String name) {

View file

@ -0,0 +1,129 @@
/**********************************************************************
* Copyright (c) 2004 Rational Software Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v0.5
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v05.html
*
* Contributors:
* IBM Rational Software - Initial API and implementation
***********************************************************************/
package org.eclipse.cdt.ui.tests.text.contentassist;
import junit.framework.Test;
import junit.framework.TestSuite;
import org.eclipse.cdt.core.parser.ast.IASTCompletionNode.CompletionKind;
/**
* @author hamer
*
* Testing Single_Name_Reference in parameter passing
* Bug#
*
*/
public class CompletionTest_SingleName_Parameter extends CompletionProposalsBaseTest{
private final String fileName = "CompletionTestStart36.cpp";
private final String fileFullPath ="resources/contentassist/" + fileName;
private final String headerFileName = "CompletionTestStart.h";
private final String headerFileFullPath ="resources/contentassist/" + headerFileName;
private final String expectedScopeName = "ASTMethod";
private final String expectedContextName = "null";
private final CompletionKind expectedKind = CompletionKind.SINGLE_NAME_REFERENCE;
private final String expectedPrefix = "x";
private final String[] expectedResults = {
"xLocal : int",
"xAClassField : float",
"xVariable : int",
"xAClassMethod(int) void",
"xFunction() bool",
"xOtherFunction() void",
"xNamespace",
"xEnumeration",
"xFirstEnum",
"xSecondEnum",
"xThirdEnum",
"XStruct",
"XMacro(x,y)"
};
public CompletionTest_SingleName_Parameter(String name) {
super(name);
}
public static Test suite() {
TestSuite suite= new TestSuite(CompletionTest_SingleName_Parameter.class.getName());
suite.addTest(new CompletionTest_SingleName_Parameter("testCompletionProposals"));
return suite;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.codeassist.tests.CompletionProposalsTest#getCompletionPosition()
*/
protected int getCompletionPosition() {
return getBuffer().indexOf(" x ") + 2;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.codeassist.tests.CompletionProposalsTest#getExpectedScope()
*/
protected String getExpectedScopeClassName() {
return expectedScopeName;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.codeassist.tests.CompletionProposalsTest#getExpectedContext()
*/
protected String getExpectedContextClassName() {
return expectedContextName;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.codeassist.tests.CompletionProposalsTest#getExpectedKind()
*/
protected CompletionKind getExpectedKind() {
return expectedKind;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.codeassist.tests.CompletionProposalsTest#getExpectedPrefix()
*/
protected String getExpectedPrefix() {
return expectedPrefix;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.codeassist.tests.CompletionProposalsTest#getExpectedResultsValues()
*/
protected String[] getExpectedResultsValues() {
return expectedResults;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.codeassist.tests.CompletionProposalsTest#getFileName()
*/
protected String getFileName() {
return fileName;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.codeassist.tests.CompletionProposalsTest#getFileFullPath()
*/
protected String getFileFullPath() {
return fileFullPath;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.codeassist.tests.CompletionProposalsTest#getHeaderFileFullPath()
*/
protected String getHeaderFileFullPath() {
return headerFileFullPath;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.codeassist.tests.CompletionProposalsTest#getHeaderFileName()
*/
protected String getHeaderFileName() {
return headerFileName;
}
}

View file

@ -1,3 +1,6 @@
2004-01-29 Hoda Amer
Tuning for the Completion Engine.
2004-01-29 Alain Magloire 2004-01-29 Alain Magloire
PR 50789. Draft work on this. PR 50789. Draft work on this.

View file

@ -78,25 +78,9 @@ public class CompletionEngine implements RelevanceConstants {
int completionStart = 0; int completionStart = 0;
int completionLength = 0; int completionLength = 0;
IPreferenceStore store = CUIPlugin.getDefault().getPreferenceStore(); IPreferenceStore store = CUIPlugin.getDefault().getPreferenceStore();
// keywords types
public static final int BASIC_TYPES_KEYWORDS = 0;
private static final String basicTypesKeywords[] = {
"namespace",
"class",
"struct",
"union",
"enum",
"bool",
"char",
"wchar_t",
"int",
"float",
"double",
"void",
"template",
};
private static final String exceptionKeyword = "...";
private Map macroMap = new HashMap(); private Map macroMap = new HashMap();
private static final String exceptionKeyword = "...";
// scope relevance element counters // scope relevance element counters
private int numFields = 0; private int numFields = 0;
private int numVariables = 0; private int numVariables = 0;
@ -395,20 +379,6 @@ public class CompletionEngine implements RelevanceConstants {
return ; return ;
} }
private List lookupKeywords(String prefix, int lookupType){
List result = new ArrayList();
switch (lookupType){
case BASIC_TYPES_KEYWORDS:
for(int i = 0; i <basicTypesKeywords.length; i++){
String kw =basicTypesKeywords[i];
if(kw.startsWith(prefix))
result.add(kw);
}
break;
}
return result;
}
private ILookupResult lookup(IASTScope searchNode, String prefix, LookupKind[] kinds, IASTNode context){ private ILookupResult lookup(IASTScope searchNode, String prefix, LookupKind[] kinds, IASTNode context){
try { try {
logLookups (kinds); logLookups (kinds);
@ -465,46 +435,6 @@ public class CompletionEngine implements RelevanceConstants {
result = lookup (searchNode, completionNode.getCompletionPrefix(), kinds, completionNode.getCompletionContext()); result = lookup (searchNode, completionNode.getCompletionPrefix(), kinds, completionNode.getCompletionContext());
addToCompletions (result); addToCompletions (result);
} }
// private void completionOnStatementStart( IASTCompletionNode completionNode )
// {
// IASTScope searchNode = completionNode.getCompletionScope();
//
// ILookupResult result = null;
// if (completionNode.getCompletionPrefix().length() > 0){
// // lookup fields and methods with the right visibility
// IASTNode.LookupKind[] kinds = new IASTNode.LookupKind[8];
// kinds[0] = IASTNode.LookupKind.FIELDS;
// kinds[1] = IASTNode.LookupKind.METHODS;
// kinds[2] = IASTNode.LookupKind.VARIABLES;
// kinds[3] = IASTNode.LookupKind.STRUCTURES;
// kinds[4] = IASTNode.LookupKind.ENUMERATIONS;
// kinds[5] = IASTNode.LookupKind.NAMESPACES;
// kinds[6] = IASTNode.LookupKind.FUNCTIONS;
// kinds[7] = IASTNode.LookupKind.LOCAL_VARIABLES;
//
// result = lookup (searchNode, completionNode.getCompletionPrefix(), kinds, null);
// addToCompletions (result);
//
// List macros = lookupMacros(completionNode.getCompletionPrefix());
// addMacrosToCompletions(macros.iterator());
// }
// else // prefix is empty
// {
// // instead of only fields and methods
// IASTNode.LookupKind[] kinds = new IASTNode.LookupKind[1];
// kinds[0] = IASTNode.LookupKind.THIS;
// result = lookup(searchNode, completionNode.getCompletionPrefix(), kinds, completionNode.getCompletionContext());
// addToCompletions(result);
//
// kinds = new IASTNode.LookupKind[1];
// kinds[0] = IASTNode.LookupKind.LOCAL_VARIABLES;
// result = lookup(searchNode, completionNode.getCompletionPrefix(), kinds, completionNode.getCompletionContext());
// addToCompletions(result);
// }
//
// }
private void completionOnScopedReference(IASTCompletionNode completionNode){ private void completionOnScopedReference(IASTCompletionNode completionNode){
// 1. Get the search scope node // 1. Get the search scope node
// the search node is the name before the qualification // the search node is the name before the qualification
@ -567,26 +497,32 @@ public class CompletionEngine implements RelevanceConstants {
// the search node is the code scope inwhich completion is requested // the search node is the code scope inwhich completion is requested
IASTScope searchNode = completionNode.getCompletionScope(); IASTScope searchNode = completionNode.getCompletionScope();
// here we have to look for any names that could be referenced within this scope // here we have to look for any names that could be referenced within this scope
// 1. lookup local variables, global variables, functions, methods, structures, enums, macros, and namespaces // 1. lookup all
IASTNode.LookupKind[] kinds = new IASTNode.LookupKind[9]; ILookupResult result = null;
kinds[0] = IASTNode.LookupKind.LOCAL_VARIABLES; if (completionNode.getCompletionPrefix().length() > 0){
kinds[1] = IASTNode.LookupKind.FIELDS; IASTNode.LookupKind[] kinds = new IASTNode.LookupKind[1];
kinds[2] = IASTNode.LookupKind.VARIABLES; kinds[0] = IASTNode.LookupKind.ALL;
kinds[3] = IASTNode.LookupKind.METHODS;
kinds[4] = IASTNode.LookupKind.FUNCTIONS;
kinds[5] = IASTNode.LookupKind.NAMESPACES;
kinds[6] = IASTNode.LookupKind.ENUMERATORS;
kinds[7] = IASTNode.LookupKind.STRUCTURES;
kinds[8] = IASTNode.LookupKind.ENUMERATIONS;
String prefix = completionNode.getCompletionPrefix(); String prefix = completionNode.getCompletionPrefix();
if(prefix.equals("(")) if(prefix.equals("("))
prefix = ""; prefix = "";
ILookupResult result = lookup(searchNode, prefix, kinds, null); result = lookup(searchNode, prefix, kinds, null);
addToCompletions(result); addToCompletions(result);
List macros = lookupMacros(completionNode.getCompletionPrefix()); List macros = lookupMacros(completionNode.getCompletionPrefix());
addMacrosToCompletions(macros.iterator()); addMacrosToCompletions(macros.iterator());
}
else // prefix is empty
{
IASTNode.LookupKind[] kinds = new IASTNode.LookupKind[1];
kinds[0] = IASTNode.LookupKind.THIS;
result = lookup(searchNode, completionNode.getCompletionPrefix(), kinds, completionNode.getCompletionContext());
addToCompletions(result);
kinds = new IASTNode.LookupKind[1];
kinds[0] = IASTNode.LookupKind.LOCAL_VARIABLES;
result = lookup(searchNode, completionNode.getCompletionPrefix(), kinds, completionNode.getCompletionContext());
addToCompletions(result);
}
} }
private void completionOnClassReference(IASTCompletionNode completionNode){ private void completionOnClassReference(IASTCompletionNode completionNode){
@ -658,12 +594,6 @@ public class CompletionEngine implements RelevanceConstants {
ILookupResult result = lookup(searchNode, completionNode.getCompletionPrefix(), kinds, null); ILookupResult result = lookup(searchNode, completionNode.getCompletionPrefix(), kinds, null);
addToCompletions(result); addToCompletions(result);
} }
private void completionOnKeyword(IASTCompletionNode completionNode){
// lookup every type of keywords
// 1. basic types keword list
List result = lookupKeywords(completionNode.getCompletionPrefix(), BASIC_TYPES_KEYWORDS);
addKeywordsToCompletions(result.iterator());
}
public IASTCompletionNode complete(IWorkingCopy sourceUnit, int completionOffset) { public IASTCompletionNode complete(IWorkingCopy sourceUnit, int completionOffset) {
long startTime = System.currentTimeMillis(); long startTime = System.currentTimeMillis();
@ -703,11 +633,6 @@ public class CompletionEngine implements RelevanceConstants {
// completionOnMemberReference // completionOnMemberReference
completionOnScopedReference(completionNode); completionOnScopedReference(completionNode);
} }
// else if(kind == CompletionKind.STATEMENT_START )
// {
// // CompletionOnStatementStart
// completionOnStatementStart(completionNode);
// }
else if(kind == CompletionKind.FIELD_TYPE){ else if(kind == CompletionKind.FIELD_TYPE){
// CompletionOnFieldType // CompletionOnFieldType
completionOnFieldType(completionNode); completionOnFieldType(completionNode);
@ -756,11 +681,8 @@ public class CompletionEngine implements RelevanceConstants {
// completionOnConstructorReference // completionOnConstructorReference
completionOnConstructorReference(completionNode); completionOnConstructorReference(completionNode);
} }
else if(kind == CompletionKind.KEYWORD){
// CompletionOnKeyword
completionOnKeyword(completionNode);
}
// add keywords in all cases except for member and scoped reference cases.
if((kind != CompletionKind.MEMBER_REFERENCE) &&(kind != CompletionKind.SCOPED_REFERENCE)){ if((kind != CompletionKind.MEMBER_REFERENCE) &&(kind != CompletionKind.SCOPED_REFERENCE)){
addKeywordsToCompletions( completionNode.getKeywords()); addKeywordsToCompletions( completionNode.getKeywords());
} }
@ -798,14 +720,12 @@ public class CompletionEngine implements RelevanceConstants {
kindStr = "MACRO_REFERENCE"; kindStr = "MACRO_REFERENCE";
else if(kind == IASTCompletionNode.CompletionKind.CONSTRUCTOR_REFERENCE) else if(kind == IASTCompletionNode.CompletionKind.CONSTRUCTOR_REFERENCE)
kindStr = "CONSTRUCTOR_REFERENCE"; kindStr = "CONSTRUCTOR_REFERENCE";
else if(kind == IASTCompletionNode.CompletionKind.KEYWORD) else if(kind == IASTCompletionNode.CompletionKind.NEW_TYPE_REFERENCE)
kindStr = "KEYWORD"; kindStr = "NEW_TYPE_REFERENCE";
else if(kind == IASTCompletionNode.CompletionKind.PREPROCESSOR_DIRECTIVE) else if(kind == IASTCompletionNode.CompletionKind.PREPROCESSOR_DIRECTIVE)
kindStr = "PREPROCESSOR_DIRECTIVE"; kindStr = "PREPROCESSOR_DIRECTIVE";
else if(kind == IASTCompletionNode.CompletionKind.USER_SPECIFIED_NAME) else if(kind == IASTCompletionNode.CompletionKind.USER_SPECIFIED_NAME)
kindStr = "USER_SPECIFIED_NAME"; kindStr = "USER_SPECIFIED_NAME";
// else if(kind == IASTCompletionNode.CompletionKind.STATEMENT_START)
// kindStr = "STATEMENT_START";
else if(kind == IASTCompletionNode.CompletionKind.NO_SUCH_KIND) else if(kind == IASTCompletionNode.CompletionKind.NO_SUCH_KIND)
kindStr = "NO_SUCH_KIND"; kindStr = "NO_SUCH_KIND";