1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-23 14:42:11 +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 "VariableType.h"
using ns1::A;
namespace ns2 {
void VT::method() {

View file

@ -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();
}

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.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<String, IncludeCandidate> candidatesMap= new HashMap<String, IncludeCandidate>();
IIndex index = ast.getIndex();
final IndexFilter filter = IndexFilter.getDeclaredBindingFilter(ast.getLinkage().getLinkageID(), false);
IIndexBinding[] bindings= index.findBindings(nameChars, false, filter, new NullProgressMonitor());
final Map<String, IncludeCandidate> candidatesMap= new HashMap<String, IncludeCandidate>();
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);
}