1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-07 17:56:01 +02:00

Fine tuning of Add Include. See bug 255952.

This commit is contained in:
Sergey Prigogin 2009-05-20 07:09:54 +00:00
parent e697d8277b
commit 75a5e159ac
6 changed files with 38 additions and 9 deletions

View file

@ -0,0 +1,5 @@
namespace ns4 {
A a;
}

View file

@ -0,0 +1,6 @@
#include "ResolvedName.h"
namespace ns4 {
A a;
}

View file

@ -0,0 +1,5 @@
namespace ns4 {
class A {};
}

View file

@ -1,8 +1,6 @@
#include "VariableTypeHelper.h" #include "VariableTypeHelper.h"
#include "VariableType.h" #include "VariableType.h"
using ns1::A;
namespace ns2 { namespace ns2 {
void VT::method() { void VT::method() {

View file

@ -111,13 +111,18 @@ public class AddIncludeTest extends TestCase {
fSourceViewer.setSelectedRange(offset, name.length()); fSourceViewer.setSelectedRange(offset, name.length());
} }
public void testVariableType() throws Exception { public void testOverloadedFunction() throws Exception {
select("a_"); select("func");
assertAddIncludeResult(); assertAddIncludeResult();
} }
public void testOverloadedFunction() throws Exception { public void testResolvedName() throws Exception {
select("func"); select("A");
assertAddIncludeResult();
}
public void testVariableType() throws Exception {
select("a_");
assertAddIncludeResult(); assertAddIncludeResult();
} }

View file

@ -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.ICompositeType;
import org.eclipse.cdt.core.dom.ast.IEnumeration; import org.eclipse.cdt.core.dom.ast.IEnumeration;
import org.eclipse.cdt.core.dom.ast.IFunction; 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.IType;
import org.eclipse.cdt.core.dom.ast.ITypedef; import org.eclipse.cdt.core.dom.ast.ITypedef;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName;
@ -216,7 +217,8 @@ public class AddIncludeOnSelectionAction extends TextEditorAction {
type = SemanticUtil.getNestedType(type, type = SemanticUtil.getNestedType(type,
SemanticUtil.CVQ | SemanticUtil.PTR | SemanticUtil.ARRAY | SemanticUtil.REF); SemanticUtil.CVQ | SemanticUtil.PTR | SemanticUtil.ARRAY | SemanticUtil.REF);
if (type instanceof IBinding) { if (type instanceof IBinding) {
nameChars = ((IBinding) type).getNameCharArray(); binding = (IBinding) type;
nameChars = binding.getNameCharArray();
} }
} }
} catch (DOMException e) { } catch (DOMException e) {
@ -226,10 +228,14 @@ public class AddIncludeOnSelectionAction extends TextEditorAction {
return; return;
} }
final Map<String, IncludeCandidate> candidatesMap= new HashMap<String, IncludeCandidate>();
IIndex index = ast.getIndex(); IIndex index = ast.getIndex();
final IndexFilter filter = IndexFilter.getDeclaredBindingFilter(ast.getLinkage().getLinkageID(), false); final IndexFilter filter = IndexFilter.getDeclaredBindingFilter(ast.getLinkage().getLinkageID(), false);
IIndexBinding[] bindings= index.findBindings(nameChars, false, filter, new NullProgressMonitor()); IIndexBinding[] bindings =
final Map<String, IncludeCandidate> candidatesMap= new HashMap<String, IncludeCandidate>(); binding instanceof IIndexBinding && !(binding instanceof IProblemBinding) ?
new IIndexBinding[] { (IIndexBinding) binding } :
index.findBindings(nameChars, false, filter, new NullProgressMonitor());
for (IIndexBinding indexBinding : bindings) { for (IIndexBinding indexBinding : bindings) {
IIndexName[] definitions= null; IIndexName[] definitions= null;
// class, struct, union, enum // class, struct, union, enum
@ -571,6 +577,10 @@ public class AddIncludeOnSelectionAction extends TextEditorAction {
} else { } else {
path = targetLocation; path = targetLocation;
} }
if (targetLocation.getDevice() != null &&
targetLocation.getDevice().equalsIgnoreCase(sourceDirectory.getDevice())) {
path = path.setDevice(null);
}
} }
return new RequiredInclude(path.toString(), isSystemIncludePath); return new RequiredInclude(path.toString(), isSystemIncludePath);
} }