Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.gameforge.idea.Corona.lang.formatter;
- import com.gameforge.idea.Corona.lang.parser.CoronaElementTypes;
- import com.gameforge.idea.Corona.lang.psi.CoronaTableConstructor;
- import com.intellij.formatting.Spacing;
- import com.intellij.lang.ASTNode;
- public class CoronaSpacing implements CoronaElementTypes {
- private static final Spacing NO_SPACING_KEEP_NEWLINE = Spacing.createSpacing(0, 0, 0, true, 0);
- private static final Spacing COMMON_SPACING = Spacing.createSpacing(1, 1, 0, false, 100);
- private static final Spacing NO_SPACING_WITH_NEWLINE = Spacing.createSpacing(0, 0, 1, false, 0);
- private static final Spacing NO_SPACING_WITH_EXTRA_LINE = Spacing.createSpacing(0, 0, 2, false, 0);
- private static final Spacing NO_SPACING = Spacing.createSpacing(0, 0, 0, false, 0);
- public static Spacing getSpacing(CoronaFormatBlock child1, CoronaFormatBlock child2) {
- ASTNode leftNode = null;
- if (child1 != null)
- leftNode = child1.getNode();
- ASTNode rightNode = child2.getNode();
- if (rightNode.getElementType() == STATEMENTS) {
- if (rightNode.getFirstChildNode().getElementType() == FUNCTION_DECLARATION)
- return NO_SPACING_WITH_EXTRA_LINE;
- return NO_SPACING_WITH_NEWLINE;
- }
- if (leftNode == null)
- return null;
- if (rightNode.getElementType() == BLOCK)
- return NO_SPACING_WITH_NEWLINE;
- if (rightNode.getElementType() == END && leftNode.getElementType() == BLOCK)
- return NO_SPACING_WITH_NEWLINE;
- // if (leftNode.getElementType() == FUNCTION_PARAMETER &&
- // (rightNode.getElementType() == END || rightNode.getTreeNext().getElementType() == END)) {
- // return NO_SPACING_WITH_EXTRA_LINE;
- // }
- if (leftNode.getElementType() == FUNCTION_CALL_TOKEN || rightNode.getElementType() == FUNCTION_CALL_TOKEN)
- return NO_SPACING;
- return null;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement