mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
(no message)
This commit is contained in:
@@ -23,6 +23,7 @@ import com.intellij.openapi.editor.ex.DocumentEx;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.codeStyle.CodeStyleManager;
|
||||
import com.intellij.psi.codeStyle.CodeStyleSettings;
|
||||
import com.intellij.psi.codeStyle.CodeStyleSettingsManager;
|
||||
import com.intellij.psi.javadoc.PsiDocComment;
|
||||
import com.intellij.psi.search.LocalSearchScope;
|
||||
@@ -203,15 +204,25 @@ public class JoinLinesHandler extends EditorWriteActionHandler {
|
||||
});
|
||||
}
|
||||
|
||||
private int tryUnwrapBlockStatement(PsiElement elementAtStartLineEnd, PsiElement elementAtNextLineStart) {
|
||||
private static int tryUnwrapBlockStatement(PsiElement elementAtStartLineEnd, PsiElement elementAtNextLineStart) {
|
||||
if (elementAtStartLineEnd == null || elementAtNextLineStart == null) return -1;
|
||||
if (!CodeStyleSettingsManager.getSettings(elementAtStartLineEnd.getProject()).KEEP_CONTROL_STATEMENT_IN_ONE_LINE) return -1;
|
||||
final CodeStyleSettings codeStyleSettings = CodeStyleSettingsManager.getSettings(elementAtStartLineEnd.getProject());
|
||||
if (!(elementAtStartLineEnd instanceof PsiJavaToken) || ((PsiJavaToken)elementAtStartLineEnd).getTokenType() != JavaTokenType.LBRACE) {
|
||||
return -1;
|
||||
}
|
||||
final PsiElement codeBlock = elementAtStartLineEnd.getParent();
|
||||
if (!(codeBlock instanceof PsiCodeBlock)) return -1;
|
||||
if (!(codeBlock.getParent() instanceof PsiBlockStatement)) return -1;
|
||||
final PsiElement parentStatement = codeBlock.getParent().getParent();
|
||||
|
||||
if (!(parentStatement instanceof PsiIfStatement && codeStyleSettings.IF_BRACE_FORCE != CodeStyleSettings.FORCE_BRACES_ALWAYS ||
|
||||
parentStatement instanceof PsiWhileStatement && codeStyleSettings.WHILE_BRACE_FORCE != CodeStyleSettings.FORCE_BRACES_ALWAYS ||
|
||||
(parentStatement instanceof PsiForStatement || parentStatement instanceof PsiForeachStatement) &&
|
||||
codeStyleSettings.FOR_BRACE_FORCE != CodeStyleSettings.FORCE_BRACES_ALWAYS ||
|
||||
parentStatement instanceof PsiDoWhileStatement &&
|
||||
codeStyleSettings.DOWHILE_BRACE_FORCE != CodeStyleSettings.FORCE_BRACES_ALWAYS)) {
|
||||
return -1;
|
||||
}
|
||||
PsiElement foundStatement = null;
|
||||
for (PsiElement element = elementAtStartLineEnd.getNextSibling(); element != null; element = element.getNextSibling()) {
|
||||
if (element instanceof PsiWhiteSpace) continue;
|
||||
@@ -231,7 +242,7 @@ public class JoinLinesHandler extends EditorWriteActionHandler {
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
private int tryJoinDeclaration(PsiElement elementAtStartLineEnd, PsiElement elementAtNextLineStart) {
|
||||
private static int tryJoinDeclaration(PsiElement elementAtStartLineEnd, PsiElement elementAtNextLineStart) {
|
||||
if (elementAtStartLineEnd == null || elementAtNextLineStart == null) return -1;
|
||||
|
||||
// first line.
|
||||
@@ -317,32 +328,27 @@ public class JoinLinesHandler extends EditorWriteActionHandler {
|
||||
|
||||
PsiExpressionStatement statement = (PsiExpressionStatement) assignment.getParent();
|
||||
|
||||
PsiDeclarationStatement newDecl = null;
|
||||
int startOffset = decl.getTextRange().getStartOffset();
|
||||
try {
|
||||
newDecl = factory.createVariableDeclarationStatement(
|
||||
PsiDeclarationStatement newDecl = factory.createVariableDeclarationStatement(
|
||||
var.getName(), var.getType(),
|
||||
initializerExpression
|
||||
);
|
||||
PsiVariable newVar = ((PsiVariable) newDecl.getDeclaredElements()[0]);
|
||||
PsiVariable newVar = (PsiVariable)newDecl.getDeclaredElements()[0];
|
||||
if (var.getModifierList().getText().length() > 0) {
|
||||
newVar.getModifierList().setModifierProperty(PsiModifier.FINAL, true);
|
||||
}
|
||||
newVar.getModifierList().replace(var.getModifierList());
|
||||
decl.replace(newDecl);
|
||||
statement.delete();
|
||||
return startOffset + newDecl.getTextRange().getEndOffset() - newDecl.getTextRange().getStartOffset();
|
||||
} catch (IncorrectOperationException e) {
|
||||
LOG.error(e);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (newDecl != null) {
|
||||
return startOffset + newDecl.getTextRange().getEndOffset() - newDecl.getTextRange().getStartOffset();
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
private int tryJoinStringLiteral(Document doc, PsiFile psiFile, int offsetNear) {
|
||||
private static int tryJoinStringLiteral(Document doc, PsiFile psiFile, int offsetNear) {
|
||||
CharSequence text = doc.getCharsSequence();
|
||||
int state = 0;
|
||||
int startQuoteOffset = -1;
|
||||
|
||||
Reference in New Issue
Block a user