• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java DefaultCodeFormatter类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.eclipse.jdt.internal.formatter.DefaultCodeFormatter的典型用法代码示例。如果您正苦于以下问题:Java DefaultCodeFormatter类的具体用法?Java DefaultCodeFormatter怎么用?Java DefaultCodeFormatter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



DefaultCodeFormatter类属于org.eclipse.jdt.internal.formatter包,在下文中一共展示了DefaultCodeFormatter类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: testFormatDefault

import org.eclipse.jdt.internal.formatter.DefaultCodeFormatter; //导入依赖的package包/类
/**
 * Format files using code formatter default options.
 */
public void testFormatDefault() throws CoreException {
  for (int i = 0; i < FORMAT_FILES.length; i++) {
    if (DACAPO_PRINT)
      System.out.print(".");
    IJavaElement element = JDT_CORE_PROJECT.findType(FORMAT_FILES[i]);
    String source = ((ICompilationUnit) element.getParent()).getSource();
    for (int j = 0; j < 2; j++)
      new DefaultCodeFormatter().format(CodeFormatter.K_COMPILATION_UNIT, source, 0, source.length(), 0, null);
  }
}
 
开发者ID:RuiChen08,项目名称:dacapobench,代码行数:14,代码来源:FullSourceWorkspaceFormatterTests.java


示例2: format

import org.eclipse.jdt.internal.formatter.DefaultCodeFormatter; //导入依赖的package包/类
public static String format(String code, Map<String, String> options) {
    DefaultCodeFormatterOptions cfOptions = DefaultCodeFormatterOptions.getJavaConventionsSettings();
    cfOptions.tab_char = DefaultCodeFormatterOptions.TAB;
    CodeFormatter cf = new DefaultCodeFormatter(cfOptions, options);
    TextEdit te = cf.format(CodeFormatter.K_UNKNOWN, code, 0, code.length(), 0, null);
    IDocument dc = new Document(code);

    try {
        te.apply(dc);
    } catch (Exception e) {
        throw new MinnalGeneratorException("Failed while formatting the code", e);
    }
    return dc.get();
}
 
开发者ID:minnal,项目名称:minnal,代码行数:15,代码来源:CodeUtils.java


示例3: createCodeFormatter

import org.eclipse.jdt.internal.formatter.DefaultCodeFormatter; //导入依赖的package包/类
/**
 * Create an instance of the built-in code formatter.
 *
 * <p>The given options should at least provide the source level ({@link
 * org.eclipse.jdt.core.JavaCore#COMPILER_SOURCE}), the compiler compliance level ({@link
 * org.eclipse.jdt.core.JavaCore#COMPILER_COMPLIANCE}) and the target platform ({@link
 * org.eclipse.jdt.core.JavaCore#COMPILER_CODEGEN_TARGET_PLATFORM}). Without these options, it is
 * not possible for the code formatter to know what kind of source it needs to format.
 *
 * <p>The given mode determines what options should be enabled when formatting the code. It can
 * have the following values: {@link #M_FORMAT_NEW}, {@link #M_FORMAT_EXISTING}, but other values
 * may be added in the future.
 *
 * @param options the options map to use for formatting with the default code formatter.
 *     Recognized options are documented on <code>JavaCore#getDefaultOptions()</code>. If set to
 *     <code>null</code>, then use the current settings from <code>JavaCore#getOptions</code>.
 * @param mode the given mode to modify the given options.
 * @return an instance of the built-in code formatter
 * @see org.eclipse.jdt.core.formatter.CodeFormatter
 * @see org.eclipse.jdt.core.JavaCore#getOptions()
 * @since 3.3
 */
public static CodeFormatter createCodeFormatter(Map options, int mode) {
  if (options == null) options = org.eclipse.jdt.core.JavaCore.getOptions();
  Map currentOptions = new HashMap(options);
  if (mode == M_FORMAT_NEW) {
    // disable the option for not formatting comments starting on first column
    currentOptions.put(
        DefaultCodeFormatterConstants
            .FORMATTER_COMMENT_FORMAT_LINE_COMMENT_STARTING_ON_FIRST_COLUMN,
        DefaultCodeFormatterConstants.TRUE);
    // disable the option for not indenting comments starting on first column
    currentOptions.put(
        DefaultCodeFormatterConstants.FORMATTER_NEVER_INDENT_BLOCK_COMMENTS_ON_FIRST_COLUMN,
        DefaultCodeFormatterConstants.FALSE);
    currentOptions.put(
        DefaultCodeFormatterConstants.FORMATTER_NEVER_INDENT_LINE_COMMENTS_ON_FIRST_COLUMN,
        DefaultCodeFormatterConstants.FALSE);
  }
  return new DefaultCodeFormatter(currentOptions);
}
 
开发者ID:eclipse,项目名称:che,代码行数:42,代码来源:ToolFactory.java


示例4: format

import org.eclipse.jdt.internal.formatter.DefaultCodeFormatter; //导入依赖的package包/类
public static TextEdit format(IDocument document, TypedPosition partition,
    Map<String, String> javaFormattingPrefs,
    Map<String, String> javaScriptFormattingPrefs, String original) {
  try {
    // Extract the JSNI block out of the document
    int offset = partition.getOffset();
    int length = partition.getLength();

    // Determine the line delimiter, indent string, and tab/indent widths
    String lineDelimiter = TextUtilities.getDefaultLineDelimiter(document);
    int tabWidth = IndentManipulation.getTabWidth(javaFormattingPrefs);
    int indentWidth = IndentManipulation.getIndentWidth(javaFormattingPrefs);

    // Get indentation level of the first line of the JSNI block (this should
    // be the line containing the JSNI method declaration)
    int methodDeclarationOffset = getMethodDeclarationOffset(document, offset);
    int jsniLine1 = document.getLineOfOffset(methodDeclarationOffset);
    int methodIndentLevel = getLineIndentLevel(document, jsniLine1, tabWidth,
        indentWidth);
    DefaultCodeFormatter defaultCodeFormatter = new DefaultCodeFormatter(
        javaFormattingPrefs);
    String indentLine = defaultCodeFormatter.createIndentationString(methodIndentLevel);

    // Extract the JSNI body out of the block and split it up by line
    String jsniSource = document.get(offset, length);
    String body = JsniParser.extractMethodBody(jsniSource);

    String formattedJs;

    // JSNI Java references mess up the JS formatter, so replace them
    // with place holder values
    JsniJavaRefReplacementResult replacementResults = replaceJsniJavaRefs(body);
    body = replacementResults.getJsni();

    TextEdit formatEdit = CodeFormatterUtil.format2(
        CodeFormatter.K_STATEMENTS, body, methodIndentLevel + 1,
        lineDelimiter, javaScriptFormattingPrefs);

    if (formatEdit != null) {

      body = restoreJsniJavaRefs(replacementResults);

      Document d = new Document(body);
      formatEdit.apply(d);

      formattedJs = d.get();

      if (!formattedJs.startsWith(lineDelimiter)) {
        formattedJs = lineDelimiter + formattedJs;
      }

      if (!formattedJs.endsWith(lineDelimiter)) {
        formattedJs = formattedJs + lineDelimiter;
      }

      formattedJs = formattedJs + indentLine;

      formattedJs = "/*-{" + formattedJs + "}-*/";

    } else {

      if (original == null) {
        return null;
      }

      formattedJs = original; // formatting failed, use the original string
    }

    return new ReplaceEdit(offset, length, formattedJs);

  } catch (Exception e) {
    GWTPluginLog.logError(e);
    return null;
  }
}
 
开发者ID:gwt-plugins,项目名称:gwt-eclipse-plugin,代码行数:76,代码来源:JsniFormattingUtil.java


示例5: getIndentToken

import org.eclipse.jdt.internal.formatter.DefaultCodeFormatter; //导入依赖的package包/类
private String getIndentToken() {
  return new DefaultCodeFormatter((Map<String, String>) prefs).createIndentationString(1);
}
 
开发者ID:gwt-plugins,项目名称:gwt-eclipse-plugin,代码行数:4,代码来源:JsniAutoEditStrategy.java


示例6: format

import org.eclipse.jdt.internal.formatter.DefaultCodeFormatter; //导入依赖的package包/类
public TextEdit format(IDocument document, TypedPosition partition, Map<String, String> javaFormattingPrefs,
					   Map<String, String> javaScriptFormattingPrefs, String original) {
	try {
		// Extract the JSNI block out of the document
		int offset = partition.getOffset();
		int length = partition.getLength();

		// Determine the line delimiter, indent string, and tab/indent widths
		String lineDelimiter = Settings.LINE_SEPARATOR;
		int tabWidth = IndentManipulation.getTabWidth(javaFormattingPrefs);
		int indentWidth = IndentManipulation.getIndentWidth(javaFormattingPrefs);

		// Get indentation level of the first line of the JSNI block (this should
		// be the line containing the JSNI method declaration)
		int methodDeclarationOffset = getMethodDeclarationOffset(document, offset);

		int jsniLine1 = document.getLineOfOffset(methodDeclarationOffset);
		int methodIndentLevel = getLineIndentLevel(document, jsniLine1, tabWidth, indentWidth);
		DefaultCodeFormatter defaultCodeFormatter = new DefaultCodeFormatter(javaFormattingPrefs);
		String indentLine = defaultCodeFormatter.createIndentationString(methodIndentLevel);

		// Extract the JSNI body out of the block and split it up by line
		String jsniSource = document.get(offset, length);
		String body = JsniParser.extractMethodBody(jsniSource);

		String formattedJs;

		// JSNI Java references mess up the JS formatter, so replace them
		// with place holder values
		JsniJavaRefReplacementResult replacementResults = replaceJsniJavaRefs(body);
		body = replacementResults.getJsni();
		CodeFormatter codeFormatter = ToolFactory.createCodeFormatter(javaScriptFormattingPrefs);

		TextEdit formatEdit = codeFormatter.format(CodeFormatter.K_STATEMENTS, body, 0, body.length(),
				methodIndentLevel + 1, lineDelimiter);

		if (formatEdit != null) {

			body = restoreJsniJavaRefs(replacementResults);

			Document d = new Document(body);
			formatEdit.apply(d);

			formattedJs = d.get();

			if (!formattedJs.startsWith(lineDelimiter)) {
				formattedJs = lineDelimiter + formattedJs;
			}

			if (!formattedJs.endsWith(lineDelimiter)) {
				formattedJs = formattedJs + lineDelimiter;
			}

			formattedJs = formattedJs + indentLine;

			formattedJs = "/*-{" + formattedJs + "}-*/";

		} else {

			if (original == null) {
				return null;
			}

			formattedJs = original; // formatting failed, use the original string
		}

		return new ReplaceEdit(offset, length, formattedJs);

	} catch (Exception e) {
		throw new RuntimeException(e);
	}
}
 
开发者ID:krasa,项目名称:EclipseCodeFormatter,代码行数:73,代码来源:JsniFormattingUtil.java


示例7: EclipseJsFormatterAdapter44

import org.eclipse.jdt.internal.formatter.DefaultCodeFormatter; //导入依赖的package包/类
@SuppressWarnings("unused")
public EclipseJsFormatterAdapter44(Map options) {
	defaultCodeFormatter = new DefaultCodeFormatter(options);
}
 
开发者ID:krasa,项目名称:EclipseCodeFormatter,代码行数:5,代码来源:EclipseJsFormatterAdapter44.java


示例8: EclipseJavaFormatterAdapter44

import org.eclipse.jdt.internal.formatter.DefaultCodeFormatter; //导入依赖的package包/类
@SuppressWarnings("unused")
public EclipseJavaFormatterAdapter44(Map options) {
	defaultCodeFormatter = new DefaultCodeFormatter(options);
}
 
开发者ID:krasa,项目名称:EclipseCodeFormatter,代码行数:5,代码来源:EclipseJavaFormatterAdapter44.java


示例9: EclipseJavaFormatterAdapter

import org.eclipse.jdt.internal.formatter.DefaultCodeFormatter; //导入依赖的package包/类
@SuppressWarnings("unused")
public EclipseJavaFormatterAdapter(Map options) {
	defaultCodeFormatter = new DefaultCodeFormatter(options);
}
 
开发者ID:krasa,项目名称:EclipseCodeFormatter,代码行数:5,代码来源:EclipseJavaFormatterAdapter.java


示例10: createCodeFormatter

import org.eclipse.jdt.internal.formatter.DefaultCodeFormatter; //导入依赖的package包/类
/**
 * Create an instance of the built-in code formatter.
 * <p>The given options should at least provide the source level ({@link JavaCore#COMPILER_SOURCE}),
 * the  compiler compliance level ({@link JavaCore#COMPILER_COMPLIANCE}) and the target platform
 * ({@link JavaCore#COMPILER_CODEGEN_TARGET_PLATFORM}).
 * Without these options, it is not possible for the code formatter to know what kind of source it needs to format.
 * </p>
 * <p>The given mode determines what options should be enabled when formatting the code. It can have the following
 * values: {@link #M_FORMAT_NEW}, {@link #M_FORMAT_EXISTING}, but other values may be added in the future.
 * </p>
 *
 * @param options the options map to use for formatting with the default code formatter. Recognized options
 * 	are documented on <code>JavaCore#getDefaultOptions()</code>. If set to <code>null</code>, then use
 * 	the current settings from <code>JavaCore#getOptions</code>.
 * @param mode the given mode to modify the given options.
 *
 * @return an instance of the built-in code formatter
 * @see CodeFormatter
 * @see JavaCore#getOptions()
 * @since 3.3
 */
public static CodeFormatter createCodeFormatter(Map options, int mode) {
	if (options == null) options = JavaCore.getOptions();
	Map currentOptions = new HashMap(options);
	if (mode == M_FORMAT_NEW) {
		// disable the option for not formatting comments starting on first column
		currentOptions.put(DefaultCodeFormatterConstants.FORMATTER_COMMENT_FORMAT_LINE_COMMENT_STARTING_ON_FIRST_COLUMN, DefaultCodeFormatterConstants.TRUE);
		// disable the option for not indenting comments starting on first column
		currentOptions.put(DefaultCodeFormatterConstants.FORMATTER_NEVER_INDENT_BLOCK_COMMENTS_ON_FIRST_COLUMN, DefaultCodeFormatterConstants.FALSE);
		currentOptions.put(DefaultCodeFormatterConstants.FORMATTER_NEVER_INDENT_LINE_COMMENTS_ON_FIRST_COLUMN, DefaultCodeFormatterConstants.FALSE);
	}
	return new DefaultCodeFormatter(currentOptions);
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:34,代码来源:ToolFactory.java



注:本文中的org.eclipse.jdt.internal.formatter.DefaultCodeFormatter类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java ISelectable类代码示例发布时间:2022-05-22
下一篇:
Java DecisionTreeModel类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap