Bug 67068 - [compiler] Empty blocks and unused parameters in abstract classes
Summary: [compiler] Empty blocks and unused parameters in abstract classes
Status: VERIFIED DUPLICATE of bug 118217
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.0   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.3 M7   Edit
Assignee: Philipe Mulet CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: 157162
  Show dependency tree
 
Reported: 2004-06-14 14:22 EDT by Carolyn MacLeod CLA
Modified: 2007-05-03 21:25 EDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Carolyn MacLeod CLA 2004-06-14 14:22:47 EDT
200406111814 (RC2)

I don't know if this is a bug, or if it's just "the way it is", but it doesn't 
seem very useful as-is...

I turned on Warnings for "Empty block not documented" and "Parameter never 
read", and a whole bunch of them showed up in abstract classes. Technically, 
it is true that the parameters to every single method in an abstract class are 
never read, however that information is not very useful to me. I already know 
that.

The same with "Empty block not documented" (i.e. I already know that abstract 
classes always have an empty block for every method - why are you telling me 
this?). (The methods are even Javadoc'ed - doesn't that count as "documented"?)
Comment 1 Jerome Lanneluc CLA 2004-06-14 17:40:19 EDT
I would expect to have abstract methods in abstract classes. Why are your 
abstract classes providing methods with no behavior ?
Comment 2 Philipe Mulet CLA 2004-06-14 18:03:00 EDT
These were discussed quite a long time ago, and consensus was reached around 
the implemented behavior. Abstract methods are considered special for the 
unused argument diagnosis (as natives), standard methods are not special, no 
matter whether they are defined in abstract classes (which means nothing for 
these methods which aren't abstract).

As for comments, the idea is that a block comment must live inside it, not 
before, not after. Thus 
   void foo() {} // empty
isn't considered as commented (for this diagnosis) where 
   void foo() {  /* empty */ }
is properly commented.

Considering leading comment (like javadoc) for documenting these was 
considered, but rejected in the end, since usually the leading comment would 
depict the protocol, where specifics are usually part of the body of the 
method. So an empty body is usually an implementation detail, and should thus 
be documented inside the code itself.

This isn't an absolute law, but rather a heuristic which happens to match most 
usecases. If we wanted to please everybody, I suspect we'd have to come up 
with so many suboptions, that it would become unmanageable.

Is it ok to close ?
Comment 3 Carolyn MacLeod CLA 2004-06-15 01:39:47 EDT
Yep - ok to close. As for why our abstract-class methods aren't declared 
abstract, I have no idea... I'll have to ask SN what the history is... <g>
Comment 4 Philipe Mulet CLA 2004-06-15 05:44:59 EDT
Closing
Comment 5 Carolyn MacLeod CLA 2004-06-15 10:48:34 EDT
FYI, just to satisfy my curiosity and yours, I looked at our abstract classes 
that have non-abstract methods, and most of them are similar to the adapter 
class pasted below. As you can see, we really do intend to have an abstract 
class with non-abstract empty methods. The javadoc for each method says "The 
default behavior is to do nothing."

So I guess what you are saying is that if we want to turn on "Empty block not 
documented", then we need to add /* empty */ to our "Adapter" class method 
bodies so that the compiler does not flag it. Oh well, I guess I just won't 
turn on that flag <g>.

Here's the sample class:

package org.eclipse.swt.events;

/**
 * This adapter class provides default implementations for the
 * methods described by the <code>ControlListener</code> interface.
 * <p>
 * Classes that wish to deal with <code>ControlEvent</code>s can
 * extend this class and override only the methods which they are
 * interested in.
 * </p>
 *
 * @see ControlListener
 * @see ControlEvent
 */
public abstract class ControlAdapter implements ControlListener {

/**
 * Sent when the location (x, y) of a control changes relative
 * to its parent (or relative to the display, for <code>Shell</code>s).
 * The default behavior is to do nothing.
 *
 * @param e an event containing information about the move
 */
public void controlMoved(ControlEvent e) {
}

/**
 * Sent when the size (width, height) of a control changes.
 * The default behavior is to do nothing.
 *
 * @param e an event containing information about the resize
 */
public void controlResized(ControlEvent e) {
}
}
Comment 6 Philipe Mulet CLA 2004-06-15 11:59:20 EDT
Maybe post 3.0 we could add a suboption to include method/class bodies or 
not...
Comment 7 Philipe Mulet CLA 2004-06-15 11:59:39 EDT
post 3.0
Comment 8 Frederic Fusier CLA 2006-09-08 13:39:38 EDT
JDT/Summit topic
Comment 9 Philipe Mulet CLA 2007-05-03 12:36:33 EDT
pls see bug 118217 for a better solution to this

*** This bug has been marked as a duplicate of bug 118217 ***
Comment 10 Olivier Thomann CLA 2007-05-03 21:25:39 EDT
Verify for 3.3M7 with I20070503-1400.