Bug 232466 - [formatter] References of inlined tags are still split in certain circumstances
Summary: [formatter] References of inlined tags are still split in certain circumstances
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.4   Edit
Hardware: PC Windows Vista
: P3 normal (vote)
Target Milestone: 3.4 RC2   Edit
Assignee: Frederic Fusier CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-05-16 06:21 EDT by Frederic Fusier CLA
Modified: 2008-05-23 05:56 EDT (History)
4 users (show)

See Also:
maxime_daniel: review+
david_audel: review+


Attachments
Proposed patch (30.63 KB, patch)
2008-05-16 07:31 EDT, Frederic Fusier CLA
no flags Details | Diff
Better patch but still no perfect... (41.94 KB, text/plain)
2008-05-18 11:49 EDT, Frederic Fusier CLA
no flags Details
First proposed patch on top of v_866 (5.43 KB, patch)
2008-05-21 04:50 EDT, Frederic Fusier CLA
no flags Details | Diff
New proposed patch after Maxime's review (5.60 KB, patch)
2008-05-21 08:30 EDT, Frederic Fusier CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Frederic Fusier CLA 2008-05-16 06:21:07 EDT
Using 3.4RC1 candidate (I20080515-2000).

Format the following test case:
/**
 * {@link SearchEngine#searchAllTypeNames(
 *		char[] packageName, 
 *		int packageMatchRule, 
 *		char[] typeName,
 *		int typeMatchRule, 
 *		int searchFor, 
 *		IJavaSearchScope scope, 
 *		TypeNameMatchRequestor nameMatchRequestor,
 *		int waitingPolicy,
 * 		org.eclipse.core.runtime.IProgressMonitor monitor)}
 */
public class X01 {

}

The output is:
/**
 * {@link SearchEngine#searchAllTypeNames(char[]packageName, intpackageMatchRule, char[]typeName, inttypeMatchRule, intsearchFor, IJavaSearchScopescope, TypeNameMatchRequestornameMatchRequestor, intwaitingPolicy, org.eclipse.core.runtime.IProgressMonitormonitor)}
 */
public class X01 {

}

There's only one line (it's bugzilla which splits it...), but first note that there's no space between arguments type and name.

If I try to reformat this output again, then I get:
/**
 * {@link SearchEngine#searchAllTypeNames(char[]packageName,
 * intpackageMatchRule, char[]typeName, inttypeMatchRule, intsearchFor,
 * IJavaSearchScopescope, TypeNameMatchRequestornameMatchRequestor,
 * intwaitingPolicy, org.eclipse.core.runtime.IProgressMonitormonitor)}
 */
public class X01 {

}

This time this is not bugzilla which is adding the lines, it's the formatter...
Comment 1 Frederic Fusier CLA 2008-05-16 06:26:35 EDT
The problem comes from the method:
org.eclipse.jdt.internal.formatter.Scribe.printJavadocBlockReference(FormatJavadocBlock, FormatJavadocReference)

The first space problem between arguments type and name is that it should add a space only when previous token is a comma, but in fact when when the previous token is neither a '*' nor a left parenthesis.

I'm investigating the second reformatting problem...
Comment 2 Frederic Fusier CLA 2008-05-16 06:29:10 EDT
The split occurs during the second formatting because the output of the first formatting leads to a syntax error. In this case, the reference is just only considered as simple text, hence possibly split if over the line max length...

So, fixing the first issue will fix both of them...
Comment 3 Frederic Fusier CLA 2008-05-16 07:31:23 EDT
Created attachment 100624 [details]
Proposed patch
Comment 4 Frederic Fusier CLA 2008-05-16 12:32:03 EDT
Jerome, I think this will be a good candidate for RC2 as it fixes 4 failures in Ganymede workspace and it's a tiny and localized change.
Comment 5 Frederic Fusier CLA 2008-05-18 11:40:13 EDT
Comment on attachment 100624 [details]
Proposed patch

This patch does not handle all cases. Typically when there are spaces inside qualified name...
Comment 6 Frederic Fusier CLA 2008-05-18 11:44:32 EDT
One more complex example:
package test.bugs.b232466;

/**
 * {@link 
 * test        .      bugs.	
 * 		b232466		.X03.LocalClass03
 * 	#
 * 		foo     (     
 *		char    [    ] 
 *			packageName, 
 *		java    .    lang	.String 
 *			packageMatchRule, 
 *		char	[		] 
 *			typeName
 *	)
 *                             }
 */
public class X03 {

class LocalClass03 {
	void foo(char[] packageName, String str,
			char[] typeName) {
	}
}

}

Should be formatted as:
package test.bugs.b232466;

/**
 * {@link test.bugs.b232466.X03.LocalClass03#foo(char[] packageName, java.lang.String packageMatchRule, char[] typeName)}
 */
public class X03 {

	class LocalClass03 {
		void foo(char[] packageName, String str, char[] typeName) {
		}
	}

}

But with initial proposed patch is incorrectly formatted as:
package test.bugs.b232466;

/**
 * {@link test . bugs. b232466 .X03.LocalClass03 # foo (char [ ] packageName, java . lang .String packageMatchRule, char [ ] typeName )
 *                             }
 */
public class X03 {

	class LocalClass03 {
		void foo(char[] packageName, String str, char[] typeName) {
		}
	}

}
Comment 7 Frederic Fusier CLA 2008-05-18 11:49:56 EDT
Created attachment 100815 [details]
Better patch but still no perfect...

This patch address the complex test case of comment 6, but unfortunately introduces 5 failures in Eclipse 3.0 full src workspace => that means more work is required on this issue. So, I guess, this implies a no go for RC2 and this bug should be targeted for 3.4.1 instead!
Comment 8 Jerome Lanneluc CLA 2008-05-21 04:29:35 EDT
The test case from comment 0 should at least be fixed for RC2 since it introduces an invalid reference. Patch from comment 3 is a good candidate. We should enter a new bug for the test case from comment 6.
Comment 9 Frederic Fusier CLA 2008-05-21 04:50:49 EDT
Created attachment 101206 [details]
First proposed patch on top of v_866
Comment 10 Frederic Fusier CLA 2008-05-21 04:52:05 EDT
Maxime, David, can you please review?
Comment 11 Frederic Fusier CLA 2008-05-21 04:58:12 EDT
(In reply to comment #8)
> The test case from comment 0 should at least be fixed for RC2 since it
> introduces an invalid reference. Patch from comment 3 is a good candidate. We
> should enter a new bug for the test case from comment 6.
> 
I've opened bug 233167 for the comment 6 issue.
Comment 12 David Audel CLA 2008-05-21 05:40:58 EDT
Patch looks good: +1.
Comment 13 Maxime Daniel CLA 2008-05-21 07:09:46 EDT
I believe that the following code is equivalent but slightly faster than the
one that is proposed (especially since -1 is hopefully not the most frequent value - I computed no stats though):
switch (previousToken) {
  case TerminalTokens.TokenNameMULTIPLY :
  case TerminalTokens.TokenNameLPAREN:
    break;
  default:      // space between method arguments
    spacePosition = buffer.length();
    // deliberate fall-through
  case -1:
    buffer.append(' ');
    this.column++; // space before reference  
    break;
}
Comment 14 Frederic Fusier CLA 2008-05-21 08:30:34 EDT
Created attachment 101239 [details]
New proposed patch after Maxime's review
Comment 15 Frederic Fusier CLA 2008-05-21 08:31:15 EDT
David, could you please review it again?
Thanks
Comment 16 David Audel CLA 2008-05-21 09:28:07 EDT
New patch looks good and better: +1.
Comment 17 Maxime Daniel CLA 2008-05-21 09:54:40 EDT
+1
Comment 18 Frederic Fusier CLA 2008-05-21 10:59:18 EDT
Released for 3.4RC2 in HEAD stream.
Comment 19 Eric Jodet CLA 2008-05-23 05:54:19 EDT
verified for 3.4RC2 using build I20080523-0100
Comment 20 Eric Jodet CLA 2008-05-23 05:56:02 EDT
-