1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-02 05:45:58 +02:00

Bug 400309 - Code completion exposes invisible nested classes

This commit is contained in:
Sergey Prigogin 2013-05-16 20:00:52 -07:00
parent f2a3ff9a9d
commit fb2f901ac1
2 changed files with 31 additions and 15 deletions

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2009 Google, Inc and others. * Copyright (c) 2009, 2013 Google, Inc and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -51,13 +51,21 @@ public class AccessControlTests extends AST2TestBase {
return suite(AccessControlTests.class); return suite(AccessControlTests.class);
} }
private AccessAssertionHelper getAssertionHelper() throws Exception {
final String code = getAboveComment();
parseAndCheckBindings(code, ParserLanguage.CPP);
return new AccessAssertionHelper(code);
}
// class A { // class A {
// public: // public:
// int a; // int a;
// typedef char E;
// }; // };
// class B : private A { // class B : private A {
// friend void test(); // friend void test();
// int b; // int b;
// typedef char* F;
// }; // };
// class C : protected B { // class C : protected B {
// }; // };
@ -66,25 +74,35 @@ public class AccessControlTests extends AST2TestBase {
// void m() { // void m() {
// a; //1 // a; //1
// b; //1 // b; //1
// E(); //1
// F(); //1
// } // }
// }; // };
// B b; // B b;
// b.a; //2 // b.a; //2
// b.b; //2 // b.b; //2
// B::E(); //2
// B::F(); //2
// C c; // C c;
// c.a; //3 // c.a; //3
// c.b; //3 // c.b; //3
// C::E(); //3
// C::F(); //3
// } // }
public void testFriends() throws Exception { public void testFriends() throws Exception {
final String code = getAboveComment(); AccessAssertionHelper ah = getAssertionHelper();
parseAndCheckBindings(code, ParserLanguage.CPP);
AccessAssertionHelper ah= new AccessAssertionHelper(code);
ah.assertAccessible("a; //1", 1); ah.assertAccessible("a; //1", 1);
ah.assertAccessible("b; //1", 1); ah.assertAccessible("b; //1", 1);
ah.assertAccessible("E(); //1", 1);
ah.assertAccessible("F(); //1", 1);
ah.assertAccessible("a; //2", 1); ah.assertAccessible("a; //2", 1);
ah.assertAccessible("b; //2", 1); ah.assertAccessible("b; //2", 1);
ah.assertAccessible("E(); //2", 1);
ah.assertAccessible("F(); //2", 1);
ah.assertNotAccessible("a; //3", 1); ah.assertNotAccessible("a; //3", 1);
ah.assertNotAccessible("b; //3", 1); ah.assertNotAccessible("b; //3", 1);
ah.assertNotAccessible("E(); //3", 1);
ah.assertNotAccessible("F(); //3", 1);
} }
// class A { // class A {
@ -101,9 +119,7 @@ public class AccessControlTests extends AST2TestBase {
// x.a = 0; // x.a = 0;
// } // }
public void testHiddenMember() throws Exception { public void testHiddenMember() throws Exception {
final String code = getAboveComment(); AccessAssertionHelper ah = getAssertionHelper();
parseAndCheckBindings(code, ParserLanguage.CPP);
AccessAssertionHelper ah= new AccessAssertionHelper(code);
ah.assertNotAccessible("a = 0", 1); ah.assertNotAccessible("a = 0", 1);
} }
@ -120,9 +136,7 @@ public class AccessControlTests extends AST2TestBase {
// }; // };
// }; // };
public void testEnclosingAsNamingClass_292232() throws Exception { public void testEnclosingAsNamingClass_292232() throws Exception {
final String code = getAboveComment(); AccessAssertionHelper ah = getAssertionHelper();
parseAndCheckBindings(code, ParserLanguage.CPP);
AccessAssertionHelper ah= new AccessAssertionHelper(code);
ah.assertAccessible("Ex a;", 2); ah.assertAccessible("Ex a;", 2);
} }
@ -147,9 +161,7 @@ public class AccessControlTests extends AST2TestBase {
// bp->mi=5; // bp->mi=5;
// } // }
public void testEnclosingAsNamingClass_292232a() throws Exception { public void testEnclosingAsNamingClass_292232a() throws Exception {
final String code = getAboveComment(); AccessAssertionHelper ah = getAssertionHelper();
parseAndCheckBindings(code, ParserLanguage.CPP);
AccessAssertionHelper ah= new AccessAssertionHelper(code);
ah.assertNotAccessible("mi=3;", 2); ah.assertNotAccessible("mi=3;", 2);
ah.assertNotAccessible("si=3;", 2); ah.assertNotAccessible("si=3;", 2);
ah.assertAccessible("mi=4;", 2); ah.assertAccessible("mi=4;", 2);

View file

@ -88,8 +88,12 @@ public class AccessContext {
if (binding instanceof ICPPMember) { if (binding instanceof ICPPMember) {
bindingVisibility = ((ICPPMember) binding).getVisibility(); bindingVisibility = ((ICPPMember) binding).getVisibility();
} else { } else {
// TODO(sprigogin): Handle visibility of nested types IBinding owner = binding.getOwner();
bindingVisibility = v_public; if (owner instanceof ICPPClassType) {
bindingVisibility = ((ICPPClassType) owner).getVisibility(binding);
} else {
bindingVisibility = v_public;
}
} }
return isAccessible(binding, bindingVisibility); return isAccessible(binding, bindingVisibility);
} }