mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-23 06:32:10 +02:00
Bug 395562 - Follow-up to fix a regression where completing the method name in an out-of-line method definition would no longer insert parentheses
Change-Id: I8bbf083e874f6d01aa85c2ba4173685228160963
This commit is contained in:
parent
add2a14628
commit
a90caec05e
2 changed files with 34 additions and 5 deletions
|
@ -719,6 +719,16 @@ public class CompletionTests extends CompletionTestBase {
|
||||||
final String[] expected = { "method", "datamem" };
|
final String[] expected = { "method", "datamem" };
|
||||||
assertMinimumCompletionResults(fCursorOffset, expected, REPLACEMENT);
|
assertMinimumCompletionResults(fCursorOffset, expected, REPLACEMENT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// struct Waldo {
|
||||||
|
// void find();
|
||||||
|
// };
|
||||||
|
// void Waldo::f/*cursor*/
|
||||||
|
public void testRegression_395562() throws Exception {
|
||||||
|
// Should include parentheses in replacement string when completing
|
||||||
|
// out-of-line method definition.
|
||||||
|
assertCompletionResults(new String[] { "find()" });
|
||||||
|
}
|
||||||
|
|
||||||
// typedef struct {
|
// typedef struct {
|
||||||
// int sx;
|
// int sx;
|
||||||
|
@ -1236,10 +1246,10 @@ public class CompletionTests extends CompletionTestBase {
|
||||||
public void testDestructorDefinition_456293() throws Exception {
|
public void testDestructorDefinition_456293() throws Exception {
|
||||||
final String[] expectedDisplay = { "~Waldo(void)" };
|
final String[] expectedDisplay = { "~Waldo(void)" };
|
||||||
assertCompletionResults(fCursorOffset, expectedDisplay, DISPLAY);
|
assertCompletionResults(fCursorOffset, expectedDisplay, DISPLAY);
|
||||||
final String[] expectedReplacement = { "Waldo" };
|
final String[] expectedReplacement = { "Waldo()" };
|
||||||
assertCompletionResults(fCursorOffset, expectedReplacement, REPLACEMENT);
|
assertCompletionResults(fCursorOffset, expectedReplacement, REPLACEMENT);
|
||||||
}
|
}
|
||||||
|
|
||||||
// template <typename T> struct vector {
|
// template <typename T> struct vector {
|
||||||
// typedef T value_type;
|
// typedef T value_type;
|
||||||
// void push_back(const value_type& value) {}
|
// void push_back(const value_type& value) {}
|
||||||
|
|
|
@ -529,7 +529,7 @@ public class DOMCompletionProposalComputer extends ParsingBasedProposalComputer
|
||||||
return relevance;
|
return relevance;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns whether a function name being completed could be a call that function.
|
// Returns whether a function name being completed could be a call to that function.
|
||||||
private boolean canBeCall(IFunction function, IASTCompletionContext astContext,
|
private boolean canBeCall(IFunction function, IASTCompletionContext astContext,
|
||||||
CContentAssistInvocationContext cContext) {
|
CContentAssistInvocationContext cContext) {
|
||||||
// Can't have a call in a using-directive.
|
// Can't have a call in a using-directive.
|
||||||
|
@ -548,6 +548,23 @@ public class DOMCompletionProposalComputer extends ParsingBasedProposalComputer
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Returns whether a function name being completed could be a definition of that function.
|
||||||
|
private boolean canBeDefinition(IFunction function, IASTCompletionContext astContext) {
|
||||||
|
if (!(astContext instanceof IASTName)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
// If content assist is invoked while completing the destructor name in an
|
||||||
|
// out-of-line destructor definition, the parser doesn't have enough information
|
||||||
|
// to recognize that this is a function definition, and so getRoleOfName() will
|
||||||
|
// incorrectly return r_reference. Since destructors are rarely referred to
|
||||||
|
// explicitly, just assume destructor name is a definition.
|
||||||
|
if (function instanceof ICPPMethod && ((ICPPMethod) function).isDestructor()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
IASTName name = (IASTName) astContext;
|
||||||
|
return name.getRoleOfName(false) == IASTNameOwner.r_definition;
|
||||||
|
}
|
||||||
|
|
||||||
private String getFunctionNameForReplacement(IFunction function, IASTCompletionContext astContext) {
|
private String getFunctionNameForReplacement(IFunction function, IASTCompletionContext astContext) {
|
||||||
// If we are completiong a destructor name ...
|
// If we are completiong a destructor name ...
|
||||||
if (function instanceof ICPPMethod && ((ICPPMethod) function).isDestructor()) {
|
if (function instanceof ICPPMethod && ((ICPPMethod) function).isDestructor()) {
|
||||||
|
@ -574,6 +591,8 @@ public class DOMCompletionProposalComputer extends ParsingBasedProposalComputer
|
||||||
repStringBuff.append(getFunctionNameForReplacement(function, astContext));
|
repStringBuff.append(getFunctionNameForReplacement(function, astContext));
|
||||||
|
|
||||||
boolean canBeCall = canBeCall(function, astContext, cContext);
|
boolean canBeCall = canBeCall(function, astContext, cContext);
|
||||||
|
boolean canBeDefinition = canBeDefinition(function, astContext);
|
||||||
|
boolean wantParens = canBeCall || canBeDefinition;
|
||||||
|
|
||||||
StringBuilder dispArgs = new StringBuilder(); // For the dispArgString
|
StringBuilder dispArgs = new StringBuilder(); // For the dispArgString
|
||||||
StringBuilder idArgs = new StringBuilder(); // For the idArgString
|
StringBuilder idArgs = new StringBuilder(); // For the idArgString
|
||||||
|
@ -652,8 +671,8 @@ public class DOMCompletionProposalComputer extends ParsingBasedProposalComputer
|
||||||
|
|
||||||
boolean inUsingDeclaration = cContext.isInUsingDirective();
|
boolean inUsingDeclaration = cContext.isInUsingDirective();
|
||||||
|
|
||||||
if (canBeCall && !cContext.isFollowedByOpeningParen()) {
|
if (wantParens && !cContext.isFollowedByOpeningParen()) {
|
||||||
// If we might be calling the function in this context, assume we are
|
// If we might be calling or defining the function in this context, assume we are
|
||||||
// (since that's the most common case) and emit parentheses.
|
// (since that's the most common case) and emit parentheses.
|
||||||
repStringBuff.append('(');
|
repStringBuff.append('(');
|
||||||
repStringBuff.append(')');
|
repStringBuff.append(')');
|
||||||
|
|
Loading…
Add table
Reference in a new issue