Create DescriptorFactory utility class

Will contain utilities needed to create different common descriptors, such as
default getters/setters, enum values/valueOf methods, etc.
This commit is contained in:
Alexander Udalov
2013-08-21 20:32:08 +04:00
parent 6eeee31381
commit 6ca71349f8
15 changed files with 224 additions and 199 deletions
@@ -33,7 +33,7 @@ import org.jetbrains.jet.codegen.state.JetTypeMapper;
import org.jetbrains.jet.lang.descriptors.*;
import org.jetbrains.jet.lang.psi.*;
import org.jetbrains.jet.lang.resolve.BindingContext;
import org.jetbrains.jet.lang.resolve.DescriptorResolver;
import org.jetbrains.jet.lang.resolve.DescriptorFactory;
import org.jetbrains.jet.lang.resolve.DescriptorUtils;
import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCall;
import org.jetbrains.jet.lang.resolve.constants.CompileTimeConstant;
@@ -231,7 +231,7 @@ public class PropertyCodegen extends GenerationStateAware {
//if (!defaultGetter || isExternallyAccessible(propertyDescriptor)) {
JvmMethodSignature signature = typeMapper.mapGetterSignature(propertyDescriptor, kind);
PropertyGetterDescriptor getterDescriptor = propertyDescriptor.getGetter();
getterDescriptor = getterDescriptor != null ? getterDescriptor : DescriptorResolver.createDefaultGetter(propertyDescriptor);
getterDescriptor = getterDescriptor != null ? getterDescriptor : DescriptorFactory.createDefaultGetter(propertyDescriptor);
if (kind != OwnerKind.TRAIT_IMPL || !defaultGetter) {
FunctionGenerationStrategy strategy;
@@ -261,7 +261,8 @@ public class PropertyCodegen extends GenerationStateAware {
if (/*!defaultSetter || isExternallyAccessible(propertyDescriptor) &&*/ propertyDescriptor.isVar()) {
JvmMethodSignature signature = typeMapper.mapSetterSignature(propertyDescriptor, kind);
PropertySetterDescriptor setterDescriptor = propertyDescriptor.getSetter();
setterDescriptor = setterDescriptor != null ? setterDescriptor : DescriptorResolver.createDefaultSetter(propertyDescriptor);
setterDescriptor =
setterDescriptor != null ? setterDescriptor : DescriptorFactory.createDefaultSetter(propertyDescriptor);
if (kind != OwnerKind.TRAIT_IMPL || !defaultSetter) {
FunctionGenerationStrategy strategy;
@@ -23,7 +23,7 @@ import org.jetbrains.jet.descriptors.serialization.descriptors.DeserializedTypeP
import org.jetbrains.jet.lang.descriptors.*;
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
import org.jetbrains.jet.lang.descriptors.impl.*;
import org.jetbrains.jet.lang.resolve.DescriptorResolver;
import org.jetbrains.jet.lang.resolve.DescriptorFactory;
import org.jetbrains.jet.lang.resolve.DescriptorUtils;
import org.jetbrains.jet.lang.resolve.lazy.storage.StorageManager;
import org.jetbrains.jet.lang.resolve.name.FqNameUnsafe;
@@ -162,7 +162,7 @@ public class DescriptorDeserializer {
);
}
else {
getter = DescriptorResolver.createDefaultGetter(property);
getter = DescriptorFactory.createDefaultGetter(property);
}
getter.initialize(property.getReturnType());
}
@@ -182,7 +182,7 @@ public class DescriptorDeserializer {
property.getReturnType(), false, null));
}
else {
setter = DescriptorResolver.createDefaultSetter(property);
setter = DescriptorFactory.createDefaultSetter(property);
}
}
@@ -24,7 +24,7 @@ import org.jetbrains.jet.descriptors.serialization.*;
import org.jetbrains.jet.lang.descriptors.*;
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
import org.jetbrains.jet.lang.descriptors.impl.*;
import org.jetbrains.jet.lang.resolve.DescriptorResolver;
import org.jetbrains.jet.lang.resolve.DescriptorFactory;
import org.jetbrains.jet.lang.resolve.OverridingUtil;
import org.jetbrains.jet.lang.resolve.TraceUtil;
import org.jetbrains.jet.lang.resolve.lazy.storage.MemoizedFunctionToNullable;
@@ -285,14 +285,16 @@ public class DeserializedClassDescriptor extends ClassDescriptorBase implements
classObject.setTypeParameterDescriptors(Collections.<TypeParameterDescriptor>emptyList());
classObject.createTypeConstructor();
ConstructorDescriptorImpl primaryConstructor = DescriptorResolver.createPrimaryConstructorForObject(classObject);
ConstructorDescriptorImpl primaryConstructor = DescriptorFactory.createPrimaryConstructorForObject(classObject);
primaryConstructor.setReturnType(classObject.getDefaultType());
classObject.setPrimaryConstructor(primaryConstructor);
JetType defaultType = getDefaultType();
JetType defaultTypeArray = KotlinBuiltIns.getInstance().getArrayType(defaultType);
classObject.getBuilder().addFunctionDescriptor(DescriptorResolver.createEnumClassObjectValuesMethod(classObject, defaultTypeArray));
classObject.getBuilder().addFunctionDescriptor(DescriptorResolver.createEnumClassObjectValueOfMethod(classObject, defaultType));
classObject.getBuilder().addFunctionDescriptor(
DescriptorFactory.createEnumClassObjectValuesMethod(classObject, defaultTypeArray));
classObject.getBuilder().addFunctionDescriptor(
DescriptorFactory.createEnumClassObjectValueOfMethod(classObject, defaultType));
return classObject;
}
@@ -304,7 +306,7 @@ public class DeserializedClassDescriptor extends ClassDescriptorBase implements
property.setType(getDefaultType(), Collections.<TypeParameterDescriptor>emptyList(),
enumClassObject.getThisAsReceiverParameter(), NO_RECEIVER_PARAMETER);
PropertyGetterDescriptorImpl getter = DescriptorResolver.createDefaultGetter(property);
PropertyGetterDescriptorImpl getter = DescriptorFactory.createDefaultGetter(property);
getter.initialize(property.getReturnType());
property.initialize(getter, null);
@@ -22,7 +22,7 @@ import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
import org.jetbrains.jet.lang.descriptors.impl.*;
import org.jetbrains.jet.lang.psi.*;
import org.jetbrains.jet.lang.resolve.BindingContext;
import org.jetbrains.jet.lang.resolve.DescriptorResolver;
import org.jetbrains.jet.lang.resolve.DescriptorFactory;
import org.jetbrains.jet.lang.resolve.ScriptNameUtil;
import org.jetbrains.jet.lang.resolve.name.FqName;
import org.jetbrains.jet.lang.resolve.name.Name;
@@ -120,15 +120,14 @@ public class ScriptDescriptor extends DeclarationDescriptorNonRootImpl {
public static void initializeWithDefaultGetterSetter(PropertyDescriptorImpl propertyDescriptor) {
PropertyGetterDescriptorImpl getter = propertyDescriptor.getGetter();
if(getter == null) {
getter = propertyDescriptor.getVisibility() != Visibilities.PRIVATE ? DescriptorResolver.createDefaultGetter(propertyDescriptor) : null;
if(getter != null)
getter.initialize(propertyDescriptor.getType());
if (getter == null && propertyDescriptor.getVisibility() != Visibilities.PRIVATE) {
getter = DescriptorFactory.createDefaultGetter(propertyDescriptor);
getter.initialize(propertyDescriptor.getType());
}
PropertySetterDescriptor setter = propertyDescriptor.getSetter();
if(setter == null) {
setter = propertyDescriptor.isVar() ? DescriptorResolver.createDefaultSetter(propertyDescriptor) : null;
if (setter == null && propertyDescriptor.isVar()) {
setter = DescriptorFactory.createDefaultSetter(propertyDescriptor);
}
propertyDescriptor.initialize(getter, setter);
}
@@ -20,7 +20,7 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.descriptors.*;
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
import org.jetbrains.jet.lang.resolve.DescriptorResolver;
import org.jetbrains.jet.lang.resolve.DescriptorFactory;
import org.jetbrains.jet.lang.resolve.name.Name;
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
import org.jetbrains.jet.lang.resolve.scopes.SubstitutingScope;
@@ -172,7 +172,7 @@ public class ClassDescriptorImpl extends DeclarationDescriptorNonRootImpl implem
@Override
public ReceiverParameterDescriptor getThisAsReceiverParameter() {
if (thisAsReceiverParameter == null) {
thisAsReceiverParameter = DescriptorResolver.createLazyReceiverParameterDescriptor(this);
thisAsReceiverParameter = DescriptorFactory.createLazyReceiverParameterDescriptor(this);
}
return thisAsReceiverParameter;
}
@@ -22,7 +22,7 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.descriptors.*;
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
import org.jetbrains.jet.lang.resolve.DescriptorResolver;
import org.jetbrains.jet.lang.resolve.DescriptorFactory;
import org.jetbrains.jet.lang.resolve.OverridingUtil;
import org.jetbrains.jet.lang.resolve.name.Name;
import org.jetbrains.jet.lang.types.DescriptorSubstitutor;
@@ -81,7 +81,7 @@ public abstract class FunctionDescriptorImpl extends DeclarationDescriptorNonRoo
this.unsubstitutedReturnType = unsubstitutedReturnType;
this.modality = modality;
this.visibility = visibility;
this.receiverParameter = DescriptorResolver.resolveReceiverParameterFor(this, receiverParameterType);
this.receiverParameter = DescriptorFactory.createReceiverParameterForCallable(this, receiverParameterType);
this.expectedThisObject = expectedThisObject;
for (int i = 0; i < typeParameters.size(); ++i) {
@@ -21,7 +21,7 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.descriptors.*;
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
import org.jetbrains.jet.lang.resolve.DescriptorResolver;
import org.jetbrains.jet.lang.resolve.DescriptorFactory;
import org.jetbrains.jet.lang.resolve.name.Name;
import org.jetbrains.jet.lang.resolve.scopes.InnerClassesScopeWrapper;
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
@@ -217,7 +217,7 @@ public abstract class MutableClassDescriptorLite extends ClassDescriptorBase {
@Override
public ReceiverParameterDescriptor getThisAsReceiverParameter() {
if (implicitReceiver == null) {
implicitReceiver = DescriptorResolver.createLazyReceiverParameterDescriptor(this);
implicitReceiver = DescriptorFactory.createLazyReceiverParameterDescriptor(this);
}
return implicitReceiver;
}
@@ -22,7 +22,7 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.descriptors.*;
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
import org.jetbrains.jet.lang.resolve.DescriptorResolver;
import org.jetbrains.jet.lang.resolve.DescriptorFactory;
import org.jetbrains.jet.lang.resolve.DescriptorUtils;
import org.jetbrains.jet.lang.resolve.OverridingUtil;
import org.jetbrains.jet.lang.resolve.name.Name;
@@ -102,7 +102,7 @@ public class PropertyDescriptorImpl extends VariableDescriptorImpl implements Pr
@Nullable ReceiverParameterDescriptor expectedThisObject,
@Nullable JetType receiverType
) {
ReceiverParameterDescriptor receiverParameter = DescriptorResolver.resolveReceiverParameterFor(this, receiverType);
ReceiverParameterDescriptor receiverParameter = DescriptorFactory.createReceiverParameterForCallable(this, receiverType);
setType(outType, typeParameters, expectedThisObject, receiverParameter);
}
@@ -0,0 +1,161 @@
/*
* Copyright 2010-2013 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.jet.lang.resolve;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.descriptors.*;
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
import org.jetbrains.jet.lang.descriptors.impl.*;
import org.jetbrains.jet.lang.resolve.name.Name;
import org.jetbrains.jet.lang.resolve.scopes.receivers.ClassReceiver;
import org.jetbrains.jet.lang.resolve.scopes.receivers.ExtensionReceiver;
import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverValue;
import org.jetbrains.jet.lang.types.JetType;
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
import java.util.Collections;
import static org.jetbrains.jet.lang.descriptors.ReceiverParameterDescriptor.NO_RECEIVER_PARAMETER;
import static org.jetbrains.jet.lang.resolve.DescriptorUtils.getDefaultConstructorVisibility;
public class DescriptorFactory {
public static final Name VALUE_OF_METHOD_NAME = Name.identifier("valueOf");
public static final Name VALUES_METHOD_NAME = Name.identifier("values");
private DescriptorFactory() {
}
@NotNull
public static PropertySetterDescriptorImpl createDefaultSetter(@NotNull PropertyDescriptor propertyDescriptor) {
return createSetter(propertyDescriptor, true);
}
@NotNull
public static PropertySetterDescriptorImpl createSetter(@NotNull PropertyDescriptor propertyDescriptor, boolean isDefault) {
PropertySetterDescriptorImpl setterDescriptor = new PropertySetterDescriptorImpl(
propertyDescriptor, Collections.<AnnotationDescriptor>emptyList(), propertyDescriptor.getModality(),
propertyDescriptor.getVisibility(),
!isDefault, isDefault, CallableMemberDescriptor.Kind.DECLARATION);
setterDescriptor.initializeDefault();
return setterDescriptor;
}
@NotNull
public static PropertyGetterDescriptorImpl createDefaultGetter(@NotNull PropertyDescriptor propertyDescriptor) {
return createGetter(propertyDescriptor, true);
}
@NotNull
public static PropertyGetterDescriptorImpl createGetter(@NotNull PropertyDescriptor propertyDescriptor, boolean isDefault) {
return new PropertyGetterDescriptorImpl(
propertyDescriptor, Collections.<AnnotationDescriptor>emptyList(), propertyDescriptor.getModality(),
propertyDescriptor.getVisibility(),
!isDefault, isDefault, CallableMemberDescriptor.Kind.DECLARATION);
}
@NotNull
public static ConstructorDescriptorImpl createPrimaryConstructorForObject(@NotNull ClassDescriptor containingClass) {
ConstructorDescriptorImpl constructorDescriptor =
new ConstructorDescriptorImpl(containingClass, Collections.<AnnotationDescriptor>emptyList(), true);
constructorDescriptor.initialize(Collections.<TypeParameterDescriptor>emptyList(),
Collections.<ValueParameterDescriptor>emptyList(),
getDefaultConstructorVisibility(containingClass));
return constructorDescriptor;
}
@NotNull
public static SimpleFunctionDescriptor createEnumClassObjectValuesMethod(
@NotNull ClassDescriptor classObject,
@NotNull JetType returnType
) {
SimpleFunctionDescriptorImpl values =
new SimpleFunctionDescriptorImpl(classObject, Collections.<AnnotationDescriptor>emptyList(), VALUES_METHOD_NAME,
CallableMemberDescriptor.Kind.DECLARATION);
return values.initialize(null, classObject.getThisAsReceiverParameter(), Collections.<TypeParameterDescriptor>emptyList(),
Collections.<ValueParameterDescriptor>emptyList(),
returnType, Modality.FINAL,
Visibilities.PUBLIC, false);
}
@NotNull
public static SimpleFunctionDescriptor createEnumClassObjectValueOfMethod(
@NotNull ClassDescriptor classObject,
@NotNull JetType returnType
) {
SimpleFunctionDescriptorImpl values =
new SimpleFunctionDescriptorImpl(classObject, Collections.<AnnotationDescriptor>emptyList(), VALUE_OF_METHOD_NAME,
CallableMemberDescriptor.Kind.DECLARATION);
ValueParameterDescriptor parameterDescriptor = new ValueParameterDescriptorImpl(
values,
0,
Collections.<AnnotationDescriptor>emptyList(),
Name.identifier("value"),
KotlinBuiltIns.getInstance().getStringType(),
false,
null);
return values.initialize(null, classObject.getThisAsReceiverParameter(),
Collections.<TypeParameterDescriptor>emptyList(),
Collections.singletonList(parameterDescriptor),
returnType, Modality.FINAL,
Visibilities.PUBLIC, false);
}
@Nullable
public static ReceiverParameterDescriptor createReceiverParameterForCallable(
@NotNull CallableDescriptor owner,
@Nullable JetType receiverParameterType
) {
return receiverParameterType == null
? NO_RECEIVER_PARAMETER
: new ReceiverParameterDescriptorImpl(owner, receiverParameterType, new ExtensionReceiver(owner, receiverParameterType));
}
@NotNull
public static ReceiverParameterDescriptor createLazyReceiverParameterDescriptor(@NotNull final ClassDescriptor classDescriptor) {
return new AbstractReceiverParameterDescriptor() {
private ClassReceiver value;
@NotNull
@Override
public JetType getType() {
// This must be lazy, thus the inner class
return classDescriptor.getDefaultType();
}
@NotNull
@Override
public ReceiverValue getValue() {
if (value == null) {
value = new ClassReceiver(classDescriptor);
}
return value;
}
@NotNull
@Override
public DeclarationDescriptor getContainingDeclaration() {
return classDescriptor;
}
@Override
public String toString() {
return "class " + classDescriptor.getName() + "::this";
}
};
}
}
@@ -35,9 +35,6 @@ import org.jetbrains.jet.lang.resolve.scopes.JetScope;
import org.jetbrains.jet.lang.resolve.scopes.JetScopeUtils;
import org.jetbrains.jet.lang.resolve.scopes.WritableScope;
import org.jetbrains.jet.lang.resolve.scopes.WritableScopeImpl;
import org.jetbrains.jet.lang.resolve.scopes.receivers.ClassReceiver;
import org.jetbrains.jet.lang.resolve.scopes.receivers.ExtensionReceiver;
import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverValue;
import org.jetbrains.jet.lang.types.*;
import org.jetbrains.jet.lang.types.checker.JetTypeChecker;
import org.jetbrains.jet.lang.types.expressions.DelegatedPropertyUtils;
@@ -59,8 +56,6 @@ import static org.jetbrains.jet.lang.resolve.ModifiersChecker.*;
import static org.jetbrains.jet.lexer.JetTokens.OVERRIDE_KEYWORD;
public class DescriptorResolver {
public static final Name VALUE_OF_METHOD_NAME = Name.identifier("valueOf");
public static final Name VALUES_METHOD_NAME = Name.identifier("values");
public static final Name COPY_METHOD_NAME = Name.identifier("copy");
public static final String COMPONENT_FUNCTION_NAME_PREFIX = "component";
@@ -71,12 +66,6 @@ public class DescriptorResolver {
@NotNull
private ExpressionTypingServices expressionTypingServices;
public static ReceiverParameterDescriptor resolveReceiverParameterFor(@NotNull CallableDescriptor owner, @Nullable JetType receiverParameterType) {
return receiverParameterType == null
? NO_RECEIVER_PARAMETER
: new ReceiverParameterDescriptorImpl(owner, receiverParameterType, new ExtensionReceiver(owner, receiverParameterType));
}
@Inject
public void setTypeResolver(@NotNull TypeResolver typeResolver) {
this.typeResolver = typeResolver;
@@ -595,23 +584,13 @@ public class DescriptorResolver {
@NotNull ClassDescriptor classDescriptor,
@NotNull BindingTrace trace
) {
ConstructorDescriptorImpl constructorDescriptor = createPrimaryConstructorForObject(classDescriptor);
ConstructorDescriptorImpl constructorDescriptor = DescriptorFactory.createPrimaryConstructorForObject(classDescriptor);
if (object != null) {
trace.record(CONSTRUCTOR, object, constructorDescriptor);
}
return constructorDescriptor;
}
@NotNull
public static ConstructorDescriptorImpl createPrimaryConstructorForObject(@NotNull ClassDescriptor containingClass) {
ConstructorDescriptorImpl constructorDescriptor =
new ConstructorDescriptorImpl(containingClass, Collections.<AnnotationDescriptor>emptyList(), true);
constructorDescriptor.initialize(Collections.<TypeParameterDescriptor>emptyList(),
Collections.<ValueParameterDescriptor>emptyList(),
getDefaultConstructorVisibility(containingClass));
return constructorDescriptor;
}
static final class UpperBoundCheckerTask {
JetTypeReference upperBound;
JetType upperBoundType;
@@ -994,7 +973,8 @@ public class DescriptorResolver {
}
}
ReceiverParameterDescriptor receiverDescriptor = resolveReceiverParameterFor(propertyDescriptor, receiverType);
ReceiverParameterDescriptor receiverDescriptor = DescriptorFactory.createReceiverParameterForCallable(propertyDescriptor,
receiverType);
JetScope propertyScope = getPropertyDeclarationInnerScope(propertyDescriptor, scope, typeParameterDescriptors,
NO_RECEIVER_PARAMETER, trace);
@@ -1197,12 +1177,7 @@ public class DescriptorResolver {
trace.record(BindingContext.PROPERTY_ACCESSOR, setter, setterDescriptor);
}
else if (property.isVar()) {
if (property.getDelegateExpression() != null) {
setterDescriptor = createSetterForDelegatedProperty(propertyDescriptor);
}
else {
setterDescriptor = createDefaultSetter(propertyDescriptor);
}
setterDescriptor = DescriptorFactory.createSetter(propertyDescriptor, property.getDelegateExpression() == null);
}
if (!property.isVar()) {
@@ -1214,27 +1189,6 @@ public class DescriptorResolver {
return setterDescriptor;
}
@NotNull
public static PropertySetterDescriptorImpl createDefaultSetter(@NotNull PropertyDescriptor propertyDescriptor) {
return createSetter(propertyDescriptor, false, true);
}
@NotNull
public static PropertySetterDescriptorImpl createSetterForDelegatedProperty(@NotNull PropertyDescriptor propertyDescriptor) {
return createSetter(propertyDescriptor, true, false);
}
@NotNull
private static PropertySetterDescriptorImpl createSetter(@NotNull PropertyDescriptor propertyDescriptor, boolean hasBody, boolean isDefault) {
PropertySetterDescriptorImpl setterDescriptor;
setterDescriptor = new PropertySetterDescriptorImpl(
propertyDescriptor, Collections.<AnnotationDescriptor>emptyList(), propertyDescriptor.getModality(),
propertyDescriptor.getVisibility(),
hasBody, isDefault, CallableMemberDescriptor.Kind.DECLARATION);
setterDescriptor.initializeDefault();
return setterDescriptor;
}
@Nullable
private PropertyGetterDescriptorImpl resolvePropertyGetterDescriptor(
@NotNull JetScope scope,
@@ -1267,36 +1221,12 @@ public class DescriptorResolver {
trace.record(BindingContext.PROPERTY_ACCESSOR, getter, getterDescriptor);
}
else {
if (property.getDelegateExpression() != null) {
getterDescriptor = createGetterForDelegatedProperty(propertyDescriptor);
}
else {
getterDescriptor = createDefaultGetter(propertyDescriptor);
}
getterDescriptor = DescriptorFactory.createGetter(propertyDescriptor, property.getDelegateExpression() == null);
getterDescriptor.initialize(propertyDescriptor.getType());
}
return getterDescriptor;
}
@NotNull
public static PropertyGetterDescriptorImpl createDefaultGetter(@NotNull PropertyDescriptor propertyDescriptor) {
return createGetter(propertyDescriptor, false, true);
}
@NotNull
public static PropertyGetterDescriptorImpl createGetterForDelegatedProperty(@NotNull PropertyDescriptor propertyDescriptor) {
return createGetter(propertyDescriptor, true, false);
}
private static PropertyGetterDescriptorImpl createGetter(@NotNull PropertyDescriptor propertyDescriptor, boolean hasBody, boolean isDefault) {
PropertyGetterDescriptorImpl getterDescriptor;
getterDescriptor = new PropertyGetterDescriptorImpl(
propertyDescriptor, Collections.<AnnotationDescriptor>emptyList(), propertyDescriptor.getModality(),
propertyDescriptor.getVisibility(),
hasBody, isDefault, CallableMemberDescriptor.Kind.DECLARATION);
return getterDescriptor;
}
@NotNull
private ConstructorDescriptorImpl createConstructorDescriptor(
@NotNull JetScope scope,
@@ -1377,8 +1307,9 @@ public class DescriptorResolver {
propertyDescriptor.setType(type, Collections.<TypeParameterDescriptor>emptyList(),
getExpectedThisObjectIfNeeded(classDescriptor), NO_RECEIVER_PARAMETER);
PropertyGetterDescriptorImpl getter = createDefaultGetter(propertyDescriptor);
PropertySetterDescriptor setter = propertyDescriptor.isVar() ? createDefaultSetter(propertyDescriptor) : null;
PropertyGetterDescriptorImpl getter = DescriptorFactory.createDefaultGetter(propertyDescriptor);
PropertySetterDescriptor setter =
propertyDescriptor.isVar() ? DescriptorFactory.createDefaultSetter(propertyDescriptor) : null;
propertyDescriptor.initialize(getter, setter);
getter.initialize(propertyDescriptor.getType());
@@ -1436,26 +1367,13 @@ public class DescriptorResolver {
) {
final ClassDescriptor enumClassDescriptor = (ClassDescriptor) classObject.getContainingDeclaration();
assert DescriptorUtils.isEnumClass(enumClassDescriptor) : "values should be created in enum class: " + enumClassDescriptor;
return createEnumClassObjectValuesMethod(classObject, DeferredType.create(trace, new RecursionIntolerantLazyValue<JetType>() {
@Override
protected JetType compute() {
return KotlinBuiltIns.getInstance().getArrayType(enumClassDescriptor.getDefaultType());
}
}));
}
@NotNull
public static SimpleFunctionDescriptor createEnumClassObjectValuesMethod(
@NotNull ClassDescriptor classObject,
@NotNull JetType returnType
) {
SimpleFunctionDescriptorImpl values =
new SimpleFunctionDescriptorImpl(classObject, Collections.<AnnotationDescriptor>emptyList(), VALUES_METHOD_NAME,
CallableMemberDescriptor.Kind.DECLARATION);
return values.initialize(null, classObject.getThisAsReceiverParameter(), Collections.<TypeParameterDescriptor>emptyList(),
Collections.<ValueParameterDescriptor>emptyList(),
returnType, Modality.FINAL,
Visibilities.PUBLIC, false);
return DescriptorFactory
.createEnumClassObjectValuesMethod(classObject, DeferredType.create(trace, new RecursionIntolerantLazyValue<JetType>() {
@Override
protected JetType compute() {
return KotlinBuiltIns.getInstance().getArrayType(enumClassDescriptor.getDefaultType());
}
}));
}
@@ -1466,69 +1384,13 @@ public class DescriptorResolver {
) {
final ClassDescriptor enumClassDescriptor = (ClassDescriptor) classObject.getContainingDeclaration();
assert DescriptorUtils.isEnumClass(enumClassDescriptor) : "valueOf should be created in enum class: " + enumClassDescriptor;
return createEnumClassObjectValueOfMethod(classObject, DeferredType.create(trace, new RecursionIntolerantLazyValue<JetType>() {
@Override
protected JetType compute() {
return enumClassDescriptor.getDefaultType();
}
}));
}
@NotNull
public static SimpleFunctionDescriptor createEnumClassObjectValueOfMethod(
@NotNull ClassDescriptor classObject,
@NotNull JetType returnType
) {
SimpleFunctionDescriptorImpl values =
new SimpleFunctionDescriptorImpl(classObject, Collections.<AnnotationDescriptor>emptyList(), VALUE_OF_METHOD_NAME,
CallableMemberDescriptor.Kind.DECLARATION);
ValueParameterDescriptor parameterDescriptor = new ValueParameterDescriptorImpl(
values,
0,
Collections.<AnnotationDescriptor>emptyList(),
Name.identifier("value"),
KotlinBuiltIns.getInstance().getStringType(),
false,
null);
return values.initialize(null, classObject.getThisAsReceiverParameter(),
Collections.<TypeParameterDescriptor>emptyList(),
Collections.singletonList(parameterDescriptor),
returnType, Modality.FINAL,
Visibilities.PUBLIC, false);
}
public static ReceiverParameterDescriptor createLazyReceiverParameterDescriptor(@NotNull final ClassDescriptor classDescriptor) {
return new AbstractReceiverParameterDescriptor() {
private ClassReceiver value;
@NotNull
@Override
public JetType getType() {
// This must be lazy, thus the inner class
return classDescriptor.getDefaultType();
}
@NotNull
@Override
public ReceiverValue getValue() {
if (value == null) {
value = new ClassReceiver(classDescriptor);
}
return value;
}
@NotNull
@Override
public DeclarationDescriptor getContainingDeclaration() {
return classDescriptor;
}
@Override
public String toString() {
return "class " + classDescriptor.getName() + "::this";
}
};
return DescriptorFactory
.createEnumClassObjectValueOfMethod(classObject, DeferredType.create(trace, new RecursionIntolerantLazyValue<JetType>() {
@Override
protected JetType compute() {
return enumClassDescriptor.getDefaultType();
}
}));
}
public static boolean checkHasOuterClassInstance(
@@ -31,7 +31,7 @@ import org.jetbrains.jet.lang.descriptors.impl.ClassDescriptorBase;
import org.jetbrains.jet.lang.psi.*;
import org.jetbrains.jet.lang.resolve.AnnotationResolver;
import org.jetbrains.jet.lang.resolve.BindingContext;
import org.jetbrains.jet.lang.resolve.DescriptorResolver;
import org.jetbrains.jet.lang.resolve.DescriptorFactory;
import org.jetbrains.jet.lang.resolve.DescriptorUtils;
import org.jetbrains.jet.lang.resolve.lazy.ForceResolveUtil;
import org.jetbrains.jet.lang.resolve.lazy.LazyDescriptor;
@@ -129,7 +129,7 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements LazyDesc
this.thisAsReceiverParameter = storageManager.createLazyValue(new Computable<ReceiverParameterDescriptor>() {
@Override
public ReceiverParameterDescriptor compute() {
return DescriptorResolver.createLazyReceiverParameterDescriptor(LazyClassDescriptor.this);
return DescriptorFactory.createLazyReceiverParameterDescriptor(LazyClassDescriptor.this);
}
});
this.annotations = storageManager.createLazyValue(new Computable<List<AnnotationDescriptor>>() {
@@ -195,12 +195,12 @@ public class LazyClassMemberScope extends AbstractLazyMemberScope<LazyClassDescr
private void generateEnumClassObjectMethods(@NotNull Collection<? super FunctionDescriptor> result, @NotNull Name name) {
if (!DescriptorUtils.isEnumClassObject(thisDescriptor)) return;
if (name.equals(DescriptorResolver.VALUES_METHOD_NAME)) {
if (name.equals(DescriptorFactory.VALUES_METHOD_NAME)) {
SimpleFunctionDescriptor valuesMethod = DescriptorResolver
.createEnumClassObjectValuesMethod(thisDescriptor, resolveSession.getTrace());
result.add(valuesMethod);
}
else if (name.equals(DescriptorResolver.VALUE_OF_METHOD_NAME)) {
else if (name.equals(DescriptorFactory.VALUE_OF_METHOD_NAME)) {
SimpleFunctionDescriptor valueOfMethod = DescriptorResolver
.createEnumClassObjectValueOfMethod(thisDescriptor, resolveSession.getTrace());
result.add(valueOfMethod);
@@ -294,8 +294,8 @@ public class LazyClassMemberScope extends AbstractLazyMemberScope<LazyClassDescr
}
}
result.addAll(getFunctions(DescriptorResolver.VALUES_METHOD_NAME));
result.addAll(getFunctions(DescriptorResolver.VALUE_OF_METHOD_NAME));
result.addAll(getFunctions(DescriptorFactory.VALUES_METHOD_NAME));
result.addAll(getFunctions(DescriptorFactory.VALUE_OF_METHOD_NAME));
addDataClassMethods(result);
}
@@ -23,7 +23,7 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.descriptors.serialization.ClassId;
import org.jetbrains.jet.lang.descriptors.*;
import org.jetbrains.jet.lang.resolve.DescriptorResolver;
import org.jetbrains.jet.lang.resolve.DescriptorFactory;
import org.jetbrains.jet.lang.resolve.DescriptorUtils;
import org.jetbrains.jet.lang.resolve.java.DescriptorSearchRule;
import org.jetbrains.jet.lang.resolve.java.JavaClassFinder;
@@ -448,12 +448,12 @@ public final class JavaClassResolver {
JetType valuesReturnType = KotlinBuiltIns.getInstance().getArrayType(containing.getDefaultType());
SimpleFunctionDescriptor valuesMethod =
DescriptorResolver.createEnumClassObjectValuesMethod(classObjectDescriptor, valuesReturnType);
DescriptorFactory.createEnumClassObjectValuesMethod(classObjectDescriptor, valuesReturnType);
classObjectDescriptor.getBuilder().addFunctionDescriptor(valuesMethod);
JetType valueOfReturnType = containing.getDefaultType();
SimpleFunctionDescriptor valueOfMethod =
DescriptorResolver.createEnumClassObjectValueOfMethod(classObjectDescriptor, valueOfReturnType);
DescriptorFactory.createEnumClassObjectValueOfMethod(classObjectDescriptor, valueOfReturnType);
classObjectDescriptor.getBuilder().addFunctionDescriptor(valueOfMethod);
return classObjectDescriptor;
@@ -22,7 +22,7 @@ import org.jetbrains.jet.lang.descriptors.*;
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
import org.jetbrains.jet.lang.descriptors.impl.ConstructorDescriptorImpl;
import org.jetbrains.jet.lang.descriptors.impl.ValueParameterDescriptorImpl;
import org.jetbrains.jet.lang.resolve.DescriptorResolver;
import org.jetbrains.jet.lang.resolve.DescriptorFactory;
import org.jetbrains.jet.lang.resolve.java.JavaVisibilities;
import org.jetbrains.jet.lang.resolve.java.structure.JavaArrayType;
import org.jetbrains.jet.lang.resolve.java.structure.JavaClass;
@@ -72,7 +72,7 @@ public final class JavaConstructorResolver {
Collection<JavaMethod> constructors = javaClass.getConstructors();
if (containingClass.getKind() == ClassKind.OBJECT || containingClass.getKind() == ClassKind.CLASS_OBJECT) {
result.add(DescriptorResolver.createPrimaryConstructorForObject(containingClass));
result.add(DescriptorFactory.createPrimaryConstructorForObject(containingClass));
}
else if (constructors.isEmpty()) {
ConstructorDescriptor defaultConstructor = resolveDefaultConstructor(javaClass, containingClass);
@@ -24,7 +24,7 @@ import org.jetbrains.jet.lang.descriptors.PropertyGetterDescriptor;
import org.jetbrains.jet.lang.descriptors.PropertySetterDescriptor;
import org.jetbrains.jet.lang.descriptors.impl.PropertyDescriptorImpl;
import org.jetbrains.jet.lang.descriptors.impl.PropertyGetterDescriptorImpl;
import org.jetbrains.jet.lang.resolve.DescriptorResolver;
import org.jetbrains.jet.lang.resolve.DescriptorFactory;
import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCall;
import org.jetbrains.k2js.translate.context.TranslationContext;
@@ -64,7 +64,7 @@ public final class KotlinPropertyAccessTranslator extends PropertyAccessTranslat
if (getter == null) {
//TODO: Temporary hack!!! Rewrite codegen!
//Now for consistency we don't create default getter for object declaration property descriptor
PropertyGetterDescriptorImpl getterImpl = DescriptorResolver.createDefaultGetter(propertyDescriptor);
PropertyGetterDescriptorImpl getterImpl = DescriptorFactory.createDefaultGetter(propertyDescriptor);
getterImpl.initialize(propertyDescriptor.getType());
((PropertyDescriptorImpl)propertyDescriptor).initialize(getterImpl, null);
getter = getterImpl;