Add common JetElement for imports: JetImportList

This commit is contained in:
Natalia Ukhorskaya
2013-10-23 18:07:22 +04:00
parent 796dad5798
commit 3287744415
24 changed files with 550 additions and 343 deletions
@@ -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);
@@ -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);
}
}
@@ -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<JetImportDirective> getImportDirectives() {
return PsiTreeUtil.getChildrenOfTypeAsList(this, JetImportDirective.class);
JetImportList importList = getImportList();
return importList != null ? importList.getImports() : Collections.<JetImportDirective>emptyList();
}
@Nullable
@@ -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, D> R accept(@NotNull JetVisitor<R, D> visitor, D data) {
return visitor.visitImportList(this, data);
}
@NotNull
public List<JetImportDirective> getImports() {
return PsiTreeUtil.getChildrenOfTypeAsList(this, JetImportDirective.class);
}
}
@@ -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()");
@@ -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<JetImportDirective> getImportDirectives() {
return PsiTreeUtil.getChildrenOfTypeAsList(this, JetImportDirective.class);
JetImportList importList = getImportList();
return importList != null ? importList.getImports() : Collections.<JetImportDirective>emptyList();
}
@NotNull
@@ -70,6 +70,10 @@ public class JetVisitor<R, D> 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);
}
@@ -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);
}
@@ -1,3 +1,3 @@
import
import<!SYNTAX!><!>
<!SYNTAX!><!>fun firstFun() {}
fun firstFun() {}
+14 -13
View File
@@ -1,24 +1,25 @@
JetFile: ImportSoftKW.kt
NAMESPACE_HEADER
<empty list>
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')
PsiWhiteSpace(' ')
PsiElement(as)('as')
PsiWhiteSpace(' ')
PsiElement(IDENTIFIER)('import')
+51 -50
View File
@@ -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)('*')
PsiWhiteSpace(' ')
PsiElement(MUL)('*')
+23 -6
View File
@@ -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 {}
fun foo() {
}
+296 -195
View File
@@ -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
<empty list>
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
<empty list>
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
<empty list>
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
<empty 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
<empty list>
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
<empty list>
PsiWhiteSpace(' ')
PsiElement(as)('as')
PsiErrorElement:Expecting identifier
<empty list>
PsiWhiteSpace('\n')
IMPORT_DIRECTIVE
PsiElement(import)('import')
PsiWhiteSpace(' ')
REFERENCE_EXPRESSION
PsiElement(IDENTIFIER)('foo')
PsiElement(DOT)('.')
PsiElement(MUL)('*')
PsiWhiteSpace(' ')
PsiElement(as)('as')
PsiErrorElement:Expecting identifier
<empty list>
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
<empty list>
PsiWhiteSpace(' ')
PsiElement(as)('as')
PsiErrorElement:Expecting identifier
<empty list>
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
<empty list>
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
<empty list>
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
<empty 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
<empty 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
<empty 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
<empty list>
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
<empty 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)('}')
+6 -5
View File
@@ -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
@@ -1,10 +1,10 @@
JetFile: ImportRecovery.kt
NAMESPACE_HEADER
<empty list>
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
<empty list>
PsiWhiteSpace('\n\n')
PsiComment(EOL_COMMENT)('// Some')
@@ -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"));
@@ -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<FoldingDescriptor> descriptors = new ArrayList<FoldingDescriptor>();
JetFile file = (JetFile) root;
List<JetImportDirective> importList = file.getImportDirectives();
if (importList != null && importList.size() > 1) {
JetImportDirective firstImport = importList.get(0);
PsiElement importKeyword = firstImport.getFirstChild();
List<JetImportDirective> 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();
}
@@ -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()
@@ -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<JetImportDirective> 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);
}
}
@@ -0,0 +1,12 @@
package sometest
import java.util.ArrayList
import java.util.HashSet
import java.util.HashMap
val some: HashSet<Int>? = null
val some2: HashMap<Int, Int>? = null
// SET_TRUE: setCollapseImports
// REGION BEFORE: 25:94
// REGION AFTER: 25:67
@@ -2,6 +2,7 @@
// ERROR: 'f' overrides nothing
// ERROR: 'f' overrides nothing
import a.B
class BB : B() {
<caret>override fun f() {}
}
@@ -2,14 +2,10 @@
package a
import java.util.Collections
package b {
import java.util.List
class M {
trait A {
val l: jet.List<Int><caret>
}
}
}
@@ -2,14 +2,10 @@
package a
import java.util.Collections
package b {
import java.util.List
class M {
trait A {
val l = <caret>Collections.emptyList<Int>()
}
}
}
@@ -42,6 +42,10 @@ class FoldingAfterOptimizeImportsTest : AbstractKotlinFoldingTest() {
doTest()
}
fun testFoldingAfterOptimizeImportsRemoveFirst() {
doTest()
}
private fun doTest() {
fixture.configureByFile(getTestName(true) + ".kt")