mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-04 06:45:43 +02:00
Bug 331056: Content assist for involving using declarations.
This commit is contained in:
parent
b30316c094
commit
f8f2a9c9a3
3 changed files with 152 additions and 138 deletions
|
@ -191,7 +191,7 @@ abstract public class CPPScope implements ICPPASTInternalScope {
|
||||||
}
|
}
|
||||||
|
|
||||||
public IBinding getBindingInAST(IASTName name, boolean forceResolve) {
|
public IBinding getBindingInAST(IASTName name, boolean forceResolve) {
|
||||||
IBinding[] bs= getBindingsInAST(name, forceResolve, false, false, false);
|
IBinding[] bs= getBindingsInAST(name, forceResolve, false, false);
|
||||||
return CPPSemantics.resolveAmbiguities(name, bs);
|
return CPPSemantics.resolveAmbiguities(name, bs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -201,7 +201,7 @@ abstract public class CPPScope implements ICPPASTInternalScope {
|
||||||
|
|
||||||
public IBinding[] getBindings(IASTName name, boolean resolve, boolean prefixLookup, IIndexFileSet fileSet,
|
public IBinding[] getBindings(IASTName name, boolean resolve, boolean prefixLookup, IIndexFileSet fileSet,
|
||||||
boolean checkPointOfDecl) {
|
boolean checkPointOfDecl) {
|
||||||
IBinding[] result = getBindingsInAST(name, resolve, prefixLookup, checkPointOfDecl, true);
|
IBinding[] result = getBindingsInAST(name, resolve, prefixLookup, checkPointOfDecl);
|
||||||
final IASTTranslationUnit tu = name.getTranslationUnit();
|
final IASTTranslationUnit tu = name.getTranslationUnit();
|
||||||
if (tu != null) {
|
if (tu != null) {
|
||||||
IIndex index = tu.getIndex();
|
IIndex index = tu.getIndex();
|
||||||
|
@ -242,8 +242,9 @@ abstract public class CPPScope implements ICPPASTInternalScope {
|
||||||
return (IBinding[]) ArrayUtil.trim(IBinding.class, result);
|
return (IBinding[]) ArrayUtil.trim(IBinding.class, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public IBinding[] getBindingsInAST(IASTName name, boolean forceResolve, boolean prefixLookup,
|
public IBinding[] getBindingsInAST(IASTName name, boolean forceResolve, boolean prefixLookup,
|
||||||
boolean checkPointOfDecl, boolean expandUsingDirectives) {
|
boolean checkPointOfDecl) {
|
||||||
populateCache();
|
populateCache();
|
||||||
final char[] c = name.getLookupKey();
|
final char[] c = name.getLookupKey();
|
||||||
IBinding[] result = null;
|
IBinding[] result = null;
|
||||||
|
@ -272,17 +273,17 @@ abstract public class CPPScope implements ICPPASTInternalScope {
|
||||||
if (obj instanceof ObjectSet<?>) {
|
if (obj instanceof ObjectSet<?>) {
|
||||||
ObjectSet<?> os= (ObjectSet<?>) obj;
|
ObjectSet<?> os= (ObjectSet<?>) obj;
|
||||||
for (int j = 0; j < os.size(); j++) {
|
for (int j = 0; j < os.size(); j++) {
|
||||||
result= addCandidate(os.keyAt(j), name, forceResolve, checkPointOfDecl, expandUsingDirectives, result);
|
result= addCandidate(os.keyAt(j), name, forceResolve, checkPointOfDecl, result);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
result = addCandidate(obj, name, forceResolve, checkPointOfDecl, expandUsingDirectives, result);
|
result = addCandidate(obj, name, forceResolve, checkPointOfDecl, result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return (IBinding[]) ArrayUtil.trim(IBinding.class, result);
|
return (IBinding[]) ArrayUtil.trim(IBinding.class, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
private IBinding[] addCandidate(Object candidate, IASTName name, boolean forceResolve,
|
private IBinding[] addCandidate(Object candidate, IASTName name, boolean forceResolve,
|
||||||
boolean checkPointOfDecl, boolean expandUsingDirectives, IBinding[] result) {
|
boolean checkPointOfDecl, IBinding[] result) {
|
||||||
if (checkPointOfDecl) {
|
if (checkPointOfDecl) {
|
||||||
IASTTranslationUnit tu= name.getTranslationUnit();
|
IASTTranslationUnit tu= name.getTranslationUnit();
|
||||||
if (!CPPSemantics.declaredBefore(candidate, name, tu != null && tu.getIndex() != null)) {
|
if (!CPPSemantics.declaredBefore(candidate, name, tu != null && tu.getIndex() != null)) {
|
||||||
|
@ -308,13 +309,7 @@ abstract public class CPPScope implements ICPPASTInternalScope {
|
||||||
binding= (IBinding) candidate;
|
binding= (IBinding) candidate;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (expandUsingDirectives && binding instanceof ICPPUsingDeclaration) {
|
return (IBinding[]) ArrayUtil.append(IBinding.class, result, binding);
|
||||||
IBinding[] delegates = ((ICPPUsingDeclaration) binding).getDelegates();
|
|
||||||
result= (IBinding[]) ArrayUtil.addAll(IBinding.class, result, delegates);
|
|
||||||
} else {
|
|
||||||
result = (IBinding[]) ArrayUtil.append(IBinding.class, result, binding);
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public final void populateCache() {
|
public final void populateCache() {
|
||||||
|
|
|
@ -1195,41 +1195,46 @@ public class CPPSemantics {
|
||||||
// For index scopes the point of declaration is ignored.
|
// For index scopes the point of declaration is ignored.
|
||||||
bindings= scope.getBindings(data.astName, true, data.prefixLookup, fileSet);
|
bindings= scope.getBindings(data.astName, true, data.prefixLookup, fileSet);
|
||||||
}
|
}
|
||||||
|
return expandUsingDeclarationsAndRemoveObjects(bindings, data.typesOnly);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static IBinding[] expandUsingDeclarationsAndRemoveObjects(final IBinding[] bindings, boolean removeObjects) {
|
||||||
|
if (bindings == null || bindings.length == 0)
|
||||||
|
return IBinding.EMPTY_BINDING_ARRAY;
|
||||||
|
|
||||||
if (data.typesOnly) {
|
for (IBinding b : bindings) {
|
||||||
return removeObjects(bindings);
|
if (b == null)
|
||||||
|
break;
|
||||||
|
|
||||||
|
if (b instanceof ICPPUsingDeclaration || (removeObjects && isObject(b))) {
|
||||||
|
List<IBinding> result= new ArrayList<IBinding>(bindings.length);
|
||||||
|
expandUsingDeclarations(bindings, removeObjects, result);
|
||||||
|
return result.toArray(new IBinding[result.size()]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return bindings;
|
return bindings;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static IBinding[] removeObjects(final IBinding[] bindings) {
|
private static boolean isObject(IBinding b) {
|
||||||
final int length = bindings.length;
|
return !(b instanceof IType || b instanceof ICPPNamespace);
|
||||||
IBinding[] copy= null;
|
}
|
||||||
int pos= 0;
|
|
||||||
for (int i = 0; i < length; i++) {
|
private static void expandUsingDeclarations(IBinding[] bindings, boolean removeObjects, List<IBinding> result) {
|
||||||
final IBinding binding= bindings[i];
|
if (bindings != null) {
|
||||||
IBinding check= binding;
|
for (IBinding b : bindings) {
|
||||||
if (binding instanceof ICPPUsingDeclaration) {
|
if (b == null)
|
||||||
IBinding[] delegates= ((ICPPUsingDeclaration) binding).getDelegates();
|
return;
|
||||||
if (delegates.length > 0)
|
if (b instanceof ICPPUsingDeclaration) {
|
||||||
check= delegates[0];
|
for (IBinding d : ((ICPPUsingDeclaration) b).getDelegates()) {
|
||||||
}
|
if (d != null && !(removeObjects && isObject(d))) {
|
||||||
if (check instanceof IType || check instanceof ICPPNamespace) {
|
result.add(d);
|
||||||
if (copy != null) {
|
}
|
||||||
copy[pos]= binding;
|
}
|
||||||
}
|
} else if (!(removeObjects && isObject(b))) {
|
||||||
pos++;
|
result.add(b);
|
||||||
} else {
|
|
||||||
if (copy == null) {
|
|
||||||
copy= new IBinding[length-1];
|
|
||||||
System.arraycopy(bindings, 0, copy, 0, pos);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (pos == 0)
|
|
||||||
return IBinding.EMPTY_BINDING_ARRAY;
|
|
||||||
|
|
||||||
return copy == null ? bindings : copy;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static ICPPTemplateScope enclosingTemplateScope(IASTNode node) {
|
private static ICPPTemplateScope enclosingTemplateScope(IASTNode node) {
|
||||||
|
|
|
@ -46,128 +46,135 @@ public class CompletionTests extends AbstractContentAssistTest {
|
||||||
private IProject fProject;
|
private IProject fProject;
|
||||||
|
|
||||||
|
|
||||||
//{DisturbWith.cpp}
|
// {DisturbWith.cpp}
|
||||||
// int gTemp;
|
// int gTemp;
|
||||||
// void gFunc();
|
// void gFunc();
|
||||||
// typedef struct {
|
// typedef struct {
|
||||||
// int mem;
|
// int mem;
|
||||||
// } gStruct;
|
// } gStruct;
|
||||||
// class gClass {};
|
// class gClass {};
|
||||||
// namespace gns {
|
// namespace gns {
|
||||||
// int gnsTemp;
|
// int gnsTemp;
|
||||||
// void gnsFunc();
|
// void gnsFunc();
|
||||||
// typedef struct {
|
// typedef struct {
|
||||||
// int mem;
|
// int mem;
|
||||||
// } gnsStruct;
|
// } gnsStruct;
|
||||||
// class gnsClass {};
|
// class gnsClass {};
|
||||||
// };
|
// };
|
||||||
|
|
||||||
//{CompletionTest.h}
|
// {CompletionTest.h}
|
||||||
//class C1;
|
// class C1;
|
||||||
//class C2;
|
// class C2;
|
||||||
//class C3;
|
// class C3;
|
||||||
//
|
//
|
||||||
//extern C1* gC1;
|
// extern C1* gC1;
|
||||||
//C2* gC2 = 0;
|
// C2* gC2 = 0;
|
||||||
//
|
//
|
||||||
//extern C1* gfC1();
|
// extern C1* gfC1();
|
||||||
//C2* gfC2();
|
// C2* gfC2();
|
||||||
//
|
//
|
||||||
//enum E1 {e11, e12};
|
// enum E1 {e11, e12};
|
||||||
//
|
//
|
||||||
//class C1 {
|
// class C1 {
|
||||||
//public:
|
// public:
|
||||||
// enum E2 {e21, e22};
|
// enum E2 {e21, e22};
|
||||||
//
|
//
|
||||||
// C1* fMySelf;
|
// C1* fMySelf;
|
||||||
// void iam1();
|
// void iam1();
|
||||||
//
|
//
|
||||||
// C1* m123();
|
// C1* m123();
|
||||||
// C1* m12();
|
// C1* m12();
|
||||||
// C1* m13();
|
// C1* m13();
|
||||||
//
|
//
|
||||||
//protected:
|
// protected:
|
||||||
// void m1protected();
|
// void m1protected();
|
||||||
//private:
|
// private:
|
||||||
// void m1private();
|
// void m1private();
|
||||||
//};
|
// };
|
||||||
//typedef C1 T1;
|
// typedef C1 T1;
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
//class C2 : public T1 {
|
// class C2 : public T1 {
|
||||||
//public:
|
// public:
|
||||||
// C2* fMySelf;
|
// C2* fMySelf;
|
||||||
// void iam2();
|
// void iam2();
|
||||||
//
|
//
|
||||||
// C2* m123();
|
// C2* m123();
|
||||||
// C2* m12();
|
// C2* m12();
|
||||||
// C2* m23();
|
// C2* m23();
|
||||||
// C1* operator()(int x);
|
// C1* operator()(int x);
|
||||||
//
|
//
|
||||||
//protected:
|
// protected:
|
||||||
// void m2protected();
|
// void m2protected();
|
||||||
//private:
|
// private:
|
||||||
// void m2private();
|
// void m2private();
|
||||||
// friend void _friend_function(C3* x);
|
// friend void _friend_function(C3* x);
|
||||||
// friend class _friend_class;
|
// friend class _friend_class;
|
||||||
//};
|
// };
|
||||||
//typedef C2 T2;
|
// typedef C2 T2;
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
//class C3 : public C2 {
|
// class C3 : public C2 {
|
||||||
//public:
|
// public:
|
||||||
// C3* fMySelf;
|
// C3* fMySelf;
|
||||||
// void iam3();
|
// void iam3();
|
||||||
//
|
//
|
||||||
// C3* m123();
|
// C3* m123();
|
||||||
// C3* m13();
|
// C3* m13();
|
||||||
//
|
//
|
||||||
// template<typename T> T tConvert();
|
// template<typename T> T tConvert();
|
||||||
//protected:
|
// protected:
|
||||||
// void m3protected();
|
// void m3protected();
|
||||||
//private:
|
// private:
|
||||||
// void m3private();
|
// void m3private();
|
||||||
//};
|
// };
|
||||||
//typedef C3 T3;
|
// typedef C3 T3;
|
||||||
//
|
//
|
||||||
//namespace ns {
|
// namespace ns {
|
||||||
// const int NSCONST= 1;
|
// const int NSCONST= 1;
|
||||||
// class CNS {
|
// class CNS {
|
||||||
// void mcns();
|
// void mcns();
|
||||||
// };
|
// };
|
||||||
//};
|
// };
|
||||||
//template <class T> class TClass {
|
// template <class T> class TClass {
|
||||||
// T fTField;
|
// T fTField;
|
||||||
//public:
|
// public:
|
||||||
// TClass(T tArg) : fTField(tArg) {
|
// TClass(T tArg) : fTField(tArg) {
|
||||||
// }
|
// }
|
||||||
// T add(T tOther) {
|
// T add(T tOther) {
|
||||||
// return fTField + tOther;
|
// return fTField + tOther;
|
||||||
// }
|
// }
|
||||||
//};
|
// };
|
||||||
//// bug 109480
|
// // bug 109480
|
||||||
//class Printer
|
// class Printer
|
||||||
//{
|
// {
|
||||||
//public:
|
// public:
|
||||||
// static void InitPrinter(unsigned char port);
|
// static void InitPrinter(unsigned char port);
|
||||||
//private:
|
// private:
|
||||||
// //Storage for port printer is on
|
// //Storage for port printer is on
|
||||||
// static unsigned char port;
|
// static unsigned char port;
|
||||||
//protected:
|
// protected:
|
||||||
//};
|
// };
|
||||||
//struct Struct1;
|
// struct Struct1;
|
||||||
//struct Struct2;
|
// struct Struct2;
|
||||||
//union Union1;
|
// union Union1;
|
||||||
//union Union2;
|
// union Union2;
|
||||||
// struct s206450 {
|
// struct s206450 {
|
||||||
// struct {int a1; int a2;};
|
// struct {int a1; int a2;};
|
||||||
// union {int u1; char u2;};
|
// union {int u1; char u2;};
|
||||||
// struct {int a3;} a4;
|
// struct {int a3;} a4;
|
||||||
// int b;
|
// int b;
|
||||||
// };
|
// };
|
||||||
// typedef enum {__nix} _e204758;
|
// typedef enum {__nix} _e204758;
|
||||||
// void _f204758(_e204758 x);
|
// void _f204758(_e204758 x);
|
||||||
|
//
|
||||||
|
// // Bug 331056
|
||||||
|
// namespace _A_331056 {
|
||||||
|
// class Reference {};
|
||||||
|
// }
|
||||||
|
// namespace _B_331056 {
|
||||||
|
// using ::_A_331056::Reference;
|
||||||
|
// }
|
||||||
|
|
||||||
public CompletionTests(String name) {
|
public CompletionTests(String name) {
|
||||||
super(name, true);
|
super(name, true);
|
||||||
|
@ -747,7 +754,7 @@ public class CompletionTests extends AbstractContentAssistTest {
|
||||||
assertCompletionResults(fCursorOffset, expected, AbstractContentAssistTest.COMPARE_REP_STRINGS);
|
assertCompletionResults(fCursorOffset, expected, AbstractContentAssistTest.COMPARE_REP_STRINGS);
|
||||||
}
|
}
|
||||||
|
|
||||||
//using namespace /*cursor*/
|
//using namespace n/*cursor*/
|
||||||
public void testAutoColons2() throws Exception {
|
public void testAutoColons2() throws Exception {
|
||||||
final String[] expected= {
|
final String[] expected= {
|
||||||
"ns"
|
"ns"
|
||||||
|
@ -1233,7 +1240,7 @@ public class CompletionTests extends AbstractContentAssistTest {
|
||||||
public void testConstructorInitializerList_EmptyInput_Bug266586() throws Exception {
|
public void testConstructorInitializerList_EmptyInput_Bug266586() throws Exception {
|
||||||
final String[] expected= {"mOne", "Base",
|
final String[] expected= {"mOne", "Base",
|
||||||
"Base(int)", "Base(const Base<Helper> &)", "Helper",
|
"Base(int)", "Base(const Base<Helper> &)", "Helper",
|
||||||
"Helper(void)", "Helper(const Helper &)",
|
"Helper(void)", "Helper(const Helper &)", "_A_331056", "_B_331056",
|
||||||
// Namespaces must be offered as well. In order for this code
|
// Namespaces must be offered as well. In order for this code
|
||||||
// to compile with gcc (e.g. 4.1.2), you need to write
|
// to compile with gcc (e.g. 4.1.2), you need to write
|
||||||
// ::ns::Base<Helper>() instead of just Base<Helper>().
|
// ::ns::Base<Helper>() instead of just Base<Helper>().
|
||||||
|
@ -1326,4 +1333,11 @@ public class CompletionTests extends AbstractContentAssistTest {
|
||||||
final String[] expected= { "push_back(const int & value) : void" };
|
final String[] expected= { "push_back(const int & value) : void" };
|
||||||
assertParameterHint(expected);
|
assertParameterHint(expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// using namespace ::_B_331056;
|
||||||
|
// Ref/*cursor*/
|
||||||
|
public void testUsingDeclaration_Bug331056() throws Exception {
|
||||||
|
final String[] expected= { "Reference" };
|
||||||
|
assertCompletionResults(fCursorOffset, expected, COMPARE_ID_STRINGS);
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Add table
Reference in a new issue