com.intellij.formatting.Wrap Java Examples

The following examples show how to use com.intellij.formatting.Wrap. 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: HaxeWrappingProcessor.java    From intellij-haxe with Apache License 2.0 6 votes vote down vote up
private static Wrap createChildWrap(ASTNode child, int parentWrap, boolean newLineAfterLBrace, boolean newLineBeforeRBrace) {
  IElementType childType = child.getElementType();
  if (childType != PLPAREN && childType != PRPAREN) {
    if (FormatterUtil.isPrecededBy(child, PLBRACK)) {
      if (newLineAfterLBrace) {
        return Wrap.createChildWrap(Wrap.createWrap(parentWrap, true), WrapType.ALWAYS, true);
      }
      else {
        return Wrap.createWrap(WrapType.NONE, true);
      }
    }
    return Wrap.createWrap(WrappingUtil.getWrapType(parentWrap), true);
  }
  if (childType == PRBRACK && newLineBeforeRBrace) {
    return Wrap.createWrap(WrapType.ALWAYS, true);
  }
  return Wrap.createWrap(WrapType.NONE, true);
}
 
Example #2
Source File: BuckBlock.java    From Buck-IntelliJ-Plugin with Apache License 2.0 6 votes vote down vote up
public BuckBlock(@Nullable final BuckBlock parent,
                 @NotNull final ASTNode node,
                 @NotNull CodeStyleSettings settings,
                 @Nullable final Alignment alignment,
                 @NotNull final Indent indent,
                 @Nullable final Wrap wrap) {
  myParent = parent;
  myAlignment = alignment;
  myIndent = indent;
  myNode = node;
  myPsiElement = node.getPsi();
  myWrap = wrap;
  mySettings = settings;

  mySpacingBuilder = BuckFormattingModelBuilder.createSpacingBuilder(settings);

  if (myPsiElement instanceof BuckArrayElements ||
      myPsiElement instanceof BuckRuleBody ||
      myPsiElement instanceof BuckListElements ||
      myPsiElement instanceof BuckObjectElements) {
    myChildWrap = Wrap.createWrap(CommonCodeStyleSettings.WRAP_ALWAYS, true);
  } else {
    myChildWrap = null;
  }
}
 
Example #3
Source File: BashBlockGenerator.java    From BashSupport with Apache License 2.0 6 votes vote down vote up
public static List<Block> generateSubBlocks(ASTNode node,
                                            Alignment _myAlignment,
                                            Wrap _myWrap,
                                            CodeStyleSettings _mySettings,
                                            BashBlock block) {
    myWrap = _myWrap;
    mySettings = _mySettings;
    myAlignment = _myAlignment;

    // For other cases
    final List<Block> subBlocks = new ArrayList<Block>();
    ASTNode children[] = getBashChildren(node);
    ASTNode prevChildNode = null;
    for (ASTNode childNode : children) {
        if (canBeCorrectBlock(childNode)) {
            final Indent indent = BashIndentProcessor.getChildIndent(block, prevChildNode, childNode);
            subBlocks.add(new BashBlock(childNode, myAlignment, indent, myWrap, mySettings));
            prevChildNode = childNode;
        }
    }
    return subBlocks;
}
 
Example #4
Source File: SoyFormattingModelBuilder.java    From bamboo-soy with Apache License 2.0 5 votes vote down vote up
@Override
public TemplateLanguageBlock createTemplateLanguageBlock(
    @NotNull ASTNode node,
    @Nullable Wrap wrap,
    @Nullable Alignment alignment,
    @Nullable List<DataLanguageBlockWrapper> foreignChildren,
    @NotNull CodeStyleSettings codeStyleSettings) {
  final FormattingDocumentModelImpl documentModel =
      FormattingDocumentModelImpl.createOn(node.getPsi().getContainingFile());
  if (node.getPsi() instanceof TagElement) {
    return new SoyTagBlock(
        this,
        codeStyleSettings,
        node,
        foreignChildren,
        new HtmlPolicy(codeStyleSettings, documentModel));
  } else if(node.getPsi() instanceof TagBlockElement) {
    return new SoyTagBlockBlock(
        this,
        codeStyleSettings,
        node,
        foreignChildren,
        new HtmlPolicy(codeStyleSettings, documentModel));
  } else if (node.getPsi() instanceof SoyStatementList) {
    return new SoyStatementListBlock(
        this,
        codeStyleSettings,
        node,
        foreignChildren,
        new HtmlPolicy(codeStyleSettings, documentModel));
  } else {
    return new SoyBlock(
      this,
      codeStyleSettings,
      node,
      foreignChildren,
      new HtmlPolicy(codeStyleSettings, documentModel));
  }
}
 
Example #5
Source File: FormattingModelBuilder.java    From protobuf-jetbrains-plugin with Apache License 2.0 5 votes vote down vote up
@NotNull
@Override
public FormattingModel createModel(PsiElement element, CodeStyleSettings settings) {
    PsiFile containingFile = element.getContainingFile().getViewProvider().getPsi(ProtoLanguage.INSTANCE);
    ASTNode fileNode = containingFile.getNode();
    Wrap wrap = Wrap.createWrap(WrapType.NONE, false);
    Alignment alignment = Alignment.createAlignment();
    ProtoFileBlock block = new ProtoFileBlock(fileNode, wrap, alignment, settings);
    return FormattingModelProvider.createFormattingModelForPsiFile(containingFile, block, settings);
}
 
Example #6
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 #7
Source File: CypherBlock.java    From jetbrains-plugin-graph-database-support with Apache License 2.0 5 votes vote down vote up
CypherBlock(@NotNull ASTNode node,
            @Nullable Alignment alignment,
            @Nullable Indent indent,
            @Nullable Wrap wrap,
            @NotNull CodeStyleSettings settings,
            @NotNull SpacingBuilder spacingBuilder) {
    this.node = node;
    this.codeStyleSettings = settings;
    this.wrap = wrap;
    this.indent = indent;
    this.alignment = alignment;
    this.spacingBuilder = spacingBuilder;
}
 
Example #8
Source File: XQueryFormattingBlock.java    From intellij-xquery with Apache License 2.0 5 votes vote down vote up
@Override
protected List<Block> buildChildren() {
    List<Block> blocks = new ArrayList<Block>();
    ASTNode child = myNode.getFirstChildNode();
    while (child != null) {
        if (child.getElementType() != TokenType.WHITE_SPACE && child.getTextRange().getLength() != 0) {
            Block block = new XQueryFormattingBlock(child, Wrap.createWrap(WrapType.NONE, false), null, settings,
                    spacingBuilder);
            blocks.add(block);
        }
        child = child.getTreeNext();
    }
    return blocks;
}
 
Example #9
Source File: GraphQLBlockWrapper.java    From js-graphql-intellij-plugin with MIT License 5 votes vote down vote up
protected GraphQLBlockWrapper(Block wrapped, @Nullable GraphQLBlockWrapper parent, @NotNull ASTNode node, @Nullable Wrap wrap, @Nullable Alignment alignment, SpacingBuilder spacingBuilder, CodeStyleSettings settings) {
    super(node, wrap, alignment);
    this.wrapped = wrapped;
    this.parent = parent;
    this.spacingBuilder = spacingBuilder;
    this.settings = settings;
}
 
Example #10
Source File: GraphQLInjectedLanguageBlockBuilder.java    From js-graphql-intellij-plugin with MIT License 5 votes vote down vote up
@Override
public boolean addInjectedBlocks(List<? super Block> result, ASTNode injectionHost, Wrap wrap, Alignment alignment, Indent indent) {
    boolean added = super.addInjectedBlocks(result, injectionHost, wrap, alignment, indent);
    if(!added) {
        // 'if (places.size() != 1) {' guard in super
        // happens when the GraphQL is interrupted by JS/TS template fragments
        added = graphQLSupportingAddInjectedBlocks(result, injectionHost, wrap, alignment, indent);
    }
    return added;
}
 
Example #11
Source File: TemplateLanguageBlockFactory.java    From consulo with Apache License 2.0 4 votes vote down vote up
TemplateLanguageBlock createTemplateLanguageBlock(@Nonnull ASTNode node,
@Nullable Wrap wrap,
@Nullable Alignment alignment,
@Nullable List<DataLanguageBlockWrapper> foreignChildren,
@Nonnull CodeStyleSettings codeStyleSettings);
 
Example #12
Source File: FluidFormattingModelBuilder.java    From idea-php-typo3-plugin with MIT License 4 votes vote down vote up
@Override
protected Block createTemplateLanguageBlock(ASTNode node, CodeStyleSettings settings, XmlFormattingPolicy xmlFormattingPolicy, Indent indent, @Nullable Alignment alignment, @Nullable Wrap wrap) {
    PsiElement nodePsi = node.getPsi();

    return (nodePsi instanceof FluidStatement && hasInjection(nodePsi) ? new FluidBlockWithInjection(this, node, wrap, alignment, settings, xmlFormattingPolicy, indent) : new FluidBlock(this, node, wrap, alignment, settings, xmlFormattingPolicy, indent));
}
 
Example #13
Source File: WrappingUtil.java    From consulo with Apache License 2.0 4 votes vote down vote up
public static Wrap createWrap(int setting) {
  return Wrap.createWrap(getWrapType(setting), true);
}
 
Example #14
Source File: XQueryFormattingBlock.java    From intellij-xquery with Apache License 2.0 4 votes vote down vote up
public XQueryFormattingBlock(@NotNull ASTNode node, @Nullable Wrap wrap, @Nullable Alignment alignment,
                             @NotNull CommonCodeStyleSettings settings, @NotNull SpacingBuilder spacingBuilder) {
    super(node, wrap, alignment);
    this.spacingBuilder = spacingBuilder;
    this.settings = settings;
}
 
Example #15
Source File: HaxeWrappingProcessor.java    From intellij-haxe with Apache License 2.0 4 votes vote down vote up
private static Wrap createWrap(boolean isNormal) {
  return Wrap.createWrap(isNormal ? WrapType.NORMAL : WrapType.NONE, true);
}
 
Example #16
Source File: HaxeWrappingProcessor.java    From intellij-haxe with Apache License 2.0 4 votes vote down vote up
Wrap createChildWrap(ASTNode child, Wrap defaultWrap, Wrap childWrap) {
  final IElementType childType = child.getElementType();
  final IElementType elementType = myNode.getElementType();
  if (childType == OCOMMA || childType == OSEMI) return defaultWrap;

  //
  // Function definition/call
  //
  if (elementType == PARAMETER_LIST || elementType == EXPRESSION_LIST) {
    final ASTNode parent = myNode.getTreeParent();
    if (parent == null) {
      return defaultWrap;
    }
    final IElementType parentType = parent.getElementType();
    if (parentType == CALL_EXPRESSION &&
        mySettings.CALL_PARAMETERS_WRAP != CommonCodeStyleSettings.DO_NOT_WRAP) {
      if (myNode.getFirstChildNode() == child) {
        return createWrap(mySettings.CALL_PARAMETERS_LPAREN_ON_NEXT_LINE);
      }
      if (!mySettings.PREFER_PARAMETERS_WRAP && childWrap != null) {
        return Wrap.createChildWrap(childWrap, WrappingUtil.getWrapType(mySettings.CALL_PARAMETERS_WRAP), true);
      }
      return Wrap.createWrap(WrappingUtil.getWrapType(mySettings.CALL_PARAMETERS_WRAP), true);
    }
    if (FUNCTION_DEFINITION.contains(parentType) &&
        mySettings.METHOD_PARAMETERS_WRAP != CommonCodeStyleSettings.DO_NOT_WRAP) {
      if (myNode.getFirstChildNode() == child) {
        return createWrap(mySettings.METHOD_PARAMETERS_LPAREN_ON_NEXT_LINE);
      }
      if (childType == PRPAREN) {
        return createWrap(mySettings.METHOD_PARAMETERS_RPAREN_ON_NEXT_LINE);
      }
      return Wrap.createWrap(WrappingUtil.getWrapType(mySettings.METHOD_PARAMETERS_WRAP), true);
    }
  }

  if (elementType == CALL_EXPRESSION) {
    if (mySettings.CALL_PARAMETERS_WRAP != CommonCodeStyleSettings.DO_NOT_WRAP) {
      if (childType == PRPAREN) {
        return createWrap(mySettings.CALL_PARAMETERS_RPAREN_ON_NEXT_LINE);
      }
    }
  }

  //
  // If
  //
  if (elementType == IF_STATEMENT && childType == KELSE) {
    return createWrap(mySettings.ELSE_ON_NEW_LINE);
  }

  //
  //Binary expressions
  //
  if (BINARY_EXPRESSIONS.contains(elementType) && mySettings.BINARY_OPERATION_WRAP != CommonCodeStyleSettings.DO_NOT_WRAP) {
    if ((mySettings.BINARY_OPERATION_SIGN_ON_NEXT_LINE && BINARY_OPERATORS.contains(childType)) ||
        (!mySettings.BINARY_OPERATION_SIGN_ON_NEXT_LINE && isRightOperand(child))) {
      return Wrap.createWrap(WrappingUtil.getWrapType(mySettings.BINARY_OPERATION_WRAP), true);
    }
  }

  //
  // Assignment
  //
  if (elementType == ASSIGN_EXPRESSION && mySettings.ASSIGNMENT_WRAP != CommonCodeStyleSettings.DO_NOT_WRAP) {
    if (childType != ASSIGN_OPERATION) {
      if (FormatterUtil.isPrecededBy(child, ASSIGN_OPERATION) &&
          mySettings.PLACE_ASSIGNMENT_SIGN_ON_NEXT_LINE) {
        return Wrap.createWrap(WrapType.NONE, true);
      }
      return Wrap.createWrap(WrappingUtil.getWrapType(mySettings.ASSIGNMENT_WRAP), true);
    }
    else if (mySettings.PLACE_ASSIGNMENT_SIGN_ON_NEXT_LINE) {
      return Wrap.createWrap(WrapType.NORMAL, true);
    }
  }

  //
  // Ternary expressions
  //
  if (elementType == TERNARY_EXPRESSION) {
    if (myNode.getFirstChildNode() != child) {
      if (mySettings.TERNARY_OPERATION_SIGNS_ON_NEXT_LINE) {
        if (!FormatterUtil.isPrecededBy(child, OQUEST) &&
            !FormatterUtil.isPrecededBy(child, OCOLON)) {
          return Wrap.createWrap(WrappingUtil.getWrapType(mySettings.TERNARY_OPERATION_WRAP), true);
        }
      }
      else if (childType != OQUEST && childType != OCOLON) {
        return Wrap.createWrap(WrappingUtil.getWrapType(mySettings.TERNARY_OPERATION_WRAP), true);
      }
    }
    return Wrap.createWrap(WrapType.NONE, true);
  }
  return defaultWrap;
}
 
Example #17
Source File: CSharpDisabledFormattingBlock.java    From consulo-csharp with Apache License 2.0 4 votes vote down vote up
@Nullable
@Override
public Wrap getWrap()
{
	return null;
}
 
Example #18
Source File: BuckBlock.java    From Buck-IntelliJ-Plugin with Apache License 2.0 4 votes vote down vote up
@Nullable
@Override
public Wrap getWrap() {
  return myWrap;
}
 
Example #19
Source File: JSGraphQLEndpointBlock.java    From js-graphql-intellij-plugin with MIT License 4 votes vote down vote up
protected JSGraphQLEndpointBlock(@Nullable JSGraphQLEndpointBlock parent, @NotNull ASTNode node, @Nullable Wrap wrap, @Nullable Alignment alignment, SpacingBuilder spacingBuilder) {
	super(node, wrap, alignment);
	this.parent = parent;
	this.spacingBuilder = spacingBuilder;
}
 
Example #20
Source File: CypherBlock.java    From jetbrains-plugin-graph-database-support with Apache License 2.0 4 votes vote down vote up
@Nullable
@Override
public Wrap getWrap() {
    return wrap;
}
 
Example #21
Source File: CypherBlock.java    From jetbrains-plugin-graph-database-support with Apache License 2.0 4 votes vote down vote up
@NotNull
private Wrap calcWrap(@NotNull ASTNode node) {
    IElementType type = node.getElementType();

    if (type == CypherTypes.READING_CLAUSE || type == CypherTypes.UPDATING_CLAUSE || type == CypherTypes.READING_WITH_RETURN
            || type == CypherTypes.RETURN || type == CypherTypes.WITH) {
        return Wrap.createWrap(WrapType.ALWAYS, true);
    }
    if (type == CypherTypes.K_USING) {
        return Wrap.createWrap(WrapType.ALWAYS, true);
    }
    if (type == CypherTypes.CALL) {
        return Wrap.createWrap(WrapType.ALWAYS, true);
    }
    if (type == CypherTypes.MERGE_ACTION) {
        return Wrap.createWrap(WrapType.ALWAYS, true);
    }
    if (isReturnBodyKeywords(node)) {
        return Wrap.createWrap(WrapType.ALWAYS, true);
    }
    if (type == CypherTypes.PATTERN_PART || type == CypherTypes.RELATIONSHIP_PATTERN) {
        return Wrap.createWrap(WrapType.CHOP_DOWN_IF_LONG, true);
    }
    if (type == CypherTypes.WHERE && TreeUtil.findParent(node, CypherTypes.LIST_COMPREHENSION) != null) {
        return Wrap.createWrap(WrapType.CHOP_DOWN_IF_LONG, true);
    }
    if (type == CypherTypes.WHERE) {
        return Wrap.createWrap(WrapType.ALWAYS, true);
    }
    if (type == CypherTypes.RETURN_ITEM) {
        return Wrap.createWrap(WrapType.CHOP_DOWN_IF_LONG, true);
    }
    if (type == CypherTypes.FOREACH) {
        return Wrap.createWrap(WrapType.ALWAYS, true);
    }
    if (type == CypherTypes.K_ELSE || type == CypherTypes.K_END) {
        return Wrap.createWrap(WrapType.ALWAYS, true);
    }
    if (type == CypherTypes.PROPERTY_KEY_NAME) {
        return Wrap.createWrap(WrapType.CHOP_DOWN_IF_LONG, true);
    }
    if (node.getTreeParent().getElementType() == CypherTypes.ARRAY && type == CypherTypes.EXPRESSION) {
        return Wrap.createWrap(WrapType.CHOP_DOWN_IF_LONG, true);
    }
    if (type == CypherTypes.K_AS) {
        return Wrap.createWrap(WrapType.CHOP_DOWN_IF_LONG, true);
    }

    return Wrap.createWrap(WrapType.NONE, false);
}
 
Example #22
Source File: CypherBlock.java    From jetbrains-plugin-graph-database-support with Apache License 2.0 4 votes vote down vote up
private CypherBlock makeSubBlock(@NotNull ASTNode node, Alignment alignment) {
    Wrap wrap = calcWrap(node);
    Indent indent = calcIndent(node);

    return new CypherBlock(node, alignment, indent, wrap, codeStyleSettings, spacingBuilder);
}
 
Example #23
Source File: LeafBlock.java    From protobuf-jetbrains-plugin with Apache License 2.0 4 votes vote down vote up
@Override
public Wrap getWrap() {
    return null;
}
 
Example #24
Source File: ProtoFileBlock.java    From protobuf-jetbrains-plugin with Apache License 2.0 4 votes vote down vote up
ProtoFileBlock(@NotNull ASTNode node, @Nullable Wrap wrap, @Nullable Alignment alignment, CodeStyleSettings settings) {
    super(node, wrap, alignment);
    this.settings = settings;

}