-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Do not return java outline dummy constructor in
primaryConstructor
Java outline parser phase for various reasons adds a dummy constructor to java classes compiling simultenously from scalac. Since they provide no information to the user and are overall misleading (with always having the same fake flags and parameters), we filter them out and return the first constructor that can be found in the source. This is also what happened up to this point when running the macro with a java classfile on the classpath instead, since those dummy constructors cannot be found there.
- Loading branch information
Showing
9 changed files
with
62 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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 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,5 @@ | ||
method <init> (Flags.JavaDefined | Flags.Method) List(List((x$0,scala.Int))) | ||
method <init> (Flags.JavaDefined | Flags.Method) List(List()) | ||
method <init> (Flags.JavaDefined | Flags.Method | Flags.Private) List(List()) | ||
method <init> (Flags.JavaDefined | Flags.Method | Flags.Private) List(List()) | ||
method <init> (Flags.JavaDefined | Flags.Method) List(List((A,_ >: scala.Nothing <: <special-ops>.<FromJavaObject>)), List((x$0,A))) |
This file contains 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,4 @@ | ||
public class JavaClass { | ||
public JavaClass(int a) {} | ||
public JavaClass(float a) {} | ||
} |
This file contains 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 @@ | ||
public class JavaClassEmpty {} |
This file contains 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,3 @@ | ||
public class JavaClassParam<A> { | ||
public JavaClassParam(A a) {} | ||
} |
This file contains 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,3 @@ | ||
class JavaClassPrivate { | ||
private JavaClassPrivate() {} | ||
} |
This file contains 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,4 @@ | ||
class JavaClassStartsWithPrivate { | ||
private JavaClassStartsWithPrivate() {} | ||
public JavaClassStartsWithPrivate(int a) {} | ||
} |
This file contains 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,16 @@ | ||
import scala.quoted.* | ||
|
||
object Macro { | ||
inline def logPrimaryConstructor[A]: String = ${ logPrimaryConstructorImpl[A] } | ||
|
||
def logPrimaryConstructorImpl[A](using Type[A], Quotes): Expr[String] = { | ||
import quotes.reflect.* | ||
|
||
val primaryConstructor = TypeRepr.of[A].typeSymbol.primaryConstructor | ||
val flags = primaryConstructor.flags.show | ||
val paramSymss = primaryConstructor.paramSymss | ||
val clauses = paramSymss.map(_.map(param => (param.name, TypeRepr.of[A].memberType(param).show))) | ||
val str = s"${primaryConstructor} (${primaryConstructor.flags.show}) ${clauses}" | ||
Expr(str) | ||
} | ||
} |
This file contains 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,6 @@ | ||
@main def Test() = | ||
println(Macro.logPrimaryConstructor[JavaClass]) | ||
println(Macro.logPrimaryConstructor[JavaClassEmpty]) | ||
println(Macro.logPrimaryConstructor[JavaClassPrivate]) | ||
println(Macro.logPrimaryConstructor[JavaClassStartsWithPrivate]) | ||
println(Macro.logPrimaryConstructor[JavaClassParam[Int]]) |