Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix handling deeply nested java classes. #423

Merged
merged 1 commit into from
Oct 11, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,16 @@ private[sbt] object Analyze {
binaryClassName = classFile.className;
loadedClass <- load(binaryClassName, Some("Error reading API from class file"))) {
binaryClassNameToLoadedClass.update(binaryClassName, loadedClass)
val srcClassName = binaryToSourceName(loadedClass)
.orElse(Option(loadedClass.getEnclosingClass).flatMap(binaryToSourceName))

def loadEnclosingClass(clazz: Class[_]): Option[String] = {
binaryToSourceName(clazz) match {
case None if clazz.getEnclosingClass != null =>
loadEnclosingClass(clazz.getEnclosingClass)
case other => other
}
}

val srcClassName = loadEnclosingClass(loadedClass)

srcClassName match {
case Some(className) =>
Expand Down
15 changes: 15 additions & 0 deletions zinc/src/test/resources/sources/NestedJavaClasses.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
class NestedJavaClasses {
public NestedJavaClasses nest() {
return new NestedJavaClasses() {
@Override
public NestedJavaClasses nest() {
return new NestedJavaClasses() {
@Override
public NestedJavaClasses nest() {
throw new RuntimeException("Way too deep!");
}
};
}
};
}
}
20 changes: 20 additions & 0 deletions zinc/src/test/scala/sbt/inc/NestedJavaClassSpec.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package sbt.inc

import sbt.internal.inc.Analysis
import sbt.io.IO

class NestedJavaClassSpec extends BaseCompilerSpec {
it should "handle nested Java classes" in {
IO.withTemporaryDirectory { tempDir =>
val projectSetup =
ProjectSetup.simple(tempDir.toPath, Seq("NestedJavaClasses.java"))

val result = projectSetup.createCompiler().doCompile()
result.analysis() match {
case analysis: Analysis =>
analysis.relations.libraryDep._2s
.filter(_.toPath.startsWith(tempDir.toPath)) shouldBe 'empty
}
}
}
}