Community
Participate
Working Groups
Build Identifier: M20100211-1343 import java.util.ArrayList; import java.util.List; public class DeprecatedTest { private final List<Object> instances; public DeprecatedTest(){ instances = new ArrayList<Object>(); instances.add(new Depr()); instances.add(new Depr1()); instances.add(new Depr2()); instances.add(new Depr3()); } @Deprecated public class Depr{} @Deprecated public class Depr1{} @Deprecated public class Depr2{} @Deprecated public class Depr3{} } Reproducible: Always
instances.add(new Depr()); instances.add(new Depr1()); instances.add(new Depr2()); instances.add(new Depr3()); new Depr(), new Depr1(), new Depr2(), new Depr3() - not stroked out.
Moving to JDT/UI
Your example doesn't contain anonymous classes ;-). Nevertheless, this is a general problem for all deprecated classes with only a default constructor. The Javadoc tool also marks the default constructor as deprecated, so MethodBinding#isDeprecated() should do that as well. package xy; /** * @deprecated use something else! */ public class DeprecatedTest { static DeprecatedTest.Depr DEPR= new DeprecatedTest().new Depr(); @Deprecated public DeprecatedTest() { Depr depr= new Depr(); depr= new Depr() { }; DeprecatedTest test= new DeprecatedTest(); test= new DeprecatedTest() { }; } /** * @deprecated bad API */ @Deprecated public class Depr { } }
This should be trivial to add. Let me check.
In fact the javadoc for org.eclipse.jdt.core.dom.IBinding#isDeprecated doesn't talk about implicitly deprecated. In this case the method binding is not declared as deprecated but is implicitly deprecated. I can fix it to be reported as deprecated when calling isDeprecated(), but I don't think that this will match the javadoc anymore. Markus, are you expecting implicitly deprecated method to return true for isDeprecated() ?
In the first example, the eclipse compiler doesn't report deprecation warnings for the usage of default constructor, because the deprecated types are defined from within the same compilation unit. You get deprecation warnings if the definition of Depr, Depr1, Depr2 and Depr3 are defined in different units.
javac doesn't report deprecation from within the same type, but it does report deprecation from within the same unit. The check for the eclipse compiler is done in: org.eclipse.jdt.internal.compiler.ast.ASTNode.isMethodUseDeprecated(MethodBinding, Scope, boolean) where we explicitly check if the declaring class of the method binding comes from the same compilation unit. We might consider changing this, but this should be done in another bug report.
Indeed, Javac also doesn't seem to consider the implicit constructor as deprecated: package xy; /** * @deprecated Class is bad */ @Deprecated @Deprecated public class Deprecated2 { // @Deprecated // public Deprecated2() { // } } package xy; public class Reference extends Deprecated2 { Reference() { super(); new Deprecated2(); } } Javac only issues warnings where Deprecated2 is explicitly referenced, but it doesn't mark "super()". I didn't find anything in the specs that would describe implicit deprecation, so I withdraw my request. We can fix this on the UI side in DeprecatedMemberHighlighting. Sorry for the hassle.
Fixed in org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlightings.DeprecatedMemberHighlighting.consumes(SemanticToken).