Classifier lookup fixed
This commit is contained in:
@@ -68,7 +68,7 @@ public class ClassDescriptorResolver {
|
||||
public void resolveMutableClassDescriptor(@NotNull JetScope scope, @NotNull JetClass classElement, @NotNull MutableClassDescriptor descriptor) {
|
||||
descriptor.setName(classElement.getName());
|
||||
|
||||
WritableScope parameterScope = descriptor.getUnsubstitutedMemberScope();
|
||||
WritableScope parameterScope = descriptor.getClassHeaderScope();
|
||||
|
||||
// This call has side-effects on the parameterScope (fills it in)
|
||||
List<TypeParameterDescriptor> typeParameters
|
||||
|
||||
@@ -17,26 +17,20 @@ public interface JetScope {
|
||||
};
|
||||
|
||||
@Nullable
|
||||
ClassDescriptor getClass(@NotNull String name);
|
||||
|
||||
@Nullable
|
||||
PropertyDescriptor getProperty(@NotNull String name);
|
||||
|
||||
@Nullable
|
||||
ExtensionDescriptor getExtension(@NotNull String name);
|
||||
ClassifierDescriptor getClassifier(@NotNull String name);
|
||||
|
||||
@Nullable
|
||||
NamespaceDescriptor getNamespace(@NotNull String name);
|
||||
|
||||
@Nullable
|
||||
TypeParameterDescriptor getTypeParameter(@NotNull String name);
|
||||
|
||||
@NotNull
|
||||
JetType getThisType();
|
||||
PropertyDescriptor getProperty(@NotNull String name);
|
||||
|
||||
@NotNull
|
||||
FunctionGroup getFunctionGroup(@NotNull String name);
|
||||
|
||||
@NotNull
|
||||
JetType getThisType();
|
||||
|
||||
@NotNull
|
||||
DeclarationDescriptor getContainingDeclaration();
|
||||
}
|
||||
}
|
||||
@@ -26,19 +26,14 @@ public class JetScopeAdapter implements JetScope {
|
||||
return scope.getFunctionGroup(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypeParameterDescriptor getTypeParameter(@NotNull String name) {
|
||||
return scope.getTypeParameter(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NamespaceDescriptor getNamespace(@NotNull String name) {
|
||||
return scope.getNamespace(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ClassDescriptor getClass(@NotNull String name) {
|
||||
return scope.getClass(name);
|
||||
public ClassifierDescriptor getClassifier(@NotNull String name) {
|
||||
return scope.getClassifier(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -46,11 +41,6 @@ public class JetScopeAdapter implements JetScope {
|
||||
return scope.getProperty(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ExtensionDescriptor getExtension(@NotNull String name) {
|
||||
return scope.getExtension(name);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public DeclarationDescriptor getContainingDeclaration() {
|
||||
|
||||
@@ -8,7 +8,7 @@ import org.jetbrains.jet.lang.types.*;
|
||||
*/
|
||||
public abstract class JetScopeImpl implements JetScope {
|
||||
@Override
|
||||
public ClassDescriptor getClass(@NotNull String name) {
|
||||
public ClassifierDescriptor getClassifier(@NotNull String name) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -17,21 +17,11 @@ public abstract class JetScopeImpl implements JetScope {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ExtensionDescriptor getExtension(@NotNull String name) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NamespaceDescriptor getNamespace(@NotNull String name) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypeParameterDescriptor getTypeParameter(@NotNull String name) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public JetType getThisType() {
|
||||
|
||||
@@ -11,6 +11,7 @@ import java.util.Map;
|
||||
* @author abreslav
|
||||
*/
|
||||
public class MutableClassDescriptor extends MutableDeclarationDescriptor implements ClassDescriptor {
|
||||
private final WritableScope classHeaderScope;
|
||||
private final WritableScope unsubstitutedMemberScope;
|
||||
private final WritableFunctionGroup constructors = new WritableFunctionGroup("<init>");
|
||||
|
||||
@@ -18,7 +19,8 @@ public class MutableClassDescriptor extends MutableDeclarationDescriptor impleme
|
||||
|
||||
public MutableClassDescriptor(@NotNull JetSemanticServices semanticServices, @NotNull DeclarationDescriptor containingDeclaration, @NotNull JetScope outerScope) {
|
||||
super(containingDeclaration);
|
||||
this.unsubstitutedMemberScope = semanticServices.createWritableScope(outerScope, this);
|
||||
this.classHeaderScope = semanticServices.createWritableScope(outerScope, this);
|
||||
this.unsubstitutedMemberScope = semanticServices.createWritableScope(classHeaderScope, this);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -68,6 +70,11 @@ public class MutableClassDescriptor extends MutableDeclarationDescriptor impleme
|
||||
return unsubstitutedMemberScope;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public WritableScope getClassHeaderScope() {
|
||||
return classHeaderScope;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R, D> R accept(DeclarationDescriptorVisitor<R, D> visitor, D data) {
|
||||
return visitor.visitClassDescriptor(this, data);
|
||||
|
||||
@@ -23,8 +23,8 @@ public class ScopeWithReceiver extends JetScopeImpl {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ClassDescriptor getClass(@NotNull String name) {
|
||||
return super.getClass(name); // TODO
|
||||
public ClassifierDescriptor getClassifier(@NotNull String name) {
|
||||
return super.getClassifier(name); // TODO
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -33,21 +33,11 @@ public class ScopeWithReceiver extends JetScopeImpl {
|
||||
// TODO : extension properties
|
||||
}
|
||||
|
||||
@Override
|
||||
public ExtensionDescriptor getExtension(@NotNull String name) {
|
||||
return super.getExtension(name); // TODO
|
||||
}
|
||||
|
||||
@Override
|
||||
public NamespaceDescriptor getNamespace(@NotNull String name) {
|
||||
return receiverTypeScope.getNamespace(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypeParameterDescriptor getTypeParameter(@NotNull String name) {
|
||||
return outerScope.getTypeParameter(name);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public JetType getThisType() {
|
||||
|
||||
@@ -48,17 +48,15 @@ public class SubstitutingScope implements JetScope {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ClassDescriptor getClass(@NotNull String name) {
|
||||
ClassDescriptor descriptor = workerScope.getClass(name);
|
||||
public ClassifierDescriptor getClassifier(@NotNull String name) {
|
||||
ClassifierDescriptor descriptor = workerScope.getClassifier(name);
|
||||
if (descriptor == null) {
|
||||
return null;
|
||||
}
|
||||
return new LazySubstitutingClassDescriptor(descriptor, substitutionContext);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ExtensionDescriptor getExtension(@NotNull String name) {
|
||||
throw new UnsupportedOperationException(); // TODO
|
||||
if (descriptor instanceof ClassDescriptor) {
|
||||
return new LazySubstitutingClassDescriptor((ClassDescriptor) descriptor, substitutionContext);
|
||||
}
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -66,11 +64,6 @@ public class SubstitutingScope implements JetScope {
|
||||
return workerScope.getNamespace(name); // TODO
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypeParameterDescriptor getTypeParameter(@NotNull String name) {
|
||||
throw new UnsupportedOperationException(); // TODO
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public JetType getThisType() {
|
||||
|
||||
@@ -114,7 +114,7 @@ public class TopDownAnalyzer {
|
||||
MutableClassDescriptor mutableClassDescriptor = new MutableClassDescriptor(semanticServices, declaringScope.getContainingDeclaration(), declaringScope);
|
||||
mutableClassDescriptor.setName(klass.getName());
|
||||
|
||||
declaringScope.addClassDescriptor(mutableClassDescriptor);
|
||||
declaringScope.addClassifierDescriptor(mutableClassDescriptor);
|
||||
|
||||
classes.put(klass, mutableClassDescriptor);
|
||||
declaringScopes.put(klass, declaringScope);
|
||||
|
||||
@@ -46,10 +46,13 @@ public class TypeResolver {
|
||||
return;
|
||||
}
|
||||
|
||||
if (type.getTypeArguments().isEmpty() && type.getQualifier() == null) {
|
||||
TypeParameterDescriptor typeParameterDescriptor = scope.getTypeParameter(referencedName);
|
||||
if (typeParameterDescriptor != null) {
|
||||
ClassifierDescriptor classifierDescriptor = resolveClass(scope, type);
|
||||
if (classifierDescriptor != null) {
|
||||
if (classifierDescriptor instanceof TypeParameterDescriptor) {
|
||||
TypeParameterDescriptor typeParameterDescriptor = (TypeParameterDescriptor) classifierDescriptor;
|
||||
|
||||
trace.recordReferenceResolution(referenceExpression, typeParameterDescriptor);
|
||||
|
||||
result[0] = new JetTypeImpl(
|
||||
attributes,
|
||||
typeParameterDescriptor.getTypeConstructor(),
|
||||
@@ -58,25 +61,24 @@ public class TypeResolver {
|
||||
// TODO : joint domain
|
||||
JetStandardClasses.STUB
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
ClassDescriptor classDescriptor = resolveClass(scope, type);
|
||||
if (classDescriptor != null) {
|
||||
trace.recordReferenceResolution(referenceExpression, classDescriptor);
|
||||
TypeConstructor typeConstructor = classDescriptor.getTypeConstructor();
|
||||
List<TypeProjection> arguments = resolveTypeProjections(scope, typeConstructor, type.getTypeArguments());
|
||||
if (arguments.size() != typeConstructor.getParameters().size()) {
|
||||
semanticServices.getErrorHandler().genericError(type.getNode(), typeConstructor.getParameters().size() + " type parameters expected"); // TODO : message
|
||||
} else {
|
||||
result[0] = new JetTypeImpl(
|
||||
attributes,
|
||||
typeConstructor,
|
||||
nullable,
|
||||
arguments,
|
||||
classDescriptor.getMemberScope(arguments)
|
||||
);
|
||||
else if (classifierDescriptor instanceof ClassDescriptor) {
|
||||
ClassDescriptor classDescriptor = (ClassDescriptor) classifierDescriptor;
|
||||
|
||||
trace.recordReferenceResolution(referenceExpression, classifierDescriptor);
|
||||
TypeConstructor typeConstructor = classifierDescriptor.getTypeConstructor();
|
||||
List<TypeProjection> arguments = resolveTypeProjections(scope, typeConstructor, type.getTypeArguments());
|
||||
if (arguments.size() != typeConstructor.getParameters().size()) {
|
||||
semanticServices.getErrorHandler().genericError(type.getNode(), typeConstructor.getParameters().size() + " type parameters expected"); // TODO : message
|
||||
} else {
|
||||
result[0] = new JetTypeImpl(
|
||||
attributes,
|
||||
typeConstructor,
|
||||
nullable,
|
||||
arguments,
|
||||
classDescriptor.getMemberScope(arguments)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -171,12 +173,7 @@ public class TypeResolver {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public ClassDescriptor resolveClassByUserType(JetScope scope, JetUserType userType) {
|
||||
return resolveClass(scope, userType);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private ClassDescriptor resolveClass(JetScope scope, JetUserType userType) {
|
||||
public ClassifierDescriptor resolveClass(JetScope scope, JetUserType userType) {
|
||||
JetSimpleNameExpression expression = userType.getReferenceExpression();
|
||||
if (expression == null) {
|
||||
return null;
|
||||
@@ -185,9 +182,9 @@ public class TypeResolver {
|
||||
if (referencedName == null) {
|
||||
return null;
|
||||
}
|
||||
ClassDescriptor classDescriptor = null;
|
||||
ClassifierDescriptor classifierDescriptor = null;
|
||||
if (userType.isAbsoluteInRootNamespace()) {
|
||||
classDescriptor = JetModuleUtil.getRootNamespaceScope(userType).getClass(referencedName);
|
||||
classifierDescriptor = JetModuleUtil.getRootNamespaceScope(userType).getClassifier(referencedName);
|
||||
}
|
||||
else {
|
||||
JetUserType qualifier = userType.getQualifier();
|
||||
@@ -197,21 +194,22 @@ public class TypeResolver {
|
||||
if (scope == null) {
|
||||
return null;
|
||||
}
|
||||
classDescriptor = scope.getClass(referencedName);
|
||||
classifierDescriptor = scope.getClassifier(referencedName);
|
||||
}
|
||||
|
||||
if (classDescriptor == null) {
|
||||
if (classifierDescriptor == null) {
|
||||
semanticServices.getErrorHandler().unresolvedReference(expression);
|
||||
}
|
||||
|
||||
return classDescriptor;
|
||||
return classifierDescriptor;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private JetScope resolveClassLookupScope(JetScope scope, JetUserType userType) {
|
||||
ClassDescriptor classDescriptor = resolveClass(scope, userType);
|
||||
if (classDescriptor != null) {
|
||||
return classDescriptor.getMemberScope(resolveTypeProjections(scope, classDescriptor.getTypeConstructor(), userType.getTypeArguments()));
|
||||
ClassifierDescriptor classifierDescriptor = resolveClass(scope, userType);
|
||||
if (classifierDescriptor instanceof ClassDescriptor) {
|
||||
List<TypeProjection> typeArguments = resolveTypeProjections(scope, classifierDescriptor.getTypeConstructor(), userType.getTypeArguments());
|
||||
return ((ClassDescriptor) classifierDescriptor).getMemberScope(typeArguments);
|
||||
}
|
||||
|
||||
NamespaceDescriptor namespaceDescriptor = resolveNamespace(scope, userType);
|
||||
|
||||
@@ -22,9 +22,7 @@ public class WritableScope extends JetScopeAdapter {
|
||||
@Nullable
|
||||
private Map<String, WritableFunctionGroup> functionGroups;
|
||||
@Nullable
|
||||
private Map<String, TypeParameterDescriptor> typeParameterDescriptors;
|
||||
@Nullable
|
||||
private Map<String, ClassDescriptor> classDescriptors;
|
||||
private Map<String, ClassifierDescriptor> classifierDescriptors;
|
||||
@Nullable
|
||||
private Map<String, NamespaceDescriptor> namespaceDescriptors;
|
||||
@Nullable
|
||||
@@ -138,65 +136,48 @@ public class WritableScope extends JetScopeAdapter {
|
||||
return functionGroup;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private Map<String, TypeParameterDescriptor> getTypeParameterDescriptors() {
|
||||
if (typeParameterDescriptors == null) {
|
||||
typeParameterDescriptors = new HashMap<String, TypeParameterDescriptor>();
|
||||
}
|
||||
return typeParameterDescriptors;
|
||||
}
|
||||
|
||||
public void addTypeParameterDescriptor(TypeParameterDescriptor typeParameterDescriptor) {
|
||||
String name = typeParameterDescriptor.getName();
|
||||
Map<String, TypeParameterDescriptor> typeParameterDescriptors = getTypeParameterDescriptors();
|
||||
TypeParameterDescriptor originalDescriptor = typeParameterDescriptors.get(name);
|
||||
Map<String, ClassifierDescriptor> classifierDescriptors = getClassifierDescriptors();
|
||||
ClassifierDescriptor originalDescriptor = classifierDescriptors.get(name);
|
||||
if (originalDescriptor != null) {
|
||||
errorHandler.redeclaration(originalDescriptor, typeParameterDescriptor);
|
||||
}
|
||||
typeParameterDescriptors.put(name, typeParameterDescriptor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypeParameterDescriptor getTypeParameter(@NotNull String name) {
|
||||
TypeParameterDescriptor typeParameterDescriptor = getTypeParameterDescriptors().get(name);
|
||||
if (typeParameterDescriptor != null) {
|
||||
return typeParameterDescriptor;
|
||||
}
|
||||
return super.getTypeParameter(name);
|
||||
classifierDescriptors.put(name, typeParameterDescriptor);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private Map<String, ClassDescriptor> getClassDescriptors() {
|
||||
if (classDescriptors == null) {
|
||||
classDescriptors = new HashMap<String, ClassDescriptor>();
|
||||
private Map<String, ClassifierDescriptor> getClassifierDescriptors() {
|
||||
if (classifierDescriptors == null) {
|
||||
classifierDescriptors = new HashMap<String, ClassifierDescriptor>();
|
||||
}
|
||||
return classDescriptors;
|
||||
return classifierDescriptors;
|
||||
}
|
||||
|
||||
public void addClassDescriptor(@NotNull ClassDescriptor classDescriptor) {
|
||||
addClassAlias(classDescriptor.getName(), classDescriptor);
|
||||
public void addClassifierDescriptor(@NotNull ClassifierDescriptor classDescriptor) {
|
||||
addClassifierAlias(classDescriptor.getName(), classDescriptor);
|
||||
}
|
||||
|
||||
public void addClassAlias(String name, ClassDescriptor classDescriptor) {
|
||||
Map<String, ClassDescriptor> classDescriptors = getClassDescriptors();
|
||||
ClassDescriptor originalDescriptor = classDescriptors.get(name);
|
||||
public void addClassifierAlias(String name, ClassifierDescriptor classifierDescriptor) {
|
||||
Map<String, ClassifierDescriptor> classifierDescriptors = getClassifierDescriptors();
|
||||
ClassifierDescriptor originalDescriptor = classifierDescriptors.get(name);
|
||||
if (originalDescriptor != null) {
|
||||
errorHandler.redeclaration(originalDescriptor, classDescriptor);
|
||||
errorHandler.redeclaration(originalDescriptor, classifierDescriptor);
|
||||
}
|
||||
classDescriptors.put(name, classDescriptor);
|
||||
classifierDescriptors.put(name, classifierDescriptor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ClassDescriptor getClass(@NotNull String name) {
|
||||
ClassDescriptor classDescriptor = getClassDescriptors().get(name);
|
||||
if (classDescriptor != null) return classDescriptor;
|
||||
public ClassifierDescriptor getClassifier(@NotNull String name) {
|
||||
ClassifierDescriptor classifierDescriptor = getClassifierDescriptors().get(name);
|
||||
if (classifierDescriptor != null) return classifierDescriptor;
|
||||
|
||||
classDescriptor = super.getClass(name);
|
||||
if (classDescriptor != null) return classDescriptor;
|
||||
classifierDescriptor = super.getClassifier(name);
|
||||
if (classifierDescriptor != null) return classifierDescriptor;
|
||||
for (JetScope imported : getImports()) {
|
||||
ClassDescriptor importedClass = imported.getClass(name);
|
||||
if (importedClass != null) {
|
||||
return importedClass;
|
||||
ClassifierDescriptor importedClassifier = imported.getClassifier(name);
|
||||
if (importedClassifier != null) {
|
||||
return importedClassifier;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
@@ -248,11 +229,6 @@ public class WritableScope extends JetScopeAdapter {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ExtensionDescriptor getExtension(@NotNull String name) {
|
||||
return super.getExtension(name); // TODO
|
||||
}
|
||||
|
||||
public void setThisType(JetType thisType) {
|
||||
if (this.thisType != null) {
|
||||
throw new UnsupportedOperationException("Receiver redeclared");
|
||||
|
||||
@@ -31,7 +31,7 @@ public class JavaClassMembersScope implements JetScope {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ClassDescriptor getClass(@NotNull String name) {
|
||||
public ClassifierDescriptor getClassifier(@NotNull String name) {
|
||||
for (PsiClass innerClass : psiClass.getAllInnerClasses()) {
|
||||
if (name.equals(innerClass.getName())) {
|
||||
if (innerClass.hasModifierProperty(PsiModifier.STATIC) != staticMembers) return null;
|
||||
@@ -90,21 +90,11 @@ public class JavaClassMembersScope implements JetScope {
|
||||
return writableFunctionGroup;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ExtensionDescriptor getExtension(@NotNull String name) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NamespaceDescriptor getNamespace(@NotNull String name) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypeParameterDescriptor getTypeParameter(@NotNull String name) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public JetType getThisType() {
|
||||
|
||||
@@ -2,7 +2,7 @@ package org.jetbrains.jet.lang.resolve.java;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.resolve.JetScopeImpl;
|
||||
import org.jetbrains.jet.lang.types.ClassDescriptor;
|
||||
import org.jetbrains.jet.lang.types.ClassifierDescriptor;
|
||||
import org.jetbrains.jet.lang.types.DeclarationDescriptor;
|
||||
import org.jetbrains.jet.lang.types.NamespaceDescriptor;
|
||||
|
||||
@@ -22,7 +22,7 @@ public class JavaPackageScope extends JetScopeImpl {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ClassDescriptor getClass(@NotNull String name) {
|
||||
public ClassifierDescriptor getClassifier(@NotNull String name) {
|
||||
return semanticServices.getDescriptorResolver().resolveClass(getQualifiedName(name));
|
||||
}
|
||||
|
||||
|
||||
@@ -8,9 +8,7 @@ import java.util.List;
|
||||
/**
|
||||
* @author abreslav
|
||||
*/
|
||||
public interface ClassDescriptor extends DeclarationDescriptor {
|
||||
@NotNull
|
||||
TypeConstructor getTypeConstructor();
|
||||
public interface ClassDescriptor extends ClassifierDescriptor {
|
||||
|
||||
@NotNull
|
||||
JetScope getMemberScope(List<TypeProjection> typeArguments);
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
package org.jetbrains.jet.lang.types;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* @author abreslav
|
||||
*/
|
||||
public interface ClassifierDescriptor extends DeclarationDescriptor {
|
||||
@NotNull
|
||||
TypeConstructor getTypeConstructor();
|
||||
}
|
||||
@@ -15,7 +15,7 @@ public class ErrorUtils {
|
||||
private static final JetScope ERROR_SCOPE = new JetScope() {
|
||||
|
||||
@Override
|
||||
public ClassDescriptor getClass(@NotNull String name) {
|
||||
public ClassifierDescriptor getClassifier(@NotNull String name) {
|
||||
return ERROR_CLASS;
|
||||
}
|
||||
|
||||
@@ -24,21 +24,11 @@ public class ErrorUtils {
|
||||
return ERROR_PROPERTY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ExtensionDescriptor getExtension(@NotNull String name) {
|
||||
return null; // TODO : review
|
||||
}
|
||||
|
||||
@Override
|
||||
public NamespaceDescriptor getNamespace(@NotNull String name) {
|
||||
return null; // TODO : review
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypeParameterDescriptor getTypeParameter(@NotNull String name) {
|
||||
return null; // TODO : review
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public JetType getThisType() {
|
||||
|
||||
@@ -166,7 +166,7 @@ public class JetStandardClasses {
|
||||
static {
|
||||
WritableScope writableScope = new WritableScope(JetScope.EMPTY, STANDARD_CLASSES_NAMESPACE, ErrorHandler.DO_NOTHING);
|
||||
STANDARD_CLASSES = writableScope;
|
||||
writableScope.addClassAlias("Unit", getTuple(0));
|
||||
writableScope.addClassifierAlias("Unit", getTuple(0));
|
||||
|
||||
Field[] declaredFields = JetStandardClasses.class.getDeclaredFields();
|
||||
for (Field field : declaredFields) {
|
||||
@@ -177,7 +177,7 @@ public class JetStandardClasses {
|
||||
if (type == ClassDescriptor.class) {
|
||||
try {
|
||||
ClassDescriptor descriptor = (ClassDescriptor) field.get(null);
|
||||
writableScope.addClassDescriptor(descriptor);
|
||||
writableScope.addClassifierDescriptor(descriptor);
|
||||
} catch (IllegalAccessException e) {
|
||||
throw new IllegalStateException(e);
|
||||
}
|
||||
@@ -185,7 +185,7 @@ public class JetStandardClasses {
|
||||
try {
|
||||
ClassDescriptor[] array = (ClassDescriptor[]) field.get(null);
|
||||
for (ClassDescriptor descriptor : array) {
|
||||
writableScope.addClassDescriptor(descriptor);
|
||||
writableScope.addClassifierDescriptor(descriptor);
|
||||
}
|
||||
} catch (IllegalAccessException e) {
|
||||
throw new IllegalStateException(e);
|
||||
|
||||
@@ -8,7 +8,6 @@ import org.jetbrains.jet.lang.ErrorHandler;
|
||||
import org.jetbrains.jet.lang.JetFileType;
|
||||
import org.jetbrains.jet.lang.JetSemanticServices;
|
||||
import org.jetbrains.jet.lang.psi.JetFile;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||
import org.jetbrains.jet.lang.resolve.BindingTraceContext;
|
||||
import org.jetbrains.jet.lang.resolve.JetScope;
|
||||
import org.jetbrains.jet.lang.resolve.TopDownAnalyzer;
|
||||
@@ -74,21 +73,20 @@ public class JetStandardLibrary {
|
||||
BindingTraceContext bindingTraceContext = new BindingTraceContext();
|
||||
TopDownAnalyzer bootstrappingTDA = new TopDownAnalyzer(bootstrappingSemanticServices, bindingTraceContext);
|
||||
bootstrappingTDA.process(JetStandardClasses.STANDARD_CLASSES, file.getRootNamespace().getDeclarations());
|
||||
BindingContext bindingContext = bindingTraceContext;
|
||||
|
||||
this.libraryScope = bindingContext.getTopLevelScope();
|
||||
this.libraryScope = bindingTraceContext.getTopLevelScope();
|
||||
|
||||
this.byteClass = libraryScope.getClass("Byte");
|
||||
this.charClass = libraryScope.getClass("Char");
|
||||
this.shortClass = libraryScope.getClass("Short");
|
||||
this.intClass = libraryScope.getClass("Int");
|
||||
this.longClass = libraryScope.getClass("Long");
|
||||
this.floatClass = libraryScope.getClass("Float");
|
||||
this.doubleClass = libraryScope.getClass("Double");
|
||||
this.booleanClass = libraryScope.getClass("Boolean");
|
||||
this.stringClass = libraryScope.getClass("String");
|
||||
this.arrayClass = libraryScope.getClass("Array");
|
||||
this.iterableClass = libraryScope.getClass("Iterable");
|
||||
this.byteClass = (ClassDescriptor) libraryScope.getClassifier("Byte");
|
||||
this.charClass = (ClassDescriptor) libraryScope.getClassifier("Char");
|
||||
this.shortClass = (ClassDescriptor) libraryScope.getClassifier("Short");
|
||||
this.intClass = (ClassDescriptor) libraryScope.getClassifier("Int");
|
||||
this.longClass = (ClassDescriptor) libraryScope.getClassifier("Long");
|
||||
this.floatClass = (ClassDescriptor) libraryScope.getClassifier("Float");
|
||||
this.doubleClass = (ClassDescriptor) libraryScope.getClassifier("Double");
|
||||
this.booleanClass = (ClassDescriptor) libraryScope.getClassifier("Boolean");
|
||||
this.stringClass = (ClassDescriptor) libraryScope.getClassifier("String");
|
||||
this.arrayClass = (ClassDescriptor) libraryScope.getClassifier("Array");
|
||||
this.iterableClass = (ClassDescriptor) libraryScope.getClassifier("Iterable");
|
||||
|
||||
this.byteType = new JetTypeImpl(getByte());
|
||||
this.charType = new JetTypeImpl(getChar());
|
||||
|
||||
@@ -511,8 +511,11 @@ public class JetTypeInferrer {
|
||||
// Errors are reported by the parser
|
||||
if (superTypeElement instanceof JetUserType) {
|
||||
JetUserType typeElement = (JetUserType) superTypeElement;
|
||||
ClassDescriptor superclass = typeResolver.resolveClassByUserType(scope, typeElement);
|
||||
if (superclass != null) {
|
||||
|
||||
ClassifierDescriptor classifierCandidate = typeResolver.resolveClass(scope, typeElement);
|
||||
if (classifierCandidate instanceof ClassDescriptor) {
|
||||
ClassDescriptor superclass = (ClassDescriptor) classifierCandidate;
|
||||
|
||||
Collection<? extends JetType> supertypes = thisType.getConstructor().getSupertypes();
|
||||
Map<TypeConstructor, TypeProjection> substitutionContext = TypeUtils.buildSubstitutionContext(thisType);
|
||||
for (JetType declaredSupertype : supertypes) {
|
||||
|
||||
@@ -9,7 +9,7 @@ import java.util.Set;
|
||||
/**
|
||||
* @author abreslav
|
||||
*/
|
||||
public class TypeParameterDescriptor extends DeclarationDescriptorImpl {
|
||||
public class TypeParameterDescriptor extends DeclarationDescriptorImpl implements ClassifierDescriptor {
|
||||
private final Variance variance;
|
||||
private final Set<JetType> upperBounds;
|
||||
private final TypeConstructor typeConstructor;
|
||||
@@ -58,6 +58,8 @@ public class TypeParameterDescriptor extends DeclarationDescriptorImpl {
|
||||
return upperBounds;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public TypeConstructor getTypeConstructor() {
|
||||
return typeConstructor;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
class A<~T~T, ~E~E> {
|
||||
val a : `T`T
|
||||
val x : A<`T`T, `E`E>
|
||||
|
||||
class X<~X.T~T> : A<`X.T`T, `E`E> {
|
||||
val a : `X.T`T
|
||||
val b : `X.E`E
|
||||
|
||||
~X.E~class E {}
|
||||
}
|
||||
}
|
||||
@@ -74,6 +74,8 @@ public class ExpectedResolveData {
|
||||
document.replaceString(start, matcher.end(), "");
|
||||
text = document.getText();
|
||||
}
|
||||
|
||||
// System.out.println("text = " + text);
|
||||
}
|
||||
|
||||
public void checkResult(JetFile file) {
|
||||
@@ -133,7 +135,7 @@ public class ExpectedResolveData {
|
||||
|
||||
JetType actualType = bindingContext.resolveTypeReference(typeReference);
|
||||
assertNotNull("Type " + name + " not resolved for reference " + name, actualType);
|
||||
ClassDescriptor expectedClass = lib.getLibraryScope().getClass(name.substring(5));
|
||||
ClassifierDescriptor expectedClass = lib.getLibraryScope().getClassifier(name.substring(5));
|
||||
assertNotNull("Expected class not found: " + name);
|
||||
assertSame("Type resolution mismatch: ", expectedClass.getTypeConstructor(), actualType.getConstructor());
|
||||
continue;
|
||||
@@ -164,7 +166,7 @@ public class ExpectedResolveData {
|
||||
JetType expressionType = bindingContext.getExpressionType(expression);
|
||||
TypeConstructor expectedTypeConstructor;
|
||||
if (typeName.startsWith("std::")) {
|
||||
ClassDescriptor expectedClass = lib.getLibraryScope().getClass(typeName.substring(5));
|
||||
ClassifierDescriptor expectedClass = lib.getLibraryScope().getClassifier(typeName.substring(5));
|
||||
|
||||
assertNotNull("Expected class not found: " + typeName, expectedClass);
|
||||
expectedTypeConstructor = expectedClass.getTypeConstructor();
|
||||
|
||||
@@ -154,4 +154,8 @@ public class JetResolveTest extends ExtensibleResolveTestCase {
|
||||
doTest("/resolve/PrimaryConstructors.jet", true, true);
|
||||
}
|
||||
|
||||
public void testClassifiers() throws Exception {
|
||||
doTest("/resolve/Classifiers.jet", true, true);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -520,7 +520,7 @@ public class JetTypeCheckerTest extends LightDaemonAnalyzerTestCase {
|
||||
|
||||
public JetScope BASIC_SCOPE = new JetScopeAdapter(library.getLibraryScope()) {
|
||||
@Override
|
||||
public ClassDescriptor getClass(@NotNull String name) {
|
||||
public ClassifierDescriptor getClassifier(@NotNull String name) {
|
||||
if (CLASSES.isEmpty()) {
|
||||
for (String classDeclaration : CLASS_DECLARATIONS) {
|
||||
JetClass classElement = JetChangeUtil.createClass(getProject(), classDeclaration);
|
||||
@@ -532,7 +532,7 @@ public class JetTypeCheckerTest extends LightDaemonAnalyzerTestCase {
|
||||
if (classDescriptor != null) {
|
||||
return classDescriptor;
|
||||
}
|
||||
return super.getClass(name);
|
||||
return super.getClassifier(name);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
Reference in New Issue
Block a user