1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00
Solution to bug#43162 : Code Assist not showing the right return value: 
        Saved a function return value string in the BasicSearchMatch object. 
        Created a new package org.eclipse.cdt.internal.core.parser.util and 
        added ASTUtil class with static methods to help convert an ASTFunction 
        return type from IASTAbstractDeclaration to String. Note that this was 
        previously implemented in the CModelBuilder. I just moved it to a common 
        library for others (BasicSearchMatch) to use. 
UI: 
        Solutions to 
        bug#43162 : Code Assist not showing the right return value 
        Bug#43145 : foo function still showing in Code Assist even if "f" is deleted 
        Bug#42810 : Code Assist adding characters after pressing <enter> 
        Bug#42861 : Code Assist should be case insensitive. 

Tests: 
        Solution to bug#43162 : Code Assist not showing the right return value. 
        Solution to Bug#42861 : Code Assist should be case insensitive. 
        Modified the CompletionProposalsTest to include upper and lower cases 
        and to include functions with different return values.
This commit is contained in:
John Camelon 2003-09-23 13:54:28 +00:00
parent e806c7013d
commit 3e361ae186
12 changed files with 325 additions and 381 deletions

View file

@ -108,7 +108,7 @@ public class CompletionProposalsTest extends TestCase{
TranslationUnit tu = new TranslationUnit(fCProject, bodyFile);
String buffer = tu.getBuffer().getContents();
Document document = new Document(buffer);
int pos = buffer.indexOf(" a ") + 2; //255;
int pos = buffer.indexOf(" a ") + 2;
int length = 0;
CCompletionProcessor completionProcessor = new CCompletionProcessor(null);
ICompletionProposal[] results = completionProcessor.evalProposals(document, pos, length, tu);
@ -126,7 +126,7 @@ public class CompletionProposalsTest extends TestCase{
assertEquals(displayString, "aVariable");
break;
case 1:
assertEquals(displayString, "aFunction() void");
assertEquals(displayString, "aFunction() bool");
break;
case 2:
assertEquals(displayString, "aClass");
@ -135,10 +135,10 @@ public class CompletionProposalsTest extends TestCase{
assertEquals(displayString, "anotherClass");
break;
case 4:
assertEquals(displayString, "aStruct");
assertEquals(displayString, "AStruct");
break;
case 5:
assertEquals(displayString, "aMacro");
assertEquals(displayString, "AMacro");
break;
case 6:
assertEquals(displayString, "anEnumeration");

View file

@ -1,9 +1,9 @@
#include "CompletionProposalsTestStart.h"
#define aMacro(x) x+1
#define AMacro(x) x+1
int aVariable = 0;
void aFunction();
bool aFunction();
enum anEnumeration {
first,
@ -11,8 +11,8 @@ enum anEnumeration {
third
};
struct aStruct{
int aStructField = 0;
struct AStruct{
int aStructField;
};
void foo(){

View file

@ -6,6 +6,6 @@ public:
class anotherClass {
public:
int anotherField = 0;
int anotherField;
void anotherMethod();
};

View file

@ -1,3 +1,12 @@
2003-09-19 Hoda Amer
Solution to bug#43162 : Code Assist not showing the right return value:
Saved a function return value string in the BasicSearchMatch object.
Created a new package org.eclipse.cdt.internal.core.parser.util and
added ASTUtil class with static methods to help convert an ASTFunction
return type from IASTAbstractDeclaration to String. Note that this was
previously implemented in the CModelBuilder. I just moved it to a common
library for others (BasicSearchMatch) to use.
2003-09-16 Alain Magloire
Putting the draft work to do a special binary parser

View file

@ -11,10 +11,8 @@
package org.eclipse.cdt.internal.core.model;
import java.io.StringReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.eclipse.cdt.core.model.CoreModel;
@ -23,19 +21,17 @@ import org.eclipse.cdt.core.model.IParent;
import org.eclipse.cdt.core.model.ITemplate;
import org.eclipse.cdt.core.parser.IParser;
import org.eclipse.cdt.core.parser.IQuickParseCallback;
import org.eclipse.cdt.core.parser.ParserLanguage;
import org.eclipse.cdt.core.parser.ParserFactory;
import org.eclipse.cdt.core.parser.ParserLanguage;
import org.eclipse.cdt.core.parser.ParserMode;
import org.eclipse.cdt.core.parser.ast.ASTClassKind;
import org.eclipse.cdt.core.parser.ast.ASTNotImplementedException;
import org.eclipse.cdt.core.parser.ast.ASTPointerOperator;
import org.eclipse.cdt.core.parser.ast.IASTAbstractDeclaration;
import org.eclipse.cdt.core.parser.ast.IASTAbstractTypeSpecifierDeclaration;
import org.eclipse.cdt.core.parser.ast.IASTBaseSpecifier;
import org.eclipse.cdt.core.parser.ast.IASTClassSpecifier;
import org.eclipse.cdt.core.parser.ast.IASTCompilationUnit;
import org.eclipse.cdt.core.parser.ast.IASTDeclaration;
import org.eclipse.cdt.core.parser.ast.IASTElaboratedTypeSpecifier;
import org.eclipse.cdt.core.parser.ast.IASTEnumerationSpecifier;
import org.eclipse.cdt.core.parser.ast.IASTEnumerator;
import org.eclipse.cdt.core.parser.ast.IASTField;
@ -45,33 +41,30 @@ import org.eclipse.cdt.core.parser.ast.IASTMacro;
import org.eclipse.cdt.core.parser.ast.IASTMethod;
import org.eclipse.cdt.core.parser.ast.IASTNamespaceDefinition;
import org.eclipse.cdt.core.parser.ast.IASTOffsetableElement;
import org.eclipse.cdt.core.parser.ast.IASTParameterDeclaration;
import org.eclipse.cdt.core.parser.ast.IASTSimpleTypeSpecifier;
import org.eclipse.cdt.core.parser.ast.IASTTemplateDeclaration;
import org.eclipse.cdt.core.parser.ast.IASTTemplateParameter;
import org.eclipse.cdt.core.parser.ast.IASTTypeSpecifier;
import org.eclipse.cdt.core.parser.ast.IASTTypeSpecifierOwner;
import org.eclipse.cdt.core.parser.ast.IASTTypedefDeclaration;
import org.eclipse.cdt.core.parser.ast.IASTVariable;
import org.eclipse.cdt.internal.core.parser.ParserException;
import org.eclipse.cdt.internal.core.parser.ScannerInfo;
import org.eclipse.cdt.internal.core.parser.ast.ASTArrayModifier;
import org.eclipse.cdt.internal.core.parser.util.ASTUtil;
import org.eclipse.core.resources.IProject;
public class CModelBuilder {
protected org.eclipse.cdt.internal.core.model.TranslationUnit translationUnit;
protected Map newElements;
protected IQuickParseCallback quickParseCallback;
protected IASTCompilationUnit compilationUnit;
private org.eclipse.cdt.internal.core.model.TranslationUnit translationUnit;
private Map newElements;
private IQuickParseCallback quickParseCallback;
private IASTCompilationUnit compilationUnit;
public CModelBuilder(org.eclipse.cdt.internal.core.model.TranslationUnit tu) {
this.translationUnit = tu ;
this.newElements = new HashMap();
}
protected IASTCompilationUnit parse( String code, boolean hasCppNature, boolean quick, boolean throwExceptionOnError ) throws ParserException
private IASTCompilationUnit parse( String code, boolean hasCppNature, boolean quick, boolean throwExceptionOnError ) throws ParserException
{
ParserMode mode = quick ? ParserMode.QUICK_PARSE : ParserMode.COMPLETE_PARSE;
quickParseCallback = ParserFactory.createQuickParseCallback();
@ -86,7 +79,7 @@ public class CModelBuilder {
return quickParseCallback.getCompilationUnit();
}
protected IASTCompilationUnit parse( String code, boolean hasCppNature )throws ParserException
private IASTCompilationUnit parse( String code, boolean hasCppNature )throws ParserException
{
return parse( code, hasCppNature, true, true );
}
@ -135,7 +128,7 @@ public class CModelBuilder {
}
protected void generateModelElements(){
private void generateModelElements(){
Iterator i = quickParseCallback.iterateOffsetableElements();
while (i.hasNext()){
IASTOffsetableElement offsetable = (IASTOffsetableElement)i.next();
@ -153,7 +146,7 @@ public class CModelBuilder {
}
}
protected void generateModelElements (Parent parent, IASTDeclaration declaration) throws ASTNotImplementedException
private void generateModelElements (Parent parent, IASTDeclaration declaration) throws ASTNotImplementedException
{
if(declaration instanceof IASTNamespaceDefinition ) {
generateModelElements(parent, (IASTNamespaceDefinition) declaration);
@ -174,7 +167,7 @@ public class CModelBuilder {
createSimpleElement(parent, declaration, false);
}
protected void generateModelElements (Parent parent, IASTNamespaceDefinition declaration) throws ASTNotImplementedException{
private void generateModelElements (Parent parent, IASTNamespaceDefinition declaration) throws ASTNotImplementedException{
// IASTNamespaceDefinition
IParent namespace = createNamespace(parent, declaration);
Iterator nsDecls = declaration.getDeclarations();
@ -184,13 +177,13 @@ public class CModelBuilder {
}
}
protected void generateModelElements (Parent parent, IASTAbstractTypeSpecifierDeclaration abstractDeclaration) throws ASTNotImplementedException
private void generateModelElements (Parent parent, IASTAbstractTypeSpecifierDeclaration abstractDeclaration) throws ASTNotImplementedException
{
// IASTAbstractTypeSpecifierDeclaration
CElement element = createAbstractElement(parent, abstractDeclaration, false);
}
protected void generateModelElements (Parent parent, IASTTemplateDeclaration templateDeclaration) throws ASTNotImplementedException
private void generateModelElements (Parent parent, IASTTemplateDeclaration templateDeclaration) throws ASTNotImplementedException
{
// Template Declaration
IASTDeclaration declaration = (IASTDeclaration)templateDeclaration.getOwnedDeclaration();
@ -200,7 +193,7 @@ public class CModelBuilder {
// set the element position
element.setPos(templateDeclaration.getStartingOffset(), templateDeclaration.getEndingOffset() - templateDeclaration.getStartingOffset());
// set the template parameters
String[] parameterTypes = getTemplateParameters(templateDeclaration);
String[] parameterTypes = ASTUtil.getTemplateParameters(templateDeclaration);
ITemplate classTemplate = (ITemplate) element;
classTemplate.setTemplateParameterTypes(parameterTypes);
}
@ -212,12 +205,12 @@ public class CModelBuilder {
// set the element position
element.setPos(templateDeclaration.getStartingOffset(), templateDeclaration.getEndingOffset() - templateDeclaration.getStartingOffset());
// set the template parameters
String[] parameterTypes = getTemplateParameters(templateDeclaration);
String[] parameterTypes = ASTUtil.getTemplateParameters(templateDeclaration);
template.setTemplateParameterTypes(parameterTypes);
}
}
protected void generateModelElements (Parent parent, IASTTypedefDeclaration declaration) throws ASTNotImplementedException
private void generateModelElements (Parent parent, IASTTypedefDeclaration declaration) throws ASTNotImplementedException
{
TypeDef typeDef = createTypeDef(parent, declaration);
IASTAbstractDeclaration abstractDeclaration = declaration.getAbstractDeclarator();
@ -266,7 +259,7 @@ public class CModelBuilder {
return element;
}
protected Include createInclusion(Parent parent, IASTInclusion inclusion){
private Include createInclusion(Parent parent, IASTInclusion inclusion){
// create element
Include element = new Include((CElement)parent, inclusion.getName(), !inclusion.isLocal());
element.setFullPathName(inclusion.getFullFileName());
@ -280,7 +273,7 @@ public class CModelBuilder {
return element;
}
protected Macro createMacro(Parent parent, IASTMacro macro){
private Macro createMacro(Parent parent, IASTMacro macro){
// create element
org.eclipse.cdt.internal.core.model.Macro element = new Macro(parent, macro.getName());
// add to parent
@ -293,7 +286,7 @@ public class CModelBuilder {
return element;
}
protected Namespace createNamespace(Parent parent, IASTNamespaceDefinition nsDef){
private Namespace createNamespace(Parent parent, IASTNamespaceDefinition nsDef){
// create element
String type = "namespace";
String nsName = (nsDef.getName() == null )
@ -310,7 +303,7 @@ public class CModelBuilder {
return element;
}
protected Enumeration createEnumeration(Parent parent, IASTEnumerationSpecifier enumSpecifier){
private Enumeration createEnumeration(Parent parent, IASTEnumerationSpecifier enumSpecifier){
// create element
String type = "enum";
String enumName = (enumSpecifier.getName() == null )
@ -334,7 +327,7 @@ public class CModelBuilder {
return element;
}
protected Enumerator createEnumerator(Parent enum, IASTEnumerator enumDef){
private Enumerator createEnumerator(Parent enum, IASTEnumerator enumDef){
Enumerator element = new Enumerator (enum, enumDef.getName().toString());
// add to parent
enum.addChild(element);
@ -346,7 +339,7 @@ public class CModelBuilder {
return element;
}
protected Structure createClass(Parent parent, IASTClassSpecifier classSpecifier, boolean isTemplate){
private Structure createClass(Parent parent, IASTClassSpecifier classSpecifier, boolean isTemplate){
// create element
String className = "";
String type = "";
@ -413,13 +406,13 @@ public class CModelBuilder {
return element;
}
protected TypeDef createTypeDef(Parent parent, IASTTypedefDeclaration typeDefDeclaration){
private TypeDef createTypeDef(Parent parent, IASTTypedefDeclaration typeDefDeclaration){
// create the element
String name = typeDefDeclaration.getName();
TypeDef element = new TypeDef( parent, name );
StringBuffer typeName = new StringBuffer(getType(typeDefDeclaration.getAbstractDeclarator()));
StringBuffer typeName = new StringBuffer(ASTUtil.getType(typeDefDeclaration.getAbstractDeclarator()));
element.setTypeName(typeName.toString());
// add to parent
@ -433,7 +426,7 @@ public class CModelBuilder {
return element;
}
protected VariableDeclaration createVariableSpecification(Parent parent, IASTVariable varDeclaration, boolean isTemplate)throws ASTNotImplementedException
private VariableDeclaration createVariableSpecification(Parent parent, IASTVariable varDeclaration, boolean isTemplate)throws ASTNotImplementedException
{
IASTAbstractDeclaration abstractDeclaration = varDeclaration.getAbstractDeclaration();
CElement abstractElement = createAbstractElement (parent, abstractDeclaration , isTemplate);
@ -470,7 +463,7 @@ public class CModelBuilder {
}
}
}
element.setTypeName ( getType(varDeclaration.getAbstractDeclaration()) );
element.setTypeName ( ASTUtil.getType(varDeclaration.getAbstractDeclaration()) );
element.setConst(varDeclaration.getAbstractDeclaration().isConst());
element.setVolatile(varDeclaration.getAbstractDeclaration().isVolatile());
element.setStatic(varDeclaration.isStatic());
@ -488,7 +481,7 @@ public class CModelBuilder {
return element;
}
protected FunctionDeclaration createFunctionSpecification(Parent parent, IASTFunction functionDeclaration, boolean isTemplate)
private FunctionDeclaration createFunctionSpecification(Parent parent, IASTFunction functionDeclaration, boolean isTemplate)
{
String name = functionDeclaration.getName();
if (name == null) {
@ -497,7 +490,7 @@ public class CModelBuilder {
}
// get parameters types
String[] parameterTypes = getFunctionParameterTypes(functionDeclaration);
String[] parameterTypes = ASTUtil.getFunctionParameterTypes(functionDeclaration);
FunctionDeclaration element = null;
@ -566,7 +559,7 @@ public class CModelBuilder {
}
}
element.setParameterTypes(parameterTypes);
element.setReturnType( getType(functionDeclaration.getReturnType()) );
element.setReturnType( ASTUtil.getType(functionDeclaration.getReturnType()) );
element.setStatic(functionDeclaration.isStatic());
// add to parent
@ -583,188 +576,4 @@ public class CModelBuilder {
return element;
}
private String[] getTemplateParameters(Iterator templateParams){
List paramList = new ArrayList();
while (templateParams.hasNext()){
StringBuffer paramType = new StringBuffer();
IASTTemplateParameter parameter = (IASTTemplateParameter)templateParams.next();
if((parameter.getIdentifier() != null) && (parameter.getIdentifier().length() != 0))
{
paramList.add(parameter.getIdentifier().toString());
}
else
{
IASTTemplateParameter.ParamKind kind = parameter.getTemplateParameterKind();
if(kind == IASTTemplateParameter.ParamKind.CLASS){
paramType.append("class");
}
if(kind == IASTTemplateParameter.ParamKind.TYPENAME){
paramType.append("typename");
}
if(kind == IASTTemplateParameter.ParamKind.TEMPLATE_LIST){
paramType.append("template<");
String[] subParams = getTemplateParameters(parameter.getTemplateParameters());
int p = 0;
if ( subParams.length > 0)
paramType.append(subParams[p++]);
while( p < subParams.length){
paramType.append(", ");
paramType.append(subParams[p++]);
}
paramType.append(">");
}
if(kind == IASTTemplateParameter.ParamKind.PARAMETER){
paramType.append(getType(parameter.getParameterDeclaration()));
}
paramList.add(paramType.toString());
} // end else
}// end while
String[] parameterTypes = new String[paramList.size()];
for(int j=0; j<paramList.size(); ++j){
parameterTypes[j] = (String) paramList.get(j);
}
return parameterTypes;
}
private String[] getTemplateParameters(IASTTemplateDeclaration templateDeclaration){
// add the parameters
Iterator i = templateDeclaration.getTemplateParameters();
return getTemplateParameters(i);
}
private String getType(IASTAbstractDeclaration declaration)
{
StringBuffer type = new StringBuffer();
// get type from declaration
type.append(getDeclarationType(declaration));
type.append(getPointerOperation(declaration));
type.append(getArrayQualifiers(declaration));
type.append(getPointerToFunctionType(declaration));
return type.toString();
}
private String getPointerToFunctionType(IASTAbstractDeclaration declaration){
StringBuffer type = new StringBuffer();
ASTPointerOperator po = declaration.getPointerToFunctionOperator();
if(po != null){
type.append("(");
type.append(getPointerOperator(po));
type.append(")");
String[] parameters =getParameterTypes(declaration.getParameters());
type.append(getParametersString(parameters));
}
return type.toString();
}
private String getDeclarationType(IASTAbstractDeclaration declaration){
StringBuffer type = new StringBuffer();
if(declaration.isConst())
type.append("const ");
IASTTypeSpecifier typeSpecifier = declaration.getTypeSpecifier();
if(typeSpecifier instanceof IASTElaboratedTypeSpecifier){
IASTElaboratedTypeSpecifier elab = (IASTElaboratedTypeSpecifier) typeSpecifier;
type.append(getElaboratedTypeSignature(elab));
}else if(typeSpecifier instanceof IASTSimpleTypeSpecifier){
IASTSimpleTypeSpecifier simpleSpecifier = (IASTSimpleTypeSpecifier) typeSpecifier;
type.append(simpleSpecifier.getTypename());
}
return type.toString();
}
private String getElaboratedTypeSignature(IASTElaboratedTypeSpecifier elab){
StringBuffer type = new StringBuffer();
ASTClassKind t = elab.getClassKind();
if( t == ASTClassKind.CLASS){
type.append("class");
}
else if( t == ASTClassKind.STRUCT){
type.append("struct");
}
else if( t == ASTClassKind.UNION){
type.append("union");
}
else if( t == ASTClassKind.STRUCT){
type.append("enum");
}
type.append(" ");
type.append(elab.getName().toString());
return type.toString();
}
private String getPointerOperation(IASTAbstractDeclaration declaration){
StringBuffer pointerString = new StringBuffer();
Iterator i = declaration.getPointerOperators();
while(i.hasNext()){
ASTPointerOperator po = (ASTPointerOperator) i.next();
pointerString.append(getPointerOperator(po));
}
return pointerString.toString();
}
private String getPointerOperator(ASTPointerOperator po){
String pointerString ="";
if(po == ASTPointerOperator.POINTER)
pointerString = ("*");
if(po == ASTPointerOperator.REFERENCE)
pointerString =("&");
if(po == ASTPointerOperator.CONST_POINTER)
pointerString =("* const");
if(po == ASTPointerOperator.VOLATILE_POINTER)
pointerString =("* volatile");
return pointerString;
}
private String getArrayQualifiers(IASTAbstractDeclaration declaration){
StringBuffer arrayString = new StringBuffer();
Iterator i = declaration.getArrayModifiers();
while (i.hasNext()){
ASTArrayModifier q = (ASTArrayModifier) i.next();
arrayString.append("[]");
}
return arrayString.toString();
}
private String[] getFunctionParameterTypes(IASTFunction functionDeclaration)
{
Iterator parameters = functionDeclaration.getParameters();
return getParameterTypes(parameters);
}
private String[] getParameterTypes(Iterator parameters){
List paramList = new ArrayList();
while (parameters.hasNext()){
IASTParameterDeclaration param = (IASTParameterDeclaration)parameters.next();
paramList.add(getType(param));
}
String[] parameterTypes = new String[paramList.size()];
for(int i=0; i<paramList.size(); ++i){
parameterTypes[i] = (String)paramList.get(i);
}
return parameterTypes;
}
private String getParametersString(String[] parameterTypes)
{
StringBuffer parameters = new StringBuffer("");
if ((parameterTypes != null) && (parameterTypes.length > 0)) {
parameters.append("(");
int i = 0;
parameters.append(parameterTypes[i++]);
while (i < parameterTypes.length) {
parameters.append(", ");
parameters.append(parameterTypes[i++]);
}
parameters.append(")");
} else {
if (parameterTypes != null) parameters.append("()");
}
return parameters.toString();
}
}

View file

@ -0,0 +1,219 @@
/*******************************************************************************
* Copyright (c) 2001 Rational Software Corp. 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:
* Rational Software - initial implementation
******************************************************************************/
package org.eclipse.cdt.internal.core.parser.util;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.eclipse.cdt.core.parser.ast.ASTClassKind;
import org.eclipse.cdt.core.parser.ast.ASTPointerOperator;
import org.eclipse.cdt.core.parser.ast.IASTAbstractDeclaration;
import org.eclipse.cdt.core.parser.ast.IASTElaboratedTypeSpecifier;
import org.eclipse.cdt.core.parser.ast.IASTFunction;
import org.eclipse.cdt.core.parser.ast.IASTParameterDeclaration;
import org.eclipse.cdt.core.parser.ast.IASTSimpleTypeSpecifier;
import org.eclipse.cdt.core.parser.ast.IASTTemplateDeclaration;
import org.eclipse.cdt.core.parser.ast.IASTTemplateParameter;
import org.eclipse.cdt.core.parser.ast.IASTTypeSpecifier;
import org.eclipse.cdt.internal.core.parser.ast.ASTArrayModifier;
/**
* This is a utility class to help convert AST elements to Strings.
*/
public class ASTUtil {
public static String[] getTemplateParameters(IASTTemplateDeclaration templateDeclaration){
// add the parameters
Iterator i = templateDeclaration.getTemplateParameters();
return getTemplateParameters(i);
}
public static String[] getTemplateParameters(Iterator templateParams){
List paramList = new ArrayList();
while (templateParams.hasNext()){
StringBuffer paramType = new StringBuffer();
IASTTemplateParameter parameter = (IASTTemplateParameter)templateParams.next();
if((parameter.getIdentifier() != null) && (parameter.getIdentifier().length() != 0))
{
paramList.add(parameter.getIdentifier().toString());
}
else
{
IASTTemplateParameter.ParamKind kind = parameter.getTemplateParameterKind();
if(kind == IASTTemplateParameter.ParamKind.CLASS){
paramType.append("class");
}
if(kind == IASTTemplateParameter.ParamKind.TYPENAME){
paramType.append("typename");
}
if(kind == IASTTemplateParameter.ParamKind.TEMPLATE_LIST){
paramType.append("template<");
String[] subParams = getTemplateParameters(parameter.getTemplateParameters());
int p = 0;
if ( subParams.length > 0)
paramType.append(subParams[p++]);
while( p < subParams.length){
paramType.append(", ");
paramType.append(subParams[p++]);
}
paramType.append(">");
}
if(kind == IASTTemplateParameter.ParamKind.PARAMETER){
paramType.append(getType(parameter.getParameterDeclaration()));
}
paramList.add(paramType.toString());
} // end else
}// end while
String[] parameterTypes = new String[paramList.size()];
for(int j=0; j<paramList.size(); ++j){
parameterTypes[j] = (String) paramList.get(j);
}
return parameterTypes;
}
public static String getType(IASTAbstractDeclaration declaration)
{
StringBuffer type = new StringBuffer();
// get type from declaration
type.append(getDeclarationType(declaration));
type.append(getPointerOperation(declaration));
type.append(getArrayQualifiers(declaration));
type.append(getPointerToFunctionType(declaration));
return type.toString();
}
public static String getPointerToFunctionType(IASTAbstractDeclaration declaration){
StringBuffer type = new StringBuffer();
ASTPointerOperator po = declaration.getPointerToFunctionOperator();
if(po != null){
type.append("(");
type.append(getPointerOperator(po));
type.append(")");
String[] parameters =getParameterTypes(declaration.getParameters());
type.append(getParametersString(parameters));
}
return type.toString();
}
public static String getDeclarationType(IASTAbstractDeclaration declaration){
StringBuffer type = new StringBuffer();
if(declaration.isConst())
type.append("const ");
IASTTypeSpecifier typeSpecifier = declaration.getTypeSpecifier();
if(typeSpecifier instanceof IASTElaboratedTypeSpecifier){
IASTElaboratedTypeSpecifier elab = (IASTElaboratedTypeSpecifier) typeSpecifier;
type.append(getElaboratedTypeSignature(elab));
}else if(typeSpecifier instanceof IASTSimpleTypeSpecifier){
IASTSimpleTypeSpecifier simpleSpecifier = (IASTSimpleTypeSpecifier) typeSpecifier;
type.append(simpleSpecifier.getTypename());
}
return type.toString();
}
public static String getElaboratedTypeSignature(IASTElaboratedTypeSpecifier elab){
StringBuffer type = new StringBuffer();
ASTClassKind t = elab.getClassKind();
if( t == ASTClassKind.CLASS){
type.append("class");
}
else if( t == ASTClassKind.STRUCT){
type.append("struct");
}
else if( t == ASTClassKind.UNION){
type.append("union");
}
else if( t == ASTClassKind.STRUCT){
type.append("enum");
}
type.append(" ");
type.append(elab.getName().toString());
return type.toString();
}
public static String getPointerOperation(IASTAbstractDeclaration declaration){
StringBuffer pointerString = new StringBuffer();
Iterator i = declaration.getPointerOperators();
while(i.hasNext()){
ASTPointerOperator po = (ASTPointerOperator) i.next();
pointerString.append(getPointerOperator(po));
}
return pointerString.toString();
}
public static String getPointerOperator(ASTPointerOperator po){
String pointerString ="";
if(po == ASTPointerOperator.POINTER)
pointerString = ("*");
if(po == ASTPointerOperator.REFERENCE)
pointerString =("&");
if(po == ASTPointerOperator.CONST_POINTER)
pointerString =("* const");
if(po == ASTPointerOperator.VOLATILE_POINTER)
pointerString =("* volatile");
return pointerString;
}
public static String getArrayQualifiers(IASTAbstractDeclaration declaration){
StringBuffer arrayString = new StringBuffer();
Iterator i = declaration.getArrayModifiers();
while (i.hasNext()){
ASTArrayModifier q = (ASTArrayModifier) i.next();
arrayString.append("[]");
}
return arrayString.toString();
}
public static String[] getFunctionParameterTypes(IASTFunction functionDeclaration)
{
Iterator parameters = functionDeclaration.getParameters();
return getParameterTypes(parameters);
}
public static String[] getParameterTypes(Iterator parameters){
List paramList = new ArrayList();
while (parameters.hasNext()){
IASTParameterDeclaration param = (IASTParameterDeclaration)parameters.next();
paramList.add(getType(param));
}
String[] parameterTypes = new String[paramList.size()];
for(int i=0; i<paramList.size(); ++i){
parameterTypes[i] = (String)paramList.get(i);
}
return parameterTypes;
}
public static String getParametersString(String[] parameterTypes)
{
StringBuffer parameters = new StringBuffer("");
if ((parameterTypes != null) && (parameterTypes.length > 0)) {
parameters.append("(");
int i = 0;
parameters.append(parameterTypes[i++]);
while (i < parameterTypes.length) {
parameters.append(", ");
parameters.append(parameterTypes[i++]);
}
parameters.append(")");
} else {
if (parameterTypes != null) parameters.append("()");
}
return parameters.toString();
}
}

View file

@ -30,6 +30,7 @@ public class BasicSearchMatch implements IMatch, Comparable {
public BasicSearchMatch(BasicSearchMatch basicMatch) {
name = basicMatch.name;
parentName = basicMatch.parentName;
returnType = basicMatch.returnType;
resource = basicMatch.resource;
path = basicMatch.path;
startOffset = basicMatch.startOffset;
@ -41,6 +42,7 @@ public class BasicSearchMatch implements IMatch, Comparable {
hashString += name;
hashString += ":" + parentName;
hashString += ":" + returnType;
hashString += ":" + getLocation().toString();
hashString += ":" + startOffset + ":" + endOffset;
hashString += ":" + type + ":" + visibility;
@ -62,7 +64,9 @@ public class BasicSearchMatch implements IMatch, Comparable {
if( type != match.getElementType() || visibility != match.getVisibility() )
return false;
if( !name.equals( match.getName() ) || !parentName.equals( match.getParentName() ) )
if( !name.equals( match.getName() )
|| !parentName.equals( match.getParentName() )
|| !returnType.equals( match.getReturnType() ) )
return false;
IPath thisPath = getLocation();
@ -90,14 +94,15 @@ public class BasicSearchMatch implements IMatch, Comparable {
str1 += " " + getStartOffset()+ " ";
str2 += " " + match.getStartOffset()+ " ";
str1 += getName() + " " + getParentName();
str2 += match.getName() + " " + match.getParentName();
str1 += getName() + " " + getParentName()+ " " + getReturnType();
str2 += match.getName() + " " + match.getParentName()+ " " + getReturnType();
return str1.compareTo( str2 );
}
public String name = null;
public String parentName = null;
public String returnType;
public IResource resource = null;
public IPath path = null;
@ -128,6 +133,10 @@ public class BasicSearchMatch implements IMatch, Comparable {
return parentName;
}
public String getReturnType() {
return returnType;
}
public IResource getResource() {
return resource;
}
@ -207,6 +216,13 @@ public class BasicSearchMatch implements IMatch, Comparable {
parentName = string;
}
/**
* @param string
*/
public void setReturnType(String string) {
returnType = string;
}
/**
* @param i
*/

View file

@ -40,6 +40,7 @@ import org.eclipse.cdt.core.parser.ast.IASTSimpleTypeSpecifier;
import org.eclipse.cdt.core.parser.ast.IASTTypeSpecifier;
import org.eclipse.cdt.core.parser.ast.IASTTypedefDeclaration;
import org.eclipse.cdt.core.parser.ast.IASTVariable;
import org.eclipse.cdt.internal.core.parser.util.ASTUtil;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
@ -110,6 +111,7 @@ public class BasicSearchResultCollector implements ICSearchResultCollector {
if( offsetable instanceof IASTFunction ){
result.name += getParameterString( (IASTFunction) offsetable );
result.returnType = ASTUtil.getType(((IASTFunction)offsetable).getReturnType());
}
setElementInfo( result, offsetable );

View file

@ -1,3 +1,14 @@
<<<<<<< ChangeLog
<<<<<<< ChangeLog
2003-09-19 Hoda Amer
Solutions to
bug#43162 : Code Assist not showing the right return value
Bug#43145 : foo function still showing in Code Assist even if "f" is deleted
Bug#42810 : Code Assist adding characters after pressing <enter>
Bug#42861 : Code Assist should be case insensitive.
=======
=======
2003-09-22 Andrew Niefer
fix for bug 43327 Code Complete finds local variables
- update calls to SearchEngine.search. CodeCompletion passes true for excludeLocalDeclarations
@ -15,6 +26,7 @@
* plugin.xml
>>>>>>> 1.181
2003-09-21 Alain Magloire
Patch contributed by Keith Campbell.
@ -43,6 +55,7 @@
* src/org/eclipse/cdt/internal/ui/editor/asm/AsmPartitionScanner.java
>>>>>>> 1.179
2003-09-18 Hoda Amer
Solution to bug#42611 : New Class Wizard should be hidden for C projects

View file

@ -14,6 +14,7 @@ import java.util.Iterator;
import java.util.Map;
import org.eclipse.cdt.internal.ui.CPluginImages;
import org.eclipse.cdt.internal.ui.ICHelpContextIds;
import org.eclipse.cdt.internal.ui.dialogs.StatusInfo;
import org.eclipse.cdt.internal.ui.dialogs.StatusUtil;
import org.eclipse.cdt.internal.ui.editor.CEditor;
@ -58,6 +59,7 @@ import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPreferencePage;
import org.eclipse.ui.editors.text.TextEditorPreferenceConstants;
import org.eclipse.ui.help.WorkbenchHelp;
import org.eclipse.ui.texteditor.AnnotationPreference;
import org.eclipse.ui.texteditor.MarkerAnnotationPreferences;
import org.eclipse.ui.texteditor.WorkbenchChainedTextFontFieldEditor;
@ -352,6 +354,7 @@ public class CEditorPreferencePage extends PreferencePage implements IWorkbenchP
*/
public void createControl(Composite parent) {
super.createControl(parent);
WorkbenchHelp.setHelp(parent, ICHelpContextIds.C_EDITOR_PREF_PAGE);
}
protected void handleListSelection() {

View file

@ -12,7 +12,6 @@ import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import org.eclipse.cdt.core.index.TagFlags;
import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.IFunction;
@ -161,7 +160,7 @@ public class CCompletionProcessor implements IContentAssistProcessor {
/**
* @see IContentAssistProcessor#computeContextInformation(ITextViewer, int)
*/
public IContextInformation[] computeContextInformation(ITextViewer viewer, int offset) {
public IContextInformation[] computeContextInformation(ITextViewer viewer, int offset) {
return null;
}
@ -206,6 +205,7 @@ public class CCompletionProcessor implements IContentAssistProcessor {
* @see IContentAssistProcessor#computeCompletionProposals(ITextViewer, int)
*/
public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int documentOffset) {
IWorkingCopyManager fManager = CUIPlugin.getDefault().getWorkingCopyManager();
ITranslationUnit unit = fManager.getWorkingCopy(fEditor.getEditorInput());
@ -242,7 +242,6 @@ public class CCompletionProcessor implements IContentAssistProcessor {
fTemplateEngine[i].reset();
fTemplateEngine[i].complete(viewer, documentOffset, null);
} catch (Exception x) {
System.out.println("Template Exception");
CUIPlugin.getDefault().log(x);
}
@ -313,11 +312,11 @@ public class CCompletionProcessor implements IContentAssistProcessor {
return order (evalProposals(document, pos, length, getCurrentScope (unit, pos)));
}
private ICCompletionProposal[] evalProposals(IDocument document, int pos, int length, ICElement currentScope) {
private ICCompletionProposal[] evalProposals(IDocument document, int startPos, int length, ICElement currentScope) {
boolean isDereference = false;
IRegion region;
String frag = "";
int pos = startPos;
// TODO: Do all possible scopes
// possible scopes include IStructure, INamespace, and ITranslationUnit
if( ( !(currentScope instanceof IMethod))
@ -372,7 +371,8 @@ public class CCompletionProcessor implements IContentAssistProcessor {
}
try {
frag = document.get(region.getOffset(), region.getLength());
//frag = document.get(region.getOffset(), region.getLength());
frag = document.get(region.getOffset(), startPos - region.getOffset());
frag = frag.trim();
} catch (BadLocationException ex) {
return null; //Bail out on error
@ -403,7 +403,7 @@ public class CCompletionProcessor implements IContentAssistProcessor {
// Based on the frag name, build a list of completion proposals
ArrayList completions = new ArrayList();
// Look in index manager
addProposalsFromModel(region, frag,currentScope, completions);
@ -431,7 +431,7 @@ public class CCompletionProcessor implements IContentAssistProcessor {
proposal = new CCompletionProposal(fname,
region.getOffset(),
region.getLength(),
getTagImage(TagFlags.T_FUNCTION),
CPluginImages.get(CPluginImages.IMG_OBJS_FUNCTION),
fproto.getPrototypeString(true),
2);
@ -447,34 +447,6 @@ public class CCompletionProcessor implements IContentAssistProcessor {
}
}
// It is not needed to follow referenced projects since search does this for us now
/* private void addProposalsFromModel(IRegion region, String frag, ICElement currentScope, ArrayList completions) {
IProject project = null;
IEditorInput input = fEditor.getEditorInput();
if (input instanceof IFileEditorInput) {
project = ((IFileEditorInput) input).getFile().getProject();
// Bail out quickly, if the project was deleted.
if (!project.exists()) {
project = null;
}
}
if (project != null) {
addProjectCompletions(project, region, frag, currentScope, completions);
// Now query referenced projects
IProject referenced[];
try {
referenced = project.getReferencedProjects();
if (referenced.length > 0) {
for (int i = 0; i < referenced.length; i++) {
addProjectCompletions(referenced[i], region, frag, currentScope, completions);
}
}
} catch (CoreException e) {
}
}
}
*/
private FunctionPrototypeSummary getPrototype (BasicSearchMatch match) {
switch(match.getElementType()){
case ICElement.C_FUNCTION:
@ -482,7 +454,7 @@ public class CCompletionProcessor implements IContentAssistProcessor {
case ICElement.C_METHOD:
case ICElement.C_METHOD_DECLARATION:
{
return (new FunctionPrototypeSummary ( match.getName() ));
return (new FunctionPrototypeSummary ( match.getReturnType() + " " + match.getName() ));
}
default:
return null;
@ -529,28 +501,18 @@ public class CCompletionProcessor implements IContentAssistProcessor {
ICSearchScope scope = SearchEngine.createCSearchScope(projectScopeElement, true);
OrPattern orPattern = new OrPattern();
// search for global variables, functions, classes, structs, unions, enums and macros
orPattern.addPattern(SearchEngine.createSearchPattern( prefix, ICSearchConstants.VAR, ICSearchConstants.DECLARATIONS, true ));
orPattern.addPattern(SearchEngine.createSearchPattern( prefix, ICSearchConstants.FUNCTION, ICSearchConstants.DECLARATIONS, true ));
orPattern.addPattern(SearchEngine.createSearchPattern( prefix, ICSearchConstants.FUNCTION, ICSearchConstants.DEFINITIONS, true ));
orPattern.addPattern(SearchEngine.createSearchPattern( prefix, ICSearchConstants.TYPE, ICSearchConstants.DECLARATIONS, true ));
orPattern.addPattern(SearchEngine.createSearchPattern( prefix, ICSearchConstants.ENUM, ICSearchConstants.DECLARATIONS, true ));
orPattern.addPattern(SearchEngine.createSearchPattern( prefix, ICSearchConstants.MACRO, ICSearchConstants.DECLARATIONS, true ));
orPattern.addPattern(SearchEngine.createSearchPattern( prefix, ICSearchConstants.VAR, ICSearchConstants.DECLARATIONS, false ));
orPattern.addPattern(SearchEngine.createSearchPattern( prefix, ICSearchConstants.FUNCTION, ICSearchConstants.DECLARATIONS, false ));
orPattern.addPattern(SearchEngine.createSearchPattern( prefix, ICSearchConstants.FUNCTION, ICSearchConstants.DEFINITIONS, false ));
orPattern.addPattern(SearchEngine.createSearchPattern( prefix, ICSearchConstants.TYPE, ICSearchConstants.DECLARATIONS, false ));
orPattern.addPattern(SearchEngine.createSearchPattern( prefix, ICSearchConstants.ENUM, ICSearchConstants.DECLARATIONS, false ));
orPattern.addPattern(SearchEngine.createSearchPattern( prefix, ICSearchConstants.MACRO, ICSearchConstants.DECLARATIONS, false ));
searchEngine.search(CUIPlugin.getWorkspace(), orPattern, scope, resultCollector, true);
elementsFound.addAll(resultCollector.getSearchResults());
if((currentScope instanceof IMethod) || (currentScope instanceof IMethodDeclaration) ){
// add the methods and fields of the parent class
/* // use search with CElement Scope
ICElement[] classScopeElements = new ICElement[1];
classScopeElements[0] = currentScope.getParent();
ICSearchScope classScope = SearchEngine.createCSearchScope(classScopeElements);
OrPattern classOrPattern = new OrPattern();
classOrPattern.addPattern(SearchEngine.createSearchPattern(prefix, ICSearchConstants.FIELD, ICSearchConstants.DECLARATIONS, true));
classOrPattern.addPattern(SearchEngine.createSearchPattern(prefix, ICSearchConstants.METHOD, ICSearchConstants.DECLARATIONS, true));
classOrPattern.addPattern(SearchEngine.createSearchPattern(prefix, ICSearchConstants.METHOD, ICSearchConstants.DEFINITIONS, true));
searchEngine.search(CUIPlugin.getWorkspace(), classOrPattern, classScope, resultCollector);
elementsFound.addAll(resultCollector.getSearchResults());
*/
// Work around until CElement scope is implemented
IStructure parentClass = (IStructure) currentScope.getParent();
ArrayList children = new ArrayList();
@ -576,6 +538,7 @@ public class CCompletionProcessor implements IContentAssistProcessor {
childMatch.setStatic(child.isStatic());
if(child instanceof IMethodDeclaration){
childMatch.setName(((IMethodDeclaration)child).getSignature());
childMatch.setReturnType( ((IMethodDeclaration)child).getReturnType() );
}
else {
childMatch.setName(child.getElementName());
@ -613,7 +576,7 @@ public class CCompletionProcessor implements IContentAssistProcessor {
infoString.append(" - Parent: ");
infoString.append(match.getParentName());
}
proposal = new CCompletionProposal(
replaceString, // Replacement string
region.getOffset(),
@ -638,94 +601,4 @@ public class CCompletionProcessor implements IContentAssistProcessor {
proposal.setAdditionalProposalInfo(infoString.toString());
}
}
// Search (and the new indexer) is used now instead of the old indexer and CTags
/* private void addProjectCompletions(IProject project, IRegion region, String frag, ArrayList completions) {
IndexModel model = IndexModel.getDefault();
ITagEntry[] tags = model.query(project, frag + "*", false, false);
if (tags != null && tags.length > 0) {
for (int i = 0; i < tags.length; i++) {
FunctionPrototypeSummary fproto = null;
String fargs = null;
String fdisplay = null;
String fdesc = null;
String fname = tags[i].getTagName();
int kind = tags[i].getKind();
//No member completion yet
if (kind == TagFlags.T_MEMBER) {
continue;
}
//This doesn't give you a nice "function" look to macros, but is safe
if (kind == TagFlags.T_FUNCTION || kind == TagFlags.T_PROTOTYPE) {
fname = fname + "()";
String pattern = tags[i].getPattern();
if(pattern != null) {
fproto = new FunctionPrototypeSummary(pattern);
}
if(fproto == null) {
fproto = new FunctionPrototypeSummary(fname);
}
}
if(fproto != null) {
fargs = fproto.getArguments();
fdisplay = fproto.getPrototypeString(true);
} else {
fdisplay = fname;
}
//@@@ In the future something more usefull could go in here (ie Doxygen/JavaDoc)
fdesc = "<b>" + fname + "</b><br>" + "Defined in:<br> " + tags[i].getFileName();
if(tags[i].getClassName() != null) {
fdesc = fdesc + "<br>Class:<br> " + tags[i].getClassName();
}
//System.out.println("tagmatch " + fname + " proto " + proto + " type" + tags[i].getKind());
CCompletionProposal proposal;
proposal = new CCompletionProposal(fname,
region.getOffset(),
region.getLength(),
getTagImage(kind),
fdisplay,
3);
completions.add(proposal);
if(fdesc != null) {
proposal.setAdditionalProposalInfo(fdesc);
}
if(fargs != null && fargs.length() > 0) {
proposal.setContextInformation(new ContextInformation(fname, fargs));
}
}
}
}
*/
private Image getTagImage(int kind) {
switch (kind) {
case TagFlags.T_PROTOTYPE :
return CPluginImages.get(CPluginImages.IMG_OBJS_DECLARATION);
case TagFlags.T_CLASS :
return CPluginImages.get(CPluginImages.IMG_OBJS_CLASS);
case TagFlags.T_ENUM :
case TagFlags.T_VARIABLE :
case TagFlags.T_MEMBER :
return CPluginImages.get(CPluginImages.IMG_OBJS_FIELD);
case TagFlags.T_FUNCTION :
return CPluginImages.get(CPluginImages.IMG_OBJS_FUNCTION);
case TagFlags.T_STRUCT :
return CPluginImages.get(CPluginImages.IMG_OBJS_STRUCT);
case TagFlags.T_UNION :
return CPluginImages.get(CPluginImages.IMG_OBJS_UNION);
case TagFlags.T_MACRO :
return CPluginImages.get(CPluginImages.IMG_OBJS_MACRO);
}
return CPluginImages.get(CPluginImages.IMG_OBJS_FUNCTION);
}
}

View file

@ -165,11 +165,11 @@ public class CCompletionProposal implements ICCompletionProposal, ICompletionPro
int functionBracketIndex;
boolean isBeforeBracket;
String replacementStringCopy = fReplacementString;
fReplacementLength = offset - fReplacementOffset;
//If just providing context information, then don't move the cursor
if(offset != (fReplacementOffset + fReplacementLength)) {
fCursorPosition = offset - fReplacementOffset;
}
// if(offset != (fReplacementOffset + fReplacementLength)) {
// fCursorPosition = offset - fReplacementOffset;
// }
try {
functionBracketIndex = fReplacementString.indexOf("()");