本文整理汇总了Java中org.eclipse.jdt.core.formatter.DefaultCodeFormatterConstants.getEclipseDefaultSettings方法的典型用法代码示例。如果您正苦于以下问题:Java DefaultCodeFormatterConstants.getEclipseDefaultSettings方法的具体用法?Java DefaultCodeFormatterConstants.getEclipseDefaultSettings怎么用?Java DefaultCodeFormatterConstants.getEclipseDefaultSettings使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.jdt.core.formatter.DefaultCodeFormatterConstants
的用法示例。
在下文中一共展示了DefaultCodeFormatterConstants.getEclipseDefaultSettings方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: formatUnitSourceCode
import org.eclipse.jdt.core.formatter.DefaultCodeFormatterConstants; //导入方法依赖的package包/类
/**
* Format a Unit Source Code
*
* @param testInterface
* @param monitor
* @throws CoreException
*/
@SuppressWarnings("unchecked")
public static void formatUnitSourceCode(IFile file, IProgressMonitor monitor) throws CoreException {
@SuppressWarnings("rawtypes")
SubMonitor subMonitor = SubMonitor.convert(monitor, 100);
ICompilationUnit unit = JavaCore.createCompilationUnitFrom(file);
subMonitor.split(50);
ICompilationUnit workingCopy = unit.getWorkingCopy(monitor);
Map options = DefaultCodeFormatterConstants.getEclipseDefaultSettings();
options.put(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_7);
options.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_1_7);
options.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_7);
options.put(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_ENUM_CONSTANTS,
DefaultCodeFormatterConstants.createAlignmentValue(true,
DefaultCodeFormatterConstants.WRAP_ONE_PER_LINE,
DefaultCodeFormatterConstants.INDENT_ON_COLUMN));
final CodeFormatter codeFormatter = ToolFactory.createCodeFormatter(options);
ISourceRange range = unit.getSourceRange();
TextEdit formatEdit = codeFormatter.format(CodeFormatter.K_COMPILATION_UNIT, unit.getSource(),
range.getOffset(), range.getLength(), 0, null);
subMonitor.split(30);
if (formatEdit != null /* && formatEdit.hasChildren()*/) {
workingCopy.applyTextEdit(formatEdit, monitor);
workingCopy.reconcile(ICompilationUnit.NO_AST, false, null, null);
workingCopy.commitWorkingCopy(true, null);
workingCopy.discardWorkingCopy();
}
file.refreshLocal(IResource.DEPTH_INFINITE, subMonitor);
subMonitor.split(20);
}
示例2: getDefaultFormatSettings
import org.eclipse.jdt.core.formatter.DefaultCodeFormatterConstants; //导入方法依赖的package包/类
public static Map<String, String> getDefaultFormatSettings() {
if (formatSettings != null && !formatSettings.isEmpty()) {
return formatSettings;
}
formatSettings = new CheCodeFormatterOptions().getCheDefaultSettings();
if (formatSettings != null && !formatSettings.isEmpty()) {
return formatSettings;
}
return DefaultCodeFormatterConstants.getEclipseDefaultSettings();
}
示例3: setFormatterSettings
import org.eclipse.jdt.core.formatter.DefaultCodeFormatterConstants; //导入方法依赖的package包/类
@SuppressWarnings({"unchecked", "deprecation"})
public void setFormatterSettings(List<Setting> settings) {
// // change the option to wrap each enum constant on a new line
// options.put(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_ENUM_CONSTANTS,
// DefaultCodeFormatterConstants.createAlignmentValue(true,
// DefaultCodeFormatterConstants.WRAP_ONE_PER_LINE,
// DefaultCodeFormatterConstants.INDENT_ON_COLUMN));
//
if (settings != null) {
options = newHashMap();
for (Setting s : settings) {
options.put(s.getId(), s.getValue());
}
} else {
options = DefaultCodeFormatterConstants.getEclipseDefaultSettings();
options.put(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_8);
options.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_1_8);
options.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_8);
options.put(JavaCore.FORMATTER_LINE_SPLIT, "160");
options.put(JavaCore.FORMATTER_TAB_CHAR, JavaCore.SPACE);
options.put(JavaCore.FORMATTER_TAB_SIZE, "4");
}
// instanciate the default code formatter with the given options
codeFormatter = ToolFactory.createCodeFormatter(options);
}
示例4: getEclipseSettings
import org.eclipse.jdt.core.formatter.DefaultCodeFormatterConstants; //导入方法依赖的package包/类
/**
* @return Returns the settings for the new eclipse profile.
*/
public static Map<String, String> getEclipseSettings() {
final Map<String, String> options= DefaultCodeFormatterConstants.getEclipseDefaultSettings();
ProfileVersioner.setLatestCompliance(options);
return options;
}