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


Java FormatterUtil.getPreviousLeaf方法代码示例

本文整理汇总了Java中com.intellij.psi.formatter.FormatterUtil.getPreviousLeaf方法的典型用法代码示例。如果您正苦于以下问题:Java FormatterUtil.getPreviousLeaf方法的具体用法?Java FormatterUtil.getPreviousLeaf怎么用?Java FormatterUtil.getPreviousLeaf使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.intellij.psi.formatter.FormatterUtil的用法示例。


在下文中一共展示了FormatterUtil.getPreviousLeaf方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: combineWithErrorElementIfPossible

import com.intellij.psi.formatter.FormatterUtil; //导入方法依赖的package包/类
/**
 * Checks if previous non-white space leaf of the given node is error element and combines formatting range relevant for it
 * with the range of the given node.
 * 
 * @param node  target node
 * @return      given node range if there is no error-element before it; combined range otherwise
 */
@Nullable
private static TextRange combineWithErrorElementIfPossible(@NotNull ASTNode node) {
  if (node.getElementType() == TokenType.ERROR_ELEMENT) {
    return node.getTextRange();
  }
  final ASTNode prevLeaf = FormatterUtil.getPreviousLeaf(node, TokenType.WHITE_SPACE);
  if (prevLeaf == null || prevLeaf.getElementType() != TokenType.ERROR_ELEMENT) {
    return node.getTextRange();
  }

  final TextRange range = doGetRangeAffectingIndent(prevLeaf);
  if (range == null) {
    return node.getTextRange();
  }
  else {
    return new TextRange(range.getStartOffset(), node.getTextRange().getEndOffset());
  } 
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:26,代码来源:JavaFormattingModelBuilder.java

示例2: combineWithErrorElementIfPossible

import com.intellij.psi.formatter.FormatterUtil; //导入方法依赖的package包/类
/**
 * Checks if previous non-white space leaf of the given node is error element and combines formatting range relevant for it
 * with the range of the given node.
 *
 * @param node target node
 * @return given node range if there is no error-element before it; combined range otherwise
 */
@Nullable
@RequiredReadAction
private static TextRange combineWithErrorElementIfPossible(@NotNull ASTNode node)
{
	if(node.getElementType() == TokenType.ERROR_ELEMENT)
	{
		return node.getTextRange();
	}
	final ASTNode prevLeaf = FormatterUtil.getPreviousLeaf(node, TokenType.WHITE_SPACE);
	if(prevLeaf == null || prevLeaf.getElementType() != TokenType.ERROR_ELEMENT)
	{
		return node.getTextRange();
	}

	final TextRange range = doGetRangeAffectingIndent(prevLeaf);
	if(range == null)
	{
		return node.getTextRange();
	}
	else
	{
		return new TextRange(range.getStartOffset(), node.getTextRange().getEndOffset());
	}
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:32,代码来源:JavaFormattingModelBuilder.java

示例3: visitForStatement

import com.intellij.psi.formatter.FormatterUtil; //导入方法依赖的package包/类
@Override
public void visitForStatement(PsiForStatement statement) {
  if (myRole2 == ChildRole.LPARENTH) {
    createSpaceInCode(mySettings.SPACE_BEFORE_FOR_PARENTHESES);
  }
  else if (myRole1 == ChildRole.LPARENTH) {
    ASTNode rparenth = findFrom(myChild2, JavaTokenType.RPARENTH, true);
    if (rparenth == null) {
      createSpaceInCode(mySettings.SPACE_WITHIN_FOR_PARENTHESES);
    }
    else {
      createParenthSpace(mySettings.FOR_STATEMENT_LPAREN_ON_NEXT_LINE, mySettings.SPACE_WITHIN_FOR_PARENTHESES,
                         new TextRange(myChild1.getTextRange().getStartOffset(), rparenth.getTextRange().getEndOffset()));
      if (myChild2.getElementType() == JavaElementType.EMPTY_STATEMENT) {
        createSpaceInCode(mySettings.SPACE_BEFORE_SEMICOLON);
      }
    }
  }
  else if (myRole2 == ChildRole.RPARENTH) {
    ASTNode lparenth = findFrom(myChild2, JavaTokenType.LPARENTH, false);
    if (lparenth == null) {
      createSpaceInCode(mySettings.SPACE_WITHIN_FOR_PARENTHESES);
    }
    else {
      ASTNode prev = FormatterUtil.getPreviousLeaf(myChild2, TokenType.WHITE_SPACE, TokenType.ERROR_ELEMENT);
      if (prev != null && prev.getElementType() == JavaTokenType.SEMICOLON) {
        // Handle empty 'initialization' or 'condition' section.
        createSpaceInCode(mySettings.SPACE_AFTER_SEMICOLON);
      }
      else {
        createParenthSpace(mySettings.FOR_STATEMENT_RPAREN_ON_NEXT_LINE, mySettings.SPACE_WITHIN_FOR_PARENTHESES,
                           new TextRange(lparenth.getTextRange().getStartOffset(), myChild2.getTextRange().getEndOffset()));
      }
    }
  }
  else if (myRole1 == ChildRole.FOR_INITIALIZATION) {
    createSpaceInCode(mySettings.SPACE_AFTER_SEMICOLON);
  }
  else if (myRole1 == ChildRole.CONDITION) {
    createSpaceInCode(mySettings.SPACE_BEFORE_SEMICOLON);
  }
  else if (myRole1 == ChildRole.FOR_SEMICOLON) {
    createSpaceInCode(mySettings.SPACE_AFTER_SEMICOLON);
  }
  else if (myRole2 == ChildRole.LOOP_BODY || myChild2.getElementType() == JavaElementType.CODE_BLOCK) {
    if (myChild2.getElementType() == JavaElementType.BLOCK_STATEMENT) {
      myResult = getSpaceBeforeLBrace(myChild2, mySettings.SPACE_BEFORE_FOR_LBRACE, null);
    }
    else if (mySettings.KEEP_CONTROL_STATEMENT_IN_ONE_LINE) {
      myResult = Spacing.createDependentLFSpacing(1, 1, myParent.getTextRange(), false, mySettings.KEEP_BLANK_LINES_IN_CODE);
    }
    else {
      myResult = Spacing.createSpacing(0, 0, 1, false, mySettings.KEEP_BLANK_LINES_IN_CODE);
    }
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:57,代码来源:JavaSpacePropertyProcessor.java

示例4: visitForStatement

import com.intellij.psi.formatter.FormatterUtil; //导入方法依赖的package包/类
@Override public void visitForStatement(PsiForStatement statement) {
  if (myRole2 == ChildRole.LPARENTH) {
    createSpaceInCode(mySettings.SPACE_BEFORE_FOR_PARENTHESES);
  }
  else if (myRole1 == ChildRole.LPARENTH) {
    ASTNode rparenth = findFrom(myChild2, JavaTokenType.RPARENTH, true);
    if (rparenth == null) {
      createSpaceInCode(mySettings.SPACE_WITHIN_FOR_PARENTHESES);
    }
    else {
      createParenthSpace(mySettings.FOR_STATEMENT_LPAREN_ON_NEXT_LINE, mySettings.SPACE_WITHIN_FOR_PARENTHESES,
                         new TextRange(myChild1.getTextRange().getStartOffset(), rparenth.getTextRange().getEndOffset()));
      if (myChild2.getElementType() == JavaElementType.EMPTY_STATEMENT) {
        createSpaceInCode(mySettings.SPACE_BEFORE_SEMICOLON);
      }
    }
  }
  else if (myRole2 == ChildRole.RPARENTH) {
    ASTNode lparenth = findFrom(myChild2, JavaTokenType.LPARENTH, false);
    if (lparenth == null) {
      createSpaceInCode(mySettings.SPACE_WITHIN_FOR_PARENTHESES);
    }
    else {
      ASTNode prev = FormatterUtil.getPreviousLeaf(myChild2, TokenType.WHITE_SPACE, TokenType.ERROR_ELEMENT);
      if (prev != null && prev.getElementType() == JavaTokenType.SEMICOLON) {
        // Handle empty 'initialization' or 'condition' section.
        createSpaceInCode(mySettings.SPACE_AFTER_SEMICOLON);
      }
      else {
        createParenthSpace(mySettings.FOR_STATEMENT_RPAREN_ON_NEXT_LINE, mySettings.SPACE_WITHIN_FOR_PARENTHESES,
                           new TextRange(lparenth.getTextRange().getStartOffset(), myChild2.getTextRange().getEndOffset()));
      }
    }
  }
  else if (myRole1 == ChildRole.FOR_INITIALIZATION) {
    createSpaceInCode(mySettings.SPACE_AFTER_SEMICOLON);
  }
  else if (myRole1 == ChildRole.CONDITION) {
    createSpaceInCode(mySettings.SPACE_BEFORE_SEMICOLON);
  }
  else if (myRole1 == ChildRole.FOR_SEMICOLON) {
    createSpaceInCode(mySettings.SPACE_AFTER_SEMICOLON);
  }
  else if (myRole2 == ChildRole.LOOP_BODY || myChild2.getElementType() == JavaElementType.CODE_BLOCK) {
    if (myChild2.getElementType() == JavaElementType.BLOCK_STATEMENT) {
      myResult = getSpaceBeforeLBrace(mySettings.SPACE_BEFORE_FOR_LBRACE, mySettings.BRACE_STYLE,
                                      new TextRange(myParent.getTextRange().getStartOffset(), myChild1.getTextRange().getEndOffset()),
                                      mySettings.KEEP_SIMPLE_BLOCKS_IN_ONE_LINE, true);
    }
    else if (mySettings.KEEP_CONTROL_STATEMENT_IN_ONE_LINE) {
      myResult = Spacing
        .createDependentLFSpacing(1, 1, myParent.getTextRange(), false, mySettings.KEEP_BLANK_LINES_IN_CODE);
    }
    else {
      myResult = Spacing.createSpacing(0, 0, 1, false, mySettings.KEEP_BLANK_LINES_IN_CODE);
    }
  }
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:59,代码来源:JavaSpacePropertyProcessor.java

示例5: visitForStatement

import com.intellij.psi.formatter.FormatterUtil; //导入方法依赖的package包/类
@Override
public void visitForStatement(PsiForStatement statement)
{
	if(myRole2 == ChildRole.LPARENTH)
	{
		createSpaceInCode(mySettings.SPACE_BEFORE_FOR_PARENTHESES);
	}
	else if(myRole1 == ChildRole.LPARENTH)
	{
		ASTNode rparenth = findFrom(myChild2, JavaTokenType.RPARENTH, true);
		if(rparenth == null)
		{
			createSpaceInCode(mySettings.SPACE_WITHIN_FOR_PARENTHESES);
		}
		else
		{
			createParenthSpace(mySettings.FOR_STATEMENT_LPAREN_ON_NEXT_LINE, mySettings.SPACE_WITHIN_FOR_PARENTHESES, new TextRange(myChild1.getTextRange().getStartOffset(), rparenth
					.getTextRange().getEndOffset()));
			if(myChild2.getElementType() == JavaElementType.EMPTY_STATEMENT)
			{
				createSpaceInCode(mySettings.SPACE_BEFORE_SEMICOLON || mySettings.SPACE_WITHIN_FOR_PARENTHESES);
			}
		}
	}
	else if(myRole2 == ChildRole.RPARENTH)
	{
		ASTNode lparenth = findFrom(myChild2, JavaTokenType.LPARENTH, false);
		if(lparenth == null)
		{
			createSpaceInCode(mySettings.SPACE_WITHIN_FOR_PARENTHESES);
		}
		else
		{
			ASTNode prev = FormatterUtil.getPreviousLeaf(myChild2, TokenType.WHITE_SPACE, TokenType.ERROR_ELEMENT);
			if(prev != null && prev.getElementType() == JavaTokenType.SEMICOLON)
			{
				// Handle empty 'initialization' or 'condition' section.
				createSpaceInCode(mySettings.SPACE_AFTER_SEMICOLON);
			}
			else
			{
				createParenthSpace(mySettings.FOR_STATEMENT_RPAREN_ON_NEXT_LINE, mySettings.SPACE_WITHIN_FOR_PARENTHESES, new TextRange(lparenth.getTextRange().getStartOffset(), myChild2
						.getTextRange().getEndOffset()));
			}
		}
	}
	else if(myRole1 == ChildRole.FOR_INITIALIZATION)
	{
		createSpaceInCode(mySettings.SPACE_AFTER_SEMICOLON);
	}
	else if(myRole1 == ChildRole.CONDITION)
	{
		createSpaceInCode(mySettings.SPACE_BEFORE_SEMICOLON);
	}
	else if(myRole1 == ChildRole.FOR_SEMICOLON)
	{
		createSpaceInCode(mySettings.SPACE_AFTER_SEMICOLON);
	}
	else if(myRole2 == ChildRole.LOOP_BODY || myChild2.getElementType() == JavaElementType.CODE_BLOCK)
	{
		processLoopBody();
	}
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:64,代码来源:JavaSpacePropertyProcessor.java


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