1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-04 14:55:41 +02:00

Partial Fix for bug#52948

This commit is contained in:
Hoda Amer 2004-03-08 21:20:11 +00:00
parent 0a6f297707
commit 29adda7a82
13 changed files with 213 additions and 18 deletions

View file

@ -1,3 +1,6 @@
2004-03-08 Hoda Amer
Partial fix for bug#52948 : Content Assist: typedef-ed types do not appear in the completion list.
2004-03-04 Alain Magloire 2004-03-04 Alain Magloire
Large cleanup(?) of the BinaryParser classes. Large cleanup(?) of the BinaryParser classes.

View file

@ -22,8 +22,8 @@ public interface IASTNode {
public static class LookupKind extends Enum { public static class LookupKind extends Enum {
public static final LookupKind ALL = new LookupKind( 0 ); public static final LookupKind ALL = new LookupKind( 0 ); // includes everything
public static final LookupKind STRUCTURES = new LookupKind( 1 ); public static final LookupKind STRUCTURES = new LookupKind( 1 ); // includes STRUCTS + UNIONS + CLASSES
public static final LookupKind STRUCTS = new LookupKind( 2 ); public static final LookupKind STRUCTS = new LookupKind( 2 );
public static final LookupKind UNIONS = new LookupKind( 3 ); public static final LookupKind UNIONS = new LookupKind( 3 );
public static final LookupKind CLASSES = new LookupKind( 4 ); public static final LookupKind CLASSES = new LookupKind( 4 );
@ -38,6 +38,8 @@ public interface IASTNode {
public static final LookupKind ENUMERATIONS = new LookupKind( 13 ); public static final LookupKind ENUMERATIONS = new LookupKind( 13 );
public static final LookupKind ENUMERATORS = new LookupKind( 14 ); public static final LookupKind ENUMERATORS = new LookupKind( 14 );
public static final LookupKind THIS = new LookupKind(15); public static final LookupKind THIS = new LookupKind(15);
public static final LookupKind TYPEDEFS = new LookupKind(16);
public static final LookupKind TYPES = new LookupKind(17); // includes STRUCTURES + ENUMERATIONS + TYPEDEFS
/** /**
* @param enumValue * @param enumValue

View file

@ -106,6 +106,7 @@ public class TypeFilter {
else if ( kind == LookupKind.NAMESPACES ) { acceptedTypes.add( TypeInfo.t_namespace ); } else if ( kind == LookupKind.NAMESPACES ) { acceptedTypes.add( TypeInfo.t_namespace ); }
else if ( kind == LookupKind.ENUMERATIONS ){ acceptedTypes.add( TypeInfo.t_enumeration ); } else if ( kind == LookupKind.ENUMERATIONS ){ acceptedTypes.add( TypeInfo.t_enumeration ); }
else if ( kind == LookupKind.ENUMERATORS ) { acceptedTypes.add( TypeInfo.t_enumerator ); } else if ( kind == LookupKind.ENUMERATORS ) { acceptedTypes.add( TypeInfo.t_enumerator ); }
else if ( kind == LookupKind.TYPEDEFS ) { acceptedTypes.add( TypeInfo.t_type ); }
} }

View file

@ -1,3 +1,6 @@
2004-03-08 Hoda Amer
Added one failed test: CompletionFailedTest_TypeDef_Bug52948
2004-03-03 John Camelon 2004-03-03 John Camelon
Updated failed test to fail in new way as Content Assist feature work continues on ... Updated failed test to fail in new way as Content Assist feature work continues on ...

View file

@ -0,0 +1,5 @@
#include "CompletionTestStart.h"
typedef int myType;
m

View file

@ -34,7 +34,7 @@ public class AutomatedSuite extends TestSuite {
public AutomatedSuite() { public AutomatedSuite() {
// Success Tests // Success Tests
addTest(PartitionTokenScannerTest.suite()); //addTest(PartitionTokenScannerTest.suite());
addTest(TextBufferTest.suite()); addTest(TextBufferTest.suite());
// completion tests // completion tests
addTest(CompletionTest_FieldType_Prefix.suite()); addTest(CompletionTest_FieldType_Prefix.suite());
@ -75,6 +75,7 @@ public class AutomatedSuite extends TestSuite {
addTest(CompletionTest_MacroRef_Prefix.suite()); addTest(CompletionTest_MacroRef_Prefix.suite());
addTest(CompletionFailedTest_FunctionReference_Bug50807.suite()); addTest(CompletionFailedTest_FunctionReference_Bug50807.suite());
addTest(CompletionFailedTest_ConstructorReference_Bug50808.suite()); addTest(CompletionFailedTest_ConstructorReference_Bug50808.suite());
addTest(CompletionFailedTest_TypeDef_Bug52948.suite());
} }
} }

View file

@ -0,0 +1,122 @@
/**********************************************************************
* 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.failedtests;
import junit.framework.Test;
import junit.framework.TestSuite;
import org.eclipse.cdt.core.parser.ast.IASTCompletionNode.CompletionKind;
import org.eclipse.cdt.ui.tests.text.contentassist.CompletionProposalsBaseTest;
/**
* @author hamer
*
* Testing Typedef as a possible returned type.
* Bug#52948
*
*/
public class CompletionFailedTest_TypeDef_Bug52948 extends CompletionProposalsBaseTest{
private final String fileName = "CompletionTestStart37.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 = "null";
private final CompletionKind expectedKind = CompletionKind.VARIABLE_TYPE;
private final String expectedPrefix = "m";
private final String[] expectedResults = {
// should be
// "myType"
};
public CompletionFailedTest_TypeDef_Bug52948(String name) {
super(name);
}
public static Test suite() {
TestSuite suite= new TestSuite(CompletionFailedTest_TypeDef_Bug52948.class.getName());
suite.addTest(new CompletionFailedTest_TypeDef_Bug52948("testCompletionProposals"));
return suite;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.codeassist.tests.CompletionProposalsTest#getCompletionPosition()
*/
protected int getCompletionPosition() {
return getBuffer().indexOf(" m ") + 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-03-08 Hoda Amer
Partial fix for bug#52948 : Content Assist: typedef-ed types do not appear in the completion list.
2004-03-08 Bogdan Gheorghe 2004-03-08 Bogdan Gheorghe
Minor refactoring to Chris Wiebe's jumbo patch - modified TypeSearchResultCollector.createMatch Minor refactoring to Chris Wiebe's jumbo patch - modified TypeSearchResultCollector.createMatch

View file

@ -51,6 +51,7 @@ import org.eclipse.cdt.core.parser.ast.IASTNamespaceDefinition;
import org.eclipse.cdt.core.parser.ast.IASTNode; import org.eclipse.cdt.core.parser.ast.IASTNode;
import org.eclipse.cdt.core.parser.ast.IASTParameterDeclaration; import org.eclipse.cdt.core.parser.ast.IASTParameterDeclaration;
import org.eclipse.cdt.core.parser.ast.IASTScope; import org.eclipse.cdt.core.parser.ast.IASTScope;
import org.eclipse.cdt.core.parser.ast.IASTTypedefDeclaration;
import org.eclipse.cdt.core.parser.ast.IASTVariable; import org.eclipse.cdt.core.parser.ast.IASTVariable;
import org.eclipse.cdt.core.parser.ast.IASTCompletionNode.CompletionKind; import org.eclipse.cdt.core.parser.ast.IASTCompletionNode.CompletionKind;
import org.eclipse.cdt.core.parser.ast.IASTNode.ILookupResult; import org.eclipse.cdt.core.parser.ast.IASTNode.ILookupResult;
@ -92,6 +93,7 @@ public class CompletionEngine implements RelevanceConstants {
private int numEnumerations = 0; private int numEnumerations = 0;
private int numEnumerators = 0; private int numEnumerators = 0;
private int numNamespaces = 0; private int numNamespaces = 0;
private int numTypedefs = 0;
public CompletionEngine(ICompletionRequestor completionRequestor){ public CompletionEngine(ICompletionRequestor completionRequestor){
requestor = completionRequestor; requestor = completionRequestor;
@ -130,6 +132,8 @@ public class CompletionEngine implements RelevanceConstants {
return STRUCT_TYPE_RELEVANCE; return STRUCT_TYPE_RELEVANCE;
case ICElement.C_UNION: case ICElement.C_UNION:
return UNION_TYPE_RELEVANCE; return UNION_TYPE_RELEVANCE;
case ICElement.C_TYPEDEF:
return TYPEDEF_TYPE_RELEVANCE;
case ICElement.C_NAMESPACE: case ICElement.C_NAMESPACE:
return NAMESPACE_TYPE_RELEVANCE; return NAMESPACE_TYPE_RELEVANCE;
case ICElement.C_MACRO: case ICElement.C_MACRO:
@ -314,6 +318,14 @@ public class CompletionEngine implements RelevanceConstants {
requestor.acceptEnumerator(enumerator.getName(), completionStart, completionLength, relevance); requestor.acceptEnumerator(enumerator.getName(), completionStart, completionLength, relevance);
} }
else if(node instanceof IASTTypedefDeclaration){
numTypedefs++;
IASTTypedefDeclaration typedef = (IASTTypedefDeclaration)node;
int relevance = computeRelevance(ICElement.C_TYPEDEF, prefix, typedef.getName());
relevance += totalNumberOfResults - numTypedefs;
requestor.acceptTypedef(typedef.getName(), completionStart, completionLength, relevance);
}
} }
private void addKeywordToCompletions (String keyword){ private void addKeywordToCompletions (String keyword){
@ -359,6 +371,7 @@ public class CompletionEngine implements RelevanceConstants {
numEnumerations = 0; numEnumerations = 0;
numEnumerators = 0; numEnumerators = 0;
numNamespaces = 0; numNamespaces = 0;
numTypedefs = 0;
} }
private void addToCompletions (ILookupResult result){ private void addToCompletions (ILookupResult result){
if(result == null){ if(result == null){
@ -441,11 +454,12 @@ public class CompletionEngine implements RelevanceConstants {
// IASTScope searchNode = completionNode.getCompletionScope(); // IASTScope searchNode = completionNode.getCompletionScope();
// // here we have to look for anything that could be referenced within this scope // // 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 // // 1. lookup local variables, global variables, functions, methods, structures, enums, and namespaces
// IASTNode.LookupKind[] kinds = new IASTNode.LookupKind[4]; // IASTNode.LookupKind[] kinds = new IASTNode.LookupKind[5];
// kinds[0] = IASTNode.LookupKind.VARIABLES; // kinds[0] = IASTNode.LookupKind.VARIABLES;
// kinds[1] = IASTNode.LookupKind.STRUCTURES; // kinds[1] = IASTNode.LookupKind.STRUCTURES;
// kinds[2] = IASTNode.LookupKind.ENUMERATIONS; // kinds[2] = IASTNode.LookupKind.ENUMERATIONS;
// kinds[3] = IASTNode.LookupKind.NAMESPACES; // kinds[3] = IASTNode.LookupKind.NAMESPACES;
// kinds[4] = IASTNode.LookupKind.TYPEDEFS;
// ILookupResult result = lookup(searchNode, completionNode.getCompletionPrefix(), kinds, completionNode.getCompletionContext()); // ILookupResult result = lookup(searchNode, completionNode.getCompletionPrefix(), kinds, completionNode.getCompletionContext());
// addToCompletions(result); // addToCompletions(result);
// // TODO // // TODO
@ -459,10 +473,11 @@ public class CompletionEngine implements RelevanceConstants {
if(completionNode.getCompletionPrefix().length() > 0 ) { if(completionNode.getCompletionPrefix().length() > 0 ) {
// 2. Lookup all types that could be used here // 2. Lookup all types that could be used here
ILookupResult result; ILookupResult result;
IASTNode.LookupKind[] kinds = new IASTNode.LookupKind[3]; IASTNode.LookupKind[] kinds = new IASTNode.LookupKind[4];
kinds[0] = IASTNode.LookupKind.STRUCTURES; kinds[0] = IASTNode.LookupKind.STRUCTURES;
kinds[1] = IASTNode.LookupKind.ENUMERATIONS; kinds[1] = IASTNode.LookupKind.ENUMERATIONS;
kinds[2] = IASTNode.LookupKind.NAMESPACES; kinds[2] = IASTNode.LookupKind.NAMESPACES;
kinds[3] = IASTNode.LookupKind.TYPEDEFS;
result = lookup(searchNode, completionNode.getCompletionPrefix(), kinds, completionNode.getCompletionContext()); result = lookup(searchNode, completionNode.getCompletionPrefix(), kinds, completionNode.getCompletionContext());
addToCompletions(result); addToCompletions(result);
} else // prefix is empty, we can not look for everything } else // prefix is empty, we can not look for everything
@ -697,7 +712,7 @@ public class CompletionEngine implements RelevanceConstants {
} }
private void logKind(String message, IASTCompletionNode.CompletionKind kind){ private void logKind(String message, IASTCompletionNode.CompletionKind kind){
if (! CCorePlugin.getDefault().isDebugging() && Util.isActive(IDebugLogConstants.CONTENTASSIST) ) if (! CUIPlugin.getDefault().isDebugging() && Util.isActive(IDebugLogConstants.CONTENTASSIST))
return; return;
String kindStr = ""; //$NON-NLS-1$ String kindStr = ""; //$NON-NLS-1$
@ -737,7 +752,7 @@ public class CompletionEngine implements RelevanceConstants {
log (message + kindStr); log (message + kindStr);
} }
private void logNode(String message, IASTNode node){ private void logNode(String message, IASTNode node){
if (! CCorePlugin.getDefault().isDebugging() && Util.isActive(IDebugLogConstants.CONTENTASSIST)) if (! CUIPlugin.getDefault().isDebugging() && Util.isActive(IDebugLogConstants.CONTENTASSIST))
return; return;
if(node == null){ if(node == null){
@ -772,13 +787,17 @@ public class CompletionEngine implements RelevanceConstants {
log(message + name); log(message + name);
return; return;
} }
if(node instanceof IASTNamespaceDefinition){
String name = "Namespace "; //$NON-NLS-1$
log(message + name);
return;
}
log(message + node.toString()); log(message + node.toString());
return; return;
} }
private void logLookups(LookupKind[] kinds){ private void logLookups(LookupKind[] kinds){
if (! CCorePlugin.getDefault().isDebugging() && Util.isActive(IDebugLogConstants.CONTENTASSIST)) if (! CUIPlugin.getDefault().isDebugging() && Util.isActive(IDebugLogConstants.CONTENTASSIST))
return; return;
StringBuffer kindName = new StringBuffer("Looking For "); //$NON-NLS-1$ StringBuffer kindName = new StringBuffer("Looking For "); //$NON-NLS-1$
@ -816,6 +835,8 @@ public class CompletionEngine implements RelevanceConstants {
kindName.append("ENUMERATORS"); //$NON-NLS-1$ kindName.append("ENUMERATORS"); //$NON-NLS-1$
else if(kind == IASTNode.LookupKind.THIS) else if(kind == IASTNode.LookupKind.THIS)
kindName.append("THIS"); //$NON-NLS-1$ kindName.append("THIS"); //$NON-NLS-1$
else if(kind == IASTNode.LookupKind.TYPEDEFS)
kindName.append("TYPEDEFS"); //$NON-NLS-1$
kindName.append(", "); //$NON-NLS-1$ kindName.append(", "); //$NON-NLS-1$
} }

View file

@ -139,4 +139,11 @@ public class CompletionRequestorAdaptor implements ICompletionRequestor {
} }
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.ui.text.contentassist.ICompletionRequestor#acceptTypedef(java.lang.String, int, int, int)
*/
public void acceptTypedef(String name, int completionStart,
int completionLength, int relevance) {
// TODO Auto-generated method stub
}
} }

View file

@ -22,6 +22,7 @@ public interface ICompletionRequestor {
void acceptClass(String name, int completionStart, int completionLength, int relevance); void acceptClass(String name, int completionStart, int completionLength, int relevance);
void acceptStruct(String name, int completionStart, int completionLength, int relevance); void acceptStruct(String name, int completionStart, int completionLength, int relevance);
void acceptUnion(String name, int completionStart, int completionLength, int relevance); void acceptUnion(String name, int completionStart, int completionLength, int relevance);
void acceptTypedef(String name, int completionStart, int completionLength, int relevance);
void acceptNamespace(String name, int completionStart, int completionLength, int relevance); void acceptNamespace(String name, int completionStart, int completionLength, int relevance);
void acceptMacro(String name, int completionStart, int completionLength, int relevance); void acceptMacro(String name, int completionStart, int completionLength, int relevance);
void acceptEnumeration(String name, int completionStart, int completionLength, int relevance); void acceptEnumeration(String name, int completionStart, int completionLength, int relevance);

View file

@ -11,17 +11,18 @@
package org.eclipse.cdt.internal.ui.text.contentassist; package org.eclipse.cdt.internal.ui.text.contentassist;
public interface RelevanceConstants { public interface RelevanceConstants {
final int CASE_MATCH_RELEVANCE = 150; final int CASE_MATCH_RELEVANCE = 160;
final int EXACT_NAME_MATCH_RELEVANCE = 40; final int EXACT_NAME_MATCH_RELEVANCE = 40;
final int LOCAL_VARIABLE_TYPE_RELEVANCE = 130; final int LOCAL_VARIABLE_TYPE_RELEVANCE = 140;
final int FIELD_TYPE_RELEVANCE = 120; final int FIELD_TYPE_RELEVANCE = 130;
final int VARIABLE_TYPE_RELEVANCE = 110; final int VARIABLE_TYPE_RELEVANCE = 120;
final int METHOD_TYPE_RELEVANCE = 100; final int METHOD_TYPE_RELEVANCE = 110;
final int FUNCTION_TYPE_RELEVANCE = 90; final int FUNCTION_TYPE_RELEVANCE = 100;
final int CLASS_TYPE_RELEVANCE = 80; final int CLASS_TYPE_RELEVANCE = 90;
final int STRUCT_TYPE_RELEVANCE = 70; final int STRUCT_TYPE_RELEVANCE = 80;
final int UNION_TYPE_RELEVANCE = 60; final int UNION_TYPE_RELEVANCE = 70;
final int TYPEDEF_TYPE_RELEVANCE = 60;
final int NAMESPACE_TYPE_RELEVANCE = 50; final int NAMESPACE_TYPE_RELEVANCE = 50;
final int MACRO_TYPE_RELEVANCE = 40; final int MACRO_TYPE_RELEVANCE = 40;
final int ENUMERATION_TYPE_RELEVANCE = 30; final int ENUMERATION_TYPE_RELEVANCE = 30;

View file

@ -475,6 +475,31 @@ public class ResultCollector extends CompletionRequestorAdaptor {
completions.add(proposal); completions.add(proposal);
} }
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.ui.text.contentassist.ICompletionRequestor#acceptTypedef(java.lang.String, int, int, int)
*/
public void acceptTypedef(String name,
int completionStart,
int completionLength,
int relevance) {
String replaceString = ""; //$NON-NLS-1$
String displayString = ""; //$NON-NLS-1$
Image image = null;
StringBuffer infoString = new StringBuffer();
// fill the replace, display and info strings
replaceString = name;
displayString = name;
// get the image
ImageDescriptor imageDescriptor = CElementImageProvider.getTypedefImageDescriptor();
image = registry.get( imageDescriptor );
// create proposal and add it to completions list
ICompletionProposal proposal = createProposal(replaceString, displayString, infoString.toString(),
null, image, completionStart, completionLength, relevance);
completions.add(proposal);
}
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.ICompletionRequestor#acceptKeyword(java.lang.String, int, int, int) * @see org.eclipse.cdt.core.ICompletionRequestor#acceptKeyword(java.lang.String, int, int, int)