A private constructor added to Nothing

This commit is contained in:
Andrey Breslav
2012-06-26 19:50:47 +02:00
parent 1361c70f68
commit 06aa1478e6
@@ -52,52 +52,52 @@ public class JetStandardClasses {
static { static {
FAKE_STANDARD_CLASSES_MODULE.setRootNamespace(STANDARD_CLASSES_FAKE_ROOT_NS); FAKE_STANDARD_CLASSES_MODULE.setRootNamespace(STANDARD_CLASSES_FAKE_ROOT_NS);
//WritableScopeImpl writableScope =
// new WritableScopeImpl(JetScope.EMPTY, FAKE_STANDARD_CLASSES_MODULE, RedeclarationHandler.DO_NOTHING);
//STANDARD_CLASSES_FAKE_ROOT_NS.initialize(writableScope);
//STANDARD_CLASSES_FAKE_ROOT_NS.getMemberScope().changeLockLevel(WritableScope.LockLevel.BOTH);
} }
public static NamespaceDescriptorImpl STANDARD_CLASSES_NAMESPACE = new NamespaceDescriptorImpl( public static NamespaceDescriptorImpl STANDARD_CLASSES_NAMESPACE = new NamespaceDescriptorImpl(
STANDARD_CLASSES_FAKE_ROOT_NS, Collections.<AnnotationDescriptor>emptyList(), Name.identifier("jet")); STANDARD_CLASSES_FAKE_ROOT_NS, Collections.<AnnotationDescriptor>emptyList(), Name.identifier("jet"));
//
//static {
// STANDARD_CLASSES_FAKE_ROOT_NS.getMemberScope().addNamespace(STANDARD_CLASSES_NAMESPACE);
//}
public static final FqName STANDARD_CLASSES_FQNAME = DescriptorUtils.getFQName(STANDARD_CLASSES_NAMESPACE).toSafe(); public static final FqName STANDARD_CLASSES_FQNAME = DescriptorUtils.getFQName(STANDARD_CLASSES_NAMESPACE).toSafe();
private static final ClassDescriptor NOTHING_CLASS = new ClassDescriptorImpl( private static final ClassDescriptor NOTHING_CLASS;
STANDARD_CLASSES_NAMESPACE, private static final JetType NOTHING_TYPE;
Collections.<AnnotationDescriptor>emptyList(), static {
Modality.FINAL, ClassDescriptorImpl nothing = new ClassDescriptorImpl(
Name.identifier("Nothing") STANDARD_CLASSES_NAMESPACE,
).initialize( Collections.<AnnotationDescriptor>emptyList(),
true, Modality.FINAL,
Collections.<TypeParameterDescriptor>emptyList(), Name.identifier("Nothing")
new AbstractCollection<JetType>() { );
@Override ConstructorDescriptorImpl constructorDescriptor = new ConstructorDescriptorImpl(nothing, Collections.<AnnotationDescriptor>emptyList(), true);
public boolean contains(Object o) { constructorDescriptor.initialize(Collections.<TypeParameterDescriptor>emptyList(), Collections.<ValueParameterDescriptor>emptyList(), Visibilities.PRIVATE);
return o instanceof JetType; NOTHING_CLASS = nothing.initialize(
} true,
Collections.<TypeParameterDescriptor>emptyList(),
new AbstractCollection<JetType>() {
@Override
public boolean contains(Object o) {
return o instanceof JetType;
}
@Override @Override
public Iterator<JetType> iterator() { public Iterator<JetType> iterator() {
throw new UnsupportedOperationException("Don't enumerate supertypes of Nothing"); throw new UnsupportedOperationException("Don't enumerate supertypes of Nothing");
} }
@Override @Override
public int size() { public int size() {
throw new UnsupportedOperationException("Supertypes of Nothing do not constitute a valid collection"); throw new UnsupportedOperationException("Supertypes of Nothing do not constitute a valid collection");
} }
}, },
JetScope.EMPTY, JetScope.EMPTY,
Collections.<ConstructorDescriptor>emptySet(), Collections.<ConstructorDescriptor>singleton(constructorDescriptor),
null, null,
null null
); );
NOTHING_TYPE = new JetTypeImpl(getNothing());
constructorDescriptor.setReturnType(NOTHING_TYPE);
}
private static final JetType NOTHING_TYPE = new JetTypeImpl(getNothing());
private static final JetType NULLABLE_NOTHING_TYPE = new JetTypeImpl( private static final JetType NULLABLE_NOTHING_TYPE = new JetTypeImpl(
Collections.<AnnotationDescriptor>emptyList(), Collections.<AnnotationDescriptor>emptyList(),
getNothing().getTypeConstructor(), getNothing().getTypeConstructor(),
@@ -243,12 +243,13 @@ public class JetStandardClasses {
RECEIVER_FUNCTION[i] = receiverFunction.initialize( RECEIVER_FUNCTION[i] = receiverFunction.initialize(
false, false,
parameters, parameters,
Collections.singleton(getAnyType()), scopeForInvokeWithReceiver, Collections.<ConstructorDescriptor>singleton(constructorDescriptorForReceiverFunction), null); Collections.singleton(getAnyType()), scopeForInvokeWithReceiver, Collections.<ConstructorDescriptor>singleton(
constructorDescriptorForReceiverFunction), null);
RECEIVER_FUNCTION_TYPE_CONSTRUCTORS.add(RECEIVER_FUNCTION[i].getTypeConstructor()); RECEIVER_FUNCTION_TYPE_CONSTRUCTORS.add(RECEIVER_FUNCTION[i].getTypeConstructor());
FunctionDescriptorUtil.initializeFromFunctionType(invokeWithReceiver, receiverFunction.getDefaultType(), new ClassReceiver(RECEIVER_FUNCTION[i]), Modality.ABSTRACT, Visibilities.PUBLIC); FunctionDescriptorUtil.initializeFromFunctionType(invokeWithReceiver, receiverFunction.getDefaultType(), new ClassReceiver(RECEIVER_FUNCTION[i]), Modality.ABSTRACT, Visibilities.PUBLIC);
constructorDescriptorForReceiverFunction.initialize(receiverFunction.getTypeConstructor().getParameters(), constructorDescriptorForReceiverFunction.initialize(receiverFunction.getTypeConstructor().getParameters(),
Collections.<ValueParameterDescriptor>emptyList(), Visibilities.PUBLIC); Collections.<ValueParameterDescriptor>emptyList(), Visibilities.PUBLIC);
constructorDescriptorForReceiverFunction.setReturnType(receiverFunction.getDefaultType()); constructorDescriptorForReceiverFunction.setReturnType(receiverFunction.getDefaultType());
} }
} }