Bug 33786 - IMethod:isSimilar - ignoring isConstructor
Summary: IMethod:isSimilar - ignoring isConstructor
Status: RESOLVED WONTFIX
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 2.1   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.0 M1   Edit
Assignee: Olivier Thomann CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2003-03-04 13:31 EST by Adam Kiezun CLA
Modified: 2003-06-02 06:13 EDT (History)
1 user (show)

See Also:


Attachments
Patch using the changes described above (2.40 KB, patch)
2003-04-04 16:47 EST, Olivier Thomann CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Adam Kiezun CLA 2003-03-04 13:31:58 EST
20030227
javadoc for IMethod.isSimilar does not check if isConstructor() is the same for 
both methods

i think it would make sense
Comment 1 Olivier Thomann CLA 2003-03-04 15:04:01 EST
This is a breaking API change. Not sure we want to do it that late in the 2.1
release cycle. Having isContructor() should be enough. isSimilar() is only
checking parameter's simple names anyway, so two methods can be considered as
similar without being the same.
Comment 2 Adam Kiezun CLA 2003-03-05 04:58:23 EST
post 2.1 is ok for me
Comment 3 Olivier Thomann CLA 2003-03-05 10:08:20 EST
Defer for post 2.1.
Comment 4 Philipe Mulet CLA 2003-04-02 06:45:21 EST
reopen - unclear we want to break API (unless implementation is clearly wrong). 
May want to introduce a new API for this.
Comment 5 Olivier Thomann CLA 2003-04-02 13:43:08 EST
Jim - any thoughts on this change?
Comment 6 Jim des Rivieres CLA 2003-04-02 14:57:46 EST
Given the way all of IMethod is spec'd, isConstructor is significant and the 
implementation should be taking it into account. That is, this is just a bug. 
Fixing it does not require changing the API.
Comment 7 Olivier Thomann CLA 2003-04-04 16:45:42 EST
Change the javadoc to:
/**
 * Returns whether this method is similar to the given method.
 * Two methods are similar if:
 * <ul>
 * <li>their element names are equal</li>
 * <li>their isConstructor() values are equal</li>
 * <li>they have the same number of parameters</li>
 * <li>the simple names of their parameter types are equal</li>
 * </ul>
 * This is a handle-only method.
 * 
 * @param method the given method
 * @return true if this method is similar to the given method.
 * @see Signature#getSimpleName
 * @since 2.0
 */
boolean isSimilar(IMethod method);

Change the current implementation for:
public boolean isSimilar(IMethod method) {
	try {
		if (this.isConstructor() != method.isConstructor()) {
			return false;
		}
	} catch(JavaModelException e) {
	}
	return
		this.areSimilarMethods(
			this.getElementName(), this.getParameterTypes(),
			method.getElementName(), method.getParameterTypes(),
			null);
}

Does it look ok for you?
Comment 8 Olivier Thomann CLA 2003-04-04 16:47:27 EST
Created attachment 4468 [details]
Patch using the changes described above
Comment 9 Adam Kiezun CLA 2003-04-07 05:26:33 EDT
code looks good
(i think it's too risky to put for 2.1.1, however)
thanks
Comment 10 Jim des Rivieres CLA 2003-04-07 10:25:42 EDT
One spec suggestion: Rather than mention method by name:
 * <li>their isConstructor() values are equal</li>
the same thing can be said less formally using words like:
 * <li>they are both methods or both constructors</li>
Comment 11 Olivier Thomann CLA 2003-04-07 16:50:59 EDT
Thanks Jim. I will change it.
Adam - Why this is too risky for 2.1.1?
Comment 12 Adam Kiezun CLA 2003-04-08 04:52:52 EDT
it might not be trivial to asses how and where we rely on the fact that it 
ignores the isConstructor

i can have a look if you really want to put it in for 2.1.1, which i think it's 
unnecessary - not a severe bug, is it?
Comment 13 Olivier Thomann CLA 2003-04-08 09:35:43 EDT
Ok, fixed and released only in 2.2 stream.
Comment 14 Olivier Thomann CLA 2003-04-08 10:02:32 EDT
Reopen. In fact we cannot fix it because isConstructor populates the java model.
Comment 15 Olivier Thomann CLA 2003-04-08 10:03:41 EDT
Close as WONTFIX. This method cannot populate the java model. So we cannot call
isConstructor() within this method.
Comment 16 Jim des Rivieres CLA 2003-04-08 10:23:00 EDT
Right. I didn't notice that isConstructor() is a handle-only method and that 
constructor-ness is not stored in the handle.

Note that the chances of a constructor handle clashing with a method handle 
are probably rather low in practice given standard naming conventions.
Comment 17 Adam Kiezun CLA 2003-04-08 11:02:17 EDT
ok, thanks anyway
i don't use that method now but i will put a workaround if i need to 
(got used by now :-))