/platform/lang-impl/src/com/intellij/formatting/alignment/AlignmentInColumnsConfig.java

https://github.com/machak/intellij-community · Java · 101 lines · 35 code · 8 blank · 58 comment · 0 complexity · 479d0df17f5c1d24605c9f9e1338c2aa MD5 · raw file

  1. /*
  2. * Copyright 2000-2010 JetBrains s.r.o.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package com.intellij.formatting.alignment;
  17. import com.intellij.psi.tree.TokenSet;
  18. /**
  19. * Encapsulates information necessary for correct <code>'align in columns'</code> processing.
  20. * <p/>
  21. * Thread-safe.
  22. * <p/>
  23. * <b>Note:</b> this class doesn't provide custom realization for {@link #hashCode()} and {@link #equals(Object)} at the moment.
  24. * Feel free to add them as necessary.
  25. *
  26. * @author Denis Zhdanov
  27. * @see AlignmentInColumnsHelper
  28. * @since May 24, 2010 3:17:40 PM
  29. */
  30. public class AlignmentInColumnsConfig {
  31. private final TokenSet myStopMultilineCheckElementTypes;
  32. private final TokenSet myTargetDeclarationTypes;
  33. private final TokenSet myWhiteSpaceTokenTypes;
  34. private final TokenSet myCommentTokenTypes;
  35. private final TokenSet myDistinguishableTypes;
  36. /**
  37. * Creates new <code>AlignmentInColumnsConfig</code> object that is used to tweak <code>'align in columns'</code> processing.
  38. * <p/>
  39. * 'Alignment in columns' means formatting code as shown below:
  40. * <p/>
  41. * <pre>
  42. * double start = 1;
  43. * int end = 2;
  44. * private int tmp = 3;
  45. * private int tmp2;
  46. * protected double tmp3;
  47. * </pre>
  48. *
  49. * @param stopMultilineCheckElementTypes <code>'align in column'</code> algorithm performs number of checks in order to decide
  50. * if two variable declarations should be aligned in columns. One of that checks is
  51. * examination for sub-elements consistency. E.g. <code>'int end = 2'</code> statement
  52. * from example above is not aligned to <code>'private int tmp = 3;'</code> because the
  53. * former doesn't have modifier. Element types given here defines boundary for such
  54. * a checks, e.g. we can define type of <code>'='</code> element to be stop check type
  55. * for example above
  56. * @param whiteSpaceTokenTypes defines types of the tokens that should be treated as a white space
  57. * @param commentTokenTypes defines types of the tokens that should be treated as comments
  58. * @param distinguishableTypes <code>'align in column'</code> algorithm doesn't align elements, containing different sets
  59. * of distinguishable elements.
  60. * E.g. <code>'private int tmp = 3'</code> is not aligned to <code>'private int tmp2'</code>
  61. * at example above, providing that distinguishable types contain <code>'='</code> token.
  62. * @param targetDeclarationTypes defines variable declaration sub-element types to be aligned. Example above
  63. * shows alignment for <code>'modifier list'</code>, <code>'type reference'</code>,
  64. * <code>'identifier'</code> and <code>'='</code> types. The general idea of this property
  65. * is to let avoid alignment of unnecessary types, e.g. variable definition expressions
  66. */
  67. public AlignmentInColumnsConfig(TokenSet stopMultilineCheckElementTypes,
  68. TokenSet whiteSpaceTokenTypes,
  69. TokenSet commentTokenTypes,
  70. TokenSet distinguishableTypes,
  71. TokenSet targetDeclarationTypes) {
  72. myStopMultilineCheckElementTypes = stopMultilineCheckElementTypes;
  73. myWhiteSpaceTokenTypes = whiteSpaceTokenTypes;
  74. myCommentTokenTypes = commentTokenTypes;
  75. myDistinguishableTypes = distinguishableTypes;
  76. myTargetDeclarationTypes = targetDeclarationTypes;
  77. }
  78. public TokenSet getStopMultilineCheckElementTypes() {
  79. return myStopMultilineCheckElementTypes;
  80. }
  81. public TokenSet getWhiteSpaceTokenTypes() {
  82. return myWhiteSpaceTokenTypes;
  83. }
  84. public TokenSet getCommentTokenTypes() {
  85. return myCommentTokenTypes;
  86. }
  87. public TokenSet getDistinguishableTypes() {
  88. return myDistinguishableTypes;
  89. }
  90. public TokenSet getTargetDeclarationTypes() {
  91. return myTargetDeclarationTypes;
  92. }
  93. }