mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Cleanup (warnings; formatting)
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2009 JetBrains s.r.o.
|
||||
* Copyright 2000-2017 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -20,12 +20,9 @@ import com.intellij.psi.PsiElement;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
|
||||
/**
|
||||
* Created by IntelliJ IDEA.
|
||||
* User: max
|
||||
* Date: Sep 5, 2003
|
||||
* Time: 3:34:15 PM
|
||||
* To change this template use Options | File Templates.
|
||||
* @author max
|
||||
* @since Sep 5, 2003
|
||||
*/
|
||||
public interface Fixer {
|
||||
void apply(Editor editor, JavaSmartEnterProcessor processor, PsiElement psiElement) throws IncorrectOperationException;
|
||||
}
|
||||
}
|
||||
+59
-68
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2009 JetBrains s.r.o.
|
||||
* Copyright 2000-2017 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -18,7 +18,6 @@ package com.intellij.codeInsight.editorActions.smartEnter;
|
||||
import com.intellij.lang.ASTNode;
|
||||
import com.intellij.openapi.editor.Document;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.psi.*;
|
||||
@@ -31,18 +30,14 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* Created by IntelliJ IDEA.
|
||||
* User: max
|
||||
* Date: Sep 5, 2003
|
||||
* Time: 3:35:49 PM
|
||||
* To change this template use Options | File Templates.
|
||||
* @author max
|
||||
* @since Sep 5, 2003
|
||||
*/
|
||||
@SuppressWarnings({"HardCodedStringLiteral"})
|
||||
public class SemicolonFixer implements Fixer {
|
||||
@Override
|
||||
public void apply(Editor editor, JavaSmartEnterProcessor processor, PsiElement psiElement) throws IncorrectOperationException {
|
||||
boolean fixed = fixReturn(editor, psiElement) || fixForUpdate(editor, psiElement, processor)
|
||||
|| fixAfterLastValidElement(editor, psiElement);
|
||||
@SuppressWarnings("unused") boolean b =
|
||||
fixReturn(editor, psiElement) || fixForUpdate(editor, psiElement) || fixAfterLastValidElement(editor, psiElement);
|
||||
}
|
||||
|
||||
private static boolean fixReturn(@NotNull Editor editor, @Nullable PsiElement psiElement) {
|
||||
@@ -60,20 +55,20 @@ public class SemicolonFixer implements Fixer {
|
||||
return false;
|
||||
}
|
||||
|
||||
private static boolean fixForUpdate(@NotNull Editor editor, @Nullable PsiElement psiElement, @NotNull JavaSmartEnterProcessor processor) {
|
||||
private static boolean fixForUpdate(@NotNull Editor editor, @Nullable PsiElement psiElement) {
|
||||
if (!(psiElement instanceof PsiForStatement)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
PsiForStatement forStatement = (PsiForStatement)psiElement;
|
||||
final PsiExpression condition = forStatement.getCondition();
|
||||
PsiExpression condition = forStatement.getCondition();
|
||||
if (forStatement.getUpdate() != null || condition == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
final TextRange range = condition.getTextRange();
|
||||
final Document document = editor.getDocument();
|
||||
final CharSequence text = document.getCharsSequence();
|
||||
TextRange range = condition.getTextRange();
|
||||
Document document = editor.getDocument();
|
||||
CharSequence text = document.getCharsSequence();
|
||||
for (int i = range.getEndOffset() - 1, max = forStatement.getTextRange().getEndOffset(); i < max; i++) {
|
||||
if (text.charAt(i) == ';') {
|
||||
return false;
|
||||
@@ -81,72 +76,68 @@ public class SemicolonFixer implements Fixer {
|
||||
}
|
||||
|
||||
String toInsert = ";";
|
||||
final Project project = editor.getProject();
|
||||
if (project != null && CodeStyleSettingsManager.getSettings(project).SPACE_AFTER_SEMICOLON) {
|
||||
if (CodeStyleSettingsManager.getSettings(psiElement.getProject()).SPACE_AFTER_SEMICOLON) {
|
||||
toInsert += " ";
|
||||
}
|
||||
document.insertString(range.getEndOffset(), toInsert);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
private static boolean fixAfterLastValidElement(@NotNull Editor editor, @Nullable PsiElement psiElement) {
|
||||
if (psiElement == null ||
|
||||
!(psiElement instanceof PsiExpressionStatement) &&
|
||||
!(psiElement instanceof PsiDeclarationStatement) &&
|
||||
!(psiElement instanceof PsiImportStatementBase) &&
|
||||
!(psiElement instanceof PsiDoWhileStatement) &&
|
||||
!(psiElement instanceof PsiReturnStatement) &&
|
||||
!(psiElement instanceof PsiThrowStatement) &&
|
||||
!(psiElement instanceof PsiBreakStatement) &&
|
||||
!(psiElement instanceof PsiContinueStatement) &&
|
||||
!(psiElement instanceof PsiAssertStatement) &&
|
||||
!(psiElement instanceof PsiPackageStatement) &&
|
||||
(!(psiElement instanceof PsiField) || psiElement instanceof PsiEnumConstant) &&
|
||||
(!(psiElement instanceof PsiMethod) || ((PsiMethod)psiElement).getBody() != null || MissingMethodBodyFixer.shouldHaveBody((PsiMethod)psiElement))) {
|
||||
return false;
|
||||
}
|
||||
String text = psiElement.getText();
|
||||
if (psiElement instanceof PsiExpressionStatement ||
|
||||
psiElement instanceof PsiDeclarationStatement ||
|
||||
psiElement instanceof PsiImportStatementBase ||
|
||||
psiElement instanceof PsiDoWhileStatement ||
|
||||
psiElement instanceof PsiReturnStatement ||
|
||||
psiElement instanceof PsiThrowStatement ||
|
||||
psiElement instanceof PsiBreakStatement ||
|
||||
psiElement instanceof PsiContinueStatement ||
|
||||
psiElement instanceof PsiAssertStatement ||
|
||||
psiElement instanceof PsiPackageStatement ||
|
||||
psiElement instanceof PsiField && !(psiElement instanceof PsiEnumConstant) ||
|
||||
psiElement instanceof PsiMethod && ((PsiMethod)psiElement).getBody() == null && !MissingMethodBodyFixer.shouldHaveBody((PsiMethod)psiElement))
|
||||
{
|
||||
String text = psiElement.getText();
|
||||
|
||||
int tailLength = 0;
|
||||
ASTNode leaf = TreeUtil.findLastLeaf(psiElement.getNode());
|
||||
while (leaf != null && ElementType.JAVA_COMMENT_OR_WHITESPACE_BIT_SET.contains(leaf.getElementType())) {
|
||||
tailLength += leaf.getTextLength();
|
||||
leaf = TreeUtil.prevLeaf(leaf);
|
||||
}
|
||||
int tailLength = 0;
|
||||
ASTNode leaf = TreeUtil.findLastLeaf(psiElement.getNode());
|
||||
while (leaf != null && ElementType.JAVA_COMMENT_OR_WHITESPACE_BIT_SET.contains(leaf.getElementType())) {
|
||||
tailLength += leaf.getTextLength();
|
||||
leaf = TreeUtil.prevLeaf(leaf);
|
||||
}
|
||||
if (leaf == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (tailLength > 0) {
|
||||
text = text.substring(0, text.length() - tailLength);
|
||||
}
|
||||
if (tailLength > 0) {
|
||||
text = text.substring(0, text.length() - tailLength);
|
||||
}
|
||||
|
||||
if (leaf == null) {
|
||||
return false;
|
||||
}
|
||||
int insertionOffset = leaf.getTextRange().getEndOffset();
|
||||
Document doc = editor.getDocument();
|
||||
if (psiElement instanceof PsiField && ((PsiField)psiElement).hasModifierProperty(PsiModifier.ABSTRACT)) {
|
||||
// abstract rarely seem to be field. It is rather incomplete method.
|
||||
doc.insertString(insertionOffset, "()");
|
||||
insertionOffset += "()".length();
|
||||
}
|
||||
int insertionOffset = leaf.getTextRange().getEndOffset();
|
||||
Document doc = editor.getDocument();
|
||||
if (psiElement instanceof PsiField && ((PsiField)psiElement).hasModifierProperty(PsiModifier.ABSTRACT)) {
|
||||
// abstract rarely seem to be field. It is rather incomplete method.
|
||||
doc.insertString(insertionOffset, "()");
|
||||
insertionOffset += "()".length();
|
||||
}
|
||||
|
||||
if (!StringUtil.endsWithChar(text, ';')) {
|
||||
final PsiElement parent = psiElement.getParent();
|
||||
String toInsert = ";";
|
||||
if (parent instanceof PsiForStatement) {
|
||||
if (((PsiForStatement)parent).getUpdate() == psiElement) {
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
final Project project = editor.getProject();
|
||||
if (project != null && CodeStyleSettingsManager.getSettings(project).SPACE_AFTER_SEMICOLON) {
|
||||
if (!StringUtil.endsWithChar(text, ';')) {
|
||||
PsiElement parent = psiElement.getParent();
|
||||
String toInsert = ";";
|
||||
if (parent instanceof PsiForStatement) {
|
||||
if (((PsiForStatement)parent).getUpdate() == psiElement) {
|
||||
return false;
|
||||
}
|
||||
if (CodeStyleSettingsManager.getSettings(psiElement.getProject()).SPACE_AFTER_SEMICOLON) {
|
||||
toInsert += " ";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
doc.insertString(insertionOffset, toInsert);
|
||||
return true;
|
||||
doc.insertString(insertionOffset, toInsert);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2012 JetBrains s.r.o.
|
||||
* Copyright 2000-2017 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,16 +16,11 @@
|
||||
package com.intellij.psi;
|
||||
|
||||
import com.intellij.util.ArrayFactory;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* Represents a Java statement.
|
||||
*/
|
||||
public interface PsiStatement extends PsiElement {
|
||||
/**
|
||||
* The empty array of PSI statements which can be reused to avoid unnecessary allocations.
|
||||
*/
|
||||
PsiStatement[] EMPTY_ARRAY = new PsiStatement[0];
|
||||
|
||||
ArrayFactory<PsiStatement> ARRAY_FACTORY = count -> count == 0 ? PsiStatement.EMPTY_ARRAY : new PsiStatement[count];
|
||||
}
|
||||
ArrayFactory<PsiStatement> ARRAY_FACTORY = count -> count == 0 ? EMPTY_ARRAY : new PsiStatement[count];
|
||||
}
|
||||
Reference in New Issue
Block a user