mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-05 23:35:48 +02:00
Bug 223660: Parameter help for constructor-style initializers.
This commit is contained in:
parent
ea310fa845
commit
d03bee7bc7
4 changed files with 86 additions and 33 deletions
|
@ -286,4 +286,14 @@ public class BasicCompletionTest extends CompletionTestBase {
|
|||
String[] expected= {"A"};
|
||||
checkNonPrefixCompletion(code, true, expected);
|
||||
}
|
||||
|
||||
// struct S {};
|
||||
// void foo() {
|
||||
// S b
|
||||
public void testCompletionInCtorOfVariable_223660() throws Exception {
|
||||
String code = getAboveComment();
|
||||
String[] expected= {"b"};
|
||||
checkNonPrefixCompletion(code, true, expected);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -85,13 +85,19 @@ public class CPPASTName extends CPPASTNameBase implements ICPPASTCompletionConte
|
|||
}
|
||||
IBinding[] bindings = CPPSemantics.findBindingsForContentAssist(n, isPrefix, namespaces);
|
||||
return filterByElaboratedTypeSpecifier(kind, bindings);
|
||||
}
|
||||
else if (parent instanceof IASTDeclarator) {
|
||||
} else if (parent instanceof IASTDeclarator) {
|
||||
IBinding[] bindings = CPPSemantics.findBindingsForContentAssist(n, isPrefix, namespaces);
|
||||
for (int i = 0; i < bindings.length; i++) {
|
||||
if (bindings[i] instanceof ICPPNamespace || bindings[i] instanceof ICPPClassType) {
|
||||
} else {
|
||||
bindings[i] = null;
|
||||
if (!isPrefix) {
|
||||
// The lookup does not find the binding, that is defined by this name
|
||||
if (bindings.length == 0) {
|
||||
bindings= new IBinding[] {n.resolveBinding()};
|
||||
}
|
||||
} else {
|
||||
for (int i = 0; i < bindings.length; i++) {
|
||||
if (bindings[i] instanceof ICPPNamespace || bindings[i] instanceof ICPPClassType) {
|
||||
} else {
|
||||
bindings[i] = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
return (IBinding[])ArrayUtil.removeNulls(IBinding.class, bindings);
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2007, 2008 QNX Software Systems and others.
|
||||
* Copyright (c) 2007, 2010 QNX Software Systems and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
|
@ -8,6 +8,7 @@
|
|||
* Contributors:
|
||||
* Bryan Wilkinson (QNX) - Initial API and implementation
|
||||
* Anton Leherbauer (Wind River Systems)
|
||||
* Markus Schorn (Wind River Systems)
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.ui.tests.text.contentassist2;
|
||||
|
||||
|
@ -23,25 +24,25 @@ public class ParameterHintTests extends AbstractContentAssistTest {
|
|||
private static final String HEADER_FILE_NAME = "PHTest.h";
|
||||
private static final String SOURCE_FILE_NAME = "PHTest.cpp";
|
||||
|
||||
//{PHTest.h}
|
||||
//class aClass {
|
||||
//public:
|
||||
// int aField;
|
||||
// void aMethod(char c);
|
||||
// void aMethod(char c, int x);
|
||||
//};
|
||||
//class bClass {
|
||||
//public:
|
||||
// bClass(int x);
|
||||
// bClass(int x, int y);
|
||||
//};
|
||||
//void aFunc(int i);
|
||||
//int anotherFunc(int i, int j);
|
||||
//int pi(aClass a);
|
||||
//int pie(aClass a);
|
||||
//int pies(aClass a);
|
||||
//template<class T>class tClass {public:tClass(T t);};
|
||||
//template<class T>void tFunc(T x, T y);
|
||||
// {PHTest.h}
|
||||
// class aClass {
|
||||
// public:
|
||||
// int aField;
|
||||
// void aMethod(char c);
|
||||
// void aMethod(char c, int x);
|
||||
// };
|
||||
// class bClass {
|
||||
// public:
|
||||
// bClass(int x);
|
||||
// bClass(int x, int y);
|
||||
// };
|
||||
// void aFunc(int i);
|
||||
// int anotherFunc(int i, int j);
|
||||
// int pi(aClass a);
|
||||
// int pie(aClass a);
|
||||
// int pies(aClass a);
|
||||
// template<class T>class tClass {public:tClass(T t);};
|
||||
// template<class T>void tFunc(T x, T y);
|
||||
|
||||
public ParameterHintTests(String name) {
|
||||
super(name, true);
|
||||
|
@ -129,7 +130,7 @@ public class ParameterHintTests extends AbstractContentAssistTest {
|
|||
}
|
||||
|
||||
//void foo(){bClass b(
|
||||
public void _testConstructor2_Bug223660() throws Exception {
|
||||
public void testConstructor2_Bug223660() throws Exception {
|
||||
// http://bugs.eclipse.org/223660
|
||||
assertParameterHints(new String[] {
|
||||
"bClass(int x)",
|
||||
|
@ -138,6 +139,18 @@ public class ParameterHintTests extends AbstractContentAssistTest {
|
|||
});
|
||||
}
|
||||
|
||||
// struct D {
|
||||
// bClass b;
|
||||
// D() : b(
|
||||
public void testConstructor3_Bug327064() throws Exception {
|
||||
// http://bugs.eclipse.org/327064
|
||||
assertParameterHints(new String[] {
|
||||
"bClass(int x)",
|
||||
"bClass(int x,int y)",
|
||||
"bClass(const bClass &)"
|
||||
});
|
||||
}
|
||||
|
||||
//void foo(){tClass<int> t=new tClass<int>(
|
||||
public void testTemplateConstructor() throws Exception {
|
||||
assertParameterHints(new String[] {
|
||||
|
@ -147,11 +160,11 @@ public class ParameterHintTests extends AbstractContentAssistTest {
|
|||
}
|
||||
|
||||
//void foo(){tClass<int> t(
|
||||
public void _testTemplateConstructor2_Bug223660() throws Exception {
|
||||
public void testTemplateConstructor2_Bug223660() throws Exception {
|
||||
// http://bugs.eclipse.org/223660
|
||||
assertParameterHints(new String[] {
|
||||
"tClass(T t)",
|
||||
"tClass(const tClass &)"
|
||||
"tClass(int t)",
|
||||
"tClass(const tClass<int> &)"
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -302,10 +302,10 @@ public class DOMCompletionProposalComputer extends ParsingBasedProposalComputer
|
|||
handleClass((ICPPClassType) binding, astContext, cContext, baseRelevance, proposals);
|
||||
} else if (binding instanceof IFunction) {
|
||||
handleFunction((IFunction)binding, cContext, baseRelevance, proposals);
|
||||
} else if (binding instanceof IVariable) {
|
||||
handleVariable((IVariable) binding, cContext, baseRelevance, proposals);
|
||||
} else if (!cContext.isContextInformationStyle()) {
|
||||
if (binding instanceof IVariable) {
|
||||
handleVariable((IVariable) binding, cContext, baseRelevance, proposals);
|
||||
} else if (binding instanceof ITypedef) {
|
||||
if (binding instanceof ITypedef) {
|
||||
proposals.add(createProposal(name, name, getImage(binding),
|
||||
baseRelevance + RelevanceConstants.TYPEDEF_TYPE_RELEVANCE, cContext));
|
||||
} else if (binding instanceof ICPPNamespace) {
|
||||
|
@ -456,6 +456,23 @@ public class DOMCompletionProposalComputer extends ParsingBasedProposalComputer
|
|||
|
||||
private void handleVariable(IVariable variable, CContentAssistInvocationContext context,
|
||||
int baseRelevance, List<ICompletionProposal> proposals) {
|
||||
if (context.isContextInformationStyle()) {
|
||||
// Handle the case where a variable is initialized with a constructor
|
||||
try {
|
||||
IType t = variable.getType();
|
||||
t= unwindTypedefs(t);
|
||||
if (t instanceof ICPPClassType) {
|
||||
ICPPClassType classType= (ICPPClassType) t;
|
||||
ICPPConstructor[] constructors = classType.getConstructors();
|
||||
for (ICPPConstructor constructor : constructors) {
|
||||
handleFunction(constructor, context, baseRelevance, proposals);
|
||||
}
|
||||
}
|
||||
} catch (DOMException e) {
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
StringBuilder repStringBuff = new StringBuilder();
|
||||
repStringBuff.append(variable.getName());
|
||||
|
||||
|
@ -490,6 +507,13 @@ public class DOMCompletionProposalComputer extends ParsingBasedProposalComputer
|
|||
proposals.add(proposal);
|
||||
}
|
||||
|
||||
private IType unwindTypedefs(final IType t) {
|
||||
IType r= t;
|
||||
while (r instanceof ITypedef)
|
||||
r= ((ITypedef) r).getType();
|
||||
return r != null ? r : t;
|
||||
}
|
||||
|
||||
private static boolean isField(IVariable variable) {
|
||||
return variable instanceof IField;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue