org.eclipse.jdt.core.ToolFactory.createCodeFormatter()方法的使用及代码示例

x33g5p2x  于2022-01-30 转载在 其他  
字(10.0k)|赞(0)|评价(0)|浏览(85)

本文整理了Java中org.eclipse.jdt.core.ToolFactory.createCodeFormatter()方法的一些代码示例,展示了ToolFactory.createCodeFormatter()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ToolFactory.createCodeFormatter()方法的具体详情如下:
包路径:org.eclipse.jdt.core.ToolFactory
类名称:ToolFactory
方法名:createCodeFormatter

ToolFactory.createCodeFormatter介绍

[英]Create an instance of a code formatter. A code formatter implementation can be contributed via the extension point "org.eclipse.jdt.core.codeFormatter". If unable to find a registered extension, the factory will default to using the default code formatter.
[中]创建代码格式化程序的实例。代码格式化程序实现可以通过扩展点“org.eclipse.jdt.core.codeFormatter”提供。如果找不到注册的扩展名,工厂将默认使用默认的代码格式化程序。

代码示例

代码示例来源:origin: aws/aws-sdk-java

/**
 * Creates a JavaCodeFormatter using the default formatter options and
 * optionally applying user provided options on top.
 *
 * @param overrideOptions user provided options to apply on top of defaults
 */
public JavaCodeFormatter(final Map<String, Object> overrideOptions) {
  Map formatterOptions = new HashMap<>(DEFAULT_FORMATTER_OPTIONS);
  if (overrideOptions != null) {
    formatterOptions.putAll(overrideOptions);
  }
  this.codeFormatter = ToolFactory.createCodeFormatter(formatterOptions,
      ToolFactory.M_FORMAT_EXISTING);
}

代码示例来源:origin: org.eclipse/org.eclipse.jst.jsp.core

private CodeFormatter getCodeFormatter() {
  if (fCodeFormatter == null)
    fCodeFormatter = ToolFactory.createCodeFormatter(null);
  return fCodeFormatter;
}

代码示例来源:origin: org.eclipse.emf/org.eclipse.emf.codegen.ecore

/**
 * Creates and returns a new JDT code formatter.
 *
 * @deprecated In EMF 2.2, a {@link org.eclipse.emf.codegen.ecore.generator.GeneratorAdapter GeneratorAdapter} should be used to
 * implement code generation. {@link org.eclipse.emf.codegen.ecore.generator.AbstractGeneratorAdapter AbstractGeneratorAdapter} provides
 * an equivalent to this method. This method will be removed after 2.2.
 */
@Deprecated
public CodeFormatter createCodeFormatter()
{
 return ToolFactory.createCodeFormatter(codeFormatterOptions);
}

代码示例来源:origin: org.eclipse/org.eclipse.emf.codegen.ecore

/**
 * Creates and returns a new JDT code formatter.
 * 
 * @deprecated In EMF 2.2, a {@link org.eclipse.emf.codegen.ecore.generator.GeneratorAdapter GeneratorAdapter} should be used to
 * implement code generation. {@link org.eclipse.emf.codegen.ecore.generator.AbstractGeneratorAdapter AbstractGeneratorAdapter} provides
 * an equivalent to this method. This method will be removed after 2.2.
 */
@Deprecated
public CodeFormatter createCodeFormatter()
{
 return ToolFactory.createCodeFormatter(codeFormatterOptions);
}

代码示例来源:origin: aws/aws-sdk-java-v2

/**
 * Creates a JavaCodeFormatter using the default formatter options and
 * optionally applying user provided options on top.
 *
 * @param overrideOptions user provided options to apply on top of defaults
 */
public JavaCodeFormatter(final Map<String, Object> overrideOptions) {
  Map formatterOptions = new HashMap<>(DEFAULT_FORMATTER_OPTIONS);
  if (overrideOptions != null) {
    formatterOptions.putAll(overrideOptions);
  }
  this.codeFormatter = ToolFactory.createCodeFormatter(formatterOptions,
                             ToolFactory.M_FORMAT_EXISTING);
}

代码示例来源:origin: com.amazonaws/aws-java-sdk-code-generator

/**
 * Creates a JavaCodeFormatter using the default formatter options and
 * optionally applying user provided options on top.
 *
 * @param overrideOptions user provided options to apply on top of defaults
 */
public JavaCodeFormatter(final Map<String, Object> overrideOptions) {
  Map formatterOptions = new HashMap<>(DEFAULT_FORMATTER_OPTIONS);
  if (overrideOptions != null) {
    formatterOptions.putAll(overrideOptions);
  }
  this.codeFormatter = ToolFactory.createCodeFormatter(formatterOptions,
      ToolFactory.M_FORMAT_EXISTING);
}

代码示例来源:origin: aws/aws-sdk-java-v2

/**
 * Creates a JavaCodeFormatter using the default formatter options and
 * optionally applying user provided options on top.
 *
 * @param overrideOptions user provided options to apply on top of defaults
 */
public JavaCodeFormatter(final Map<String, Object> overrideOptions) {
  Map formatterOptions = new HashMap<>(DEFAULT_FORMATTER_OPTIONS);
  if (overrideOptions != null) {
    formatterOptions.putAll(overrideOptions);
  }
  this.codeFormatter = ToolFactory.createCodeFormatter(formatterOptions,
                             ToolFactory.M_FORMAT_EXISTING);
}

代码示例来源:origin: youribonnaffe/gradle-format-plugin

public JavaFormatter(Properties settings) {
  if (settings == null) {
    // if no settings run with jdk 5 as default
    settings = new Properties();
    settings.put(JavaCore.COMPILER_SOURCE, "1.5");
    settings.put(JavaCore.COMPILER_COMPLIANCE, "1.5");
    settings.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, "1.5");
  }
  this.codeFormatter = ToolFactory.createCodeFormatter(settings);
}

代码示例来源:origin: com.marvinformatics.formatter/jdt-core

public JavaFormatter(
    Map<String, String> options,
    String compilerSources,
    String compilerCompliance,
    String compilerCodegenTargetPlatform,
    String lineEnding) {
  options.put(JavaCore.COMPILER_SOURCE, compilerSources);
  options.put(JavaCore.COMPILER_COMPLIANCE, compilerCompliance);
  options.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, compilerCodegenTargetPlatform);
  formatter = ToolFactory.createCodeFormatter(options);
  this.lineEnding = lineEnding;
}

代码示例来源:origin: org.hibernate/hibernate-tools

public JavaFormatter(Map<Object, Object> settings) {
  if(settings==null) {
    // if no settings run with jdk 5 as default 
    settings = new HashMap<Object, Object>();
    settings.put( JavaCore.COMPILER_SOURCE, "1.5");
    settings.put( JavaCore.COMPILER_COMPLIANCE, "1.5");
    settings.put( JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, "1.5");			
  }
  
  this.codeFormatter = ToolFactory.createCodeFormatter(settings);
}

代码示例来源:origin: hibernate/hibernate-tools

public Formatter(Map<Object, Object> settings) {
  if(settings==null) {
    // if no settings run with jdk 5 as default 
    settings = new HashMap<Object, Object>();
    settings.put( JavaCore.COMPILER_SOURCE, "1.5");
    settings.put( JavaCore.COMPILER_COMPLIANCE, "1.5");
    settings.put( JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, "1.5");			
  }
  
  this.codeFormatter = ToolFactory.createCodeFormatter(settings);
}

代码示例来源:origin: com.marvinformatics.formatter/java-formatter

public JavaFormatter(
    Map<String, String> options,
    String compilerSources,
    String compilerCompliance,
    String compilerCodegenTargetPlatform,
    LineEnding lineEnding) {
  options.put(JavaCore.COMPILER_SOURCE, compilerSources);
  options.put(JavaCore.COMPILER_COMPLIANCE, compilerCompliance);
  options.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, compilerCodegenTargetPlatform);
  formatter = ToolFactory.createCodeFormatter(new HashMap<>(options));
  this.lineEnding = lineEnding;
}

代码示例来源:origin: org.eclipse/org.eclipse.jdt.ui

/**
 * Creates edits that describe how to format the given string. Returns <code>null</code> if the code could not be formatted for the given kind.
 * @throws IllegalArgumentException If the offset and length are not inside the string, a
 *  IllegalArgumentException is thrown.
 */
public static TextEdit format2(int kind, String string, int offset, int length, int indentationLevel, String lineSeparator, Map options) {
  if (offset < 0 || length < 0 || offset + length > string.length()) {
    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$
  }
  return ToolFactory.createCodeFormatter(options).format(kind, string, offset, length, indentationLevel, lineSeparator);
}

代码示例来源:origin: org.eclipse/org.eclipse.jdt.ui

public static TextEdit reformat(int kind, String string, int offset, int length, int indentationLevel, String lineSeparator, Map options) {
  if (offset < 0 || length < 0 || offset + length > string.length()) {
    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$
  }
  return ToolFactory.createCodeFormatter(options, ToolFactory.M_FORMAT_EXISTING).format(kind, string, offset, length, indentationLevel, lineSeparator);
}

代码示例来源:origin: net.revelc.code/formatter-maven-plugin

/**
 * Create a {@link CodeFormatter} instance to be used by this mojo.
 *
 * @throws MojoExecutionException the mojo execution exception
 */
private void createCodeFormatter() throws MojoExecutionException {
  Map<String, String> options = getFormattingOptions();
  this.formatter = ToolFactory.createCodeFormatter(options);
}

代码示例来源:origin: org.eclipse.scout.sdk.deps/org.eclipse.jdt.core

public TextEdit formatString(int kind, String string, int offset, int length, int indentationLevel) {
  return ToolFactory.createCodeFormatter(this.options).format(kind, string, offset, length, indentationLevel, this.lineDelimiter);
}

代码示例来源:origin: com.google.code.maven-play-plugin.org.eclipse.jdt/org.eclipse.jdt.core

public TextEdit formatString(int kind, String string, int offset, int length, int indentationLevel) {
  return ToolFactory.createCodeFormatter(this.options).format(kind, string, offset, length, indentationLevel, this.lineDelimiter);
}

代码示例来源:origin: org.jboss.forge/roaster-jdt

public static String format(String source)
{
  // TODO locate user's eclipse project settings, use those if we can.
  Properties options = readConfig("org.eclipse.jdt.core.prefs");
  final CodeFormatter codeFormatter = ToolFactory.createCodeFormatter(options);
  return ensureCorrectNewLines(formatFile(source, codeFormatter));
}

代码示例来源:origin: org.eclipse/org.eclipse.jdt.ui

/**
 * Creates a string that represents the given number of indentation units.
 * The returned string can contain tabs and/or spaces depending on the core
 * formatter preferences.
 * 
 * @param indentationUnits the number of indentation units to generate
 * @param project the project from which to get the formatter settings,
 *        <code>null</code> if the workspace default should be used
 * @return the indent string
 */
public static String createIndentString(int indentationUnits, IJavaProject project) {
  Map options= project != null ? project.getOptions(true) : JavaCore.getOptions();		
  return ToolFactory.createCodeFormatter(options).createIndentationString(indentationUnits);
}

代码示例来源:origin: ma.glasnost.orika/orika-eclipse-tools

public EclipseJdtCompiler(ClassLoader parentLoader) {
  this.byteCodeClassLoader = new ByteCodeClassLoader(parentLoader);
  this.formatter = ToolFactory
      .createCodeFormatter(getFormattingOptions());
  this.compilerNameEnvironment = new NameEnvironment(
      this.byteCodeClassLoader);
  this.compilerRequester = new CompilerRequestor();
  this.compiler = new Compiler(compilerNameEnvironment,
      DefaultErrorHandlingPolicies.proceedWithAllProblems(),
      getCompilerOptions(), compilerRequester,
      new DefaultProblemFactory(Locale.getDefault()));
}

相关文章