Moved getPackageFilesWithCallables to frontend.java and reused it.
This commit is contained in:
@@ -20,7 +20,6 @@ import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Ordering;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.progress.ProcessCanceledException;
|
||||
import com.intellij.openapi.util.Condition;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import com.intellij.util.SmartList;
|
||||
@@ -90,7 +89,7 @@ public class PackageCodegen {
|
||||
|
||||
String className = AsmUtil.internalNameByFqNameWithoutInnerClasses(getPackageClassFqName(fqName));
|
||||
ClassBuilder v = PackageCodegen.this.state.getFactory()
|
||||
.newVisitor(Type.getObjectType(className), getPackageFilesWithCallables(files));
|
||||
.newVisitor(Type.getObjectType(className), PackagePartClassUtils.getPackageFilesWithCallables(files));
|
||||
v.defineClass(sourceFile, V1_6,
|
||||
ACC_PUBLIC | ACC_FINAL,
|
||||
className,
|
||||
@@ -114,7 +113,7 @@ public class PackageCodegen {
|
||||
return null;
|
||||
}
|
||||
|
||||
List<JetFile> packageFilesWithCallables = getPackageFilesWithCallables(packageFiles);
|
||||
List<JetFile> packageFilesWithCallables = PackagePartClassUtils.getPackageFilesWithCallables(packageFiles);
|
||||
return packageFilesWithCallables.size() == 1 ? packageFilesWithCallables.get(0) : null;
|
||||
}
|
||||
|
||||
@@ -358,21 +357,6 @@ public class PackageCodegen {
|
||||
MemberCodegen.genClassOrObject(context, classOrObject, state, null);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static List<JetFile> getPackageFilesWithCallables(@NotNull Collection<JetFile> packageFiles) {
|
||||
return ContainerUtil.filter(packageFiles, new Condition<JetFile>() {
|
||||
@Override
|
||||
public boolean value(JetFile packageFile) {
|
||||
for (JetDeclaration declaration : packageFile.getDeclarations()) {
|
||||
if (declaration instanceof JetProperty || declaration instanceof JetNamedFunction) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void done() {
|
||||
v.done();
|
||||
}
|
||||
|
||||
+23
@@ -16,18 +16,26 @@
|
||||
|
||||
package org.jetbrains.jet.lang.resolve.kotlin;
|
||||
|
||||
import com.intellij.openapi.util.Condition;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.util.PathUtil;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.descriptors.serialization.descriptors.DeserializedCallableMemberDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.PackageFragmentDescriptor;
|
||||
import org.jetbrains.jet.lang.psi.JetDeclaration;
|
||||
import org.jetbrains.jet.lang.psi.JetFile;
|
||||
import org.jetbrains.jet.lang.psi.JetNamedFunction;
|
||||
import org.jetbrains.jet.lang.psi.JetProperty;
|
||||
import org.jetbrains.jet.lang.resolve.java.JvmClassName;
|
||||
import org.jetbrains.jet.lang.resolve.name.FqName;
|
||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
import org.jetbrains.org.objectweb.asm.Type;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import static org.jetbrains.jet.lang.resolve.java.PackageClassUtils.getPackageClassFqName;
|
||||
|
||||
public class PackagePartClassUtils {
|
||||
@@ -70,4 +78,19 @@ public class PackagePartClassUtils {
|
||||
FqName packageFqName = ((PackageFragmentDescriptor) callable.getContainingDeclaration()).getFqName();
|
||||
return packageFqName.child(BaseDescriptorLoader.getPackagePartClassName(callable));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static List<JetFile> getPackageFilesWithCallables(@NotNull Collection<JetFile> packageFiles) {
|
||||
return ContainerUtil.filter(packageFiles, new Condition<JetFile>() {
|
||||
@Override
|
||||
public boolean value(JetFile packageFile) {
|
||||
for (JetDeclaration declaration : packageFile.getDeclarations()) {
|
||||
if (declaration instanceof JetProperty || declaration instanceof JetNamedFunction) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
+2
-4
@@ -79,10 +79,8 @@ public class IncrementalPackageFragmentProvider(
|
||||
fqNameToPackageFragment[fqName] = IncrementalPackageFragment(fqName)
|
||||
}
|
||||
|
||||
for (source in sourceFiles) {
|
||||
if (source.getDeclarations().any { it is JetProperty || it is JetNamedFunction }) {
|
||||
createPackageFragment(source.getPackageFqName())
|
||||
}
|
||||
for (source in PackagePartClassUtils.getPackageFilesWithCallables(sourceFiles)) {
|
||||
createPackageFragment(source.getPackageFqName())
|
||||
}
|
||||
|
||||
for (fqName in incrementalCache.getPackagesWithRemovedFiles(moduleId, sourceFiles)) {
|
||||
|
||||
@@ -37,6 +37,7 @@ import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.lang.resolve.java.JavaPsiFacadeKotlinHacks;
|
||||
import org.jetbrains.jet.lang.resolve.java.PackageClassUtils;
|
||||
import org.jetbrains.jet.lang.resolve.kotlin.PackagePartClassUtils;
|
||||
import org.jetbrains.jet.lang.resolve.name.FqName;
|
||||
import org.jetbrains.jet.lang.resolve.name.NamePackage;
|
||||
|
||||
@@ -141,7 +142,7 @@ public class JavaElementFinder extends PsiElementFinder implements JavaPsiFacade
|
||||
|
||||
private void findPackageClass(FqName qualifiedName, GlobalSearchScope scope, List<PsiClass> answer) {
|
||||
Collection<JetFile> filesForPackage = lightClassGenerationSupport.findFilesForPackage(qualifiedName, scope);
|
||||
if (!shouldGeneratePackageClass(filesForPackage)) return;
|
||||
if (PackagePartClassUtils.getPackageFilesWithCallables(filesForPackage).isEmpty()) return;
|
||||
|
||||
KotlinLightClassForPackage lightClass = KotlinLightClassForPackage.create(psiManager, qualifiedName, scope, filesForPackage);
|
||||
if (lightClass == null) return;
|
||||
@@ -155,18 +156,6 @@ public class JavaElementFinder extends PsiElementFinder implements JavaPsiFacade
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean shouldGeneratePackageClass(@NotNull Collection<JetFile> packageFiles) {
|
||||
for (JetFile file : packageFiles) {
|
||||
for (JetDeclaration declaration : file.getDeclarations()) {
|
||||
if (declaration instanceof JetProperty || declaration instanceof JetNamedFunction) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Set<String> getClassNames(@NotNull PsiPackage psiPackage, @NotNull GlobalSearchScope scope) {
|
||||
|
||||
Reference in New Issue
Block a user