Skip to content

Commit

Permalink
Merge pull request #93 from scala-ide/issue/show-only-accessible-memb…
Browse files Browse the repository at this point in the history
…ers-1000784

Only show accessible members in the completion lists.
  • Loading branch information
dragos committed Apr 23, 2012
2 parents 2d75b85 + 578c268 commit 88040b7
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,34 @@ class CompletionTests {
str.replace("(", "").replace(")", "").replace("java.lang.String", "String")
}

/**
* Test that completion shows only accessible members.
*/
@Test
def accessibilityTests() {
val oraclePos14 = List("secretPrivate: Unit",
"secretProtected: Unit",
"secretProtectedInPackage: Unit",
"secretPublic: Unit")

val oraclePos16 = List("secretPrivate: Unit",
"secretPrivateThis: Unit",
"secretProtected: Unit",
"secretProtectedInPackage: Unit",
"secretPublic: Unit")
val oraclePos22 = List(
"secretProtected: Unit",
"secretProtectedInPackage: Unit",
"secretPublic: Unit")
val oraclePos28 = List(
"secretProtectedInPackage: Unit",
"secretPublic: Unit")
val oraclePos37 = List(
"secretPublic: Unit")

runTest("accessibility/AccessibilityTest.scala", true)(oraclePos14, oraclePos16, oraclePos22, oraclePos28, oraclePos37)
}

@Test
def ticket1000475() {
val oraclePos73 = List("toString(): String")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package accessibility {

class Foo {
private def secretPrivate(): Unit
private[this] def secretPrivateThis(): Unit

protected def secretProtected(): Unit

protected[accessibility] def secretProtectedInPackage(): Unit

def secretPublic(): Unit

def someTests(other: Foo) {
other.secr /*!*/ // should be all but scretThis

this.secr /*!*/ // should hit five completions
}
}

class AccessibilityChecks extends Foo {
def someTests {
this.secr /*!*/ // should not list secretPrivate*
}
}

class UnrelatedClass {
def someTests(foo: Foo) {
foo.secr /*!*/ // should list public and protected[accessiblity]
}
}

}

package other {
class SomeChecsk {
def foo(o: accessibility.Foo) {
o.secr /*!*/ // should only match secretPublic
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,11 @@ class ScalaCompletions extends HasLogger {
compiler.askOption { () =>
for (completion <- completions) {
completion match {
case compiler.TypeMember(sym, tpe, accessible, inherited, viaView) if !sym.isConstructor && nameMatches(sym) =>
case compiler.TypeMember(sym, tpe, true, inherited, viaView) if !sym.isConstructor && nameMatches(sym) =>
val completionProposal= compiler.mkCompletionProposal(start, sym, tpe, inherited, viaView)
if (!isCompletionAlreadyListed(completionProposal))
buff += completionProposal
case compiler.ScopeMember(sym, tpe, accessible, _) if !sym.isConstructor && nameMatches(sym) =>
case compiler.ScopeMember(sym, tpe, true, _) if !sym.isConstructor && nameMatches(sym) =>
val completionProposal= compiler.mkCompletionProposal(start, sym, tpe, false, compiler.NoSymbol)
if (!isCompletionAlreadyListed(completionProposal))
buff += completionProposal
Expand Down

0 comments on commit 88040b7

Please sign in to comment.