KotlinCodeAnalyzer interface extracted
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* Copyright 2010-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.lang.resolve.lazy;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.ModuleConfiguration;
|
||||
import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.ModuleDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.NamespaceDescriptor;
|
||||
import org.jetbrains.jet.lang.psi.JetClassOrObject;
|
||||
import org.jetbrains.jet.lang.psi.JetDeclaration;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||
import org.jetbrains.jet.lang.resolve.name.FqName;
|
||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
|
||||
public interface KotlinCodeAnalyzer {
|
||||
ModuleDescriptor getRootModuleDescriptor();
|
||||
|
||||
@NotNull
|
||||
ModuleConfiguration getModuleConfiguration();
|
||||
|
||||
@Nullable
|
||||
NamespaceDescriptor getPackageDescriptor(@NotNull Name shortName);
|
||||
|
||||
@Nullable
|
||||
NamespaceDescriptor getPackageDescriptorByFqName(FqName fqName);
|
||||
|
||||
@NotNull
|
||||
ClassDescriptor getClassDescriptor(@NotNull JetClassOrObject classOrObject);
|
||||
|
||||
@NotNull
|
||||
BindingContext getBindingContext();
|
||||
|
||||
@NotNull
|
||||
DeclarationDescriptor resolveToDescriptor(JetDeclaration declaration);
|
||||
|
||||
/**
|
||||
* Forces all descriptors to be resolved.
|
||||
*
|
||||
* Use this method when laziness plays against you, e.g. when lazy descriptors may be accessed in a multi-threaded setting
|
||||
*/
|
||||
void forceResolveAll();
|
||||
}
|
||||
@@ -38,7 +38,7 @@ import java.util.List;
|
||||
|
||||
import static org.jetbrains.jet.lang.resolve.lazy.ResolveSessionUtils.safeNameForLazyResolve;
|
||||
|
||||
public class ResolveSession {
|
||||
public class ResolveSession implements KotlinCodeAnalyzer {
|
||||
private static final Function<FqName, Name> NO_ALIASES = new Function<FqName, Name>() {
|
||||
|
||||
@Override
|
||||
@@ -128,6 +128,7 @@ public class ResolveSession {
|
||||
return specialClasses.apply(fqName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ModuleDescriptor getRootModuleDescriptor() {
|
||||
return module;
|
||||
}
|
||||
@@ -137,16 +138,19 @@ public class ResolveSession {
|
||||
return storageManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public ModuleConfiguration getModuleConfiguration() {
|
||||
return moduleConfiguration;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public NamespaceDescriptor getPackageDescriptor(@NotNull Name shortName) {
|
||||
return rootPackage.getMemberScope().getNamespace(shortName);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public NamespaceDescriptor getPackageDescriptorByFqName(FqName fqName) {
|
||||
if (fqName.isRoot()) {
|
||||
@@ -162,6 +166,7 @@ public class ResolveSession {
|
||||
return current;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public ClassDescriptor getClassDescriptor(@NotNull JetClassOrObject classOrObject) {
|
||||
if (classOrObject.getParent() instanceof JetClassObject) {
|
||||
@@ -195,6 +200,7 @@ public class ResolveSession {
|
||||
return classObjectDescriptor;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public BindingContext getBindingContext() {
|
||||
return trace.getBindingContext();
|
||||
@@ -210,6 +216,7 @@ public class ResolveSession {
|
||||
return declarationProviderFactory;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public DeclarationDescriptor resolveToDescriptor(JetDeclaration declaration) {
|
||||
DeclarationDescriptor result = declaration.accept(new JetVisitor<DeclarationDescriptor, Void>() {
|
||||
@@ -319,11 +326,7 @@ public class ResolveSession {
|
||||
return actualName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Forces all descriptors to be resolved.
|
||||
*
|
||||
* Use this method when laziness plays against you, e.g. when lazy descriptors may be accessed in a multi-threaded setting
|
||||
*/
|
||||
@Override
|
||||
public void forceResolveAll() {
|
||||
rootPackage.acceptVoid(new DeclarationDescriptorVisitorEmptyBodies<Void, Void>() {
|
||||
|
||||
|
||||
+10
-10
@@ -154,12 +154,12 @@ public class ResolveSessionUtils {
|
||||
return trace.getBindingContext();
|
||||
}
|
||||
|
||||
private static void delegationSpecifierAdditionalResolve(final ResolveSession resolveSession,
|
||||
private static void delegationSpecifierAdditionalResolve(final KotlinCodeAnalyzer analyzer,
|
||||
final JetDelegationSpecifierList specifier, DelegatingBindingTrace trace, JetFile file) {
|
||||
BodyResolver bodyResolver = createBodyResolverWithEmptyContext(trace, file, resolveSession.getModuleConfiguration());
|
||||
BodyResolver bodyResolver = createBodyResolverWithEmptyContext(trace, file, analyzer.getModuleConfiguration());
|
||||
|
||||
JetClassOrObject classOrObject = (JetClassOrObject) specifier.getParent();
|
||||
LazyClassDescriptor descriptor = (LazyClassDescriptor) resolveSession.resolveToDescriptor(classOrObject);
|
||||
LazyClassDescriptor descriptor = (LazyClassDescriptor) analyzer.resolveToDescriptor(classOrObject);
|
||||
|
||||
// Activate resolving of supertypes
|
||||
descriptor.getTypeConstructor().getSupertypes();
|
||||
@@ -206,14 +206,14 @@ public class ResolveSessionUtils {
|
||||
}
|
||||
|
||||
private static boolean initializerAdditionalResolve(
|
||||
ResolveSession resolveSession,
|
||||
KotlinCodeAnalyzer analyzer,
|
||||
JetClassInitializer classInitializer,
|
||||
DelegatingBindingTrace trace,
|
||||
JetFile file
|
||||
) {
|
||||
BodyResolver bodyResolver = createBodyResolverWithEmptyContext(trace, file, resolveSession.getModuleConfiguration());
|
||||
BodyResolver bodyResolver = createBodyResolverWithEmptyContext(trace, file, analyzer.getModuleConfiguration());
|
||||
JetClassOrObject classOrObject = PsiTreeUtil.getParentOfType(classInitializer, JetClassOrObject.class);
|
||||
LazyClassDescriptor classOrObjectDescriptor = (LazyClassDescriptor) resolveSession.resolveToDescriptor(classOrObject);
|
||||
LazyClassDescriptor classOrObjectDescriptor = (LazyClassDescriptor) analyzer.resolveToDescriptor(classOrObject);
|
||||
bodyResolver.resolveAnonymousInitializers(classOrObject, classOrObjectDescriptor.getUnsubstitutedPrimaryConstructor(),
|
||||
classOrObjectDescriptor.getScopeForPropertyInitializerResolution());
|
||||
|
||||
@@ -321,15 +321,15 @@ public class ResolveSessionUtils {
|
||||
|
||||
@NotNull
|
||||
public static Collection<ClassDescriptor> getClassDescriptorsByFqName(
|
||||
@NotNull ResolveSession resolveSession,
|
||||
@NotNull KotlinCodeAnalyzer analyzer,
|
||||
@NotNull FqName fqName
|
||||
) {
|
||||
return getClassOrObjectDescriptorsByFqName(resolveSession, fqName, false);
|
||||
return getClassOrObjectDescriptorsByFqName(analyzer, fqName, false);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static Collection<ClassDescriptor> getClassOrObjectDescriptorsByFqName(
|
||||
@NotNull ResolveSession resolveSession,
|
||||
@NotNull KotlinCodeAnalyzer analyzer,
|
||||
@NotNull FqName fqName,
|
||||
boolean includeObjectDeclarations
|
||||
) {
|
||||
@@ -341,7 +341,7 @@ public class ResolveSessionUtils {
|
||||
|
||||
FqName packageFqName = fqName.parent();
|
||||
while (true) {
|
||||
NamespaceDescriptor packageDescriptor = resolveSession.getPackageDescriptorByFqName(packageFqName);
|
||||
NamespaceDescriptor packageDescriptor = analyzer.getPackageDescriptorByFqName(packageFqName);
|
||||
if (packageDescriptor != null) {
|
||||
FqName classInPackagePath = new FqName(QualifiedNamesUtil.tail(packageFqName, fqName));
|
||||
Collection<ClassDescriptor> descriptors = getClassOrObjectDescriptorsByFqName(packageDescriptor, classInPackagePath,
|
||||
|
||||
@@ -35,10 +35,9 @@ import org.jetbrains.jet.lang.PlatformToKotlinClassMap;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
|
||||
import org.jetbrains.jet.lang.psi.JetFile;
|
||||
import org.jetbrains.jet.lang.psi.JetImportDirective;
|
||||
import org.jetbrains.jet.lang.psi.JetPsiFactory;
|
||||
import org.jetbrains.jet.lang.resolve.*;
|
||||
import org.jetbrains.jet.lang.resolve.lazy.FileBasedDeclarationProviderFactory;
|
||||
import org.jetbrains.jet.lang.resolve.lazy.KotlinCodeAnalyzer;
|
||||
import org.jetbrains.jet.lang.resolve.lazy.LockBasedStorageManager;
|
||||
import org.jetbrains.jet.lang.resolve.lazy.ResolveSession;
|
||||
import org.jetbrains.jet.lang.resolve.name.FqName;
|
||||
@@ -135,7 +134,7 @@ public class KotlinBuiltIns {
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
private final ResolveSession resolveSession;
|
||||
private final KotlinCodeAnalyzer anazlyer;
|
||||
private final ModuleDescriptor builtInsModule;
|
||||
|
||||
private volatile ImmutableSet<ClassDescriptor> nonPhysicalClasses;
|
||||
@@ -172,7 +171,7 @@ public class KotlinBuiltIns {
|
||||
private KotlinBuiltIns(@NotNull Project project) {
|
||||
try {
|
||||
this.builtInsModule = new ModuleDescriptor(Name.special("<built-ins lazy module>"));
|
||||
this.resolveSession = createLazyResolveSession(project);
|
||||
this.anazlyer = createLazyResolveSession(project);
|
||||
|
||||
this.functionClassesSet = computeIndexedClasses("Function", getFunctionTraitCount());
|
||||
this.extensionFunctionClassesSet = computeIndexedClasses("ExtensionFunction", getFunctionTraitCount());
|
||||
@@ -215,13 +214,13 @@ public class KotlinBuiltIns {
|
||||
|
||||
nonPhysicalClasses = computeNonPhysicalClasses();
|
||||
|
||||
resolveSession.forceResolveAll();
|
||||
anazlyer.forceResolveAll();
|
||||
|
||||
AnalyzingUtils.throwExceptionOnErrors(resolveSession.getBindingContext());
|
||||
AnalyzingUtils.throwExceptionOnErrors(anazlyer.getBindingContext());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private ResolveSession createLazyResolveSession(@NotNull Project project) throws IOException {
|
||||
private KotlinCodeAnalyzer createLazyResolveSession(@NotNull Project project) throws IOException {
|
||||
List<JetFile> files = loadResourcesAsJetFiles(project, LIBRARY_FILES);
|
||||
LockBasedStorageManager storageManager = new LockBasedStorageManager();
|
||||
return new ResolveSession(
|
||||
|
||||
@@ -71,7 +71,7 @@ public abstract class AbstractLazyResolveTest extends JetLiteFixture {
|
||||
}
|
||||
});
|
||||
|
||||
ResolveSession resolveSession = LazyResolveTestUtil.resolveLazilyWithSession(files, getEnvironment());
|
||||
KotlinCodeAnalyzer resolveSession = LazyResolveTestUtil.resolveLazilyWithSession(files, getEnvironment());
|
||||
|
||||
NamespaceDescriptor actual = resolveSession.getPackageDescriptor(Name.identifier("test"));
|
||||
Assert.assertNotNull("Package 'test' was not found", actual);
|
||||
|
||||
@@ -82,7 +82,7 @@ public class LazyResolveTestUtil {
|
||||
return module;
|
||||
}
|
||||
|
||||
public static ResolveSession resolveLazilyWithSession(List<JetFile> files, JetCoreEnvironment environment) {
|
||||
public static KotlinCodeAnalyzer resolveLazilyWithSession(List<JetFile> files, JetCoreEnvironment environment) {
|
||||
JetTestUtils.newTrace(environment);
|
||||
|
||||
ModuleDescriptor javaModule = new ModuleDescriptor(Name.special("<java module>"));
|
||||
|
||||
Reference in New Issue
Block a user