Fix import resolution for some cases of malformed imports ("import some.")
Fix parsing import directives in case of non-identifier after "import" Add diagnostics test for malformed imports
This commit is contained in:
@@ -286,10 +286,18 @@ public class JetParsing extends AbstractJetParsing {
|
||||
return;
|
||||
}
|
||||
|
||||
PsiBuilder.Marker qualifiedName = mark();
|
||||
if (!at(IDENTIFIER)) {
|
||||
PsiBuilder.Marker error = mark();
|
||||
skipUntil(TokenSet.create(EOL_OR_SEMICOLON));
|
||||
error.error("Expecting qualified name");
|
||||
importDirective.done(IMPORT_DIRECTIVE);
|
||||
consumeIf(SEMICOLON);
|
||||
return;
|
||||
}
|
||||
|
||||
PsiBuilder.Marker qualifiedName = mark();
|
||||
PsiBuilder.Marker reference = mark();
|
||||
expect(IDENTIFIER, "Expecting qualified name");
|
||||
advance(); // IDENTIFIER
|
||||
reference.done(REFERENCE_EXPRESSION);
|
||||
|
||||
while (at(DOT) && lookahead(1) != MUL) {
|
||||
|
||||
@@ -100,8 +100,6 @@ public class JetImportDirective extends JetElementImplStub<KotlinImportDirective
|
||||
@Nullable
|
||||
@IfNotParsed
|
||||
public ImportPath getImportPath() {
|
||||
if (!isValidImport()) return null;
|
||||
|
||||
FqName importFqn = fqNameFromExpression(getImportedReference());
|
||||
if (importFqn == null) {
|
||||
return null;
|
||||
@@ -134,8 +132,13 @@ public class JetImportDirective extends JetElementImplStub<KotlinImportDirective
|
||||
JetDotQualifiedExpression dotQualifiedExpression = (JetDotQualifiedExpression) expression;
|
||||
FqName parentFqn = fqNameFromExpression(dotQualifiedExpression.getReceiverExpression());
|
||||
Name child = nameFromExpression(dotQualifiedExpression.getSelectorExpression());
|
||||
|
||||
return parentFqn != null && child != null ? parentFqn.child(child) : null;
|
||||
if (child == null) {
|
||||
return parentFqn;
|
||||
}
|
||||
if (parentFqn != null) {
|
||||
return parentFqn.child(child);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
else if (expression instanceof JetSimpleNameExpression) {
|
||||
JetSimpleNameExpression simpleNameExpression = (JetSimpleNameExpression) expression;
|
||||
|
||||
+1
-1
@@ -36,7 +36,7 @@ import org.jetbrains.kotlin.psi.stubs.impl.KotlinFileStubImpl;
|
||||
import java.io.IOException;
|
||||
|
||||
public class JetFileElementType extends IStubFileElementType<KotlinFileStub> {
|
||||
public static final int STUB_VERSION = 47;
|
||||
public static final int STUB_VERSION = 48;
|
||||
|
||||
private static final String NAME = "kotlin.FILE";
|
||||
|
||||
|
||||
Reference in New Issue
Block a user