mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-06 17:26:01 +02:00
Bug 466861 - Do not lose template parameters of derived class when doing
access checking for content assist Change-Id: I850bc2c1f7f49682fc51ad5be621a7125936dd08 Signed-off-by: Nathan Ridge <zeratul976@hotmail.com>
This commit is contained in:
parent
165175210d
commit
c75374a1ef
2 changed files with 31 additions and 10 deletions
|
@ -173,22 +173,27 @@ public class AccessContext {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Return true if 'c' is the same type as 'target', or a specialization of 'target'.
|
||||||
|
private static boolean isSameTypeOrSpecialization(ICPPClassType c, ICPPClassType target) {
|
||||||
|
if (!(c instanceof ICPPSpecialization)) {
|
||||||
|
while (target instanceof ICPPSpecialization) {
|
||||||
|
IBinding specialized = ((ICPPSpecialization) target).getSpecializedBinding();
|
||||||
|
if (specialized instanceof ICPPClassType) {
|
||||||
|
target = (ICPPClassType) specialized;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return c.isSameType(target);
|
||||||
|
}
|
||||||
|
|
||||||
private boolean isAccessible(IBinding binding, int bindingVisibility, ICPPClassType owner,
|
private boolean isAccessible(IBinding binding, int bindingVisibility, ICPPClassType owner,
|
||||||
ICPPClassType derivedClass, int accessLevel, int depth) {
|
ICPPClassType derivedClass, int accessLevel, int depth) {
|
||||||
if (depth > CPPSemantics.MAX_INHERITANCE_DEPTH)
|
if (depth > CPPSemantics.MAX_INHERITANCE_DEPTH)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
accessLevel = getMemberAccessLevel(derivedClass, accessLevel);
|
accessLevel = getMemberAccessLevel(derivedClass, accessLevel);
|
||||||
|
|
||||||
if (!(owner instanceof ICPPSpecialization)) {
|
if (isSameTypeOrSpecialization(owner, derivedClass)) {
|
||||||
while (derivedClass instanceof ICPPSpecialization) {
|
|
||||||
IBinding specialized = ((ICPPSpecialization) derivedClass).getSpecializedBinding();
|
|
||||||
if (specialized instanceof ICPPClassType) {
|
|
||||||
derivedClass = (ICPPClassType) specialized;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (owner.isSameType(derivedClass)) {
|
|
||||||
return isAccessible(bindingVisibility, accessLevel);
|
return isAccessible(bindingVisibility, accessLevel);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1706,4 +1706,20 @@ public class CompletionTests extends AbstractContentAssistTest {
|
||||||
assertCompletionResults(fCursorOffset, expected, DISPLAY);
|
assertCompletionResults(fCursorOffset, expected, DISPLAY);
|
||||||
assertDotReplacedWithArrow();
|
assertDotReplacedWithArrow();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// struct A {
|
||||||
|
// void foo();
|
||||||
|
// };
|
||||||
|
//
|
||||||
|
// template <class T>
|
||||||
|
// class C : public T {};
|
||||||
|
//
|
||||||
|
// int main() {
|
||||||
|
// C<A> c;
|
||||||
|
// c./*cursor*/
|
||||||
|
// }
|
||||||
|
public void testInheritanceFromTemplateParameter_bug466861() throws Exception {
|
||||||
|
final String[] expected = { "A", "C", "foo(void)" };
|
||||||
|
assertCompletionResults(fCursorOffset, expected, ID);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue