Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSergey Prigogin2013-09-12 19:04:05 -0400
committerSergey Prigogin2013-09-12 19:13:43 -0400
commit4d282cfe2b31f40091286cb1dac9829f72b324de (patch)
tree5bccdb07be2e4887abcc1f0966f780c82e6fb485
parent78000addef3ad8dfad3a487c67219b888e4b5933 (diff)
downloadorg.eclipse.cdt-4d282cfe2b31f40091286cb1dac9829f72b324de.tar.gz
org.eclipse.cdt-4d282cfe2b31f40091286cb1dac9829f72b324de.tar.xz
org.eclipse.cdt-4d282cfe2b31f40091286cb1dac9829f72b324de.zip
Bug 417143 - Organize Includes removes include of the header declaring a
variable.
-rw-r--r--core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/includes/BindingClassifierTest.java5
-rw-r--r--core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/includes/IncludeOrganizerTest.java17
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/includes/BindingClassifier.java16
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/includes/IncludeOrganizer.java9
4 files changed, 36 insertions, 11 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 56ca50d774..b96ff39abd 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
@@ -349,7 +349,8 @@ public class BindingClassifierTest extends OneSourceMultipleHeadersTestCase {
assertDeclared("B");
}
- // int a;
+ // typedef unsigned int size_t;
+ // size_t a;
// void test() {
// void* x = &a;
@@ -362,7 +363,7 @@ public class BindingClassifierTest extends OneSourceMultipleHeadersTestCase {
// struct A {
// void operator()(int p);
// };
- // const A& a;
+ // A a;
// void test() {
// a(1);
diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/includes/IncludeOrganizerTest.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/includes/IncludeOrganizerTest.java
index b01bf4c530..141549b09e 100644
--- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/includes/IncludeOrganizerTest.java
+++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/includes/IncludeOrganizerTest.java
@@ -458,6 +458,23 @@ public class IncludeOrganizerTest extends IncludesTestBase {
}
//h1.h
+ //typedef int int32;
+
+ //h2.h
+ //#include "h1.h"
+ //extern int32 var;
+
+ //source.cpp
+ //int a = var;
+ //====================
+ //#include "h2.h"
+ //
+ //int a = var;
+ public void testVariableReference() throws Exception {
+ assertExpectedResults();
+ }
+
+ //h1.h
//namespace ns3 {
//class C {};
//namespace ns2 {
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 e07f016b1d..be289254a0 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
@@ -313,8 +313,6 @@ public class BindingClassifier {
} else {
bindings.add(binding);
}
- // Resolve the type of the variable.
- binding = getTypeBinding(((IVariable) binding).getType());
} else if (binding instanceof IType) {
// Resolve the type.
binding = getTypeBinding((IType) binding);
@@ -391,12 +389,14 @@ public class BindingClassifier {
if (fAst.getDeclarationsInAST(binding).length != 0)
return; // Declared locally.
- if (!canForwardDeclare(binding))
- defineBinding(binding);
-
if (!fProcessedDeclaredBindings.add(binding))
return;
+ if (!canForwardDeclare(binding)) {
+ defineBinding(binding);
+ return;
+ }
+
List<IBinding> requiredBindings = getRequiredBindings(binding);
for (IBinding requiredBinding : requiredBindings) {
@@ -1049,8 +1049,10 @@ public class BindingClassifier {
IBinding binding = ((IASTIdExpression) functionNameExpression).getName().resolveBinding();
if (binding instanceof IFunction) {
declareFunction((IFunction) binding, functionCallExpression);
- } else if (binding instanceof IType) {
- defineBinding(binding);
+ } else {
+ if (binding instanceof IType)
+ defineBinding(binding);
+
if (functionCallExpression instanceof IASTImplicitNameOwner) {
IASTImplicitName[] implicitNames = ((IASTImplicitNameOwner) functionCallExpression).getImplicitNames();
for (IASTName name : implicitNames) {
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/includes/IncludeOrganizer.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/includes/IncludeOrganizer.java
index b2dd84b589..ad3d44f23f 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/includes/IncludeOrganizer.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/includes/IncludeOrganizer.java
@@ -1008,12 +1008,17 @@ public class IncludeOrganizer {
indexNames[indexNames.length - 1] = indexName;
}
}
- } else if (allowDeclarations || binding instanceof IFunction) {
- // For functions we need to include the declaration.
+ } else if (allowDeclarations || binding instanceof IFunction || binding instanceof IVariable) {
+ // For functions and variables we need to include a declaration.
indexNames = index.findDeclarations(binding);
} else {
// For all other bindings we need to include the definition.
indexNames = index.findDefinitions(binding);
+ if (indexNames.length == 0) {
+ // If we could not find any definitions, there is still a chance that
+ // a declaration would be sufficient.
+ indexNames = index.findDeclarations(binding);
+ }
}
if (indexNames.length != 0) {

Back to the top