Java Code Examples for org.eclipse.jdt.internal.compiler.util.Util#LINE_SEPARATOR

The following examples show how to use org.eclipse.jdt.internal.compiler.util.Util#LINE_SEPARATOR . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DefaultCodeFormatter.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private TextEdit formatComment(int kind, String source, int indentationLevel, String lineSeparator, IRegion[] regions) {
	Object oldOption = oldCommentFormatOption();
	boolean isFormattingComments = false;
	if (oldOption == null) {
		switch (kind & K_MASK) {
			case K_SINGLE_LINE_COMMENT:
				isFormattingComments = DefaultCodeFormatterConstants.TRUE.equals(this.options.get(DefaultCodeFormatterConstants.FORMATTER_COMMENT_FORMAT_LINE_COMMENT));
				break;
			case K_MULTI_LINE_COMMENT:
				isFormattingComments = DefaultCodeFormatterConstants.TRUE.equals(this.options.get(DefaultCodeFormatterConstants.FORMATTER_COMMENT_FORMAT_BLOCK_COMMENT));
				break;
			case K_JAVA_DOC:
				isFormattingComments = DefaultCodeFormatterConstants.TRUE.equals(this.options.get(DefaultCodeFormatterConstants.FORMATTER_COMMENT_FORMAT_JAVADOC_COMMENT));
		}
	} else {
		isFormattingComments = DefaultCodeFormatterConstants.TRUE.equals(oldOption);
	}
	if (isFormattingComments) {
		if (lineSeparator != null) {
			this.preferences.line_separator = lineSeparator;
		} else {
			this.preferences.line_separator = Util.LINE_SEPARATOR;
		}
		this.preferences.initial_indentation_level = indentationLevel;
		if (this.codeSnippetParsingUtil == null) this.codeSnippetParsingUtil = new CodeSnippetParsingUtil();
		this.codeSnippetParsingUtil.parseCompilationUnit(source.toCharArray(), getDefaultCompilerOptions(), true);
		this.newCodeFormatter = new CodeFormatterVisitor(this.preferences, this.options, regions, this.codeSnippetParsingUtil, true);
		IRegion coveredRegion = getCoveredRegion(regions);
		int start = coveredRegion.getOffset();
		int end = start + coveredRegion.getLength();
		this.newCodeFormatter.formatComment(kind, source, start, end, indentationLevel);
		return this.newCodeFormatter.scribe.getRootEdit();
	}
	return null;
}
 
Example 2
Source File: DefaultCodeFormatter.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private TextEdit formatCompilationUnit(String source, int indentationLevel, String lineSeparator, IRegion[] regions, boolean includeComments) {
	CompilationUnitDeclaration compilationUnitDeclaration = this.codeSnippetParsingUtil.parseCompilationUnit(source.toCharArray(), getDefaultCompilerOptions(), true);

	if (lineSeparator != null) {
		this.preferences.line_separator = lineSeparator;
	} else {
		this.preferences.line_separator = Util.LINE_SEPARATOR;
	}
	this.preferences.initial_indentation_level = indentationLevel;

	this.newCodeFormatter = new CodeFormatterVisitor(this.preferences, this.options, regions, this.codeSnippetParsingUtil, includeComments);

	return this.newCodeFormatter.format(source, compilationUnitDeclaration);
}
 
Example 3
Source File: DefaultCodeFormatter.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private TextEdit internalFormatClassBodyDeclarations(String source, int indentationLevel, String lineSeparator, ASTNode[] bodyDeclarations, IRegion[] regions, boolean includeComments) {
	if (lineSeparator != null) {
		this.preferences.line_separator = lineSeparator;
	} else {
		this.preferences.line_separator = Util.LINE_SEPARATOR;
	}
	this.preferences.initial_indentation_level = indentationLevel;

	this.newCodeFormatter = new CodeFormatterVisitor(this.preferences, this.options, regions, this.codeSnippetParsingUtil, includeComments);
	return this.newCodeFormatter.format(source, bodyDeclarations);
}
 
Example 4
Source File: DefaultCodeFormatter.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private TextEdit internalFormatExpression(String source, int indentationLevel, String lineSeparator, Expression expression, IRegion[] regions, boolean includeComments) {
	if (lineSeparator != null) {
		this.preferences.line_separator = lineSeparator;
	} else {
		this.preferences.line_separator = Util.LINE_SEPARATOR;
	}
	this.preferences.initial_indentation_level = indentationLevel;

	this.newCodeFormatter = new CodeFormatterVisitor(this.preferences, this.options, regions, this.codeSnippetParsingUtil, includeComments);

	TextEdit textEdit = this.newCodeFormatter.format(source, expression);
	return textEdit;
}
 
Example 5
Source File: DefaultCodeFormatter.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private TextEdit internalFormatStatements(String source, int indentationLevel, String lineSeparator, ConstructorDeclaration constructorDeclaration, IRegion[] regions, boolean includeComments) {
	if (lineSeparator != null) {
		this.preferences.line_separator = lineSeparator;
	} else {
		this.preferences.line_separator = Util.LINE_SEPARATOR;
	}
	this.preferences.initial_indentation_level = indentationLevel;

	this.newCodeFormatter = new CodeFormatterVisitor(this.preferences, this.options, regions, this.codeSnippetParsingUtil, includeComments);

	return this.newCodeFormatter.format(source, constructorDeclaration);
}