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

Collapse All | Expand All

(-)formatter/org/eclipse/jdt/core/formatter/DefaultCodeFormatterConstants.java (+12 lines)
Lines 865-870 Link Here
865
	public static final String FORMATTER_INDENT_EMPTY_LINES = JavaCore.PLUGIN_ID + ".formatter.indent_empty_lines"; //$NON-NLS-1$	
865
	public static final String FORMATTER_INDENT_EMPTY_LINES = JavaCore.PLUGIN_ID + ".formatter.indent_empty_lines"; //$NON-NLS-1$	
866
	/**
866
	/**
867
	 * <pre>
867
	 * <pre>
868
	 * FORMATTER / Option to indent comments that start on the first column
869
	 *     - option id:         "org.eclipse.jdt.core.formatter.indent_comments_on_first_column"
870
	 *     - possible values:   { TRUE, FALSE }
871
	 *     - default:           FALSE
872
	 * </pre>
873
	 * @see #TRUE
874
	 * @see #FALSE
875
	 * @since 3.3
876
	 */
877
	public static final String FORMATTER_INDENT_COMMENTS_ON_FIRST_COLUMN = JavaCore.PLUGIN_ID + ".formatter.indent_comments_on_first_column"; //$NON-NLS-1$	
878
	/**
879
	 * <pre>
868
	 * FORMATTER / Option to indent statements inside a block
880
	 * FORMATTER / Option to indent statements inside a block
869
	 *     - option id:         "org.eclipse.jdt.core.formatter.indent_statements_compare_to_block"
881
	 *     - option id:         "org.eclipse.jdt.core.formatter.indent_statements_compare_to_block"
870
	 *     - possible values:   { TRUE, FALSE }
882
	 *     - possible values:   { TRUE, FALSE }
(-)formatter/org/eclipse/jdt/core/formatter/CodeFormatterApplication.java (-2 / +10 lines)
Lines 21-30 Link Here
21
import java.io.IOException;
21
import java.io.IOException;
22
import java.text.MessageFormat;
22
import java.text.MessageFormat;
23
import java.util.ArrayList;
23
import java.util.ArrayList;
24
import java.util.Map;
24
import java.util.Properties;
25
import java.util.Properties;
25
26
26
import org.eclipse.equinox.app.IApplication;
27
import org.eclipse.equinox.app.IApplication;
27
import org.eclipse.equinox.app.IApplicationContext;
28
import org.eclipse.equinox.app.IApplicationContext;
29
import org.eclipse.jdt.core.JavaCore;
28
import org.eclipse.jdt.core.ToolFactory;
30
import org.eclipse.jdt.core.ToolFactory;
29
import org.eclipse.jdt.internal.core.util.Util;
31
import org.eclipse.jdt.internal.core.util.Util;
30
import org.eclipse.jface.text.BadLocationException;
32
import org.eclipse.jface.text.BadLocationException;
Lines 158-164 Link Here
158
160
159
	private String configName;
161
	private String configName;
160
162
161
	private Properties options = null;
163
	private Map options = null;
162
164
163
	private static final String PDE_LAUNCH = "-pdelaunch"; //$NON-NLS-1$
165
	private static final String PDE_LAUNCH = "-pdelaunch"; //$NON-NLS-1$
164
166
Lines 374-379 Link Here
374
		}
376
		}
375
377
376
		// format the list of files and/or directories
378
		// format the list of files and/or directories
379
		if (this.options == null) {
380
			this.options = JavaCore.getOptions();
381
			this.options.put(
382
				DefaultCodeFormatterConstants.FORMATTER_INDENT_COMMENTS_ON_FIRST_COLUMN,
383
				DefaultCodeFormatterConstants.TRUE);
384
		}
377
		final CodeFormatter codeFormatter = ToolFactory.createCodeFormatter(this.options);
385
		final CodeFormatter codeFormatter = ToolFactory.createCodeFormatter(this.options);
378
		for (int i = 0, max = filesToFormat.length; i < max; i++) {
386
		for (int i = 0, max = filesToFormat.length; i < max; i++) {
379
			final File file = filesToFormat[i];
387
			final File file = filesToFormat[i];
Lines 381-387 Link Here
381
				formatDirTree(file, codeFormatter);
389
				formatDirTree(file, codeFormatter);
382
			} else if (Util.isJavaLikeFileName(file.getPath())) {
390
			} else if (Util.isJavaLikeFileName(file.getPath())) {
383
				formatFile(file, codeFormatter);
391
				formatFile(file, codeFormatter);
384
			}			
392
			}
385
		}
393
		}
386
		if (!this.quiet) {
394
		if (!this.quiet) {
387
			System.out.println(Messages.bind(Messages.CommandLineDone));
395
			System.out.println(Messages.bind(Messages.CommandLineDone));
(-)formatter/org/eclipse/jdt/internal/formatter/Scribe.java (-4 / +31 lines)
Lines 608-613 Link Here
608
		this.edits = new OptimizedReplaceEdit[INITIAL_SIZE];
608
		this.edits = new OptimizedReplaceEdit[INITIAL_SIZE];
609
	}	
609
	}	
610
	
610
	
611
	private boolean isOnFirstColumn(int start) {
612
		if (this.lineEnds == null) return start == 0;
613
		int index = Arrays.binarySearch(this.lineEnds, start);
614
		// we want the line end of the previous line
615
		int previousLineEnd = this.getLineEnd(-index - 1);
616
		return previousLineEnd != -1 && previousLineEnd == start - 1;
617
	}
618
611
	private boolean isValidEdit(OptimizedReplaceEdit edit) {
619
	private boolean isValidEdit(OptimizedReplaceEdit edit) {
612
		final int editLength= edit.length;
620
		final int editLength= edit.length;
613
		final int editReplacementLength= edit.replacement.length();
621
		final int editReplacementLength= edit.replacement.length();
Lines 663-669 Link Here
663
			handleLineTooLong();
671
			handleLineTooLong();
664
		}
672
		}
665
		this.lastNumberOfNewLines = 0;
673
		this.lastNumberOfNewLines = 0;
666
		printIndentationIfNecessary();
674
		if (this.indentationLevel != 0) {
675
			printIndentationIfNecessary();
676
		}
667
		if (considerSpaceIfAny) {
677
		if (considerSpaceIfAny) {
668
			this.space();
678
			this.space();
669
		}
679
		}
Lines 685-691 Link Here
685
		boolean isNewLine = false;
695
		boolean isNewLine = false;
686
		int start = currentTokenStartPosition;
696
		int start = currentTokenStartPosition;
687
		int nextCharacterStart = currentTokenStartPosition;
697
		int nextCharacterStart = currentTokenStartPosition;
688
		printIndentationIfNecessary();
698
		boolean indentComment = false;
699
		if (this.indentationLevel != 0) {
700
			if (this.formatter.preferences.indent_comments_on_first_column) {
701
				indentComment = true;
702
				printIndentationIfNecessary();
703
			} else if (!isOnFirstColumn(start)) {
704
				indentComment = true;
705
				printIndentationIfNecessary();
706
			}
707
		}
689
		if (this.pendingSpace) {
708
		if (this.pendingSpace) {
690
			this.addInsertEdit(currentTokenStartPosition, " "); //$NON-NLS-1$
709
			this.addInsertEdit(currentTokenStartPosition, " "); //$NON-NLS-1$
691
		}
710
		}
Lines 728-734 Link Here
728
747
729
						StringBuffer buffer = new StringBuffer();
748
						StringBuffer buffer = new StringBuffer();
730
						buffer.append(this.lineSeparator);
749
						buffer.append(this.lineSeparator);
731
						printIndentationIfNecessary(buffer);
750
						if (indentComment) {
751
							printIndentationIfNecessary(buffer);
752
						}
732
						buffer.append(' ');
753
						buffer.append(' ');
733
				
754
				
734
						addReplaceEdit(start, previousStart - 1, String.valueOf(buffer));
755
						addReplaceEdit(start, previousStart - 1, String.valueOf(buffer));
Lines 982-988 Link Here
982
		int currentCharacter;
1003
		int currentCharacter;
983
		int start = currentTokenStartPosition;
1004
		int start = currentTokenStartPosition;
984
		int nextCharacterStart = currentTokenStartPosition;
1005
		int nextCharacterStart = currentTokenStartPosition;
985
		printIndentationIfNecessary();
1006
		if (this.indentationLevel != 0) {
1007
			if (this.formatter.preferences.indent_comments_on_first_column) {
1008
				printIndentationIfNecessary();
1009
			} else if (!isOnFirstColumn(start)) {
1010
				printIndentationIfNecessary();
1011
			}
1012
		}
986
		if (this.pendingSpace) {
1013
		if (this.pendingSpace) {
987
			this.addInsertEdit(currentTokenStartPosition, " "); //$NON-NLS-1$
1014
			this.addInsertEdit(currentTokenStartPosition, " "); //$NON-NLS-1$
988
		}
1015
		}
(-)formatter/org/eclipse/jdt/internal/formatter/CodeFormatterVisitor.java (-2 / +6 lines)
Lines 3157-3163 Link Here
3157
			
3157
			
3158
		if (constructorDeclaration.ignoreFurtherInvestigation) {
3158
		if (constructorDeclaration.ignoreFurtherInvestigation) {
3159
			this.scribe.printComment();
3159
			this.scribe.printComment();
3160
			this.scribe.printIndentationIfNecessary();
3160
			if (this.scribe.indentationLevel != 0) {
3161
				this.scribe.printIndentationIfNecessary();
3162
			}
3161
			this.scribe.scanner.resetTo(constructorDeclaration.declarationSourceEnd + 1, this.scribe.scannerEndPosition - 1);
3163
			this.scribe.scanner.resetTo(constructorDeclaration.declarationSourceEnd + 1, this.scribe.scannerEndPosition - 1);
3162
			this.scribe.printTrailingComment();
3164
			this.scribe.printTrailingComment();
3163
			switch(this.scribe.scanner.source[this.scribe.scanner.currentPosition]) {
3165
			switch(this.scribe.scanner.source[this.scribe.scanner.currentPosition]) {
Lines 4041-4047 Link Here
4041
4043
4042
		if (methodDeclaration.ignoreFurtherInvestigation) {
4044
		if (methodDeclaration.ignoreFurtherInvestigation) {
4043
			this.scribe.printComment();
4045
			this.scribe.printComment();
4044
			this.scribe.printIndentationIfNecessary();
4046
			if (this.scribe.indentationLevel != 0) {
4047
				this.scribe.printIndentationIfNecessary();
4048
			}
4045
			this.scribe.scanner.resetTo(methodDeclaration.declarationSourceEnd + 1, this.scribe.scannerEndPosition - 1);
4049
			this.scribe.scanner.resetTo(methodDeclaration.declarationSourceEnd + 1, this.scribe.scannerEndPosition - 1);
4046
			this.scribe.printTrailingComment();
4050
			this.scribe.printTrailingComment();
4047
			switch(this.scribe.scanner.source[this.scribe.scanner.currentPosition]) {
4051
			switch(this.scribe.scanner.source[this.scribe.scanner.currentPosition]) {
(-)formatter/org/eclipse/jdt/internal/formatter/DefaultCodeFormatterOptions.java (+9 lines)
Lines 117-122 Link Here
117
	public boolean indent_body_declarations_compare_to_enum_declaration_header;
117
	public boolean indent_body_declarations_compare_to_enum_declaration_header;
118
	public boolean indent_body_declarations_compare_to_type_header;
118
	public boolean indent_body_declarations_compare_to_type_header;
119
	public boolean indent_breaks_compare_to_cases;
119
	public boolean indent_breaks_compare_to_cases;
120
	public boolean indent_comments_on_first_column;
120
	public boolean indent_empty_lines;
121
	public boolean indent_empty_lines;
121
	public boolean indent_switchstatements_compare_to_cases;
122
	public boolean indent_switchstatements_compare_to_cases;
122
	public boolean indent_switchstatements_compare_to_switch;
123
	public boolean indent_switchstatements_compare_to_switch;
Lines 390-395 Link Here
390
		options.put(DefaultCodeFormatterConstants.FORMATTER_INDENT_BODY_DECLARATIONS_COMPARE_TO_ENUM_DECLARATION_HEADER, this.indent_body_declarations_compare_to_enum_declaration_header ? DefaultCodeFormatterConstants.TRUE : DefaultCodeFormatterConstants.FALSE);
391
		options.put(DefaultCodeFormatterConstants.FORMATTER_INDENT_BODY_DECLARATIONS_COMPARE_TO_ENUM_DECLARATION_HEADER, this.indent_body_declarations_compare_to_enum_declaration_header ? DefaultCodeFormatterConstants.TRUE : DefaultCodeFormatterConstants.FALSE);
391
		options.put(DefaultCodeFormatterConstants.FORMATTER_INDENT_BODY_DECLARATIONS_COMPARE_TO_TYPE_HEADER, this.indent_body_declarations_compare_to_type_header ? DefaultCodeFormatterConstants.TRUE : DefaultCodeFormatterConstants.FALSE);
392
		options.put(DefaultCodeFormatterConstants.FORMATTER_INDENT_BODY_DECLARATIONS_COMPARE_TO_TYPE_HEADER, this.indent_body_declarations_compare_to_type_header ? DefaultCodeFormatterConstants.TRUE : DefaultCodeFormatterConstants.FALSE);
392
		options.put(DefaultCodeFormatterConstants.FORMATTER_INDENT_BREAKS_COMPARE_TO_CASES, this.indent_breaks_compare_to_cases ? DefaultCodeFormatterConstants.TRUE : DefaultCodeFormatterConstants.FALSE);
393
		options.put(DefaultCodeFormatterConstants.FORMATTER_INDENT_BREAKS_COMPARE_TO_CASES, this.indent_breaks_compare_to_cases ? DefaultCodeFormatterConstants.TRUE : DefaultCodeFormatterConstants.FALSE);
394
		options.put(DefaultCodeFormatterConstants.FORMATTER_INDENT_COMMENTS_ON_FIRST_COLUMN, this.indent_comments_on_first_column ? DefaultCodeFormatterConstants.TRUE : DefaultCodeFormatterConstants.FALSE);
393
		options.put(DefaultCodeFormatterConstants.FORMATTER_INDENT_EMPTY_LINES, this.indent_empty_lines ? DefaultCodeFormatterConstants.TRUE : DefaultCodeFormatterConstants.FALSE);
395
		options.put(DefaultCodeFormatterConstants.FORMATTER_INDENT_EMPTY_LINES, this.indent_empty_lines ? DefaultCodeFormatterConstants.TRUE : DefaultCodeFormatterConstants.FALSE);
394
		options.put(DefaultCodeFormatterConstants.FORMATTER_INDENT_SWITCHSTATEMENTS_COMPARE_TO_CASES, this.indent_switchstatements_compare_to_cases ? DefaultCodeFormatterConstants.TRUE : DefaultCodeFormatterConstants.FALSE);
396
		options.put(DefaultCodeFormatterConstants.FORMATTER_INDENT_SWITCHSTATEMENTS_COMPARE_TO_CASES, this.indent_switchstatements_compare_to_cases ? DefaultCodeFormatterConstants.TRUE : DefaultCodeFormatterConstants.FALSE);
395
		options.put(DefaultCodeFormatterConstants.FORMATTER_INDENT_SWITCHSTATEMENTS_COMPARE_TO_SWITCH, this.indent_switchstatements_compare_to_switch ? DefaultCodeFormatterConstants.TRUE : DefaultCodeFormatterConstants.FALSE);
397
		options.put(DefaultCodeFormatterConstants.FORMATTER_INDENT_SWITCHSTATEMENTS_COMPARE_TO_SWITCH, this.indent_switchstatements_compare_to_switch ? DefaultCodeFormatterConstants.TRUE : DefaultCodeFormatterConstants.FALSE);
Lines 1100-1105 Link Here
1100
		if (indentBreaksCompareToCasesOption != null) {
1102
		if (indentBreaksCompareToCasesOption != null) {
1101
			this.indent_breaks_compare_to_cases = DefaultCodeFormatterConstants.TRUE.equals(indentBreaksCompareToCasesOption);
1103
			this.indent_breaks_compare_to_cases = DefaultCodeFormatterConstants.TRUE.equals(indentBreaksCompareToCasesOption);
1102
		}
1104
		}
1105
		final Object indentCommentsOnFirstColumnOption = settings.get(DefaultCodeFormatterConstants.FORMATTER_INDENT_COMMENTS_ON_FIRST_COLUMN);
1106
		if (indentCommentsOnFirstColumnOption != null) {
1107
			this.indent_comments_on_first_column = DefaultCodeFormatterConstants.TRUE.equals(indentCommentsOnFirstColumnOption);
1108
		}
1103
		final Object indentEmptyLinesOption = settings.get(DefaultCodeFormatterConstants.FORMATTER_INDENT_EMPTY_LINES);
1109
		final Object indentEmptyLinesOption = settings.get(DefaultCodeFormatterConstants.FORMATTER_INDENT_EMPTY_LINES);
1104
		if (indentEmptyLinesOption != null) {
1110
		if (indentEmptyLinesOption != null) {
1105
			this.indent_empty_lines = DefaultCodeFormatterConstants.TRUE.equals(indentEmptyLinesOption);
1111
			this.indent_empty_lines = DefaultCodeFormatterConstants.TRUE.equals(indentEmptyLinesOption);
Lines 1961-1966 Link Here
1961
		this.indent_body_declarations_compare_to_enum_declaration_header = true;
1967
		this.indent_body_declarations_compare_to_enum_declaration_header = true;
1962
		this.indent_body_declarations_compare_to_type_header = true;
1968
		this.indent_body_declarations_compare_to_type_header = true;
1963
		this.indent_breaks_compare_to_cases = true;
1969
		this.indent_breaks_compare_to_cases = true;
1970
		this.indent_comments_on_first_column = true;
1964
		this.indent_empty_lines = false;
1971
		this.indent_empty_lines = false;
1965
		this.indent_switchstatements_compare_to_cases = true;
1972
		this.indent_switchstatements_compare_to_cases = true;
1966
		this.indent_switchstatements_compare_to_switch = true;
1973
		this.indent_switchstatements_compare_to_switch = true;
Lines 2151-2156 Link Here
2151
		setJavaConventionsSettings();
2158
		setJavaConventionsSettings();
2152
		this.tab_char = TAB;
2159
		this.tab_char = TAB;
2153
		this.tab_size = 4;
2160
		this.tab_size = 4;
2161
		this.indent_comments_on_first_column = false;
2154
	}
2162
	}
2155
2163
2156
	public void setJavaConventionsSettings() {
2164
	public void setJavaConventionsSettings() {
Lines 2220-2225 Link Here
2220
		this.indent_body_declarations_compare_to_enum_declaration_header = true;
2228
		this.indent_body_declarations_compare_to_enum_declaration_header = true;
2221
		this.indent_body_declarations_compare_to_type_header = true;
2229
		this.indent_body_declarations_compare_to_type_header = true;
2222
		this.indent_breaks_compare_to_cases = true;
2230
		this.indent_breaks_compare_to_cases = true;
2231
		this.indent_comments_on_first_column = true;
2223
		this.indent_empty_lines = false;
2232
		this.indent_empty_lines = false;
2224
		this.indent_switchstatements_compare_to_cases = true;
2233
		this.indent_switchstatements_compare_to_cases = true;
2225
		this.indent_switchstatements_compare_to_switch = false;
2234
		this.indent_switchstatements_compare_to_switch = false;

Return to bug 20793