当前位置: 首页>>代码示例>>Java>>正文


Java JavaFormatterUtil类代码示例

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


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

示例1: create

import com.intellij.psi.formatter.java.JavaFormatterUtil; //导入依赖的package包/类
/**
 * Creates {@link Wrap wrap} to be used with the children blocks of the the given block.
 *
 * @param block                   target block which sub-blocks should use wrap created by the current method
 * @param settings                code formatting settings to consider during wrap construction
 * @param reservedWrapsProvider   reserved {@code 'element type -> wrap instance'} mappings provider. <b>Note:</b> this
 *                                argument is considered to be a part of legacy heritage and is intended to be removed as
 *                                soon as formatting code refactoring is done
 * @return                        wrap to use for the sub-blocks of the given block
 */
@Nullable
public Wrap create(ASTBlock block, CommonCodeStyleSettings settings, ReservedWrapsProvider reservedWrapsProvider) {
  ASTNode node = block.getNode();
  Wrap wrap = block.getWrap();
  final IElementType nodeType = node.getElementType();
  if (nodeType == JavaElementType.EXTENDS_LIST || nodeType == JavaElementType.IMPLEMENTS_LIST) {
    return Wrap.createWrap(settings.EXTENDS_LIST_WRAP, false);
  }
  else if (node instanceof PsiPolyadicExpression) {
    Wrap actualWrap = wrap != null ? wrap : reservedWrapsProvider.getReservedWrap(JavaElementType.BINARY_EXPRESSION);
    if (actualWrap == null) {
      return Wrap.createWrap(settings.BINARY_OPERATION_WRAP, false);
    }
    else {
      if (JavaFormatterUtil.areSamePriorityBinaryExpressions(node, node.getTreeParent())) {
        return actualWrap;
      }
      else {
        return Wrap.createChildWrap(actualWrap, WrapType.byLegacyRepresentation(settings.BINARY_OPERATION_WRAP), false);
      }
    }
  }
  else if (nodeType == JavaElementType.CONDITIONAL_EXPRESSION) {
    return Wrap.createWrap(settings.TERNARY_OPERATION_WRAP, false);
  }
  else if (nodeType == JavaElementType.ASSERT_STATEMENT) {
    return Wrap.createWrap(settings.ASSERT_STATEMENT_WRAP, false);
  }
  else if (nodeType == JavaElementType.FOR_STATEMENT) {
    return Wrap.createWrap(settings.FOR_STATEMENT_WRAP, false);
  }
  else if (nodeType == JavaElementType.THROWS_LIST) {
    return Wrap.createWrap(settings.THROWS_LIST_WRAP, true);
  }
  else if (nodeType == JavaElementType.CODE_BLOCK) {
    if (settings.KEEP_SIMPLE_METHODS_IN_ONE_LINE && node.getPsi().getParent() instanceof PsiMethod && !node.textContains('\n')) {
      return null;
    }
    return Wrap.createWrap(WrapType.NORMAL, false);
  }
  else if (JavaFormatterUtil.isAssignment(node)) {
    return Wrap.createWrap(settings.ASSIGNMENT_WRAP, true);
  }
  else {
    return null;
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:58,代码来源:JavaChildBlockWrapFactory.java

示例2: create

import com.intellij.psi.formatter.java.JavaFormatterUtil; //导入依赖的package包/类
/**
 * Creates {@link Wrap wrap} to be used with the children blocks of the the given block.
 *
 * @param block                   target block which sub-blocks should use wrap created by the current method
 * @param settings                code formatting settings to consider during wrap construction
 * @param reservedWrapsProvider   reserved {@code 'element type -> wrap instance'} mappings provider. <b>Note:</b> this
 *                                argument is considered to be a part of legacy heritage and is intended to be removed as
 *                                soon as formatting code refactoring is done
 * @return                        wrap to use for the sub-blocks of the given block
 */
@Nullable
public Wrap create(ASTBlock block, CommonCodeStyleSettings settings, ReservedWrapsProvider reservedWrapsProvider) {
  ASTNode node = block.getNode();
  Wrap wrap = block.getWrap();
  final IElementType nodeType = node.getElementType();
  if (nodeType == JavaElementType.EXTENDS_LIST || nodeType == JavaElementType.IMPLEMENTS_LIST) {
    return Wrap.createWrap(settings.EXTENDS_LIST_WRAP, false);
  }
  else if (node instanceof PsiPolyadicExpression) {
    Wrap actualWrap = wrap != null ? wrap : reservedWrapsProvider.getReservedWrap(JavaElementType.BINARY_EXPRESSION);
    if (actualWrap == null) {
      return Wrap.createWrap(settings.BINARY_OPERATION_WRAP, false);
    }
    else {
      if (JavaFormatterUtil.areSamePriorityBinaryExpressions(node, node.getTreeParent())) {
        return actualWrap;
      }
      else {
        return Wrap.createChildWrap(actualWrap, WrapType.byLegacyRepresentation(settings.BINARY_OPERATION_WRAP), false);
      }
    }
  }
  else if (nodeType == JavaElementType.CONDITIONAL_EXPRESSION) {
    return Wrap.createWrap(settings.TERNARY_OPERATION_WRAP, false);
  }
  else if (nodeType == JavaElementType.ASSERT_STATEMENT) {
    return Wrap.createWrap(settings.ASSERT_STATEMENT_WRAP, false);
  }
  else if (nodeType == JavaElementType.FOR_STATEMENT) {
    return Wrap.createWrap(settings.FOR_STATEMENT_WRAP, false);
  }
  else if (nodeType == JavaElementType.THROWS_LIST) {
    return Wrap.createWrap(settings.THROWS_LIST_WRAP, true);
  }
  else if (nodeType == JavaElementType.CODE_BLOCK) {
    return Wrap.createWrap(Wrap.NORMAL, false);
  }
  else if (JavaFormatterUtil.isAssignment(node)) {
    return Wrap.createWrap(settings.ASSIGNMENT_WRAP, true);
  }
  else {
    return null;
  }
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:55,代码来源:JavaChildBlockWrapFactory.java

示例3: create

import com.intellij.psi.formatter.java.JavaFormatterUtil; //导入依赖的package包/类
/**
 * Creates {@link Wrap wrap} to be used with the children blocks of the the given block.
 *
 * @param block                 target block which sub-blocks should use wrap created by the current method
 * @param settings              code formatting settings to consider during wrap construction
 * @param reservedWrapsProvider reserved {@code 'element type -> wrap instance'} mappings provider. <b>Note:</b> this
 *                              argument is considered to be a part of legacy heritage and is intended to be removed as
 *                              soon as formatting code refactoring is done
 * @return wrap to use for the sub-blocks of the given block
 */
@Nullable
public Wrap create(ASTBlock block, CommonCodeStyleSettings settings, ReservedWrapsProvider reservedWrapsProvider)
{
	ASTNode node = block.getNode();
	Wrap wrap = block.getWrap();
	final IElementType nodeType = node.getElementType();
	if(nodeType == JavaElementType.EXTENDS_LIST || nodeType == JavaElementType.IMPLEMENTS_LIST)
	{
		return Wrap.createWrap(settings.EXTENDS_LIST_WRAP, false);
	}
	else if(node instanceof PsiPolyadicExpression)
	{
		Wrap actualWrap = wrap != null ? wrap : reservedWrapsProvider.getReservedWrap(JavaElementType.BINARY_EXPRESSION);
		if(actualWrap == null)
		{
			return Wrap.createWrap(settings.BINARY_OPERATION_WRAP, false);
		}
		else
		{
			if(JavaFormatterUtil.areSamePriorityBinaryExpressions(node, node.getTreeParent()))
			{
				return actualWrap;
			}
			else
			{
				return Wrap.createChildWrap(actualWrap, WrapType.byLegacyRepresentation(settings.BINARY_OPERATION_WRAP), false);
			}
		}
	}
	else if(nodeType == JavaElementType.CONDITIONAL_EXPRESSION)
	{
		return Wrap.createWrap(settings.TERNARY_OPERATION_WRAP, false);
	}
	else if(nodeType == JavaElementType.ASSERT_STATEMENT)
	{
		return Wrap.createWrap(settings.ASSERT_STATEMENT_WRAP, false);
	}
	else if(nodeType == JavaElementType.FOR_STATEMENT)
	{
		return Wrap.createWrap(settings.FOR_STATEMENT_WRAP, false);
	}
	else if(nodeType == JavaElementType.THROWS_LIST)
	{
		return Wrap.createWrap(settings.THROWS_LIST_WRAP, true);
	}
	else if(nodeType == JavaElementType.CODE_BLOCK)
	{
		if(settings.KEEP_SIMPLE_METHODS_IN_ONE_LINE && node.getPsi().getParent() instanceof PsiMethod && !node.textContains('\n'))
		{
			return null;
		}
		return Wrap.createWrap(WrapType.NORMAL, false);
	}
	else if(JavaFormatterUtil.isAssignment(node))
	{
		return Wrap.createWrap(settings.ASSIGNMENT_WRAP, true);
	}
	else
	{
		return null;
	}
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:73,代码来源:JavaChildBlockWrapFactory.java


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