Implement stub based package declaration provider for lazy resolve
Implement StubPackageMemberDeclarationProvider Introduce DeclarationProviderFactoryService to provide difference factories in CLI and Plugin When indexing treat top level declarations without name specially so that they can be found in index Implement PluginDeclarationProviderFactoryService which uses file based approach for non indexed files and stub based for others
This commit is contained in:
@@ -1,4 +1,11 @@
|
|||||||
<root>
|
<root>
|
||||||
|
<item name='com.intellij.psi.stubs.AbstractStubIndex java.util.Collection<Key> getAllKeys(com.intellij.openapi.project.Project)'>
|
||||||
|
<annotation name='org.jetbrains.annotations.NotNull'/>
|
||||||
|
</item>
|
||||||
|
<item
|
||||||
|
name='com.intellij.psi.stubs.AbstractStubIndex java.util.Collection<Psi> get(Key, com.intellij.openapi.project.Project, com.intellij.psi.search.GlobalSearchScope)'>
|
||||||
|
<annotation name='org.jetbrains.annotations.NotNull'/>
|
||||||
|
</item>
|
||||||
<item
|
<item
|
||||||
name='com.intellij.psi.stubs.AbstractStubIndex java.util.Collection<Psi> get(Key, com.intellij.openapi.project.Project, com.intellij.psi.search.GlobalSearchScope) 2'>
|
name='com.intellij.psi.stubs.AbstractStubIndex java.util.Collection<Psi> get(Key, com.intellij.openapi.project.Project, com.intellij.psi.search.GlobalSearchScope) 2'>
|
||||||
<annotation name='org.jetbrains.annotations.NotNull'/>
|
<annotation name='org.jetbrains.annotations.NotNull'/>
|
||||||
|
|||||||
@@ -57,6 +57,8 @@ import org.jetbrains.jet.lang.psi.JetFile;
|
|||||||
import org.jetbrains.jet.lang.resolve.java.JetFilesProvider;
|
import org.jetbrains.jet.lang.resolve.java.JetFilesProvider;
|
||||||
import org.jetbrains.jet.lang.resolve.kotlin.KotlinBinaryClassCache;
|
import org.jetbrains.jet.lang.resolve.kotlin.KotlinBinaryClassCache;
|
||||||
import org.jetbrains.jet.lang.resolve.kotlin.VirtualFileFinder;
|
import org.jetbrains.jet.lang.resolve.kotlin.VirtualFileFinder;
|
||||||
|
import org.jetbrains.jet.lang.resolve.lazy.declarations.CliDeclarationProviderFactoryService;
|
||||||
|
import org.jetbrains.jet.lang.resolve.lazy.declarations.DeclarationProviderFactoryService;
|
||||||
import org.jetbrains.jet.plugin.JetFileType;
|
import org.jetbrains.jet.plugin.JetFileType;
|
||||||
import org.jetbrains.jet.utils.PathUtil;
|
import org.jetbrains.jet.utils.PathUtil;
|
||||||
|
|
||||||
@@ -75,7 +77,10 @@ public class JetCoreEnvironment {
|
|||||||
private static int ourProjectCount = 0;
|
private static int ourProjectCount = 0;
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public static JetCoreEnvironment createForProduction(@NotNull Disposable parentDisposable, @NotNull CompilerConfiguration configuration) {
|
public static JetCoreEnvironment createForProduction(
|
||||||
|
@NotNull Disposable parentDisposable,
|
||||||
|
@NotNull CompilerConfiguration configuration
|
||||||
|
) {
|
||||||
// JPS may run many instances of the compiler in parallel (there's an option for compiling independent modules in parallel in IntelliJ)
|
// JPS may run many instances of the compiler in parallel (there's an option for compiling independent modules in parallel in IntelliJ)
|
||||||
// All projects share the same ApplicationEnvironment, and when the last project is disposed, the ApplicationEnvironment is disposed as well
|
// All projects share the same ApplicationEnvironment, and when the last project is disposed, the ApplicationEnvironment is disposed as well
|
||||||
Disposer.register(parentDisposable, new Disposable() {
|
Disposer.register(parentDisposable, new Disposable() {
|
||||||
@@ -88,7 +93,8 @@ public class JetCoreEnvironment {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
JetCoreEnvironment environment = new JetCoreEnvironment(parentDisposable, getOrCreateApplicationEnvironmentForProduction(), configuration);
|
JetCoreEnvironment environment =
|
||||||
|
new JetCoreEnvironment(parentDisposable, getOrCreateApplicationEnvironmentForProduction(), configuration);
|
||||||
synchronized (APPLICATION_LOCK) {
|
synchronized (APPLICATION_LOCK) {
|
||||||
ourProjectCount++;
|
ourProjectCount++;
|
||||||
}
|
}
|
||||||
@@ -146,6 +152,8 @@ public class JetCoreEnvironment {
|
|||||||
|
|
||||||
applicationEnvironment.getApplication().registerService(OperationModeProvider.class, new CompilerModeProvider());
|
applicationEnvironment.getApplication().registerService(OperationModeProvider.class, new CompilerModeProvider());
|
||||||
applicationEnvironment.getApplication().registerService(KotlinBinaryClassCache.class, new KotlinBinaryClassCache());
|
applicationEnvironment.getApplication().registerService(KotlinBinaryClassCache.class, new KotlinBinaryClassCache());
|
||||||
|
applicationEnvironment.getApplication().registerService(DeclarationProviderFactoryService.class,
|
||||||
|
new CliDeclarationProviderFactoryService());
|
||||||
|
|
||||||
return applicationEnvironment;
|
return applicationEnvironment;
|
||||||
}
|
}
|
||||||
@@ -185,7 +193,7 @@ public class JetCoreEnvironment {
|
|||||||
CoreApplicationEnvironment.registerExtensionPoint(Extensions.getRootArea(), ClsCustomNavigationPolicy.EP_NAME,
|
CoreApplicationEnvironment.registerExtensionPoint(Extensions.getRootArea(), ClsCustomNavigationPolicy.EP_NAME,
|
||||||
ClsCustomNavigationPolicy.class);
|
ClsCustomNavigationPolicy.class);
|
||||||
CoreApplicationEnvironment.registerExtensionPoint(Extensions.getRootArea(), ClassFileDecompilers.EP_NAME,
|
CoreApplicationEnvironment.registerExtensionPoint(Extensions.getRootArea(), ClassFileDecompilers.EP_NAME,
|
||||||
ClassFileDecompilers.Decompiler.class);
|
ClassFileDecompilers.Decompiler.class);
|
||||||
|
|
||||||
annotationsManager = new CoreExternalAnnotationsManager(project.getComponent(PsiManager.class));
|
annotationsManager = new CoreExternalAnnotationsManager(project.getComponent(PsiManager.class));
|
||||||
project.registerService(ExternalAnnotationsManager.class, annotationsManager);
|
project.registerService(ExternalAnnotationsManager.class, annotationsManager);
|
||||||
|
|||||||
+25
-17
@@ -37,7 +37,8 @@ import org.jetbrains.jet.lang.psi.JetFile;
|
|||||||
import org.jetbrains.jet.lang.resolve.*;
|
import org.jetbrains.jet.lang.resolve.*;
|
||||||
import org.jetbrains.jet.lang.resolve.java.mapping.JavaToKotlinClassMap;
|
import org.jetbrains.jet.lang.resolve.java.mapping.JavaToKotlinClassMap;
|
||||||
import org.jetbrains.jet.lang.resolve.lazy.ResolveSession;
|
import org.jetbrains.jet.lang.resolve.lazy.ResolveSession;
|
||||||
import org.jetbrains.jet.lang.resolve.lazy.declarations.FileBasedDeclarationProviderFactory;
|
import org.jetbrains.jet.lang.resolve.lazy.declarations.DeclarationProviderFactory;
|
||||||
|
import org.jetbrains.jet.lang.resolve.lazy.declarations.DeclarationProviderFactoryService;
|
||||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||||
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
|
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
|
||||||
|
|
||||||
@@ -59,21 +60,24 @@ public enum AnalyzerFacadeForJVM implements AnalyzerFacade {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
@NotNull
|
@NotNull
|
||||||
public AnalyzeExhaust analyzeFiles(@NotNull Project project,
|
public AnalyzeExhaust analyzeFiles(
|
||||||
|
@NotNull Project project,
|
||||||
@NotNull Collection<JetFile> files,
|
@NotNull Collection<JetFile> files,
|
||||||
@NotNull List<AnalyzerScriptParameter> scriptParameters,
|
@NotNull List<AnalyzerScriptParameter> scriptParameters,
|
||||||
@NotNull Predicate<PsiFile> filesToAnalyzeCompletely) {
|
@NotNull Predicate<PsiFile> filesToAnalyzeCompletely
|
||||||
|
) {
|
||||||
return analyzeFilesWithJavaIntegration(project, files, scriptParameters, filesToAnalyzeCompletely, true);
|
return analyzeFilesWithJavaIntegration(project, files, scriptParameters, filesToAnalyzeCompletely, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public AnalyzeExhaust analyzeBodiesInFiles(@NotNull Project project,
|
public AnalyzeExhaust analyzeBodiesInFiles(
|
||||||
@NotNull List<AnalyzerScriptParameter> scriptParameters,
|
@NotNull Project project,
|
||||||
@NotNull Predicate<PsiFile> filesForBodiesResolve,
|
@NotNull List<AnalyzerScriptParameter> scriptParameters,
|
||||||
@NotNull BindingTrace headersTraceContext,
|
@NotNull Predicate<PsiFile> filesForBodiesResolve,
|
||||||
@NotNull BodiesResolveContext bodiesResolveContext,
|
@NotNull BindingTrace headersTraceContext,
|
||||||
@NotNull ModuleDescriptor module
|
@NotNull BodiesResolveContext bodiesResolveContext,
|
||||||
|
@NotNull ModuleDescriptor module
|
||||||
) {
|
) {
|
||||||
return AnalyzerFacadeForEverything.analyzeBodiesInFilesWithJavaIntegration(
|
return AnalyzerFacadeForEverything.analyzeBodiesInFilesWithJavaIntegration(
|
||||||
project, scriptParameters, filesForBodiesResolve,
|
project, scriptParameters, filesForBodiesResolve,
|
||||||
@@ -95,10 +99,8 @@ public enum AnalyzerFacadeForJVM implements AnalyzerFacade {
|
|||||||
) {
|
) {
|
||||||
GlobalContextImpl globalContext = ContextPackage.GlobalContext();
|
GlobalContextImpl globalContext = ContextPackage.GlobalContext();
|
||||||
|
|
||||||
// TODO: Replace with stub declaration provider
|
DeclarationProviderFactory declarationProviderFactory =
|
||||||
FileBasedDeclarationProviderFactory declarationProviderFactory = new FileBasedDeclarationProviderFactory(
|
DeclarationProviderFactoryService.createDeclarationProviderFactory(project, globalContext.getStorageManager(), files);
|
||||||
globalContext.getStorageManager(),
|
|
||||||
files);
|
|
||||||
|
|
||||||
InjectorForLazyResolveWithJava resolveWithJava = new InjectorForLazyResolveWithJava(
|
InjectorForLazyResolveWithJava resolveWithJava = new InjectorForLazyResolveWithJava(
|
||||||
project,
|
project,
|
||||||
@@ -120,7 +122,8 @@ public enum AnalyzerFacadeForJVM implements AnalyzerFacade {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public static AnalyzeExhaust analyzeOneFileWithJavaIntegrationAndCheckForErrors(
|
public static AnalyzeExhaust analyzeOneFileWithJavaIntegrationAndCheckForErrors(
|
||||||
JetFile file, List<AnalyzerScriptParameter> scriptParameters) {
|
JetFile file, List<AnalyzerScriptParameter> scriptParameters
|
||||||
|
) {
|
||||||
AnalyzingUtils.checkForSyntacticErrors(file);
|
AnalyzingUtils.checkForSyntacticErrors(file);
|
||||||
|
|
||||||
AnalyzeExhaust analyzeExhaust = analyzeOneFileWithJavaIntegration(file, scriptParameters);
|
AnalyzeExhaust analyzeExhaust = analyzeOneFileWithJavaIntegration(file, scriptParameters);
|
||||||
@@ -132,7 +135,8 @@ public enum AnalyzerFacadeForJVM implements AnalyzerFacade {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public static AnalyzeExhaust analyzeOneFileWithJavaIntegration(
|
public static AnalyzeExhaust analyzeOneFileWithJavaIntegration(
|
||||||
JetFile file, List<AnalyzerScriptParameter> scriptParameters) {
|
JetFile file, List<AnalyzerScriptParameter> scriptParameters
|
||||||
|
) {
|
||||||
return analyzeFilesWithJavaIntegration(file.getProject(), Collections.singleton(file), scriptParameters,
|
return analyzeFilesWithJavaIntegration(file.getProject(), Collections.singleton(file), scriptParameters,
|
||||||
Predicates.<PsiFile>alwaysTrue());
|
Predicates.<PsiFile>alwaysTrue());
|
||||||
}
|
}
|
||||||
@@ -169,8 +173,12 @@ public enum AnalyzerFacadeForJVM implements AnalyzerFacade {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public static AnalyzeExhaust analyzeFilesWithJavaIntegration(
|
public static AnalyzeExhaust analyzeFilesWithJavaIntegration(
|
||||||
Project project, Collection<JetFile> files, List<AnalyzerScriptParameter> scriptParameters, Predicate<PsiFile> filesToAnalyzeCompletely,
|
Project project,
|
||||||
boolean storeContextForBodiesResolve) {
|
Collection<JetFile> files,
|
||||||
|
List<AnalyzerScriptParameter> scriptParameters,
|
||||||
|
Predicate<PsiFile> filesToAnalyzeCompletely,
|
||||||
|
boolean storeContextForBodiesResolve
|
||||||
|
) {
|
||||||
BindingTraceContext bindingTraceContext = new BindingTraceContext();
|
BindingTraceContext bindingTraceContext = new BindingTraceContext();
|
||||||
|
|
||||||
return analyzeFilesWithJavaIntegration(project, files, bindingTraceContext, scriptParameters, filesToAnalyzeCompletely,
|
return analyzeFilesWithJavaIntegration(project, files, bindingTraceContext, scriptParameters, filesToAnalyzeCompletely,
|
||||||
|
|||||||
@@ -44,7 +44,10 @@ import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
|
|||||||
import org.jetbrains.jet.lexer.JetToken;
|
import org.jetbrains.jet.lexer.JetToken;
|
||||||
import org.jetbrains.jet.lexer.JetTokens;
|
import org.jetbrains.jet.lexer.JetTokens;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.Collection;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
public class JetPsiUtil {
|
public class JetPsiUtil {
|
||||||
private JetPsiUtil() {
|
private JetPsiUtil() {
|
||||||
@@ -205,42 +208,47 @@ public class JetPsiUtil {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FqName parentFqName = getParentFqName(namedDeclaration);
|
||||||
|
|
||||||
|
if (parentFqName == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return parentFqName.child(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public static FqName getParentFqName(@NotNull JetNamedDeclaration namedDeclaration) {
|
||||||
PsiElement parent = namedDeclaration.getParent();
|
PsiElement parent = namedDeclaration.getParent();
|
||||||
if (parent instanceof JetClassBody) {
|
if (parent instanceof JetClassBody) {
|
||||||
// One nesting to JetClassBody doesn't affect to qualified name
|
// One nesting to JetClassBody doesn't affect to qualified name
|
||||||
parent = parent.getParent();
|
parent = parent.getParent();
|
||||||
}
|
}
|
||||||
|
|
||||||
FqName firstPart = null;
|
|
||||||
if (parent instanceof JetFile) {
|
if (parent instanceof JetFile) {
|
||||||
firstPart = getFQName((JetFile) parent);
|
return getFQName((JetFile) parent);
|
||||||
}
|
}
|
||||||
else if (parent instanceof JetNamedFunction || parent instanceof JetClass) {
|
else if (parent instanceof JetNamedFunction || parent instanceof JetClass) {
|
||||||
firstPart = getFQName((JetNamedDeclaration) parent);
|
return getFQName((JetNamedDeclaration) parent);
|
||||||
}
|
}
|
||||||
else if (namedDeclaration instanceof JetParameter) {
|
else if (namedDeclaration instanceof JetParameter) {
|
||||||
JetClass constructorClass = getClassIfParameterIsProperty((JetParameter) namedDeclaration);
|
JetClass constructorClass = getClassIfParameterIsProperty((JetParameter) namedDeclaration);
|
||||||
if (constructorClass != null) {
|
if (constructorClass != null) {
|
||||||
firstPart = getFQName(constructorClass);
|
return getFQName(constructorClass);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (parent instanceof JetObjectDeclaration) {
|
else if (parent instanceof JetObjectDeclaration) {
|
||||||
if (parent.getParent() instanceof JetClassObject) {
|
if (parent.getParent() instanceof JetClassObject) {
|
||||||
JetClassOrObject classOrObject = PsiTreeUtil.getParentOfType(parent, JetClassOrObject.class);
|
JetClassOrObject classOrObject = PsiTreeUtil.getParentOfType(parent, JetClassOrObject.class);
|
||||||
if (classOrObject != null) {
|
if (classOrObject != null) {
|
||||||
firstPart = getFQName(classOrObject);
|
return getFQName(classOrObject);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
firstPart = getFQName((JetNamedDeclaration) parent);
|
return getFQName((JetNamedDeclaration) parent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return null;
|
||||||
if (firstPart == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return firstPart.child(name);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @return <code>null</code> iff the tye has syntactic errors */
|
/** @return <code>null</code> iff the tye has syntactic errors */
|
||||||
@@ -811,7 +819,7 @@ public class JetPsiUtil {
|
|||||||
|
|
||||||
final List<JetElement> results = Lists.newArrayList();
|
final List<JetElement> results = Lists.newArrayList();
|
||||||
|
|
||||||
((JetElement) root).accept(
|
root.accept(
|
||||||
new JetVisitorVoid() {
|
new JetVisitorVoid() {
|
||||||
@Override
|
@Override
|
||||||
public void visitJetElement(@NotNull JetElement element) {
|
public void visitJetElement(@NotNull JetElement element) {
|
||||||
|
|||||||
+2
-1
@@ -30,6 +30,7 @@ import org.jetbrains.jet.lang.psi.JetPsiUtil;
|
|||||||
import org.jetbrains.jet.lang.psi.psiUtil.PsiUtilPackage;
|
import org.jetbrains.jet.lang.psi.psiUtil.PsiUtilPackage;
|
||||||
import org.jetbrains.jet.lang.psi.stubs.PsiJetClassStub;
|
import org.jetbrains.jet.lang.psi.stubs.PsiJetClassStub;
|
||||||
import org.jetbrains.jet.lang.psi.stubs.impl.PsiJetClassStubImpl;
|
import org.jetbrains.jet.lang.psi.stubs.impl.PsiJetClassStubImpl;
|
||||||
|
import org.jetbrains.jet.lang.resolve.lazy.ResolveSessionUtils;
|
||||||
import org.jetbrains.jet.lang.resolve.name.FqName;
|
import org.jetbrains.jet.lang.resolve.name.FqName;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@@ -57,7 +58,7 @@ public class JetClassElementType extends JetStubElementType<PsiJetClassStub, Jet
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PsiJetClassStub createStub(@NotNull JetClass psi, StubElement parentStub) {
|
public PsiJetClassStub createStub(@NotNull JetClass psi, StubElement parentStub) {
|
||||||
FqName fqName = psi.getFqName();
|
FqName fqName = ResolveSessionUtils.safeFqNameForLazyResolve(psi);
|
||||||
boolean isEnumEntry = psi instanceof JetEnumEntry;
|
boolean isEnumEntry = psi instanceof JetEnumEntry;
|
||||||
List<String> superNames = PsiUtilPackage.getSuperNames(psi);
|
List<String> superNames = PsiUtilPackage.getSuperNames(psi);
|
||||||
return new PsiJetClassStubImpl(
|
return new PsiJetClassStubImpl(
|
||||||
|
|||||||
+4
-8
@@ -29,6 +29,7 @@ import org.jetbrains.jet.lang.psi.JetFile;
|
|||||||
import org.jetbrains.jet.lang.psi.JetNamedFunction;
|
import org.jetbrains.jet.lang.psi.JetNamedFunction;
|
||||||
import org.jetbrains.jet.lang.psi.stubs.PsiJetFunctionStub;
|
import org.jetbrains.jet.lang.psi.stubs.PsiJetFunctionStub;
|
||||||
import org.jetbrains.jet.lang.psi.stubs.impl.PsiJetFunctionStubImpl;
|
import org.jetbrains.jet.lang.psi.stubs.impl.PsiJetFunctionStubImpl;
|
||||||
|
import org.jetbrains.jet.lang.resolve.lazy.ResolveSessionUtils;
|
||||||
import org.jetbrains.jet.lang.resolve.name.FqName;
|
import org.jetbrains.jet.lang.resolve.name.FqName;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@@ -53,10 +54,7 @@ public class JetFunctionElementType extends JetStubElementType<PsiJetFunctionStu
|
|||||||
public boolean shouldCreateStub(ASTNode node) {
|
public boolean shouldCreateStub(ASTNode node) {
|
||||||
if (super.shouldCreateStub(node)) {
|
if (super.shouldCreateStub(node)) {
|
||||||
PsiElement psi = node.getPsi();
|
PsiElement psi = node.getPsi();
|
||||||
if (psi instanceof JetNamedFunction) {
|
return psi instanceof JetNamedFunction;
|
||||||
JetNamedFunction function = (JetNamedFunction) psi;
|
|
||||||
return function.getName() != null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
@@ -66,10 +64,8 @@ public class JetFunctionElementType extends JetStubElementType<PsiJetFunctionStu
|
|||||||
public PsiJetFunctionStub createStub(@NotNull JetNamedFunction psi, @NotNull StubElement parentStub) {
|
public PsiJetFunctionStub createStub(@NotNull JetNamedFunction psi, @NotNull StubElement parentStub) {
|
||||||
boolean isTopLevel = psi.getParent() instanceof JetFile;
|
boolean isTopLevel = psi.getParent() instanceof JetFile;
|
||||||
boolean isExtension = psi.getReceiverTypeRef() != null;
|
boolean isExtension = psi.getReceiverTypeRef() != null;
|
||||||
|
FqName fqName = ResolveSessionUtils.safeFqNameForLazyResolve(psi);
|
||||||
FqName qualifiedName = psi.getFqName();
|
return new PsiJetFunctionStubImpl(parentStub, psi.getName(), isTopLevel, fqName, isExtension);
|
||||||
|
|
||||||
return new PsiJetFunctionStubImpl(parentStub, psi.getName(), isTopLevel, qualifiedName, isExtension);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
+2
-1
@@ -30,6 +30,7 @@ import org.jetbrains.jet.lang.psi.JetPsiUtil;
|
|||||||
import org.jetbrains.jet.lang.psi.psiUtil.PsiUtilPackage;
|
import org.jetbrains.jet.lang.psi.psiUtil.PsiUtilPackage;
|
||||||
import org.jetbrains.jet.lang.psi.stubs.PsiJetObjectStub;
|
import org.jetbrains.jet.lang.psi.stubs.PsiJetObjectStub;
|
||||||
import org.jetbrains.jet.lang.psi.stubs.impl.PsiJetObjectStubImpl;
|
import org.jetbrains.jet.lang.psi.stubs.impl.PsiJetObjectStubImpl;
|
||||||
|
import org.jetbrains.jet.lang.resolve.lazy.ResolveSessionUtils;
|
||||||
import org.jetbrains.jet.lang.resolve.name.FqName;
|
import org.jetbrains.jet.lang.resolve.name.FqName;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@@ -58,7 +59,7 @@ public class JetObjectElementType extends JetStubElementType<PsiJetObjectStub, J
|
|||||||
@Override
|
@Override
|
||||||
public PsiJetObjectStub createStub(@NotNull JetObjectDeclaration psi, StubElement parentStub) {
|
public PsiJetObjectStub createStub(@NotNull JetObjectDeclaration psi, StubElement parentStub) {
|
||||||
String name = psi.getName();
|
String name = psi.getName();
|
||||||
FqName fqName = psi.getFqName();
|
FqName fqName = ResolveSessionUtils.safeFqNameForLazyResolve(psi);
|
||||||
List<String> superNames = PsiUtilPackage.getSuperNames(psi);
|
List<String> superNames = PsiUtilPackage.getSuperNames(psi);
|
||||||
return new PsiJetObjectStubImpl(
|
return new PsiJetObjectStubImpl(
|
||||||
parentStub,
|
parentStub,
|
||||||
|
|||||||
+3
-5
@@ -30,6 +30,7 @@ import org.jetbrains.jet.lang.psi.JetProperty;
|
|||||||
import org.jetbrains.jet.lang.psi.JetTypeReference;
|
import org.jetbrains.jet.lang.psi.JetTypeReference;
|
||||||
import org.jetbrains.jet.lang.psi.stubs.PsiJetPropertyStub;
|
import org.jetbrains.jet.lang.psi.stubs.PsiJetPropertyStub;
|
||||||
import org.jetbrains.jet.lang.psi.stubs.impl.PsiJetPropertyStubImpl;
|
import org.jetbrains.jet.lang.psi.stubs.impl.PsiJetPropertyStubImpl;
|
||||||
|
import org.jetbrains.jet.lang.resolve.lazy.ResolveSessionUtils;
|
||||||
import org.jetbrains.jet.lang.resolve.name.FqName;
|
import org.jetbrains.jet.lang.resolve.name.FqName;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@@ -53,10 +54,7 @@ public class JetPropertyElementType extends JetStubElementType<PsiJetPropertyStu
|
|||||||
public boolean shouldCreateStub(ASTNode node) {
|
public boolean shouldCreateStub(ASTNode node) {
|
||||||
if (super.shouldCreateStub(node)) {
|
if (super.shouldCreateStub(node)) {
|
||||||
PsiElement psi = node.getPsi();
|
PsiElement psi = node.getPsi();
|
||||||
if (psi instanceof JetProperty) {
|
return psi instanceof JetProperty;
|
||||||
JetProperty property = (JetProperty) psi;
|
|
||||||
return property.getName() != null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
@@ -72,7 +70,7 @@ public class JetPropertyElementType extends JetStubElementType<PsiJetPropertyStu
|
|||||||
psi.getText(), psi.getParent() != null ? psi.getParent().getText() : "<no parent>");
|
psi.getText(), psi.getParent() != null ? psi.getParent().getText() : "<no parent>");
|
||||||
|
|
||||||
return new PsiJetPropertyStubImpl(parentStub,
|
return new PsiJetPropertyStubImpl(parentStub,
|
||||||
psi.getName(), psi.isVar(), psi.isTopLevel(), psi.getFqName(),
|
psi.getName(), psi.isVar(), psi.isTopLevel(), ResolveSessionUtils.safeFqNameForLazyResolve(psi),
|
||||||
typeRef != null ? typeRef.getText() : null,
|
typeRef != null ? typeRef.getText() : null,
|
||||||
expression != null ? expression.getText() : null);
|
expression != null ? expression.getText() : null);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,17 +21,18 @@ import com.google.common.base.Predicates;
|
|||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.jet.lang.descriptors.*;
|
import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
|
||||||
import org.jetbrains.jet.lang.psi.JetNamed;
|
import org.jetbrains.jet.lang.descriptors.ClassifierDescriptor;
|
||||||
|
import org.jetbrains.jet.lang.descriptors.PackageViewDescriptor;
|
||||||
|
import org.jetbrains.jet.lang.psi.JetNamedDeclaration;
|
||||||
|
import org.jetbrains.jet.lang.psi.JetPsiUtil;
|
||||||
import org.jetbrains.jet.lang.resolve.name.FqName;
|
import org.jetbrains.jet.lang.resolve.name.FqName;
|
||||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||||
import org.jetbrains.jet.lang.resolve.name.NamePackage;
|
import org.jetbrains.jet.lang.resolve.name.NamePackage;
|
||||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class ResolveSessionUtils {
|
public class ResolveSessionUtils {
|
||||||
|
|
||||||
@@ -141,12 +142,19 @@ public class ResolveSessionUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public static Name safeNameForLazyResolve(@NotNull JetNamed named) {
|
public static Name safeNameForLazyResolve(@NotNull JetNamedDeclaration declaration) {
|
||||||
return safeNameForLazyResolve(named.getNameAsName());
|
return safeNameForLazyResolve(declaration.getNameAsName());
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public static Name safeNameForLazyResolve(@Nullable Name name) {
|
public static Name safeNameForLazyResolve(@Nullable Name name) {
|
||||||
return name != null ? name : NO_NAME_FOR_LAZY_RESOLVE;
|
return name != null ? name : NO_NAME_FOR_LAZY_RESOLVE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public static FqName safeFqNameForLazyResolve(@NotNull JetNamedDeclaration declaration) {
|
||||||
|
//NOTE: should only create special names for package level declarations, so we can safely rely on real fq name for parent
|
||||||
|
FqName parentFqName = JetPsiUtil.getParentFqName(declaration);
|
||||||
|
return parentFqName != null ? parentFqName.child(safeNameForLazyResolve(declaration)) : null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+47
@@ -0,0 +1,47 @@
|
|||||||
|
/*
|
||||||
|
* 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.
|
||||||
|
* 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.resolve.lazy.declarations;
|
||||||
|
|
||||||
|
import kotlin.Function1;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
import org.jetbrains.jet.lang.resolve.name.FqName;
|
||||||
|
import org.jetbrains.jet.storage.LockBasedStorageManager;
|
||||||
|
import org.jetbrains.jet.storage.MemoizedFunctionToNullable;
|
||||||
|
import org.jetbrains.jet.storage.StorageManager;
|
||||||
|
|
||||||
|
public abstract class AbstractDeclarationProviderFactory implements DeclarationProviderFactory {
|
||||||
|
private final MemoizedFunctionToNullable<FqName, PackageMemberDeclarationProvider> packageDeclarationProviders;
|
||||||
|
|
||||||
|
public AbstractDeclarationProviderFactory(@NotNull StorageManager storageManager) {
|
||||||
|
this.packageDeclarationProviders =
|
||||||
|
storageManager.createMemoizedFunctionWithNullableValues(new Function1<FqName, PackageMemberDeclarationProvider>() {
|
||||||
|
@Override
|
||||||
|
public PackageMemberDeclarationProvider invoke(FqName fqName) {
|
||||||
|
return createPackageMemberDeclarationProvider(fqName);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
protected abstract PackageMemberDeclarationProvider createPackageMemberDeclarationProvider(@NotNull FqName name);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PackageMemberDeclarationProvider getPackageMemberDeclarationProvider(@NotNull FqName packageFqName) {
|
||||||
|
return packageDeclarationProviders.invoke(packageFqName);
|
||||||
|
}
|
||||||
|
}
|
||||||
+34
@@ -0,0 +1,34 @@
|
|||||||
|
/*
|
||||||
|
* 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.
|
||||||
|
* 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.resolve.lazy.declarations;
|
||||||
|
|
||||||
|
import com.intellij.openapi.project.Project;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.jet.lang.psi.JetFile;
|
||||||
|
import org.jetbrains.jet.storage.StorageManager;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
|
||||||
|
public final class CliDeclarationProviderFactoryService extends DeclarationProviderFactoryService {
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public DeclarationProviderFactory create(
|
||||||
|
@NotNull Project project, @NotNull StorageManager storageManager, @NotNull Collection<JetFile> files
|
||||||
|
) {
|
||||||
|
return new FileBasedDeclarationProviderFactory(storageManager, files);
|
||||||
|
}
|
||||||
|
}
|
||||||
+6
@@ -17,6 +17,7 @@
|
|||||||
package org.jetbrains.jet.lang.resolve.lazy.declarations;
|
package org.jetbrains.jet.lang.resolve.lazy.declarations;
|
||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.ReadOnly;
|
||||||
import org.jetbrains.jet.lang.psi.JetClassOrObject;
|
import org.jetbrains.jet.lang.psi.JetClassOrObject;
|
||||||
import org.jetbrains.jet.lang.psi.JetDeclaration;
|
import org.jetbrains.jet.lang.psi.JetDeclaration;
|
||||||
import org.jetbrains.jet.lang.psi.JetNamedFunction;
|
import org.jetbrains.jet.lang.psi.JetNamedFunction;
|
||||||
@@ -27,14 +28,19 @@ import java.util.Collection;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public interface DeclarationProvider {
|
public interface DeclarationProvider {
|
||||||
|
@ReadOnly
|
||||||
|
@NotNull
|
||||||
List<JetDeclaration> getAllDeclarations();
|
List<JetDeclaration> getAllDeclarations();
|
||||||
|
|
||||||
|
@ReadOnly
|
||||||
@NotNull
|
@NotNull
|
||||||
Collection<JetNamedFunction> getFunctionDeclarations(@NotNull Name name);
|
Collection<JetNamedFunction> getFunctionDeclarations(@NotNull Name name);
|
||||||
|
|
||||||
|
@ReadOnly
|
||||||
@NotNull
|
@NotNull
|
||||||
Collection<JetProperty> getPropertyDeclarations(@NotNull Name name);
|
Collection<JetProperty> getPropertyDeclarations(@NotNull Name name);
|
||||||
|
|
||||||
|
@ReadOnly
|
||||||
@NotNull
|
@NotNull
|
||||||
Collection<JetClassOrObject> getClassOrObjectDeclarations(@NotNull Name name);
|
Collection<JetClassOrObject> getClassOrObjectDeclarations(@NotNull Name name);
|
||||||
}
|
}
|
||||||
|
|||||||
+43
@@ -0,0 +1,43 @@
|
|||||||
|
/*
|
||||||
|
* 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.
|
||||||
|
* 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.resolve.lazy.declarations;
|
||||||
|
|
||||||
|
import com.intellij.openapi.components.ServiceManager;
|
||||||
|
import com.intellij.openapi.project.Project;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.jet.lang.psi.JetFile;
|
||||||
|
import org.jetbrains.jet.storage.StorageManager;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
|
||||||
|
public abstract class DeclarationProviderFactoryService {
|
||||||
|
@NotNull
|
||||||
|
public abstract DeclarationProviderFactory create(
|
||||||
|
@NotNull Project project,
|
||||||
|
@NotNull StorageManager storageManager,
|
||||||
|
@NotNull Collection<JetFile> files
|
||||||
|
);
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public static DeclarationProviderFactory createDeclarationProviderFactory(
|
||||||
|
@NotNull Project project,
|
||||||
|
@NotNull StorageManager storageManager,
|
||||||
|
@NotNull Collection<JetFile> files
|
||||||
|
) {
|
||||||
|
return ServiceManager.getService(DeclarationProviderFactoryService.class).create(project, storageManager, files);
|
||||||
|
}
|
||||||
|
}
|
||||||
+5
-18
@@ -22,7 +22,6 @@ import com.intellij.psi.NavigatablePsiElement;
|
|||||||
import com.intellij.util.Function;
|
import com.intellij.util.Function;
|
||||||
import com.intellij.util.containers.ContainerUtil;
|
import com.intellij.util.containers.ContainerUtil;
|
||||||
import kotlin.Function0;
|
import kotlin.Function0;
|
||||||
import kotlin.Function1;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.jet.lang.psi.JetFile;
|
import org.jetbrains.jet.lang.psi.JetFile;
|
||||||
@@ -30,16 +29,15 @@ import org.jetbrains.jet.lang.psi.JetPackageDirective;
|
|||||||
import org.jetbrains.jet.lang.psi.JetPsiUtil;
|
import org.jetbrains.jet.lang.psi.JetPsiUtil;
|
||||||
import org.jetbrains.jet.lang.resolve.lazy.data.JetClassLikeInfo;
|
import org.jetbrains.jet.lang.resolve.lazy.data.JetClassLikeInfo;
|
||||||
import org.jetbrains.jet.lang.resolve.name.FqName;
|
import org.jetbrains.jet.lang.resolve.name.FqName;
|
||||||
import org.jetbrains.jet.storage.MemoizedFunctionToNullable;
|
import org.jetbrains.jet.lang.resolve.name.NamePackage;
|
||||||
import org.jetbrains.jet.storage.NotNullLazyValue;
|
import org.jetbrains.jet.storage.NotNullLazyValue;
|
||||||
import org.jetbrains.jet.storage.StorageManager;
|
import org.jetbrains.jet.storage.StorageManager;
|
||||||
import org.jetbrains.jet.lang.resolve.name.NamePackage;
|
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
public class FileBasedDeclarationProviderFactory implements DeclarationProviderFactory {
|
public class FileBasedDeclarationProviderFactory extends AbstractDeclarationProviderFactory {
|
||||||
|
|
||||||
private static class Index {
|
private static class Index {
|
||||||
private final Multimap<FqName, JetFile> filesByPackage = HashMultimap.create();
|
private final Multimap<FqName, JetFile> filesByPackage = HashMultimap.create();
|
||||||
@@ -49,9 +47,8 @@ public class FileBasedDeclarationProviderFactory implements DeclarationProviderF
|
|||||||
private final StorageManager storageManager;
|
private final StorageManager storageManager;
|
||||||
private final NotNullLazyValue<Index> index;
|
private final NotNullLazyValue<Index> index;
|
||||||
|
|
||||||
private final MemoizedFunctionToNullable<FqName, PackageMemberDeclarationProvider> packageDeclarationProviders;
|
|
||||||
|
|
||||||
public FileBasedDeclarationProviderFactory(@NotNull StorageManager storageManager, @NotNull final Collection<JetFile> files) {
|
public FileBasedDeclarationProviderFactory(@NotNull StorageManager storageManager, @NotNull final Collection<JetFile> files) {
|
||||||
|
super(storageManager);
|
||||||
this.storageManager = storageManager;
|
this.storageManager = storageManager;
|
||||||
this.index = storageManager.createLazyValue(new Function0<Index>() {
|
this.index = storageManager.createLazyValue(new Function0<Index>() {
|
||||||
@Override
|
@Override
|
||||||
@@ -59,12 +56,6 @@ public class FileBasedDeclarationProviderFactory implements DeclarationProviderF
|
|||||||
return computeFilesByPackage(files);
|
return computeFilesByPackage(files);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
this.packageDeclarationProviders = storageManager.createMemoizedFunctionWithNullableValues(new Function1<FqName, PackageMemberDeclarationProvider>() {
|
|
||||||
@Override
|
|
||||||
public PackageMemberDeclarationProvider invoke(FqName fqName) {
|
|
||||||
return createPackageMemberDeclarationProvider(fqName);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@@ -124,13 +115,9 @@ public class FileBasedDeclarationProviderFactory implements DeclarationProviderF
|
|||||||
return resultElements;
|
return resultElements;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public PackageMemberDeclarationProvider getPackageMemberDeclarationProvider(@NotNull FqName packageFqName) {
|
|
||||||
return packageDeclarationProviders.invoke(packageFqName);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public PackageMemberDeclarationProvider createPackageMemberDeclarationProvider(@NotNull FqName packageFqName) {
|
@Override
|
||||||
|
protected PackageMemberDeclarationProvider createPackageMemberDeclarationProvider(@NotNull FqName packageFqName) {
|
||||||
if (isPackageDeclaredExplicitly(packageFqName)) {
|
if (isPackageDeclaredExplicitly(packageFqName)) {
|
||||||
return new FileBasedPackageMemberDeclarationProvider(
|
return new FileBasedPackageMemberDeclarationProvider(
|
||||||
storageManager, packageFqName, this, index.invoke().filesByPackage.get(packageFqName));
|
storageManager, packageFqName, this, index.invoke().filesByPackage.get(packageFqName));
|
||||||
|
|||||||
+2
-1
@@ -63,6 +63,7 @@ public class FileBasedPackageMemberDeclarationProvider extends AbstractPsiBasedD
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public Collection<FqName> getAllDeclaredPackages() {
|
public Collection<FqName> getAllDeclaredPackages() {
|
||||||
return allDeclaredPackages.invoke();
|
return allDeclaredPackages.invoke();
|
||||||
@@ -70,7 +71,7 @@ public class FileBasedPackageMemberDeclarationProvider extends AbstractPsiBasedD
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public Collection<NavigatablePsiElement> getPackageDeclarations(FqName fqName) {
|
public Collection<NavigatablePsiElement> getPackageDeclarations(@NotNull FqName fqName) {
|
||||||
return factory.getPackageDeclarations(fqName);
|
return factory.getPackageDeclarations(fqName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+8
-4
@@ -26,12 +26,16 @@ import java.util.Collection;
|
|||||||
|
|
||||||
public interface PackageMemberDeclarationProvider extends DeclarationProvider {
|
public interface PackageMemberDeclarationProvider extends DeclarationProvider {
|
||||||
|
|
||||||
|
//TODO: method name
|
||||||
|
@ReadOnly
|
||||||
|
@NotNull
|
||||||
Collection<FqName> getAllDeclaredPackages();
|
Collection<FqName> getAllDeclaredPackages();
|
||||||
|
|
||||||
@NotNull
|
|
||||||
Collection<NavigatablePsiElement> getPackageDeclarations(FqName fqName);
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
@ReadOnly
|
@ReadOnly
|
||||||
|
@NotNull
|
||||||
|
Collection<NavigatablePsiElement> getPackageDeclarations(@NotNull FqName fqName);
|
||||||
|
|
||||||
|
@ReadOnly
|
||||||
|
@NotNull
|
||||||
Collection<JetFile> getPackageFiles();
|
Collection<JetFile> getPackageFiles();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -108,6 +108,9 @@
|
|||||||
<applicationService serviceInterface="org.jetbrains.jet.lang.resolve.kotlin.KotlinBinaryClassCache"
|
<applicationService serviceInterface="org.jetbrains.jet.lang.resolve.kotlin.KotlinBinaryClassCache"
|
||||||
serviceImplementation="org.jetbrains.jet.lang.resolve.kotlin.KotlinBinaryClassCache"/>
|
serviceImplementation="org.jetbrains.jet.lang.resolve.kotlin.KotlinBinaryClassCache"/>
|
||||||
|
|
||||||
|
<applicationService serviceInterface="org.jetbrains.jet.lang.resolve.lazy.declarations.DeclarationProviderFactoryService"
|
||||||
|
serviceImplementation="org.jetbrains.jet.plugin.stubindex.resolve.PluginDeclarationProviderFactoryService"/>
|
||||||
|
|
||||||
<projectService serviceInterface="org.jetbrains.jet.lang.resolve.java.JetFilesProvider"
|
<projectService serviceInterface="org.jetbrains.jet.lang.resolve.java.JetFilesProvider"
|
||||||
serviceImplementation="org.jetbrains.jet.plugin.project.PluginJetFilesProvider"/>
|
serviceImplementation="org.jetbrains.jet.plugin.project.PluginJetFilesProvider"/>
|
||||||
|
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ public class JetAllPackagesIndex extends StringStubIndexExtension<JetFile> {
|
|||||||
|
|
||||||
private static final JetAllPackagesIndex ourInstance = new JetAllPackagesIndex();
|
private static final JetAllPackagesIndex ourInstance = new JetAllPackagesIndex();
|
||||||
|
|
||||||
|
@NotNull
|
||||||
public static JetAllPackagesIndex getInstance() {
|
public static JetAllPackagesIndex getInstance() {
|
||||||
return ourInstance;
|
return ourInstance;
|
||||||
}
|
}
|
||||||
@@ -48,6 +49,7 @@ public class JetAllPackagesIndex extends StringStubIndexExtension<JetFile> {
|
|||||||
return KEY;
|
return KEY;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public Collection<JetFile> get(String fqName, Project project, @NotNull GlobalSearchScope scope) {
|
public Collection<JetFile> get(String fqName, Project project, @NotNull GlobalSearchScope scope) {
|
||||||
return super.get(fqName, project, JetSourceFilterScope.kotlinSourcesAndLibraries(scope));
|
return super.get(fqName, project, JetSourceFilterScope.kotlinSourcesAndLibraries(scope));
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ public class JetFullClassNameIndex extends StringStubIndexExtension<JetClassOrOb
|
|||||||
|
|
||||||
private static final JetFullClassNameIndex ourInstance = new JetFullClassNameIndex();
|
private static final JetFullClassNameIndex ourInstance = new JetFullClassNameIndex();
|
||||||
|
|
||||||
|
@NotNull
|
||||||
public static JetFullClassNameIndex getInstance() {
|
public static JetFullClassNameIndex getInstance() {
|
||||||
return ourInstance;
|
return ourInstance;
|
||||||
}
|
}
|
||||||
@@ -42,6 +43,7 @@ public class JetFullClassNameIndex extends StringStubIndexExtension<JetClassOrOb
|
|||||||
return KEY;
|
return KEY;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public Collection<JetClassOrObject> get(String fqName, Project project, @NotNull GlobalSearchScope scope) {
|
public Collection<JetClassOrObject> get(String fqName, Project project, @NotNull GlobalSearchScope scope) {
|
||||||
return super.get(fqName, project, JetSourceFilterScope.kotlinSourcesAndLibraries(scope));
|
return super.get(fqName, project, JetSourceFilterScope.kotlinSourcesAndLibraries(scope));
|
||||||
|
|||||||
@@ -27,11 +27,13 @@ import org.jetbrains.jet.plugin.JetFileType;
|
|||||||
import org.jetbrains.jet.plugin.JetPluginUtil;
|
import org.jetbrains.jet.plugin.JetPluginUtil;
|
||||||
|
|
||||||
public class JetSourceFilterScope extends DelegatingGlobalSearchScope {
|
public class JetSourceFilterScope extends DelegatingGlobalSearchScope {
|
||||||
public static JetSourceFilterScope kotlinSourcesAndLibraries(@NotNull GlobalSearchScope delegate) {
|
@NotNull
|
||||||
|
public static GlobalSearchScope kotlinSourcesAndLibraries(@NotNull GlobalSearchScope delegate) {
|
||||||
return new JetSourceFilterScope(delegate, true);
|
return new JetSourceFilterScope(delegate, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static JetSourceFilterScope kotlinSources(@NotNull GlobalSearchScope delegate) {
|
@NotNull
|
||||||
|
public static GlobalSearchScope kotlinSources(@NotNull GlobalSearchScope delegate) {
|
||||||
return new JetSourceFilterScope(delegate, false);
|
return new JetSourceFilterScope(delegate, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ public class JetTopLevelFunctionsFqnNameIndex extends StringStubIndexExtension<J
|
|||||||
|
|
||||||
private static final JetTopLevelFunctionsFqnNameIndex INSTANCE = new JetTopLevelFunctionsFqnNameIndex();
|
private static final JetTopLevelFunctionsFqnNameIndex INSTANCE = new JetTopLevelFunctionsFqnNameIndex();
|
||||||
|
|
||||||
|
@NotNull
|
||||||
public static JetTopLevelFunctionsFqnNameIndex getInstance() {
|
public static JetTopLevelFunctionsFqnNameIndex getInstance() {
|
||||||
return INSTANCE;
|
return INSTANCE;
|
||||||
}
|
}
|
||||||
@@ -45,6 +46,7 @@ public class JetTopLevelFunctionsFqnNameIndex extends StringStubIndexExtension<J
|
|||||||
return KEY;
|
return KEY;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public Collection<JetNamedFunction> get(String s, Project project, @NotNull GlobalSearchScope scope) {
|
public Collection<JetNamedFunction> get(String s, Project project, @NotNull GlobalSearchScope scope) {
|
||||||
return super.get(s, project, JetSourceFilterScope.kotlinSourcesAndLibraries(scope));
|
return super.get(s, project, JetSourceFilterScope.kotlinSourcesAndLibraries(scope));
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ public class JetTopLevelPropertiesFqnNameIndex extends StringStubIndexExtension<
|
|||||||
|
|
||||||
private static final JetTopLevelPropertiesFqnNameIndex INSTANCE = new JetTopLevelPropertiesFqnNameIndex();
|
private static final JetTopLevelPropertiesFqnNameIndex INSTANCE = new JetTopLevelPropertiesFqnNameIndex();
|
||||||
|
|
||||||
|
@NotNull
|
||||||
public static JetTopLevelPropertiesFqnNameIndex getInstance() {
|
public static JetTopLevelPropertiesFqnNameIndex getInstance() {
|
||||||
return INSTANCE;
|
return INSTANCE;
|
||||||
}
|
}
|
||||||
@@ -42,6 +43,7 @@ public class JetTopLevelPropertiesFqnNameIndex extends StringStubIndexExtension<
|
|||||||
return KEY;
|
return KEY;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public Collection<JetProperty> get(String s, Project project, @NotNull GlobalSearchScope scope) {
|
public Collection<JetProperty> get(String s, Project project, @NotNull GlobalSearchScope scope) {
|
||||||
return super.get(s, project, JetSourceFilterScope.kotlinSourcesAndLibraries(scope));
|
return super.get(s, project, JetSourceFilterScope.kotlinSourcesAndLibraries(scope));
|
||||||
|
|||||||
@@ -120,30 +120,29 @@ public class StubIndexServiceImpl implements StubIndexService {
|
|||||||
else {
|
else {
|
||||||
sink.occurrence(JetTopLevelExtensionFunctionShortNameIndex.getInstance().getKey(), name);
|
sink.occurrence(JetTopLevelExtensionFunctionShortNameIndex.getInstance().getKey(), name);
|
||||||
}
|
}
|
||||||
|
|
||||||
FqName topFQName = stub.getFqName();
|
|
||||||
if (topFQName != null) {
|
|
||||||
sink.occurrence(JetTopLevelFunctionsFqnNameIndex.getInstance().getKey(), topFQName.asString());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sink.occurrence(JetFunctionShortNameIndex.getInstance().getKey(), name);
|
sink.occurrence(JetFunctionShortNameIndex.getInstance().getKey(), name);
|
||||||
}
|
}
|
||||||
|
// can have special fq name in case of syntactically incorrect function with no name
|
||||||
|
FqName topFQName = stub.getFqName();
|
||||||
|
if (topFQName != null) {
|
||||||
|
sink.occurrence(JetTopLevelFunctionsFqnNameIndex.getInstance().getKey(), topFQName.asString());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void indexProperty(PsiJetPropertyStub stub, IndexSink sink) {
|
public void indexProperty(PsiJetPropertyStub stub, IndexSink sink) {
|
||||||
String propertyName = stub.getName();
|
String propertyName = stub.getName();
|
||||||
if (propertyName != null) {
|
if (propertyName != null) {
|
||||||
if (stub.isTopLevel()) {
|
|
||||||
FqName topFQName = stub.getFqName();
|
|
||||||
if (topFQName != null) {
|
|
||||||
sink.occurrence(JetTopLevelPropertiesFqnNameIndex.getInstance().getKey(), topFQName.asString());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
sink.occurrence(JetPropertyShortNameIndex.getInstance().getKey(), propertyName);
|
sink.occurrence(JetPropertyShortNameIndex.getInstance().getKey(), propertyName);
|
||||||
}
|
}
|
||||||
|
// can have special fq name in case of syntactically incorrect function with no name
|
||||||
|
if (stub.isTopLevel()) {
|
||||||
|
FqName topFQName = stub.getFqName();
|
||||||
|
if (topFQName != null) {
|
||||||
|
sink.occurrence(JetTopLevelPropertiesFqnNameIndex.getInstance().getKey(), topFQName.asString());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
-42
@@ -1,42 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.plugin.stubindex.resolve;
|
|
||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
import org.jetbrains.jet.lang.psi.JetClassOrObject;
|
|
||||||
import org.jetbrains.jet.lang.psi.JetDeclaration;
|
|
||||||
import org.jetbrains.jet.lang.resolve.lazy.declarations.DeclarationProvider;
|
|
||||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
|
||||||
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public abstract class AbstractStubDeclarationProvider implements DeclarationProvider {
|
|
||||||
@Override
|
|
||||||
public List<JetDeclaration> getAllDeclarations() {
|
|
||||||
// TODO:
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
@Override
|
|
||||||
public Collection<JetClassOrObject> getClassOrObjectDeclarations(@NotNull Name name) {
|
|
||||||
// TODO:
|
|
||||||
return Collections.emptyList();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+40
@@ -0,0 +1,40 @@
|
|||||||
|
/*
|
||||||
|
* 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.
|
||||||
|
* 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.plugin.stubindex.resolve
|
||||||
|
|
||||||
|
import com.intellij.psi.NavigatablePsiElement
|
||||||
|
import org.jetbrains.jet.lang.psi.*
|
||||||
|
import org.jetbrains.jet.lang.resolve.lazy.declarations.FileBasedPackageMemberDeclarationProvider
|
||||||
|
import org.jetbrains.jet.lang.resolve.lazy.declarations.PackageMemberDeclarationProvider
|
||||||
|
import org.jetbrains.jet.lang.resolve.name.FqName
|
||||||
|
import org.jetbrains.jet.lang.resolve.name.Name
|
||||||
|
|
||||||
|
public class CombinedPackageMemberDeclarationProvider(val providers: Collection<PackageMemberDeclarationProvider>) : PackageMemberDeclarationProvider {
|
||||||
|
override fun getAllDeclaredPackages() = providers.flatMap { it.getAllDeclaredPackages() }
|
||||||
|
|
||||||
|
override fun getPackageDeclarations(fqName: FqName) = providers.flatMap { it.getPackageDeclarations(fqName) }
|
||||||
|
|
||||||
|
override fun getPackageFiles() = providers.flatMap { it.getPackageFiles() }
|
||||||
|
|
||||||
|
override fun getAllDeclarations() = providers.flatMap { it.getAllDeclarations() }
|
||||||
|
|
||||||
|
override fun getFunctionDeclarations(name: Name) = providers.flatMap { it.getFunctionDeclarations(name) }
|
||||||
|
|
||||||
|
override fun getPropertyDeclarations(name: Name) = providers.flatMap { it.getPropertyDeclarations(name) }
|
||||||
|
|
||||||
|
override fun getClassOrObjectDeclarations(name: Name) = providers.flatMap { it.getClassOrObjectDeclarations(name) }
|
||||||
|
}
|
||||||
+61
@@ -0,0 +1,61 @@
|
|||||||
|
/*
|
||||||
|
* 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.
|
||||||
|
* 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.plugin.stubindex.resolve
|
||||||
|
|
||||||
|
import com.intellij.openapi.project.Project
|
||||||
|
import com.intellij.psi.search.GlobalSearchScope
|
||||||
|
import org.jetbrains.annotations.Nullable
|
||||||
|
import org.jetbrains.jet.lang.psi.JetFile
|
||||||
|
import org.jetbrains.jet.lang.resolve.lazy.data.JetClassLikeInfo
|
||||||
|
import org.jetbrains.jet.lang.resolve.lazy.declarations.*
|
||||||
|
import org.jetbrains.jet.lang.resolve.name.FqName
|
||||||
|
import org.jetbrains.jet.plugin.stubindex.JetAllPackagesIndex
|
||||||
|
import org.jetbrains.jet.storage.StorageManager
|
||||||
|
import java.util.Arrays
|
||||||
|
|
||||||
|
public class PluginDeclarationProviderFactory(
|
||||||
|
private val project: Project,
|
||||||
|
private val indexedFilesScope: GlobalSearchScope,
|
||||||
|
private val storageManager: StorageManager,
|
||||||
|
private val nonIndexedFiles: Collection<JetFile>
|
||||||
|
) : AbstractDeclarationProviderFactory(storageManager) {
|
||||||
|
private val fileBasedDeclarationProviderFactory = FileBasedDeclarationProviderFactory(storageManager, nonIndexedFiles)
|
||||||
|
|
||||||
|
override fun getClassMemberDeclarationProvider(classLikeInfo: JetClassLikeInfo): ClassMemberDeclarationProvider {
|
||||||
|
return PsiBasedClassMemberDeclarationProvider(storageManager, classLikeInfo)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun createPackageMemberDeclarationProvider(name: FqName): PackageMemberDeclarationProvider? {
|
||||||
|
val fileBasedProvider = fileBasedDeclarationProviderFactory.getPackageMemberDeclarationProvider(name)
|
||||||
|
val stubBasedProvider = getStubBasedPackageMemberDeclarationProvider(name)
|
||||||
|
return when {
|
||||||
|
fileBasedProvider == null && stubBasedProvider == null -> null
|
||||||
|
fileBasedProvider == null -> stubBasedProvider
|
||||||
|
stubBasedProvider == null -> fileBasedProvider
|
||||||
|
else -> CombinedPackageMemberDeclarationProvider(listOf(stubBasedProvider, fileBasedProvider))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun getStubBasedPackageMemberDeclarationProvider(name: FqName): PackageMemberDeclarationProvider? {
|
||||||
|
//TODO: better check
|
||||||
|
val files = JetAllPackagesIndex.getInstance().get(name.asString(), project, indexedFilesScope)
|
||||||
|
if (files.isEmpty()) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
return StubBasedPackageMemberDeclarationProvider(name, project, indexedFilesScope)
|
||||||
|
}
|
||||||
|
}
|
||||||
+44
@@ -0,0 +1,44 @@
|
|||||||
|
/*
|
||||||
|
* 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.
|
||||||
|
* 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.plugin.stubindex.resolve
|
||||||
|
|
||||||
|
import com.intellij.openapi.project.Project
|
||||||
|
import com.intellij.openapi.util.Condition
|
||||||
|
import com.intellij.openapi.vfs.VirtualFile
|
||||||
|
import com.intellij.psi.search.GlobalSearchScope
|
||||||
|
import com.intellij.util.Function
|
||||||
|
import com.intellij.util.containers.ContainerUtil
|
||||||
|
import org.jetbrains.jet.lang.psi.JetFile
|
||||||
|
import org.jetbrains.jet.lang.resolve.lazy.declarations.DeclarationProviderFactory
|
||||||
|
import org.jetbrains.jet.lang.resolve.lazy.declarations.DeclarationProviderFactoryService
|
||||||
|
import org.jetbrains.jet.plugin.stubindex.JetSourceFilterScope
|
||||||
|
import org.jetbrains.jet.storage.StorageManager
|
||||||
|
|
||||||
|
public class PluginDeclarationProviderFactoryService : DeclarationProviderFactoryService() {
|
||||||
|
|
||||||
|
override fun create(project: Project, storageManager: StorageManager, files: Collection<JetFile>): DeclarationProviderFactory {
|
||||||
|
val indexedSourcesScope = JetSourceFilterScope.kotlinSourcesAndLibraries(GlobalSearchScope.allScope(project))
|
||||||
|
val nonIndexedFiles = files.filter {
|
||||||
|
file ->
|
||||||
|
!file.isPhysical() || !indexedSourcesScope.contains(file.getVirtualFile()!!)
|
||||||
|
}
|
||||||
|
val physicalFilesScope = GlobalSearchScope.filesScope(project, files.filter { it.isPhysical() }.map { it.getVirtualFile()!! })
|
||||||
|
val indexedFilesScope = indexedSourcesScope.intersectWith(physicalFilesScope)
|
||||||
|
|
||||||
|
return PluginDeclarationProviderFactory(project, indexedFilesScope, storageManager, nonIndexedFiles)
|
||||||
|
}
|
||||||
|
}
|
||||||
+99
@@ -0,0 +1,99 @@
|
|||||||
|
/*
|
||||||
|
* 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.
|
||||||
|
* 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.plugin.stubindex.resolve
|
||||||
|
|
||||||
|
import com.intellij.openapi.project.Project
|
||||||
|
import com.intellij.psi.NavigatablePsiElement
|
||||||
|
import com.intellij.psi.search.GlobalSearchScope
|
||||||
|
import com.intellij.psi.stubs.StringStubIndexExtension
|
||||||
|
import org.jetbrains.jet.lang.psi.*
|
||||||
|
import org.jetbrains.jet.lang.resolve.lazy.declarations.PackageMemberDeclarationProvider
|
||||||
|
import org.jetbrains.jet.lang.resolve.name.FqName
|
||||||
|
import org.jetbrains.jet.lang.resolve.name.Name
|
||||||
|
import org.jetbrains.jet.plugin.stubindex.JetAllPackagesIndex
|
||||||
|
import org.jetbrains.jet.plugin.stubindex.JetFullClassNameIndex
|
||||||
|
import org.jetbrains.jet.plugin.stubindex.JetTopLevelFunctionsFqnNameIndex
|
||||||
|
import org.jetbrains.jet.plugin.stubindex.JetTopLevelPropertiesFqnNameIndex
|
||||||
|
import java.util.*
|
||||||
|
import org.jetbrains.jet.plugin.stubindex.JetSourceFilterScope.kotlinSources
|
||||||
|
import org.jetbrains.jet.lang.resolve.name.numberOfSegments
|
||||||
|
|
||||||
|
public class StubBasedPackageMemberDeclarationProvider(
|
||||||
|
private val fqName: FqName,
|
||||||
|
private val project: Project,
|
||||||
|
private val searchScope: GlobalSearchScope
|
||||||
|
) : PackageMemberDeclarationProvider {
|
||||||
|
|
||||||
|
override fun getAllDeclarations(): List<JetDeclaration> {
|
||||||
|
return TOP_LEVEL_DECLARATION_INDICES.flatMap {
|
||||||
|
index ->
|
||||||
|
val fqNames = index.getAllKeys(project).toSet().map { FqName(it) }.filter { !it.isRoot() && it.parent() == fqName }
|
||||||
|
fqNames.flatMap { index.get(it.asString(), project, searchScope) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getClassOrObjectDeclarations(name: Name): Collection<JetClassOrObject> {
|
||||||
|
return JetFullClassNameIndex.getInstance().get(childName(name), project, searchScope)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getFunctionDeclarations(name: Name): Collection<JetNamedFunction> {
|
||||||
|
return JetTopLevelFunctionsFqnNameIndex.getInstance().get(childName(name), project, searchScope)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getPropertyDeclarations(name: Name): Collection<JetProperty> {
|
||||||
|
return JetTopLevelPropertiesFqnNameIndex.getInstance().get(childName(name), project, searchScope)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getAllDeclaredPackages(): Collection<FqName> {
|
||||||
|
//TODO: duplication with light class generation support
|
||||||
|
val allPackagesInProject = JetAllPackagesIndex.getInstance().getAllKeys(project)
|
||||||
|
return allPackagesInProject.filter {
|
||||||
|
val otherPackageFqName = FqName(it)
|
||||||
|
!otherPackageFqName.isRoot() && otherPackageFqName.parent() == fqName
|
||||||
|
}.map { FqName(it) }
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getPackageDeclarations(fqName: FqName): Collection<NavigatablePsiElement> {
|
||||||
|
if (fqName.isRoot()) {
|
||||||
|
return Collections.emptyList()
|
||||||
|
}
|
||||||
|
|
||||||
|
val files = JetAllPackagesIndex.getInstance().get(fqName.asString(), project, searchScope)
|
||||||
|
return files.map {
|
||||||
|
file ->
|
||||||
|
JetPsiUtil.getPackageReference(file, fqName.numberOfSegments() - 1)
|
||||||
|
}.filterNotNull()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getPackageFiles(): Collection<JetFile> {
|
||||||
|
//TODO: duplicate with light class generation support
|
||||||
|
val files = JetAllPackagesIndex.getInstance().get(fqName.asString(), project, kotlinSources(searchScope))
|
||||||
|
return files.filter {
|
||||||
|
fqName.equals(JetPsiUtil.getFQName(it))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun childName(name: Name): String {
|
||||||
|
return fqName.child(name).asString()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private val TOP_LEVEL_DECLARATION_INDICES: List<StringStubIndexExtension<out JetNamedDeclaration>> = listOf(
|
||||||
|
JetFullClassNameIndex.getInstance(),
|
||||||
|
JetTopLevelFunctionsFqnNameIndex.getInstance(),
|
||||||
|
JetTopLevelPropertiesFqnNameIndex.getInstance()
|
||||||
|
)
|
||||||
-52
@@ -1,52 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.plugin.stubindex.resolve;
|
|
||||||
|
|
||||||
import com.intellij.openapi.project.Project;
|
|
||||||
import com.intellij.psi.search.GlobalSearchScope;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
import org.jetbrains.jet.lang.resolve.lazy.data.JetClassLikeInfo;
|
|
||||||
import org.jetbrains.jet.lang.resolve.lazy.declarations.ClassMemberDeclarationProvider;
|
|
||||||
import org.jetbrains.jet.lang.resolve.lazy.declarations.DeclarationProviderFactory;
|
|
||||||
import org.jetbrains.jet.lang.resolve.lazy.declarations.PackageMemberDeclarationProvider;
|
|
||||||
import org.jetbrains.jet.lang.resolve.lazy.declarations.PsiBasedClassMemberDeclarationProvider;
|
|
||||||
import org.jetbrains.jet.storage.StorageManager;
|
|
||||||
import org.jetbrains.jet.lang.resolve.name.FqName;
|
|
||||||
|
|
||||||
public class StubDeclarationProviderFactory implements DeclarationProviderFactory {
|
|
||||||
|
|
||||||
private final Project project;
|
|
||||||
private final GlobalSearchScope searchScope;
|
|
||||||
private final StorageManager storageManager;
|
|
||||||
|
|
||||||
public StubDeclarationProviderFactory(@NotNull Project project, @NotNull GlobalSearchScope scope, @NotNull StorageManager manager) {
|
|
||||||
this.project = project;
|
|
||||||
searchScope = scope;
|
|
||||||
storageManager = manager;
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
@Override
|
|
||||||
public ClassMemberDeclarationProvider getClassMemberDeclarationProvider(@NotNull JetClassLikeInfo classLikeInfo) {
|
|
||||||
return new PsiBasedClassMemberDeclarationProvider(storageManager, classLikeInfo);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public PackageMemberDeclarationProvider getPackageMemberDeclarationProvider(@NotNull FqName packageFqName) {
|
|
||||||
return new StubPackageMemberDeclarationProvider(packageFqName, project, searchScope);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-99
@@ -1,99 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.
|
|
||||||
* 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.plugin.stubindex.resolve;
|
|
||||||
|
|
||||||
import com.intellij.openapi.project.Project;
|
|
||||||
import com.intellij.psi.NavigatablePsiElement;
|
|
||||||
import com.intellij.psi.search.GlobalSearchScope;
|
|
||||||
import com.intellij.util.Function;
|
|
||||||
import com.intellij.util.containers.ContainerUtil;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
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.psi.JetPsiUtil;
|
|
||||||
import org.jetbrains.jet.lang.resolve.lazy.declarations.PackageMemberDeclarationProvider;
|
|
||||||
import org.jetbrains.jet.lang.resolve.name.FqName;
|
|
||||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
|
||||||
import org.jetbrains.jet.plugin.stubindex.JetAllPackagesIndex;
|
|
||||||
import org.jetbrains.jet.plugin.stubindex.JetTopLevelFunctionsFqnNameIndex;
|
|
||||||
import org.jetbrains.jet.plugin.stubindex.JetTopLevelPropertiesFqnNameIndex;
|
|
||||||
import org.jetbrains.jet.lang.resolve.name.NamePackage;
|
|
||||||
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.Collections;
|
|
||||||
|
|
||||||
public class StubPackageMemberDeclarationProvider extends AbstractStubDeclarationProvider implements PackageMemberDeclarationProvider {
|
|
||||||
private final FqName fqName;
|
|
||||||
private final Project project;
|
|
||||||
private final GlobalSearchScope searchScope;
|
|
||||||
|
|
||||||
public StubPackageMemberDeclarationProvider(@NotNull FqName fqName, @NotNull Project project, @NotNull GlobalSearchScope searchScope) {
|
|
||||||
this.fqName = fqName;
|
|
||||||
this.project = project;
|
|
||||||
this.searchScope = searchScope;
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
@Override
|
|
||||||
public Collection<JetNamedFunction> getFunctionDeclarations(@NotNull Name name) {
|
|
||||||
return JetTopLevelFunctionsFqnNameIndex.getInstance().get(fqName.child(name).toString(), project, searchScope);
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
@Override
|
|
||||||
public Collection<JetProperty> getPropertyDeclarations(@NotNull Name name) {
|
|
||||||
return JetTopLevelPropertiesFqnNameIndex.getInstance().get(fqName.child(name).toString(), project, searchScope);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Collection<FqName> getAllDeclaredPackages() {
|
|
||||||
// get all packages in this project
|
|
||||||
Collection<String> allPackagesInProject = JetAllPackagesIndex.getInstance().getAllKeys(project);
|
|
||||||
return ContainerUtil.mapNotNull(allPackagesInProject, new Function<String, FqName>() {
|
|
||||||
@Override
|
|
||||||
public FqName fun(String packageFqName) {
|
|
||||||
// filter by the search scope
|
|
||||||
Collection<JetFile> files = JetAllPackagesIndex.getInstance().get(packageFqName, project, searchScope);
|
|
||||||
if (files.isEmpty()) return null;
|
|
||||||
return new FqName(packageFqName);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
@Override
|
|
||||||
public Collection<NavigatablePsiElement> getPackageDeclarations(final FqName fqName) {
|
|
||||||
if (fqName.isRoot()) {
|
|
||||||
return Collections.emptyList();
|
|
||||||
}
|
|
||||||
|
|
||||||
Collection<JetFile> files = JetAllPackagesIndex.getInstance().get(fqName.asString(), project, searchScope);
|
|
||||||
return ContainerUtil.map(files, new Function<JetFile, NavigatablePsiElement>() {
|
|
||||||
@Override
|
|
||||||
public NavigatablePsiElement fun(JetFile file) {
|
|
||||||
return JetPsiUtil.getPackageReference(file, NamePackage.numberOfSegments(fqName) - 1);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
@Override
|
|
||||||
public Collection<JetFile> getPackageFiles() {
|
|
||||||
return JetAllPackagesIndex.getInstance().get(fqName.asString(), project, searchScope);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -27,7 +27,7 @@ import org.jetbrains.jet.lang.psi.JetProperty;
|
|||||||
import org.jetbrains.jet.lang.resolve.name.FqName;
|
import org.jetbrains.jet.lang.resolve.name.FqName;
|
||||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||||
import org.jetbrains.jet.plugin.JetFileType;
|
import org.jetbrains.jet.plugin.JetFileType;
|
||||||
import org.jetbrains.jet.plugin.stubindex.resolve.StubPackageMemberDeclarationProvider;
|
import org.jetbrains.jet.plugin.stubindex.resolve.StubBasedPackageMemberDeclarationProvider;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -37,8 +37,8 @@ public class JetStubResolveTest extends LightCodeInsightFixtureTestCase {
|
|||||||
myFixture.configureByText(JetFileType.INSTANCE,
|
myFixture.configureByText(JetFileType.INSTANCE,
|
||||||
"package test.testing\n" +
|
"package test.testing\n" +
|
||||||
"fun some() {}");
|
"fun some() {}");
|
||||||
StubPackageMemberDeclarationProvider provider =
|
StubBasedPackageMemberDeclarationProvider provider =
|
||||||
new StubPackageMemberDeclarationProvider(new FqName("test.testing"), getProject(), GlobalSearchScope.projectScope(getProject()));
|
new StubBasedPackageMemberDeclarationProvider(new FqName("test.testing"), getProject(), GlobalSearchScope.projectScope(getProject()));
|
||||||
|
|
||||||
List<JetNamedFunction> some = Lists.newArrayList(provider.getFunctionDeclarations(Name.identifier("some")));
|
List<JetNamedFunction> some = Lists.newArrayList(provider.getFunctionDeclarations(Name.identifier("some")));
|
||||||
|
|
||||||
@@ -52,8 +52,8 @@ public class JetStubResolveTest extends LightCodeInsightFixtureTestCase {
|
|||||||
"fun other(v : Int) = 12\n" +
|
"fun other(v : Int) = 12\n" +
|
||||||
"fun other(v : String) {}");
|
"fun other(v : String) {}");
|
||||||
|
|
||||||
StubPackageMemberDeclarationProvider provider =
|
StubBasedPackageMemberDeclarationProvider provider =
|
||||||
new StubPackageMemberDeclarationProvider(new FqName("test.testing"), getProject(), GlobalSearchScope.projectScope(getProject()));
|
new StubBasedPackageMemberDeclarationProvider(new FqName("test.testing"), getProject(), GlobalSearchScope.projectScope(getProject()));
|
||||||
|
|
||||||
List<JetNamedFunction> other = Lists.newArrayList(provider.getFunctionDeclarations(Name.identifier("other")));
|
List<JetNamedFunction> other = Lists.newArrayList(provider.getFunctionDeclarations(Name.identifier("other")));
|
||||||
Collection<String> functionTexts = Collections2.transform(other, new Function<JetNamedFunction, String>() {
|
Collection<String> functionTexts = Collections2.transform(other, new Function<JetNamedFunction, String>() {
|
||||||
@@ -73,8 +73,8 @@ public class JetStubResolveTest extends LightCodeInsightFixtureTestCase {
|
|||||||
"package test.testing\n" +
|
"package test.testing\n" +
|
||||||
"val test = 12\n");
|
"val test = 12\n");
|
||||||
|
|
||||||
StubPackageMemberDeclarationProvider provider =
|
StubBasedPackageMemberDeclarationProvider provider =
|
||||||
new StubPackageMemberDeclarationProvider(new FqName("test.testing"), getProject(), GlobalSearchScope.projectScope(getProject()));
|
new StubBasedPackageMemberDeclarationProvider(new FqName("test.testing"), getProject(), GlobalSearchScope.projectScope(getProject()));
|
||||||
|
|
||||||
List<JetProperty> testProperties = Lists.newArrayList(provider.getPropertyDeclarations(Name.identifier("test")));
|
List<JetProperty> testProperties = Lists.newArrayList(provider.getPropertyDeclarations(Name.identifier("test")));
|
||||||
|
|
||||||
@@ -85,7 +85,7 @@ public class JetStubResolveTest extends LightCodeInsightFixtureTestCase {
|
|||||||
public void testGetPackageByIntermediatePartition() {
|
public void testGetPackageByIntermediatePartition() {
|
||||||
myFixture.configureByText(JetFileType.INSTANCE, "package first.second.third");
|
myFixture.configureByText(JetFileType.INSTANCE, "package first.second.third");
|
||||||
|
|
||||||
StubPackageMemberDeclarationProvider provider = new StubPackageMemberDeclarationProvider(
|
StubBasedPackageMemberDeclarationProvider provider = new StubBasedPackageMemberDeclarationProvider(
|
||||||
new FqName("first.second"), getProject(), GlobalSearchScope.projectScope(getProject()));
|
new FqName("first.second"), getProject(), GlobalSearchScope.projectScope(getProject()));
|
||||||
|
|
||||||
Collection<NavigatablePsiElement> packageDeclarations = provider.getPackageDeclarations(new FqName("first.second"));
|
Collection<NavigatablePsiElement> packageDeclarations = provider.getPackageDeclarations(new FqName("first.second"));
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ import org.jetbrains.jet.lang.descriptors.ModuleDescriptorImpl;
|
|||||||
import org.jetbrains.jet.lang.psi.JetFile;
|
import org.jetbrains.jet.lang.psi.JetFile;
|
||||||
import org.jetbrains.jet.lang.resolve.*;
|
import org.jetbrains.jet.lang.resolve.*;
|
||||||
import org.jetbrains.jet.lang.resolve.lazy.ResolveSession;
|
import org.jetbrains.jet.lang.resolve.lazy.ResolveSession;
|
||||||
import org.jetbrains.jet.lang.resolve.lazy.declarations.FileBasedDeclarationProviderFactory;
|
import org.jetbrains.jet.lang.resolve.lazy.declarations.DeclarationProviderFactory;
|
||||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||||
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
|
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
|
||||||
import org.jetbrains.k2js.config.Config;
|
import org.jetbrains.k2js.config.Config;
|
||||||
@@ -45,6 +45,8 @@ import java.util.Collection;
|
|||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import static org.jetbrains.jet.lang.resolve.lazy.declarations.DeclarationProviderFactoryService.createDeclarationProviderFactory;
|
||||||
|
|
||||||
public final class AnalyzerFacadeForJS {
|
public final class AnalyzerFacadeForJS {
|
||||||
public static final List<ImportPath> DEFAULT_IMPORTS = ImmutableList.of(
|
public static final List<ImportPath> DEFAULT_IMPORTS = ImmutableList.of(
|
||||||
new ImportPath("js.*"),
|
new ImportPath("js.*"),
|
||||||
@@ -155,8 +157,9 @@ public final class AnalyzerFacadeForJS {
|
|||||||
@NotNull
|
@NotNull
|
||||||
public static ResolveSession getLazyResolveSession(Collection<JetFile> files, Config config) {
|
public static ResolveSession getLazyResolveSession(Collection<JetFile> files, Config config) {
|
||||||
GlobalContextImpl globalContext = ContextPackage.GlobalContext();
|
GlobalContextImpl globalContext = ContextPackage.GlobalContext();
|
||||||
FileBasedDeclarationProviderFactory declarationProviderFactory = new FileBasedDeclarationProviderFactory(
|
DeclarationProviderFactory declarationProviderFactory =
|
||||||
globalContext.getStorageManager(), Config.withJsLibAdded(files, config));
|
createDeclarationProviderFactory(config.getProject(), globalContext.getStorageManager(),
|
||||||
|
Config.withJsLibAdded(files, config));
|
||||||
ModuleDescriptorImpl module = createJsModule("<lazy module>");
|
ModuleDescriptorImpl module = createJsModule("<lazy module>");
|
||||||
module.addFragmentProvider(DependencyKind.BUILT_INS, KotlinBuiltIns.getInstance().getBuiltInsModule().getPackageFragmentProvider());
|
module.addFragmentProvider(DependencyKind.BUILT_INS, KotlinBuiltIns.getInstance().getBuiltInsModule().getPackageFragmentProvider());
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user