From 50c5677fcfd26594c89550c72ccbf33e7534baab Mon Sep 17 00:00:00 2001 From: Sergey Prigogin Date: Mon, 26 Aug 2013 13:15:02 -0700 Subject: [PATCH] Bug 415914 - Organize Includes doesn't add include for a constructor call --- .../includes/BindingClassifierTest.java | 31 +++++++++++++++++++ .../includes/BindingClassifier.java | 19 +++++++----- 2 files changed, 42 insertions(+), 8 deletions(-) diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/includes/BindingClassifierTest.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/includes/BindingClassifierTest.java index 4442c29f66f..dad5e16e527 100644 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/includes/BindingClassifierTest.java +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/includes/BindingClassifierTest.java @@ -258,6 +258,37 @@ public class BindingClassifierTest extends OneSourceMultipleHeadersTestCase { assertDeclared("f"); } + // struct A { + // A(void* p); + // }; + + // void test() { + // A(nullptr); + // } + public void testConstructorCall() throws Exception { + getPreferenceStore().setValue(PreferenceConstants.FORWARD_DECLARE_FUNCTIONS, true); + // A header declaring the function is not responsible for defining the parameter type since + // the implicit conversion from B to A is provided externally to parameter type. + assertDefined("A"); + assertDeclared(); + } + + // struct A { + // A(void* p); + // }; + // typedef A B; + + // void test() { + // B(nullptr); + // } + public void testConstructorCallWithTypedef() throws Exception { + getPreferenceStore().setValue(PreferenceConstants.FORWARD_DECLARE_FUNCTIONS, true); + // A header declaring the function is not responsible for defining the parameter type since + // the implicit conversion from B to A is provided externally to parameter type. + assertDefined("B"); + assertDeclared(); + } + // struct A { // A(const B& b); // }; diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/includes/BindingClassifier.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/includes/BindingClassifier.java index 444fdfebcf5..ff14c6450d6 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/includes/BindingClassifier.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/includes/BindingClassifier.java @@ -1030,12 +1030,15 @@ public class BindingClassifier { IBinding binding = ((IASTIdExpression) functionNameExpression).getName().resolveBinding(); if (binding instanceof IFunction) { declareFunction((IFunction) binding, functionCallExpression); - } else if (functionCallExpression instanceof IASTImplicitNameOwner) { - IASTImplicitName[] implicitNames = ((IASTImplicitNameOwner) functionCallExpression).getImplicitNames(); - for (IASTName name : implicitNames) { - binding = name.resolveBinding(); - if (binding instanceof IFunction) { - declareFunction((IFunction) binding, functionCallExpression); + } else if (binding instanceof IType) { + defineBinding(binding); + if (functionCallExpression instanceof IASTImplicitNameOwner) { + IASTImplicitName[] implicitNames = ((IASTImplicitNameOwner) functionCallExpression).getImplicitNames(); + for (IASTName name : implicitNames) { + binding = name.resolveBinding(); + if (binding instanceof IFunction) { + declareFunction((IFunction) binding, functionCallExpression); + } } } } @@ -1123,11 +1126,11 @@ public class BindingClassifier { } else { IBinding owner = binding.getOwner(); if (owner instanceof IType) { - defineBinding(owner); // Member access requires definition of the containing type. + defineBinding(owner); // Member access requires definition of the containing type. if (binding instanceof IProblemBinding) declareBinding(binding); } else { - declareBinding(binding); // Declare the binding of this name. + declareBinding(binding); // Declare the binding of this name. } } }