mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-09-01 12:43:26 +02:00
Bug 511048 - Offer completion proposals for nonstatic methods in a using-declaration
Change-Id: Ifb3aee10c354aebe606c439cdda1453b1cc29095
This commit is contained in:
parent
bbbf9c7059
commit
fcd3f62d31
2 changed files with 26 additions and 3 deletions
|
@ -38,6 +38,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNameSpecifier;
|
|||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTOperatorName;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateId;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTUsingDeclaration;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassScope;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPConstructor;
|
||||
|
@ -342,6 +343,11 @@ public class CPPASTQualifiedName extends CPPASTNameBase
|
|||
return bindings;
|
||||
}
|
||||
|
||||
// Are we inside a using-declaration?
|
||||
private boolean inUsingDecl() {
|
||||
return getParent() instanceof ICPPASTUsingDeclaration;
|
||||
}
|
||||
|
||||
private boolean canBeFieldAccess(ICPPClassType baseClass) {
|
||||
IASTNode parent= getParent();
|
||||
if (parent instanceof IASTFieldReference) {
|
||||
|
@ -368,14 +374,14 @@ public class CPPASTQualifiedName extends CPPASTNameBase
|
|||
private List<IBinding> filterClassScopeBindings(ICPPClassType classType, IBinding[] bindings,
|
||||
final boolean isDeclaration) {
|
||||
List<IBinding> filtered = new ArrayList<IBinding>();
|
||||
final boolean canBeFieldAccess = canBeFieldAccess(classType);
|
||||
final boolean allowNonstatic = canBeFieldAccess(classType) || inUsingDecl();
|
||||
final IBinding templateDefinition = (classType instanceof ICPPTemplateInstance)
|
||||
? ((ICPPTemplateInstance) classType).getTemplateDefinition() : null;
|
||||
|
||||
for (final IBinding binding : bindings) {
|
||||
if (binding instanceof IField) {
|
||||
IField field = (IField) binding;
|
||||
if (!canBeFieldAccess && !field.isStatic())
|
||||
if (!allowNonstatic && !field.isStatic())
|
||||
continue;
|
||||
} else if (binding instanceof ICPPMethod) {
|
||||
ICPPMethod method = (ICPPMethod) binding;
|
||||
|
@ -383,7 +389,7 @@ public class CPPASTQualifiedName extends CPPASTNameBase
|
|||
continue;
|
||||
if (!isDeclaration) {
|
||||
if (method.isDestructor() || method instanceof ICPPConstructor
|
||||
|| (!canBeFieldAccess && !method.isStatic()))
|
||||
|| (!allowNonstatic && !method.isStatic()))
|
||||
continue;
|
||||
}
|
||||
} else if (binding instanceof IEnumerator || binding instanceof IEnumeration) {
|
||||
|
|
|
@ -1255,6 +1255,23 @@ public class CompletionTests extends CompletionTestBase {
|
|||
assertCompletionResults(fCursorOffset, expected, REPLACEMENT);
|
||||
}
|
||||
|
||||
// class Base {
|
||||
// private:
|
||||
// void priv();
|
||||
// protected:
|
||||
// void prot();
|
||||
// public:
|
||||
// void publ();
|
||||
// };
|
||||
// class Derived : Base {
|
||||
// using Base::/*cursor*/
|
||||
// };
|
||||
public void testUsingDeclarationInClass_511048() throws Exception {
|
||||
final String[] expected = { "prot(void)", "publ(void)" };
|
||||
assertCompletionResults(fCursorOffset, expected, ID);
|
||||
}
|
||||
|
||||
|
||||
// template <typen/*cursor*/
|
||||
public void testTemplateDeclaration_397288() throws Exception {
|
||||
final String[] expected= { "typename" };
|
||||
|
|
Loading…
Add table
Reference in a new issue