mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-31 21:05:37 +02:00
Bug 456293 - Completion of destructor name
Change-Id: I53422b1daf693e8ab6c0ad64857e8b07c970444c
This commit is contained in:
parent
1afc08fea8
commit
b1d6194e14
2 changed files with 42 additions and 16 deletions
|
@ -1405,6 +1405,17 @@ public class CompletionTests extends AbstractContentAssistTest {
|
||||||
final String[] expected = { "Waldo(const Waldo &)", "Waldo(int, int)" };
|
final String[] expected = { "Waldo(const Waldo &)", "Waldo(int, int)" };
|
||||||
assertCompletionResults(fCursorOffset, expected, ID);
|
assertCompletionResults(fCursorOffset, expected, ID);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// struct Waldo {
|
||||||
|
// ~Waldo();
|
||||||
|
// };
|
||||||
|
// Waldo::~/*cursor*/
|
||||||
|
public void testDestructorDefinition_456293() throws Exception {
|
||||||
|
final String[] expectedDisplay = { "~Waldo(void)" };
|
||||||
|
assertContentAssistResults(fCursorOffset, expectedDisplay, true, DISPLAY);
|
||||||
|
final String[] expectedReplacement = { "Waldo" };
|
||||||
|
assertContentAssistResults(fCursorOffset, expectedReplacement, true, REPLACEMENT);
|
||||||
|
}
|
||||||
|
|
||||||
// template <typename T> struct vector {
|
// template <typename T> struct vector {
|
||||||
// typedef T value_type;
|
// typedef T value_type;
|
||||||
|
|
|
@ -540,17 +540,33 @@ public class DOMCompletionProposalComputer extends ParsingBasedProposalComputer
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String getFunctionNameForReplacement(IFunction function, IASTCompletionContext astContext) {
|
||||||
|
// If we are completiong a destructor name ...
|
||||||
|
if (function instanceof ICPPMethod && ((ICPPMethod) function).isDestructor()) {
|
||||||
|
if (astContext instanceof IASTName) {
|
||||||
|
char[] simpleId = ((IASTName) astContext).getLastName().getSimpleID();
|
||||||
|
// .. and the invocation site already contains the '~' ...
|
||||||
|
if (simpleId.length > 0 && simpleId[0] == '~') {
|
||||||
|
// ... then do not include the '~' in the replacement string.
|
||||||
|
// As far as the completion proposal computer is concerned, the '~' is not part
|
||||||
|
// of the prefix, so including it in the replacement would mean getting a second
|
||||||
|
// '~' in the resulting code.
|
||||||
|
return function.getName().substring(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return function.getName();
|
||||||
|
}
|
||||||
|
|
||||||
private void handleFunction(IFunction function, IASTCompletionContext astContext,
|
private void handleFunction(IFunction function, IASTCompletionContext astContext,
|
||||||
CContentAssistInvocationContext cContext, int baseRelevance, List<ICompletionProposal> proposals) {
|
CContentAssistInvocationContext cContext, int baseRelevance, List<ICompletionProposal> proposals) {
|
||||||
Image image = getImage(function);
|
Image image = getImage(function);
|
||||||
|
|
||||||
StringBuilder repStringBuff = new StringBuilder();
|
StringBuilder repStringBuff = new StringBuilder();
|
||||||
repStringBuff.append(function.getName());
|
repStringBuff.append(getFunctionNameForReplacement(function, astContext));
|
||||||
|
|
||||||
boolean canBeCall = canBeCall(function, astContext, cContext);
|
boolean canBeCall = canBeCall(function, astContext, cContext);
|
||||||
|
|
||||||
repStringBuff.append('(');
|
|
||||||
|
|
||||||
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
|
||||||
boolean hasArgs = true;
|
boolean hasArgs = true;
|
||||||
|
@ -610,7 +626,8 @@ public class DOMCompletionProposalComputer extends ParsingBasedProposalComputer
|
||||||
String dispArgString = dispArgs.toString();
|
String dispArgString = dispArgs.toString();
|
||||||
String idArgString = idArgs.toString();
|
String idArgString = idArgs.toString();
|
||||||
String contextDispargString = hasArgs ? dispArgString : null;
|
String contextDispargString = hasArgs ? dispArgString : null;
|
||||||
StringBuilder dispStringBuff = new StringBuilder(repStringBuff);
|
StringBuilder dispStringBuff = new StringBuilder(function.getName());
|
||||||
|
dispStringBuff.append('(');
|
||||||
dispStringBuff.append(dispArgString);
|
dispStringBuff.append(dispArgString);
|
||||||
dispStringBuff.append(')');
|
dispStringBuff.append(')');
|
||||||
if (returnTypeStr != null && !returnTypeStr.isEmpty()) {
|
if (returnTypeStr != null && !returnTypeStr.isEmpty()) {
|
||||||
|
@ -619,25 +636,23 @@ public class DOMCompletionProposalComputer extends ParsingBasedProposalComputer
|
||||||
}
|
}
|
||||||
String dispString = dispStringBuff.toString();
|
String dispString = dispStringBuff.toString();
|
||||||
|
|
||||||
StringBuilder idStringBuff = new StringBuilder(repStringBuff);
|
StringBuilder idStringBuff = new StringBuilder(function.getName());
|
||||||
|
idStringBuff.append('(');
|
||||||
idStringBuff.append(idArgString);
|
idStringBuff.append(idArgString);
|
||||||
idStringBuff.append(')');
|
idStringBuff.append(')');
|
||||||
String idString = idStringBuff.toString();
|
String idString = idStringBuff.toString();
|
||||||
|
|
||||||
boolean inUsingDeclaration = cContext.isInUsingDirective();
|
boolean inUsingDeclaration = cContext.isInUsingDirective();
|
||||||
|
|
||||||
// If we can't be calling the function in this context, do not
|
if (canBeCall) {
|
||||||
// emit parentheses, since the user will just have to delete them.
|
// If we might be calling the function in this context, assume we are
|
||||||
if (!canBeCall) {
|
// (since that's the most common case) and emit parentheses.
|
||||||
repStringBuff.setLength(repStringBuff.length() - 1); // Remove opening parenthesis
|
repStringBuff.append('(');
|
||||||
|
|
||||||
// In a using declaration, emitting a semicolon instead is useful.
|
|
||||||
if (inUsingDeclaration && !cContext.isFollowedBySemicolon()) {
|
|
||||||
repStringBuff.append(';');
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
repStringBuff.append(')');
|
repStringBuff.append(')');
|
||||||
}
|
} else if (inUsingDeclaration && !cContext.isFollowedBySemicolon()) {
|
||||||
|
// In a using declaration, emitting a semicolon instead is useful.
|
||||||
|
repStringBuff.append(';');
|
||||||
|
}
|
||||||
|
|
||||||
String repString = repStringBuff.toString();
|
String repString = repStringBuff.toString();
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue