I have this Java method:
/**
* Old method is deprecated.
* @deprecated Use {@link #newMethod()} instead.
* @return boolean
*/
@Deprecated
public static boolean oldMethod() {
return false;
}
and then later on:
boolean result = oldMethod();
In the VS Code editor, the oldMethod()
doesn’t show with strikethough like it does in the NetBeans (and other decent IDEs). Oddly, it does show as strikethrough in the popup code completion, but not in the final code.
I also tried calling the method from a different class, and it still has the same issue:
public class Class2 {
void example() {
Class1.oldMethod();
}
}
I’m using the Apache NetBeans language server extension – however I have the same behaviour when using the ones from Oracle, Red Hat and Microsoft. Also, I checked the "Editor: Show Deprecated" setting and it is turned on. Why is it not shown?
2
Answers
The deprecated tag will only apply the strikethrough on the final code if you are accessing the method from a different class/module. The java Deprecated description states, "A module being deprecated does not cause warnings to be issued for uses of types within the module."(Oracle Documentation) For example, if I were to create a class with a deprecated method like you said,
then calling oldMethod() would not result in a visual strikethrough. However, if I were to create another class as such,
}
then it will visually result in a strikethrough: Class1.
OldMethod().I have also tested
"editor.showDeprecated": true
was not working for me.After playing around with VS Code configurations, I have found the solution.
Solution: Update the
.vscode/settings.json
of your Java Project to haveeditor.semanticTokenColorCustomizations
that you can use to do the customization on the semantics.Screenshot of the
settings.json
location in your project:settings.json
:Screenshot of the Java code:
As soon as you use
@Deprecated
annotation, it will put strikethrough.