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

Content Assist fixes

This commit is contained in:
Hoda Amer 2004-04-30 18:30:39 +00:00
parent 2c54ea985e
commit 1d8bbf919e
8 changed files with 304 additions and 21 deletions

View file

@ -1,3 +1,7 @@
2004-04-30 Hoda Amer
Added CompletionFailedTest_ScopedReference_ConstructorDefinition
Added CompletionTest_ScopedReference_NonCodeScope
2004-04-12 Hoda Amer
Updated CompletionFailedTest_ScopedReference_NoPrefix_Bug50152, renamed it to CompletionTest_ScopedReference_NoPrefix and moved it out of the failed tests folder.

View file

@ -0,0 +1,10 @@
class Foo{
public:
Foo();
void bar();
static void fum();
static int x;
int y;
};
Foo::

View file

@ -0,0 +1,10 @@
class Foo{
public:
Foo();
void bar();
static void fum();
static int x;
int y;
};
void Foo::

View file

@ -8,6 +8,8 @@ package org.eclipse.cdt.ui.tests;
import junit.framework.Test;
import junit.framework.TestSuite;
import org.eclipse.cdt.ui.tests.text.contentassist.CompletionFailedTest_MemberReference_Arrow_Prefix2;
import org.eclipse.cdt.ui.tests.text.contentassist.CompletionFailedTest_ScopedReference_ConstructorDefinition;
import org.eclipse.cdt.ui.tests.text.contentassist.CompletionTest_ArgumentType_NoPrefix;
import org.eclipse.cdt.ui.tests.text.contentassist.CompletionTest_ArgumentType_NoPrefix2;
import org.eclipse.cdt.ui.tests.text.contentassist.CompletionTest_ArgumentType_Prefix;
@ -25,7 +27,6 @@ import org.eclipse.cdt.ui.tests.text.contentassist.CompletionTest_MacroRef_NoPre
import org.eclipse.cdt.ui.tests.text.contentassist.CompletionTest_MacroRef_Prefix;
import org.eclipse.cdt.ui.tests.text.contentassist.CompletionTest_MemberReference_Arrow_NoPrefix;
import org.eclipse.cdt.ui.tests.text.contentassist.CompletionTest_MemberReference_Arrow_Prefix;
import org.eclipse.cdt.ui.tests.text.contentassist.CompletionFailedTest_MemberReference_Arrow_Prefix2;
import org.eclipse.cdt.ui.tests.text.contentassist.CompletionTest_MemberReference_Dot_NoPrefix;
import org.eclipse.cdt.ui.tests.text.contentassist.CompletionTest_MemberReference_Dot_Prefix;
import org.eclipse.cdt.ui.tests.text.contentassist.CompletionTest_NamespaceRef_NoPrefix;
@ -33,6 +34,7 @@ import org.eclipse.cdt.ui.tests.text.contentassist.CompletionTest_NamespaceRef_P
import org.eclipse.cdt.ui.tests.text.contentassist.CompletionTest_NewTypeReference_NoPrefix;
import org.eclipse.cdt.ui.tests.text.contentassist.CompletionTest_NewTypeReference_Prefix;
import org.eclipse.cdt.ui.tests.text.contentassist.CompletionTest_ScopedReference_NoPrefix;
import org.eclipse.cdt.ui.tests.text.contentassist.CompletionTest_ScopedReference_NonCodeScope;
import org.eclipse.cdt.ui.tests.text.contentassist.CompletionTest_ScopedReference_Prefix;
import org.eclipse.cdt.ui.tests.text.contentassist.CompletionTest_SingleName_Method_NoPrefix;
import org.eclipse.cdt.ui.tests.text.contentassist.CompletionTest_SingleName_Method_Prefix;
@ -87,7 +89,6 @@ public class AutomatedSuite extends TestSuite {
addTest(CompletionTest_MemberReference_Dot_Prefix.suite());
addTest(CompletionTest_MemberReference_Dot_NoPrefix.suite());
addTest(CompletionTest_MemberReference_Arrow_Prefix.suite());
addTest(CompletionFailedTest_MemberReference_Arrow_Prefix2.suite());
addTest(CompletionTest_MemberReference_Arrow_NoPrefix.suite());
addTest(CompletionTest_NamespaceRef_Prefix.suite());
addTest(CompletionTest_NamespaceRef_NoPrefix.suite());
@ -100,15 +101,18 @@ public class AutomatedSuite extends TestSuite {
addTest(CompletionTest_ExceptionReference_NoPrefix.suite());
addTest(CompletionTest_ExceptionReference_Prefix.suite());
addTest(CompletionTest_FunctionReference_Prefix.suite());
// Failed Tests
addTest(CompletionTest_ScopedReference_NoPrefix.suite());
addTest(CompletionTest_ScopedReference_Prefix.suite());
addTest(CompletionTest_ScopedReference_NonCodeScope.suite());
addTest(CompletionTest_MacroRef_NoPrefix.suite());
addTest(CompletionTest_MacroRef_Prefix.suite());
addTest(CompletionTest_FunctionReference_NoPrefix.suite());
addTest(CompletionTest_ConstructorReference.suite());
addTest(CompletionTest_TypeDef_NoPrefix.suite());
// Failed Tests
addTest(CompletionFailedTest_MemberReference_Arrow_Prefix2.suite());
addTest(CompletionFailedTest_ScopedReference_ConstructorDefinition.suite());
}
}

View file

@ -0,0 +1,117 @@
/**********************************************************************
* 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 Scoped_Reference, with no prefix
* Bug#50152: Wrong context sent after a "::"
*
*/
public class CompletionFailedTest_ScopedReference_ConstructorDefinition extends CompletionProposalsBaseTest{
private final String fileName = "CompletionTestStart38.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 = "ASTCompilationUnit";
private final String expectedContextName = "ASTClassSpecifier";
private final CompletionKind expectedKind = CompletionKind.VARIABLE_TYPE; // should be CompletionKind.CONSTRUCTOR_REFERENCE
private final String expectedPrefix = "";
private final String[] expectedResults = {
// "Foo()"
};
public CompletionFailedTest_ScopedReference_ConstructorDefinition(String name) {
super(name);
}
public static Test suite() {
TestSuite suite= new TestSuite(CompletionFailedTest_ScopedReference_ConstructorDefinition.class.getName());
suite.addTest(new CompletionFailedTest_ScopedReference_ConstructorDefinition("testCompletionProposals"));
return suite;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.codeassist.tests.CompletionProposalsTest#getCompletionPosition()
*/
protected int getCompletionPosition() {
return getBuffer().indexOf(":: ") + 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

@ -0,0 +1,119 @@
/**********************************************************************
* 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 Scoped_Reference, with no prefix
* Bug#50152: Wrong context sent after a "::"
*
*/
public class CompletionTest_ScopedReference_NonCodeScope extends CompletionProposalsBaseTest{
private final String fileName = "CompletionTestStart39.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 = "ASTCompilationUnit";
private final String expectedContextName = "ASTClassSpecifier";
private final CompletionKind expectedKind = CompletionKind.SINGLE_NAME_REFERENCE;
private final String expectedPrefix = "";
private final String[] expectedResults = {
"x : int",
"bar() void",
"fum() void"
};
public CompletionTest_ScopedReference_NonCodeScope(String name) {
super(name);
}
public static Test suite() {
TestSuite suite= new TestSuite(CompletionTest_ScopedReference_NonCodeScope.class.getName());
suite.addTest(new CompletionTest_ScopedReference_NonCodeScope("testCompletionProposals"));
return suite;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.codeassist.tests.CompletionProposalsTest#getCompletionPosition()
*/
protected int getCompletionPosition() {
return getBuffer().indexOf(":: ") + 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-04-30 Hoda Amer
Partial fix for bug#60298 : [Content Assist] "No completions available" when using Content Assist during class definitions
2004-04-23 Alain Magloire
Tentative fix for PR 59098.

View file

@ -161,7 +161,7 @@ public class CompletionEngine implements RelevanceConstants {
}
//C or CPP?
ParserLanguage language = CoreModel.getDefault().hasCCNature(project) ? ParserLanguage.CPP : ParserLanguage.C;
ParserLanguage language = CoreModel.hasCCNature(project) ? ParserLanguage.CPP : ParserLanguage.C;
IParser parser = null;
IScanner scanner = null;
@ -205,10 +205,10 @@ public class CompletionEngine implements RelevanceConstants {
}
}
private void addNodeToCompletions(IASTNode node, String prefix, int totalNumberOfResults, boolean addStaticMembersOnly){
private void addNodeToCompletions(IASTNode node, String prefix, int totalNumberOfResults, boolean addStaticMethodsOnly, boolean addStaticFieldsOnly){
if(node instanceof IASTField){
IASTField field = (IASTField)node;
if(addStaticMembersOnly && (!field.isStatic()))
if(addStaticFieldsOnly && (!field.isStatic()))
return;
int relevance = computeRelevance(ICElement.C_FIELD, prefix, field.getName());
@ -237,7 +237,7 @@ public class CompletionEngine implements RelevanceConstants {
completionStart, completionLength, relevance);
}else {
// global variable
if(addStaticMembersOnly && (!variable.isStatic()))
if(addStaticFieldsOnly && (!variable.isStatic()))
return;
int relevance = computeRelevance(ICElement.C_VARIABLE, prefix, variable.getName());
@ -249,7 +249,7 @@ public class CompletionEngine implements RelevanceConstants {
}
else if(node instanceof IASTMethod) {
IASTMethod method = (IASTMethod)node;
if(addStaticMembersOnly && (!method.isStatic()))
if(addStaticMethodsOnly && (!method.isStatic()))
return;
int relevance = computeRelevance(ICElement.C_METHOD, prefix, method.getName());
@ -262,7 +262,7 @@ public class CompletionEngine implements RelevanceConstants {
}
else if(node instanceof IASTFunction){
IASTFunction function = (IASTFunction)node;
if(addStaticMembersOnly && (!function.isStatic()))
if(addStaticMethodsOnly && (!function.isStatic()))
return;
int relevance = computeRelevance(ICElement.C_FUNCTION, prefix, function.getName());
@ -386,10 +386,10 @@ public class CompletionEngine implements RelevanceConstants {
}
private void addToCompletions (ILookupResult result){
addToCompletions(result, false);
addToCompletions(result, false, false);
}
private void addToCompletions (ILookupResult result, boolean addStaticMembersOnly){
private void addToCompletions (ILookupResult result, boolean addStaticMethodsOnly, boolean addStaticFieldsOnly){
if(result == null){
log("Lookup Results = null ................. !!! No Lookup Results found !!! "); //$NON-NLS-1$
return;
@ -401,7 +401,7 @@ public class CompletionEngine implements RelevanceConstants {
while (nodes.hasNext()){
IASTNode node = (IASTNode) nodes.next();
addNodeToCompletions(node, result.getPrefix(), numberOfElements, addStaticMembersOnly);
addNodeToCompletions(node, result.getPrefix(), numberOfElements, addStaticMethodsOnly, addStaticFieldsOnly);
}
return ;
}
@ -472,7 +472,9 @@ public class CompletionEngine implements RelevanceConstants {
IASTScope searchNode = completionNode.getCompletionScope();
// here we have to look for anything that could be referenced within this scope
// 1. lookup local variables, global variables, functions, methods, structures, enums, and namespaces
IASTNode.LookupKind[] kinds = new IASTNode.LookupKind[9];
IASTNode.LookupKind[] kinds = new IASTNode.LookupKind[1];
kinds[0] = IASTNode.LookupKind.ALL;
/*
kinds[0] = IASTNode.LookupKind.VARIABLES;
kinds[1] = IASTNode.LookupKind.STRUCTURES;
kinds[2] = IASTNode.LookupKind.ENUMERATIONS;
@ -482,13 +484,19 @@ public class CompletionEngine implements RelevanceConstants {
kinds[6] = IASTNode.LookupKind.METHODS;
kinds[7] = IASTNode.LookupKind.FUNCTIONS;
kinds[8] = IASTNode.LookupKind.ENUMERATORS;
kinds[9] = IASTNode.LookupKind.CONSTRUCTORS;
*/
ILookupResult result = lookup(searchNode, completionNode.getCompletionPrefix(), kinds, completionNode.getCompletionContext());
// lookup static members (field / methods) in types
if( (completionNode.getCompletionContext() != null)
&& (completionNode.getCompletionContext() instanceof IASTClassSpecifier)
&& (((IASTClassSpecifier) completionNode.getCompletionContext()).getClassKind() != ASTClassKind.ENUM)){
addToCompletions(result, true);
&& (((IASTClassSpecifier) completionNode.getCompletionContext()).getClassKind() != ASTClassKind.ENUM) ){
if (completionNode.getCompletionScope() instanceof IASTCodeScope){
addToCompletions(result, true, true);
}
else {
addToCompletions(result, false, true);
}
} else {
addToCompletions(result);
}
@ -727,12 +735,20 @@ public class CompletionEngine implements RelevanceConstants {
completionOnMemberReference(completionNode);
}
else if(kind == CompletionKind.FIELD_TYPE){
if (completionNode.getCompletionContext() == null){
// CompletionOnFieldType
completionOnFieldType(completionNode);
}else {
completionOnScopedReference(completionNode);
}
}
else if(kind == CompletionKind.VARIABLE_TYPE) {
if (completionNode.getCompletionContext() == null){
// CompletionOnVariableType
completionOnVariableType(completionNode);
}else {
completionOnScopedReference(completionNode);
}
}
else if(kind == CompletionKind.ARGUMENT_TYPE){
// CompletionOnArgumentType