private void processPrimaryConstructor(MutableClassDescriptor classDescriptor, JetClass klass) { if (classDescriptor.getKind() == ClassKind.TRAIT) { JetParameterList primaryConstructorParameterList = klass.getPrimaryConstructorParameterList(); if (primaryConstructorParameterList != null) { context.getTrace().report(CONSTRUCTOR_IN_TRAIT.on(primaryConstructorParameterList)); } if (!klass.hasPrimaryConstructor()) return; } // TODO : not all the parameters are real properties JetScope memberScope = classDescriptor.getScopeForSupertypeResolution(); ConstructorDescriptor constructorDescriptor = context .getDescriptorResolver() .resolvePrimaryConstructorDescriptor(memberScope, classDescriptor, klass); for (JetParameter parameter : klass.getPrimaryConstructorParameters()) { if (parameter.getValOrVarNode() != null) { PropertyDescriptor propertyDescriptor = context .getDescriptorResolver() .resolvePrimaryConstructorParameterToAProperty( classDescriptor, memberScope, parameter); classDescriptor.addPropertyDescriptor(propertyDescriptor); context.getPrimaryConstructorParameterProperties().add(propertyDescriptor); } } if (constructorDescriptor != null) { classDescriptor.setPrimaryConstructor(constructorDescriptor, context.getTrace()); } }
private void createClassObjectForEnumClass( @NotNull MutableClassDescriptor mutableClassDescriptor) { if (mutableClassDescriptor.getKind() == ClassKind.ENUM_CLASS) { MutableClassDescriptor classObject = createSyntheticClassObject(mutableClassDescriptor); mutableClassDescriptor.getBuilder().setClassObjectDescriptor(classObject); classObject .getBuilder() .addFunctionDescriptor( DescriptorResolver.createEnumClassObjectValuesMethod(classObject, trace)); classObject .getBuilder() .addFunctionDescriptor( DescriptorResolver.createEnumClassObjectValueOfMethod(classObject, trace)); } }
private void processSecondaryConstructor( MutableClassDescriptor classDescriptor, JetSecondaryConstructor constructor) { if (classDescriptor.getKind() == ClassKind.TRAIT) { // context.getTrace().getErrorHandler().genericError(constructor.getNameNode(), "A // trait may not have a constructor"); context.getTrace().report(CONSTRUCTOR_IN_TRAIT.on(constructor.getNameNode())); } ConstructorDescriptor constructorDescriptor = context .getDescriptorResolver() .resolveSecondaryConstructorDescriptor( classDescriptor.getScopeForMemberResolution(), classDescriptor, constructor); classDescriptor.addConstructor(constructorDescriptor, context.getTrace()); context.getConstructors().put(constructor, constructorDescriptor); context.getDeclaringScopes().put(constructor, classDescriptor.getScopeForMemberLookup()); }
private void createTypeConstructors(@NotNull TopDownAnalysisContext c) { for (Map.Entry<JetClassOrObject, ClassDescriptorWithResolutionScopes> entry : c.getClasses().entrySet()) { JetClassOrObject classOrObject = entry.getKey(); MutableClassDescriptor descriptor = (MutableClassDescriptor) entry.getValue(); if (classOrObject instanceof JetClass) { descriptorResolver.resolveMutableClassDescriptor( (JetClass) classOrObject, descriptor, trace); } else if (classOrObject instanceof JetObjectDeclaration) { descriptor.setModality(Modality.FINAL); descriptor.setVisibility( resolveVisibilityFromModifiers(classOrObject, getDefaultClassVisibility(descriptor))); descriptor.setTypeParameterDescriptors(Collections.<TypeParameterDescriptor>emptyList()); } descriptor.createTypeConstructor(); ClassKind kind = descriptor.getKind(); if (kind == ClassKind.ENUM_ENTRY || kind == ClassKind.OBJECT || kind == ClassKind.ENUM_CLASS) { MutableClassDescriptorLite classObject = descriptor.getClassObjectDescriptor(); assert classObject != null : "Enum entries and named objects should have class objects: " + classOrObject.getText(); JetType supertype; if (kind == ClassKind.ENUM_CLASS) { supertype = KotlinBuiltIns.getInstance().getAnyType(); } else { // This is a clever hack: each enum entry and object declaration (i.e. singleton) has a // synthetic class object. // We make this class object inherit from the singleton here, thus allowing to use the // singleton's class object where // the instance of the singleton is applicable. Effectively all members of the singleton // would be present in its class // object as fake overrides, so you can access them via standard class object notation: // ObjectName.memberName() supertype = descriptor.getDefaultType(); } classObject.setSupertypes(Collections.singleton(supertype)); classObject.createTypeConstructor(); } } }