Completion fails with exception "Toplevel class has no fqName" (KT-5119)
Groovy scripts files can create PsiClasses with null qualfied names (getQualifiedName()) and names (getName()). #KT-5119 Fixed
This commit is contained in:
+19
-1
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010-2013 JetBrains s.r.o.
|
||||
* Copyright 2010-2014 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.
|
||||
@@ -17,6 +17,8 @@
|
||||
package org.jetbrains.jet.lang.resolve.java.structure.impl;
|
||||
|
||||
import com.intellij.psi.*;
|
||||
import kotlin.Function1;
|
||||
import kotlin.KotlinPackage;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.resolve.java.structure.*;
|
||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
@@ -141,11 +143,27 @@ public class JavaElementCollectionFromPsiArrayUtil {
|
||||
return result;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static <Psi, Java> List<Java> convert(@NotNull Iterable<Psi> elements, @NotNull final Factory<Psi, Java> factory) {
|
||||
if (!elements.iterator().hasNext()) return Collections.emptyList();
|
||||
return KotlinPackage.map(elements, new Function1<Psi, Java>() {
|
||||
@Override
|
||||
public Java invoke(Psi psi) {
|
||||
return factory.create(psi);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static Collection<JavaClass> classes(@NotNull PsiClass[] classes) {
|
||||
return convert(classes, Factories.CLASSES);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static Collection<JavaClass> classes(@NotNull Iterable<PsiClass> classes) {
|
||||
return convert(classes, Factories.CLASSES);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static Collection<JavaPackage> packages(@NotNull PsiPackage[] packages) {
|
||||
return convert(packages, Factories.PACKAGES);
|
||||
|
||||
+10
-2
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010-2013 JetBrains s.r.o.
|
||||
* Copyright 2010-2014 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.
|
||||
@@ -16,7 +16,10 @@
|
||||
|
||||
package org.jetbrains.jet.lang.resolve.java.structure.impl;
|
||||
|
||||
import com.intellij.openapi.util.Condition;
|
||||
import com.intellij.psi.PsiClass;
|
||||
import com.intellij.psi.PsiPackage;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.resolve.java.structure.JavaClass;
|
||||
import org.jetbrains.jet.lang.resolve.java.structure.JavaPackage;
|
||||
@@ -35,7 +38,12 @@ public class JavaPackageImpl extends JavaElementImpl<PsiPackage> implements Java
|
||||
@Override
|
||||
@NotNull
|
||||
public Collection<JavaClass> getClasses() {
|
||||
return classes(getPsi().getClasses());
|
||||
return classes(ContainerUtil.filter(getPsi().getClasses(), new Condition<PsiClass>() {
|
||||
@Override
|
||||
public boolean value(PsiClass aClass) {
|
||||
return aClass.getName() != null;
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user