mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
- Handle position after 'for' statement
- Do not indent before '{'
This commit is contained in:
@@ -46,6 +46,7 @@ public class JavaLineIndentProvider extends JavaLikeLangLineIndentProvider {
|
||||
SYNTAX_MAP.put(JavaTokenType.DEFAULT_KEYWORD, SwitchDefault);
|
||||
SYNTAX_MAP.put(JavaTokenType.IF_KEYWORD, IfKeyword);
|
||||
SYNTAX_MAP.put(JavaTokenType.ELSE_KEYWORD, ElseKeyword);
|
||||
SYNTAX_MAP.put(JavaTokenType.FOR_KEYWORD, ForKeyword);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
||||
+10
-5
@@ -54,7 +54,8 @@ public abstract class JavaLikeLangLineIndentProvider extends FormatterBasedLineI
|
||||
SwitchCase,
|
||||
SwitchDefault,
|
||||
ElseKeyword,
|
||||
IfKeyword
|
||||
IfKeyword,
|
||||
ForKeyword
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@@ -105,11 +106,15 @@ public abstract class JavaLikeLangLineIndentProvider extends FormatterBasedLineI
|
||||
else {
|
||||
SemanticEditorPosition position = getPosition(editor, offset);
|
||||
if (position.before().isAt(RightParenthesis)) {
|
||||
int offsetAfterParen = position.getStartOffset() + 1;
|
||||
position.beforeParentheses(LeftParenthesis, RightParenthesis);
|
||||
if (!position.isAtEnd()) {
|
||||
position.beforeOptional(Whitespace);
|
||||
if (position.isAt(IfKeyword)) {
|
||||
return createIndentData(NORMAL, IfKeyword);
|
||||
if (position.isAt(IfKeyword) || position.isAt(ForKeyword)) {
|
||||
SyntaxElement element = position.getCurrElement();
|
||||
assert element != null;
|
||||
Type indentType = getPosition(editor, offsetAfterParen).afterOptional(Whitespace).isAt(BlockOpeningBrace) ? NONE : NORMAL;
|
||||
return createIndentData(indentType, element);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -183,7 +188,7 @@ public abstract class JavaLikeLangLineIndentProvider extends FormatterBasedLineI
|
||||
if (BlockOpeningBrace.equals(afterElement) && !isOnSeparateLine(editor, afterElement, offset)) {
|
||||
return findStatementStart(editor, afterElement, offset);
|
||||
}
|
||||
else if (IfKeyword.equals(afterElement)) {
|
||||
else if (IfKeyword.equals(afterElement) || ForKeyword.equals(afterElement)) {
|
||||
return findStatementStart(editor, null, offset);
|
||||
}
|
||||
return CharArrayUtil.shiftBackward(docChars, offset, " \t\n\r");
|
||||
@@ -242,7 +247,7 @@ public abstract class JavaLikeLangLineIndentProvider extends FormatterBasedLineI
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static Pair<Type,SyntaxElement> createIndentData(@Nullable Type type, @NotNull SyntaxElement element) {
|
||||
protected static Pair<Type,SyntaxElement> createIndentData(@Nullable Type type, @NotNull SyntaxElement element) {
|
||||
return type != null ? Pair.create(type, element) : null;
|
||||
}
|
||||
|
||||
|
||||
+13
@@ -20,6 +20,7 @@ import com.intellij.openapi.editor.highlighter.HighlighterIterator;
|
||||
import com.intellij.psi.tree.IElementType;
|
||||
import com.intellij.util.text.CharArrayUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* @author Rustam Vishnyakov
|
||||
@@ -56,6 +57,13 @@ public abstract class SemanticEditorPosition {
|
||||
return this;
|
||||
}
|
||||
|
||||
public SemanticEditorPosition afterOptional(@NotNull SyntaxElement syntaxElement) {
|
||||
if (!myIterator.atEnd()) {
|
||||
if (syntaxElement.equals(map(myIterator.getTokenType()))) myIterator.advance();
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public SemanticEditorPosition after() {
|
||||
if (!myIterator.atEnd()) {
|
||||
myIterator.advance();
|
||||
@@ -116,6 +124,11 @@ public abstract class SemanticEditorPosition {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public SyntaxElement getCurrElement() {
|
||||
return !myIterator.atEnd() ? map(myIterator.getTokenType()) : null;
|
||||
}
|
||||
|
||||
public boolean matchesRule(@NotNull Rule rule) {
|
||||
return rule.check(this);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user