-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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 #10422 from som-snytt/issue/12799-inherited-annots
Deduplicate JavaDeprecatedAttr in ClassfileParser
- Loading branch information
Showing
13 changed files
with
126 additions
and
20 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
Test_2.scala:8: warning: method answer in class C is deprecated (since beginning) | ||
println(C.answer()) | ||
^ | ||
Test_2.scala:8: warning: class C in package example is deprecated (since you like it) | ||
println(C.answer()) | ||
^ | ||
error: No warnings can be incurred under -Werror. | ||
2 warnings | ||
1 error |
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,11 @@ | ||
|
||
package example; | ||
|
||
@Deprecated(since="you like it") | ||
public class C { | ||
|
||
@Deprecated(since="beginning") | ||
public static int answer() { | ||
return 42; | ||
} | ||
} |
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,9 @@ | ||
|
||
// scalac: -Werror -Xlint | ||
// javaVersion: 9+ | ||
|
||
import example._ | ||
|
||
object Test extends App { | ||
println(C.answer()) | ||
} |
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,10 @@ | ||
Test_2.scala:7: warning: class B in package example is deprecated (since 1.0): beeless | ||
val deprecatedMethod = classOf[B].getMethod("a") | ||
^ | ||
Test_2.scala:9: warning: method a in trait A is deprecated | ||
println(new B().a) | ||
^ | ||
Test_2.scala:9: warning: class B in package example is deprecated (since 1.0): beeless | ||
println(new B().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,9 @@ | ||
|
||
package example; | ||
|
||
interface A { | ||
@Deprecated | ||
default String a() { | ||
return "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,5 @@ | ||
|
||
package example | ||
|
||
@deprecated("beeless", since="1.0") | ||
class B extends 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,11 @@ | ||
|
||
// scalac: -Xlint | ||
|
||
import example._ | ||
|
||
object Test extends App { | ||
val deprecatedMethod = classOf[B].getMethod("a") | ||
assert(deprecatedMethod.isAnnotationPresent(classOf[Deprecated])) | ||
println(new B().a) | ||
} | ||
//java.lang.annotation.AnnotationFormatError: Duplicate annotation for class: interface java.lang.Deprecated: @java.lang.Deprecated(forRemoval=false, since="") |
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,4 @@ | ||
|
||
import java.lang.annotation._ | ||
|
||
@Deprecated @Retention(RetentionPolicy.RUNTIME) class Foo |
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,24 @@ | ||
|
||
import java.lang.annotation._ | ||
|
||
object Test extends App { | ||
classOf[Foo].getAnnotation(classOf[Deprecated]) | ||
|
||
assert(classOf[Foo].getAnnotation(classOf[Retention]).value() == RetentionPolicy.RUNTIME) | ||
|
||
import reflect.runtime.universe._ | ||
|
||
val List(d, r) = symbolOf[Foo].annotations | ||
|
||
d.tree match { | ||
case Apply(Select(New(tpt), _), Nil) => | ||
assert (tpt.tpe.typeSymbol == symbolOf[Deprecated], tpt.tpe.typeSymbol) | ||
} | ||
|
||
val RetentionPolicy_RUNTIME = symbolOf[RetentionPolicy].companion.info.decl(TermName("RUNTIME")) | ||
r.tree match { | ||
case Apply(Select(New(tpt), _), List(NamedArg(Ident(TermName("value")), Literal(Constant(RetentionPolicy_RUNTIME))))) => | ||
assert(tpt.tpe.typeSymbol == symbolOf[Retention], tpt.tpe.typeSymbol) | ||
} | ||
|
||
} |