Skip to content

Commit

Permalink
Avoid false positives for classes defined in methods
Browse files Browse the repository at this point in the history
If a class has the `EnclosingMethod` attribute, we know it was defined
in the body of a method (or a val/var initializer), and is not part of
the API of a class.

Fixes lightbend-labs#147
  • Loading branch information
retronym committed Nov 30, 2016
1 parent 32553b4 commit 85d6191
Show file tree
Hide file tree
Showing 12 changed files with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ abstract class ClassInfo(val owner: PackageInfo) extends HasDeclarationName with
var _innerClasses: Seq[String] = Seq.empty
def innerClasses = { ensureLoaded(); _innerClasses }

var _isLocalClass = false
def isLocalClass = { ensureLoaded(); _isLocalClass}

var _isTopLevel = true
def isTopLevel = { ensureLoaded(); _isTopLevel }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,8 @@ abstract class ClassfileParser(definitions: Definitions) {
if (pool.getClassName(outerIndex) == c.bytecodeName) n else ""
} else ""
}.filterNot(_.isEmpty)
} else if (attrName == "EnclosingMethod") {
c._isLocalClass = true
} else if (attrName == "Scala" || attrName == "ScalaSig") {
this.parsedClass.isScala = true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ abstract class PackageInfo(val owner: PackageInfo) {
else if (prefix.isEmpty) clazz.isTopLevel && !clazz.bytecodeName.contains("$$")
else prefix.exists(_.innerClasses contains clazz.bytecodeName)
}
clazz.isPublic && isReachable
clazz.isPublic && !clazz.isLocalClass && isReachable
}

accessibleClassesUnder(Set.empty, Set.empty)
Expand Down
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
class A { def f() = { class Local } }
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
class A { def f() = { } }
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
class A { def f() = { class Local { def v1 = "v1"} } }
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
class A { def f() = { class Local } }
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
class A { def f() = { } }
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
class A { def f() = { class Local } }

0 comments on commit 85d6191

Please sign in to comment.