Java Code Examples for com.intellij.formatting.Indent#getNoneIndent()

The following examples show how to use com.intellij.formatting.Indent#getNoneIndent() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FusionIndentProcessor.java    From intellij-neos with GNU General Public License v3.0 6 votes vote down vote up
/**
 * @param node An ASTNode
 * @return The calculated indent for the given node
 */
public static Indent getIndent(ASTNode node) {
    IElementType type = node.getElementType();
    Indent indent = Indent.getNoneIndent();
    ASTNode parent = node.getTreeParent();
    if (parent == null) {
        return indent;
    }
    if (TYPES_WHICH_PROVOKE_AN_INDENT.contains(parent.getElementType())) {
        indent = Indent.getIndent(Indent.Type.NORMAL, false, true);
    }
    if (TYPES_WHICH_DO_NOT_NEED_AN_BEGINNING_INDENT.contains(type)) {
        indent = Indent.getNoneIndent();
    }
    if (TYPES_WHICH_CANNOT_GET_AN_INDENT.contains(type)) {
        indent = Indent.getAbsoluteNoneIndent();
    }
    return indent;
}
 
Example 2
Source File: CSharpIndentProcessor.java    From consulo-csharp with Apache License 2.0 6 votes vote down vote up
@RequiredReadAction
@Nonnull
public Indent getChildIndent()
{
	IElementType elementType = myBlock.getNode().getElementType();
	if(elementType == CSharpStubElements.FILE ||
			elementType == CSharpElements.MODIFIER_LIST ||
			elementType == CSharpElements.IF_STATEMENT ||
			elementType == CSharpElements.TRY_STATEMENT ||
			elementType == CSharpStubElements.MODIFIER_LIST)
	{
		return Indent.getNoneIndent();
	}

	return Indent.getNormalIndent();
}
 
Example 3
Source File: BashIndentProcessor.java    From BashSupport with Apache License 2.0 6 votes vote down vote up
/**
 * Calculates indent, based on code style, between parent block and child node
 *
 * @param parent        parent block
 * @param child         child node
 * @param prevChildNode previous child node
 * @return indent
 */
@NotNull
public static Indent getChildIndent(@NotNull final BashBlock parent, @Nullable final ASTNode prevChildNode, @NotNull final ASTNode child) {
    ASTNode node = parent.getNode();
    IElementType nodeType = node.getElementType();
    PsiElement psiElement = node.getPsi();

    // For Bash file
    if (psiElement instanceof BashFile) {
        return Indent.getNoneIndent();
    }

    if (BLOCKS.contains(nodeType)) {
        return indentForBlock(psiElement, child);
    }

    //subshell as function body
    ASTNode parentNode = node.getTreeParent();
    if (parentNode != null && parentNode.getElementType() == SUBSHELL_COMMAND) {
        if (parentNode.getTreeParent() != null && parentNode.getTreeParent().getElementType() == FUNCTION_DEF_COMMAND) {
            return Indent.getNormalIndent();
        }
    }

    return Indent.getNoneIndent();
}
 
Example 4
Source File: JSGraphQLEndpointBlock.java    From js-graphql-intellij-plugin with MIT License 6 votes vote down vote up
@Override
public Indent getIndent() {

	if (INDENT_EXCLUSIONS.contains(myNode.getElementType())) {
		return Indent.getNoneIndent();
	}

	if (parent != null) {
		final IElementType elementType = parent.myNode.getElementType();
		if (INDENT_PARENTS.contains(elementType)) {
			return Indent.getNormalIndent();
		}
	}

	// default is no indentation
	return Indent.getNoneIndent();

}
 
Example 5
Source File: XQueryFormattingBlock.java    From intellij-xquery with Apache License 2.0 5 votes vote down vote up
@NotNull
@Override
public ChildAttributes getChildAttributes(int newChildIndex) {
    IElementType type = myNode.getElementType();
    Indent childIndent = calculateChildIndent(type, false);
    if (childIndent == null && newChildIndex > 0) {
        IElementType calculatedType = getIElementType(newChildIndex);
        childIndent = calculateChildIndent(calculatedType, true);
    }
    return new ChildAttributes(childIndent != null ? childIndent : Indent.getNoneIndent(), null);
}
 
Example 6
Source File: SoyBlock.java    From bamboo-soy with Apache License 2.0 5 votes vote down vote up
@Override
public Indent getChildIndent() {
  PsiElement element = myNode.getPsi();
  if (element instanceof TagBlockElement) {
    return Indent.getNormalIndent();
  } else if (myNode.getPsi() instanceof TagElement) {
    return Indent.getContinuationWithoutFirstIndent();
  } else {
    return Indent.getNoneIndent();
  }
}
 
Example 7
Source File: BashIndentProcessor.java    From BashSupport with Apache License 2.0 5 votes vote down vote up
/**
 * Indent for common block
 *
 * @param psiBlock
 * @param child
 * @return
 */
private static Indent indentForBlock(PsiElement psiBlock, ASTNode child) {
    if (LEFT_CURLY.equals(child.getElementType()) || RIGHT_CURLY.equals(child.getElementType())) {
        return Indent.getNoneIndent();
    }

    return Indent.getNormalIndent();
}
 
Example 8
Source File: BuckBlock.java    From Buck-IntelliJ-Plugin with Apache License 2.0 5 votes vote down vote up
@NotNull
@Override
public ChildAttributes getChildAttributes(int newChildIndex) {
  if (hasElementType(myNode, BUCK_CONTAINERS)) {
    return new ChildAttributes(Indent.getNormalIndent(), null);
  } else if (myNode.getPsi() instanceof PsiFile) {
    return new ChildAttributes(Indent.getNoneIndent(), null);
  } else {
    return new ChildAttributes(null, null);
  }
}
 
Example 9
Source File: BuckFormattingModelBuilder.java    From Buck-IntelliJ-Plugin with Apache License 2.0 5 votes vote down vote up
@NotNull
@Override
public FormattingModel createModel(@NotNull PsiElement element,
                                   @NotNull CodeStyleSettings settings,
                                   @NotNull FormattingMode mode) {
  final BuckBlock block =
      new BuckBlock(null, element.getNode(), settings, null, Indent.getNoneIndent(), null);
  return FormattingModelProvider.createFormattingModelForPsiFile(
      element.getContainingFile(),
      block,
      settings);
}
 
Example 10
Source File: JSGraphQLEndpointBlock.java    From js-graphql-intellij-plugin with MIT License 5 votes vote down vote up
@Nullable
@Override
protected Indent getChildIndent() {
	if (parent == null) {
		return Indent.getNoneIndent();
	}
	if (INDENT_PARENTS.contains(myNode.getElementType())) {
		return Indent.getNormalIndent();
	}
	return Indent.getNoneIndent();
}
 
Example 11
Source File: GraphQLBlockWrapper.java    From js-graphql-intellij-plugin with MIT License 5 votes vote down vote up
@Override
public Indent getIndent() {
    if(myNode.getPsi() instanceof JSStringTemplateExpression) {
        // we're a GraphQL block for a JS string template expression, so return normal indent to indent queries inside the template string
        return Indent.getNormalIndent();
    }
    if(wrapped != null) {
        Indent indent = wrapped.getIndent();
        if(indent != null) {
            return indent;
        }
    }
    return Indent.getNoneIndent();
}
 
Example 12
Source File: GraphQLBlockWrapper.java    From js-graphql-intellij-plugin with MIT License 5 votes vote down vote up
@Nullable
@Override
protected Indent getChildIndent() {
    if(myNode.getPsi() instanceof JSStringTemplateExpression) {
        // enter in a top-level block inside template indents, e.g. queries etc.
        return Indent.getNormalIndent();
    }
    if(wrapped != null) {
        return wrapped.getChildAttributes(0).getChildIndent();
    }
    if(parent == null) {
        return Indent.getNoneIndent();
    }
    return Indent.getIndent(Indent.Type.NORMAL, false, false);
}
 
Example 13
Source File: CypherFormattingModelBuilder.java    From jetbrains-plugin-graph-database-support with Apache License 2.0 5 votes vote down vote up
@NotNull
@Override
public FormattingModel createModel(PsiElement element, CodeStyleSettings settings) {
    CypherBlock block = new CypherBlock(element.getNode(), Alignment.createAlignment(),
            Indent.getNoneIndent(), Wrap.createWrap(WrapType.NONE, false),
            settings,
            CypherFormattingModelBuilder.createSpacingBuilder(settings)
    );
    return FormattingModelProvider.createFormattingModelForPsiFile(element.getContainingFile(), block, settings);
}
 
Example 14
Source File: SoyBlock.java    From bamboo-soy with Apache License 2.0 5 votes vote down vote up
private boolean isParentStatementOrStatementContainerIndented() {
  BlockWithParent parent = getParent();
  while (parent instanceof SoyBlock || isSynthetic(parent)) {
    if (parent instanceof SoyBlock && ((SoyBlock) parent).isStatementOrStatementContainer()) {
      return ((SoyBlock) parent).getIndent() != Indent.getNoneIndent();
    }
    parent = parent.getParent();
  }
  return false;
}
 
Example 15
Source File: CypherBlock.java    From jetbrains-plugin-graph-database-support with Apache License 2.0 4 votes vote down vote up
@NotNull
@Override
public ChildAttributes getChildAttributes(int newChildIndex) {
    return new ChildAttributes(Indent.getNoneIndent(), null);
}
 
Example 16
Source File: CypherBlock.java    From jetbrains-plugin-graph-database-support with Apache License 2.0 4 votes vote down vote up
@NotNull
private Indent calcIndent(@NotNull ASTNode node) {
    IElementType parentType = this.node.getElementType();
    IElementType type = node.getElementType();

    if ((parentType == CypherTypes.SINGLE_PART_QUERY || parentType == CypherTypes.MULTI_PART_QUERY)
            && (type == CypherTypes.READING_CLAUSE || type == CypherTypes.UPDATING_CLAUSE || type == CypherTypes.READING_WITH_RETURN)) {
        return Indent.getNoneIndent();
    }
    if (parentType == CypherTypes.READING_WITH_RETURN && type == CypherTypes.READING_CLAUSE) {
        return Indent.getNoneIndent();
    }
    if (type == CypherTypes.READING_CLAUSE || type == CypherTypes.UPDATING_CLAUSE) {
        return Indent.getNormalIndent();
    }
    if (type == CypherTypes.MERGE_ACTION) {
        return Indent.getNormalIndent();
    }
    if (isReturnBodyKeywords(node)) {
        return Indent.getNormalIndent();
    }
    if (type == CypherTypes.PATTERN_PART || type == CypherTypes.RELATIONSHIP_PATTERN) {
        return Indent.getContinuationIndent();
    }
    if (type == CypherTypes.RETURN_ITEM) {
        return Indent.getContinuationIndent();
    }
    if (type == CypherTypes.WHERE) {
        return Indent.getNormalIndent();
    }
    if (parentType == CypherTypes.CASE_EXPRESSION || parentType == CypherTypes.CASE_ALTERNATIVES) {
        if (type == CypherTypes.K_WHEN || type == CypherTypes.K_ELSE || type == CypherTypes.K_END) {
            return Indent.getContinuationIndent();
        }
    }
    if (type == CypherTypes.PROPERTY_KEY_NAME) {
        return Indent.getContinuationIndent();
    }
    if (parentType == CypherTypes.ARRAY && type == CypherTypes.EXPRESSION) {
        return Indent.getContinuationIndent();
    }

    return Indent.getNoneIndent();
}
 
Example 17
Source File: HaxeIndentProcessor.java    From intellij-haxe with Apache License 2.0 4 votes vote down vote up
public Indent getChildIndent(ASTNode node) {
  final IElementType elementType = node.getElementType();
  final ASTNode prevSibling = UsefulPsiTreeUtil.getPrevSiblingSkipWhiteSpacesAndComments(node);
  final IElementType prevSiblingType = prevSibling == null ? null : prevSibling.getElementType();
  final ASTNode parent = node.getTreeParent();
  final IElementType parentType = parent != null ? parent.getElementType() : null;
  final ASTNode superParent = parent == null ? null : parent.getTreeParent();
  final IElementType superParentType = superParent == null ? null : superParent.getElementType();

  final int braceStyle = FUNCTION_DEFINITION.contains(superParentType) ? settings.METHOD_BRACE_STYLE : settings.BRACE_STYLE;

  if (parent == null || parent.getTreeParent() == null) {
    return Indent.getNoneIndent();
  }
  if (COMMENTS.contains(elementType)) {
    if (settings.KEEP_FIRST_COLUMN_COMMENT && isAtFirstColumn(node)) {
      return Indent.getAbsoluteNoneIndent();
    }
    return Indent.getNormalIndent();
  }
  if (elementType == PLCURLY || elementType == PRCURLY) {
    switch (braceStyle) {
      case CommonCodeStyleSettings.END_OF_LINE:
      case CommonCodeStyleSettings.NEXT_LINE:
      case CommonCodeStyleSettings.NEXT_LINE_IF_WRAPPED:
        return Indent.getNoneIndent();
      case CommonCodeStyleSettings.NEXT_LINE_SHIFTED:
      case CommonCodeStyleSettings.NEXT_LINE_SHIFTED2:
        return Indent.getNormalIndent();
      default:
        return Indent.getNoneIndent();
    }
  }
  if (parentType == PARENTHESIZED_EXPRESSION) {
    if (elementType == PLPAREN || elementType == PRPAREN) {
      return Indent.getNoneIndent();
    }
    return Indent.getNormalIndent();
  }
  if (needIndent(parentType, elementType)) {
    final PsiElement psi = node.getPsi();
    if (psi.getParent() instanceof PsiFile) {
      return Indent.getNoneIndent();
    }
    return Indent.getNormalIndent();
  }
  if (FUNCTION_DEFINITION.contains(parentType) || parentType == CALL_EXPRESSION) {
    if (elementType == PARAMETER_LIST || elementType == EXPRESSION_LIST) {
      return Indent.getNormalIndent();
    }
  }
  if (parentType == FOR_STATEMENT && prevSiblingType == PRPAREN && elementType != BLOCK_STATEMENT) {
    return Indent.getNormalIndent();
  }
  if (parentType == WHILE_STATEMENT && prevSiblingType == PRPAREN && elementType != BLOCK_STATEMENT) {
    return Indent.getNormalIndent();
  }
  if (parentType == DO_WHILE_STATEMENT && prevSiblingType == KDO && elementType != BLOCK_STATEMENT) {
    return Indent.getNormalIndent();
  }
  if ((parentType == RETURN_STATEMENT || parentType == RETURN_STATEMENT_WITHOUT_SEMICOLON) &&
      prevSiblingType == KRETURN &&
      elementType != BLOCK_STATEMENT) {
    return Indent.getNormalIndent();
  }
  if (parentType == IF_STATEMENT &&
      (prevSiblingType == PRPAREN || prevSiblingType == KELSE) &&
      elementType != BLOCK_STATEMENT &&
      elementType != IF_STATEMENT) {
    return Indent.getNormalIndent();
  }
  return Indent.getNoneIndent();
}
 
Example 18
Source File: XQueryFormattingBlock.java    From intellij-xquery with Apache License 2.0 4 votes vote down vote up
@Override
public Indent getIndent() {
    IElementType type = myNode.getElementType();
    ASTNode parent = myNode.getTreeParent();
    IElementType parentType = parent != null ? parent.getElementType() : null;
    IElementType prevType = getTypeOfPreviousElement(myNode);

    if (parent == null)
        return Indent.getNoneIndent();
    if (isExpressionAfterBrace(type, prevType) || isExpressionAfterParenthesis(type, prevType)
            || isXmlChild(type) || isForOrLetBinding(parentType)
            || isExprInsideOfEnclosedExpr(type, parentType))
        return Indent.getNormalIndent();
    if (isASingleExpression()) {
        if (parentType == IF_EXPR) {
            return Indent.getNormalIndent();
        }
        if (parentType == WHERE_CLAUSE ||
                parentType == RETURN_CLAUSE ||
                parentType == VAR_VALUE ||
                parentType == ORDER_SPEC ||
                parentType == SWITCH_RETURN_CLAUSE) {
            return Indent.getNormalIndent();
        }
    }
    if (type == SWITCH_RETURN_CLAUSE || type == SWITCH_DEFAULT_RETURN_CLAUSE || type ==
            TYPESWITCH_DEFAULT_RETURN_CLAUSE || type == CASE_CLAUSE || type == SWITCH_CASE_CLAUSE) {
        return Indent.getNormalIndent();
    }
    if (isParamOrArgumentList(parentType) && (type != L_PAR && type != R_PAR)) {
        return Indent.getContinuationIndent();
    }
    if (isChildOfSingleExpression()) {
        if (BIN_OPERATORS.contains(type) || BIN_OPERATORS.contains(prevType)) {
            return Indent.getContinuationIndent();
        }
        if (((type == SLASH || type == SLASH_SLASH || type == RELATIVE_PATH_OPERATOR) && (prevType == STEP_EXPR))
                || ((type == STEP_EXPR) && (prevType == SLASH || prevType == SLASH_SLASH || prevType == RELATIVE_PATH_OPERATOR))) {
            return Indent.getContinuationIndent();
        }
    }
    return Indent.getNoneIndent();
}