jet.Any: modality and constructor straightened
This commit is contained in:
@@ -16,7 +16,6 @@
|
|||||||
|
|
||||||
package org.jetbrains.jet.codegen;
|
package org.jetbrains.jet.codegen;
|
||||||
|
|
||||||
import com.intellij.openapi.util.Pair;
|
|
||||||
import com.intellij.util.containers.MultiMap;
|
import com.intellij.util.containers.MultiMap;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
@@ -25,14 +24,13 @@ import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
|
|||||||
import org.jetbrains.jet.lang.psi.*;
|
import org.jetbrains.jet.lang.psi.*;
|
||||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||||
import org.jetbrains.jet.lang.resolve.DescriptorUtils;
|
import org.jetbrains.jet.lang.resolve.DescriptorUtils;
|
||||||
import org.jetbrains.jet.lang.resolve.name.FqName;
|
|
||||||
import org.jetbrains.jet.lang.resolve.java.JvmAbi;
|
import org.jetbrains.jet.lang.resolve.java.JvmAbi;
|
||||||
import org.jetbrains.jet.lang.resolve.java.JvmClassName;
|
import org.jetbrains.jet.lang.resolve.java.JvmClassName;
|
||||||
|
import org.jetbrains.jet.lang.resolve.name.FqName;
|
||||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
||||||
import org.jetbrains.jet.lang.types.lang.JetStandardClasses;
|
import org.jetbrains.jet.lang.types.lang.JetStandardClasses;
|
||||||
|
|
||||||
import javax.annotation.PostConstruct;
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
@@ -78,6 +76,7 @@ public class ClosureAnnotator {
|
|||||||
classDescriptor = new ClassDescriptorImpl(
|
classDescriptor = new ClassDescriptorImpl(
|
||||||
funDescriptor,
|
funDescriptor,
|
||||||
Collections.<AnnotationDescriptor>emptyList(),
|
Collections.<AnnotationDescriptor>emptyList(),
|
||||||
|
Modality.FINAL,
|
||||||
Name.special("<closure>"));
|
Name.special("<closure>"));
|
||||||
recordName(classDescriptor, name);
|
recordName(classDescriptor, name);
|
||||||
classDescriptor.initialize(
|
classDescriptor.initialize(
|
||||||
@@ -102,6 +101,7 @@ public class ClosureAnnotator {
|
|||||||
ClassDescriptorImpl classDescriptor = new ClassDescriptorImpl(
|
ClassDescriptorImpl classDescriptor = new ClassDescriptorImpl(
|
||||||
scriptDescriptor,
|
scriptDescriptor,
|
||||||
Collections.<AnnotationDescriptor>emptyList(),
|
Collections.<AnnotationDescriptor>emptyList(),
|
||||||
|
Modality.FINAL,
|
||||||
Name.special("<script-" + className + ">"));
|
Name.special("<script-" + className + ">"));
|
||||||
recordName(classDescriptor, className);
|
recordName(classDescriptor, className);
|
||||||
classDescriptor.initialize(
|
classDescriptor.initialize(
|
||||||
|
|||||||
@@ -39,12 +39,15 @@ public class ClassDescriptorImpl extends DeclarationDescriptorNonRootImpl implem
|
|||||||
private Set<ConstructorDescriptor> constructors;
|
private Set<ConstructorDescriptor> constructors;
|
||||||
private ConstructorDescriptor primaryConstructor;
|
private ConstructorDescriptor primaryConstructor;
|
||||||
private ReceiverDescriptor implicitReceiver;
|
private ReceiverDescriptor implicitReceiver;
|
||||||
|
private final Modality modality;
|
||||||
|
|
||||||
public ClassDescriptorImpl(
|
public ClassDescriptorImpl(
|
||||||
@NotNull DeclarationDescriptor containingDeclaration,
|
@NotNull DeclarationDescriptor containingDeclaration,
|
||||||
@NotNull List<AnnotationDescriptor> annotations,
|
@NotNull List<AnnotationDescriptor> annotations,
|
||||||
|
@NotNull Modality modality,
|
||||||
@NotNull Name name) {
|
@NotNull Name name) {
|
||||||
super(containingDeclaration, annotations, name);
|
super(containingDeclaration, annotations, name);
|
||||||
|
this.modality = modality;
|
||||||
}
|
}
|
||||||
|
|
||||||
public final ClassDescriptorImpl initialize(boolean sealed,
|
public final ClassDescriptorImpl initialize(boolean sealed,
|
||||||
@@ -155,7 +158,7 @@ public class ClassDescriptorImpl extends DeclarationDescriptorNonRootImpl implem
|
|||||||
@Override
|
@Override
|
||||||
@NotNull
|
@NotNull
|
||||||
public Modality getModality() {
|
public Modality getModality() {
|
||||||
return Modality.FINAL;
|
return modality;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
|
|||||||
@@ -118,7 +118,7 @@ public class ErrorUtils {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final ClassDescriptorImpl ERROR_CLASS = new ClassDescriptorImpl(ERROR_MODULE, Collections.<AnnotationDescriptor>emptyList(), Name.special("<ERROR CLASS>")) {
|
private static final ClassDescriptorImpl ERROR_CLASS = new ClassDescriptorImpl(ERROR_MODULE, Collections.<AnnotationDescriptor>emptyList(), Modality.OPEN, Name.special("<ERROR CLASS>")) {
|
||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public Collection<ConstructorDescriptor> getConstructors() {
|
public Collection<ConstructorDescriptor> getConstructors() {
|
||||||
|
|||||||
@@ -70,6 +70,7 @@ public class JetStandardClasses {
|
|||||||
private static final ClassDescriptor NOTHING_CLASS = new ClassDescriptorImpl(
|
private static final ClassDescriptor NOTHING_CLASS = new ClassDescriptorImpl(
|
||||||
STANDARD_CLASSES_NAMESPACE,
|
STANDARD_CLASSES_NAMESPACE,
|
||||||
Collections.<AnnotationDescriptor>emptyList(),
|
Collections.<AnnotationDescriptor>emptyList(),
|
||||||
|
Modality.FINAL,
|
||||||
Name.identifier("Nothing")
|
Name.identifier("Nothing")
|
||||||
).initialize(
|
).initialize(
|
||||||
true,
|
true,
|
||||||
@@ -106,31 +107,41 @@ public class JetStandardClasses {
|
|||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
private static final ClassDescriptor ANY = new ClassDescriptorImpl(
|
private static final ClassDescriptor ANY;
|
||||||
STANDARD_CLASSES_NAMESPACE,
|
private static final JetType ANY_TYPE;
|
||||||
Collections.<AnnotationDescriptor>emptyList(),
|
|
||||||
Name.identifier("Any")).initialize(
|
|
||||||
false,
|
|
||||||
Collections.<TypeParameterDescriptor>emptyList(),
|
|
||||||
Collections.<JetType>emptySet(),
|
|
||||||
JetScope.EMPTY,
|
|
||||||
Collections.<ConstructorDescriptor>emptySet(),
|
|
||||||
null,
|
|
||||||
null
|
|
||||||
);
|
|
||||||
|
|
||||||
private static final JetType ANY_TYPE = new JetTypeImpl(ANY.getTypeConstructor(), new JetScopeImpl() {
|
static {
|
||||||
@NotNull
|
ClassDescriptorImpl any = new ClassDescriptorImpl(
|
||||||
@Override
|
STANDARD_CLASSES_NAMESPACE,
|
||||||
public DeclarationDescriptor getContainingDeclaration() {
|
Collections.<AnnotationDescriptor>emptyList(),
|
||||||
return STANDARD_CLASSES_NAMESPACE;
|
Modality.OPEN,
|
||||||
}
|
Name.identifier("Any")
|
||||||
|
);
|
||||||
|
ConstructorDescriptorImpl constructorDescriptor = new ConstructorDescriptorImpl(any, Collections.<AnnotationDescriptor>emptyList(), true);
|
||||||
|
constructorDescriptor.initialize(Collections.<TypeParameterDescriptor>emptyList(), Collections.<ValueParameterDescriptor>emptyList(), Visibilities.PUBLIC);
|
||||||
|
ANY = any.initialize(
|
||||||
|
false,
|
||||||
|
Collections.<TypeParameterDescriptor>emptyList(),
|
||||||
|
Collections.<JetType>emptySet(),
|
||||||
|
JetScope.EMPTY,
|
||||||
|
Collections.<ConstructorDescriptor>singleton(constructorDescriptor),
|
||||||
|
null,
|
||||||
|
null
|
||||||
|
);
|
||||||
|
ANY_TYPE = new JetTypeImpl(ANY.getTypeConstructor(), new JetScopeImpl() {
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public DeclarationDescriptor getContainingDeclaration() {
|
||||||
|
return STANDARD_CLASSES_NAMESPACE;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "Scope for Any";
|
return "Scope for Any";
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
constructorDescriptor.setReturnType(ANY_TYPE);
|
||||||
|
}
|
||||||
private static final JetType NULLABLE_ANY_TYPE = new JetTypeImpl(ANY_TYPE.getAnnotations(), ANY_TYPE.getConstructor(), true, ANY_TYPE.getArguments(), ANY_TYPE.getMemberScope());
|
private static final JetType NULLABLE_ANY_TYPE = new JetTypeImpl(ANY_TYPE.getAnnotations(), ANY_TYPE.getConstructor(), true, ANY_TYPE.getArguments(), ANY_TYPE.getMemberScope());
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
@@ -154,6 +165,7 @@ public class JetStandardClasses {
|
|||||||
ClassDescriptorImpl classDescriptor = new ClassDescriptorImpl(
|
ClassDescriptorImpl classDescriptor = new ClassDescriptorImpl(
|
||||||
STANDARD_CLASSES_NAMESPACE,
|
STANDARD_CLASSES_NAMESPACE,
|
||||||
Collections.<AnnotationDescriptor>emptyList(),
|
Collections.<AnnotationDescriptor>emptyList(),
|
||||||
|
Modality.FINAL,
|
||||||
Name.identifier("Tuple" + i));
|
Name.identifier("Tuple" + i));
|
||||||
WritableScopeImpl writableScope = new WritableScopeImpl(JetScope.EMPTY, classDescriptor, RedeclarationHandler.THROW_EXCEPTION, "tuples");
|
WritableScopeImpl writableScope = new WritableScopeImpl(JetScope.EMPTY, classDescriptor, RedeclarationHandler.THROW_EXCEPTION, "tuples");
|
||||||
for (int j = 0; j < i; j++) {
|
for (int j = 0; j < i; j++) {
|
||||||
@@ -196,6 +208,7 @@ public class JetStandardClasses {
|
|||||||
ClassDescriptorImpl function = new ClassDescriptorImpl(
|
ClassDescriptorImpl function = new ClassDescriptorImpl(
|
||||||
STANDARD_CLASSES_NAMESPACE,
|
STANDARD_CLASSES_NAMESPACE,
|
||||||
Collections.<AnnotationDescriptor>emptyList(),
|
Collections.<AnnotationDescriptor>emptyList(),
|
||||||
|
Modality.OPEN,
|
||||||
Name.identifier("Function" + i));
|
Name.identifier("Function" + i));
|
||||||
|
|
||||||
SimpleFunctionDescriptorImpl invoke = new SimpleFunctionDescriptorImpl(function, Collections.<AnnotationDescriptor>emptyList(), Name.identifier("invoke"), CallableMemberDescriptor.Kind.DECLARATION);
|
SimpleFunctionDescriptorImpl invoke = new SimpleFunctionDescriptorImpl(function, Collections.<AnnotationDescriptor>emptyList(), Name.identifier("invoke"), CallableMemberDescriptor.Kind.DECLARATION);
|
||||||
@@ -211,6 +224,7 @@ public class JetStandardClasses {
|
|||||||
ClassDescriptorImpl receiverFunction = new ClassDescriptorImpl(
|
ClassDescriptorImpl receiverFunction = new ClassDescriptorImpl(
|
||||||
STANDARD_CLASSES_NAMESPACE,
|
STANDARD_CLASSES_NAMESPACE,
|
||||||
Collections.<AnnotationDescriptor>emptyList(),
|
Collections.<AnnotationDescriptor>emptyList(),
|
||||||
|
Modality.OPEN,
|
||||||
Name.identifier("ExtensionFunction" + i));
|
Name.identifier("ExtensionFunction" + i));
|
||||||
SimpleFunctionDescriptorImpl invokeWithReceiver = new SimpleFunctionDescriptorImpl(receiverFunction, Collections.<AnnotationDescriptor>emptyList(), Name.identifier("invoke"), CallableMemberDescriptor.Kind.DECLARATION);
|
SimpleFunctionDescriptorImpl invokeWithReceiver = new SimpleFunctionDescriptorImpl(receiverFunction, Collections.<AnnotationDescriptor>emptyList(), Name.identifier("invoke"), CallableMemberDescriptor.Kind.DECLARATION);
|
||||||
WritableScope scopeForInvokeWithReceiver = createScopeForInvokeFunction(receiverFunction, invokeWithReceiver);
|
WritableScope scopeForInvokeWithReceiver = createScopeForInvokeFunction(receiverFunction, invokeWithReceiver);
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
//KT-1249 IllegalStateException invoking function property
|
//KT-1249 IllegalStateException invoking function property
|
||||||
class TestClass(val body : () -> Unit) : Any {
|
class TestClass(val body : () -> Unit) : Any() {
|
||||||
fun run() {
|
fun run() {
|
||||||
body()
|
body()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -689,6 +689,7 @@ public class JetTypeCheckerTest extends JetLiteFixture {
|
|||||||
final ClassDescriptorImpl classDescriptor = new ClassDescriptorImpl(
|
final ClassDescriptorImpl classDescriptor = new ClassDescriptorImpl(
|
||||||
scope.getContainingDeclaration(),
|
scope.getContainingDeclaration(),
|
||||||
Collections.<AnnotationDescriptor>emptyList(),
|
Collections.<AnnotationDescriptor>emptyList(),
|
||||||
|
Modality.FINAL,
|
||||||
JetPsiUtil.safeName(classElement.getName()));
|
JetPsiUtil.safeName(classElement.getName()));
|
||||||
|
|
||||||
BindingTrace trace = JetTestUtils.DUMMY_TRACE;
|
BindingTrace trace = JetTestUtils.DUMMY_TRACE;
|
||||||
|
|||||||
Reference in New Issue
Block a user