From 75a5e159acfb8a019d414e94f14b18f9f3ec7b31 Mon Sep 17 00:00:00 2001 From: Sergey Prigogin Date: Wed, 20 May 2009 07:09:54 +0000 Subject: [PATCH] Fine tuning of Add Include. See bug 255952. --- .../resources/addInclude/ResolvedName.cpp | 5 +++++ .../addInclude/ResolvedName.cpp.expected | 6 ++++++ .../resources/addInclude/ResolvedName.h | 5 +++++ .../addInclude/VariableType.cpp.expected | 2 -- .../cdt/ui/tests/text/AddIncludeTest.java | 13 +++++++++---- .../ui/editor/AddIncludeOnSelectionAction.java | 16 +++++++++++++--- 6 files changed, 38 insertions(+), 9 deletions(-) create mode 100644 core/org.eclipse.cdt.ui.tests/resources/addInclude/ResolvedName.cpp create mode 100644 core/org.eclipse.cdt.ui.tests/resources/addInclude/ResolvedName.cpp.expected create mode 100644 core/org.eclipse.cdt.ui.tests/resources/addInclude/ResolvedName.h diff --git a/core/org.eclipse.cdt.ui.tests/resources/addInclude/ResolvedName.cpp b/core/org.eclipse.cdt.ui.tests/resources/addInclude/ResolvedName.cpp new file mode 100644 index 00000000000..644fbfc4ecd --- /dev/null +++ b/core/org.eclipse.cdt.ui.tests/resources/addInclude/ResolvedName.cpp @@ -0,0 +1,5 @@ +namespace ns4 { + +A a; + +} diff --git a/core/org.eclipse.cdt.ui.tests/resources/addInclude/ResolvedName.cpp.expected b/core/org.eclipse.cdt.ui.tests/resources/addInclude/ResolvedName.cpp.expected new file mode 100644 index 00000000000..93773200182 --- /dev/null +++ b/core/org.eclipse.cdt.ui.tests/resources/addInclude/ResolvedName.cpp.expected @@ -0,0 +1,6 @@ +#include "ResolvedName.h" +namespace ns4 { + +A a; + +} diff --git a/core/org.eclipse.cdt.ui.tests/resources/addInclude/ResolvedName.h b/core/org.eclipse.cdt.ui.tests/resources/addInclude/ResolvedName.h new file mode 100644 index 00000000000..bf44b3749f9 --- /dev/null +++ b/core/org.eclipse.cdt.ui.tests/resources/addInclude/ResolvedName.h @@ -0,0 +1,5 @@ +namespace ns4 { + +class A {}; + +} diff --git a/core/org.eclipse.cdt.ui.tests/resources/addInclude/VariableType.cpp.expected b/core/org.eclipse.cdt.ui.tests/resources/addInclude/VariableType.cpp.expected index d5dfa667cc5..d991b1486b7 100644 --- a/core/org.eclipse.cdt.ui.tests/resources/addInclude/VariableType.cpp.expected +++ b/core/org.eclipse.cdt.ui.tests/resources/addInclude/VariableType.cpp.expected @@ -1,8 +1,6 @@ #include "VariableTypeHelper.h" #include "VariableType.h" -using ns1::A; - namespace ns2 { void VT::method() { diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/AddIncludeTest.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/AddIncludeTest.java index 1f939da068e..f0db809cf7b 100644 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/AddIncludeTest.java +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/AddIncludeTest.java @@ -111,13 +111,18 @@ public class AddIncludeTest extends TestCase { fSourceViewer.setSelectedRange(offset, name.length()); } - public void testVariableType() throws Exception { - select("a_"); + public void testOverloadedFunction() throws Exception { + select("func"); assertAddIncludeResult(); } - public void testOverloadedFunction() throws Exception { - select("func"); + public void testResolvedName() throws Exception { + select("A"); + assertAddIncludeResult(); + } + + public void testVariableType() throws Exception { + select("a_"); assertAddIncludeResult(); } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/AddIncludeOnSelectionAction.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/AddIncludeOnSelectionAction.java index cc13a163233..40b5321286f 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/AddIncludeOnSelectionAction.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/AddIncludeOnSelectionAction.java @@ -54,6 +54,7 @@ import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.ICompositeType; import org.eclipse.cdt.core.dom.ast.IEnumeration; import org.eclipse.cdt.core.dom.ast.IFunction; +import org.eclipse.cdt.core.dom.ast.IProblemBinding; import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.ITypedef; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName; @@ -216,7 +217,8 @@ public class AddIncludeOnSelectionAction extends TextEditorAction { type = SemanticUtil.getNestedType(type, SemanticUtil.CVQ | SemanticUtil.PTR | SemanticUtil.ARRAY | SemanticUtil.REF); if (type instanceof IBinding) { - nameChars = ((IBinding) type).getNameCharArray(); + binding = (IBinding) type; + nameChars = binding.getNameCharArray(); } } } catch (DOMException e) { @@ -226,10 +228,14 @@ public class AddIncludeOnSelectionAction extends TextEditorAction { return; } + final Map candidatesMap= new HashMap(); IIndex index = ast.getIndex(); final IndexFilter filter = IndexFilter.getDeclaredBindingFilter(ast.getLinkage().getLinkageID(), false); - IIndexBinding[] bindings= index.findBindings(nameChars, false, filter, new NullProgressMonitor()); - final Map candidatesMap= new HashMap(); + IIndexBinding[] bindings = + binding instanceof IIndexBinding && !(binding instanceof IProblemBinding) ? + new IIndexBinding[] { (IIndexBinding) binding } : + index.findBindings(nameChars, false, filter, new NullProgressMonitor()); + for (IIndexBinding indexBinding : bindings) { IIndexName[] definitions= null; // class, struct, union, enum @@ -571,6 +577,10 @@ public class AddIncludeOnSelectionAction extends TextEditorAction { } else { path = targetLocation; } + if (targetLocation.getDevice() != null && + targetLocation.getDevice().equalsIgnoreCase(sourceDirectory.getDevice())) { + path = path.setDevice(null); + } } return new RequiredInclude(path.toString(), isSystemIncludePath); }