forked from scala/scala
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request scala#5570 from adriaanm/t10075
SI-10075 propagate annotations to lazy val's underlying field
- Loading branch information
Showing
10 changed files
with
199 additions
and
22 deletions.
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
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
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
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,35 @@ | ||
class NotSerializable | ||
|
||
trait SerializableActually { | ||
@transient | ||
lazy val notSerializedTLV: NotSerializable = new NotSerializable | ||
|
||
@transient | ||
val notSerializedTL: NotSerializable = new NotSerializable | ||
|
||
@transient | ||
var notSerializedTR: NotSerializable = new NotSerializable | ||
} | ||
|
||
class SerializableBecauseTransient extends Serializable with SerializableActually { | ||
@transient | ||
lazy val notSerializedLV: NotSerializable = new NotSerializable | ||
|
||
@transient | ||
val notSerializedL: NotSerializable = new NotSerializable | ||
|
||
@transient | ||
var notSerializedR: NotSerializable = new NotSerializable | ||
} | ||
|
||
// Indirectly check that the @transient annotation on `notSerialized` made it to the underyling field in bytecode. | ||
// If it doesn't, `writeObject` will fail to serialize the field `notSerialized`, because `NotSerializable` is not serializable | ||
object Test { | ||
def main(args: Array[String]): Unit = { | ||
val obj = new SerializableBecauseTransient | ||
// must force, since `null` valued field is serialized regardless of its type | ||
val forceTLV = obj.notSerializedTLV | ||
val forceLV = obj.notSerializedLV | ||
new java.io.ObjectOutputStream(new java.io.ByteArrayOutputStream) writeObject obj | ||
} | ||
} |
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,60 @@ | ||
private volatile byte C.bitmap$0 | ||
@RetainedAnnotation() private int C.lzyValFieldAnnotation | ||
public int C.lzyValFieldAnnotation() | ||
private int C.lzyValFieldAnnotation$lzycompute() | ||
private int C.lzyValGetterAnnotation | ||
@RetainedAnnotation() public int C.lzyValGetterAnnotation() | ||
private int C.lzyValGetterAnnotation$lzycompute() | ||
@RetainedAnnotation() private final int C.valFieldAnnotation | ||
public int C.valFieldAnnotation() | ||
private final int C.valGetterAnnotation | ||
@RetainedAnnotation() public int C.valGetterAnnotation() | ||
@RetainedAnnotation() private int C.varFieldAnnotation | ||
public int C.varFieldAnnotation() | ||
public void C.varFieldAnnotation_$eq(int) | ||
private int C.varGetterAnnotation | ||
@RetainedAnnotation() public int C.varGetterAnnotation() | ||
public void C.varGetterAnnotation_$eq(int) | ||
private int C.varSetterAnnotation | ||
public int C.varSetterAnnotation() | ||
@RetainedAnnotation() public void C.varSetterAnnotation_$eq(int) | ||
public static void T.$init$(T) | ||
public abstract void T.T$_setter_$valFieldAnnotation_$eq(int) | ||
public abstract void T.T$_setter_$valGetterAnnotation_$eq(int) | ||
public default int T.lzyValFieldAnnotation() | ||
public static int T.lzyValFieldAnnotation$(T) | ||
@RetainedAnnotation() public default int T.lzyValGetterAnnotation() | ||
public static int T.lzyValGetterAnnotation$(T) | ||
@RetainedAnnotation() public default int T.method() | ||
public static int T.method$(T) | ||
public abstract int T.valFieldAnnotation() | ||
@RetainedAnnotation() public abstract int T.valGetterAnnotation() | ||
public abstract int T.varFieldAnnotation() | ||
public abstract void T.varFieldAnnotation_$eq(int) | ||
@RetainedAnnotation() public abstract int T.varGetterAnnotation() | ||
public abstract void T.varGetterAnnotation_$eq(int) | ||
public abstract int T.varSetterAnnotation() | ||
@RetainedAnnotation() public abstract void T.varSetterAnnotation_$eq(int) | ||
public void TMix.T$_setter_$valFieldAnnotation_$eq(int) | ||
public void TMix.T$_setter_$valGetterAnnotation_$eq(int) | ||
private volatile byte TMix.bitmap$0 | ||
@RetainedAnnotation() private int TMix.lzyValFieldAnnotation | ||
public int TMix.lzyValFieldAnnotation() | ||
private int TMix.lzyValFieldAnnotation$lzycompute() | ||
private int TMix.lzyValGetterAnnotation | ||
@RetainedAnnotation() public int TMix.lzyValGetterAnnotation() | ||
private int TMix.lzyValGetterAnnotation$lzycompute() | ||
@RetainedAnnotation() public int TMix.method() | ||
@RetainedAnnotation() private final int TMix.valFieldAnnotation | ||
public int TMix.valFieldAnnotation() | ||
private final int TMix.valGetterAnnotation | ||
@RetainedAnnotation() public int TMix.valGetterAnnotation() | ||
@RetainedAnnotation() private int TMix.varFieldAnnotation | ||
public int TMix.varFieldAnnotation() | ||
public void TMix.varFieldAnnotation_$eq(int) | ||
private int TMix.varGetterAnnotation | ||
@RetainedAnnotation() public int TMix.varGetterAnnotation() | ||
public void TMix.varGetterAnnotation_$eq(int) | ||
private int TMix.varSetterAnnotation | ||
public int TMix.varSetterAnnotation() | ||
@RetainedAnnotation() public void TMix.varSetterAnnotation_$eq(int) |
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 @@ | ||
import java.lang.annotation.*; | ||
|
||
@Retention(RetentionPolicy.RUNTIME) | ||
@interface RetainedAnnotation { } |
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,56 @@ | ||
class C { | ||
@(RetainedAnnotation @annotation.meta.field) | ||
lazy val lzyValFieldAnnotation = 42 | ||
|
||
@(RetainedAnnotation @annotation.meta.getter) | ||
lazy val lzyValGetterAnnotation = 42 | ||
|
||
@(RetainedAnnotation @annotation.meta.field) | ||
val valFieldAnnotation = 42 | ||
|
||
@(RetainedAnnotation @annotation.meta.getter) | ||
val valGetterAnnotation = 42 | ||
|
||
@(RetainedAnnotation @annotation.meta.field) | ||
var varFieldAnnotation = 42 | ||
|
||
@(RetainedAnnotation @annotation.meta.getter) | ||
var varGetterAnnotation = 42 | ||
|
||
@(RetainedAnnotation @annotation.meta.setter) | ||
var varSetterAnnotation = 42 | ||
} | ||
|
||
trait T { | ||
@(RetainedAnnotation @annotation.meta.field) | ||
lazy val lzyValFieldAnnotation = 42 | ||
|
||
@(RetainedAnnotation @annotation.meta.getter) | ||
lazy val lzyValGetterAnnotation = 42 | ||
|
||
@(RetainedAnnotation @annotation.meta.field) | ||
val valFieldAnnotation = 42 | ||
|
||
@(RetainedAnnotation @annotation.meta.getter) | ||
val valGetterAnnotation = 42 | ||
|
||
@(RetainedAnnotation @annotation.meta.field) | ||
var varFieldAnnotation = 42 | ||
|
||
@(RetainedAnnotation @annotation.meta.getter) | ||
var varGetterAnnotation = 42 | ||
|
||
@(RetainedAnnotation @annotation.meta.setter) | ||
var varSetterAnnotation = 42 | ||
|
||
@RetainedAnnotation | ||
def method = 42 | ||
} | ||
class TMix extends T | ||
|
||
object Test extends App { | ||
(List(classOf[C], classOf[T], classOf[TMix]). | ||
flatMap(cls => cls.getDeclaredFields ++ cls.getDeclaredMethods)). | ||
sortBy(x => (x.getDeclaringClass.getName, x.getName, x.toString)). | ||
foreach(x => println(x.getAnnotations.toList.mkString(" ") + " " + x)) | ||
} |