mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[groovy] add line feed after package definition (IDEA-140767)
This commit is contained in:
+4
-2
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2014 JetBrains s.r.o.
|
||||
* Copyright 2000-2015 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.
|
||||
@@ -143,6 +143,7 @@ public class GroovyCodeStyleManagerImpl extends GroovyCodeStyleManager {
|
||||
if (PsiImplUtil.hasElementType(prev, GroovyTokenTypes.mSEMI)) prev = prev.getPrevSibling();
|
||||
if (PsiImplUtil.isWhiteSpaceOrNls(prev)) prev = prev.getPrevSibling();
|
||||
|
||||
ASTNode node = psiFile.getNode();
|
||||
if (prev instanceof GrImportStatement) {
|
||||
final int idx_before = getPackageEntryIdx(entries, (GrImportStatement)prev);
|
||||
final int idx = getPackageEntryIdx(entries, result);
|
||||
@@ -151,11 +152,12 @@ public class GroovyCodeStyleManagerImpl extends GroovyCodeStyleManager {
|
||||
//skip space and semicolon after import
|
||||
if (PsiImplUtil.isWhiteSpaceOrNls(prev.getNextSibling()) && PsiImplUtil
|
||||
.hasElementType(prev.getNextSibling().getNextSibling(), GroovyTokenTypes.mSEMI)) prev = prev.getNextSibling().getNextSibling();
|
||||
ASTNode node = psiFile.getNode();
|
||||
while (PsiImplUtil.isWhiteSpaceOrNls(prev.getNextSibling())) {
|
||||
node.removeChild(prev.getNextSibling().getNode());
|
||||
}
|
||||
node.addLeaf(GroovyTokenTypes.mNLS, StringUtil.repeat("\n", spaceCount + 1), result.getNode());
|
||||
} else if (prev instanceof GrPackageDefinition) {
|
||||
node.addLeaf(GroovyTokenTypes.mNLS, "\n", result.getNode());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+31
-1
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2014 JetBrains s.r.o.
|
||||
* Copyright 2000-2015 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.
|
||||
@@ -362,4 +362,34 @@ import groovyx.gpars.GParsExecutorsPool
|
||||
GParsExecutorsPool oi
|
||||
''')
|
||||
}
|
||||
|
||||
void 'test do not remove space between package and imports'() {
|
||||
myFixture.addClass('package some; class Import {}')
|
||||
myFixture.addClass('package some; class ImportToBeDeleted {}')
|
||||
myFixture.addClass('package some; class OtherImport {}')
|
||||
myFixture.configureByText('_.groovy', '''\
|
||||
package pkg
|
||||
|
||||
import some.OtherImport
|
||||
import some.Import
|
||||
import some.ImportToBeDeleted
|
||||
|
||||
class MyClass {
|
||||
def a = new Import()
|
||||
def b = new OtherImport()
|
||||
}
|
||||
''')
|
||||
doOptimizeImports()
|
||||
myFixture.checkResult '''\
|
||||
package pkg
|
||||
|
||||
import some.Import
|
||||
import some.OtherImport
|
||||
|
||||
class MyClass {
|
||||
def a = new Import()
|
||||
def b = new OtherImport()
|
||||
}
|
||||
'''
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user