Refactoring: use static imports everywhere in file

This commit is contained in:
Nikolay Krasko
2012-09-17 12:24:07 +04:00
parent 72fb2c0d02
commit 9481862550
@@ -26,8 +26,6 @@ import com.intellij.psi.tree.IElementType;
import com.intellij.psi.tree.TokenSet; import com.intellij.psi.tree.TokenSet;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.JetNodeTypes;
import org.jetbrains.jet.lexer.JetTokens;
import org.jetbrains.jet.plugin.JetLanguage; import org.jetbrains.jet.plugin.JetLanguage;
import java.util.*; import java.util.*;
@@ -47,9 +45,9 @@ public class JetBlock extends AbstractBlock {
private List<Block> mySubBlocks; private List<Block> mySubBlocks;
private static final TokenSet CODE_BLOCKS = TokenSet.create( private static final TokenSet CODE_BLOCKS = TokenSet.create(
JetNodeTypes.BLOCK, BLOCK,
JetNodeTypes.CLASS_BODY, CLASS_BODY,
JetNodeTypes.FUNCTION_LITERAL); FUNCTION_LITERAL);
// private static final List<IndentWhitespaceRule> // private static final List<IndentWhitespaceRule>
@@ -104,7 +102,7 @@ public class JetBlock extends AbstractBlock {
Wrap wrap = null; Wrap wrap = null;
// Affects to spaces around operators... // Affects to spaces around operators...
if (child.getElementType() == JetNodeTypes.OPERATION_REFERENCE) { if (child.getElementType() == OPERATION_REFERENCE) {
ASTNode operationNode = child.getFirstChildNode(); ASTNode operationNode = child.getFirstChildNode();
if (operationNode != null) { if (operationNode != null) {
return new JetBlock(operationNode, childAlignment, Indent.getNoneIndent(), wrap, mySettings, mySpacingBuilder); return new JetBlock(operationNode, childAlignment, Indent.getNoneIndent(), wrap, mySettings, mySpacingBuilder);
@@ -115,7 +113,7 @@ public class JetBlock extends AbstractBlock {
} }
private static Indent indentIfNotBrace(@NotNull ASTNode child) { private static Indent indentIfNotBrace(@NotNull ASTNode child) {
return child.getElementType() == JetTokens.RBRACE || child.getElementType() == JetTokens.LBRACE return child.getElementType() == RBRACE || child.getElementType() == LBRACE
? Indent.getNoneIndent() ? Indent.getNoneIndent()
: Indent.getNormalIndent(); : Indent.getNormalIndent();
} }
@@ -185,22 +183,22 @@ public class JetBlock extends AbstractBlock {
public ChildAttributes getChildAttributes(int newChildIndex) { public ChildAttributes getChildAttributes(int newChildIndex) {
final IElementType type = getNode().getElementType(); final IElementType type = getNode().getElementType();
if (CODE_BLOCKS.contains(type) || if (CODE_BLOCKS.contains(type) ||
type == JetNodeTypes.WHEN || type == WHEN ||
type == JetNodeTypes.IF || type == IF ||
type == JetNodeTypes.FOR || type == FOR ||
type == JetNodeTypes.WHILE || type == WHILE ||
type == JetNodeTypes.DO_WHILE) { type == DO_WHILE) {
return new ChildAttributes(Indent.getNormalIndent(), null); return new ChildAttributes(Indent.getNormalIndent(), null);
} }
else if (type == JetNodeTypes.TRY) { else if (type == TRY) {
// In try - try BLOCK catch BLOCK finally BLOCK // In try - try BLOCK catch BLOCK finally BLOCK
return new ChildAttributes(Indent.getNoneIndent(), null); return new ChildAttributes(Indent.getNoneIndent(), null);
} }
else if (type == JetNodeTypes.DOT_QUALIFIED_EXPRESSION) { else if (type == DOT_QUALIFIED_EXPRESSION) {
return new ChildAttributes(Indent.getContinuationWithoutFirstIndent(), null); return new ChildAttributes(Indent.getContinuationWithoutFirstIndent(), null);
} }
else if (type == JetNodeTypes.VALUE_PARAMETER_LIST || type == JetNodeTypes.VALUE_ARGUMENT_LIST) { else if (type == VALUE_PARAMETER_LIST || type == VALUE_ARGUMENT_LIST) {
// Child index 1 - cursor is after ( - parameter alignment should be recreated // Child index 1 - cursor is after ( - parameter alignment should be recreated
// Child index 0 - before expression - know nothing about it // Child index 0 - before expression - know nothing about it
if (newChildIndex != 1 && newChildIndex != 0 && newChildIndex < getSubBlocks().size()) { if (newChildIndex != 1 && newChildIndex != 0 && newChildIndex < getSubBlocks().size()) {
@@ -231,15 +229,15 @@ public class JetBlock extends AbstractBlock {
// Redefine list of strategies for some special elements // Redefine list of strategies for some special elements
IElementType parentType = myNode.getElementType(); IElementType parentType = myNode.getElementType();
if (parentType == JetNodeTypes.VALUE_PARAMETER_LIST) { if (parentType == VALUE_PARAMETER_LIST) {
strategy = getAlignmentForChildInParenthesis( strategy = getAlignmentForChildInParenthesis(
jetCommonSettings.ALIGN_MULTILINE_PARAMETERS, JetNodeTypes.VALUE_PARAMETER, JetTokens.COMMA, jetCommonSettings.ALIGN_MULTILINE_PARAMETERS, VALUE_PARAMETER, COMMA,
jetCommonSettings.ALIGN_MULTILINE_METHOD_BRACKETS, JetTokens.LPAR, JetTokens.RPAR); jetCommonSettings.ALIGN_MULTILINE_METHOD_BRACKETS, LPAR, RPAR);
} }
else if (parentType == JetNodeTypes.VALUE_ARGUMENT_LIST) { else if (parentType == VALUE_ARGUMENT_LIST) {
strategy = getAlignmentForChildInParenthesis( strategy = getAlignmentForChildInParenthesis(
jetCommonSettings.ALIGN_MULTILINE_PARAMETERS_IN_CALLS, JetNodeTypes.VALUE_ARGUMENT, JetTokens.COMMA, jetCommonSettings.ALIGN_MULTILINE_PARAMETERS_IN_CALLS, VALUE_ARGUMENT, COMMA,
jetCommonSettings.ALIGN_MULTILINE_METHOD_BRACKETS, JetTokens.LPAR, JetTokens.RPAR); jetCommonSettings.ALIGN_MULTILINE_METHOD_BRACKETS, LPAR, RPAR);
} }
// Construct information about children alignment // Construct information about children alignment
@@ -296,36 +294,36 @@ public class JetBlock extends AbstractBlock {
static ASTIndentStrategy[] INDENT_RULES = new ASTIndentStrategy[] { static ASTIndentStrategy[] INDENT_RULES = new ASTIndentStrategy[] {
ASTIndentStrategy.forNode("No indent for braces in blocks") ASTIndentStrategy.forNode("No indent for braces in blocks")
.in(JetNodeTypes.BLOCK, JetNodeTypes.CLASS_BODY, JetNodeTypes.FUNCTION_LITERAL) .in(BLOCK, CLASS_BODY, FUNCTION_LITERAL)
.forType(JetTokens.RBRACE, JetTokens.LBRACE) .forType(RBRACE, LBRACE)
.set(Indent.getNoneIndent()), .set(Indent.getNoneIndent()),
ASTIndentStrategy.forNode("Indent for block content") ASTIndentStrategy.forNode("Indent for block content")
.in(JetNodeTypes.BLOCK, JetNodeTypes.CLASS_BODY, JetNodeTypes.FUNCTION_LITERAL) .in(BLOCK, CLASS_BODY, FUNCTION_LITERAL)
.notForType(JetTokens.RBRACE, JetTokens.LBRACE, JetNodeTypes.BLOCK) .notForType(RBRACE, LBRACE, BLOCK)
.set(Indent.getNormalIndent()), .set(Indent.getNormalIndent()),
ASTIndentStrategy.forNode("Indent for property accessors") ASTIndentStrategy.forNode("Indent for property accessors")
.in(JetNodeTypes.PROPERTY) .in(PROPERTY)
.forType(JetNodeTypes.PROPERTY_ACCESSOR) .forType(PROPERTY_ACCESSOR)
.set(Indent.getNormalIndent()), .set(Indent.getNormalIndent()),
ASTIndentStrategy.forNode("For a single statement if 'for'") ASTIndentStrategy.forNode("For a single statement if 'for'")
.in(JetNodeTypes.BODY) .in(BODY)
.notForType(JetNodeTypes.BLOCK) .notForType(BLOCK)
.set(Indent.getNormalIndent()), .set(Indent.getNormalIndent()),
ASTIndentStrategy.forNode("For the entry in when") ASTIndentStrategy.forNode("For the entry in when")
.forType(JetNodeTypes.WHEN_ENTRY) .forType(WHEN_ENTRY)
.set(Indent.getNormalIndent()), .set(Indent.getNormalIndent()),
ASTIndentStrategy.forNode("For single statement in THEN and ELSE") ASTIndentStrategy.forNode("For single statement in THEN and ELSE")
.in(JetNodeTypes.THEN, JetNodeTypes.ELSE) .in(THEN, ELSE)
.notForType(JetNodeTypes.BLOCK) .notForType(BLOCK)
.set(Indent.getNormalIndent()), .set(Indent.getNormalIndent()),
ASTIndentStrategy.forNode("Indent for parts") ASTIndentStrategy.forNode("Indent for parts")
.in(JetNodeTypes.PROPERTY, JetNodeTypes.FUN) .in(PROPERTY, FUN)
.set(Indent.getContinuationWithoutFirstIndent()), .set(Indent.getContinuationWithoutFirstIndent()),
}; };
@@ -343,14 +341,14 @@ public class JetBlock extends AbstractBlock {
// TODO: Try to rewrite other rules to declarative style // TODO: Try to rewrite other rules to declarative style
if (childParent != null && childParent.getElementType() == JetNodeTypes.WHEN_ENTRY) { if (childParent != null && childParent.getElementType() == WHEN_ENTRY) {
ASTNode prev = getPrevWithoutWhitespace(child); ASTNode prev = getPrevWithoutWhitespace(child);
if (prev != null && prev.getText().equals("->")) { if (prev != null && prev.getText().equals("->")) {
return indentIfNotBrace(child); return indentIfNotBrace(child);
} }
} }
if (childParent != null && childParent.getElementType() == JetNodeTypes.DOT_QUALIFIED_EXPRESSION) { if (childParent != null && childParent.getElementType() == DOT_QUALIFIED_EXPRESSION) {
if (childParent.getFirstChildNode() != child && childParent.getLastChildNode() != child) { if (childParent.getFirstChildNode() != child && childParent.getLastChildNode() != child) {
return Indent.getContinuationWithoutFirstIndent(false); return Indent.getContinuationWithoutFirstIndent(false);
} }
@@ -359,16 +357,16 @@ public class JetBlock extends AbstractBlock {
if (childParent != null) { if (childParent != null) {
IElementType parentType = childParent.getElementType(); IElementType parentType = childParent.getElementType();
if (parentType == JetNodeTypes.VALUE_PARAMETER_LIST || parentType == JetNodeTypes.VALUE_ARGUMENT_LIST) { if (parentType == VALUE_PARAMETER_LIST || parentType == VALUE_ARGUMENT_LIST) {
ASTNode prev = getPrevWithoutWhitespace(child); ASTNode prev = getPrevWithoutWhitespace(child);
if (childType == JetTokens.RPAR && (prev == null || prev.getElementType() != TokenType.ERROR_ELEMENT)) { if (childType == RPAR && (prev == null || prev.getElementType() != TokenType.ERROR_ELEMENT)) {
return Indent.getNoneIndent(); return Indent.getNoneIndent();
} }
return Indent.getContinuationWithoutFirstIndent(); return Indent.getContinuationWithoutFirstIndent();
} }
if (parentType == JetNodeTypes.TYPE_PARAMETER_LIST || parentType == JetNodeTypes.TYPE_ARGUMENT_LIST) { if (parentType == TYPE_PARAMETER_LIST || parentType == TYPE_ARGUMENT_LIST) {
return Indent.getContinuationWithoutFirstIndent(); return Indent.getContinuationWithoutFirstIndent();
} }
} }