View | Details | Raw Unified | Return to bug 102780 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/jdt/core/tests/formatter/FormatterRegressionTests.java (-1 / +67 lines)
Lines 131-137 Link Here
131
//			assertEquals("Should not have edits", 0, edit.getChildren().length);
131
//			assertEquals("Should not have edits", 0, edit.getChildren().length);
132
			final String result2 = org.eclipse.jdt.internal.core.util.Util.editedString(result, edit);
132
			final String result2 = org.eclipse.jdt.internal.core.util.Util.editedString(result, edit);
133
			if (!result.equals(result2)) {
133
			if (!result.equals(result2)) {
134
				assertSourceEquals("Different reformatting", Util.convertToIndependantLineDelimiter(result), Util.convertToIndependantLineDelimiter(result2));
134
				assertSourceEquals("Second formatting is different from first one!", Util.convertToIndependantLineDelimiter(result), Util.convertToIndependantLineDelimiter(result2));
135
			}
135
			}
136
		}
136
		}
137
		return result;
137
		return result;
Lines 863-868 Link Here
863
	public void test083() {
863
	public void test083() {
864
		DefaultCodeFormatterOptions preferences = new DefaultCodeFormatterOptions(DefaultCodeFormatterConstants.getEclipse21Settings());
864
		DefaultCodeFormatterOptions preferences = new DefaultCodeFormatterOptions(DefaultCodeFormatterConstants.getEclipse21Settings());
865
		preferences.number_of_empty_lines_to_preserve = 0;
865
		preferences.number_of_empty_lines_to_preserve = 0;
866
		preferences.comment_insert_empty_line_before_root_tags = false; // ejd bug 102780
866
		preferences.tab_char = DefaultCodeFormatterOptions.TAB;
867
		preferences.tab_char = DefaultCodeFormatterOptions.TAB;
867
		DefaultCodeFormatter codeFormatter = new DefaultCodeFormatter(preferences);
868
		DefaultCodeFormatter codeFormatter = new DefaultCodeFormatter(preferences);
868
		runTest(codeFormatter, "test083", "A.java", CodeFormatter.K_CLASS_BODY_DECLARATIONS);//$NON-NLS-1$ //$NON-NLS-2$
869
		runTest(codeFormatter, "test083", "A.java", CodeFormatter.K_CLASS_BODY_DECLARATIONS);//$NON-NLS-1$ //$NON-NLS-2$
Lines 1413-1418 Link Here
1413
		DefaultCodeFormatterOptions preferences = new DefaultCodeFormatterOptions(DefaultCodeFormatterConstants.getEclipse21Settings());
1414
		DefaultCodeFormatterOptions preferences = new DefaultCodeFormatterOptions(DefaultCodeFormatterConstants.getEclipse21Settings());
1414
		preferences.number_of_empty_lines_to_preserve = 0;
1415
		preferences.number_of_empty_lines_to_preserve = 0;
1415
		preferences.tab_char = DefaultCodeFormatterOptions.TAB;
1416
		preferences.tab_char = DefaultCodeFormatterOptions.TAB;
1417
		preferences.comment_indent_root_tags = false; // ejd bug 102780
1418
		preferences.comment_indent_parameter_description = false; // ejd bug 102780
1416
		DefaultCodeFormatter codeFormatter = new DefaultCodeFormatter(preferences);
1419
		DefaultCodeFormatter codeFormatter = new DefaultCodeFormatter(preferences);
1417
		runTest(codeFormatter, "test137", "A.java", CodeFormatter.K_COMPILATION_UNIT, true);//$NON-NLS-1$ //$NON-NLS-2$
1420
		runTest(codeFormatter, "test137", "A.java", CodeFormatter.K_COMPILATION_UNIT, true);//$NON-NLS-1$ //$NON-NLS-2$
1418
	}
1421
	}
Lines 1572-1577 Link Here
1572
	public void test159() {
1575
	public void test159() {
1573
		DefaultCodeFormatterOptions preferences = new DefaultCodeFormatterOptions(DefaultCodeFormatterConstants.getEclipse21Settings());
1576
		DefaultCodeFormatterOptions preferences = new DefaultCodeFormatterOptions(DefaultCodeFormatterConstants.getEclipse21Settings());
1574
		preferences.number_of_empty_lines_to_preserve = 1;
1577
		preferences.number_of_empty_lines_to_preserve = 1;
1578
		preferences.comment_insert_empty_line_before_root_tags = false; // necessary once bug 102780 fixed
1575
		DefaultCodeFormatter codeFormatter = new DefaultCodeFormatter(preferences);
1579
		DefaultCodeFormatter codeFormatter = new DefaultCodeFormatter(preferences);
1576
		runTest(codeFormatter, "test159", "A.java", CodeFormatter.K_COMPILATION_UNIT);//$NON-NLS-1$ //$NON-NLS-2$
1580
		runTest(codeFormatter, "test159", "A.java", CodeFormatter.K_COMPILATION_UNIT);//$NON-NLS-1$ //$NON-NLS-2$
1577
	}	
1581
	}	
Lines 8796-8801 Link Here
8796
	public void test616() {
8800
	public void test616() {
8797
		Map options = DefaultCodeFormatterConstants.getEclipseDefaultSettings();
8801
		Map options = DefaultCodeFormatterConstants.getEclipseDefaultSettings();
8798
		DefaultCodeFormatterOptions preferences = new DefaultCodeFormatterOptions(options);
8802
		DefaultCodeFormatterOptions preferences = new DefaultCodeFormatterOptions(options);
8803
		preferences.comment_insert_empty_line_before_root_tags = false; // necessary once bug 102780 fixed
8799
		DefaultCodeFormatter codeFormatter = new DefaultCodeFormatter(preferences);
8804
		DefaultCodeFormatter codeFormatter = new DefaultCodeFormatter(preferences);
8800
		runTest(codeFormatter, "test616", "A.java", CodeFormatter.K_COMPILATION_UNIT, false);//$NON-NLS-1$ //$NON-NLS-2$
8805
		runTest(codeFormatter, "test616", "A.java", CodeFormatter.K_COMPILATION_UNIT, false);//$NON-NLS-1$ //$NON-NLS-2$
8801
	}
8806
	}
Lines 9296-9301 Link Here
9296
		DefaultCodeFormatterOptions preferences = new DefaultCodeFormatterOptions(options);
9301
		DefaultCodeFormatterOptions preferences = new DefaultCodeFormatterOptions(options);
9297
		preferences.never_indent_block_comments_on_first_column = false;
9302
		preferences.never_indent_block_comments_on_first_column = false;
9298
		preferences.never_indent_line_comments_on_first_column = false;
9303
		preferences.never_indent_line_comments_on_first_column = false;
9304
		preferences.comment_insert_empty_line_before_root_tags = false; // necessary once bug 102780 fixed
9299
		DefaultCodeFormatter codeFormatter = new DefaultCodeFormatter(preferences);
9305
		DefaultCodeFormatter codeFormatter = new DefaultCodeFormatter(preferences);
9300
		runTest(codeFormatter, "test658", "A.java");//$NON-NLS-1$ //$NON-NLS-2$
9306
		runTest(codeFormatter, "test658", "A.java");//$NON-NLS-1$ //$NON-NLS-2$
9301
	}
9307
	}
Lines 9306-9311 Link Here
9306
		DefaultCodeFormatterOptions preferences = new DefaultCodeFormatterOptions(options);
9312
		DefaultCodeFormatterOptions preferences = new DefaultCodeFormatterOptions(options);
9307
		preferences.never_indent_block_comments_on_first_column = true;
9313
		preferences.never_indent_block_comments_on_first_column = true;
9308
		preferences.never_indent_line_comments_on_first_column = true;
9314
		preferences.never_indent_line_comments_on_first_column = true;
9315
		preferences.comment_insert_empty_line_before_root_tags = false; // necessary once bug 102780 fixed
9309
		DefaultCodeFormatter codeFormatter = new DefaultCodeFormatter(preferences);
9316
		DefaultCodeFormatter codeFormatter = new DefaultCodeFormatter(preferences);
9310
		runTest(codeFormatter, "test659", "A.java");//$NON-NLS-1$ //$NON-NLS-2$
9317
		runTest(codeFormatter, "test659", "A.java");//$NON-NLS-1$ //$NON-NLS-2$
9311
	}
9318
	}
Lines 9316-9321 Link Here
9316
		DefaultCodeFormatterOptions preferences = new DefaultCodeFormatterOptions(options);
9323
		DefaultCodeFormatterOptions preferences = new DefaultCodeFormatterOptions(options);
9317
		preferences.never_indent_block_comments_on_first_column = false;
9324
		preferences.never_indent_block_comments_on_first_column = false;
9318
		preferences.never_indent_line_comments_on_first_column = true;
9325
		preferences.never_indent_line_comments_on_first_column = true;
9326
		preferences.comment_insert_empty_line_before_root_tags = false; // necessary once bug 102780 fixed
9319
		DefaultCodeFormatter codeFormatter = new DefaultCodeFormatter(preferences);
9327
		DefaultCodeFormatter codeFormatter = new DefaultCodeFormatter(preferences);
9320
		runTest(codeFormatter, "test660", "A.java");//$NON-NLS-1$ //$NON-NLS-2$
9328
		runTest(codeFormatter, "test660", "A.java");//$NON-NLS-1$ //$NON-NLS-2$
9321
	}
9329
	}
Lines 9326-9331 Link Here
9326
		DefaultCodeFormatterOptions preferences = new DefaultCodeFormatterOptions(options);
9334
		DefaultCodeFormatterOptions preferences = new DefaultCodeFormatterOptions(options);
9327
		preferences.never_indent_block_comments_on_first_column = true;
9335
		preferences.never_indent_block_comments_on_first_column = true;
9328
		preferences.never_indent_line_comments_on_first_column = false;
9336
		preferences.never_indent_line_comments_on_first_column = false;
9337
		preferences.comment_insert_empty_line_before_root_tags = false; // necessary once bug 102780 fixed
9329
		DefaultCodeFormatter codeFormatter = new DefaultCodeFormatter(preferences);
9338
		DefaultCodeFormatter codeFormatter = new DefaultCodeFormatter(preferences);
9330
		runTest(codeFormatter, "test661", "A.java");//$NON-NLS-1$ //$NON-NLS-2$
9339
		runTest(codeFormatter, "test661", "A.java");//$NON-NLS-1$ //$NON-NLS-2$
9331
	}
9340
	}
Lines 9336-9341 Link Here
9336
		DefaultCodeFormatterOptions preferences = new DefaultCodeFormatterOptions(options);
9345
		DefaultCodeFormatterOptions preferences = new DefaultCodeFormatterOptions(options);
9337
		preferences.never_indent_block_comments_on_first_column = true;
9346
		preferences.never_indent_block_comments_on_first_column = true;
9338
		preferences.never_indent_line_comments_on_first_column = true;
9347
		preferences.never_indent_line_comments_on_first_column = true;
9348
		preferences.comment_insert_empty_line_before_root_tags = false; // necessary once bug 102780 fixed
9339
		DefaultCodeFormatter codeFormatter = new DefaultCodeFormatter(preferences);
9349
		DefaultCodeFormatter codeFormatter = new DefaultCodeFormatter(preferences);
9340
		runTest(codeFormatter, "test662", "A.java");//$NON-NLS-1$ //$NON-NLS-2$
9350
		runTest(codeFormatter, "test662", "A.java");//$NON-NLS-1$ //$NON-NLS-2$
9341
	}
9351
	}
Lines 9346-9351 Link Here
9346
		DefaultCodeFormatterOptions preferences = new DefaultCodeFormatterOptions(options);
9356
		DefaultCodeFormatterOptions preferences = new DefaultCodeFormatterOptions(options);
9347
		preferences.never_indent_block_comments_on_first_column = true;
9357
		preferences.never_indent_block_comments_on_first_column = true;
9348
		preferences.never_indent_line_comments_on_first_column = true;
9358
		preferences.never_indent_line_comments_on_first_column = true;
9359
		preferences.comment_insert_empty_line_before_root_tags = false; // necessary once bug 102780 fixed
9349
		DefaultCodeFormatter codeFormatter = new DefaultCodeFormatter(preferences);
9360
		DefaultCodeFormatter codeFormatter = new DefaultCodeFormatter(preferences);
9350
		runTest(codeFormatter, "test663", "A.java");//$NON-NLS-1$ //$NON-NLS-2$
9361
		runTest(codeFormatter, "test663", "A.java");//$NON-NLS-1$ //$NON-NLS-2$
9351
	}
9362
	}
Lines 10113-10116 Link Here
10113
			JavaCore.setOptions(javaCoreOptions);
10124
			JavaCore.setOptions(javaCoreOptions);
10114
		}
10125
		}
10115
	}
10126
	}
10127
	
10128
	// https://bugs.eclipse.org/bugs/show_bug.cgi?id=102780
10129
	public void test713() {
10130
		final Map options = DefaultCodeFormatterConstants.getEclipseDefaultSettings();
10131
		DefaultCodeFormatterOptions preferences = new DefaultCodeFormatterOptions(options);
10132
		DefaultCodeFormatter codeFormatter = new DefaultCodeFormatter(preferences);
10133
		runTest(codeFormatter, "test713", "X.java", CodeFormatter.K_COMPILATION_UNIT, false);//$NON-NLS-1$ //$NON-NLS-2$
10134
	}
10135
	
10136
	// https://bugs.eclipse.org/bugs/show_bug.cgi?id=102780
10137
	public void _test714() {
10138
		final Map options = DefaultCodeFormatterConstants.getEclipseDefaultSettings();
10139
		DefaultCodeFormatterOptions preferences = new DefaultCodeFormatterOptions(options);
10140
		DefaultCodeFormatter codeFormatter = new DefaultCodeFormatter(preferences);
10141
		runTest(codeFormatter, "test714", "X.java", CodeFormatter.K_COMPILATION_UNIT, false);//$NON-NLS-1$ //$NON-NLS-2$
10142
	}
10143
	
10144
	// https://bugs.eclipse.org/bugs/show_bug.cgi?id=102780
10145
	// test default options
10146
	public void test715() {
10147
		final Map options = DefaultCodeFormatterConstants.getEclipseDefaultSettings();
10148
		DefaultCodeFormatterOptions preferences = new DefaultCodeFormatterOptions(options);
10149
		DefaultCodeFormatter codeFormatter = new DefaultCodeFormatter(preferences);
10150
		runTest(codeFormatter, "test715", "A.java", CodeFormatter.K_COMPILATION_UNIT, false);//$NON-NLS-1$ //$NON-NLS-2$
10151
	}
10152
	
10153
	// https://bugs.eclipse.org/bugs/show_bug.cgi?id=102780
10154
	// test preference: never_indent_line_comments_on_first_column
10155
	public void test716() {
10156
		final Map options = DefaultCodeFormatterConstants.getEclipseDefaultSettings();
10157
		DefaultCodeFormatterOptions preferences = new DefaultCodeFormatterOptions(options);
10158
		preferences.never_indent_line_comments_on_first_column = true;
10159
		DefaultCodeFormatter codeFormatter = new DefaultCodeFormatter(preferences);
10160
		runTest(codeFormatter, "test716", "A.java", CodeFormatter.K_COMPILATION_UNIT, false);//$NON-NLS-1$ //$NON-NLS-2$
10161
	}
10162
	
10163
	// https://bugs.eclipse.org/bugs/show_bug.cgi?id=102780
10164
	// test preference: never_indent_block_comments_on_first_column
10165
	public void test717() {
10166
		final Map options = DefaultCodeFormatterConstants.getEclipseDefaultSettings();
10167
		DefaultCodeFormatterOptions preferences = new DefaultCodeFormatterOptions(options);
10168
		preferences.never_indent_block_comments_on_first_column = true;
10169
		DefaultCodeFormatter codeFormatter = new DefaultCodeFormatter(preferences);
10170
		runTest(codeFormatter, "test717", "A.java", CodeFormatter.K_COMPILATION_UNIT, false);//$NON-NLS-1$ //$NON-NLS-2$
10171
	}
10172
	
10173
	// https://bugs.eclipse.org/bugs/show_bug.cgi?id=102780
10174
	// test preference: comment_insert_empty_line_before_root_tags
10175
	public void test718() {
10176
		final Map options = DefaultCodeFormatterConstants.getEclipseDefaultSettings();
10177
		DefaultCodeFormatterOptions preferences = new DefaultCodeFormatterOptions(options);
10178
		preferences.comment_insert_empty_line_before_root_tags = false;
10179
		DefaultCodeFormatter codeFormatter = new DefaultCodeFormatter(preferences);
10180
		runTest(codeFormatter, "test718", "A.java", CodeFormatter.K_COMPILATION_UNIT, false);//$NON-NLS-1$ //$NON-NLS-2$
10181
	}
10116
}
10182
}
(-)workspace/Formatter/test720/A_in.java (+15 lines)
Added Link Here
1
public class Test {
2
// Test line comment
3
	int i;
4
	/*
5
	 * test block comment
6
	 */
7
	int k;
8
9
/**
10
 * Test javadoc comment
11
 * @param args given arguments
12
 */
13
	public static void main(String[] args) {
14
	}
15
}
(-)workspace/Formatter/test719/A_out.java (+15 lines)
Added Link Here
1
public class Test {
2
	// Test line comment
3
	int i;
4
	/*
5
	 * test block comment
6
	 */
7
	int k;
8
9
	/**
10
	 * Test javadoc comment
11
	 * @param args given arguments
12
	 */
13
	public static void main(String[] args) {
14
	}
15
}
(-)workspace/Formatter/test713/X_out.java (+10 lines)
Added Link Here
1
package p;
2
3
public class X {
4
5
	/**
6
	 * @deprecated Use {@link B#FOO} instead
7
	 */
8
	private static final String FOO = B.FOO;
9
10
}
(-)workspace/Formatter/test716/A_in.java (+15 lines)
Added Link Here
1
public class Test {
2
// Test line comment
3
	int i;
4
	/*
5
	 * test block comment
6
	 */
7
	int k;
8
9
/**
10
 * Test javadoc comment
11
 * @param args given arguments
12
 */
13
	public static void main(String[] args) {
14
	}
15
}
(-)workspace/Formatter/test714/X_out.java (+89 lines)
Added Link Here
1
/**
2
 * An example for comment formatting. This example is meant to illustrate the various possibilities offered by <i>Eclipse</i> in order to format comments.
3
 */
4
5
package pkg1;
6
7
/**
8
 * This is the comment for the example interface.
9
 */
10
public class X {
11
12
	int myInt
13
	// This is a long comment that should be split in multiple line comments in
14
	// case the line comment formatting is enabled
15
	= 1;
16
17
	/*
18
	 * 
19
	 * block comment formatting
20
	 * 
21
	 * These possibilities include: <ul><li>Formatting of header comments.</li><li>Formatting
22
	 * of Javadoc tags</li></ul>
23
	 * 
24
	 * 
25
	 * 
26
	 */
27
	String myString;
28
	/**
29
	 * 
30
	 * @see {@link X#foo(int, int)}
31
	 */
32
33
	/**
34
	 * @deprecated
35
	 */
36
	public void foo() {
37
38
	}
39
40
	/**
41
	 * The following is some sample code which illustrates source formatting
42
	 * within javadoc comments:
43
	 * 
44
	 * <pre>
45
	 * public class Example {
46
	 * 	final int a = 1;
47
	 * 	final boolean b = true;
48
	 * }
49
	 * </pre>
50
	 * 
51
	 * Descriptions of parameters and return values are best appended at end of
52
	 * the javadoc comment.
53
	 * 
54
	 * @param aParam
55
	 *            The first parameter. For an optimum result, this should be an
56
	 *            odd number between 0 and 100.
57
	 * @param bParam
58
	 *            The second parameter.
59
	 * 
60
	 * between 10 and 20
61
	 * @return The result of the foo operation, usually within 0 and 1000.
62
	 */
63
	public int foo(int aParam, int bParam) {
64
		return this.myInt;
65
	}
66
67
	/**
68
	 * 
69
	 * The following is some sample code which illustrates source formatting
70
	 * within javadoc comments:
71
	 * 
72
	 * 
73
	 * <pre>
74
	 * public class Example {
75
	 * 	final int a = 1;
76
	 * 	final boolean b = true;
77
	 * }
78
	 * </pre>
79
	 * 
80
	 * 
81
	 * Descriptions of parameters and return values are best appended at end of
82
	 * the javadoc comment.
83
	 * 
84
	 * 
85
	 */
86
	public void bar() {
87
88
	}
89
}
(-)workspace/Formatter/test720/A_out.java (+15 lines)
Added Link Here
1
public class Test {
2
	// Test line comment
3
	int i;
4
	/*
5
	 * test block comment
6
	 */
7
	int k;
8
9
	/**
10
	 * Test javadoc comment
11
	 * @param args given arguments
12
	 */
13
	public static void main(String[] args) {
14
	}
15
}
(-)workspace/Formatter/test718/A_out.java (+15 lines)
Added Link Here
1
public class Test {
2
	// Test line comment
3
	int i;
4
	/*
5
	 * test block comment
6
	 */
7
	int k;
8
9
	/**
10
	 * Test javadoc comment
11
	 * @param args given arguments
12
	 */
13
	public static void main(String[] args) {
14
	}
15
}
(-)workspace/Formatter/test713/X_in.java (+10 lines)
Added Link Here
1
package p;
2
3
public class X {
4
	
5
	/**
6
	 * @deprecated Use {@link B#FOO} instead
7
	 */
8
	         private static final String FOO= B.FOO;
9
10
}
(-)workspace/Formatter/test718/A_in.java (+15 lines)
Added Link Here
1
public class Test {
2
// Test line comment
3
	int i;
4
	/*
5
	 * test block comment
6
	 */
7
	int k;
8
9
/**
10
 * Test javadoc comment
11
 * @param args given arguments
12
 */
13
	public static void main(String[] args) {
14
	}
15
}
(-)workspace/Formatter/test716/A_out.java (+16 lines)
Added Link Here
1
public class Test {
2
// Test line comment
3
	int i;
4
	/*
5
	 * test block comment
6
	 */
7
	int k;
8
9
	/**
10
	 * Test javadoc comment
11
	 * 
12
	 * @param args given arguments
13
	 */
14
	public static void main(String[] args) {
15
	}
16
}
(-)workspace/Formatter/test715/A_out.java (+16 lines)
Added Link Here
1
public class Test {
2
	// Test line comment
3
	int i;
4
	/*
5
	 * test block comment
6
	 */
7
	int k;
8
9
	/**
10
	 * Test javadoc comment
11
	 * 
12
	 * @param args given arguments
13
	 */
14
	public static void main(String[] args) {
15
	}
16
}
(-)workspace/Formatter/test717/A_out.java (+16 lines)
Added Link Here
1
public class Test {
2
	// Test line comment
3
	int i;
4
/*
5
 * test block comment
6
 */
7
	int k;
8
9
	/**
10
	 * Test javadoc comment
11
	 * 
12
	 * @param args given arguments
13
	 */
14
	public static void main(String[] args) {
15
	}
16
}
(-)workspace/Formatter/test719/A_in.java (+15 lines)
Added Link Here
1
public class Test {
2
// Test line comment
3
	int i;
4
	/*
5
	 * test block comment
6
	 */
7
	int k;
8
9
/**
10
 * Test javadoc comment
11
 * @param args given arguments
12
 */
13
	public static void main(String[] args) {
14
	}
15
}
(-)workspace/Formatter/test717/A_in.java (+15 lines)
Added Link Here
1
public class Test {
2
// Test line comment
3
	int i;
4
/*
5
 * test block comment
6
 */
7
	int k;
8
9
/**
10
 * Test javadoc comment
11
 * @param args given arguments
12
 */
13
	public static void main(String[] args) {
14
	}
15
}
(-)workspace/Formatter/test714/X_in.java (+68 lines)
Added Link Here
1
/**
2
* An example for comment formatting. This example is meant to illustrate the various possibilities offered by <i>Eclipse</i> in order to format comments.
3
*/
4
5
6
package pkg1;
7
/**
8
 * This is the comment for the example interface.
9
 */
10
public class X {
11
12
	int myInt
13
// This is a long comment that should be split in multiple line comments in case the line comment formatting is enabled
14
	= 1;
15
	
16
/*
17
*
18
* block comment formatting
19
*
20
* These possibilities include:
21
* <ul><li>Formatting of header comments.</li><li>Formatting of Javadoc tags</li></ul>
22
* 
23
* 
24
* 
25
*/
26
	String myString;
27
/**
28
 *
29
*@see                     	{@link X#foo(int, int)}
30
*/
31
32
/**
33
*@deprecated 
34
*/
35
	public void foo() {
36
		
37
	}
38
	
39
/**
40
*The following is some sample code which illustrates source formatting within javadoc comments:
41
*<pre>public class Example {final int a= 1;final boolean b= true;}</pre>
42
*Descriptions of parameters and return values are best appended at end of the javadoc comment.
43
*@param aParam The first parameter. For an optimum result, this should be an odd number
44
*between 0 and 100.
45
*@param bParam The second parameter.
46
*
47
*between 10 and 20
48
*@return The result of the foo operation, usually within 0 and 1000.
49
*/public int foo(int aParam, int bParam){
50
	return this.myInt;
51
}
52
53
/**
54
* 
55
*The following is some sample code which illustrates source formatting within javadoc comments:
56
*
57
*
58
*<pre>public class Example {final int a= 1;final boolean b= true;}</pre>
59
*
60
*
61
*Descriptions of parameters and return values are best appended at end of the javadoc comment.
62
* 
63
* 
64
 */
65
public	void	bar() {
66
	
67
}
68
}
(-)workspace/Formatter/test715/A_in.java (+15 lines)
Added Link Here
1
public class Test {
2
// Test line comment
3
	int i;
4
	/*
5
	 * test block comment
6
	 */
7
	int k;
8
9
/**
10
 * Test javadoc comment
11
 * @param args given arguments
12
 */
13
	public static void main(String[] args) {
14
	}
15
}
(-)formatter/org/eclipse/jdt/internal/formatter/Scribe.java (-42 / +509 lines)
Lines 26-33 Link Here
26
import org.eclipse.jdt.internal.core.util.RecordedParsingInformation;
26
import org.eclipse.jdt.internal.core.util.RecordedParsingInformation;
27
import org.eclipse.jdt.internal.formatter.align.Alignment;
27
import org.eclipse.jdt.internal.formatter.align.Alignment;
28
import org.eclipse.jdt.internal.formatter.align.AlignmentException;
28
import org.eclipse.jdt.internal.formatter.align.AlignmentException;
29
import org.eclipse.jdt.internal.formatter.comment.CommentFormatterUtil;
30
import org.eclipse.jdt.internal.formatter.comment.IJavaDocTagConstants;
29
import org.eclipse.jface.text.IRegion;
31
import org.eclipse.jface.text.IRegion;
30
import org.eclipse.jface.text.Region;
32
import org.eclipse.jface.text.Region;
33
import org.eclipse.text.edits.MalformedTreeException;
31
import org.eclipse.text.edits.MultiTextEdit;
34
import org.eclipse.text.edits.MultiTextEdit;
32
import org.eclipse.text.edits.ReplaceEdit;
35
import org.eclipse.text.edits.ReplaceEdit;
33
import org.eclipse.text.edits.TextEdit;
36
import org.eclipse.text.edits.TextEdit;
Lines 81-86 Link Here
81
	
84
	
82
	private final boolean formatJavadocComment;
85
	private final boolean formatJavadocComment;
83
	private final boolean formatBlockComment;
86
	private final boolean formatBlockComment;
87
	private FormatterCommentParser formatterCommentParser; // specialized parser to format comments
84
	
88
	
85
	Scribe(CodeFormatterVisitor formatter, long sourceLevel, IRegion[] regions, CodeSnippetParsingUtil codeSnippetParsingUtil) {
89
	Scribe(CodeFormatterVisitor formatter, long sourceLevel, IRegion[] regions, CodeSnippetParsingUtil codeSnippetParsingUtil) {
86
		this.scanner = new Scanner(true, true, false/*nls*/, sourceLevel/*sourceLevel*/, null/*taskTags*/, null/*taskPriorities*/, true/*taskCaseSensitive*/);
90
		this.scanner = new Scanner(true, true, false/*nls*/, sourceLevel/*sourceLevel*/, null/*taskTags*/, null/*taskPriorities*/, true/*taskCaseSensitive*/);
Lines 438-443 Link Here
438
		this.memberAlignment = current.enclosing;
442
		this.memberAlignment = current.enclosing;
439
	}
443
	}
440
	
444
	
445
	private void formatJavadocTag(FormatJavadocTag aTag) {
446
		if( aTag == null) return;
447
		
448
		int lastEnd = aTag.startPosition;
449
		boolean isTagParam = false, isTextSection = false; // handle formatting preferences
450
        
451
		// tag name
452
		String tagName = aTag.tagName;
453
		if (tagName != null) {
454
			isTagParam = IJavaDocTagConstants.PARAM_TAG.equalsIgnoreCase(tagName);
455
			lastEnd += tagName.length();			
456
			this.scanner.resetTo(lastEnd, this.scannerEndPosition - 1);
457
		} else {
458
			isTextSection = true;
459
		}
460
		
461
		// reference
462
		FormatJavadocReference reference = aTag.reference;
463
		if (reference != null) {
464
			lastEnd = reference.endPosition;
465
			String refName = reference.name;
466
			if (refName != null) {
467
				int start = reference.startPosition;
468
				if (start - lastEnd > 2) { // trim blanks if any
469
					addReplaceEdit(lastEnd, start - 1, IJavaDocTagConstants.SPACE);
470
				}
471
			}
472
473
			// handle formatting prefs
474
			if (! aTag.inlineTag) {
475
				if (! isTextSection && aTag.nodesPtr > - 1) {
476
					int startLine = Util.getLineNumber(aTag.startPosition, this.lineEnds, 0, this.line);
477
					boolean multiLines = Util.getLineNumber(aTag.endPosition, this.lineEnds, 0, this.line) - startLine > 0;
478
					if (multiLines) {
479
						if (isTagParam) {
480
							// pref: new line after param tag
481
							if (this.formatter.preferences.comment_insert_new_line_for_parameter) {
482
								printNewLine(this.scanner.currentPosition + 1);
483
							}
484
							// pref: indent description after @param tags
485
							if (this.formatter.preferences.comment_indent_parameter_description) {
486
								this.indent();
487
							}
488
						}
489
						// pref: indent javadoc tags
490
						if (this.formatter.preferences.comment_indent_root_tags) {
491
							this.indent();
492
						}
493
					}
494
				}
495
			}
496
			this.scanner.resetTo(lastEnd, this.scannerEndPosition - 1);
497
		}
498
				
499
		// tag section iterate through the tags composing this Javadoc
500
		for (int i = 0, max = aTag.nodesPtr; i <= max ; i++) {
501
			FormatJavadocNode aNode = aTag.nodes[i];
502
			this.scanner.resetTo(aNode.startPosition, this.scannerEndPosition - 1);
503
			 // trim blanks if any, we we're one the same line
504
			if (aNode.startPosition - lastEnd > 2 &&
505
					this.line == Util.getLineNumber(aNode.startPosition, this.lineEnds, 0, this.line)) {
506
				addReplaceEdit(lastEnd + 1, aNode.startPosition - 1, IJavaDocTagConstants.SPACE);
507
			}
508
			if (aNode.isTag()) { // format inline tag
509
				this.formatJavadocTag((FormatJavadocTag) aNode);
510
			} else { // format text
511
				this.formatText((FormatJavadocText) aNode, true);				
512
			}
513
			lastEnd = aNode.endPosition;
514
		}
515
		this.scanner.resetTo(aTag.endPosition, this.scannerEndPosition - 1);
516
	}
517
	
518
	/*
519
	 * formats the first section of a javadoc comment
520
	 */
521
	private void formatJavadocHeader() {
522
		FormatJavadoc javadoc = (FormatJavadoc) formatterCommentParser.docComment;		
523
		FormatJavadocTag firstTag = javadoc.tags[0];
524
		FormatJavadocNode firstNode = firstTag.nodes[0];
525
		if (firstNode.isText()) {
526
			formatText((FormatJavadocText)firstNode, false);
527
		}
528
		this.scanner.resetTo(firstTag.endPosition + 1, this.scannerEndPosition - 1);
529
	}
530
	
531
	/*
532
	 * 
533
	 */
534
	private void formatText(FormatJavadocText text, boolean insideTag) {
535
		int sectionStart, sectionLength;
536
		int nextLine = 0, previousLine = -1, lineCount = 0, lastEnd = 0; // counters to handle the text formatting
537
		
538
		// iterate through text sections
539
		for (int j = 0, jMax = text.textSeparatorsPtr; j <= jMax ; j++) {
540
			sectionStart = (int) (text.textSeparators[j] >>> 32);
541
			sectionLength = (int) (text.textSeparators[j] & 0x00000000FFFFFFFFL);
542
			nextLine = Util.getLineNumber(sectionStart, this.lineEnds, 0, this.line);
543
			lineCount = nextLine - previousLine;
544
			
545
			// empty lines may have been skipped at parsing time, fill the gap if needed
546
			if (previousLine != -1 && lineCount > 1) {
547
				this.formatText(lastEnd + 1, sectionStart - lastEnd, insideTag);
548
			}
549
			// format the text section
550
			formatText(sectionStart, sectionLength, insideTag);
551
			lastEnd = sectionStart + sectionLength;
552
			previousLine = nextLine;			
553
		}
554
	}
555
	
556
	private void formatText(int startPosition, int length, boolean insideTag) {
557
		// init scanner and variables
558
		int endPosition = startPosition + length;		
559
		this.scanner.resetTo(startPosition, endPosition - 1);
560
		int currentCharacter;
561
		boolean isNewLine = false;
562
		int start = startPosition;
563
		int nextCharacterStart = startPosition;
564
		int previousStart = startPosition;
565
		boolean onFirstColumn = isOnFirstColumn(start);
566
		
567
		// handle indentation
568
		if (! insideTag && this.indentationLevel != 0) {
569
			printIndentationIfNecessary();
570
		}
571
		
572
		if (this.pendingSpace) {
573
			this.addInsertEdit(startPosition, " "); //$NON-NLS-1$
574
		}
575
		this.needSpace = false;
576
		this.pendingSpace = false;
577
578
		int currentCommentOffset = onFirstColumn ? 0 : getCurrentCommentOffset(start);
579
580
		while (nextCharacterStart <= endPosition && (currentCharacter = this.scanner.getNextChar()) != -1) {
581
			nextCharacterStart = this.scanner.currentPosition;
582
			
583
			switch(currentCharacter) {
584
				case '\r' :
585
					start = previousStart;
586
					isNewLine = true;
587
					if (this.scanner.getNextChar('\n')) {
588
						currentCharacter = '\n';
589
						nextCharacterStart = this.scanner.currentPosition;
590
					}
591
					break;
592
				case '\n' :
593
					start = previousStart;
594
					isNewLine = true;
595
					nextCharacterStart = this.scanner.currentPosition;
596
					break;
597
				default:
598
					if (isNewLine) {
599
						this.column = 1;
600
						this.line++;
601
						isNewLine = false;
602
						
603
						StringBuffer buffer = new StringBuffer();
604
						if (onFirstColumn) {
605
							// simply insert indentation if necessary
606
							buffer.append(this.lineSeparator);
607
							printIndentationIfNecessary(buffer);
608
							if (ScannerHelper.isWhitespace((char) currentCharacter)) {
609
								int previousStartPosition = this.scanner.currentPosition;
610
								while(currentCharacter != -1 && currentCharacter != '\r' && currentCharacter != '\n' && ScannerHelper.isWhitespace((char) currentCharacter)) {
611
									previousStart = nextCharacterStart;
612
									previousStartPosition = this.scanner.currentPosition;
613
									currentCharacter = this.scanner.getNextChar();
614
									nextCharacterStart = this.scanner.currentPosition;
615
								}
616
								if (currentCharacter == '\r' || currentCharacter == '\n') {
617
									nextCharacterStart = previousStartPosition;
618
								}
619
							}
620
							if (currentCharacter != '\r' && currentCharacter != '\n') {
621
								buffer.append(' ');
622
							}
623
						} else {
624
							if (ScannerHelper.isWhitespace((char) currentCharacter)) {
625
								int previousStartPosition = this.scanner.currentPosition;
626
								int count = 0;
627
								loop: while(currentCharacter != -1 && currentCharacter != '\r' && currentCharacter != '\n' && ScannerHelper.isWhitespace((char) currentCharacter)) {
628
									if (count >= currentCommentOffset) {
629
										break loop;
630
									}
631
									previousStart = nextCharacterStart;
632
									previousStartPosition = this.scanner.currentPosition;
633
									switch(currentCharacter) {
634
										case '\t' :
635
											count += this.tabLength;
636
											break;
637
										default :
638
											count ++;
639
									}
640
									currentCharacter = this.scanner.getNextChar();
641
									nextCharacterStart = this.scanner.currentPosition;
642
								}
643
								if (currentCharacter == '\r' || currentCharacter == '\n') {
644
									nextCharacterStart = previousStartPosition;
645
								}
646
							}
647
							buffer.append(this.lineSeparator);
648
							printIndentationIfNecessary(buffer);
649
							int previousStartTemp = previousStart;
650
							int nextCharacterStartTemp = nextCharacterStart;
651
							while(currentCharacter != -1 && currentCharacter != '\r' && currentCharacter != '\n' && ScannerHelper.isWhitespace((char) currentCharacter)) {
652
								previousStart = nextCharacterStart;
653
								currentCharacter = this.scanner.getNextChar();
654
								nextCharacterStart = this.scanner.currentPosition;
655
							}
656
							if (currentCharacter == '*') {
657
								buffer.append(' ');
658
							} else {
659
								previousStart = previousStartTemp;
660
								nextCharacterStart = nextCharacterStartTemp;
661
							}
662
							this.scanner.currentPosition = nextCharacterStart;
663
							}
664
						addReplaceEdit(start, previousStart - 1, String.valueOf(buffer));
665
					} else {
666
						this.column += (nextCharacterStart - previousStart);
667
					}
668
			}
669
			previousStart = nextCharacterStart;
670
			this.scanner.currentPosition = nextCharacterStart;
671
		}
672
		this.lastNumberOfNewLines = 0;
673
		needSpace = false;
674
		this.scanner.resetTo(endPosition, this.scannerEndPosition - 1);
675
	}
676
	
441
	public Alignment getAlignment(String name){
677
	public Alignment getAlignment(String name){
442
		if (this.currentAlignment != null) {
678
		if (this.currentAlignment != null) {
443
			return this.currentAlignment.getAlignment(name);
679
			return this.currentAlignment.getAlignment(name);
Lines 657-666 Link Here
657
		} else {
893
		} else {
658
			edit = new MultiTextEdit(textRegionStart, length - 1);
894
			edit = new MultiTextEdit(textRegionStart, length - 1);
659
		}
895
		}
896
		
660
		for (int i= 0, max = this.editsIndex; i < max; i++) {
897
		for (int i= 0, max = this.editsIndex; i < max; i++) {
661
			OptimizedReplaceEdit currentEdit = edits[i];
898
			OptimizedReplaceEdit currentEdit = edits[i];
662
			if (isValidEdit(currentEdit)) {
899
			if (isValidEdit(currentEdit)) {
663
				edit.addChild(new ReplaceEdit(currentEdit.offset, currentEdit.length, currentEdit.replacement));
900
				try {
901
					edit.addChild(new ReplaceEdit(currentEdit.offset, currentEdit.length, currentEdit.replacement));
902
				}
903
				catch (MalformedTreeException ex) {
904
					// log exception in case of error
905
					CommentFormatterUtil.log(ex);
906
				}
664
			}
907
			}
665
		}
908
		}
666
		this.edits = null;
909
		this.edits = null;
Lines 736-741 Link Here
736
		this.scannerEndPosition = compilationUnitSource.length;
979
		this.scannerEndPosition = compilationUnitSource.length;
737
		this.scanner.resetTo(0, this.scannerEndPosition - 1);
980
		this.scanner.resetTo(0, this.scannerEndPosition - 1);
738
		this.edits = new OptimizedReplaceEdit[INITIAL_SIZE];
981
		this.edits = new OptimizedReplaceEdit[INITIAL_SIZE];
982
		initFormatterCommentParser();
983
	}
984
	
985
	private void initFormatterCommentParser() {
986
		this.formatterCommentParser = new FormatterCommentParser(null);
987
		this.formatterCommentParser.scanner.setSource(this.scanner.source);
988
		this.formatterCommentParser.source = this.scanner.source;
989
		this.formatterCommentParser.scanner.lineEnds = this.scanner.lineEnds;
739
	}
990
	}
740
	
991
	
741
	/**
992
	/**
Lines 936-943 Link Here
936
		column += s.length;
1187
		column += s.length;
937
		needSpace = true;
1188
		needSpace = true;
938
	}
1189
	}
1190
	
1191
	/*
1192
	 * print and format a block comment
1193
	 */
1194
	private void printBlockComment() {
1195
		int currentTokenStartPosition = this.scanner.getCurrentTokenStartPosition();
1196
		int currentTokenEndPosition = this.scanner.getCurrentTokenEndPosition() + 1;
1197
		
1198
		this.scanner.resetTo(currentTokenStartPosition, currentTokenEndPosition - 1);
1199
		int currentCharacter;
1200
		boolean isNewLine = false;
1201
		int start = currentTokenStartPosition;
1202
		int nextCharacterStart = currentTokenStartPosition;
1203
		int previousStart = currentTokenStartPosition;
1204
		boolean onFirstColumn = isOnFirstColumn(start);
939
1205
940
	private void printBlockComment(char[] s, boolean isJavadoc) {
1206
		boolean indentComment = false;
1207
		if (this.indentationLevel != 0) {
1208
			if (!this.formatter.preferences.never_indent_block_comments_on_first_column
1209
					|| !onFirstColumn) {
1210
				indentComment = true;
1211
				printIndentationIfNecessary();
1212
			}
1213
		}
1214
		if (this.pendingSpace) {
1215
			this.addInsertEdit(currentTokenStartPosition, " "); //$NON-NLS-1$
1216
		}
1217
		this.needSpace = false;
1218
		this.pendingSpace = false;
1219
1220
		int currentCommentOffset = onFirstColumn ? 0 : getCurrentCommentOffset(start);
1221
1222
		while (nextCharacterStart <= currentTokenEndPosition && (currentCharacter = this.scanner.getNextChar()) != -1) {
1223
			nextCharacterStart = this.scanner.currentPosition;
1224
1225
			switch(currentCharacter) {
1226
				case '\r' :
1227
					start = previousStart;
1228
					isNewLine = true;
1229
					if (this.scanner.getNextChar('\n')) {
1230
						currentCharacter = '\n';
1231
						nextCharacterStart = this.scanner.currentPosition;
1232
					}
1233
					break;
1234
				case '\n' :
1235
					start = previousStart;
1236
					isNewLine = true;
1237
					nextCharacterStart = this.scanner.currentPosition;
1238
					break;
1239
				default:
1240
					if (isNewLine) {
1241
						this.column = 1;
1242
						this.line++;
1243
						isNewLine = false;
1244
						
1245
						StringBuffer buffer = new StringBuffer();
1246
						if (onFirstColumn) {
1247
							// simply insert indentation if necessary
1248
							buffer.append(this.lineSeparator);
1249
							if (indentComment) {
1250
								printIndentationIfNecessary(buffer);
1251
							}
1252
							if (ScannerHelper.isWhitespace((char) currentCharacter)) {
1253
								int previousStartPosition = this.scanner.currentPosition;
1254
								while(currentCharacter != -1 && currentCharacter != '\r' && currentCharacter != '\n' && ScannerHelper.isWhitespace((char) currentCharacter)) {
1255
									previousStart = nextCharacterStart;
1256
									previousStartPosition = this.scanner.currentPosition;
1257
									currentCharacter = this.scanner.getNextChar();
1258
									nextCharacterStart = this.scanner.currentPosition;
1259
								}
1260
								if (currentCharacter == '\r' || currentCharacter == '\n') {
1261
									nextCharacterStart = previousStartPosition;
1262
								}
1263
							}
1264
							if (currentCharacter != '\r' && currentCharacter != '\n') {
1265
								buffer.append(' ');
1266
							}							
1267
						} else {
1268
							if (ScannerHelper.isWhitespace((char) currentCharacter)) {
1269
								int previousStartPosition = this.scanner.currentPosition;
1270
								int count = 0;
1271
								loop: while(currentCharacter != -1 && currentCharacter != '\r' && currentCharacter != '\n' && ScannerHelper.isWhitespace((char) currentCharacter)) {
1272
									if (count >= currentCommentOffset) {
1273
										break loop;
1274
									}
1275
									previousStart = nextCharacterStart;
1276
									previousStartPosition = this.scanner.currentPosition;
1277
									switch(currentCharacter) {
1278
										case '\t' :
1279
											count += this.tabLength;
1280
											break;
1281
										default :
1282
											count ++;
1283
									}
1284
									currentCharacter = this.scanner.getNextChar();
1285
									nextCharacterStart = this.scanner.currentPosition;
1286
								}
1287
								if (currentCharacter == '\r' || currentCharacter == '\n') {
1288
									nextCharacterStart = previousStartPosition;
1289
								}
1290
							}
1291
							buffer.append(this.lineSeparator);
1292
							if (indentComment) {
1293
								printIndentationIfNecessary(buffer);
1294
							}
1295
							int previousStartTemp = previousStart;
1296
							int nextCharacterStartTemp = nextCharacterStart;
1297
							while(currentCharacter != -1 && currentCharacter != '\r' && currentCharacter != '\n' && ScannerHelper.isWhitespace((char) currentCharacter)) {
1298
								previousStart = nextCharacterStart;
1299
								currentCharacter = this.scanner.getNextChar();
1300
								nextCharacterStart = this.scanner.currentPosition;
1301
							}
1302
							if (currentCharacter == '*') {
1303
								buffer.append(' ');
1304
							} else {
1305
								previousStart = previousStartTemp;
1306
								nextCharacterStart = nextCharacterStartTemp;
1307
							}
1308
							this.scanner.currentPosition = nextCharacterStart;
1309
						}
1310
						addReplaceEdit(start, previousStart - 1, String.valueOf(buffer));
1311
					} else {
1312
						this.column += (nextCharacterStart - previousStart);
1313
					}
1314
			}
1315
			previousStart = nextCharacterStart;
1316
			this.scanner.currentPosition = nextCharacterStart;
1317
		}
1318
		this.lastNumberOfNewLines = 0;
1319
		needSpace = false;
1320
		this.scanner.resetTo(currentTokenEndPosition, this.scannerEndPosition - 1);
1321
	}
1322
	
1323
	/*
1324
	 * Common method to format javadoc or block comments without formatting
1325
	 */
1326
	private void printCommentWithoutFormatting() {
941
		int currentTokenStartPosition = this.scanner.getCurrentTokenStartPosition();
1327
		int currentTokenStartPosition = this.scanner.getCurrentTokenStartPosition();
942
		int currentTokenEndPosition = this.scanner.getCurrentTokenEndPosition() + 1;
1328
		int currentTokenEndPosition = this.scanner.getCurrentTokenEndPosition() + 1;
943
		
1329
		
Lines 951-958 Link Here
951
1337
952
		boolean indentComment = false;
1338
		boolean indentComment = false;
953
		if (this.indentationLevel != 0) {
1339
		if (this.indentationLevel != 0) {
954
			if (isJavadoc
1340
			if (!this.formatter.preferences.never_indent_block_comments_on_first_column
955
					|| !this.formatter.preferences.never_indent_block_comments_on_first_column
956
					|| !onFirstColumn) {
1341
					|| !onFirstColumn) {
957
				indentComment = true;
1342
				indentComment = true;
958
				printIndentationIfNecessary();
1343
				printIndentationIfNecessary();
Lines 965-971 Link Here
965
		this.pendingSpace = false;
1350
		this.pendingSpace = false;
966
1351
967
		int currentCommentOffset = onFirstColumn ? 0 : getCurrentCommentOffset(start);
1352
		int currentCommentOffset = onFirstColumn ? 0 : getCurrentCommentOffset(start);
968
		boolean formatComment = (isJavadoc && formatJavadocComment) || (!isJavadoc && formatBlockComment);
969
1353
970
		while (nextCharacterStart <= currentTokenEndPosition && (currentCharacter = this.scanner.getNextChar()) != -1) {
1354
		while (nextCharacterStart <= currentTokenEndPosition && (currentCharacter = this.scanner.getNextChar()) != -1) {
971
			nextCharacterStart = this.scanner.currentPosition;
1355
			nextCharacterStart = this.scanner.currentPosition;
Lines 997-1003 Link Here
997
							if (indentComment) {
1381
							if (indentComment) {
998
								printIndentationIfNecessary(buffer);
1382
								printIndentationIfNecessary(buffer);
999
							}
1383
							}
1000
							if (formatComment) {
1384
							if (this.formatBlockComment) {
1001
								if (ScannerHelper.isWhitespace((char) currentCharacter)) {
1385
								if (ScannerHelper.isWhitespace((char) currentCharacter)) {
1002
									int previousStartPosition = this.scanner.currentPosition;
1386
									int previousStartPosition = this.scanner.currentPosition;
1003
									while(currentCharacter != -1 && currentCharacter != '\r' && currentCharacter != '\n' && ScannerHelper.isWhitespace((char) currentCharacter)) {
1387
									while(currentCharacter != -1 && currentCharacter != '\r' && currentCharacter != '\n' && ScannerHelper.isWhitespace((char) currentCharacter)) {
Lines 1042-1048 Link Here
1042
							if (indentComment) {
1426
							if (indentComment) {
1043
								printIndentationIfNecessary(buffer);
1427
								printIndentationIfNecessary(buffer);
1044
							}
1428
							}
1045
							if (formatComment) {
1429
							if (this.formatBlockComment) {
1046
								int previousStartTemp = previousStart;
1430
								int previousStartTemp = previousStart;
1047
								int nextCharacterStartTemp = nextCharacterStart;
1431
								int nextCharacterStartTemp = nextCharacterStart;
1048
								while(currentCharacter != -1 && currentCharacter != '\r' && currentCharacter != '\n' && ScannerHelper.isWhitespace((char) currentCharacter)) {
1432
								while(currentCharacter != -1 && currentCharacter != '\r' && currentCharacter != '\n' && ScannerHelper.isWhitespace((char) currentCharacter)) {
Lines 1070-1078 Link Here
1070
		this.lastNumberOfNewLines = 0;
1454
		this.lastNumberOfNewLines = 0;
1071
		needSpace = false;
1455
		needSpace = false;
1072
		this.scanner.resetTo(currentTokenEndPosition, this.scannerEndPosition - 1);
1456
		this.scanner.resetTo(currentTokenEndPosition, this.scannerEndPosition - 1);
1073
		if (isJavadoc) {
1074
			printNewLine();
1075
		}
1076
	}
1457
	}
1077
	
1458
	
1078
	public void printEndOfCompilationUnit() {
1459
	public void printEndOfCompilationUnit() {
Lines 1132-1138 Link Here
1132
							space();
1513
							space();
1133
						} 
1514
						} 
1134
						hasWhitespace = false;
1515
						hasWhitespace = false;
1135
						this.printLineComment(this.scanner.getRawTokenSource());
1516
						this.printLineComment();
1136
						currentTokenStartPosition = this.scanner.currentPosition;
1517
						currentTokenStartPosition = this.scanner.currentPosition;
1137
						hasLineComment = true;		
1518
						hasLineComment = true;		
1138
						count = 0;
1519
						count = 0;
Lines 1148-1154 Link Here
1148
							space();
1529
							space();
1149
						} 
1530
						} 
1150
						hasWhitespace = false;
1531
						hasWhitespace = false;
1151
						this.printBlockComment(this.scanner.getRawTokenSource(), false);
1532
						this.printBlockComment();
1152
						currentTokenStartPosition = this.scanner.currentPosition;
1533
						currentTokenStartPosition = this.scanner.currentPosition;
1153
						hasLineComment = false;
1534
						hasLineComment = false;
1154
						hasComment = true;
1535
						hasComment = true;
Lines 1165-1171 Link Here
1165
							space();
1546
							space();
1166
						} 
1547
						} 
1167
						hasWhitespace = false;
1548
						hasWhitespace = false;
1168
						this.printBlockComment(this.scanner.getRawTokenSource(), true);
1549
						this.printJavadocComment();
1169
						currentTokenStartPosition = this.scanner.currentPosition;
1550
						currentTokenStartPosition = this.scanner.currentPosition;
1170
						hasLineComment = false;
1551
						hasLineComment = false;
1171
						hasComment = true;
1552
						hasComment = true;
Lines 1190-1196 Link Here
1190
			throw new AbortFormatting(e);
1571
			throw new AbortFormatting(e);
1191
		}
1572
		}
1192
	}
1573
	}
1193
1574
	
1575
	/*
1576
	 * Main method to print and format comments (javadoc, block and single line comments)
1577
	 */
1194
	public void printComment() {
1578
	public void printComment() {
1195
		try {
1579
		try {
1196
			// if we have a space between two tokens we ensure it will be dumped in the formatted string
1580
			// if we have a space between two tokens we ensure it will be dumped in the formatted string
Lines 1232-1237 Link Here
1232
							this.preserveEmptyLines(count, this.scanner.getCurrentTokenStartPosition());
1616
							this.preserveEmptyLines(count, this.scanner.getCurrentTokenStartPosition());
1233
							addDeleteEdit(this.scanner.getCurrentTokenStartPosition(), this.scanner.getCurrentTokenEndPosition());
1617
							addDeleteEdit(this.scanner.getCurrentTokenStartPosition(), this.scanner.getCurrentTokenEndPosition());
1234
						} else if (count != 0 && this.formatter.preferences.number_of_empty_lines_to_preserve != 0) {
1618
						} else if (count != 0 && this.formatter.preferences.number_of_empty_lines_to_preserve != 0) {
1619
							// https://bugs.eclipse.org/bugs/show_bug.cgi?id=184398
1620
							if (currentTokenStartPosition == 0 && count > 1 && (count * this.lineSeparator.length() < this.scanner.source.length)) {
1621
								count = count - this.lineSeparator.length() + 1;
1622
							}
1235
							addReplaceEdit(this.scanner.getCurrentTokenStartPosition(), this.scanner.getCurrentTokenEndPosition(), this.getPreserveEmptyLines(count - 1));
1623
							addReplaceEdit(this.scanner.getCurrentTokenStartPosition(), this.scanner.getCurrentTokenEndPosition(), this.getPreserveEmptyLines(count - 1));
1236
						} else {
1624
						} else {
1237
							addDeleteEdit(this.scanner.getCurrentTokenStartPosition(), this.scanner.getCurrentTokenEndPosition());
1625
							addDeleteEdit(this.scanner.getCurrentTokenStartPosition(), this.scanner.getCurrentTokenEndPosition());
Lines 1249-1255 Link Here
1249
							space();
1637
							space();
1250
						} 
1638
						} 
1251
						hasWhitespace = false;
1639
						hasWhitespace = false;
1252
						this.printLineComment(this.scanner.getRawTokenSource());
1640
						this.printLineComment();
1253
						currentTokenStartPosition = this.scanner.currentPosition;
1641
						currentTokenStartPosition = this.scanner.currentPosition;
1254
						hasLineComment = true;		
1642
						hasLineComment = true;		
1255
						count = 0;
1643
						count = 0;
Lines 1265-1271 Link Here
1265
							space();
1653
							space();
1266
						} 
1654
						} 
1267
						hasWhitespace = false;
1655
						hasWhitespace = false;
1268
						this.printBlockComment(this.scanner.getRawTokenSource(), false);
1656
						if (this.formatBlockComment) {
1657
							this.printBlockComment();
1658
						} else {
1659
							this.printCommentWithoutFormatting();
1660
						}
1269
						currentTokenStartPosition = this.scanner.currentPosition;
1661
						currentTokenStartPosition = this.scanner.currentPosition;
1270
						hasLineComment = false;
1662
						hasLineComment = false;
1271
						hasComment = true;
1663
						hasComment = true;
Lines 1282-1288 Link Here
1282
							space();
1674
							space();
1283
						} 
1675
						} 
1284
						hasWhitespace = false;
1676
						hasWhitespace = false;
1285
						this.printBlockComment(this.scanner.getRawTokenSource(), true);
1677
						if (this.formatJavadocComment) {
1678
							this.printJavadocComment();
1679
						} else {
1680
							this.printCommentWithoutFormatting();
1681
						}
1286
						currentTokenStartPosition = this.scanner.currentPosition;
1682
						currentTokenStartPosition = this.scanner.currentPosition;
1287
						hasLineComment = false;
1683
						hasLineComment = false;
1288
						hasComment = true;
1684
						hasComment = true;
Lines 1299-1305 Link Here
1299
		}
1695
		}
1300
	}
1696
	}
1301
	
1697
	
1302
	private void printLineComment(char[] s) {
1698
	/*
1699
	 * Print and formats a single line comment
1700
	 */
1701
	private void printLineComment() {
1303
		int currentTokenStartPosition = this.scanner.getCurrentTokenStartPosition();
1702
		int currentTokenStartPosition = this.scanner.getCurrentTokenStartPosition();
1304
		int currentTokenEndPosition = this.scanner.getCurrentTokenEndPosition() + 1;
1703
		int currentTokenEndPosition = this.scanner.getCurrentTokenEndPosition() + 1;
1305
		if (CharOperation.indexOf(Scanner.TAG_PREFIX, this.scanner.source, true, currentTokenStartPosition, currentTokenEndPosition) != -1) {
1704
		if (CharOperation.indexOf(Scanner.TAG_PREFIX, this.scanner.source, true, currentTokenStartPosition, currentTokenEndPosition) != -1) {
Lines 1468-1474 Link Here
1468
				break;
1867
				break;
1469
		}
1868
		}
1470
	}
1869
	}
1870
	
1871
	/*
1872
	 * Print and formats a javadoc comments
1873
	 */
1874
	private void printJavadocComment() {
1875
		int currentTokenStartPosition = this.scanner.getCurrentTokenStartPosition();
1876
		int currentTokenEndPosition = this.scanner.getCurrentTokenEndPosition() + 1;
1877
		
1878
		// handle indentation
1879
		int lastIndentationLevel = this.indentationLevel;
1880
		if (this.indentationLevel != 0) {
1881
			printIndentationIfNecessary();
1882
		}
1883
		
1884
		// handle pending space if any
1885
		if (this.pendingSpace) {
1886
			this.addInsertEdit(currentTokenStartPosition, " "); //$NON-NLS-1$
1887
		}
1888
		this.needSpace = false;
1889
		this.pendingSpace = false;		
1890
		
1891
		// parse the comment on the fly
1892
		if (! this.formatterCommentParser.parse(currentTokenStartPosition, currentTokenEndPosition, this.lineSeparator.length())) {
1893
			// problem occured while parsing the javadoc, early abort formatting
1894
			return;
1895
		}
1896
		
1897
		FormatJavadoc javadoc = (FormatJavadoc) formatterCommentParser.docComment;		
1898
		if (javadoc.tags.length >  0) {
1899
			int max = javadoc.tags.length;
1900
			// check if we're dealing with a single text section
1901
			if (max == 2 && javadoc.tags[1].tagName == null) {
1902
				// we only have the header + a text section --> format as text
1903
				int textStart = javadoc.tags[0].startPosition;
1904
				this.formatText(javadoc.sourceStart, javadoc.sourceEnd - textStart, false);
1905
			} else {// formatting a standard javadoc, composed of a text section + a tag section
1906
				// format the comment header
1907
				formatJavadocHeader();
1908
1909
				// format all other FJTags composing this comment
1910
				int lineOfDescriptionEnd = -1;
1911
				for (int i = 1; i < max ; i++) {
1912
					FormatJavadocTag nextTag = javadoc.tags[i];
1913
					// pref: blank line before javadoc tag section
1914
					if (lineOfDescriptionEnd > -1 && this.formatter.preferences.comment_insert_empty_line_before_root_tags) {
1915
						if (Util.getLineNumber(nextTag.startPosition, this.lineEnds, 0, this.line) - lineOfDescriptionEnd == 1) { // add new line only if needed
1916
							printNewCommentLine(javadoc.tags[i - 1].endPosition);
1917
						}
1918
					}
1919
1920
					// format tag
1921
					this.formatJavadocTag(nextTag);
1471
1922
1923
					if (nextTag.tagName == null) { // description section formatted, remember line number
1924
						lineOfDescriptionEnd = this.line;
1925
					}
1926
				}
1927
			}
1928
		}
1929
		this.lastNumberOfNewLines = 0;
1930
		needSpace = false;
1931
		this.scanner.resetTo(javadoc.sourceEnd, this.scannerEndPosition - 1);
1932
		printNewLine();
1933
		this.indentationLevel = lastIndentationLevel;
1934
	}
1935
	
1472
	public void printModifiers(Annotation[] annotations, ASTVisitor visitor) {
1936
	public void printModifiers(Annotation[] annotations, ASTVisitor visitor) {
1473
		printModifiers(annotations, visitor, ICodeFormatterConstants.ANNOTATION_UNSPECIFIED);
1937
		printModifiers(annotations, visitor, ICodeFormatterConstants.ANNOTATION_UNSPECIFIED);
1474
	}
1938
	}
Lines 1538-1554 Link Here
1538
						currentTokenStartPosition = this.scanner.currentPosition;
2002
						currentTokenStartPosition = this.scanner.currentPosition;
1539
						break;
2003
						break;
1540
					case TerminalTokens.TokenNameCOMMENT_BLOCK :
2004
					case TerminalTokens.TokenNameCOMMENT_BLOCK :
1541
						this.printBlockComment(this.scanner.getRawTokenSource(), false);
2005
						this.printBlockComment();
1542
						currentTokenStartPosition = this.scanner.currentPosition;
2006
						currentTokenStartPosition = this.scanner.currentPosition;
1543
						hasComment = true;
2007
						hasComment = true;
1544
						break;
2008
						break;
1545
					case TerminalTokens.TokenNameCOMMENT_JAVADOC :
2009
					case TerminalTokens.TokenNameCOMMENT_JAVADOC :
1546
						this.printBlockComment(this.scanner.getRawTokenSource(), true);
2010
						this.printJavadocComment();
1547
						currentTokenStartPosition = this.scanner.currentPosition;
2011
						currentTokenStartPosition = this.scanner.currentPosition;
1548
						hasComment = true;
2012
						hasComment = true;
1549
						break;
2013
						break;
1550
					case TerminalTokens.TokenNameCOMMENT_LINE :
2014
					case TerminalTokens.TokenNameCOMMENT_LINE :
1551
						this.printLineComment(this.scanner.getRawTokenSource());
2015
						this.printLineComment();
1552
						currentTokenStartPosition = this.scanner.currentPosition;
2016
						currentTokenStartPosition = this.scanner.currentPosition;
1553
						break;
2017
						break;
1554
					case TerminalTokens.TokenNameWHITESPACE :
2018
					case TerminalTokens.TokenNameWHITESPACE :
Lines 1587-1608 Link Here
1587
		} catch (InvalidInputException e) {
2051
		} catch (InvalidInputException e) {
1588
			throw new AbortFormatting(e);
2052
			throw new AbortFormatting(e);
1589
		}
2053
		}
2054
	}	
2055
2056
	/*
2057
	 * Inserts a new comment (javadoc / block) line at the given position
2058
	 */
2059
	private void printNewCommentLine(int insertPosition) {
2060
		this.column = 0;
2061
		StringBuffer buffer = new StringBuffer();
2062
		buffer.append(this.lineSeparator);
2063
		printIndentationIfNecessary(buffer);
2064
		buffer.append(" * "); //$NON-NLS-1$
2065
		addInsertEdit(insertPosition, buffer.toString());
1590
	}
2066
	}
1591
	
2067
	
1592
	public void printNewLine() {
2068
	public void printNewLine() {
1593
		if (this.nlsTagCounter > 0) {
2069
		this.printNewLine(this.scanner.getCurrentTokenEndPosition() + 1);
1594
			return;
1595
		}
1596
		if (lastNumberOfNewLines >= 1) {
1597
			column = 1; // ensure that the scribe is at the beginning of a new line
1598
			return;
1599
		}
1600
		addInsertEdit(this.scanner.getCurrentTokenEndPosition() + 1, this.lineSeparator);
1601
		line++;
1602
		lastNumberOfNewLines = 1;
1603
		column = 1;
1604
		needSpace = false;
1605
		this.pendingSpace = false;
1606
	}
2070
	}
1607
2071
1608
	public void printNewLine(int insertPosition) {
2072
	public void printNewLine(int insertPosition) {
Lines 1678-1689 Link Here
1678
						currentTokenStartPosition = this.scanner.currentPosition;
2142
						currentTokenStartPosition = this.scanner.currentPosition;
1679
						break;
2143
						break;
1680
					case TerminalTokens.TokenNameCOMMENT_BLOCK :
2144
					case TerminalTokens.TokenNameCOMMENT_BLOCK :
2145
						this.printBlockComment();
2146
						currentTokenStartPosition = this.scanner.currentPosition;
2147
						break;
1681
					case TerminalTokens.TokenNameCOMMENT_JAVADOC :
2148
					case TerminalTokens.TokenNameCOMMENT_JAVADOC :
1682
						this.printBlockComment(this.scanner.getRawTokenSource(), false);
2149
						this.printJavadocComment();
1683
						currentTokenStartPosition = this.scanner.currentPosition;
2150
						currentTokenStartPosition = this.scanner.currentPosition;
1684
						break;
2151
						break;
1685
					case TerminalTokens.TokenNameCOMMENT_LINE :
2152
					case TerminalTokens.TokenNameCOMMENT_LINE :
1686
						this.printLineComment(this.scanner.getRawTokenSource());
2153
						this.printLineComment();
1687
						currentTokenStartPosition = this.scanner.currentPosition;
2154
						currentTokenStartPosition = this.scanner.currentPosition;
1688
						break;
2155
						break;
1689
					case TerminalTokens.TokenNameIdentifier :
2156
					case TerminalTokens.TokenNameIdentifier :
Lines 1722-1732 Link Here
1722
						break;
2189
						break;
1723
					case TerminalTokens.TokenNameCOMMENT_BLOCK :
2190
					case TerminalTokens.TokenNameCOMMENT_BLOCK :
1724
					case TerminalTokens.TokenNameCOMMENT_JAVADOC :
2191
					case TerminalTokens.TokenNameCOMMENT_JAVADOC :
1725
						this.printBlockComment(this.scanner.getRawTokenSource(), false);
2192
						this.printBlockComment();
1726
						currentTokenStartPosition = this.scanner.currentPosition;
2193
						currentTokenStartPosition = this.scanner.currentPosition;
1727
						break;
2194
						break;
1728
					case TerminalTokens.TokenNameCOMMENT_LINE :
2195
					case TerminalTokens.TokenNameCOMMENT_LINE :
1729
						this.printLineComment(this.scanner.getRawTokenSource());
2196
						this.printLineComment();
1730
						currentTokenStartPosition = this.scanner.currentPosition;
2197
						currentTokenStartPosition = this.scanner.currentPosition;
1731
						break;
2198
						break;
1732
					case TerminalTokens.TokenNameIdentifier :
2199
					case TerminalTokens.TokenNameIdentifier :
Lines 1809-1815 Link Here
1809
						if (hasWhitespaces) {
2276
						if (hasWhitespaces) {
1810
							space();
2277
							space();
1811
						}
2278
						}
1812
						this.printLineComment(this.scanner.getRawTokenSource());
2279
						this.printLineComment();
1813
						currentTokenStartPosition = this.scanner.currentPosition;
2280
						currentTokenStartPosition = this.scanner.currentPosition;
1814
						hasLineComment = true;
2281
						hasLineComment = true;
1815
						break;
2282
						break;
Lines 1817-1823 Link Here
1817
						if (hasWhitespaces) {
2284
						if (hasWhitespaces) {
1818
							space();
2285
							space();
1819
						}
2286
						}
1820
						this.printBlockComment(this.scanner.getRawTokenSource(), false);
2287
						this.printBlockComment();
1821
						currentTokenStartPosition = this.scanner.currentPosition;
2288
						currentTokenStartPosition = this.scanner.currentPosition;
1822
						break;
2289
						break;
1823
					default :
2290
					default :
Lines 1882-1888 Link Here
1882
						if (hasWhitespaces) {
2349
						if (hasWhitespaces) {
1883
							space();
2350
							space();
1884
						}
2351
						}
1885
						this.printLineComment(this.scanner.getRawTokenSource());
2352
						this.printLineComment();
1886
						currentTokenStartPosition = this.scanner.currentPosition;
2353
						currentTokenStartPosition = this.scanner.currentPosition;
1887
						hasLineComment = true;
2354
						hasLineComment = true;
1888
						break;
2355
						break;
Lines 1890-1896 Link Here
1890
						if (hasWhitespaces) {
2357
						if (hasWhitespaces) {
1891
							space();
2358
							space();
1892
						}
2359
						}
1893
						this.printBlockComment(this.scanner.getRawTokenSource(), false);
2360
						this.printBlockComment();
1894
						currentTokenStartPosition = this.scanner.currentPosition;
2361
						currentTokenStartPosition = this.scanner.currentPosition;
1895
						hasComment = true;
2362
						hasComment = true;
1896
						break;
2363
						break;
(-)formatter/org/eclipse/jdt/internal/formatter/DefaultCodeFormatter.java (-2 / +3 lines)
Lines 150-156 Link Here
150
			throw new IllegalArgumentException();
150
			throw new IllegalArgumentException();
151
		}
151
		}
152
		switch(kind) {
152
		switch(kind) {
153
			case K_JAVA_DOC :
153
			// bug 102780: disable specific formatting for javadocs
154
			// case K_JAVA_DOC :
154
			case K_MULTI_LINE_COMMENT :
155
			case K_MULTI_LINE_COMMENT :
155
			case K_SINGLE_LINE_COMMENT :
156
			case K_SINGLE_LINE_COMMENT :
156
				this.codeSnippetParsingUtil = new CodeSnippetParsingUtil();
157
				this.codeSnippetParsingUtil = new CodeSnippetParsingUtil();
Lines 178-186 Link Here
178
				return formatExpression(source, indentationLevel, lineSeparator, regions);
179
				return formatExpression(source, indentationLevel, lineSeparator, regions);
179
			case K_STATEMENTS :
180
			case K_STATEMENTS :
180
				return formatStatements(source, indentationLevel, lineSeparator, regions);
181
				return formatStatements(source, indentationLevel, lineSeparator, regions);
182
			case K_JAVA_DOC :
181
			case K_UNKNOWN :
183
			case K_UNKNOWN :
182
				return probeFormatting(source, indentationLevel, lineSeparator, regions);
184
				return probeFormatting(source, indentationLevel, lineSeparator, regions);
183
			case K_JAVA_DOC :
184
			case K_MULTI_LINE_COMMENT :
185
			case K_MULTI_LINE_COMMENT :
185
			case K_SINGLE_LINE_COMMENT :
186
			case K_SINGLE_LINE_COMMENT :
186
				//https://bugs.eclipse.org/bugs/show_bug.cgi?id=204091
187
				//https://bugs.eclipse.org/bugs/show_bug.cgi?id=204091
(-)compiler/org/eclipse/jdt/internal/compiler/parser/JavadocParser.java (-2 / +2 lines)
Lines 28-35 Link Here
28
	
28
	
29
	// bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=51600
29
	// bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=51600
30
	// Store param references for tag with invalid syntax
30
	// Store param references for tag with invalid syntax
31
	private int invalidParamReferencesPtr = -1;
31
	protected int invalidParamReferencesPtr = -1;
32
	private ASTNode[] invalidParamReferencesStack;
32
	protected ASTNode[] invalidParamReferencesStack;
33
33
34
	// bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=153399
34
	// bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=153399
35
	// Store value tag positions
35
	// Store value tag positions
(-)compiler/org/eclipse/jdt/internal/compiler/parser/Parser.java (-2 / +2 lines)
Lines 8846-8852 Link Here
8846
	final boolean checkNLS = this.options.getSeverity(CompilerOptions.NonExternalizedString) != ProblemSeverities.Ignore;
8846
	final boolean checkNLS = this.options.getSeverity(CompilerOptions.NonExternalizedString) != ProblemSeverities.Ignore;
8847
	this.checkExternalizeStrings = checkNLS;
8847
	this.checkExternalizeStrings = checkNLS;
8848
	this.scanner.checkNonExternalizedStringLiterals = initializeNLS && checkNLS;
8848
	this.scanner.checkNonExternalizedStringLiterals = initializeNLS && checkNLS;
8849
	this.scanner.lastPosistion = -1;
8849
	this.scanner.lastPosition = -1;
8850
8850
8851
	resetModifiers();
8851
	resetModifiers();
8852
8852
Lines 10354-10360 Link Here
10354
	
10354
	
10355
	if (this.lastPosistion < this.scanner.currentPosition) {
10355
	if (this.lastPosistion < this.scanner.currentPosition) {
10356
		this.lastPosistion = this.scanner.currentPosition;
10356
		this.lastPosistion = this.scanner.currentPosition;
10357
		this.scanner.lastPosistion = this.scanner.currentPosition;
10357
		this.scanner.lastPosition = this.scanner.currentPosition;
10358
	}
10358
	}
10359
	
10359
	
10360
	/* attempt to reset state in order to resume to parse loop */
10360
	/* attempt to reset state in order to resume to parse loop */
(-)compiler/org/eclipse/jdt/internal/compiler/parser/Scanner.java (-5 / +5 lines)
Lines 157-163 Link Here
157
	protected int nlsTagsPtr;
157
	protected int nlsTagsPtr;
158
	public boolean checkNonExternalizedStringLiterals;
158
	public boolean checkNonExternalizedStringLiterals;
159
	
159
	
160
	protected int lastPosistion;
160
	protected int lastPosition;
161
	
161
	
162
	// generic support
162
	// generic support
163
	public boolean returnOnlyGreater = false;
163
	public boolean returnOnlyGreater = false;
Lines 1510-1516 Link Here
1510
								if (this.taskTags != null) checkTaskTag(this.startPosition, this.currentPosition);
1510
								if (this.taskTags != null) checkTaskTag(this.startPosition, this.currentPosition);
1511
								if ((this.currentCharacter == '\r') || (this.currentCharacter == '\n')) {
1511
								if ((this.currentCharacter == '\r') || (this.currentCharacter == '\n')) {
1512
									if (this.checkNonExternalizedStringLiterals &&
1512
									if (this.checkNonExternalizedStringLiterals &&
1513
											this.lastPosistion < this.currentPosition) {
1513
											this.lastPosition < this.currentPosition) {
1514
										parseTags();
1514
										parseTags();
1515
									}
1515
									}
1516
									if (this.recordLineSeparator) {
1516
									if (this.recordLineSeparator) {
Lines 1529-1535 Link Here
1529
								recordComment(TokenNameCOMMENT_LINE);
1529
								recordComment(TokenNameCOMMENT_LINE);
1530
								if (this.taskTags != null) checkTaskTag(this.startPosition, this.currentPosition);
1530
								if (this.taskTags != null) checkTaskTag(this.startPosition, this.currentPosition);
1531
								if (this.checkNonExternalizedStringLiterals &&
1531
								if (this.checkNonExternalizedStringLiterals &&
1532
										this.lastPosistion < this.currentPosition) {
1532
										this.lastPosition < this.currentPosition) {
1533
									parseTags();
1533
									parseTags();
1534
								}
1534
								}
1535
								if (this.tokenizeComments) {
1535
								if (this.tokenizeComments) {
Lines 1956-1962 Link Here
1956
								if (this.recordLineSeparator
1956
								if (this.recordLineSeparator
1957
									&& ((this.currentCharacter == '\r') || (this.currentCharacter == '\n'))) {
1957
									&& ((this.currentCharacter == '\r') || (this.currentCharacter == '\n'))) {
1958
										if (this.checkNonExternalizedStringLiterals &&
1958
										if (this.checkNonExternalizedStringLiterals &&
1959
												this.lastPosistion < this.currentPosition) {
1959
												this.lastPosition < this.currentPosition) {
1960
											parseTags();
1960
											parseTags();
1961
										}
1961
										}
1962
										if (this.recordLineSeparator) {
1962
										if (this.recordLineSeparator) {
Lines 1972-1978 Link Here
1972
								this.currentPosition--;
1972
								this.currentPosition--;
1973
								recordComment(TokenNameCOMMENT_LINE);
1973
								recordComment(TokenNameCOMMENT_LINE);
1974
								if (this.checkNonExternalizedStringLiterals &&
1974
								if (this.checkNonExternalizedStringLiterals &&
1975
										this.lastPosistion < this.currentPosition) {
1975
										this.lastPosition < this.currentPosition) {
1976
									parseTags();
1976
									parseTags();
1977
								}
1977
								}
1978
								if (!this.tokenizeComments) {
1978
								if (!this.tokenizeComments) {
(-)compiler/org/eclipse/jdt/internal/compiler/parser/AbstractCommentParser.java (-3 / +6 lines)
Lines 29-34 Link Here
29
	public final static int SELECTION_PARSER = 3;
29
	public final static int SELECTION_PARSER = 3;
30
	public final static int COMPLETION_PARSER = 4;
30
	public final static int COMPLETION_PARSER = 4;
31
	public final static int SOURCE_PARSER = 5;
31
	public final static int SOURCE_PARSER = 5;
32
	public final static int FORMATTER_COMMENT_PARSER = 6;
32
	protected final static int PARSER_KIND = 0x00FF;
33
	protected final static int PARSER_KIND = 0x00FF;
33
	protected final static int TEXT_PARSE = 0x0100; // flag saying that text must be stored
34
	protected final static int TEXT_PARSE = 0x0100; // flag saying that text must be stored
34
	protected final static int TEXT_VERIF = 0x0200; // flag saying that text must be verified
35
	protected final static int TEXT_VERIF = 0x0200; // flag saying that text must be verified
Lines 74-80 Link Here
74
	protected int tagValue = NO_TAG_VALUE;
75
	protected int tagValue = NO_TAG_VALUE;
75
	
76
	
76
	// Line pointers
77
	// Line pointers
77
	private int linePtr, lastLinePtr;
78
	private int lastLinePtr;
79
	protected int linePtr;
78
	
80
	
79
	// Identifier stack
81
	// Identifier stack
80
	protected int identifierPtr;
82
	protected int identifierPtr;
Lines 152-157 Link Here
152
			boolean pushText = (this.kind & TEXT_PARSE) != 0;
154
			boolean pushText = (this.kind & TEXT_PARSE) != 0;
153
			boolean verifText = (this.kind & TEXT_VERIF) != 0;
155
			boolean verifText = (this.kind & TEXT_VERIF) != 0;
154
			boolean isDomParser = (this.kind & DOM_PARSER) != 0;
156
			boolean isDomParser = (this.kind & DOM_PARSER) != 0;
157
			boolean isFormatterParser = (this.kind & FORMATTER_COMMENT_PARSER) != 0;
155
			
158
			
156
			// Loop on each comment character
159
			// Loop on each comment character
157
			while (!abort && this.index < this.javadocEnd) {
160
			while (!abort && this.index < this.javadocEnd) {
Lines 201-207 Link Here
201
								if (this.textStart != -1 && this.textStart < previousPosition) {
204
								if (this.textStart != -1 && this.textStart < previousPosition) {
202
									if (pushText) pushText(this.textStart, previousPosition);
205
									if (pushText) pushText(this.textStart, previousPosition);
203
								}
206
								}
204
								if (isDomParser) refreshInlineTagPosition(previousPosition);
207
								if (isDomParser || isFormatterParser) refreshInlineTagPosition(previousPosition);
205
							}
208
							}
206
							if (previousChar == '{') {
209
							if (previousChar == '{') {
207
								if (this.textStart != -1 && this.textStart < this.inlineTagStart) {
210
								if (this.textStart != -1 && this.textStart < this.inlineTagStart) {
Lines 221-227 Link Here
221
									validComment = false;
224
									validComment = false;
222
									// bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=51600
225
									// bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=51600
223
									// for DOM AST node, store tag as text in case of invalid syntax
226
									// for DOM AST node, store tag as text in case of invalid syntax
224
									if (isDomParser) {
227
									if (isDomParser || isFormatterParser) {
225
										createTag();
228
										createTag();
226
									}
229
									}
227
									this.textStart = this.tagSourceEnd+1;
230
									this.textStart = this.tagSourceEnd+1;
(-)formatter/org/eclipse/jdt/internal/formatter/comment/IJavaDocTagConstants.java (+6 lines)
Lines 108-111 Link Here
108
108
109
	/** Tag prefix of comment tags */
109
	/** Tag prefix of comment tags */
110
	public static final char COMMENT_TAG_PREFIX= '@';
110
	public static final char COMMENT_TAG_PREFIX= '@';
111
	
112
	/** param tag */
113
	public static final String PARAM_TAG = "@param"; //$NON-NLS-1$
114
	
115
	/** space */
116
	public static final String SPACE = " "; //$NON-NLS-1$
111
}
117
}
(-)formatter/org/eclipse/jdt/internal/formatter/FormatJavadocTag.java (+106 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2008 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.jdt.internal.formatter;
12
13
public class FormatJavadocTag extends FormatJavadocNode {
14
	/**
15
	 * A FJTag is composed of: - a tag name (String) - can be null when dealing
16
	 * with the Javadoc comment's main text section - a FJReference (can be
17
	 * null) - an array of FJNodes (can be empty)
18
	 */
19
	protected String tagName;
20
	protected FormatJavadocReference reference;
21
	protected FormatJavadocNode[] nodes;
22
	protected int nodesPtr = -1;
23
24
	/**
25
	 * A FJtag can have inline tags or can be inlined
26
	 */
27
	protected boolean inlineTag = false;
28
	private boolean hasInlineTag = false;
29
30
	public FormatJavadocTag(int offset, int endPosition) {
31
		super(offset, endPosition);
32
	}
33
34
	public boolean isTag() {
35
		return true;
36
	}
37
38
	public void addNode(FormatJavadocNode newNode) {
39
		if (newNode == null)
40
			return;
41
		if (this.nodesPtr == -1) { // lazy initialization
42
			this.nodes = new FormatJavadocNode[DEFAULT_ARRAY_SIZE];
43
			this.nodes[++nodesPtr] = newNode;
44
			this.endPosition = newNode.endPosition;
45
			return;
46
		} else if (this.nodesPtr == this.nodes.length - 1) { // resize if needed
47
			System.arraycopy(this.nodes, 0, (this.nodes = new FormatJavadocNode[this.nodes.length * 2]), 0, this.nodesPtr + 1);
48
		}
49
50
		if (newNode.isTag()) { // add inline tag
51
			this.hasInlineTag = true;
52
			((FormatJavadocTag) newNode).inlineTag = true;
53
			this.nodes[++nodesPtr] = newNode;
54
		} else { // add text
55
			FormatJavadocNode lastNode = this.nodes[this.nodesPtr];
56
			if (lastNode.isText()) {
57
				((FormatJavadocText) lastNode).appendTextElement(
58
						newNode.startPosition, newNode.endPosition);
59
			} else {
60
				this.nodes[++nodesPtr] = newNode;
61
			}
62
		}
63
		this.endPosition = newNode.endPosition;
64
	}
65
66
	public String toString() {
67
		StringBuffer buffer = new StringBuffer();
68
		String space = " "; //$NON-NLS-1$
69
		String inLineTag = space + (this.inlineTag ? "(Inline Tag)" : "") + space; //$NON-NLS-1$//$NON-NLS-2$
70
		String nameToString = space + (this.tagName == null ? "NO NAME" : this.tagName.toString()) + space; //$NON-NLS-1$
71
		String referenceToString = this.reference == null ? "NO REFERENCE" : this.reference.toString() + space; //$NON-NLS-1$
72
		buffer.append("[FJTag] -").append(inLineTag).append(nameToString).append(referenceToString).append(" - at offset: " + this.startPosition + " end position : " + this.endPosition + "\n"); //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$//$NON-NLS-4$
73
		if (this.nodesPtr > -1) {
74
			for (int i = 0; i < (this.nodesPtr + 1); i++) {
75
				buffer.append(this.nodes[i].toString());
76
			}
77
		} else {
78
			buffer.append("	").append("EMPTY NODE STACK" + "\n"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
79
		}
80
		return buffer.toString();
81
	}
82
83
	public void setSourceRange(int newOffset, int newEndPosition) {
84
		this.startPosition = newOffset;
85
		this.endPosition = newEndPosition;
86
	}
87
88
	public boolean hasInlineTag() {
89
		return this.hasInlineTag;
90
	}
91
92
	public FormatJavadocTag getPreviousInlineTag() {
93
		if (hasInlineTag()) {
94
			int i = this.nodesPtr; 
95
			while (i >= 0) {
96
				FormatJavadocNode aNode = this.nodes[i];
97
				if (aNode.isTag()) {
98
					return (FormatJavadocTag) aNode;
99
				}
100
				i--;
101
			}
102
			return null;
103
		}
104
		return null;
105
	}
106
}
(-)formatter/org/eclipse/jdt/internal/formatter/FormatJavadoc.java (+34 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2008 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.jdt.internal.formatter;
12
13
import org.eclipse.jdt.internal.compiler.ast.Javadoc;
14
15
/**
16
 * Represents a full Javadoc comment
17
 * It is composed of an array of FJTags {@link FormatJavadocTag} 
18
 * These FJTags are composed of FJNodes, which can be:
19
 * - FJText {@link FormatJavadocText}
20
 * - FJTags {@link FormatJavadocTag} which in this case are inline tags
21
 */
22
public class FormatJavadoc extends Javadoc {
23
24
	FormatJavadocTag[] tags;
25
26
	public FormatJavadoc(int sourceStart, int sourceEnd, int initialSize) {
27
		super(sourceStart, sourceEnd);
28
		init(initialSize);
29
	}
30
	
31
	private void init(int initialSize) {
32
		this.tags = new FormatJavadocTag[initialSize];
33
	}
34
}
(-)formatter/org/eclipse/jdt/internal/formatter/FormatterCommentParser.java (+640 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2008 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.jdt.internal.formatter;
12
13
import java.util.List;
14
15
import org.eclipse.jdt.core.compiler.CharOperation;
16
import org.eclipse.jdt.core.compiler.InvalidInputException;
17
import org.eclipse.jdt.internal.compiler.ast.Expression;
18
import org.eclipse.jdt.internal.compiler.ast.JavadocArgumentExpression;
19
import org.eclipse.jdt.internal.compiler.ast.JavadocFieldReference;
20
import org.eclipse.jdt.internal.compiler.ast.JavadocImplicitTypeReference;
21
import org.eclipse.jdt.internal.compiler.ast.JavadocMessageSend;
22
import org.eclipse.jdt.internal.compiler.ast.JavadocSingleNameReference;
23
import org.eclipse.jdt.internal.compiler.ast.JavadocSingleTypeReference;
24
import org.eclipse.jdt.internal.compiler.ast.TypeReference;
25
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
26
import org.eclipse.jdt.internal.compiler.parser.JavadocParser;
27
import org.eclipse.jdt.internal.compiler.parser.Parser;
28
import org.eclipse.jdt.internal.compiler.parser.ScannerHelper;
29
import org.eclipse.jdt.internal.compiler.parser.TerminalTokens;
30
import org.eclipse.jdt.internal.formatter.comment.IJavaDocTagConstants;
31
32
/**
33
 * Internal parser used for formatting javadoc comments.
34
 * 
35
 * @since 3.4
36
 */
37
38
public class FormatterCommentParser extends JavadocParser implements
39
		IJavaDocTagConstants {
40
41
	FormatterCommentParser(Parser sourceParser) {
42
		super(sourceParser);
43
		this.kind = FORMATTER_COMMENT_PARSER | TEXT_PARSE;
44
		this.reportProblems = false;
45
		this.checkDocComment = true;
46
	}
47
48
	public boolean parse(int start, int end, int separatorLength) {
49
		this.resetASTStack();
50
		// Init
51
		this.javadocStart = start;
52
		this.javadocEnd = end;
53
		this.firstTagPosition = this.javadocStart;
54
55
		// parse comment
56
		commentParse();
57
58
		return this.docComment != null;
59
	}
60
61
	public String toString() {
62
		StringBuffer buffer = new StringBuffer();
63
		buffer.append("FormatterCommentParser\n"); //$NON-NLS-1$
64
		buffer.append(super.toString());
65
		return buffer.toString();
66
	}
67
68
	/*
69
	 * (non-Javadoc)
70
	 * 
71
	 * @see org.eclipse.jdt.internal.compiler.parser.AbstractCommentParser#createArgumentReference(char[],
72
	 *      java.lang.Object, int)
73
	 */
74
	protected Object createArgumentReference(char[] name, int dim, boolean isVarargs, Object typeRef, long[] dimPositions, long argNamePos) throws InvalidInputException {
75
		Expression argRef;
76
		if (typeRef instanceof FormatJavadocReference) {
77
			argRef = (Expression) super.createArgumentReference(name, dim, isVarargs, ((FormatJavadocReference) typeRef).node, dimPositions, argNamePos);
78
		} else {
79
			argRef = (Expression) super.createArgumentReference(name, dim, isVarargs, typeRef, dimPositions, argNamePos);
80
		}
81
		return argRef;
82
	}
83
84
	/*
85
	 * (non-Javadoc)
86
	 * 
87
	 * @see org.eclipse.jdt.internal.compiler.parser.AbstractCommentParser#createFieldReference()
88
	 */
89
	protected Object createFieldReference(Object receiver) throws InvalidInputException {
90
		if (receiver == null) {
91
			return internalCreateFieldReference();
92
		}
93
		JavadocFieldReference fieldRef = (JavadocFieldReference) super.createFieldReference(receiver);
94
		return new FormatJavadocReference(fieldRef);
95
	}
96
97
	private void createHeader() {
98
		int start = this.textStart == -1 ? this.tagSourceStart : this.textStart;
99
		FormatJavadocTag header = new FormatJavadocTag(this.javadocStart, start - 1);
100
		pushOnAstStack(header, true);
101
		header.addNode(new FormatJavadocText(this.javadocStart, start - 1));
102
	}
103
104
	private Object createImplicitMethodReference(List arguments) throws InvalidInputException {
105
		try {
106
			int length = this.identifierLengthStack[0];
107
			TypeReference typeRef = new JavadocImplicitTypeReference(this.identifierStack[length - 1], this.memberStart);
108
			if (arguments == null) {
109
				JavadocMessageSend msg = new JavadocMessageSend(this.identifierStack[length - 1], this.identifierPositionStack[length - 1]);
110
				msg.receiver = typeRef;
111
				msg.tagValue = this.tagValue;
112
				msg.sourceEnd = this.scanner.getCurrentTokenEndPosition();
113
				return msg;
114
			} else {
115
				JavadocArgumentExpression[] expressions = new JavadocArgumentExpression[arguments.size()];
116
				arguments.toArray(expressions);
117
				JavadocMessageSend msg = new JavadocMessageSend(this.identifierStack[length - 1], this.identifierPositionStack[length - 1], expressions);
118
				msg.receiver = typeRef;
119
				msg.tagValue = this.tagValue;
120
				msg.sourceEnd = this.scanner.getCurrentTokenEndPosition();
121
				return msg;
122
			}
123
		} catch (ClassCastException ex) {
124
			throw new InvalidInputException();
125
		}
126
	}
127
128
	/*
129
	 * (non-Javadoc)
130
	 * 
131
	 * @see org.eclipse.jdt.internal.compiler.parser.AbstractCommentParser#createMethodReference(java.lang.Object[])
132
	 */
133
	protected Object createMethodReference(Object receiver, List arguments) throws InvalidInputException {
134
		if (receiver == null) { // implicit type ref
135
			return new FormatJavadocReference((Expression) createImplicitMethodReference(arguments));
136
		}
137
		if (receiver instanceof FormatJavadocReference) {return new FormatJavadocReference((Expression) super.createMethodReference(((FormatJavadocReference) receiver).node, arguments));
138
		} else {
139
			return new FormatJavadocReference((Expression) super.createMethodReference(receiver, arguments));
140
		}
141
	}
142
143
	/*
144
	 * (non-Javadoc)
145
	 * 
146
	 * @see org.eclipse.jdt.internal.compiler.parser.AbstractCommentParser#createTag()
147
	 */
148
	protected void createTag() {
149
		if (this.astLengthPtr == -1) {
150
			createHeader();
151
		}
152
		addTag(internalCreateTag());
153
	}
154
155
	/*
156
	 * (non-Javadoc)
157
	 * 
158
	 * @see org.eclipse.jdt.internal.compiler.parser.AbstractCommentParser#createTypeReference()
159
	 */
160
	protected Object createTypeReference(int primitiveToken) {
161
		TypeReference typeRef = (TypeReference) super.createTypeReference(primitiveToken);
162
		return new FormatJavadocReference(typeRef);
163
	}
164
165
	/*
166
	 * (non-Javadoc)
167
	 * 
168
	 * @see org.eclipse.jdt.internal.compiler.parser.AbstractCommentParser#parseIdentifierTag(boolean)
169
	 */
170
	protected boolean parseIdentifierTag(boolean report) {
171
		if (super.parseIdentifierTag(report)) {
172
			createTag();
173
			this.index = this.tagSourceEnd + 1;
174
			this.scanner.resetTo(this.index, this.javadocEnd);
175
			return true;
176
		}
177
		return false;
178
	}
179
180
	/*
181
	 * Parse @return tag declaration
182
	 */
183
	protected boolean parseReturn() {
184
		createTag();
185
		return true;
186
	}
187
188
	/*
189
	 * (non-Javadoc)
190
	 * 
191
	 * @see org.eclipse.jdt.internal.compiler.parser.AbstractCommentParser#parseTag(int)
192
	 */
193
	protected boolean parseTag(int previousPosition) throws InvalidInputException {
194
195
		// Read tag name
196
		int currentPosition = this.index;
197
		int token = readTokenAndConsume();
198
		char[] tagName = CharOperation.NO_CHAR;
199
		if (currentPosition == this.scanner.startPosition) {
200
			this.tagSourceStart = this.scanner.getCurrentTokenStartPosition();
201
			this.tagSourceEnd = this.scanner.getCurrentTokenEndPosition();
202
			tagName = this.scanner.getCurrentIdentifierSource();
203
		} else {
204
			this.tagSourceEnd = currentPosition - 1;
205
		}
206
207
		// Try to get tag name other than java identifier
208
		// (see bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=51660)
209
		if (this.scanner.currentCharacter != ' '
210
				&& !ScannerHelper.isWhitespace(this.scanner.currentCharacter)) {
211
			tagNameToken: while (token != TerminalTokens.TokenNameEOF
212
					&& this.index < this.scanner.eofPosition) {
213
				int length = tagName.length;
214
				// !, ", #, %, &, ', -, :, <, >, * chars and spaces are not
215
				// allowed in tag names
216
				switch (this.scanner.currentCharacter) {
217
				case '}':
218
				case '*': // break for '*' as this is perhaps the end of
219
					// comment (bug 65288)
220
				case '!':
221
				case '#':
222
				case '%':
223
				case '&':
224
				case '\'':
225
				case '"':
226
				case ':':
227
				case '<':
228
				case '>':
229
					break tagNameToken;
230
				case '-': // allowed in tag names as this character is often
231
					// used in doclets (bug 68087)
232
					System.arraycopy(tagName, 0,
233
							tagName = new char[length + 1], 0, length);
234
					tagName[length] = this.scanner.currentCharacter;
235
					break;
236
				default:
237
					if (this.scanner.currentCharacter == ' '
238
							|| ScannerHelper
239
									.isWhitespace(this.scanner.currentCharacter)) {
240
						break tagNameToken;
241
					}
242
					token = readTokenAndConsume();
243
					char[] ident = this.scanner.getCurrentIdentifierSource();
244
					System.arraycopy(tagName, 0, tagName = new char[length
245
							+ ident.length], 0, length);
246
					System.arraycopy(ident, 0, tagName, length, ident.length);
247
					break;
248
				}
249
				this.tagSourceEnd = this.scanner.getCurrentTokenEndPosition();
250
				this.scanner.getNextChar();
251
				this.index = this.scanner.currentPosition;
252
			}
253
		}
254
		int length = tagName.length;
255
		this.index = this.tagSourceEnd + 1;
256
		this.scanner.currentPosition = this.tagSourceEnd + 1;
257
		this.tagSourceStart = previousPosition;
258
259
		// tage name may be empty (see bug
260
		// https://bugs.eclipse.org/bugs/show_bug.cgi?id=125903)
261
		if (tagName.length == 0) {
262
			return false;
263
		}
264
265
		// Decide which parse to perform depending on tag name
266
		this.tagValue = NO_TAG_VALUE;
267
		boolean valid = true;
268
		switch (token) {
269
		case TerminalTokens.TokenNameIdentifier:
270
			switch (tagName[0]) {
271
			case 'c':
272
				if (length == TAG_CATEGORY_LENGTH
273
						&& CharOperation.equals(TAG_CATEGORY, tagName)) {
274
					this.tagValue = TAG_CATEGORY_VALUE;
275
					valid = parseIdentifierTag(false); // TODO (frederic)
276
					// reconsider parameter
277
					// value when @category
278
					// will be significant
279
					// in spec
280
				} else {
281
					this.tagValue = TAG_OTHERS_VALUE;
282
					createTag();
283
				}
284
				break;
285
			case 'd':
286
				if (length == TAG_DEPRECATED_LENGTH
287
						&& CharOperation.equals(TAG_DEPRECATED, tagName)) {
288
					this.deprecated = true;
289
					this.tagValue = TAG_DEPRECATED_VALUE;
290
				} else {
291
					this.tagValue = TAG_OTHERS_VALUE;
292
				}
293
				createTag();
294
				break;
295
			case 'i':
296
				if (length == TAG_INHERITDOC_LENGTH
297
						&& CharOperation.equals(TAG_INHERITDOC, tagName)) {
298
					// inhibits inherited flag when tags have been already
299
					// stored
300
					// see bug
301
					// https://bugs.eclipse.org/bugs/show_bug.cgi?id=51606
302
					// Note that for DOM_PARSER, nodes stack may be not empty
303
					// even no '@' tag
304
					// was encountered in comment. But it cannot be the case for
305
					// COMPILER_PARSER
306
					// and so is enough as it is only this parser which signals
307
					// the missing tag warnings...
308
					if (this.astPtr == -1) {
309
						this.inheritedPositions = (((long) this.tagSourceStart) << 32)
310
								+ this.tagSourceEnd;
311
					}
312
					this.tagValue = TAG_INHERITDOC_VALUE;
313
				} else {
314
					this.tagValue = TAG_OTHERS_VALUE;
315
				}
316
				createTag();
317
				break;
318
			case 'p':
319
				if (length == TAG_PARAM_LENGTH
320
						&& CharOperation.equals(TAG_PARAM, tagName)) {
321
					this.tagValue = TAG_PARAM_VALUE;
322
					valid = parseParam();
323
				} else {
324
					this.tagValue = TAG_OTHERS_VALUE;
325
					createTag();
326
				}
327
				break;
328
			case 'e':
329
				if (length == TAG_EXCEPTION_LENGTH
330
						&& CharOperation.equals(TAG_EXCEPTION, tagName)) {
331
					this.tagValue = TAG_EXCEPTION_VALUE;
332
					valid = parseThrows();
333
				} else {
334
					this.tagValue = TAG_OTHERS_VALUE;
335
					createTag();
336
				}
337
				break;
338
			case 's':
339
				if (length == TAG_SEE_LENGTH
340
						&& CharOperation.equals(TAG_SEE, tagName)) {
341
					this.tagValue = TAG_SEE_VALUE;
342
					if (this.inlineTagStarted) {
343
						// bug
344
						// https://bugs.eclipse.org/bugs/show_bug.cgi?id=53290
345
						// Cannot have @see inside inline comment
346
						valid = false;
347
					} else {
348
						valid = parseReference();
349
					}
350
				} else {
351
					this.tagValue = TAG_OTHERS_VALUE;
352
					createTag();
353
				}
354
				break;
355
			case 'l':
356
				if (length == TAG_LINK_LENGTH
357
						&& CharOperation.equals(TAG_LINK, tagName)) {
358
					this.tagValue = TAG_LINK_VALUE;
359
				} else if (length == TAG_LINKPLAIN_LENGTH
360
						&& CharOperation.equals(TAG_LINKPLAIN, tagName)) {
361
					this.tagValue = TAG_LINKPLAIN_VALUE;
362
				}
363
				if (this.tagValue != NO_TAG_VALUE) {
364
					if (this.inlineTagStarted) {
365
						valid = parseReference();
366
					} else {
367
						// bug
368
						// https://bugs.eclipse.org/bugs/show_bug.cgi?id=53290
369
						// Cannot have @link outside inline comment
370
						valid = false;
371
					}
372
				} else {
373
					this.tagValue = TAG_OTHERS_VALUE;
374
					createTag();
375
				}
376
				break;
377
			case 'v':
378
				if (this.sourceLevel >= ClassFileConstants.JDK1_5
379
						&& length == TAG_VALUE_LENGTH
380
						&& CharOperation.equals(TAG_VALUE, tagName)) {
381
					this.tagValue = TAG_VALUE_VALUE;
382
					if (this.inlineTagStarted) {
383
						valid = parseReference();
384
					} else {
385
						valid = false;
386
					}
387
				} else {
388
					this.tagValue = TAG_OTHERS_VALUE;
389
					createTag();
390
				}
391
				break;
392
			default:
393
				this.tagValue = TAG_OTHERS_VALUE;
394
				createTag();
395
			}
396
			break;
397
		case TerminalTokens.TokenNamereturn:
398
			this.tagValue = TAG_RETURN_VALUE;
399
			valid = parseReturn();
400
			break;
401
		case TerminalTokens.TokenNamethrows:
402
			this.tagValue = TAG_THROWS_VALUE;
403
			valid = parseThrows();
404
			break;
405
		case TerminalTokens.TokenNameabstract:
406
		case TerminalTokens.TokenNameassert:
407
		case TerminalTokens.TokenNameboolean:
408
		case TerminalTokens.TokenNamebreak:
409
		case TerminalTokens.TokenNamebyte:
410
		case TerminalTokens.TokenNamecase:
411
		case TerminalTokens.TokenNamecatch:
412
		case TerminalTokens.TokenNamechar:
413
		case TerminalTokens.TokenNameclass:
414
		case TerminalTokens.TokenNamecontinue:
415
		case TerminalTokens.TokenNamedefault:
416
		case TerminalTokens.TokenNamedo:
417
		case TerminalTokens.TokenNamedouble:
418
		case TerminalTokens.TokenNameelse:
419
		case TerminalTokens.TokenNameextends:
420
		case TerminalTokens.TokenNamefalse:
421
		case TerminalTokens.TokenNamefinal:
422
		case TerminalTokens.TokenNamefinally:
423
		case TerminalTokens.TokenNamefloat:
424
		case TerminalTokens.TokenNamefor:
425
		case TerminalTokens.TokenNameif:
426
		case TerminalTokens.TokenNameimplements:
427
		case TerminalTokens.TokenNameimport:
428
		case TerminalTokens.TokenNameinstanceof:
429
		case TerminalTokens.TokenNameint:
430
		case TerminalTokens.TokenNameinterface:
431
		case TerminalTokens.TokenNamelong:
432
		case TerminalTokens.TokenNamenative:
433
		case TerminalTokens.TokenNamenew:
434
		case TerminalTokens.TokenNamenull:
435
		case TerminalTokens.TokenNamepackage:
436
		case TerminalTokens.TokenNameprivate:
437
		case TerminalTokens.TokenNameprotected:
438
		case TerminalTokens.TokenNamepublic:
439
		case TerminalTokens.TokenNameshort:
440
		case TerminalTokens.TokenNamestatic:
441
		case TerminalTokens.TokenNamestrictfp:
442
		case TerminalTokens.TokenNamesuper:
443
		case TerminalTokens.TokenNameswitch:
444
		case TerminalTokens.TokenNamesynchronized:
445
		case TerminalTokens.TokenNamethis:
446
		case TerminalTokens.TokenNamethrow:
447
		case TerminalTokens.TokenNametransient:
448
		case TerminalTokens.TokenNametrue:
449
		case TerminalTokens.TokenNametry:
450
		case TerminalTokens.TokenNamevoid:
451
		case TerminalTokens.TokenNamevolatile:
452
		case TerminalTokens.TokenNamewhile:
453
			this.tagValue = TAG_OTHERS_VALUE;
454
			createTag();
455
			break;
456
		}
457
		this.textStart = this.index;
458
		return valid;
459
	}
460
461
	/*
462
	 * (non-Javadoc)
463
	 * 
464
	 * @see org.eclipse.jdt.internal.compiler.parser.AbstractCommentParser#pushParamName(java.lang.Object)
465
	 */
466
	protected boolean pushParamName(boolean isTypeParam) {
467
		// create javadoc header if needed
468
		if (this.astPtr == -1) {
469
			createHeader();
470
		}
471
472
		boolean valid = super.pushParamName(isTypeParam);
473
		Expression ref;
474
		if (valid && this.astLengthPtr > -1) {
475
			if (isTypeParam) {
476
				ref = (JavadocSingleTypeReference) this.astStack[this.astPtr];
477
			} else {
478
				ref = (JavadocSingleNameReference) this.astStack[this.astPtr];
479
			}
480
		} else { // invalid param name are stored in another stack
481
			if (isTypeParam && this.invalidParamReferencesPtr > -1) {
482
				ref = (JavadocSingleTypeReference) this.invalidParamReferencesStack[this.invalidParamReferencesPtr];
483
			} else {
484
				ref = (JavadocSingleNameReference) this.invalidParamReferencesStack[this.invalidParamReferencesPtr];
485
			}
486
		}
487
		if (ref != null) {
488
			// create new FJTag
489
			FormatJavadocTag paramTag = internalCreateTag();
490
			FormatJavadocReference fjRef = new FormatJavadocReference(ref);
491
			paramTag.reference = fjRef;
492
			paramTag.endPosition = fjRef.endPosition;
493
			if (valid) {
494
				this.astStack[this.astPtr] = paramTag; // replace in the AST
495
				// stack
496
			} else {
497
				pushOnAstStack(paramTag, true);
498
			}
499
			this.scanner.resetTo(paramTag.endPosition + 1, this.javadocEnd);
500
		}
501
		return true;
502
	}
503
504
	/*
505
	 * (non-Javadoc)
506
	 * 
507
	 * @see org.eclipse.jdt.internal.compiler.parser.AbstractCommentParser#pushSeeRef(java.lang.Object)
508
	 */
509
	protected boolean pushSeeRef(Object statement) {
510
		if (!(statement instanceof FormatJavadocReference)) return false;
511
		internalPushRef((FormatJavadocReference) statement);
512
		return true;
513
	}
514
515
	/*
516
	 * (non-Javadoc)
517
	 * 
518
	 * @see org.eclipse.jdt.internal.compiler.parser.AbstractCommentParser#pushText(int,
519
	 *      int)
520
	 */
521
	protected void pushText(int start, int end) {
522
		FormatJavadocTag tag; // tag that will hold the text to push
523
524
		// check last FJTag on the stack if any
525
		if (this.astPtr == -1) {
526
			createHeader();
527
			tag = new FormatJavadocTag(start, end);
528
			addTag(tag);
529
		} else {
530
			tag = (FormatJavadocTag) this.astStack[astPtr];
531
		}
532
		tag.addNode(new FormatJavadocText(start, end)); // push the text
533
		this.textStart = -1;
534
	}
535
536
	/*
537
	 * (non-Javadoc) Will update the inline tag position (end position) once tag
538
	 * was fully parsed.
539
	 * 
540
	 * @see org.eclipse.jdt.internal.compiler.parser.AbstractCommentParser#pushText(int,
541
	 *      int)
542
	 */
543
	protected void refreshInlineTagPosition(int previousPosition) {
544
		if (this.astPtr != -1) {
545
			FormatJavadocTag previousTag = (FormatJavadocTag) this.astStack[this.astPtr];
546
			if (this.inlineTagStarted) {
547
				int previousStart = previousTag.startPosition;
548
				previousTag.setSourceRange(previousStart, previousPosition);
549
				if (previousTag.hasInlineTag()) {
550
					FormatJavadocTag inlineTag = previousTag.getPreviousInlineTag();
551
					int inlineStart = inlineTag.startPosition;
552
					inlineTag.setSourceRange(inlineStart, previousPosition);
553
				}
554
			}
555
		}
556
	}
557
558
	private void resetASTStack() {
559
		this.astStack = new Object[30];
560
		this.astPtr = -1;
561
	}
562
563
	/*
564
	 * (non-Javadoc)
565
	 * 
566
	 * @see org.eclipse.jdt.internal.compiler.parser.AbstractCommentParser#pushThrowName(java.lang.Object)
567
	 */
568
	protected boolean pushThrowName(Object typeRef) {
569
		if (!(typeRef instanceof FormatJavadocReference)) return false;
570
		internalPushRef((FormatJavadocReference) typeRef);
571
		return true;
572
	}
573
574
	/*
575
	 * Add stored tag elements to associated comment.
576
	 */
577
	protected void updateDocComment() {
578
		FormatJavadoc formatJavadoc = new FormatJavadoc(this.javadocStart, this.javadocEnd, this.astPtr + 1);
579
		System.arraycopy(this.astStack, 0, formatJavadoc.tags, 0, this.astPtr + 1);
580
		this.docComment = formatJavadoc;
581
	}
582
583
	private FormatJavadocTag internalCreateTag() {
584
		// create new tag
585
		FormatJavadocTag newTag = new FormatJavadocTag(this.tagSourceStart,
586
				this.tagSourceEnd);
587
		this.scanner.resetTo(this.tagSourceStart, this.tagSourceEnd);
588
		StringBuffer tagName = new StringBuffer();
589
		this.scanner.getNextChar();
590
		while (this.scanner.currentPosition <= (this.tagSourceEnd + 1)) {
591
			tagName.append(this.scanner.currentCharacter);
592
			this.scanner.getNextChar();
593
		}
594
		newTag.tagName = tagName.toString();
595
		return newTag;
596
	}
597
598
	private FormatJavadocReference internalCreateFieldReference() throws InvalidInputException {
599
		try {
600
			JavadocFieldReference field = new JavadocFieldReference(this.identifierStack[0], this.identifierPositionStack[0]);
601
			field.tagSourceStart = this.tagSourceStart;
602
			field.tagSourceEnd = this.tagSourceEnd;
603
			field.tagValue = this.tagValue;
604
			return new FormatJavadocReference(field);
605
		} catch (ClassCastException ex) {
606
			throw new InvalidInputException();
607
		}
608
	}
609
610
	private void addTag(FormatJavadocTag newTag) {
611
		// handle inline tags
612
		if (this.inlineTagStarted) {
613
			// adjust start position and length for inline tags
614
			newTag.startPosition = this.inlineTagStart;
615
			FormatJavadocTag lastTag;
616
			if (this.astPtr == -1) {
617
				lastTag = new FormatJavadocTag(newTag.startPosition,
618
						this.tagSourceEnd - newTag.startPosition + 1);
619
				pushOnAstStack(lastTag, true);
620
			} else {
621
				lastTag = (FormatJavadocTag) this.astStack[this.astPtr];
622
			}
623
			lastTag.addNode(newTag); // add inline tag
624
		} else {
625
			pushOnAstStack(newTag, true);
626
		}
627
		this.scanner.resetTo(newTag.endPosition + 1, this.javadocEnd);
628
	}
629
630
	private void internalPushRef(FormatJavadocReference ref) {
631
		// create javadoc header if needed
632
		if (this.astPtr == -1) {
633
			createHeader();
634
		}
635
		FormatJavadocTag newTag = internalCreateTag();
636
		newTag.reference = ref;
637
		newTag.endPosition = ref.endPosition;
638
		addTag(newTag);
639
	}
640
}
(-)formatter/org/eclipse/jdt/internal/formatter/FormatJavadocReference.java (+32 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2008 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.jdt.internal.formatter;
12
13
import org.eclipse.jdt.internal.compiler.ast.ASTNode;
14
15
public class FormatJavadocReference extends FormatJavadocNode {
16
17
	protected String name;
18
	protected ASTNode node;
19
20
	public FormatJavadocReference(ASTNode node) {
21
		super(node.sourceStart, node.sourceEnd);
22
		this.name = node.toString();
23
		this.node = node;
24
	}
25
26
	public String toString() {
27
		StringBuffer buffer = new StringBuffer();
28
		String nameToString = this.name == null ? "[FJRef] - NO NAME" : this.name.toString(); //$NON-NLS-1$
29
		buffer.append(nameToString);
30
		return buffer.toString();
31
	}
32
}
(-)formatter/org/eclipse/jdt/internal/formatter/FormatJavadocText.java (+53 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2008 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.jdt.internal.formatter;
12
13
public class FormatJavadocText extends FormatJavadocNode {
14
15
	protected long[] textSeparators;
16
	protected int textSeparatorsPtr = -1;
17
18
	public FormatJavadocText(int start, int end) {
19
		super(start, end);
20
		addSeparator(start, end - start);
21
	}
22
23
	public boolean isText() {
24
		return true;
25
	}
26
27
	public void appendTextElement(int textStart, int newEndPosition) {
28
		this.endPosition = newEndPosition;
29
		addSeparator(textStart, newEndPosition - textStart);
30
	}
31
32
	private void addSeparator(int textStart, int textLength) {
33
		if (this.textSeparatorsPtr == -1) { // lazy initialization
34
			this.textSeparators = new long[DEFAULT_ARRAY_SIZE];
35
		} else { // resize if needed
36
			if (this.textSeparatorsPtr == this.textSeparators.length - 1) {
37
				System.arraycopy(this.textSeparators, 0, (this.textSeparators = new long[this.textSeparators.length * 2]), 0, this.textSeparatorsPtr + 1);
38
			}
39
		}
40
		this.textSeparators[++this.textSeparatorsPtr] = (((long) textStart) << 32) + (textLength + 1);
41
	}
42
43
	public String toString() {
44
		StringBuffer buffer = new StringBuffer();
45
		buffer.append("	").append("[FJText] - at offset: " + this.startPosition).append(" end position: " + this.endPosition).append("\n"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
46
		if (this.textSeparatorsPtr > -1) {
47
			buffer.append("	").append("Number of text sections: " + (this.textSeparatorsPtr + 1) + "\n"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
48
		} else {
49
			buffer.append("	").append("NO TEXT SEPARATOR" + "\n"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
50
		}
51
		return buffer.toString();
52
	}
53
}
(-)formatter/org/eclipse/jdt/internal/formatter/FormatterParser.java (+21 lines)
Added Link Here
1
package org.eclipse.jdt.internal.formatter;
2
3
import org.eclipse.jdt.internal.compiler.parser.JavadocParser;
4
import org.eclipse.jdt.internal.compiler.problem.ProblemReporter;
5
import org.eclipse.jdt.internal.core.util.CommentRecorderParser;
6
7
/**
8
 * Internal formatter parser used for parsing Javadoc comments.
9
 * 
10
 * @since 3.4
11
 */
12
13
public class FormatterParser extends CommentRecorderParser {	
14
	public FormatterParser(ProblemReporter problemReporter) {
15
		super(problemReporter, false);
16
	}
17
	
18
	protected JavadocParser createJavadocParser() {
19
		return new FormatterCommentParser(this);
20
	}
21
}
(-)formatter/org/eclipse/jdt/internal/formatter/FormatJavadocNode.java (+41 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2008 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.jdt.internal.formatter;
12
13
import org.eclipse.core.runtime.Assert;
14
15
public abstract class FormatJavadocNode {
16
17
	// default size used for array
18
	protected int DEFAULT_ARRAY_SIZE = 10;
19
	protected int startPosition, endPosition;
20
21
	/**
22
	 * Constructor for the Javadoc comment components
23
	 * 
24
	 * @param startPosition
25
	 * @param endPosition
26
	 */
27
	public FormatJavadocNode(int startPosition, int endPosition) {
28
		Assert.isTrue(startPosition >= 0);
29
		Assert.isTrue(endPosition >= startPosition);
30
		this.startPosition = startPosition;
31
		this.endPosition = endPosition;
32
	}
33
34
	public boolean isTag() {
35
		return false;
36
	}
37
38
	public boolean isText() {
39
		return false;
40
	}
41
}

Return to bug 102780