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.CodeStyleSettingsManager;
|
||||
import com.intellij.psi.javadoc.PsiDocComment;
|
||||
import com.intellij.psi.search.LocalSearchScope;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
@@ -128,6 +129,9 @@ public class JoinLinesHandler extends EditorWriteActionHandler {
|
||||
PsiElement psiAtStartLineEnd = psiFile.findElementAt(start);
|
||||
PsiElement psiAtNextLineStart = psiFile.findElementAt(end);
|
||||
rc = tryJoinDeclaration(psiAtStartLineEnd, psiAtNextLineStart);
|
||||
if (rc == -1) {
|
||||
rc = tryUnwrapBlockStatement(psiAtStartLineEnd, psiAtNextLineStart);
|
||||
}
|
||||
}
|
||||
|
||||
if (rc != -1) {
|
||||
@@ -198,6 +202,34 @@ public class JoinLinesHandler extends EditorWriteActionHandler {
|
||||
});
|
||||
}
|
||||
|
||||
private 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;
|
||||
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;
|
||||
PsiElement foundStatement = null;
|
||||
for (PsiElement element = elementAtStartLineEnd.getNextSibling(); element != null; element = element.getNextSibling()) {
|
||||
if (element instanceof PsiWhiteSpace) continue;
|
||||
if (element instanceof PsiJavaToken && ((PsiJavaToken)element).getTokenType() == JavaTokenType.RBRACE && element.getParent() == codeBlock) {
|
||||
if (foundStatement == null) return -1;
|
||||
break;
|
||||
}
|
||||
if (foundStatement != null) return -1;
|
||||
foundStatement = element;
|
||||
}
|
||||
try {
|
||||
final PsiElement newStatement = codeBlock.getParent().replace(foundStatement);
|
||||
return newStatement.getTextRange().getStartOffset();
|
||||
}
|
||||
catch (IncorrectOperationException e) {
|
||||
LOG.error(e);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
private int tryJoinDeclaration(PsiElement elementAtStartLineEnd, PsiElement elementAtNextLineStart) {
|
||||
if (elementAtStartLineEnd == null || elementAtNextLineStart == null) return -1;
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ import com.intellij.codeInsight.daemon.impl.HighlightInfoComposite;
|
||||
import com.intellij.codeInsight.hint.*;
|
||||
import com.intellij.ide.ui.LafManager;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.application.impl.ApplicationImpl;
|
||||
import com.intellij.openapi.application.impl.ApplicationImpl;
|
||||
import com.intellij.openapi.command.CommandProcessor;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.editor.*;
|
||||
@@ -179,6 +179,9 @@ public class EditorMarkupModelImpl extends MarkupModelImpl implements EditorMark
|
||||
MarkSpot currentSpot = null;
|
||||
while (!startQueue.isEmpty() || !endQueue.isEmpty() || index != sortedHighlighters.size()) {
|
||||
LOG.assertTrue(startQueue.size() == endQueue.size());
|
||||
final THashSet<PositionedRangeHighlighter> set = new THashSet<PositionedRangeHighlighter>(startQueue);
|
||||
LOG.assertTrue(set.containsAll(endQueue));
|
||||
|
||||
final PositionedRangeHighlighter positionedMark;
|
||||
boolean addingNew;
|
||||
if (index != sortedHighlighters.size()) {
|
||||
@@ -229,7 +232,14 @@ public class EditorMarkupModelImpl extends MarkupModelImpl implements EditorMark
|
||||
currentSpot = new MarkSpot(positionedMark.yEnd, -1);
|
||||
while (!endQueue.isEmpty() && endQueue.peek().yEnd == positionedMark.yEnd) {
|
||||
final PositionedRangeHighlighter highlighter = endQueue.remove();
|
||||
startQueue.remove(highlighter);
|
||||
for (Iterator<PositionedRangeHighlighter> iterator = startQueue.iterator(); iterator.hasNext();) {
|
||||
PositionedRangeHighlighter positioned = iterator.next();
|
||||
if (positioned == highlighter) {
|
||||
iterator.remove();
|
||||
break;
|
||||
}
|
||||
}
|
||||
//startQueue.remove(highlighter);
|
||||
}
|
||||
if (startQueue.size() == 0) {
|
||||
currentSpot = null;
|
||||
|
||||
Reference in New Issue
Block a user