Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNathan Ridge2017-06-08 02:57:45 -0400
committerNathan Ridge2017-06-08 02:57:45 -0400
commitc24e5d17b3863516ab776d2df6819804ffef0e52 (patch)
treeb2f925f197cbe774ac0222cb694052e6dd8aff0c
parent68a609fe4498d8237dd99bd884564f9cf6715137 (diff)
downloadorg.eclipse.cdt-c24e5d17b3863516ab776d2df6819804ffef0e52.tar.gz
org.eclipse.cdt-c24e5d17b3863516ab776d2df6819804ffef0e52.tar.xz
org.eclipse.cdt-c24e5d17b3863516ab776d2df6819804ffef0e52.zip
Bug 517954 - ClassCastException in CVisitor.findBindingsForContentAssist()
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CVisitor.java10
-rw-r--r--core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/contentassist2/AbstractContentAssistTest.java4
-rw-r--r--core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/contentassist2/CompletionTests_PlainC.java10
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/contentassist/ContentAssistMessages.java2
4 files changed, 24 insertions, 2 deletions
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CVisitor.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CVisitor.java
index 4320aae23d..b582c2e4bb 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CVisitor.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CVisitor.java
@@ -1529,7 +1529,15 @@ public class CVisitor extends ASTQueries {
IBinding[] result = null;
if (prop == IASTFieldReference.FIELD_NAME) {
- result = (IBinding[]) findBinding((IASTFieldReference) name.getParent(), isPrefix);
+ Object res = findBinding((IASTFieldReference) name.getParent(), isPrefix);
+ if (isPrefix) {
+ result = (IBinding[]) res;
+ } else {
+ IBinding binding = (IBinding) res;
+ if (binding != null) {
+ result = new IBinding[] { binding };
+ }
+ }
} else if (prop == ICASTFieldDesignator.FIELD_NAME) {
result = findBindingForContentAssist((ICASTFieldDesignator) name.getParent(), isPrefix);
} else {
diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/contentassist2/AbstractContentAssistTest.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/contentassist2/AbstractContentAssistTest.java
index 9a5a7aac63..f255fa9858 100644
--- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/contentassist2/AbstractContentAssistTest.java
+++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/contentassist2/AbstractContentAssistTest.java
@@ -54,6 +54,7 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTNameBase;
import org.eclipse.cdt.internal.ui.text.contentassist.CCompletionProposal;
import org.eclipse.cdt.internal.ui.text.contentassist.CContentAssistProcessor;
+import org.eclipse.cdt.internal.ui.text.contentassist.ContentAssistMessages;
import org.eclipse.cdt.internal.ui.text.contentassist.ContentAssistPreference;
import org.eclipse.cdt.internal.ui.text.contentassist.ParameterGuessingProposal;
import org.eclipse.cdt.internal.ui.text.contentassist.RelevanceConstants;
@@ -155,6 +156,9 @@ public abstract class AbstractContentAssistTest extends BaseUITestCase {
(Object[]) processor.computeContextInformation(sourceViewer, offset);
long endTime= System.currentTimeMillis();
assertTrue(results != null);
+ // Make sure no exception was thrown during content assist invocation.
+ assertTrue(processor.getErrorMessage() == null ||
+ processor.getErrorMessage().equals(ContentAssistMessages.ContentAssistProcessor_no_completions));
if (filterResults) {
if (isTemplate) {
diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/contentassist2/CompletionTests_PlainC.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/contentassist2/CompletionTests_PlainC.java
index a3bf908d3c..ba2995fbd0 100644
--- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/contentassist2/CompletionTests_PlainC.java
+++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/contentassist2/CompletionTests_PlainC.java
@@ -976,4 +976,14 @@ public class CompletionTests_PlainC extends AbstractContentAssistTest {
final String[] expected= {"_f204758(_e204758)"};
assertCompletionResults(expected);
}
+
+ // int main(void) {
+ // struct {
+ // void (*bar)(p1, p2, p3...);
+ // } foo;
+ // foo.bar(/*cursor*/
+ public void testClassCastException_Bug517954() throws Exception {
+ // Just check that no exception is thrown while invoking completion.
+ assertContentAssistResults(fCursorOffset, new String[]{}, DEFAULT_FLAGS | ALLOW_EXTRA_RESULTS, CompareType.ID);
+ }
}
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/contentassist/ContentAssistMessages.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/contentassist/ContentAssistMessages.java
index 06754c5e22..9951fd57c1 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/contentassist/ContentAssistMessages.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/contentassist/ContentAssistMessages.java
@@ -16,7 +16,7 @@ import org.eclipse.osgi.util.NLS;
/**
* Helper class to get NLSed messages.
*/
-final class ContentAssistMessages extends NLS {
+public final class ContentAssistMessages extends NLS {
private static final String BUNDLE_NAME= ContentAssistMessages.class.getName();

Back to the top