Advertisement
Guest User

SpacingHelper

a guest
Jun 1st, 2016
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.80 KB | None | 0 0
  1. package com.gameforge.idea.Corona.lang.formatter;
  2.  
  3. import com.gameforge.idea.Corona.lang.parser.CoronaElementTypes;
  4. import com.gameforge.idea.Corona.lang.psi.CoronaTableConstructor;
  5. import com.intellij.formatting.Spacing;
  6. import com.intellij.lang.ASTNode;
  7.  
  8. public class CoronaSpacing implements CoronaElementTypes {
  9.     private static final Spacing NO_SPACING_KEEP_NEWLINE = Spacing.createSpacing(0, 0, 0, true, 0);
  10.     private static final Spacing COMMON_SPACING = Spacing.createSpacing(1, 1, 0, false, 100);
  11.  
  12.     private static final Spacing NO_SPACING_WITH_NEWLINE = Spacing.createSpacing(0, 0, 1, false, 0);
  13.     private static final Spacing NO_SPACING_WITH_EXTRA_LINE = Spacing.createSpacing(0, 0, 2, false, 0);
  14.     private static final Spacing NO_SPACING = Spacing.createSpacing(0, 0, 0, false, 0);
  15.  
  16.     public static Spacing getSpacing(CoronaFormatBlock child1, CoronaFormatBlock child2) {
  17.         ASTNode leftNode = null;
  18.         if (child1 != null)
  19.             leftNode = child1.getNode();
  20.         ASTNode rightNode = child2.getNode();
  21.  
  22.         if (rightNode.getElementType() == STATEMENTS) {
  23.             if (rightNode.getFirstChildNode().getElementType() == FUNCTION_DECLARATION)
  24.                 return NO_SPACING_WITH_EXTRA_LINE;
  25.             return NO_SPACING_WITH_NEWLINE;
  26.         }
  27.  
  28.         if (leftNode == null)
  29.             return null;
  30.  
  31.         if (rightNode.getElementType() == BLOCK)
  32.             return NO_SPACING_WITH_NEWLINE;
  33.  
  34.         if (rightNode.getElementType() == END && leftNode.getElementType() == BLOCK)
  35.             return NO_SPACING_WITH_NEWLINE;
  36.  
  37. //      if (leftNode.getElementType() == FUNCTION_PARAMETER &&
  38. //              (rightNode.getElementType() == END || rightNode.getTreeNext().getElementType() == END)) {
  39. //          return NO_SPACING_WITH_EXTRA_LINE;
  40. //      }
  41.  
  42.         if (leftNode.getElementType() == FUNCTION_CALL_TOKEN || rightNode.getElementType() == FUNCTION_CALL_TOKEN)
  43.             return NO_SPACING;
  44.  
  45.         return null;
  46.     }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement