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