mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Cleanup (formatting)
This commit is contained in:
+49
-40
@@ -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.
|
||||
@@ -22,9 +22,12 @@ import com.intellij.psi.impl.source.tree.*;
|
||||
import com.intellij.psi.scope.ElementClassHint;
|
||||
import com.intellij.psi.scope.PsiScopeProcessor;
|
||||
import com.intellij.psi.tree.TokenSet;
|
||||
import com.intellij.util.CharTable;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class PsiDeclarationStatementImpl extends CompositePsiElement implements PsiDeclarationStatement {
|
||||
private static final TokenSet DECLARED_ELEMENT_BIT_SET = TokenSet.create(JavaElementType.LOCAL_VARIABLE, JavaElementType.CLASS);
|
||||
|
||||
public PsiDeclarationStatementImpl() {
|
||||
super(JavaElementType.DECLARATION_STATEMENT);
|
||||
}
|
||||
@@ -35,8 +38,6 @@ public class PsiDeclarationStatementImpl extends CompositePsiElement implements
|
||||
return getChildrenAsPsiElements(DECLARED_ELEMENT_BIT_SET, PsiElement.ARRAY_FACTORY);
|
||||
}
|
||||
|
||||
private static final TokenSet DECLARED_ELEMENT_BIT_SET = TokenSet.create(JavaElementType.LOCAL_VARIABLE, JavaElementType.CLASS);
|
||||
|
||||
@Override
|
||||
public int getChildRole(ASTNode child) {
|
||||
if (child.getElementType() == JavaTokenType.COMMA) return ChildRole.COMMA;
|
||||
@@ -48,30 +49,33 @@ public class PsiDeclarationStatementImpl extends CompositePsiElement implements
|
||||
if (DECLARED_ELEMENT_BIT_SET.contains(child.getElementType())) {
|
||||
PsiElement[] declaredElements = getDeclaredElements();
|
||||
int length = declaredElements.length;
|
||||
|
||||
if (length == 1) {
|
||||
getTreeParent().deleteChildInternal(this);
|
||||
return;
|
||||
}
|
||||
|
||||
if (length > 0) {
|
||||
if (length == 1) {
|
||||
getTreeParent().deleteChildInternal(this);
|
||||
return;
|
||||
} else {
|
||||
if (SourceTreeToPsiMap.psiElementToTree(declaredElements[length - 1]) == child) {
|
||||
removeCommaBefore(child);
|
||||
final LeafElement semicolon = Factory.createSingleLeafElement(JavaTokenType.SEMICOLON, ";", 0, 1,
|
||||
SharedImplUtil.findCharTableByTree(this), getManager());
|
||||
SourceTreeToPsiMap.psiElementToTree(declaredElements[length - 2]).addChild(semicolon, null);
|
||||
}
|
||||
else if (SourceTreeToPsiMap.psiElementToTree(declaredElements[0]) == child) {
|
||||
CompositeElement next = (CompositeElement)SourceTreeToPsiMap.psiElementToTree(declaredElements[1]);
|
||||
ASTNode copyChild = child.copyElement();
|
||||
ASTNode nameChild = ((CompositeElement)copyChild).findChildByRole(ChildRole.NAME);
|
||||
removeCommaBefore(next);
|
||||
next.addInternal((TreeElement)copyChild.getFirstChildNode(), nameChild.getTreePrev(), null, Boolean.FALSE);
|
||||
}
|
||||
else {
|
||||
removeCommaBefore (child);
|
||||
}
|
||||
if (SourceTreeToPsiMap.psiElementToTree(declaredElements[length - 1]) == child) {
|
||||
removeCommaBefore(child);
|
||||
CharTable charTable = SharedImplUtil.findCharTableByTree(this);
|
||||
LeafElement semicolon = Factory.createSingleLeafElement(JavaTokenType.SEMICOLON, ";", charTable, getManager());
|
||||
SourceTreeToPsiMap.psiToTreeNotNull(declaredElements[length - 2]).addChild(semicolon, null);
|
||||
}
|
||||
else if (SourceTreeToPsiMap.psiElementToTree(declaredElements[0]) == child) {
|
||||
CompositeElement next = (CompositeElement)SourceTreeToPsiMap.psiToTreeNotNull(declaredElements[1]);
|
||||
ASTNode copyChild = child.copyElement();
|
||||
ASTNode nameChild = ((CompositeElement)copyChild).findChildByRole(ChildRole.NAME);
|
||||
assert nameChild != null;
|
||||
removeCommaBefore(next);
|
||||
next.addInternal((TreeElement)copyChild.getFirstChildNode(), nameChild.getTreePrev(), null, Boolean.FALSE);
|
||||
}
|
||||
else {
|
||||
removeCommaBefore(child);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
super.deleteChildInternal(child);
|
||||
}
|
||||
|
||||
@@ -79,8 +83,11 @@ public class PsiDeclarationStatementImpl extends CompositePsiElement implements
|
||||
ASTNode prev = child;
|
||||
do {
|
||||
prev = prev.getTreePrev();
|
||||
} while (prev != null && ElementType.JAVA_COMMENT_OR_WHITESPACE_BIT_SET.contains(prev.getElementType()));
|
||||
if (prev != null && prev.getElementType() == JavaTokenType.COMMA) deleteChildInternal(prev);
|
||||
}
|
||||
while (prev != null && ElementType.JAVA_COMMENT_OR_WHITESPACE_BIT_SET.contains(prev.getElementType()));
|
||||
if (prev != null && prev.getElementType() == JavaTokenType.COMMA) {
|
||||
deleteChildInternal(prev);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -93,28 +100,30 @@ public class PsiDeclarationStatementImpl extends CompositePsiElement implements
|
||||
}
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "PsiDeclarationStatement";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean processDeclarations(@NotNull PsiScopeProcessor processor, @NotNull ResolveState state, PsiElement lastParent, @NotNull PsiElement place) {
|
||||
public boolean processDeclarations(@NotNull PsiScopeProcessor processor,
|
||||
@NotNull ResolveState state,
|
||||
PsiElement lastParent,
|
||||
@NotNull PsiElement place) {
|
||||
processor.handleEvent(PsiScopeProcessor.Event.SET_DECLARATION_HOLDER, this);
|
||||
PsiElement[] decls = getDeclaredElements();
|
||||
for (PsiElement decl : decls) {
|
||||
if (decl != lastParent) {
|
||||
if (!processor.execute(decl, state)) return false;
|
||||
|
||||
for (PsiElement element : getDeclaredElements()) {
|
||||
if (element != lastParent) {
|
||||
if (!processor.execute(element, state)) return false;
|
||||
}
|
||||
else {
|
||||
final ElementClassHint hint = processor.getHint(ElementClassHint.KEY);
|
||||
if (lastParent instanceof PsiClass) {
|
||||
if (hint == null || hint.shouldProcess(ElementClassHint.DeclarationKind.CLASS)) {
|
||||
if (!processor.execute(lastParent, state)) return false;
|
||||
}
|
||||
ElementClassHint hint = processor.getHint(ElementClassHint.KEY);
|
||||
if (lastParent instanceof PsiClass && (hint == null || hint.shouldProcess(ElementClassHint.DeclarationKind.CLASS))) {
|
||||
if (!processor.execute(lastParent, state)) return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "PsiDeclarationStatement";
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
// "Initialize in constructor" "true"
|
||||
class A {
|
||||
private final int var;
|
||||
private final int var;
|
||||
|
||||
private Main() {
|
||||
var = 0;
|
||||
|
||||
+2
-2
@@ -1,6 +1,6 @@
|
||||
// "Initialize in constructor" "true"
|
||||
class A {
|
||||
private final int v<caret>ar;
|
||||
private final int v<caret>ar;
|
||||
|
||||
private Main()
|
||||
private Main()
|
||||
}
|
||||
+4
-5
@@ -3,10 +3,9 @@ import java.io.*;
|
||||
|
||||
class a {
|
||||
int k;
|
||||
|
||||
private int run() {
|
||||
/*ddddd*/ Object oo = (Object) new Integer(0);
|
||||
|
||||
return 0;
|
||||
/*ddddd*/ Object oo = (Object) new Integer(0);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+4
-5
@@ -3,10 +3,9 @@ import java.io.*;
|
||||
|
||||
class a {
|
||||
int k;
|
||||
|
||||
private int run() {
|
||||
Object <caret>o1, /*ddddd*/ oo = (Object) new Integer(0);
|
||||
|
||||
return 0;
|
||||
Object <caret>o1, /*ddddd*/ oo = (Object) new Integer(0);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+1
-1
@@ -25,7 +25,7 @@ public class InitializeFinalFieldInConstructorFixTest extends LightQuickFixParam
|
||||
enableInspectionTool(new UnusedDeclarationInspection());
|
||||
}
|
||||
|
||||
public void test() throws Exception { doAllTests(); }
|
||||
public void test() { doAllTests(); }
|
||||
|
||||
@Override
|
||||
protected String getBasePath() {
|
||||
|
||||
+2
-7
@@ -24,16 +24,11 @@ public class RemoveUnusedVariableTest extends LightQuickFixParameterizedTestCase
|
||||
super.setUp();
|
||||
enableInspectionTool(new UnusedDeclarationInspection());
|
||||
}
|
||||
|
||||
|
||||
public void test() throws Exception {
|
||||
doAllTests();
|
||||
}
|
||||
public void test() { doAllTests(); }
|
||||
|
||||
@Override
|
||||
protected String getBasePath() {
|
||||
return "/codeInsight/daemonCodeAnalyzer/quickFix/removeUnusedVariable";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -40,20 +40,8 @@ public class FileParserTest extends JavaParsingTestCase {
|
||||
public void testUnclosedImport3() { doParserTest("import static a"); }
|
||||
public void testImportBrokenFromBeginning() { doParserTest("xx import a;"); }
|
||||
|
||||
public void testExtraSemicolons() {
|
||||
doParserTest(
|
||||
"package p;;\n" +
|
||||
"import a;;\n" +
|
||||
"class C{};");
|
||||
}
|
||||
|
||||
public void testFileWithClass() {
|
||||
doParserTest(
|
||||
"package a;\n" +
|
||||
"import b;\n" +
|
||||
"public class C { }\n" +
|
||||
"class D { }");
|
||||
}
|
||||
public void testExtraSemicolons() { doParserTest("package p;;\nimport a;;\nclass C{};"); }
|
||||
public void testFileWithClass() { doParserTest("package a;\nimport b;\npublic class C { }\nclass D { }"); }
|
||||
|
||||
public void testBindBefore0() { doParserTest("class A{\n // comment\n int field;\n}"); }
|
||||
public void testBindBefore1() { doParserTest("class A{\n // comment\n\n int field;\n}"); }
|
||||
|
||||
Reference in New Issue
Block a user