Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNathan Ridge2017-01-11 20:53:00 -0500
committerNathan Ridge2017-01-25 19:03:25 -0500
commit07ca5174d52599810a7d1b029749058b9dd1a5ba (patch)
tree6613ab2a07db498944a94c528282c443fbcf258f
parent81cbe876668119819deb101956e03f7490886be2 (diff)
downloadorg.eclipse.cdt-07ca5174d52599810a7d1b029749058b9dd1a5ba.tar.gz
org.eclipse.cdt-07ca5174d52599810a7d1b029749058b9dd1a5ba.tar.xz
org.eclipse.cdt-07ca5174d52599810a7d1b029749058b9dd1a5ba.zip
Bug 72391 - When completing a function, do not insert parentheses if they are already present
-rw-r--r--core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/contentassist2/CompletionTests.java8
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/contentassist/CContentAssistInvocationContext.java16
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/contentassist/DOMCompletionProposalComputer.java6
3 files changed, 28 insertions, 2 deletions
diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/contentassist2/CompletionTests.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/contentassist2/CompletionTests.java
index 04b8ee4b0f..cc64d398d4 100644
--- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/contentassist2/CompletionTests.java
+++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/contentassist2/CompletionTests.java
@@ -1676,4 +1676,12 @@ public class CompletionTests extends CompletionTestBase {
assertCompletionResults(fCursorOffset, expected, ID);
assertDotReplacedWithArrow();
}
+
+ // void waldo();
+ // int main() {
+ // wal/*cursor*/();
+ // }
+ public void testExistingParens_72391() throws Exception {
+ assertCompletionResults(new String[] { "waldo" }); // expect no parens in replacement
+ }
}
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/contentassist/CContentAssistInvocationContext.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/contentassist/CContentAssistInvocationContext.java
index 0ca11f5bb7..02590fa357 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/contentassist/CContentAssistInvocationContext.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/contentassist/CContentAssistInvocationContext.java
@@ -195,6 +195,17 @@ public class CContentAssistInvocationContext extends ContentAssistInvocationCont
return token == Symbols.TokenSEMICOLON;
}
};
+
+ private final Lazy<Boolean> followedByOpeningParen = new Lazy<Boolean>() {
+ @Override
+ protected Boolean calculateValue() {
+ final IDocument doc = getDocument();
+ final int offset = getInvocationOffset();
+ final CHeuristicScanner.TokenStream tokenStream = new CHeuristicScanner.TokenStream(doc, offset);
+ final int token = tokenStream.nextToken();
+ return token == Symbols.TokenLPAREN;
+ }
+ };
private final Lazy<String> functionParameterDelimiter = new Lazy<String>() {
@Override
@@ -452,6 +463,11 @@ public class CContentAssistInvocationContext extends ContentAssistInvocationCont
assertNotDisposed();
return followedBySemicolon.value();
}
+
+ public boolean isFollowedByOpeningParen() {
+ assertNotDisposed();
+ return followedByOpeningParen.value();
+ }
public String getFunctionParameterDelimiter() {
assertNotDisposed();
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/contentassist/DOMCompletionProposalComputer.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/contentassist/DOMCompletionProposalComputer.java
index 0e776ed617..cd0be417b6 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/contentassist/DOMCompletionProposalComputer.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/contentassist/DOMCompletionProposalComputer.java
@@ -614,8 +614,10 @@ public class DOMCompletionProposalComputer extends ParsingBasedProposalComputer
// Instead, emitting a semicolon is useful.
boolean inUsingDeclaration = context.isInUsingDirective();
if (!inUsingDeclaration) {
- repStringBuff.append('(');
- repStringBuff.append(')');
+ if (!context.isFollowedByOpeningParen()) {
+ repStringBuff.append('(');
+ repStringBuff.append(')');
+ }
} else if (!context.isFollowedBySemicolon()) {
repStringBuff.append(';');
}

Back to the top