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

Collapse All | Expand All

(-)core extension/org/eclipse/jdt/internal/corext/util/CodeFormatterUtil.java (-4 / +4 lines)
Lines 233-247 Link Here
233
		return format2(kind, string, 0, string.length(), indentationLevel, lineSeparator, options);
233
		return format2(kind, string, 0, string.length(), indentationLevel, lineSeparator, options);
234
	}
234
	}
235
	
235
	
236
	public static TextEdit reFormat(int kind, String string, int offset, int length, int indentationLevel, String lineSeparator, Map options) {
236
	public static TextEdit reformat(int kind, String string, int offset, int length, int indentationLevel, String lineSeparator, Map options) {
237
		if (offset < 0 || length < 0 || offset + length > string.length()) {
237
		if (offset < 0 || length < 0 || offset + length > string.length()) {
238
			throw new IllegalArgumentException("offset or length outside of string. offset: " + offset + ", length: " + length + ", string size: " + string.length());   //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
238
			throw new IllegalArgumentException("offset or length outside of string. offset: " + offset + ", length: " + length + ", string size: " + string.length());   //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
239
		}
239
		}
240
		return ToolFactory.createCodeFormatter(options, ToolFactory.M_FORMAT_HONOR_NEVER_INDENT_COMMENT_OPTIONS).format(kind, string, offset, length, indentationLevel, lineSeparator);
240
		return ToolFactory.createCodeFormatter(options, ToolFactory.M_FORMAT_EXISTING).format(kind, string, offset, length, indentationLevel, lineSeparator);
241
	}
241
	}
242
	
242
	
243
	public static TextEdit reFormat(int kind, String string, int indentationLevel, String lineSeparator, Map options) {
243
	public static TextEdit reformat(int kind, String string, int indentationLevel, String lineSeparator, Map options) {
244
		return reFormat(kind, string, 0, string.length(), indentationLevel, lineSeparator, options);
244
		return reformat(kind, string, 0, string.length(), indentationLevel, lineSeparator, options);
245
	}
245
	}
246
	
246
	
247
	/**
247
	/**
(-)ui/org/eclipse/jdt/internal/ui/fix/CodeFormatFix.java (-1 / +1 lines)
Lines 53-59 Link Here
53
			String content= cu.getBuffer().getContents();
53
			String content= cu.getBuffer().getContents();
54
			Document document= new Document(content);
54
			Document document= new Document(content);
55
			
55
			
56
			TextEdit edit= CodeFormatterUtil.reFormat(CodeFormatter.K_COMPILATION_UNIT, content, 0, TextUtilities.getDefaultLineDelimiter(document), fomatterSettings);
56
			TextEdit edit= CodeFormatterUtil.reformat(CodeFormatter.K_COMPILATION_UNIT, content, 0, TextUtilities.getDefaultLineDelimiter(document), fomatterSettings);
57
			if (edit == null || !edit.hasChildren())
57
			if (edit == null || !edit.hasChildren())
58
				return null;
58
				return null;
59
			
59
			
(-)ui/org/eclipse/jdt/internal/ui/text/java/JavaFormattingStrategy.java (-1 / +1 lines)
Lines 61-67 Link Here
61
			Map partitioners= null;
61
			Map partitioners= null;
62
			try {
62
			try {
63
63
64
				final TextEdit edit= CodeFormatterUtil.reFormat(CodeFormatter.K_COMPILATION_UNIT, document.get(), partition.getOffset(), partition.getLength(), 0, TextUtilities.getDefaultLineDelimiter(document), getPreferences());
64
				final TextEdit edit= CodeFormatterUtil.reformat(CodeFormatter.K_COMPILATION_UNIT, document.get(), partition.getOffset(), partition.getLength(), 0, TextUtilities.getDefaultLineDelimiter(document), getPreferences());
65
				if (edit != null) {
65
				if (edit != null) {
66
					if (edit.getChildrenSize() > 20)
66
					if (edit.getChildrenSize() > 20)
67
						partitioners= TextUtilities.removeDocumentPartitioners(document);
67
						partitioners= TextUtilities.removeDocumentPartitioners(document);
(-)ui/org/eclipse/jdt/internal/ui/text/comment/CommentFormattingStrategy.java (-1 / +1 lines)
Lines 115-121 Link Here
115
				int partitionOffset= position.getOffset() - sourceOffset;
115
				int partitionOffset= position.getOffset() - sourceOffset;
116
				int sourceLength= partitionOffset + position.getLength();
116
				int sourceLength= partitionOffset + position.getLength();
117
				String source= document.get(sourceOffset, sourceLength);
117
				String source= document.get(sourceOffset, sourceLength);
118
				CodeFormatter commentFormatter= ToolFactory.createCodeFormatter(preferences, ToolFactory.M_FORMAT_HONOR_NEVER_INDENT_COMMENT_OPTIONS);
118
				CodeFormatter commentFormatter= ToolFactory.createCodeFormatter(preferences, ToolFactory.M_FORMAT_EXISTING);
119
				int indentationLevel= inferIndentationLevel(source.substring(0, partitionOffset), getTabSize(preferences), getIndentSize(preferences));
119
				int indentationLevel= inferIndentationLevel(source.substring(0, partitionOffset), getTabSize(preferences), getIndentSize(preferences));
120
				edit= commentFormatter.format(getKindForPartitionType(position.getType()), source, partitionOffset, position.getLength(), indentationLevel, TextUtilities.getDefaultLineDelimiter(document));
120
				edit= commentFormatter.format(getKindForPartitionType(position.getType()), source, partitionOffset, position.getLength(), indentationLevel, TextUtilities.getDefaultLineDelimiter(document));
121
121

Return to bug 188650