-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Fix #8215 Add ability to detect attempted Tasty inspection of a Java class #8220
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
95f38af
i8215 Add ability to detect attempted Tasty inspection of a Java class
gzoller e870c41
changed method name to be more descriptive
gzoller 22cff0d
Fixed flags bug in ReadTasty
gzoller 0afdbcd
wording fix in comment
gzoller 1e1a3a3
implemented requested changes
gzoller 5d7db95
Attempt to fix build bug
gzoller 22d56f3
second attempted fix
gzoller File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
12 changes: 12 additions & 0 deletions
12
compiler/src/dotty/tools/dotc/fromtasty/JavaCompilationUnit.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package dotty.tools.dotc.fromtasty | ||
|
||
import dotty.tools.dotc.CompilationUnit | ||
import dotty.tools.dotc.util.NoSource | ||
|
||
/** A marker CompilationUnit to return up the call stack from ReadTasty. This will tell us that we've | ||
* encountered, and attempted to inspect, a Java class file. We can't TASTy-inspect a Java class obviously, | ||
* but we want to return the fact we found it so that higher-up we can take appropriate action if desired. | ||
*/ | ||
class JavaCompilationUnit(val className: String) extends CompilationUnit(NoSource) { | ||
override def toString: String = s"Java class file $className" | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
compiler/src/dotty/tools/dotc/fromtasty/Scala2CompilationUnit.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package dotty.tools.dotc.fromtasty | ||
|
||
import dotty.tools.dotc.CompilationUnit | ||
import dotty.tools.dotc.util.NoSource | ||
|
||
/** A marker CompilationUnit to return up the call stack from ReadTasty. This will tell us that we've | ||
* encountered, and attempted to inspect, a Scala2 class file (which has no .tasty file). | ||
* In this case we still want to return the fact we found it so that higher-up we can take appropriate | ||
* action if desired. | ||
*/ | ||
class Scala2CompilationUnit(val className: String) extends CompilationUnit(NoSource) { | ||
override def toString: String = s"Scala2 class file $className" | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import scala.tasty.Reflection | ||
import scala.tasty.inspector._ | ||
|
||
case class I8215(id: String) | ||
|
||
object Test { | ||
def main(args: Array[String]): Unit = { | ||
|
||
// Tasty Scala Class | ||
val inspect1 = new TestInspector_NonTasty() | ||
inspect1.inspect("", List("I8215")) | ||
assert(inspect1.isJava == false) | ||
assert(inspect1.isScala2 == false) | ||
assert(inspect1.className == "") | ||
|
||
// Java Class | ||
val inspect2 = new TestInspector_NonTasty() | ||
inspect2.inspect("", List("java.util.UUID")) | ||
assert(inspect2.isJava == true) | ||
assert(inspect2.isScala2 == false) | ||
assert(inspect2.className == "java.util.UUID") | ||
|
||
// Legacy non-Tasty Scala class | ||
val inspect3 = new TestInspector_NonTasty() | ||
inspect3.inspect("", List("scala.collection.immutable.RedBlackTree")) | ||
assert(inspect3.isJava == false) | ||
assert(inspect3.isScala2 == true) | ||
assert(inspect3.className == "scala.collection.immutable.RedBlackTree") | ||
} | ||
} | ||
|
||
class TestInspector_NonTasty() extends TastyInspector: | ||
|
||
var isJava: Boolean = false | ||
var isScala2: Boolean = false | ||
var className: String = "" | ||
|
||
protected def processCompilationUnit(reflect: Reflection)(root: reflect.Tree): Unit = | ||
import reflect.{_, given _} | ||
isJava = reflect.rootContext.isJavaCompilationUnit() | ||
isScala2 = reflect.rootContext.isScala2CompilationUnit() | ||
className = reflect.rootContext.compilationUnitClassname() |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.