mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-08 10:16:03 +02:00
Follow-up fix for bug 72824 - Missing proposals in method definition context
This commit is contained in:
parent
b81075824d
commit
c9ea66eaaf
3 changed files with 23 additions and 9 deletions
|
@ -20,6 +20,7 @@ import org.eclipse.cdt.core.dom.ast.IASTCompletionContext;
|
|||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTNameOwner;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration;
|
||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.IEnumerator;
|
||||
import org.eclipse.cdt.core.dom.ast.IField;
|
||||
|
@ -28,6 +29,7 @@ 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.ICPPClassType;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPConstructor;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMember;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespace;
|
||||
|
@ -330,6 +332,7 @@ public class CPPASTQualifiedName extends CPPASTNode implements
|
|||
}
|
||||
|
||||
try {
|
||||
final boolean isDeclaration = getParent().getParent() instanceof IASTSimpleDeclaration;
|
||||
IBinding[] bindings = classType.getCompositeScope().find(new String(name), isPrefix);
|
||||
for (int i = 0; i < bindings.length; i++) {
|
||||
if (bindings[i] instanceof ICPPMember) {
|
||||
|
@ -342,8 +345,11 @@ public class CPPASTQualifiedName extends CPPASTNode implements
|
|||
} else if (member instanceof ICPPMethod) {
|
||||
ICPPMethod method = (ICPPMethod) member;
|
||||
if (method.isImplicit()) continue;
|
||||
if (method.isDestructor() || method instanceof ICPPConstructor) {
|
||||
if (!isDeclaration) continue;
|
||||
} else if (!method.isStatic() && !isDeclaration) continue;
|
||||
}
|
||||
} else if (!(bindings[i] instanceof IEnumerator)) continue;
|
||||
} else if (!(bindings[i] instanceof IEnumerator) || isDeclaration) continue;
|
||||
|
||||
filtered.add(bindings[i]);
|
||||
}
|
||||
|
|
|
@ -317,16 +317,12 @@ public class CPPClassScope extends CPPScope implements ICPPClassScope {
|
|||
}
|
||||
|
||||
IBinding[] results = null;
|
||||
|
||||
results = (IBinding[]) ArrayUtil.addAll( IBinding.class, results, super.find( name, prefixLookup ));
|
||||
|
||||
if((prefixLookup && CharArrayUtils.equals(compName.toCharArray(), 0, n.length, n, false))
|
||||
|| (!prefixLookup && CharArrayUtils.equals(compName.toCharArray(), n))) {
|
||||
results = (IBinding[]) ArrayUtil.addAll( IBinding.class, null, getConstructors( bindings, true ) );
|
||||
if (!prefixLookup) {
|
||||
return results;
|
||||
}
|
||||
results = (IBinding[]) ArrayUtil.addAll( IBinding.class, results, getConstructors( bindings, true ) );
|
||||
}
|
||||
|
||||
results = (IBinding[]) ArrayUtil.addAll( IBinding.class, results, super.find( name, prefixLookup ));
|
||||
return results != null ? results : IBinding.EMPTY_BINDING_ARRAY;
|
||||
}
|
||||
|
||||
|
|
|
@ -199,6 +199,7 @@ public class ContentAssistTests extends BaseUITestCase {
|
|||
writer.write( "public : \n"); //$NON-NLS-1$
|
||||
writer.write( " enum _Ability { IDIOT, NORMAL, CHEAT } ; \n"); //$NON-NLS-1$
|
||||
writer.write( " Strategy( _Ability a ) { } \n"); //$NON-NLS-1$
|
||||
writer.write( " _Ability getAbility(); \n"); //$NON-NLS-1$
|
||||
writer.write( "}; \n"); //$NON-NLS-1$
|
||||
writer.write( "int main(){ \n"); //$NON-NLS-1$
|
||||
|
||||
|
@ -220,7 +221,18 @@ public class ContentAssistTests extends BaseUITestCase {
|
|||
assertEquals( "CHEAT", results[0].getDisplayString() ); //$NON-NLS-1$
|
||||
assertEquals( "IDIOT", results[1].getDisplayString() ); //$NON-NLS-1$
|
||||
assertEquals( "NORMAL", results[2].getDisplayString() ); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
// in a method definition context, constructors and methods should be proposed
|
||||
|
||||
c2 = code + "return 0;}\nStrategy::\n"; //$NON-NLS-1$
|
||||
|
||||
cu = importFile( "strategy.cpp", c2 ); //$NON-NLS-1$
|
||||
|
||||
results = getResults( cu, c2.indexOf( "::" ) + 2 ); //$NON-NLS-1$
|
||||
assertEquals( 2, results.length );
|
||||
assertEquals( "getAbility(void) enum _Ability", results[0].getDisplayString() ); //$NON-NLS-1$
|
||||
assertEquals( "Strategy(enum _Ability a)", results[1].getDisplayString() ); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
public void testBug72559() throws Exception {
|
||||
StringWriter writer = new StringWriter();
|
||||
|
|
Loading…
Add table
Reference in a new issue