Remove ResolveSession.getResolutionScope() and extend usage of ScopeProvider.getResolutionScopeForDeclaration()
This commit is contained in:
@@ -20,6 +20,7 @@ import com.google.common.base.Predicate;
|
||||
import com.google.common.base.Predicates;
|
||||
import com.google.common.collect.Collections2;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
@@ -139,7 +140,8 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements ClassDes
|
||||
}
|
||||
scope.changeLockLevel(WritableScope.LockLevel.READING);
|
||||
|
||||
scopeForClassHeaderResolution = new ChainedScope(this, scope, resolveSession.getResolutionScope(declarationProvider.getOwnerInfo().getScopeAnchor()));
|
||||
PsiElement scopeAnchor = declarationProvider.getOwnerInfo().getScopeAnchor();
|
||||
scopeForClassHeaderResolution = new ChainedScope(this, scope, getScopeProvider().getResolutionScopeForDeclaration(scopeAnchor));
|
||||
}
|
||||
return scopeForClassHeaderResolution;
|
||||
}
|
||||
@@ -285,8 +287,8 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements ClassDes
|
||||
JetModifierList modifierList = classInfo.getModifierList();
|
||||
if (modifierList != null) {
|
||||
AnnotationResolver annotationResolver = resolveSession.getInjector().getAnnotationResolver();
|
||||
annotations = annotationResolver
|
||||
.resolveAnnotations(resolveSession.getResolutionScope(classInfo.getScopeAnchor()), modifierList, resolveSession.getTrace());
|
||||
JetScope scopeForDeclaration = getScopeProvider().getResolutionScopeForDeclaration(classInfo.getScopeAnchor());
|
||||
annotations = annotationResolver.resolveAnnotations(scopeForDeclaration, modifierList, resolveSession.getTrace());
|
||||
}
|
||||
else {
|
||||
annotations = Collections.emptyList();
|
||||
@@ -426,4 +428,8 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements ClassDes
|
||||
};
|
||||
}
|
||||
|
||||
private ScopeProvider getScopeProvider() {
|
||||
return resolveSession.getInjector().getScopeProvider();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -34,7 +34,6 @@ import org.jetbrains.jet.lang.resolve.BindingTraceContext;
|
||||
import org.jetbrains.jet.lang.resolve.name.FqName;
|
||||
import org.jetbrains.jet.lang.resolve.name.FqNameUnsafe;
|
||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.InnerClassesScopeWrapper;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
||||
|
||||
import java.util.List;
|
||||
@@ -135,7 +134,7 @@ public class ResolveSession {
|
||||
if (classOrObject.getParent() instanceof JetClassObject) {
|
||||
return getClassObjectDescriptor((JetClassObject) classOrObject.getParent());
|
||||
}
|
||||
JetScope resolutionScope = getInjector().getScopeProvider().getResolutionScopeForDeclaration((JetDeclaration) classOrObject);
|
||||
JetScope resolutionScope = getInjector().getScopeProvider().getResolutionScopeForDeclaration(classOrObject);
|
||||
Name name = classOrObject.getNameAsName();
|
||||
assert name != null : "Name is null for " + classOrObject + " " + classOrObject.getText();
|
||||
ClassifierDescriptor classifier = resolutionScope.getClassifier(name);
|
||||
@@ -170,33 +169,6 @@ public class ResolveSession {
|
||||
return declarationProviderFactory;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public JetScope getResolutionScope(@NotNull PsiElement element) {
|
||||
PsiElement parent = element.getParent();
|
||||
if (parent instanceof JetFile) {
|
||||
JetFile file = (JetFile) parent;
|
||||
return getInjector().getScopeProvider().getFileScopeForDeclarationResolution(file);
|
||||
}
|
||||
|
||||
if (parent instanceof JetClassBody) {
|
||||
return getEnclosingLazyClass(element).getScopeForMemberDeclarationResolution();
|
||||
}
|
||||
|
||||
if (parent instanceof JetClassObject) {
|
||||
return new InnerClassesScopeWrapper(getEnclosingLazyClass(element).getScopeForMemberDeclarationResolution());
|
||||
}
|
||||
|
||||
throw new IllegalArgumentException("Unsupported PSI element: " + element);
|
||||
}
|
||||
|
||||
private LazyClassDescriptor getEnclosingLazyClass(PsiElement element) {
|
||||
JetClassOrObject classOrObject = PsiTreeUtil.getParentOfType(element.getParent(), JetClassOrObject.class);
|
||||
assert classOrObject != null : "Called for an element that is not a class member: " + element;
|
||||
ClassDescriptor classDescriptor = getClassDescriptor(classOrObject);
|
||||
assert classDescriptor instanceof LazyClassDescriptor : "Trying to resolve a member of a non-lazily loaded class: " + element;
|
||||
return (LazyClassDescriptor) classDescriptor;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public DeclarationDescriptor resolveToDescriptor(JetDeclaration declaration) {
|
||||
DeclarationDescriptor result = declaration.accept(new JetVisitor<DeclarationDescriptor, Void>() {
|
||||
|
||||
@@ -183,7 +183,7 @@ public class ResolveSessionUtils {
|
||||
JetFile file
|
||||
) {
|
||||
BodyResolver bodyResolver = createBodyResolver(trace, file, resolveSession.getModuleConfiguration());
|
||||
JetScope scope = resolveSession.getResolutionScope(namedFunction);
|
||||
JetScope scope = resolveSession.getInjector().getScopeProvider().getResolutionScopeForDeclaration(namedFunction);
|
||||
FunctionDescriptor functionDescriptor = (FunctionDescriptor) resolveSession.resolveToDescriptor(namedFunction);
|
||||
bodyResolver.resolveFunctionBody(trace, namedFunction, functionDescriptor, scope);
|
||||
}
|
||||
@@ -216,11 +216,12 @@ public class ResolveSessionUtils {
|
||||
}
|
||||
|
||||
private static JetScope getExpressionResolutionScope(@NotNull ResolveSession resolveSession, @NotNull JetExpression expression) {
|
||||
ScopeProvider provider = resolveSession.getInjector().getScopeProvider();
|
||||
JetDeclaration parentDeclaration = PsiTreeUtil.getParentOfType(expression, JetDeclaration.class);
|
||||
if (parentDeclaration == null) {
|
||||
return resolveSession.getResolutionScope(expression.getContainingFile().getFirstChild());
|
||||
return provider.getFileScopeForDeclarationResolution((JetFile) expression.getContainingFile());
|
||||
}
|
||||
return resolveSession.getResolutionScope(parentDeclaration);
|
||||
return provider.getResolutionScopeForDeclaration(parentDeclaration);
|
||||
}
|
||||
|
||||
public static JetScope getExpressionMemberScope(@NotNull ResolveSession resolveSession, @NotNull JetExpression expression) {
|
||||
|
||||
@@ -80,13 +80,19 @@ public class ScopeProvider {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public JetScope getResolutionScopeForDeclaration(@NotNull JetDeclaration jetDeclaration) {
|
||||
PsiElement immediateParent = jetDeclaration.getParent();
|
||||
if (immediateParent instanceof JetFile) {
|
||||
return getFileScopeForDeclarationResolution((JetFile) immediateParent);
|
||||
}
|
||||
public JetScope getResolutionScopeForDeclaration(@NotNull PsiElement elementOfDeclaration) {
|
||||
JetDeclaration jetDeclaration = PsiTreeUtil.getParentOfType(elementOfDeclaration, JetDeclaration.class, false);
|
||||
|
||||
assert !(elementOfDeclaration instanceof JetDeclaration) || jetDeclaration == elementOfDeclaration :
|
||||
"For JetDeclaration element getParentOfType() should return itself.";
|
||||
|
||||
JetDeclaration parentDeclaration = PsiTreeUtil.getParentOfType(jetDeclaration, JetDeclaration.class);
|
||||
if (parentDeclaration == null) {
|
||||
return getFileScopeForDeclarationResolution((JetFile) elementOfDeclaration.getContainingFile());
|
||||
}
|
||||
|
||||
assert jetDeclaration != null : "Can't happen because of getParentOfType(null, ?) == null";
|
||||
|
||||
if (parentDeclaration instanceof JetClassOrObject) {
|
||||
JetClassOrObject classOrObject = (JetClassOrObject) parentDeclaration;
|
||||
LazyClassDescriptor classDescriptor = (LazyClassDescriptor) resolveSession.getClassDescriptor(classOrObject);
|
||||
@@ -98,13 +104,18 @@ public class ScopeProvider {
|
||||
}
|
||||
return classDescriptor.getScopeForMemberDeclarationResolution();
|
||||
}
|
||||
else if (parentDeclaration instanceof JetClassObject) {
|
||||
|
||||
if (parentDeclaration instanceof JetClassObject) {
|
||||
assert jetDeclaration instanceof JetObjectDeclaration : "Should be situation for getting scope for object in class [object {...}]";
|
||||
|
||||
JetClassObject classObject = (JetClassObject) parentDeclaration;
|
||||
LazyClassDescriptor classObjectDescriptor = resolveSession.getClassObjectDescriptor(classObject);
|
||||
return classObjectDescriptor.getScopeForMemberDeclarationResolution();
|
||||
}
|
||||
else {
|
||||
throw new IllegalStateException("Don't call this method for local declarations: " + jetDeclaration + " " + jetDeclaration.getText());
|
||||
LazyClassDescriptor classObjectDescriptor =
|
||||
(LazyClassDescriptor) resolveSession.getClassObjectDescriptor(classObject).getContainingDeclaration();
|
||||
|
||||
// During class object header resolve there should be no resolution for parent class generic params
|
||||
return new InnerClassesScopeWrapper(classObjectDescriptor.getScopeForMemberDeclarationResolution());
|
||||
}
|
||||
|
||||
throw new IllegalStateException("Don't call this method for local declarations: " + jetDeclaration + " " + jetDeclaration.getText());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package test
|
||||
|
||||
class Some {
|
||||
TestAnnotation class object {
|
||||
annotation class TestAnnotation
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
namespace test
|
||||
|
||||
internal final class test.Some : jet.Any {
|
||||
public final /*constructor*/ fun <init>(): test.Some
|
||||
[ERROR : Unresolved annotation type]() internal final class object test.Some.<class-object-for-Some> : jet.Any {
|
||||
private final /*constructor*/ fun <init>(): test.Some.<class-object-for-Some>
|
||||
internal final annotation class test.Some.<class-object-for-Some>.TestAnnotation : jet.Annotation {
|
||||
public final /*constructor*/ fun <init>(): test.Some.<class-object-for-Some>.TestAnnotation
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package test
|
||||
|
||||
open class ToResolve<SomeClass>(f : (Int) -> Int)
|
||||
fun testFun(a : Int) = 12
|
||||
|
||||
class TestSome<P> {
|
||||
class object : ToResolve<P>({testFun(it)}) {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
namespace test
|
||||
|
||||
internal final class test.TestSome</*0*/ P : jet.Any?> : jet.Any {
|
||||
public final /*constructor*/ fun </*0*/ P : jet.Any?><init>(): test.TestSome<P>
|
||||
internal final class object test.TestSome.<class-object-for-TestSome> : test.ToResolve<[ERROR : P]> {
|
||||
private final /*constructor*/ fun <init>(): test.TestSome.<class-object-for-TestSome>
|
||||
}
|
||||
}
|
||||
internal open class test.ToResolve</*0*/ SomeClass : jet.Any?> : jet.Any {
|
||||
public final /*constructor*/ fun </*0*/ SomeClass : jet.Any?><init>(/*0*/ f: jet.Function1<jet.Int, jet.Int>): test.ToResolve<SomeClass>
|
||||
}
|
||||
internal final fun testFun(/*0*/ a: jet.Int): jet.Int
|
||||
+11
-4
@@ -15,16 +15,13 @@
|
||||
*/
|
||||
package org.jetbrains.jet.lang.resolve.lazy;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import junit.framework.Test;
|
||||
import junit.framework.TestSuite;
|
||||
|
||||
import java.io.File;
|
||||
import org.jetbrains.jet.JetTestUtils;
|
||||
import org.jetbrains.jet.test.InnerTestClasses;
|
||||
import org.jetbrains.jet.test.TestMetadata;
|
||||
|
||||
import org.jetbrains.jet.lang.resolve.lazy.AbstractLazyResolveNamespaceComparingTest;
|
||||
import java.io.File;
|
||||
|
||||
/** This class is generated by {@link org.jetbrains.jet.lang.resolve.lazy.AbstractLazyResolveNamespaceComparingTest}. DO NOT MODIFY MANUALLY */
|
||||
@InnerTestClasses({LazyResolveNamespaceComparingTestGenerated.LoadKotlin.class, LazyResolveNamespaceComparingTestGenerated.LoadJava.class, LazyResolveNamespaceComparingTestGenerated.NamespaceComparator.class})
|
||||
@@ -1349,6 +1346,16 @@ public class LazyResolveNamespaceComparingTestGenerated extends AbstractLazyReso
|
||||
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.lang.resolve.lazy.AbstractLazyResolveNamespaceComparingTest", new File("compiler/testData/lazyResolve/namespaceComparator"), "kt", true);
|
||||
}
|
||||
|
||||
@TestMetadata("classObjectAnnotation.kt")
|
||||
public void testClassObjectAnnotation() throws Exception {
|
||||
doTestSinglePackage("compiler/testData/lazyResolve/namespaceComparator/classObjectAnnotation.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("classObjectHeader.kt")
|
||||
public void testClassObjectHeader() throws Exception {
|
||||
doTestSinglePackage("compiler/testData/lazyResolve/namespaceComparator/classObjectHeader.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("enum.kt")
|
||||
public void testEnum() throws Exception {
|
||||
doTestSinglePackage("compiler/testData/lazyResolve/namespaceComparator/enum.kt");
|
||||
|
||||
Reference in New Issue
Block a user