mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-09-04 14:13:24 +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.ICPPASTOperatorName;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName;
|
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.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.ICPPClassScope;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPConstructor;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPConstructor;
|
||||||
|
@ -342,6 +343,11 @@ public class CPPASTQualifiedName extends CPPASTNameBase
|
||||||
return bindings;
|
return bindings;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Are we inside a using-declaration?
|
||||||
|
private boolean inUsingDecl() {
|
||||||
|
return getParent() instanceof ICPPASTUsingDeclaration;
|
||||||
|
}
|
||||||
|
|
||||||
private boolean canBeFieldAccess(ICPPClassType baseClass) {
|
private boolean canBeFieldAccess(ICPPClassType baseClass) {
|
||||||
IASTNode parent= getParent();
|
IASTNode parent= getParent();
|
||||||
if (parent instanceof IASTFieldReference) {
|
if (parent instanceof IASTFieldReference) {
|
||||||
|
@ -368,14 +374,14 @@ public class CPPASTQualifiedName extends CPPASTNameBase
|
||||||
private List<IBinding> filterClassScopeBindings(ICPPClassType classType, IBinding[] bindings,
|
private List<IBinding> filterClassScopeBindings(ICPPClassType classType, IBinding[] bindings,
|
||||||
final boolean isDeclaration) {
|
final boolean isDeclaration) {
|
||||||
List<IBinding> filtered = new ArrayList<IBinding>();
|
List<IBinding> filtered = new ArrayList<IBinding>();
|
||||||
final boolean canBeFieldAccess = canBeFieldAccess(classType);
|
final boolean allowNonstatic = canBeFieldAccess(classType) || inUsingDecl();
|
||||||
final IBinding templateDefinition = (classType instanceof ICPPTemplateInstance)
|
final IBinding templateDefinition = (classType instanceof ICPPTemplateInstance)
|
||||||
? ((ICPPTemplateInstance) classType).getTemplateDefinition() : null;
|
? ((ICPPTemplateInstance) classType).getTemplateDefinition() : null;
|
||||||
|
|
||||||
for (final IBinding binding : bindings) {
|
for (final IBinding binding : bindings) {
|
||||||
if (binding instanceof IField) {
|
if (binding instanceof IField) {
|
||||||
IField field = (IField) binding;
|
IField field = (IField) binding;
|
||||||
if (!canBeFieldAccess && !field.isStatic())
|
if (!allowNonstatic && !field.isStatic())
|
||||||
continue;
|
continue;
|
||||||
} else if (binding instanceof ICPPMethod) {
|
} else if (binding instanceof ICPPMethod) {
|
||||||
ICPPMethod method = (ICPPMethod) binding;
|
ICPPMethod method = (ICPPMethod) binding;
|
||||||
|
@ -383,7 +389,7 @@ public class CPPASTQualifiedName extends CPPASTNameBase
|
||||||
continue;
|
continue;
|
||||||
if (!isDeclaration) {
|
if (!isDeclaration) {
|
||||||
if (method.isDestructor() || method instanceof ICPPConstructor
|
if (method.isDestructor() || method instanceof ICPPConstructor
|
||||||
|| (!canBeFieldAccess && !method.isStatic()))
|
|| (!allowNonstatic && !method.isStatic()))
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
} else if (binding instanceof IEnumerator || binding instanceof IEnumeration) {
|
} else if (binding instanceof IEnumerator || binding instanceof IEnumeration) {
|
||||||
|
|
|
@ -1255,6 +1255,23 @@ public class CompletionTests extends CompletionTestBase {
|
||||||
assertCompletionResults(fCursorOffset, expected, REPLACEMENT);
|
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*/
|
// template <typen/*cursor*/
|
||||||
public void testTemplateDeclaration_397288() throws Exception {
|
public void testTemplateDeclaration_397288() throws Exception {
|
||||||
final String[] expected= { "typename" };
|
final String[] expected= { "typename" };
|
||||||
|
|
Loading…
Add table
Reference in a new issue