本文整理汇总了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());
}
}
示例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());
}
}
示例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);
}
}
}
示例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);
}
}
}
示例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();
}
}