Bug 334978 - [syntax highlighting] default constructor of deprecated type should be rendered with strikethrough
Summary: [syntax highlighting] default constructor of deprecated type should be render...
Status: RESOLVED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Text (show other bugs)
Version: 3.7   Edit
Hardware: PC Linux
: P3 minor (vote)
Target Milestone: 3.7 M6   Edit
Assignee: Markus Keller CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-01-21 02:23 EST by Eduard CLA
Modified: 2011-03-04 10:30 EST (History)
4 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Eduard CLA 2011-01-21 02:23:46 EST
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
Comment 1 Eduard CLA 2011-01-21 04:25:42 EST
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.
Comment 2 Ayushman Jain CLA 2011-01-21 04:30:47 EST
Moving to JDT/UI
Comment 3 Markus Keller CLA 2011-01-21 12:03:10 EST
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 {
    }
}
Comment 4 Olivier Thomann CLA 2011-01-21 12:06:18 EST
This should be trivial to add. Let me check.
Comment 5 Olivier Thomann CLA 2011-01-21 13:49:21 EST
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() ?
Comment 6 Olivier Thomann CLA 2011-01-21 13:57:26 EST
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.
Comment 7 Olivier Thomann CLA 2011-01-21 14:05:50 EST
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.
Comment 8 Markus Keller CLA 2011-01-21 14:55:12 EST
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.
Comment 9 Markus Keller CLA 2011-03-04 10:30:56 EST
Fixed in org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlightings.DeprecatedMemberHighlighting.consumes(SemanticToken).