提交 6446e83b 编写于 作者: S Stepan Koltsov

remove VariableDescriptor.inType

(approved by Andrey Breslav)
上级 4b9e4b65
......@@ -229,7 +229,7 @@ public abstract class CodegenContext {
pd.getName() + "$bridge$" + accessors.size()
);
JetType receiverType = pd.getReceiverParameter().exists() ? pd.getReceiverParameter().getType() : null;
myAccessor.setType(pd.getInType(), pd.getOutType(), Collections.<TypeParameterDescriptor>emptyList(), pd.getExpectedThisObject(), receiverType);
myAccessor.setType(pd.getOutType(), Collections.<TypeParameterDescriptor>emptyList(), pd.getExpectedThisObject(), receiverType);
PropertyGetterDescriptor pgd = new PropertyGetterDescriptor(
myAccessor, Collections.<AnnotationDescriptor>emptyList(), myAccessor.getModality(),
......
......@@ -672,9 +672,11 @@ public class JetTypeMapper {
@Nullable
public JvmMethodSignature mapSetterSignature(PropertyDescriptor descriptor, OwnerKind kind) {
JetType inType = descriptor.getInType();
if(inType == null)
if (!descriptor.isVar()) {
return null;
}
JetType outType = descriptor.getOutType();
String name = PropertyCodegen.setterName(descriptor.getName());
ArrayList<Type> params = new ArrayList<Type>();
......@@ -694,7 +696,7 @@ public class JetTypeMapper {
}
}
params.add(mapType(inType));
params.add(mapType(outType));
// TODO: proper generic signature
return new JvmMethodSignature(new Method(name, Type.VOID_TYPE, params.toArray(new Type[params.size()])), null, null, null, null);
......
......@@ -743,7 +743,7 @@ public class JavaDescriptorResolver {
i,
Collections.<AnnotationDescriptor>emptyList(), // TODO
name,
null, // TODO : review
false,
changeNullable ? TypeUtils.makeNullableAsSpecified(outType, nullable) : outType,
hasDefaultValue,
varargElementType
......@@ -767,7 +767,6 @@ public class JavaDescriptorResolver {
null,
DescriptorUtils.getExpectedThisObjectIfNeeded(containingDeclaration),
field.getName(),
isFinal ? null : type,
type);
semanticServices.getTrace().record(BindingContext.VARIABLE, field, propertyDescriptor);
fieldDescriptorCache.put(field, propertyDescriptor);
......
......@@ -60,7 +60,7 @@ public class FunctionDescriptorUtil {
substitutedDescriptor,
unsubstitutedValueParameter,
unsubstitutedValueParameter.getAnnotations(),
unsubstitutedValueParameter.getInType() == null ? null : substitutedType,
unsubstitutedValueParameter.isVar(),
substitutedType,
substituteVarargElementType
));
......
......@@ -19,7 +19,7 @@ public class LocalVariableDescriptor extends VariableDescriptorImpl {
@NotNull String name,
@Nullable JetType type,
boolean mutable) {
super(containingDeclaration, annotations, name, mutable ? type : null, type);
super(containingDeclaration, annotations, name, type);
isVar = mutable;
}
......
......@@ -71,23 +71,20 @@ public class PropertyDescriptor extends VariableDescriptorImpl implements Callab
@Nullable JetType receiverType,
@NotNull ReceiverDescriptor expectedThisObject,
@NotNull String name,
@Nullable JetType inType,
@NotNull JetType outType
) {
this(containingDeclaration, annotations, modality, visibility, isVar, name);
setType(inType, outType, Collections.<TypeParameterDescriptor>emptyList(), expectedThisObject, receiverType);
setType(outType, Collections.<TypeParameterDescriptor>emptyList(), expectedThisObject, receiverType);
}
public void setType(@Nullable JetType inType, @NotNull JetType outType, @NotNull List<TypeParameterDescriptor> typeParameters, @NotNull ReceiverDescriptor expectedThisObject, @Nullable JetType receiverType) {
public void setType(@NotNull JetType outType, @NotNull List<TypeParameterDescriptor> typeParameters, @NotNull ReceiverDescriptor expectedThisObject, @Nullable JetType receiverType) {
ReceiverDescriptor receiver = receiverType == null
? NO_RECEIVER
: new ExtensionReceiver(this, receiverType);
setType(inType, outType, typeParameters, expectedThisObject, receiver);
setType(outType, typeParameters, expectedThisObject, receiver);
}
public void setType(@Nullable JetType inType, @NotNull JetType outType, @NotNull List<TypeParameterDescriptor> typeParameters, @NotNull ReceiverDescriptor expectedThisObject, @NotNull ReceiverDescriptor receiver) {
assert !isVar || inType != null;
setInType(inType);
public void setType(@NotNull JetType outType, @NotNull List<TypeParameterDescriptor> typeParameters, @NotNull ReceiverDescriptor expectedThisObject, @NotNull ReceiverDescriptor receiver) {
setOutType(outType);
this.typeParemeters = typeParameters;
......@@ -123,17 +120,6 @@ public class PropertyDescriptor extends VariableDescriptorImpl implements Callab
return getOutType();
}
@Override
public JetType getInType() {
return super.getInType();
}
@Override
@NotNull
public JetType getOutType() {
return super.getOutType();
}
public boolean isVar() {
return isVar;
}
......@@ -170,11 +156,9 @@ public class PropertyDescriptor extends VariableDescriptorImpl implements Callab
List<TypeParameterDescriptor> substitutedTypeParameters = Lists.newArrayList();
TypeSubstitutor substitutor = DescriptorSubstitutor.substituteTypeParameters(getTypeParameters(), originalSubstitutor, substitutedDescriptor, substitutedTypeParameters);
JetType originalInType = getInType();
JetType inType = originalInType == null ? null : substitutor.substitute(originalInType, Variance.IN_VARIANCE);
JetType originalOutType = getOutType();
JetType outType = substitutor.substitute(originalOutType, Variance.OUT_VARIANCE);
if (inType == null && outType == null) {
if (outType == null) {
return null; // TODO : tell the user that the property was projected out
}
......@@ -196,7 +180,7 @@ public class PropertyDescriptor extends VariableDescriptorImpl implements Callab
substitutedReceiverType = null;
}
substitutedDescriptor.setType(inType, outType, substitutedTypeParameters, substitutedExpectedThisObject, substitutedReceiverType);
substitutedDescriptor.setType(outType, substitutedTypeParameters, substitutedExpectedThisObject, substitutedReceiverType);
return substitutedDescriptor;
}
......@@ -231,7 +215,7 @@ public class PropertyDescriptor extends VariableDescriptorImpl implements Callab
DescriptorUtils.convertModality(modality, makeNonAbstract), visibility, isVar,
getName());
propertyDescriptor.setType(getInType(), getOutType(), DescriptorUtils.copyTypeParameters(propertyDescriptor, getTypeParameters()), expectedThisObject, receiver.exists() ? receiver.getType() : null);
propertyDescriptor.setType(getOutType(), DescriptorUtils.copyTypeParameters(propertyDescriptor, getTypeParameters()), expectedThisObject, receiver.exists() ? receiver.getType() : null);
PropertyGetterDescriptor newGetter = getter == null ? null : new PropertyGetterDescriptor(
propertyDescriptor, Lists.newArrayList(getter.getAnnotations()),
......
......@@ -35,7 +35,7 @@ public class PropertySetterDescriptor extends PropertyAccessorDescriptor {
public void initializeDefault() {
assert parameter == null;
parameter = new ValueParameterDescriptorImpl(this, 0, Collections.<AnnotationDescriptor>emptyList(), "<>", null, getCorrespondingProperty().getReturnType(), false, null);
parameter = new ValueParameterDescriptorImpl(this, 0, Collections.<AnnotationDescriptor>emptyList(), "<>", false, getCorrespondingProperty().getReturnType(), false, null);
}
@NotNull
......
......@@ -24,42 +24,37 @@ public class ValueParameterDescriptorImpl extends VariableDescriptorImpl impleme
int index,
@NotNull List<AnnotationDescriptor> annotations,
@NotNull String name,
@Nullable JetType inType,
boolean isVar,
@NotNull JetType outType,
boolean hasDefaultValue,
@Nullable JetType varargElementType) {
super(containingDeclaration, annotations, name, inType, outType);
super(containingDeclaration, annotations, name, outType);
this.original = this;
this.index = index;
this.hasDefaultValue = hasDefaultValue;
this.varargElementType = varargElementType;
this.isVar = inType != null;
this.isVar = isVar;
}
public ValueParameterDescriptorImpl(
@NotNull DeclarationDescriptor containingDeclaration,
@NotNull ValueParameterDescriptor original,
@NotNull List<AnnotationDescriptor> annotations,
@Nullable JetType inType,
boolean isVar,
@NotNull JetType outType,
@Nullable JetType varargElementType
) {
super(containingDeclaration, annotations, original.getName(), inType, outType);
super(containingDeclaration, annotations, original.getName(), outType);
this.original = original;
this.index = original.getIndex();
this.hasDefaultValue = original.hasDefaultValue();
this.varargElementType = varargElementType;
this.isVar = inType != null;
this.isVar = isVar;
}
@Override
public void setType(@NotNull JetType type) {
assert getOutType() == null;
setOutType(type);
if (isVar) {
assert getInType() == null;
setInType(type);
}
}
@Override
......@@ -107,6 +102,6 @@ public class ValueParameterDescriptorImpl extends VariableDescriptorImpl impleme
@NotNull
@Override
public ValueParameterDescriptor copy(@NotNull DeclarationDescriptor newOwner) {
return new ValueParameterDescriptorImpl(newOwner, index, Lists.newArrayList(getAnnotations()), getName(), getInType(), getOutType(), hasDefaultValue, varargElementType);
return new ValueParameterDescriptorImpl(newOwner, index, Lists.newArrayList(getAnnotations()), getName(), isVar, getOutType(), hasDefaultValue, varargElementType);
}
}
......@@ -9,18 +9,9 @@ import org.jetbrains.jet.lang.types.TypeSubstitutor;
* @author abreslav
*/
public interface VariableDescriptor extends CallableDescriptor {
/**
* @return <code>null</code> for write-only variables (i.e. properties), variable value type otherwise
*/
@Nullable
@NotNull
JetType getOutType();
/**
* @return <code>null</code> for read-only variables (i.e. val's etc), or the type expected on assignment type otherwise
*/
@Nullable
JetType getInType();
@Override
@SuppressWarnings({"NullableProblems"})
@NotNull
......
......@@ -34,11 +34,6 @@ public class VariableDescriptorBoundToReceiver implements VariableDescriptor {
return variableDescriptor.getOutType();
}
@Override
public JetType getInType() {
return variableDescriptor.getInType();
}
@NotNull
@Override
public DeclarationDescriptor getContainingDeclaration() {
......
......@@ -14,19 +14,15 @@ import java.util.Set;
* @author abreslav
*/
public abstract class VariableDescriptorImpl extends DeclarationDescriptorImpl implements VariableDescriptor {
private JetType inType;
private JetType outType;
public VariableDescriptorImpl(
@NotNull DeclarationDescriptor containingDeclaration,
@NotNull List<AnnotationDescriptor> annotations,
@NotNull String name,
@Nullable JetType inType,
@Nullable JetType outType) {
@NotNull JetType outType) {
super(containingDeclaration, annotations, name);
assert (inType != null) || (outType != null);
this.inType = inType;
this.outType = outType;
}
......@@ -44,16 +40,8 @@ public abstract class VariableDescriptorImpl extends DeclarationDescriptorImpl i
return outType;
}
@Override
public JetType getInType() {
return inType;
}
protected void setInType(JetType inType) {
this.inType = inType;
}
protected void setOutType(JetType outType) {
assert this.outType == null;
this.outType = outType;
}
......
......@@ -264,7 +264,7 @@ public class DescriptorResolver {
index,
annotationResolver.createAnnotationStubs(valueParameter.getModifierList()),
JetPsiUtil.safeName(valueParameter.getName()),
valueParameter.isMutable() ? variableType : null,
valueParameter.isMutable(),
variableType,
valueParameter.getDefaultValue() != null,
varargElementType
......@@ -479,7 +479,7 @@ public class DescriptorResolver {
JetPsiUtil.safeName(objectDeclaration.getName())
);
propertyDescriptor.setType(null, classDescriptor.getDefaultType(), Collections.<TypeParameterDescriptor>emptyList(), DescriptorUtils.getExpectedThisObjectIfNeeded(containingDeclaration), ReceiverDescriptor.NO_RECEIVER);
propertyDescriptor.setType(classDescriptor.getDefaultType(), Collections.<TypeParameterDescriptor>emptyList(), DescriptorUtils.getExpectedThisObjectIfNeeded(containingDeclaration), ReceiverDescriptor.NO_RECEIVER);
propertyDescriptor.initialize(null, null);
JetObjectDeclarationName nameAsDeclaration = objectDeclaration.getNameAsDeclaration();
......@@ -553,8 +553,7 @@ public class DescriptorResolver {
JetType type = getVariableType(propertyScope, property, DataFlowInfo.EMPTY, true);
JetType inType = isVar ? type : null;
propertyDescriptor.setType(inType, type, typeParameterDescriptors, DescriptorUtils.getExpectedThisObjectIfNeeded(containingDeclaration), receiverDescriptor);
propertyDescriptor.setType(type, typeParameterDescriptors, DescriptorUtils.getExpectedThisObjectIfNeeded(containingDeclaration), receiverDescriptor);
PropertyGetterDescriptor getter = resolvePropertyGetterDescriptor(scopeWithTypeParameters, property, propertyDescriptor);
PropertySetterDescriptor setter = resolvePropertySetterDescriptor(scopeWithTypeParameters, property, propertyDescriptor);
......@@ -686,11 +685,11 @@ public class DescriptorResolver {
JetType type;
JetTypeReference typeReference = parameter.getTypeReference();
if (typeReference == null) {
type = propertyDescriptor.getInType(); // TODO : this maybe unknown at this point
type = propertyDescriptor.getOutType(); // TODO : this maybe unknown at this point
}
else {
type = typeResolver.resolveType(scope, typeReference);
JetType inType = propertyDescriptor.getInType();
JetType inType = propertyDescriptor.getOutType();
if (inType != null) {
if (!TypeUtils.equalTypes(type, inType)) {
// trace.getErrorHandler().genericError(typeReference.getNode(), "Setter parameter type must be equal to the type of the property, i.e. " + inType);
......@@ -842,8 +841,7 @@ public class DescriptorResolver {
isMutable,
name == null ? "<no name>" : name
);
JetType inType = isMutable ? type : null;
propertyDescriptor.setType(inType, type, Collections.<TypeParameterDescriptor>emptyList(), DescriptorUtils.getExpectedThisObjectIfNeeded(classDescriptor), ReceiverDescriptor.NO_RECEIVER);
propertyDescriptor.setType(type, Collections.<TypeParameterDescriptor>emptyList(), DescriptorUtils.getExpectedThisObjectIfNeeded(classDescriptor), ReceiverDescriptor.NO_RECEIVER);
PropertyGetterDescriptor getter = createDefaultGetter(propertyDescriptor);
PropertySetterDescriptor setter = createDefaultSetter(propertyDescriptor);
......
......@@ -116,7 +116,7 @@ public class ErrorUtils {
null,
ReceiverDescriptor.NO_RECEIVER,
"<ERROR PROPERTY>",
ERROR_PROPERTY_TYPE, ERROR_PROPERTY_TYPE);
ERROR_PROPERTY_TYPE);
private static final Set<VariableDescriptor> ERROR_PROPERTY_GROUP = Collections.singleton(ERROR_PROPERTY);
private static FunctionDescriptor createErrorFunction(List<TypeParameterDescriptor> typeParameters, List<JetType> positionedValueArgumentTypes) {
......@@ -165,7 +165,7 @@ public class ErrorUtils {
i,
Collections.<AnnotationDescriptor>emptyList(),
"<ERROR VALUE_PARAMETER>",
ERROR_PARAMETER_TYPE,
true,
ERROR_PARAMETER_TYPE,
false,
null));
......
......@@ -385,7 +385,7 @@ public class JetStandardClasses {
List<ValueParameterDescriptor> valueParameters = Lists.newArrayList();
for (int i = first; i <= last; i++) {
JetType parameterType = arguments.get(i).getType();
ValueParameterDescriptorImpl valueParameterDescriptor = new ValueParameterDescriptorImpl(functionDescriptor, i, Collections.<AnnotationDescriptor>emptyList(), "p" + i, null, parameterType, false, null);
ValueParameterDescriptorImpl valueParameterDescriptor = new ValueParameterDescriptorImpl(functionDescriptor, i, Collections.<AnnotationDescriptor>emptyList(), "p" + i, false, parameterType, false, null);
valueParameters.add(valueParameterDescriptor);
}
return valueParameters;
......
......@@ -145,7 +145,7 @@ public class ClosureExpressionsTypingVisitor extends ExpressionTypingVisitor {
if (functionTypeExpected && !hasDeclaredValueParameters && expectedValueParameters.size() == 1) {
ValueParameterDescriptor valueParameterDescriptor = expectedValueParameters.get(0);
ValueParameterDescriptor it = new ValueParameterDescriptorImpl(
functionDescriptor, 0, Collections.<AnnotationDescriptor>emptyList(), "it", valueParameterDescriptor.getInType(), valueParameterDescriptor.getOutType(), valueParameterDescriptor.hasDefaultValue(), valueParameterDescriptor.getVarargElementType()
functionDescriptor, 0, Collections.<AnnotationDescriptor>emptyList(), "it", false, valueParameterDescriptor.getOutType(), valueParameterDescriptor.hasDefaultValue(), valueParameterDescriptor.getVarargElementType()
);
valueParameterDescriptors.add(it);
context.trace.record(AUTO_CREATED_IT, it);
......
......@@ -136,7 +136,7 @@ public class DescriptorRenderer implements Renderer {
@Override
public Void visitVariableDescriptor(VariableDescriptor descriptor, StringBuilder builder) {
String typeString = renderPropertyPrefixAndComputeTypeString(builder, Collections.<TypeParameterDescriptor>emptyList(), ReceiverDescriptor.NO_RECEIVER, descriptor.getOutType(), descriptor.getInType());
String typeString = renderPropertyPrefixAndComputeTypeString(builder, Collections.<TypeParameterDescriptor>emptyList(), ReceiverDescriptor.NO_RECEIVER, descriptor.getOutType());
renderName(descriptor, builder);
builder.append(" : ").append(escape(typeString));
return super.visitVariableDescriptor(descriptor, builder);
......@@ -146,26 +146,16 @@ public class DescriptorRenderer implements Renderer {
@NotNull StringBuilder builder,
@NotNull List<TypeParameterDescriptor> typeParameters,
@NotNull ReceiverDescriptor receiver,
@Nullable JetType outType,
@Nullable JetType inType) {
@Nullable JetType outType) {
String typeString = lt() + "no type>";
if (inType != null && outType != null) {
if (outType != null) {
builder.append(renderKeyword("var")).append(" ");
if (inType.equals(outType)) {
typeString = renderType(outType);
}
else {
typeString = "<" + renderKeyword("in") + ": " + renderType(inType) + " " + renderKeyword("out") + ": " + renderType(outType) + ">";
}
typeString = renderType(outType);
}
else if (outType != null) {
builder.append(renderKeyword("val")).append(" ");
typeString = renderType(outType);
}
else if (inType != null) {
builder.append(lt()).append("write-only> ");
typeString = renderType(inType);
}
renderTypeParameters(typeParameters, builder);
......@@ -182,8 +172,7 @@ public class DescriptorRenderer implements Renderer {
String typeString = renderPropertyPrefixAndComputeTypeString(
builder, descriptor.getTypeParameters(),
descriptor.getReceiverParameter(),
descriptor.getOutType(),
descriptor.getInType());
descriptor.getOutType());
renderName(descriptor, builder);
builder.append(" : ").append(escape(typeString));
return null;
......
......@@ -7,7 +7,7 @@ var x : Int = 1 + x
val xx : Int = <!PROPERTY_INITIALIZER_NO_BACKING_FIELD!>1 + x<!>
get() : Int = 1
<!VAL_WITH_SETTER!>set(value : Long) {}<!>
<!VAL_WITH_SETTER!>set(value : <!WRONG_SETTER_PARAMETER_TYPE!>Long<!>) {}<!>
val p : Int = <!PROPERTY_INITIALIZER_NO_BACKING_FIELD!>1<!>
get() = 1
......@@ -26,4 +26,4 @@ class Test() {
a = <!NO_BACKING_FIELD_CUSTOM_ACCESSORS!>$b<!>
}
public val <!PUBLIC_MEMBER_SHOULD_SPECIFY_TYPE!>i<!> = 1
}
\ No newline at end of file
}
......@@ -7,7 +7,7 @@
val xx : Int = <error>1 + x</error>
get() : Int = 1
<error>set(value : Long) {}</error>
<error>set(value : <error>Long</error>) {}</error>
val p : Int = <error>1</error>
get() = 1
......@@ -25,4 +25,4 @@ class Test() {
<error>$b</error> = $a
a = <error>$b</error>
}
}
\ No newline at end of file
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册