Java Code Examples for com.intellij.psi.codeStyle.CommonCodeStyleSettings#NEXT_LINE_SHIFTED

The following examples show how to use com.intellij.psi.codeStyle.CommonCodeStyleSettings#NEXT_LINE_SHIFTED . 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: JavaLikeLangLineIndentProvider.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nullable
protected Indent getIndentInBlock(@Nonnull Project project, @Nullable Language language, @Nonnull SemanticEditorPosition blockStartPosition) {
  if (language != null) {
    CommonCodeStyleSettings settings = CodeStyle.getSettings(blockStartPosition.getEditor()).getCommonSettings(language);
    if (settings.BRACE_STYLE == CommonCodeStyleSettings.NEXT_LINE_SHIFTED) {
      return getDefaultIndentFromType(settings.METHOD_BRACE_STYLE == CommonCodeStyleSettings.NEXT_LINE_SHIFTED ? NONE : null);
    }
  }
  return getDefaultIndentFromType(NORMAL);
}
 
Example 2
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 3
Source File: HaxeFormatterTest.java    From intellij-haxe with Apache License 2.0 4 votes vote down vote up
public void testBracePlacement2() throws Exception {
  myTestStyleSettings.KEEP_LINE_BREAKS = false;
  myTestStyleSettings.BRACE_STYLE = CommonCodeStyleSettings.END_OF_LINE;
  myTestStyleSettings.METHOD_BRACE_STYLE = CommonCodeStyleSettings.NEXT_LINE_SHIFTED;
  doTest();
}