Skip to content

Commit

Permalink
Honour @deprecated in joint-compiled Java sources
Browse files Browse the repository at this point in the history
  • Loading branch information
dwijnand committed Apr 22, 2020
1 parent 44477d3 commit 5ef207b
Show file tree
Hide file tree
Showing 11 changed files with 33 additions and 7 deletions.
Expand Up @@ -821,11 +821,9 @@ abstract class ClassfileParser(reader: ReusableInstance[ReusableDataReader]) {
in.skip(attrLen)

case tpnme.DeprecatedATTR =>
val arg = Literal(Constant("see corresponding Javadoc for more information."))
sym.addAnnotation(DeprecatedAttr, arg, Literal(Constant("")))
in.skip(attrLen)
if (sym == clazz)
staticModule.addAnnotation(DeprecatedAttr, arg, Literal(Constant("")))
staticModule.addAnnotation(JavaDeprecatedAttr)

case tpnme.ConstantValueATTR =>
completer.constant = pool.getConstant(u2)
Expand Down
1 change: 1 addition & 0 deletions src/reflect/scala/reflect/internal/Definitions.scala
Expand Up @@ -1200,6 +1200,7 @@ trait Definitions extends api.StandardDefinitions {
lazy val UncheckedBoundsClass = getClassIfDefined("scala.reflect.internal.annotations.uncheckedBounds")
lazy val UnspecializedClass = requiredClass[scala.annotation.unspecialized]
lazy val VolatileAttr = requiredClass[scala.volatile]
lazy val JavaDeprecatedAttr = requiredClass[java.lang.Deprecated]
lazy val FunctionalInterfaceClass = requiredClass[java.lang.FunctionalInterface]

// Meta-annotations
Expand Down
2 changes: 1 addition & 1 deletion src/reflect/scala/reflect/internal/Symbols.scala
Expand Up @@ -904,7 +904,7 @@ trait Symbols extends api.Symbols { self: SymbolTable =>
def isStrictFP: Boolean = !isDeferred && (hasAnnotation(ScalaStrictFPAttr) || originalOwner.isStrictFP)
def isSerializable = info.baseClasses.exists(p => p == SerializableClass || p == JavaSerializableClass)
def hasBridgeAnnotation = hasAnnotation(BridgeClass)
def isDeprecated = hasAnnotation(DeprecatedAttr)
def isDeprecated = hasAnnotation(DeprecatedAttr) || (isJava && hasAnnotation(JavaDeprecatedAttr))
def deprecationMessage = getAnnotation(DeprecatedAttr) flatMap (_ stringArg 0)
def deprecationVersion = getAnnotation(DeprecatedAttr) flatMap (_ stringArg 1)
def deprecatedParamName = getAnnotation(DeprecatedNameAttr) flatMap (_ symbolArg 0 orElse Some(nme.NO_NAME))
Expand Down
1 change: 1 addition & 0 deletions src/reflect/scala/reflect/runtime/JavaUniverseForce.scala
Expand Up @@ -428,6 +428,7 @@ trait JavaUniverseForce { self: runtime.JavaUniverse =>
definitions.UncheckedBoundsClass
definitions.UnspecializedClass
definitions.VolatileAttr
definitions.JavaDeprecatedAttr
definitions.FunctionalInterfaceClass
definitions.BeanGetterTargetClass
definitions.BeanSetterTargetClass
Expand Down
1 change: 0 additions & 1 deletion test/files/jvm/deprecation.check
@@ -1,3 +1,2 @@
warning: there were four deprecation warnings; re-run with -deprecation for details
Note: deprecation/Use_2.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
4 changes: 2 additions & 2 deletions test/files/neg/t10752.check
@@ -1,7 +1,7 @@
Test_2.scala:2: warning: class DeprecatedClass in package p1 is deprecated: see corresponding Javadoc for more information.
Test_2.scala:2: warning: class DeprecatedClass in package p1 is deprecated
def useC = p1.DeprecatedClass.foo
^
Test_2.scala:3: warning: method foo in class DeprecatedMethod is deprecated: see corresponding Javadoc for more information.
Test_2.scala:3: warning: method foo in class DeprecatedMethod is deprecated
def useM = p1.DeprecatedMethod.foo
^
error: No warnings can be incurred under -Xfatal-warnings.
Expand Down
9 changes: 9 additions & 0 deletions test/files/neg/t9617.check
@@ -0,0 +1,9 @@
Test.scala:3: warning: class DeprecatedClass in package p1 is deprecated
def useC = p1.DeprecatedClass.foo
^
Test.scala:4: warning: method foo in class DeprecatedMethod is deprecated
def useM = p1.DeprecatedMethod.foo
^
error: No warnings can be incurred under -Xfatal-warnings.
two warnings found
one error found
6 changes: 6 additions & 0 deletions test/files/neg/t9617/DeprecatedClass.java
@@ -0,0 +1,6 @@
package p1;

@Deprecated
public class DeprecatedClass {
public static void foo() {}
}
6 changes: 6 additions & 0 deletions test/files/neg/t9617/DeprecatedMethod.java
@@ -0,0 +1,6 @@
package p1;

public class DeprecatedMethod {
@Deprecated
public static void foo() {}
}
1 change: 1 addition & 0 deletions test/files/neg/t9617/Test.flags
@@ -0,0 +1 @@
-Xfatal-warnings -deprecation
5 changes: 5 additions & 0 deletions test/files/neg/t9617/Test.scala
@@ -0,0 +1,5 @@
// Joint-compilation copy of test/files/neg/t10752/Test_2.scala
object Test {
def useC = p1.DeprecatedClass.foo
def useM = p1.DeprecatedMethod.foo
}

0 comments on commit 5ef207b

Please sign in to comment.