diff --git a/compiler/frontend/src/org/jetbrains/jet/JetNodeTypes.java b/compiler/frontend/src/org/jetbrains/jet/JetNodeTypes.java index 3a87496d899..a68a104ccd9 100644 --- a/compiler/frontend/src/org/jetbrains/jet/JetNodeTypes.java +++ b/compiler/frontend/src/org/jetbrains/jet/JetNodeTypes.java @@ -51,6 +51,7 @@ public interface JetNodeTypes { IElementType VALUE_PARAMETER = JetStubElementTypes.VALUE_PARAMETER; JetNodeType CLASS_BODY = new JetNodeType("CLASS_BODY", JetClassBody.class); + JetNodeType IMPORT_LIST = new JetNodeType("IMPORT_LIST", JetImportList.class); JetNodeType IMPORT_DIRECTIVE = new JetNodeType("IMPORT_DIRECTIVE", JetImportDirective.class); JetNodeType MODIFIER_LIST = new JetNodeType("MODIFIER_LIST", JetModifierList.class); JetNodeType PRIMARY_CONSTRUCTOR_MODIFIER_LIST = new JetNodeType("PRIMARY_CONSTRUCTOR_MODIFIER_LIST", JetModifierList.class); diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/parsing/JetParsing.java b/compiler/frontend/src/org/jetbrains/jet/lang/parsing/JetParsing.java index 58f748f1e05..f7a216c6412 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/parsing/JetParsing.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/parsing/JetParsing.java @@ -86,7 +86,7 @@ public class JetParsing extends AbstractJetParsing { /* * [start] jetlFile - * : preamble toplevelObject[| import]* [eof] + * : preamble toplevelObject* [eof] * ; */ void parseFile() { @@ -94,7 +94,9 @@ public class JetParsing extends AbstractJetParsing { parsePreamble(true); - parseToplevelDeclarations(false); + while (!eof()) { + parseTopLevelObject(); + } fileMarker.done(JET_FILE); } @@ -140,20 +142,6 @@ public class JetParsing extends AbstractJetParsing { fileMarker.done(JET_FILE); } - /* - * toplevelObject[| import]* - */ - private void parseToplevelDeclarations(boolean insideBlock) { - while (!eof() && (!insideBlock || !at(RBRACE))) { - if (at(IMPORT_KEYWORD)) { - parseImportDirective(); - } - else { - parseTopLevelObject(); - } - } - } - /* *preamble * : namespaceHeader? import* @@ -230,6 +218,10 @@ public class JetParsing extends AbstractJetParsing { PsiBuilder.Marker importDirective = mark(); advance(); // IMPORT_KEYWORD + if (closeImportWithErrorIfNewline(importDirective, "Expecting qualified name")) { + return; + } + PsiBuilder.Marker qualifiedName = mark(); PsiBuilder.Marker reference = mark(); @@ -239,6 +231,11 @@ public class JetParsing extends AbstractJetParsing { while (at(DOT) && lookahead(1) != MUL) { advance(); // DOT + if (closeImportWithErrorIfNewline(importDirective, "Import must be placed on a single line")) { + qualifiedName.drop(); + return; + } + reference = mark(); if (expect(IDENTIFIER, "Qualified name must be a '.'-separated identifier list", IMPORT_RECOVERY_SET)) { reference.done(REFERENCE_EXPRESSION); @@ -257,29 +254,44 @@ public class JetParsing extends AbstractJetParsing { advance(); // DOT assert _at(MUL); advance(); // MUL - handleUselessRename(); + if (at(AS_KEYWORD)) { + PsiBuilder.Marker as = mark(); + advance(); // AS_KEYWORD + if (closeImportWithErrorIfNewline(importDirective, "Expecting identifier")) { + as.drop(); + return; + } + consumeIf(IDENTIFIER); + as.error("Cannot rename all imported items to one identifier"); + } } if (at(AS_KEYWORD)) { advance(); // AS_KEYWORD + if (closeImportWithErrorIfNewline(importDirective, "Expecting identifier")) { + return; + } expect(IDENTIFIER, "Expecting identifier", TokenSet.create(SEMICOLON)); } consumeIf(SEMICOLON); importDirective.done(IMPORT_DIRECTIVE); } - private void parseImportDirectives() { - // TODO: Duplicate with parsing imports in parseToplevelDeclarations - while (at(IMPORT_KEYWORD)) { - parseImportDirective(); + private boolean closeImportWithErrorIfNewline(PsiBuilder.Marker importDirective, String errorMessage) { + if (myBuilder.newlineBeforeCurrentToken()) { + error(errorMessage); + importDirective.done(IMPORT_DIRECTIVE); + return true; } + return false; } - private void handleUselessRename() { - if (at(AS_KEYWORD)) { - PsiBuilder.Marker as = mark(); - advance(); // AS_KEYWORD - consumeIf(IDENTIFIER); - as.error("Cannot rename a all imported items to one identifier"); + private void parseImportDirectives() { + if (at(IMPORT_KEYWORD)) { + PsiBuilder.Marker importList = mark(); + while (at(IMPORT_KEYWORD)) { + parseImportDirective(); + } + importList.done(IMPORT_LIST); } } diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetFile.java b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetFile.java index ea4f138e853..d351bc06966 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetFile.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetFile.java @@ -19,21 +19,9 @@ package org.jetbrains.jet.lang.psi; import com.intellij.extapi.psi.PsiFileBase; import com.intellij.lang.ASTNode; import com.intellij.lang.FileASTNode; -import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.fileTypes.FileType; -import com.intellij.openapi.util.text.StringUtil; -import com.intellij.openapi.vfs.VirtualFile; -import com.intellij.openapi.vfs.VirtualFileWithId; import com.intellij.psi.FileViewProvider; import com.intellij.psi.PsiElementVisitor; -import com.intellij.psi.PsiFile; -import com.intellij.psi.PsiLock; -import com.intellij.psi.stubs.ObjectStubTree; -import com.intellij.psi.stubs.StubBase; -import com.intellij.psi.stubs.StubTree; -import com.intellij.psi.stubs.StubTreeLoader; -import com.intellij.psi.tree.IElementType; -import com.intellij.psi.tree.IStubFileElementType; import com.intellij.psi.util.PsiTreeUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -42,6 +30,7 @@ import org.jetbrains.jet.lang.psi.stubs.PsiJetFileStub; import org.jetbrains.jet.plugin.JetFileType; import org.jetbrains.jet.plugin.JetLanguage; +import java.util.Collections; import java.util.List; public class JetFile extends PsiFileBase implements JetDeclarationContainer, JetElement { @@ -79,8 +68,15 @@ public class JetFile extends PsiFileBase implements JetDeclarationContainer, Jet return PsiTreeUtil.getChildrenOfTypeAsList(this, JetDeclaration.class); } + @Nullable + public JetImportList getImportList() { + return findChildByClass(JetImportList.class); + } + + @NotNull public List getImportDirectives() { - return PsiTreeUtil.getChildrenOfTypeAsList(this, JetImportDirective.class); + JetImportList importList = getImportList(); + return importList != null ? importList.getImports() : Collections.emptyList(); } @Nullable diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetImportList.java b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetImportList.java new file mode 100644 index 00000000000..b3e38f74d7b --- /dev/null +++ b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetImportList.java @@ -0,0 +1,45 @@ +/* + * Copyright 2010-2013 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jetbrains.jet.lang.psi; + +import com.intellij.lang.ASTNode; +import com.intellij.psi.util.PsiTreeUtil; +import org.jetbrains.annotations.NotNull; + +import java.util.List; + +public class JetImportList extends JetElementImpl { + + public JetImportList(@NotNull ASTNode node) { + super(node); + } + + @Override + public void accept(@NotNull JetVisitorVoid visitor) { + visitor.visitImportList(this); + } + + @Override + public R accept(@NotNull JetVisitor visitor, D data) { + return visitor.visitImportList(this, data); + } + + @NotNull + public List getImports() { + return PsiTreeUtil.getChildrenOfTypeAsList(this, JetImportDirective.class); + } +} diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetPsiFactory.java b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetPsiFactory.java index 3d0a793aa65..d4721450e42 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetPsiFactory.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetPsiFactory.java @@ -305,6 +305,12 @@ public class JetPsiFactory { return namespace.getImportDirectives().iterator().next(); } + @NotNull + public static JetImportList createImportDirectiveWithImportList(Project project, @NotNull ImportPath importPath) { + JetImportDirective importDirective = createImportDirective(project, importPath); + return (JetImportList) importDirective.getParent(); + } + @NotNull public static PsiElement createPrimaryConstructor(Project project) { JetClass aClass = createClass(project, "class A()"); diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetScript.java b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetScript.java index 24b08449afc..d1fd2183e44 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetScript.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetScript.java @@ -19,7 +19,9 @@ package org.jetbrains.jet.lang.psi; import com.intellij.lang.ASTNode; import com.intellij.psi.util.PsiTreeUtil; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import java.util.Collections; import java.util.List; public class JetScript extends JetDeclarationImpl { @@ -33,9 +35,15 @@ public class JetScript extends JetDeclarationImpl { return findNotNullChildByClass(JetBlockExpression.class); } + @Nullable + public JetImportList getImportList() { + return findChildByClass(JetImportList.class); + } + @NotNull public List getImportDirectives() { - return PsiTreeUtil.getChildrenOfTypeAsList(this, JetImportDirective.class); + JetImportList importList = getImportList(); + return importList != null ? importList.getImports() : Collections.emptyList(); } @NotNull diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetVisitor.java b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetVisitor.java index 0ff97c83382..4fa4ee02c0e 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetVisitor.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetVisitor.java @@ -70,6 +70,10 @@ public class JetVisitor extends PsiElementVisitor { return visitJetElement(importDirective, data); } + public R visitImportList(@NotNull JetImportList importList, D data) { + return visitJetElement(importList, data); + } + public R visitClassBody(@NotNull JetClassBody classBody, D data) { return visitJetElement(classBody, data); } diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetVisitorVoid.java b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetVisitorVoid.java index 3005dc33124..ff0be8afff0 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetVisitorVoid.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetVisitorVoid.java @@ -59,6 +59,10 @@ public class JetVisitorVoid extends PsiElementVisitor { visitJetElement(importDirective); } + public void visitImportList(JetImportList importList) { + visitJetElement(importList); + } + public void visitClassBody(JetClassBody classBody) { visitJetElement(classBody); } diff --git a/compiler/testData/diagnostics/tests/ProcessingEmptyImport.kt b/compiler/testData/diagnostics/tests/ProcessingEmptyImport.kt index 3ed438400f7..35c39eae02b 100644 --- a/compiler/testData/diagnostics/tests/ProcessingEmptyImport.kt +++ b/compiler/testData/diagnostics/tests/ProcessingEmptyImport.kt @@ -1,3 +1,3 @@ -import +import -fun firstFun() {} \ No newline at end of file +fun firstFun() {} \ No newline at end of file diff --git a/compiler/testData/psi/ImportSoftKW.txt b/compiler/testData/psi/ImportSoftKW.txt index 2ea08bc2cf1..7b1f29b9f9d 100644 --- a/compiler/testData/psi/ImportSoftKW.txt +++ b/compiler/testData/psi/ImportSoftKW.txt @@ -1,24 +1,25 @@ JetFile: ImportSoftKW.kt NAMESPACE_HEADER - IMPORT_DIRECTIVE - PsiElement(import)('import') - PsiWhiteSpace(' ') - DOT_QUALIFIED_EXPRESSION + IMPORT_LIST + IMPORT_DIRECTIVE + PsiElement(import)('import') + PsiWhiteSpace(' ') DOT_QUALIFIED_EXPRESSION DOT_QUALIFIED_EXPRESSION - REFERENCE_EXPRESSION - PsiElement(IDENTIFIER)('import') + DOT_QUALIFIED_EXPRESSION + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('import') + PsiElement(DOT)('.') + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('import') PsiElement(DOT)('.') REFERENCE_EXPRESSION PsiElement(IDENTIFIER)('import') PsiElement(DOT)('.') REFERENCE_EXPRESSION PsiElement(IDENTIFIER)('import') - PsiElement(DOT)('.') - REFERENCE_EXPRESSION - PsiElement(IDENTIFIER)('import') - PsiWhiteSpace(' ') - PsiElement(as)('as') - PsiWhiteSpace(' ') - PsiElement(IDENTIFIER)('import') \ No newline at end of file + PsiWhiteSpace(' ') + PsiElement(as)('as') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('import') \ No newline at end of file diff --git a/compiler/testData/psi/Imports.txt b/compiler/testData/psi/Imports.txt index 8c268e514c1..938223be257 100644 --- a/compiler/testData/psi/Imports.txt +++ b/compiler/testData/psi/Imports.txt @@ -11,59 +11,60 @@ JetFile: Imports.kt REFERENCE_EXPRESSION PsiElement(IDENTIFIER)('goo') PsiWhiteSpace('\n\n') - IMPORT_DIRECTIVE - PsiElement(import)('import') - PsiWhiteSpace(' ') - REFERENCE_EXPRESSION - PsiElement(IDENTIFIER)('foo') - PsiWhiteSpace('\n') - IMPORT_DIRECTIVE - PsiElement(import)('import') - PsiWhiteSpace(' ') - DOT_QUALIFIED_EXPRESSION + IMPORT_LIST + IMPORT_DIRECTIVE + PsiElement(import)('import') + PsiWhiteSpace(' ') + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('foo') + PsiWhiteSpace('\n') + IMPORT_DIRECTIVE + PsiElement(import)('import') + PsiWhiteSpace(' ') + DOT_QUALIFIED_EXPRESSION + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('foo') + PsiElement(DOT)('.') + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('bar') + PsiWhiteSpace('\n') + IMPORT_DIRECTIVE + PsiElement(import)('import') + PsiWhiteSpace(' ') + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('foo') + PsiWhiteSpace(' ') + PsiElement(as)('as') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('bar') + PsiWhiteSpace('\n') + IMPORT_DIRECTIVE + PsiElement(import)('import') + PsiWhiteSpace(' ') + DOT_QUALIFIED_EXPRESSION + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('foo') + PsiElement(DOT)('.') + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('bar') + PsiWhiteSpace(' ') + PsiElement(as)('as') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('bar') + PsiWhiteSpace('\n') + IMPORT_DIRECTIVE + PsiElement(import)('import') + PsiWhiteSpace(' ') REFERENCE_EXPRESSION PsiElement(IDENTIFIER)('foo') PsiElement(DOT)('.') - REFERENCE_EXPRESSION - PsiElement(IDENTIFIER)('bar') - PsiWhiteSpace('\n') - IMPORT_DIRECTIVE - PsiElement(import)('import') - PsiWhiteSpace(' ') - REFERENCE_EXPRESSION - PsiElement(IDENTIFIER)('foo') - PsiWhiteSpace(' ') - PsiElement(as)('as') - PsiWhiteSpace(' ') - PsiElement(IDENTIFIER)('bar') - PsiWhiteSpace('\n') - IMPORT_DIRECTIVE - PsiElement(import)('import') - PsiWhiteSpace(' ') - DOT_QUALIFIED_EXPRESSION + PsiElement(MUL)('*') + PsiWhiteSpace('\n') + IMPORT_DIRECTIVE + PsiElement(import)('import') + PsiWhiteSpace(' ') REFERENCE_EXPRESSION PsiElement(IDENTIFIER)('foo') PsiElement(DOT)('.') - REFERENCE_EXPRESSION - PsiElement(IDENTIFIER)('bar') - PsiWhiteSpace(' ') - PsiElement(as)('as') - PsiWhiteSpace(' ') - PsiElement(IDENTIFIER)('bar') - PsiWhiteSpace('\n') - IMPORT_DIRECTIVE - PsiElement(import)('import') - PsiWhiteSpace(' ') - REFERENCE_EXPRESSION - PsiElement(IDENTIFIER)('foo') - PsiElement(DOT)('.') - PsiElement(MUL)('*') - PsiWhiteSpace('\n') - IMPORT_DIRECTIVE - PsiElement(import)('import') - PsiWhiteSpace(' ') - REFERENCE_EXPRESSION - PsiElement(IDENTIFIER)('foo') - PsiElement(DOT)('.') - PsiWhiteSpace(' ') - PsiElement(MUL)('*') \ No newline at end of file + PsiWhiteSpace(' ') + PsiElement(MUL)('*') \ No newline at end of file diff --git a/compiler/testData/psi/Imports_ERR.kt b/compiler/testData/psi/Imports_ERR.kt index e099fbc0e72..91ddaef2bed 100644 --- a/compiler/testData/psi/Imports_ERR.kt +++ b/compiler/testData/psi/Imports_ERR.kt @@ -1,17 +1,34 @@ package foo.bar.goo -import foo as +import + import foo. +import foo.* +import foo.; +import foo.*; + +import foo as +import foo. as +import foo.* as +import foo. as ; +import foo.* as; + +import foo as . +import foo as ; +import foo as * +import foo as sdfsdf +import foo.* as ; +import foo.* as bar import foo.bar. import foo. as bar +import foo. as bar ; + import foo.bar.* as bar import foo.bar.* as - -import foo as ; -import foo. ; import foo.bar. ; -import foo. as bar ; import foo.bar.* as bar ; import foo.bar.* as ; -class Foo {} \ No newline at end of file +fun foo() { + +} diff --git a/compiler/testData/psi/Imports_ERR.txt b/compiler/testData/psi/Imports_ERR.txt index d7c6c257854..4d4cfbffcd5 100644 --- a/compiler/testData/psi/Imports_ERR.txt +++ b/compiler/testData/psi/Imports_ERR.txt @@ -11,150 +11,186 @@ JetFile: Imports_ERR.kt REFERENCE_EXPRESSION PsiElement(IDENTIFIER)('goo') PsiWhiteSpace('\n\n') - IMPORT_DIRECTIVE - PsiElement(import)('import') - PsiWhiteSpace(' ') - REFERENCE_EXPRESSION - PsiElement(IDENTIFIER)('foo') - PsiWhiteSpace(' ') - PsiElement(as)('as') - PsiWhiteSpace('\n') - PsiElement(IDENTIFIER)('import') - PsiWhiteSpace(' ') - MODIFIER_LIST - ANNOTATION_ENTRY - CONSTRUCTOR_CALLEE - TYPE_REFERENCE - USER_TYPE - USER_TYPE - REFERENCE_EXPRESSION - PsiElement(IDENTIFIER)('foo') - PsiElement(DOT)('.') - PsiWhiteSpace('\n') - REFERENCE_EXPRESSION - PsiElement(IDENTIFIER)('import') - PsiWhiteSpace(' ') - ANNOTATION_ENTRY - CONSTRUCTOR_CALLEE - TYPE_REFERENCE - USER_TYPE - USER_TYPE - USER_TYPE - REFERENCE_EXPRESSION - PsiElement(IDENTIFIER)('foo') - PsiElement(DOT)('.') - REFERENCE_EXPRESSION - PsiElement(IDENTIFIER)('bar') - PsiElement(DOT)('.') - PsiWhiteSpace('\n') - REFERENCE_EXPRESSION - PsiElement(IDENTIFIER)('import') - PsiWhiteSpace(' ') - ANNOTATION_ENTRY - CONSTRUCTOR_CALLEE - TYPE_REFERENCE - USER_TYPE - USER_TYPE - REFERENCE_EXPRESSION - PsiElement(IDENTIFIER)('foo') - PsiElement(DOT)('.') - PsiWhiteSpace(' ') - PsiErrorElement:Expecting type name - PsiElement(as)('as') - PsiWhiteSpace(' ') - ANNOTATION_ENTRY - CONSTRUCTOR_CALLEE - TYPE_REFERENCE - USER_TYPE - REFERENCE_EXPRESSION - PsiElement(IDENTIFIER)('bar') - PsiWhiteSpace('\n') - ANNOTATION_ENTRY - CONSTRUCTOR_CALLEE - TYPE_REFERENCE - USER_TYPE - REFERENCE_EXPRESSION - PsiElement(IDENTIFIER)('import') - PsiWhiteSpace(' ') - ANNOTATION_ENTRY - CONSTRUCTOR_CALLEE - TYPE_REFERENCE - USER_TYPE - USER_TYPE - USER_TYPE - REFERENCE_EXPRESSION - PsiElement(IDENTIFIER)('foo') - PsiElement(DOT)('.') - REFERENCE_EXPRESSION - PsiElement(IDENTIFIER)('bar') - PsiElement(DOT)('.') - PsiErrorElement:Expecting type name - PsiElement(MUL)('*') - PsiWhiteSpace(' ') - PsiErrorElement:Expecting package directive or top level declaration - PsiElement(as)('as') - PsiWhiteSpace(' ') - MODIFIER_LIST - ANNOTATION_ENTRY - CONSTRUCTOR_CALLEE - TYPE_REFERENCE - USER_TYPE - REFERENCE_EXPRESSION - PsiElement(IDENTIFIER)('bar') - PsiWhiteSpace('\n') - ANNOTATION_ENTRY - CONSTRUCTOR_CALLEE - TYPE_REFERENCE - USER_TYPE - REFERENCE_EXPRESSION - PsiElement(IDENTIFIER)('import') - PsiWhiteSpace(' ') - ANNOTATION_ENTRY - CONSTRUCTOR_CALLEE - TYPE_REFERENCE - USER_TYPE - USER_TYPE - USER_TYPE - REFERENCE_EXPRESSION - PsiElement(IDENTIFIER)('foo') - PsiElement(DOT)('.') - REFERENCE_EXPRESSION - PsiElement(IDENTIFIER)('bar') - PsiElement(DOT)('.') - PsiErrorElement:Expecting type name - PsiElement(MUL)('*') - PsiWhiteSpace(' ') - PsiErrorElement:Expecting package directive or top level declaration - PsiElement(as)('as') - PsiWhiteSpace('\n\n') - IMPORT_DIRECTIVE - PsiElement(import)('import') - PsiWhiteSpace(' ') - REFERENCE_EXPRESSION - PsiElement(IDENTIFIER)('foo') - PsiWhiteSpace(' ') - PsiElement(as)('as') - PsiErrorElement:Expecting identifier - - PsiWhiteSpace(' ') - PsiElement(SEMICOLON)(';') - PsiWhiteSpace('\n') - IMPORT_DIRECTIVE - PsiElement(import)('import') - PsiWhiteSpace(' ') - DOT_QUALIFIED_EXPRESSION + IMPORT_LIST + IMPORT_DIRECTIVE + PsiElement(import)('import') + PsiErrorElement:Expecting qualified name + + PsiWhiteSpace('\n\n') + IMPORT_DIRECTIVE + PsiElement(import)('import') + PsiWhiteSpace(' ') REFERENCE_EXPRESSION PsiElement(IDENTIFIER)('foo') PsiElement(DOT)('.') - PsiErrorElement:Qualified name must be a '.'-separated identifier list + PsiErrorElement:Import must be placed on a single line - PsiWhiteSpace(' ') - PsiElement(SEMICOLON)(';') - PsiWhiteSpace('\n') - IMPORT_DIRECTIVE - PsiElement(import)('import') - PsiWhiteSpace(' ') - DOT_QUALIFIED_EXPRESSION + PsiWhiteSpace('\n') + IMPORT_DIRECTIVE + PsiElement(import)('import') + PsiWhiteSpace(' ') + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('foo') + PsiElement(DOT)('.') + PsiElement(MUL)('*') + PsiWhiteSpace('\n') + IMPORT_DIRECTIVE + PsiElement(import)('import') + PsiWhiteSpace(' ') + DOT_QUALIFIED_EXPRESSION + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('foo') + PsiElement(DOT)('.') + PsiErrorElement:Qualified name must be a '.'-separated identifier list + + PsiElement(SEMICOLON)(';') + PsiWhiteSpace('\n') + IMPORT_DIRECTIVE + PsiElement(import)('import') + PsiWhiteSpace(' ') + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('foo') + PsiElement(DOT)('.') + PsiElement(MUL)('*') + PsiElement(SEMICOLON)(';') + PsiWhiteSpace('\n\n') + IMPORT_DIRECTIVE + PsiElement(import)('import') + PsiWhiteSpace(' ') + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('foo') + PsiWhiteSpace(' ') + PsiElement(as)('as') + PsiErrorElement:Expecting identifier + + PsiWhiteSpace('\n') + IMPORT_DIRECTIVE + PsiElement(import)('import') + PsiWhiteSpace(' ') + DOT_QUALIFIED_EXPRESSION + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('foo') + PsiElement(DOT)('.') + PsiErrorElement:Qualified name must be a '.'-separated identifier list + + PsiWhiteSpace(' ') + PsiElement(as)('as') + PsiErrorElement:Expecting identifier + + PsiWhiteSpace('\n') + IMPORT_DIRECTIVE + PsiElement(import)('import') + PsiWhiteSpace(' ') + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('foo') + PsiElement(DOT)('.') + PsiElement(MUL)('*') + PsiWhiteSpace(' ') + PsiElement(as)('as') + PsiErrorElement:Expecting identifier + + PsiWhiteSpace('\n') + IMPORT_DIRECTIVE + PsiElement(import)('import') + PsiWhiteSpace(' ') + DOT_QUALIFIED_EXPRESSION + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('foo') + PsiElement(DOT)('.') + PsiErrorElement:Qualified name must be a '.'-separated identifier list + + PsiWhiteSpace(' ') + PsiElement(as)('as') + PsiErrorElement:Expecting identifier + + PsiWhiteSpace(' ') + PsiElement(SEMICOLON)(';') + PsiWhiteSpace('\n') + IMPORT_DIRECTIVE + PsiElement(import)('import') + PsiWhiteSpace(' ') + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('foo') + PsiElement(DOT)('.') + PsiElement(MUL)('*') + PsiWhiteSpace(' ') + PsiErrorElement:Cannot rename all imported items to one identifier + PsiElement(as)('as') + PsiElement(SEMICOLON)(';') + PsiWhiteSpace('\n\n') + IMPORT_DIRECTIVE + PsiElement(import)('import') + PsiWhiteSpace(' ') + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('foo') + PsiWhiteSpace(' ') + PsiElement(as)('as') + PsiWhiteSpace(' ') + PsiErrorElement:Expecting identifier + PsiElement(DOT)('.') + PsiWhiteSpace('\n') + IMPORT_DIRECTIVE + PsiElement(import)('import') + PsiWhiteSpace(' ') + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('foo') + PsiWhiteSpace(' ') + PsiElement(as)('as') + PsiErrorElement:Expecting identifier + + PsiWhiteSpace(' ') + PsiElement(SEMICOLON)(';') + PsiWhiteSpace('\n') + IMPORT_DIRECTIVE + PsiElement(import)('import') + PsiWhiteSpace(' ') + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('foo') + PsiWhiteSpace(' ') + PsiElement(as)('as') + PsiWhiteSpace(' ') + PsiErrorElement:Expecting identifier + PsiElement(MUL)('*') + PsiWhiteSpace('\n') + IMPORT_DIRECTIVE + PsiElement(import)('import') + PsiWhiteSpace(' ') + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('foo') + PsiWhiteSpace(' ') + PsiElement(as)('as') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('sdfsdf') + PsiWhiteSpace('\n') + IMPORT_DIRECTIVE + PsiElement(import)('import') + PsiWhiteSpace(' ') + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('foo') + PsiElement(DOT)('.') + PsiElement(MUL)('*') + PsiWhiteSpace(' ') + PsiErrorElement:Cannot rename a all imported items to one identifier + PsiElement(as)('as') + PsiWhiteSpace(' ') + PsiElement(SEMICOLON)(';') + PsiWhiteSpace('\n') + IMPORT_DIRECTIVE + PsiElement(import)('import') + PsiWhiteSpace(' ') + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('foo') + PsiElement(DOT)('.') + PsiElement(MUL)('*') + PsiWhiteSpace(' ') + PsiErrorElement:Cannot rename all imported items to one identifier + PsiElement(as)('as') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('bar') + PsiWhiteSpace('\n') + IMPORT_DIRECTIVE + PsiElement(import)('import') + PsiWhiteSpace(' ') DOT_QUALIFIED_EXPRESSION REFERENCE_EXPRESSION PsiElement(IDENTIFIER)('foo') @@ -162,68 +198,133 @@ JetFile: Imports_ERR.kt REFERENCE_EXPRESSION PsiElement(IDENTIFIER)('bar') PsiElement(DOT)('.') - PsiErrorElement:Qualified name must be a '.'-separated identifier list + PsiErrorElement:Import must be placed on a single line - PsiWhiteSpace(' ') - PsiElement(SEMICOLON)(';') - PsiWhiteSpace('\n') - IMPORT_DIRECTIVE - PsiElement(import)('import') - PsiWhiteSpace(' ') - DOT_QUALIFIED_EXPRESSION - REFERENCE_EXPRESSION - PsiElement(IDENTIFIER)('foo') - PsiElement(DOT)('.') - PsiErrorElement:Qualified name must be a '.'-separated identifier list - - PsiWhiteSpace(' ') - PsiElement(as)('as') - PsiWhiteSpace(' ') - PsiElement(IDENTIFIER)('bar') - PsiWhiteSpace(' ') - PsiElement(SEMICOLON)(';') - PsiWhiteSpace('\n') - IMPORT_DIRECTIVE - PsiElement(import)('import') - PsiWhiteSpace(' ') - DOT_QUALIFIED_EXPRESSION - REFERENCE_EXPRESSION - PsiElement(IDENTIFIER)('foo') - PsiElement(DOT)('.') - REFERENCE_EXPRESSION - PsiElement(IDENTIFIER)('bar') - PsiElement(DOT)('.') - PsiElement(MUL)('*') - PsiWhiteSpace(' ') - PsiErrorElement:Cannot rename a all imported items to one identifier + PsiWhiteSpace('\n') + IMPORT_DIRECTIVE + PsiElement(import)('import') + PsiWhiteSpace(' ') + DOT_QUALIFIED_EXPRESSION + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('foo') + PsiElement(DOT)('.') + PsiErrorElement:Qualified name must be a '.'-separated identifier list + + PsiWhiteSpace(' ') PsiElement(as)('as') PsiWhiteSpace(' ') PsiElement(IDENTIFIER)('bar') - PsiWhiteSpace(' ') - PsiElement(SEMICOLON)(';') - PsiWhiteSpace('\n') - IMPORT_DIRECTIVE - PsiElement(import)('import') - PsiWhiteSpace(' ') - DOT_QUALIFIED_EXPRESSION - REFERENCE_EXPRESSION - PsiElement(IDENTIFIER)('foo') - PsiElement(DOT)('.') - REFERENCE_EXPRESSION - PsiElement(IDENTIFIER)('bar') - PsiElement(DOT)('.') - PsiElement(MUL)('*') - PsiWhiteSpace(' ') - PsiErrorElement:Cannot rename a all imported items to one identifier + PsiWhiteSpace('\n') + IMPORT_DIRECTIVE + PsiElement(import)('import') + PsiWhiteSpace(' ') + DOT_QUALIFIED_EXPRESSION + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('foo') + PsiElement(DOT)('.') + PsiErrorElement:Qualified name must be a '.'-separated identifier list + + PsiWhiteSpace(' ') PsiElement(as)('as') - PsiWhiteSpace(' ') - PsiElement(SEMICOLON)(';') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('bar') + PsiWhiteSpace(' ') + PsiElement(SEMICOLON)(';') + PsiWhiteSpace('\n\n') + IMPORT_DIRECTIVE + PsiElement(import)('import') + PsiWhiteSpace(' ') + DOT_QUALIFIED_EXPRESSION + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('foo') + PsiElement(DOT)('.') + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('bar') + PsiElement(DOT)('.') + PsiElement(MUL)('*') + PsiWhiteSpace(' ') + PsiErrorElement:Cannot rename all imported items to one identifier + PsiElement(as)('as') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('bar') + PsiWhiteSpace('\n') + IMPORT_DIRECTIVE + PsiElement(import)('import') + PsiWhiteSpace(' ') + DOT_QUALIFIED_EXPRESSION + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('foo') + PsiElement(DOT)('.') + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('bar') + PsiElement(DOT)('.') + PsiElement(MUL)('*') + PsiWhiteSpace(' ') + PsiElement(as)('as') + PsiErrorElement:Expecting identifier + + PsiWhiteSpace('\n') + IMPORT_DIRECTIVE + PsiElement(import)('import') + PsiWhiteSpace(' ') + DOT_QUALIFIED_EXPRESSION + DOT_QUALIFIED_EXPRESSION + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('foo') + PsiElement(DOT)('.') + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('bar') + PsiElement(DOT)('.') + PsiErrorElement:Qualified name must be a '.'-separated identifier list + + PsiWhiteSpace(' ') + PsiElement(SEMICOLON)(';') + PsiWhiteSpace('\n') + IMPORT_DIRECTIVE + PsiElement(import)('import') + PsiWhiteSpace(' ') + DOT_QUALIFIED_EXPRESSION + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('foo') + PsiElement(DOT)('.') + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('bar') + PsiElement(DOT)('.') + PsiElement(MUL)('*') + PsiWhiteSpace(' ') + PsiErrorElement:Cannot rename all imported items to one identifier + PsiElement(as)('as') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('bar') + PsiWhiteSpace(' ') + PsiElement(SEMICOLON)(';') + PsiWhiteSpace('\n') + IMPORT_DIRECTIVE + PsiElement(import)('import') + PsiWhiteSpace(' ') + DOT_QUALIFIED_EXPRESSION + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('foo') + PsiElement(DOT)('.') + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('bar') + PsiElement(DOT)('.') + PsiElement(MUL)('*') + PsiWhiteSpace(' ') + PsiErrorElement:Cannot rename all imported items to one identifier + PsiElement(as)('as') + PsiWhiteSpace(' ') + PsiElement(SEMICOLON)(';') PsiWhiteSpace('\n\n') - CLASS - PsiElement(class)('class') + FUN + PsiElement(fun)('fun') PsiWhiteSpace(' ') - PsiElement(IDENTIFIER)('Foo') + PsiElement(IDENTIFIER)('foo') + VALUE_PARAMETER_LIST + PsiElement(LPAR)('(') + PsiElement(RPAR)(')') PsiWhiteSpace(' ') - CLASS_BODY + BLOCK PsiElement(LBRACE)('{') + PsiWhiteSpace('\n\n') PsiElement(RBRACE)('}') \ No newline at end of file diff --git a/compiler/testData/psi/SoftKeywords.txt b/compiler/testData/psi/SoftKeywords.txt index 2761b8fb755..a77557ea810 100644 --- a/compiler/testData/psi/SoftKeywords.txt +++ b/compiler/testData/psi/SoftKeywords.txt @@ -11,11 +11,12 @@ JetFile: SoftKeywords.kt REFERENCE_EXPRESSION PsiElement(IDENTIFIER)('goo') PsiWhiteSpace('\n\n') - IMPORT_DIRECTIVE - PsiElement(import)('import') - PsiWhiteSpace(' ') - REFERENCE_EXPRESSION - PsiElement(IDENTIFIER)('foo') + IMPORT_LIST + IMPORT_DIRECTIVE + PsiElement(import)('import') + PsiWhiteSpace(' ') + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('foo') PsiWhiteSpace('\n\n') CLASS MODIFIER_LIST diff --git a/compiler/testData/psi/recovery/ImportRecovery.txt b/compiler/testData/psi/recovery/ImportRecovery.txt index 467e83172fe..f00d408bb7b 100644 --- a/compiler/testData/psi/recovery/ImportRecovery.txt +++ b/compiler/testData/psi/recovery/ImportRecovery.txt @@ -1,10 +1,10 @@ JetFile: ImportRecovery.kt NAMESPACE_HEADER - IMPORT_DIRECTIVE - PsiElement(import)('import') - PsiWhiteSpace(' ') - DOT_QUALIFIED_EXPRESSION + IMPORT_LIST + IMPORT_DIRECTIVE + PsiElement(import)('import') + PsiWhiteSpace(' ') DOT_QUALIFIED_EXPRESSION REFERENCE_EXPRESSION PsiElement(IDENTIFIER)('some') @@ -12,7 +12,7 @@ JetFile: ImportRecovery.kt REFERENCE_EXPRESSION PsiElement(IDENTIFIER)('test') PsiElement(DOT)('.') - PsiErrorElement:Qualified name must be a '.'-separated identifier list + PsiErrorElement:Import must be placed on a single line PsiWhiteSpace('\n\n') PsiComment(EOL_COMMENT)('// Some') diff --git a/compiler/tests/org/jetbrains/jet/lang/psi/JetPsiUtilTest.java b/compiler/tests/org/jetbrains/jet/lang/psi/JetPsiUtilTest.java index 4ab390859c1..5ea4003314c 100644 --- a/compiler/tests/org/jetbrains/jet/lang/psi/JetPsiUtilTest.java +++ b/compiler/tests/org/jetbrains/jet/lang/psi/JetPsiUtilTest.java @@ -62,7 +62,6 @@ public class JetPsiUtilTest extends JetLiteFixture { Assert.assertEquals(new ImportPath(new FqName("some.test"), true), getImportPathFromParsed("import some.test.*")); Assert.assertEquals(new ImportPath(new FqName("some.test"), false, Name.identifier("SomeTest")), getImportPathFromParsed("import some.test as SomeTest")); - Assert.assertEquals(new ImportPath(new FqName("some.Test"), false), getImportPathFromParsed("import some.\nTest")); Assert.assertEquals(new ImportPath(new FqName("some.Test"), false), getImportPathFromParsed("import some./* hello world */Test")); Assert.assertEquals(new ImportPath(new FqName("some.Test"), false), getImportPathFromParsed("import some. Test")); diff --git a/idea/src/org/jetbrains/jet/plugin/JetFoldingBuilder.java b/idea/src/org/jetbrains/jet/plugin/JetFoldingBuilder.java index cb4494691c8..e6bda54d692 100644 --- a/idea/src/org/jetbrains/jet/plugin/JetFoldingBuilder.java +++ b/idea/src/org/jetbrains/jet/plugin/JetFoldingBuilder.java @@ -31,6 +31,7 @@ import org.jetbrains.jet.JetNodeTypes; import org.jetbrains.jet.kdoc.lexer.KDocTokens; import org.jetbrains.jet.lang.psi.JetFile; import org.jetbrains.jet.lang.psi.JetImportDirective; +import org.jetbrains.jet.lang.psi.JetImportList; import org.jetbrains.jet.lexer.JetTokens; import java.util.ArrayList; @@ -46,14 +47,16 @@ public class JetFoldingBuilder extends FoldingBuilderEx implements DumbAware { List descriptors = new ArrayList(); JetFile file = (JetFile) root; - List importList = file.getImportDirectives(); - if (importList != null && importList.size() > 1) { - JetImportDirective firstImport = importList.get(0); - PsiElement importKeyword = firstImport.getFirstChild(); + List imports = file.getImportDirectives(); + if (imports.size() > 1) { + PsiElement importKeyword = imports.get(0).getFirstChild(); int startOffset = importKeyword.getTextRange().getEndOffset() + 1; - int endOffset = importList.get(importList.size() - 1).getTextRange().getEndOffset(); + + JetImportList importList = file.getImportList(); + int endOffset = importList.getTextRange().getEndOffset(); + TextRange range = new TextRange(startOffset, endOffset); - descriptors.add(new FoldingDescriptor(firstImport, range)); + descriptors.add(new FoldingDescriptor(importList, range)); } appendDescriptors(root.getNode(), document, descriptors); @@ -86,7 +89,7 @@ public class JetFoldingBuilder extends FoldingBuilderEx implements DumbAware { if (node.getElementType() == KDocTokens.KDOC) { return "/**...*/"; } - if (node.getPsi() instanceof JetImportDirective) { + if (node.getPsi() instanceof JetImportList) { return "..."; } return "{...}"; @@ -96,7 +99,7 @@ public class JetFoldingBuilder extends FoldingBuilderEx implements DumbAware { public boolean isCollapsedByDefault(@NotNull ASTNode astNode) { JavaCodeFoldingSettings settings = JavaCodeFoldingSettings.getInstance(); - if (astNode.getPsi() instanceof JetImportDirective) { + if (astNode.getPsi() instanceof JetImportList) { return settings.isCollapseImports(); } diff --git a/idea/src/org/jetbrains/jet/plugin/formatter/JetFormattingModelBuilder.java b/idea/src/org/jetbrains/jet/plugin/formatter/JetFormattingModelBuilder.java index aa740e1bbb0..ff8f3473af5 100644 --- a/idea/src/org/jetbrains/jet/plugin/formatter/JetFormattingModelBuilder.java +++ b/idea/src/org/jetbrains/jet/plugin/formatter/JetFormattingModelBuilder.java @@ -52,7 +52,7 @@ public class JetFormattingModelBuilder implements FormattingModelBuilder { .after(NAMESPACE_HEADER).blankLines(1) .between(IMPORT_DIRECTIVE, IMPORT_DIRECTIVE).lineBreakInCode() - .after(IMPORT_DIRECTIVE).blankLines(1) + .after(IMPORT_LIST).blankLines(1) .before(DOC_COMMENT).lineBreakInCode() .before(FUN).lineBreakInCode() diff --git a/idea/src/org/jetbrains/jet/plugin/quickfix/ImportInsertHelper.java b/idea/src/org/jetbrains/jet/plugin/quickfix/ImportInsertHelper.java index 08283ca310d..da49103a0e1 100644 --- a/idea/src/org/jetbrains/jet/plugin/quickfix/ImportInsertHelper.java +++ b/idea/src/org/jetbrains/jet/plugin/quickfix/ImportInsertHelper.java @@ -125,21 +125,20 @@ public class ImportInsertHelper { writeImportToFile(importPath, file); } - public static void writeImportToFile(ImportPath importPath, JetFile file) { - JetImportDirective newDirective = JetPsiFactory.createImportDirective(file.getProject(), importPath); - List importDirectives = file.getImportDirectives(); - - if (!importDirectives.isEmpty()) { - JetImportDirective lastDirective = importDirectives.get(importDirectives.size() - 1); - lastDirective.getParent().addAfter(newDirective, lastDirective); + public static void writeImportToFile(@NotNull ImportPath importPath, @NotNull JetFile file) { + JetImportList importList = file.getImportList(); + if (importList != null) { + JetImportDirective newDirective = JetPsiFactory.createImportDirective(file.getProject(), importPath); + importList.add(newDirective); } else { + JetImportList newDirective = JetPsiFactory.createImportDirectiveWithImportList(file.getProject(), importPath); JetNamespaceHeader header = file.getNamespaceHeader(); if (header == null) { throw new IllegalStateException("Scripts are not supported: " + file.getName()); } - header.getParent().addAfter(newDirective, file.getNamespaceHeader()); + header.getParent().addAfter(newDirective, header); } } diff --git a/idea/testData/folding/afterOptimizeImports/foldingAfterOptimizeImportsRemoveFirst.kt b/idea/testData/folding/afterOptimizeImports/foldingAfterOptimizeImportsRemoveFirst.kt new file mode 100644 index 00000000000..9ade2c38211 --- /dev/null +++ b/idea/testData/folding/afterOptimizeImports/foldingAfterOptimizeImportsRemoveFirst.kt @@ -0,0 +1,12 @@ +package sometest + +import java.util.ArrayList +import java.util.HashSet +import java.util.HashMap + +val some: HashSet? = null +val some2: HashMap? = null + +// SET_TRUE: setCollapseImports +// REGION BEFORE: 25:94 +// REGION AFTER: 25:67 \ No newline at end of file diff --git a/idea/testData/quickfix/override/nothingToOverride/import.before.Main.kt b/idea/testData/quickfix/override/nothingToOverride/import.before.Main.kt index 7b981a0662c..64ace0dffc8 100644 --- a/idea/testData/quickfix/override/nothingToOverride/import.before.Main.kt +++ b/idea/testData/quickfix/override/nothingToOverride/import.before.Main.kt @@ -2,6 +2,7 @@ // ERROR: 'f' overrides nothing // ERROR: 'f' overrides nothing import a.B + class BB : B() { override fun f() {} } diff --git a/idea/testData/quickfix/typeImports/afterHasThisImport.kt b/idea/testData/quickfix/typeImports/afterHasThisImport.kt index dc3fad4764a..be22e3bb09e 100644 --- a/idea/testData/quickfix/typeImports/afterHasThisImport.kt +++ b/idea/testData/quickfix/typeImports/afterHasThisImport.kt @@ -2,14 +2,10 @@ package a import java.util.Collections - -package b { - import java.util.List class M { trait A { val l: jet.List } -} } \ No newline at end of file diff --git a/idea/testData/quickfix/typeImports/beforeHasThisImport.kt b/idea/testData/quickfix/typeImports/beforeHasThisImport.kt index 284c4ad6202..e8bfff62534 100644 --- a/idea/testData/quickfix/typeImports/beforeHasThisImport.kt +++ b/idea/testData/quickfix/typeImports/beforeHasThisImport.kt @@ -2,14 +2,10 @@ package a import java.util.Collections - -package b { - import java.util.List class M { trait A { val l = Collections.emptyList() } -} } \ No newline at end of file diff --git a/idea/tests/org/jetbrains/jet/plugin/folding/FoldingAfterOptimizeImportsTest.kt b/idea/tests/org/jetbrains/jet/plugin/folding/FoldingAfterOptimizeImportsTest.kt index 1c33d0a0a83..c18baab0525 100644 --- a/idea/tests/org/jetbrains/jet/plugin/folding/FoldingAfterOptimizeImportsTest.kt +++ b/idea/tests/org/jetbrains/jet/plugin/folding/FoldingAfterOptimizeImportsTest.kt @@ -42,6 +42,10 @@ class FoldingAfterOptimizeImportsTest : AbstractKotlinFoldingTest() { doTest() } + fun testFoldingAfterOptimizeImportsRemoveFirst() { + doTest() + } + private fun doTest() { fixture.configureByFile(getTestName(true) + ".kt")