JetVariableDeclaration made JetCallableDeclaration and renamed getTypeRef/setTypeRef, getReturnTypeRef/setReturnTypeRef to getTypeReference/setTypeReference

This commit is contained in:
Valentin Kipyatkov
2014-10-07 12:50:34 +04:00
parent c42b7b1780
commit 31ebee81f0
47 changed files with 119 additions and 115 deletions
@@ -53,7 +53,7 @@ public class AlternativeFieldSignatureData extends ElementAlternativeSignatureDa
try { try {
checkForSyntaxErrors(altPropertyDeclaration); checkForSyntaxErrors(altPropertyDeclaration);
checkFieldAnnotation(altPropertyDeclaration, field, isVar); checkFieldAnnotation(altPropertyDeclaration, field, isVar);
altReturnType = computeReturnType(originalReturnType, altPropertyDeclaration.getTypeRef(), altReturnType = computeReturnType(originalReturnType, altPropertyDeclaration.getTypeReference(),
new HashMap<TypeParameterDescriptor, TypeParameterDescriptorImpl>()); new HashMap<TypeParameterDescriptor, TypeParameterDescriptorImpl>());
} }
catch (AlternativeSignatureMismatchException e) { catch (AlternativeSignatureMismatchException e) {
@@ -73,7 +73,7 @@ public class AlternativeFieldSignatureData extends ElementAlternativeSignatureDa
field.getName().asString(), altProperty.getName()); field.getName().asString(), altProperty.getName());
} }
if (altProperty.getTypeRef() == null) { if (altProperty.getTypeReference() == null) {
throw new AlternativeSignatureMismatchException("Field annotation for shouldn't have type reference"); throw new AlternativeSignatureMismatchException("Field annotation for shouldn't have type reference");
} }
@@ -89,7 +89,7 @@ public class AlternativeMethodSignatureData extends ElementAlternativeSignatureD
computeValueParameters(valueParameters); computeValueParameters(valueParameters);
if (originalReturnType != null) { if (originalReturnType != null) {
altReturnType = computeReturnType(originalReturnType, altFunDeclaration.getReturnTypeRef(), originalToAltTypeParameters); altReturnType = computeReturnType(originalReturnType, altFunDeclaration.getTypeReference(), originalToAltTypeParameters);
} }
if (hasSuperMethods) { if (hasSuperMethods) {
@@ -72,12 +72,12 @@ public class PositioningStrategies {
PsiElement nameIdentifierOrPlaceholder = null; PsiElement nameIdentifierOrPlaceholder = null;
if (declaration instanceof JetNamedFunction) { if (declaration instanceof JetNamedFunction) {
JetFunction function = (JetNamedFunction) declaration; JetFunction function = (JetNamedFunction) declaration;
returnTypeRef = function.getReturnTypeRef(); returnTypeRef = function.getTypeReference();
nameIdentifierOrPlaceholder = function.getNameIdentifier(); nameIdentifierOrPlaceholder = function.getNameIdentifier();
} }
else if (declaration instanceof JetProperty) { else if (declaration instanceof JetProperty) {
JetProperty property = (JetProperty) declaration; JetProperty property = (JetProperty) declaration;
returnTypeRef = property.getTypeRef(); returnTypeRef = property.getTypeReference();
nameIdentifierOrPlaceholder = property.getNameIdentifier(); nameIdentifierOrPlaceholder = property.getNameIdentifier();
} }
else if (declaration instanceof JetPropertyAccessor) { else if (declaration instanceof JetPropertyAccessor) {
@@ -148,7 +148,7 @@ public class PositioningStrategies {
JetNamedFunction function = (JetNamedFunction)element; JetNamedFunction function = (JetNamedFunction)element;
PsiElement endOfSignatureElement; PsiElement endOfSignatureElement;
JetParameterList valueParameterList = function.getValueParameterList(); JetParameterList valueParameterList = function.getValueParameterList();
JetElement returnTypeRef = function.getReturnTypeRef(); JetElement returnTypeRef = function.getTypeReference();
PsiElement nameIdentifier = function.getNameIdentifier(); PsiElement nameIdentifier = function.getNameIdentifier();
if (returnTypeRef != null) { if (returnTypeRef != null) {
endOfSignatureElement = returnTypeRef; endOfSignatureElement = returnTypeRef;
@@ -167,7 +167,7 @@ public class PositioningStrategies {
else if (element instanceof JetProperty) { else if (element instanceof JetProperty) {
JetProperty property = (JetProperty) element; JetProperty property = (JetProperty) element;
PsiElement endOfSignatureElement; PsiElement endOfSignatureElement;
JetTypeReference propertyTypeRef = property.getTypeRef(); JetTypeReference propertyTypeRef = property.getTypeReference();
PsiElement nameIdentifier = property.getNameIdentifier(); PsiElement nameIdentifier = property.getNameIdentifier();
if (propertyTypeRef != null) { if (propertyTypeRef != null) {
endOfSignatureElement = propertyTypeRef; endOfSignatureElement = propertyTypeRef;
@@ -266,7 +266,7 @@ private object DebugTextBuildingVisitor : JetVisitor<String, Unit>() {
appendInn(typeParameterList) appendInn(typeParameterList)
} }
appendInn(function.getValueParameterList()) appendInn(function.getValueParameterList())
appendInn(function.getReturnTypeRef(), prefix = ": ") appendInn(function.getTypeReference(), prefix = ": ")
appendInn(function.getTypeConstraintList(), prefix = " ") appendInn(function.getTypeConstraintList(), prefix = " ")
} }
} }
@@ -302,7 +302,7 @@ private object DebugTextBuildingVisitor : JetVisitor<String, Unit>() {
appendInn(property.getModifierList(), suffix = " ") appendInn(property.getModifierList(), suffix = " ")
append(if (property.isVar()) "var " else "val ") append(if (property.isVar()) "var " else "val ")
appendInn(property.getNameAsName()) appendInn(property.getNameAsName())
appendInn(property.getTypeRef(), prefix = ": ") appendInn(property.getTypeReference(), prefix = ": ")
} }
} }
@@ -26,8 +26,8 @@ public interface JetCallableDeclaration extends JetNamedDeclaration, JetTypePara
JetTypeReference getReceiverTypeRef(); JetTypeReference getReceiverTypeRef();
@Nullable @Nullable
JetTypeReference getReturnTypeRef(); JetTypeReference getTypeReference();
@Nullable @Nullable
JetTypeReference setReturnTypeRef(@Nullable JetTypeReference typeRef); JetTypeReference setTypeReference(@Nullable JetTypeReference typeRef);
} }
@@ -53,7 +53,7 @@ public class JetFunctionLiteralExpression extends JetExpressionImpl {
} }
public boolean hasDeclaredReturnType() { public boolean hasDeclaredReturnType() {
return getFunctionLiteral().getReturnTypeRef() != null; return getFunctionLiteral().getTypeReference() != null;
} }
@NotNull @NotNull
@@ -56,7 +56,7 @@ abstract public class JetFunctionNotStubbed extends JetTypeParameterListOwnerNot
@Override @Override
public boolean hasDeclaredReturnType() { public boolean hasDeclaredReturnType() {
return getReturnTypeRef() != null; return getTypeReference() != null;
} }
@Override @Override
@@ -77,13 +77,13 @@ abstract public class JetFunctionNotStubbed extends JetTypeParameterListOwnerNot
@Override @Override
@Nullable @Nullable
public JetTypeReference getReturnTypeRef() { public JetTypeReference getTypeReference() {
return TypeRefHelpersPackage.getTypeRef(this); return TypeRefHelpersPackage.getTypeRef(this);
} }
@Nullable @Nullable
@Override @Override
public JetTypeReference setReturnTypeRef(@Nullable JetTypeReference typeRef) { public JetTypeReference setTypeReference(@Nullable JetTypeReference typeRef) {
return TypeRefHelpersPackage.setTypeRef(this, getValueParameterList(), typeRef); return TypeRefHelpersPackage.setTypeRef(this, getValueParameterList(), typeRef);
} }
@@ -42,7 +42,7 @@ public final class JetModifiableBlockHelper {
} }
else if (declaration instanceof JetProperty) { else if (declaration instanceof JetProperty) {
JetProperty property = (JetProperty) declaration; JetProperty property = (JetProperty) declaration;
if (property.getTypeRef() != null) { if (property.getTypeReference() != null) {
return takePartInDeclarationTypeInference(property); return takePartInDeclarationTypeInference(property);
} }
@@ -71,7 +71,7 @@ public final class JetModifiableBlockHelper {
} }
else if (declaration instanceof JetProperty) { else if (declaration instanceof JetProperty) {
JetProperty property = (JetProperty) declaration; JetProperty property = (JetProperty) declaration;
if (property.getTypeRef() == null) { if (property.getTypeReference() == null) {
return true; return true;
} }
} }
@@ -25,6 +25,9 @@ import org.jetbrains.jet.lang.psi.typeRefHelpers.TypeRefHelpersPackage;
import org.jetbrains.jet.lang.resolve.name.FqName; import org.jetbrains.jet.lang.resolve.name.FqName;
import org.jetbrains.jet.lexer.JetTokens; import org.jetbrains.jet.lexer.JetTokens;
import java.util.Collections;
import java.util.List;
import static org.jetbrains.jet.lexer.JetTokens.VAL_KEYWORD; import static org.jetbrains.jet.lexer.JetTokens.VAL_KEYWORD;
import static org.jetbrains.jet.lexer.JetTokens.VAR_KEYWORD; import static org.jetbrains.jet.lexer.JetTokens.VAR_KEYWORD;
@@ -34,16 +37,40 @@ public class JetMultiDeclarationEntry extends JetNamedDeclarationNotStubbed impl
} }
@Override @Override
public JetTypeReference getTypeRef() { public JetTypeReference getTypeReference() {
return TypeRefHelpersPackage.getTypeRef(this); return TypeRefHelpersPackage.getTypeRef(this);
} }
@Override @Override
@Nullable @Nullable
public JetTypeReference setTypeRef(@Nullable JetTypeReference typeRef) { public JetTypeReference setTypeReference(@Nullable JetTypeReference typeRef) {
return TypeRefHelpersPackage.setTypeRef(this, getNameIdentifier(), typeRef); return TypeRefHelpersPackage.setTypeRef(this, getNameIdentifier(), typeRef);
} }
@Nullable
@Override
public JetParameterList getValueParameterList() {
return null;
}
@Nullable
@Override
public JetTypeReference getReceiverTypeRef() {
return null;
}
@NotNull
@Override
public List<JetTypeConstraint> getTypeConstraints() {
return Collections.emptyList();
}
@NotNull
@Override
public List<JetTypeParameter> getTypeParameters() {
return Collections.emptyList();
}
@Override @Override
public <R, D> R accept(@NotNull JetVisitor<R, D> visitor, D data) { public <R, D> R accept(@NotNull JetVisitor<R, D> visitor, D data) {
return visitor.visitMultiDeclarationEntry(this, data); return visitor.visitMultiDeclarationEntry(this, data);
@@ -126,7 +126,7 @@ public class JetNamedFunction extends JetTypeParameterListOwnerStub<PsiJetFuncti
@Override @Override
public boolean hasDeclaredReturnType() { public boolean hasDeclaredReturnType() {
return getReturnTypeRef() != null; return getTypeReference() != null;
} }
@Override @Override
@@ -165,7 +165,7 @@ public class JetNamedFunction extends JetTypeParameterListOwnerStub<PsiJetFuncti
@Override @Override
@Nullable @Nullable
public JetTypeReference getReturnTypeRef() { public JetTypeReference getTypeReference() {
PsiJetFunctionStub stub = getStub(); PsiJetFunctionStub stub = getStub();
if (stub != null) { if (stub != null) {
List<JetTypeReference> typeReferences = getStubOrPsiChildrenAsList(JetStubElementTypes.TYPE_REFERENCE); List<JetTypeReference> typeReferences = getStubOrPsiChildrenAsList(JetStubElementTypes.TYPE_REFERENCE);
@@ -180,7 +180,7 @@ public class JetNamedFunction extends JetTypeParameterListOwnerStub<PsiJetFuncti
@Override @Override
@Nullable @Nullable
public JetTypeReference setReturnTypeRef(@Nullable JetTypeReference typeRef) { public JetTypeReference setTypeReference(@Nullable JetTypeReference typeRef) {
return TypeRefHelpersPackage.setTypeRef(this, getValueParameterList(), typeRef); return TypeRefHelpersPackage.setTypeRef(this, getValueParameterList(), typeRef);
} }
@@ -37,8 +37,7 @@ import java.util.List;
import static org.jetbrains.jet.JetNodeTypes.PROPERTY_DELEGATE; import static org.jetbrains.jet.JetNodeTypes.PROPERTY_DELEGATE;
import static org.jetbrains.jet.lexer.JetTokens.*; import static org.jetbrains.jet.lexer.JetTokens.*;
public class JetProperty extends JetTypeParameterListOwnerStub<PsiJetPropertyStub> implements JetVariableDeclaration, public class JetProperty extends JetTypeParameterListOwnerStub<PsiJetPropertyStub> implements JetVariableDeclaration {
JetCallableDeclaration {
private static final Logger LOG = Logger.getInstance(JetProperty.class); private static final Logger LOG = Logger.getInstance(JetProperty.class);
@@ -116,21 +115,9 @@ public class JetProperty extends JetTypeParameterListOwnerStub<PsiJetPropertyStu
return null; return null;
} }
@Nullable
@Override
public JetTypeReference getReturnTypeRef() {
return getTypeRef();
}
@Nullable
@Override
public JetTypeReference setReturnTypeRef(@Nullable JetTypeReference typeRef) {
return setTypeRef(typeRef);
}
@Override @Override
@Nullable @Nullable
public JetTypeReference getTypeRef() { public JetTypeReference getTypeReference() {
PsiJetPropertyStub stub = getStub(); PsiJetPropertyStub stub = getStub();
if (stub != null) { if (stub != null) {
if (!stub.hasReturnTypeRef()) { if (!stub.hasReturnTypeRef()) {
@@ -151,7 +138,7 @@ public class JetProperty extends JetTypeParameterListOwnerStub<PsiJetPropertyStu
@Override @Override
@Nullable @Nullable
public JetTypeReference setTypeRef(@Nullable JetTypeReference typeRef) { public JetTypeReference setTypeReference(@Nullable JetTypeReference typeRef) {
return TypeRefHelpersPackage.setTypeRef(this, getNameIdentifier(), typeRef); return TypeRefHelpersPackage.setTypeRef(this, getNameIdentifier(), typeRef);
} }
@@ -242,7 +229,7 @@ public class JetProperty extends JetTypeParameterListOwnerStub<PsiJetPropertyStu
} }
else { else {
if (initializer != null) { if (initializer != null) {
PsiElement addAfter = getTypeRef(); PsiElement addAfter = getTypeReference();
if (addAfter == null) { if (addAfter == null) {
addAfter = getNameIdentifier(); addAfter = getNameIdentifier();
} }
@@ -68,7 +68,7 @@ public class JetPsiFactory(private val project: Project) {
} }
public fun createType(`type`: String): JetTypeReference { public fun createType(`type`: String): JetTypeReference {
return createProperty("val x : $`type`").getTypeRef()!! return createProperty("val x : $`type`").getTypeReference()!!
} }
public fun createStar(): PsiElement { public fun createStar(): PsiElement {
@@ -19,15 +19,9 @@ package org.jetbrains.jet.lang.psi;
import com.intellij.lang.ASTNode; import com.intellij.lang.ASTNode;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
public interface JetVariableDeclaration extends JetDeclaration, JetWithExpressionInitializer, JetNamedDeclaration { public interface JetVariableDeclaration extends JetCallableDeclaration, JetWithExpressionInitializer {
boolean isVar(); boolean isVar();
@Nullable @Nullable
ASTNode getValOrVarNode(); ASTNode getValOrVarNode();
@Nullable
JetTypeReference getTypeRef();
@Nullable
JetTypeReference setTypeRef(@Nullable JetTypeReference typeRef);
} }
@@ -16,8 +16,6 @@
package org.jetbrains.jet.lang.psi.stubs.elements; package org.jetbrains.jet.lang.psi.stubs.elements;
import com.intellij.lang.ASTNode;
import com.intellij.psi.PsiElement;
import com.intellij.psi.stubs.IndexSink; import com.intellij.psi.stubs.IndexSink;
import com.intellij.psi.stubs.StubElement; import com.intellij.psi.stubs.StubElement;
import com.intellij.psi.stubs.StubInputStream; import com.intellij.psi.stubs.StubInputStream;
@@ -25,7 +23,6 @@ import com.intellij.psi.stubs.StubOutputStream;
import com.intellij.util.io.StringRef; import com.intellij.util.io.StringRef;
import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.psi.JetDeclaration;
import org.jetbrains.jet.lang.psi.JetProperty; import org.jetbrains.jet.lang.psi.JetProperty;
import org.jetbrains.jet.lang.psi.stubs.PsiJetPropertyStub; import org.jetbrains.jet.lang.psi.stubs.PsiJetPropertyStub;
import org.jetbrains.jet.lang.psi.stubs.impl.PsiJetPropertyStubImpl; import org.jetbrains.jet.lang.psi.stubs.impl.PsiJetPropertyStubImpl;
@@ -49,7 +46,7 @@ public class JetPropertyElementType extends JetStubElementType<PsiJetPropertyStu
parentStub, StringRef.fromString(psi.getName()), parentStub, StringRef.fromString(psi.getName()),
psi.isVar(), psi.isTopLevel(), psi.hasDelegate(), psi.isVar(), psi.isTopLevel(), psi.hasDelegate(),
psi.hasDelegateExpression(), psi.hasInitializer(), psi.hasDelegateExpression(), psi.hasInitializer(),
psi.getReceiverTypeRef() != null, psi.getReturnTypeRef() != null, psi.getReceiverTypeRef() != null, psi.getTypeReference() != null,
ResolveSessionUtils.safeFqNameForLazyResolve(psi) ResolveSessionUtils.safeFqNameForLazyResolve(psi)
); );
} }
@@ -562,7 +562,7 @@ public class BodyResolver {
) { ) {
JetScope propertyDeclarationInnerScope = JetScopeUtils.getPropertyDeclarationInnerScopeForInitializer( JetScope propertyDeclarationInnerScope = JetScopeUtils.getPropertyDeclarationInnerScopeForInitializer(
scope, propertyDescriptor.getTypeParameters(), NO_RECEIVER_PARAMETER, trace); scope, propertyDescriptor.getTypeParameters(), NO_RECEIVER_PARAMETER, trace);
JetType expectedTypeForInitializer = property.getTypeRef() != null ? propertyDescriptor.getType() : NO_EXPECTED_TYPE; JetType expectedTypeForInitializer = property.getTypeReference() != null ? propertyDescriptor.getType() : NO_EXPECTED_TYPE;
CompileTimeConstant<?> compileTimeInitializer = propertyDescriptor.getCompileTimeInitializer(); CompileTimeConstant<?> compileTimeInitializer = propertyDescriptor.getCompileTimeInitializer();
if (compileTimeInitializer == null) { if (compileTimeInitializer == null) {
expressionTypingServices.getType(propertyDeclarationInnerScope, initializer, expectedTypeForInitializer, c.getOuterDataFlowInfo(), trace); expressionTypingServices.getType(propertyDeclarationInnerScope, initializer, expectedTypeForInitializer, c.getOuterDataFlowInfo(), trace);
@@ -362,12 +362,12 @@ public class DeclarationsChecker {
private void checkDeclaredTypeInPublicMember(JetNamedDeclaration member, CallableMemberDescriptor memberDescriptor) { private void checkDeclaredTypeInPublicMember(JetNamedDeclaration member, CallableMemberDescriptor memberDescriptor) {
boolean hasDeferredType; boolean hasDeferredType;
if (member instanceof JetProperty) { if (member instanceof JetProperty) {
hasDeferredType = ((JetProperty) member).getTypeRef() == null && DescriptorResolver.hasBody((JetProperty) member); hasDeferredType = ((JetProperty) member).getTypeReference() == null && DescriptorResolver.hasBody((JetProperty) member);
} }
else { else {
assert member instanceof JetFunction; assert member instanceof JetFunction;
JetFunction function = (JetFunction) member; JetFunction function = (JetFunction) member;
hasDeferredType = function.getReturnTypeRef() == null && function.hasBody() && !function.hasBlockBody(); hasDeferredType = function.getTypeReference() == null && function.hasBody() && !function.hasBlockBody();
} }
if ((memberDescriptor.getVisibility().isPublicAPI()) && memberDescriptor.getOverriddenDescriptors().size() == 0 && hasDeferredType) { if ((memberDescriptor.getVisibility().isPublicAPI()) && memberDescriptor.getOverriddenDescriptors().size() == 0 && hasDeferredType) {
trace.report(PUBLIC_MEMBER_SHOULD_SPECIFY_TYPE.on(member)); trace.report(PUBLIC_MEMBER_SHOULD_SPECIFY_TYPE.on(member));
@@ -425,7 +425,7 @@ public class DeclarationsChecker {
(setter != null && setter.hasBody()); (setter != null && setter.hasBody());
if (propertyDescriptor.getModality() == Modality.ABSTRACT) { if (propertyDescriptor.getModality() == Modality.ABSTRACT) {
if (!property.hasDelegateExpressionOrInitializer() && property.getTypeRef() == null) { if (!property.hasDelegateExpressionOrInitializer() && property.getTypeReference() == null) {
trace.report(PROPERTY_WITH_NO_TYPE_NO_INITIALIZER.on(property)); trace.report(PROPERTY_WITH_NO_TYPE_NO_INITIALIZER.on(property));
} }
return; return;
@@ -454,7 +454,7 @@ public class DeclarationsChecker {
trace.report(MUST_BE_INITIALIZED_OR_BE_ABSTRACT.on(property)); trace.report(MUST_BE_INITIALIZED_OR_BE_ABSTRACT.on(property));
} }
} }
if (!error && property.getTypeRef() == null) { if (!error && property.getTypeReference() == null) {
trace.report(PROPERTY_WITH_NO_TYPE_NO_INITIALIZER.on(property)); trace.report(PROPERTY_WITH_NO_TYPE_NO_INITIALIZER.on(property));
} }
if (inTrait && property.hasModifier(JetTokens.FINAL_KEYWORD) && backingFieldRequired) { if (inTrait && property.hasModifier(JetTokens.FINAL_KEYWORD) && backingFieldRequired) {
@@ -302,7 +302,7 @@ public class DelegatedPropertyResolver {
@NotNull final JetScope accessorScope, @NotNull final JetScope accessorScope,
@NotNull final BindingTrace trace @NotNull final BindingTrace trace
) { ) {
final JetType expectedType = property.getTypeRef() != null ? propertyDescriptor.getType() : NO_EXPECTED_TYPE; final JetType expectedType = property.getTypeReference() != null ? propertyDescriptor.getType() : NO_EXPECTED_TYPE;
return new ConstraintSystemCompleter() { return new ConstraintSystemCompleter() {
@Override @Override
public void completeConstraintSystem( public void completeConstraintSystem(
@@ -331,7 +331,7 @@ public class DescriptorResolver {
innerScope.changeLockLevel(WritableScope.LockLevel.READING); innerScope.changeLockLevel(WritableScope.LockLevel.READING);
JetTypeReference returnTypeRef = function.getReturnTypeRef(); JetTypeReference returnTypeRef = function.getTypeReference();
JetType returnType; JetType returnType;
if (returnTypeRef != null) { if (returnTypeRef != null) {
returnType = typeResolver.resolveType(innerScope, returnTypeRef, trace, true); returnType = typeResolver.resolveType(innerScope, returnTypeRef, trace, true);
@@ -1005,7 +1005,7 @@ public class DescriptorResolver {
boolean notLocal, boolean notLocal,
@NotNull final BindingTrace trace @NotNull final BindingTrace trace
) { ) {
JetTypeReference propertyTypeRef = variable.getTypeRef(); JetTypeReference propertyTypeRef = variable.getTypeReference();
boolean hasDelegate = variable instanceof JetProperty && ((JetProperty) variable).hasDelegateExpression(); boolean hasDelegate = variable instanceof JetProperty && ((JetProperty) variable).hasDelegateExpression();
if (propertyTypeRef == null) { if (propertyTypeRef == null) {
@@ -41,7 +41,6 @@ import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
import javax.inject.Inject; import javax.inject.Inject;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Set;
import static org.jetbrains.jet.lang.resolve.BindingContextUtils.getRecordedTypeInfo; import static org.jetbrains.jet.lang.resolve.BindingContextUtils.getRecordedTypeInfo;
import static org.jetbrains.jet.lang.resolve.calls.CallResolverUtil.ResolveArgumentsMode; import static org.jetbrains.jet.lang.resolve.calls.CallResolverUtil.ResolveArgumentsMode;
@@ -211,7 +210,7 @@ public class ArgumentTypeResolver {
parameterTypes.add(resolveTypeRefWithDefault(parameter.getTypeReference(), scope, temporaryTrace, DONT_CARE)); parameterTypes.add(resolveTypeRefWithDefault(parameter.getTypeReference(), scope, temporaryTrace, DONT_CARE));
} }
JetFunctionLiteral functionLiteral = expression.getFunctionLiteral(); JetFunctionLiteral functionLiteral = expression.getFunctionLiteral();
JetType returnType = resolveTypeRefWithDefault(functionLiteral.getReturnTypeRef(), scope, temporaryTrace, DONT_CARE); JetType returnType = resolveTypeRefWithDefault(functionLiteral.getTypeReference(), scope, temporaryTrace, DONT_CARE);
assert returnType != null; assert returnType != null;
JetType receiverType = resolveTypeRefWithDefault(functionLiteral.getReceiverTypeRef(), scope, temporaryTrace, null); JetType receiverType = resolveTypeRefWithDefault(functionLiteral.getReceiverTypeRef(), scope, temporaryTrace, null);
return KotlinBuiltIns.getInstance().getFunctionType(Annotations.EMPTY, receiverType, parameterTypes, return KotlinBuiltIns.getInstance().getFunctionType(Annotations.EMPTY, receiverType, parameterTypes,
@@ -48,6 +48,6 @@ public fun shouldBeScriptClassMember(declaration: JetDeclaration): Boolean {
// To avoid the necessity to always analyze the whole body of a script even if just its class descriptor is needed // To avoid the necessity to always analyze the whole body of a script even if just its class descriptor is needed
// we only add those vals, vars and funs that have explicitly specified return types // we only add those vals, vars and funs that have explicitly specified return types
// (or implicit Unit for function with block body) // (or implicit Unit for function with block body)
return declaration is JetCallableDeclaration && declaration.getReturnTypeRef() != null return declaration is JetCallableDeclaration && declaration.getTypeReference() != null
|| declaration is JetNamedFunction && declaration.hasBlockBody() || declaration is JetNamedFunction && declaration.hasBlockBody()
} }
@@ -275,7 +275,7 @@ public class ClosureExpressionsTypingVisitor extends ExpressionTypingVisitor {
assert bodyExpression != null; assert bodyExpression != null;
JetScope functionInnerScope = FunctionDescriptorUtil.getFunctionInnerScope(context.scope, functionDescriptor, context.trace); JetScope functionInnerScope = FunctionDescriptorUtil.getFunctionInnerScope(context.scope, functionDescriptor, context.trace);
JetTypeReference returnTypeRef = functionLiteral.getReturnTypeRef(); JetTypeReference returnTypeRef = functionLiteral.getTypeReference();
JetType declaredReturnType = null; JetType declaredReturnType = null;
if (returnTypeRef != null) { if (returnTypeRef != null) {
declaredReturnType = components.expressionTypingServices.getTypeResolver().resolveType(context.scope, returnTypeRef, context.trace, true); declaredReturnType = components.expressionTypingServices.getTypeResolver().resolveType(context.scope, returnTypeRef, context.trace, true);
@@ -517,7 +517,7 @@ public class ControlStructureTypingVisitor extends ExpressionTypingVisitor {
private static JetType getFunctionExpectedReturnType(@NotNull FunctionDescriptor descriptor, @NotNull JetElement function) { private static JetType getFunctionExpectedReturnType(@NotNull FunctionDescriptor descriptor, @NotNull JetElement function) {
JetType expectedType; JetType expectedType;
if (function instanceof JetFunction) { if (function instanceof JetFunction) {
if (((JetFunction) function).getReturnTypeRef() != null || ((JetFunction) function).hasBlockBody()) { if (((JetFunction) function).getTypeReference() != null || ((JetFunction) function).hasBlockBody()) {
expectedType = descriptor.getReturnType(); expectedType = descriptor.getReturnType();
} }
else { else {
@@ -391,7 +391,7 @@ public class ExpressionTypingUtils {
@NotNull @NotNull
private JetType getExpectedTypeForComponent(ExpressionTypingContext context, JetMultiDeclarationEntry entry) { private JetType getExpectedTypeForComponent(ExpressionTypingContext context, JetMultiDeclarationEntry entry) {
JetTypeReference entryTypeRef = entry.getTypeRef(); JetTypeReference entryTypeRef = entry.getTypeReference();
if (entryTypeRef != null) { if (entryTypeRef != null) {
return expressionTypingServices.getTypeResolver().resolveType(context.scope, entryTypeRef, context.trace, true); return expressionTypingServices.getTypeResolver().resolveType(context.scope, entryTypeRef, context.trace, true);
} }
@@ -60,7 +60,7 @@ public class RemoveExplicitTypeArguments : JetSelfTargetingIntention<JetTypeArgu
// therefore we should resolve outer call with erased type arguments for inner call // therefore we should resolve outer call with erased type arguments for inner call
val parent = callExpression.getParent() val parent = callExpression.getParent()
val expectedTypeIsExplicitInCode = when (parent) { val expectedTypeIsExplicitInCode = when (parent) {
is JetProperty -> parent.getInitializer() == callExpression && parent.getTypeRef() != null is JetProperty -> parent.getInitializer() == callExpression && parent.getTypeReference() != null
is JetDeclarationWithBody -> parent.getBodyExpression() == callExpression is JetDeclarationWithBody -> parent.getBodyExpression() == callExpression
is JetReturnExpression -> true is JetReturnExpression -> true
else -> false else -> false
@@ -125,7 +125,7 @@ public class MoveDeclarationsOutHelper {
@NotNull @NotNull
private static JetProperty createProperty(@NotNull JetProperty property, @NotNull JetType propertyType, @Nullable String initializer) { private static JetProperty createProperty(@NotNull JetProperty property, @NotNull JetType propertyType, @Nullable String initializer) {
JetTypeReference typeRef = property.getTypeRef(); JetTypeReference typeRef = property.getTypeReference();
String typeString = null; String typeString = null;
if (typeRef != null) { if (typeRef != null) {
typeString = typeRef.getText(); typeString = typeRef.getText();
@@ -75,7 +75,7 @@ public class JetDeclarationMover extends AbstractJetUpDownMover {
JetTypeReference receiverTypeRef = function.getReceiverTypeRef(); JetTypeReference receiverTypeRef = function.getReceiverTypeRef();
if (receiverTypeRef != null) memberSuspects.add(receiverTypeRef); if (receiverTypeRef != null) memberSuspects.add(receiverTypeRef);
JetTypeReference returnTypeRef = function.getReturnTypeRef(); JetTypeReference returnTypeRef = function.getTypeReference();
if (returnTypeRef != null) memberSuspects.add(returnTypeRef); if (returnTypeRef != null) memberSuspects.add(returnTypeRef);
} }
@@ -90,7 +90,7 @@ public class JetDeclarationMover extends AbstractJetUpDownMover {
JetTypeReference receiverTypeRef = property.getReceiverTypeRef(); JetTypeReference receiverTypeRef = property.getReceiverTypeRef();
if (receiverTypeRef != null) memberSuspects.add(receiverTypeRef); if (receiverTypeRef != null) memberSuspects.add(receiverTypeRef);
JetTypeReference returnTypeRef = property.getTypeRef(); JetTypeReference returnTypeRef = property.getTypeReference();
if (returnTypeRef != null) memberSuspects.add(returnTypeRef); if (returnTypeRef != null) memberSuspects.add(returnTypeRef);
} }
} }
@@ -46,7 +46,7 @@ public object JetKeywordInsertHandler : InsertHandler<LookupElement> {
val element = context.getFile().findElementAt(context.getStartOffset()) val element = context.getFile().findElementAt(context.getStartOffset())
if (element != null) { if (element != null) {
val jetFunction = PsiTreeUtil.getParentOfType(element, javaClass<JetFunction>()) val jetFunction = PsiTreeUtil.getParentOfType(element, javaClass<JetFunction>())
if (jetFunction != null && (!jetFunction.hasDeclaredReturnType() || JetPsiUtil.isVoidType(jetFunction.getReturnTypeRef()))) { if (jetFunction != null && (!jetFunction.hasDeclaredReturnType() || JetPsiUtil.isVoidType(jetFunction.getTypeReference()))) {
// No space for void function // No space for void function
return return
} }
@@ -161,8 +161,8 @@ class SmartCompletion(val expression: JetSimpleNameExpression,
private fun implicitlyTypedDeclarationFromInitializer(expression: JetExpression): JetDeclaration? { private fun implicitlyTypedDeclarationFromInitializer(expression: JetExpression): JetDeclaration? {
val parent = expression.getParent() val parent = expression.getParent()
when (parent) { when (parent) {
is JetVariableDeclaration -> if (expression == parent.getInitializer() && parent.getTypeRef() == null) return parent is JetVariableDeclaration -> if (expression == parent.getInitializer() && parent.getTypeReference() == null) return parent
is JetNamedFunction -> if (expression == parent.getInitializer() && parent.getReturnTypeRef() == null) return parent is JetNamedFunction -> if (expression == parent.getInitializer() && parent.getTypeReference() == null) return parent
} }
return null return null
} }
@@ -61,7 +61,7 @@ public object JetUsageTypeProvider : UsageTypeProviderEx {
val property = refExpr.getParentByType(javaClass<JetProperty>()) val property = refExpr.getParentByType(javaClass<JetProperty>())
if (property != null) { if (property != null) {
when { when {
property.getTypeRef().isAncestor(refExpr) -> property.getTypeReference().isAncestor(refExpr) ->
return if (property.isLocal()) UsageType.CLASS_LOCAL_VAR_DECLARATION else JetUsageTypes.NON_LOCAL_PROPERTY_TYPE return if (property.isLocal()) UsageType.CLASS_LOCAL_VAR_DECLARATION else JetUsageTypes.NON_LOCAL_PROPERTY_TYPE
property.getReceiverTypeRef().isAncestor(refExpr) -> property.getReceiverTypeRef().isAncestor(refExpr) ->
@@ -72,7 +72,7 @@ public object JetUsageTypeProvider : UsageTypeProviderEx {
val function = refExpr.getParentByType(javaClass<JetFunction>()) val function = refExpr.getParentByType(javaClass<JetFunction>())
if (function != null) { if (function != null) {
when { when {
function.getReturnTypeRef().isAncestor(refExpr) -> function.getTypeReference().isAncestor(refExpr) ->
return JetUsageTypes.FUNCTION_RETURN_TYPE return JetUsageTypes.FUNCTION_RETURN_TYPE
function.getReceiverTypeRef().isAncestor(refExpr) -> function.getReceiverTypeRef().isAncestor(refExpr) ->
return JetUsageTypes.EXTENSION_RECEIVER_TYPE return JetUsageTypes.EXTENSION_RECEIVER_TYPE
@@ -90,7 +90,7 @@ public class MakeTypeExplicitInLambdaIntention : JetSelfTargetingIntention<JetFu
val returnTypeExpr = psiFactory.createType(DescriptorRenderer.SOURCE_CODE.renderType(expectedReturnType)) val returnTypeExpr = psiFactory.createType(DescriptorRenderer.SOURCE_CODE.renderType(expectedReturnType))
functionLiteral.addAfter(returnTypeExpr, paramList) functionLiteral.addAfter(returnTypeExpr, paramList)
functionLiteral.addAfter(returnTypeColon, paramList) functionLiteral.addAfter(returnTypeColon, paramList)
ShortenReferences.process(functionLiteral.getReturnTypeRef()!!) ShortenReferences.process(functionLiteral.getTypeReference()!!)
} }
// Step 3: make the receiver type explicit // Step 3: make the receiver type explicit
@@ -70,11 +70,11 @@ public class SpecifyTypeExplicitlyAction extends PsiElementBaseIntentionAction {
JetType type = getTypeForDeclaration((JetNamedDeclaration) parent); JetType type = getTypeForDeclaration((JetNamedDeclaration) parent);
if (parent instanceof JetProperty) { if (parent instanceof JetProperty) {
JetProperty property = (JetProperty) parent; JetProperty property = (JetProperty) parent;
if (property.getTypeRef() == null) { if (property.getTypeReference() == null) {
addTypeAnnotation(project, editor, property, type); addTypeAnnotation(project, editor, property, type);
} }
else { else {
property.setTypeRef(null); property.setTypeReference(null);
} }
} }
else if (parent instanceof JetParameter) { else if (parent instanceof JetParameter) {
@@ -88,7 +88,7 @@ public class SpecifyTypeExplicitlyAction extends PsiElementBaseIntentionAction {
} }
else if (parent instanceof JetNamedFunction) { else if (parent instanceof JetNamedFunction) {
JetNamedFunction function = (JetNamedFunction) parent; JetNamedFunction function = (JetNamedFunction) parent;
assert function.getReturnTypeRef() == null; assert function.getTypeReference() == null;
addTypeAnnotation(project, editor, function, type); addTypeAnnotation(project, editor, function, type);
} }
else { else {
@@ -113,7 +113,7 @@ public class SpecifyTypeExplicitlyAction extends PsiElementBaseIntentionAction {
JetNamedDeclaration declaration = (JetNamedDeclaration) parent; JetNamedDeclaration declaration = (JetNamedDeclaration) parent;
if (declaration instanceof JetProperty && !PsiTreeUtil.isAncestor(((JetProperty) declaration).getInitializer(), element, false)) { if (declaration instanceof JetProperty && !PsiTreeUtil.isAncestor(((JetProperty) declaration).getInitializer(), element, false)) {
if (((JetProperty) declaration).getTypeRef() != null) { if (((JetProperty) declaration).getTypeReference() != null) {
setText(JetBundle.message("specify.type.explicitly.remove.action.name")); setText(JetBundle.message("specify.type.explicitly.remove.action.name"));
return true; return true;
} }
@@ -121,7 +121,7 @@ public class SpecifyTypeExplicitlyAction extends PsiElementBaseIntentionAction {
setText(JetBundle.message("specify.type.explicitly.add.action.name")); setText(JetBundle.message("specify.type.explicitly.add.action.name"));
} }
} }
else if (declaration instanceof JetNamedFunction && ((JetNamedFunction) declaration).getReturnTypeRef() == null else if (declaration instanceof JetNamedFunction && ((JetNamedFunction) declaration).getTypeReference() == null
&& !((JetNamedFunction) declaration).hasBlockBody()) { && !((JetNamedFunction) declaration).hasBlockBody()) {
setText(JetBundle.message("specify.type.explicitly.add.return.type.action.name")); setText(JetBundle.message("specify.type.explicitly.add.return.type.action.name"));
} }
@@ -181,7 +181,7 @@ public class SpecifyTypeExplicitlyAction extends PsiElementBaseIntentionAction {
@NotNull JetProperty property, @NotNull JetProperty property,
@NotNull JetType exprType @NotNull JetType exprType
) { ) {
if (property.getTypeRef() != null) return; if (property.getTypeReference() != null) return;
addTypeAnnotationWithTemplate(project, editor, property, exprType); addTypeAnnotationWithTemplate(project, editor, property, exprType);
} }
@@ -191,7 +191,7 @@ public class SpecifyTypeExplicitlyAction extends PsiElementBaseIntentionAction {
addTypeAnnotationWithTemplate(project, editor, function, exprType); addTypeAnnotationWithTemplate(project, editor, function, exprType);
} }
else { else {
function.setReturnTypeRef(anyTypeRef(project)); function.setTypeReference(anyTypeRef(project));
} }
} }
@@ -265,13 +265,13 @@ public class SpecifyTypeExplicitlyAction extends PsiElementBaseIntentionAction {
@Nullable @Nullable
private static JetTypeReference getTypeRef(@NotNull JetNamedDeclaration namedDeclaration) { private static JetTypeReference getTypeRef(@NotNull JetNamedDeclaration namedDeclaration) {
if (namedDeclaration instanceof JetProperty) { if (namedDeclaration instanceof JetProperty) {
return ((JetProperty) namedDeclaration).getTypeRef(); return ((JetProperty) namedDeclaration).getTypeReference();
} }
else if (namedDeclaration instanceof JetParameter) { else if (namedDeclaration instanceof JetParameter) {
return ((JetParameter) namedDeclaration).getTypeReference(); return ((JetParameter) namedDeclaration).getTypeReference();
} }
else if (namedDeclaration instanceof JetFunction) { else if (namedDeclaration instanceof JetFunction) {
return ((JetFunction) namedDeclaration).getReturnTypeRef(); return ((JetFunction) namedDeclaration).getTypeReference();
} }
assert false : "Wrong namedDeclaration: " + namedDeclaration.getText(); assert false : "Wrong namedDeclaration: " + namedDeclaration.getText();
return null; return null;
@@ -280,13 +280,13 @@ public class SpecifyTypeExplicitlyAction extends PsiElementBaseIntentionAction {
@Nullable @Nullable
private static JetTypeReference setTypeRef(@NotNull JetNamedDeclaration namedDeclaration, @Nullable JetTypeReference typeRef) { private static JetTypeReference setTypeRef(@NotNull JetNamedDeclaration namedDeclaration, @Nullable JetTypeReference typeRef) {
if (namedDeclaration instanceof JetProperty) { if (namedDeclaration instanceof JetProperty) {
return ((JetProperty) namedDeclaration).setTypeRef(typeRef); return ((JetProperty) namedDeclaration).setTypeReference(typeRef);
} }
else if (namedDeclaration instanceof JetParameter) { else if (namedDeclaration instanceof JetParameter) {
return ((JetParameter) namedDeclaration).setTypeRef(typeRef); return ((JetParameter) namedDeclaration).setTypeRef(typeRef);
} }
else if (namedDeclaration instanceof JetFunction) { else if (namedDeclaration instanceof JetFunction) {
return ((JetFunction) namedDeclaration).setReturnTypeRef(typeRef); return ((JetFunction) namedDeclaration).setTypeReference(typeRef);
} }
assert false : "Wrong namedDeclaration: " + namedDeclaration.getText(); assert false : "Wrong namedDeclaration: " + namedDeclaration.getText();
return null; return null;
@@ -34,7 +34,7 @@ fun specifyTypeExplicitly(declaration: JetNamedFunction, `type`: JetType) {
if (`type`.isError()) return if (`type`.isError()) return
val typeReference = JetPsiFactory(declaration).createType(DescriptorRenderer.SOURCE_CODE.renderType(`type`)) val typeReference = JetPsiFactory(declaration).createType(DescriptorRenderer.SOURCE_CODE.renderType(`type`))
specifyTypeExplicitly(declaration, typeReference) specifyTypeExplicitly(declaration, typeReference)
ShortenReferences.process(declaration.getReturnTypeRef()!!) ShortenReferences.process(declaration.getTypeReference()!!)
} }
fun specifyTypeExplicitly(declaration: JetNamedFunction, typeReference: JetTypeReference) { fun specifyTypeExplicitly(declaration: JetNamedFunction, typeReference: JetTypeReference) {
@@ -104,7 +104,7 @@ public class ConvertMemberToExtension extends BaseIntentionAction {
String name = identifier == null ? "" : identifier.getText(); String name = identifier == null ? "" : identifier.getText();
JetParameterList valueParameterList = member.getValueParameterList(); JetParameterList valueParameterList = member.getValueParameterList();
JetTypeReference returnTypeRef = member.getReturnTypeRef(); JetTypeReference returnTypeRef = member.getTypeReference();
String extensionText = modifiers(member) + String extensionText = modifiers(member) +
memberType(member) + " " + memberType(member) + " " +
@@ -42,7 +42,7 @@ public class DeclarationUtils {
@Nullable @Nullable
private static JetType getPropertyTypeIfNeeded(@NotNull JetProperty property) { private static JetType getPropertyTypeIfNeeded(@NotNull JetProperty property) {
if (property.getTypeRef() != null) return null; if (property.getTypeReference() != null) return null;
JetType type = AnalyzerFacadeWithCache.getContextForElement(property).get( JetType type = AnalyzerFacadeWithCache.getContextForElement(property).get(
BindingContext.EXPRESSION_TYPE, property.getInitializer() BindingContext.EXPRESSION_TYPE, property.getInitializer()
@@ -74,7 +74,7 @@ public class DeclarationUtils {
String typeStr = inferredType != null String typeStr = inferredType != null
? DescriptorRenderer.FQ_NAMES_IN_TYPES.renderType(inferredType) ? DescriptorRenderer.FQ_NAMES_IN_TYPES.renderType(inferredType)
: JetPsiUtil.getNullableText(property.getTypeRef()); : JetPsiUtil.getNullableText(property.getTypeReference());
//noinspection ConstantConditions //noinspection ConstantConditions
property = (JetProperty) property.replace( property = (JetProperty) property.replace(
@@ -82,7 +82,7 @@ public class DeclarationUtils {
); );
if (inferredType != null) { if (inferredType != null) {
ShortenReferences.INSTANCE$.process(property.getTypeRef()); ShortenReferences.INSTANCE$.process(property.getTypeReference());
} }
return newInitializer; return newInitializer;
@@ -59,7 +59,7 @@ public class JetDeclarationTreeNode extends AbstractPsiBasedNode<JetDeclaration>
if (declaration instanceof JetProperty) { if (declaration instanceof JetProperty) {
JetProperty property = (JetProperty) declaration; JetProperty property = (JetProperty) declaration;
JetTypeReference ref = property.getTypeRef(); JetTypeReference ref = property.getTypeReference();
if (ref != null) { if (ref != null) {
if (settings.SPACE_BEFORE_TYPE_COLON) text += " "; if (settings.SPACE_BEFORE_TYPE_COLON) text += " ";
text += ":"; text += ":";
@@ -90,7 +90,7 @@ public class JetDeclarationTreeNode extends AbstractPsiBasedNode<JetDeclaration>
} }
if (parameters.size() > 0) text = text.substring(0, text.length() - 2); if (parameters.size() > 0) text = text.substring(0, text.length() - 2);
text += ")"; text += ")";
JetTypeReference typeReference = function.getReturnTypeRef(); JetTypeReference typeReference = function.getTypeReference();
if (typeReference != null) { if (typeReference != null) {
if (settings.SPACE_BEFORE_TYPE_COLON) text += " "; if (settings.SPACE_BEFORE_TYPE_COLON) text += " ";
text += ":"; text += ":";
@@ -53,7 +53,7 @@ public class ChangeFunctionLiteralReturnTypeFix extends JetIntentionAction<JetFu
public ChangeFunctionLiteralReturnTypeFix(@NotNull JetFunctionLiteralExpression functionLiteralExpression, @NotNull JetType type) { public ChangeFunctionLiteralReturnTypeFix(@NotNull JetFunctionLiteralExpression functionLiteralExpression, @NotNull JetType type) {
super(functionLiteralExpression); super(functionLiteralExpression);
renderedType = DescriptorRenderer.SHORT_NAMES_IN_TYPES.renderType(type); renderedType = DescriptorRenderer.SHORT_NAMES_IN_TYPES.renderType(type);
functionLiteralReturnTypeRef = functionLiteralExpression.getFunctionLiteral().getReturnTypeRef(); functionLiteralReturnTypeRef = functionLiteralExpression.getFunctionLiteral().getTypeReference();
BindingContext context = ResolvePackage.getBindingContext(functionLiteralExpression.getContainingJetFile()); BindingContext context = ResolvePackage.getBindingContext(functionLiteralExpression.getContainingJetFile());
JetType functionLiteralType = context.get(BindingContext.EXPRESSION_TYPE, functionLiteralExpression); JetType functionLiteralType = context.get(BindingContext.EXPRESSION_TYPE, functionLiteralExpression);
@@ -71,7 +71,7 @@ public class ChangeFunctionLiteralReturnTypeFix extends JetIntentionAction<JetFu
JetProperty correspondingProperty = PsiTreeUtil.getParentOfType(functionLiteralExpression, JetProperty.class); JetProperty correspondingProperty = PsiTreeUtil.getParentOfType(functionLiteralExpression, JetProperty.class);
if (correspondingProperty != null && QuickFixUtil.canEvaluateTo(correspondingProperty.getInitializer(), functionLiteralExpression)) { if (correspondingProperty != null && QuickFixUtil.canEvaluateTo(correspondingProperty.getInitializer(), functionLiteralExpression)) {
JetTypeReference correspondingPropertyTypeRef = correspondingProperty.getTypeRef(); JetTypeReference correspondingPropertyTypeRef = correspondingProperty.getTypeReference();
JetType propertyType = context.get(BindingContext.TYPE, correspondingPropertyTypeRef); JetType propertyType = context.get(BindingContext.TYPE, correspondingPropertyTypeRef);
if (propertyType != null && !JetTypeChecker.DEFAULT.isSubtypeOf(eventualFunctionLiteralType, propertyType)) { if (propertyType != null && !JetTypeChecker.DEFAULT.isSubtypeOf(eventualFunctionLiteralType, propertyType)) {
appropriateQuickFix = new ChangeVariableTypeFix(correspondingProperty, eventualFunctionLiteralType); appropriateQuickFix = new ChangeVariableTypeFix(correspondingProperty, eventualFunctionLiteralType);
@@ -97,7 +97,7 @@ public class ChangeFunctionLiteralReturnTypeFix extends JetIntentionAction<JetFu
JetFunction parentFunction = PsiTreeUtil.getParentOfType(functionLiteralExpression, JetFunction.class, true); JetFunction parentFunction = PsiTreeUtil.getParentOfType(functionLiteralExpression, JetFunction.class, true);
if (parentFunction != null && QuickFixUtil.canFunctionOrGetterReturnExpression(parentFunction, functionLiteralExpression)) { if (parentFunction != null && QuickFixUtil.canFunctionOrGetterReturnExpression(parentFunction, functionLiteralExpression)) {
JetTypeReference parentFunctionReturnTypeRef = parentFunction.getReturnTypeRef(); JetTypeReference parentFunctionReturnTypeRef = parentFunction.getTypeReference();
JetType parentFunctionReturnType = context.get(BindingContext.TYPE, parentFunctionReturnTypeRef); JetType parentFunctionReturnType = context.get(BindingContext.TYPE, parentFunctionReturnTypeRef);
if (parentFunctionReturnType != null && !JetTypeChecker.DEFAULT.isSubtypeOf(eventualFunctionLiteralType, parentFunctionReturnType)) { if (parentFunctionReturnType != null && !JetTypeChecker.DEFAULT.isSubtypeOf(eventualFunctionLiteralType, parentFunctionReturnType)) {
appropriateQuickFix = new ChangeFunctionReturnTypeFix(parentFunction, eventualFunctionLiteralType); appropriateQuickFix = new ChangeFunctionReturnTypeFix(parentFunction, eventualFunctionLiteralType);
@@ -108,10 +108,10 @@ public class ChangeFunctionReturnTypeFix extends JetIntentionAction<JetFunction>
} }
else { else {
if (!(KotlinBuiltIns.getInstance().isUnit(type) && element.hasBlockBody())) { if (!(KotlinBuiltIns.getInstance().isUnit(type) && element.hasBlockBody())) {
element.setReturnTypeRef(JetPsiFactory(project).createType(renderedType)); element.setTypeReference(JetPsiFactory(project).createType(renderedType));
} }
else { else {
element.setReturnTypeRef(null); element.setTypeReference(null);
} }
} }
} }
@@ -137,7 +137,7 @@ public class ChangeFunctionReturnTypeFix extends JetIntentionAction<JetFunction>
if (resolvedCall == null) return null; if (resolvedCall == null) return null;
JetFunction componentFunction = (JetFunction) DescriptorToSourceUtils JetFunction componentFunction = (JetFunction) DescriptorToSourceUtils
.descriptorToDeclaration(resolvedCall.getCandidateDescriptor()); .descriptorToDeclaration(resolvedCall.getCandidateDescriptor());
JetType expectedType = context.get(BindingContext.TYPE, entry.getTypeRef()); JetType expectedType = context.get(BindingContext.TYPE, entry.getTypeReference());
if (componentFunction != null && expectedType != null) { if (componentFunction != null && expectedType != null) {
return new ChangeFunctionReturnTypeFix(componentFunction, expectedType); return new ChangeFunctionReturnTypeFix(componentFunction, expectedType);
} }
@@ -371,7 +371,7 @@ public class ChangeMemberFunctionSignatureFix extends JetHintAction<JetNamedFunc
public void run() { public void run() {
JetNamedFunction patternFunction = psiFactory.createFunction(signatureString); JetNamedFunction patternFunction = psiFactory.createFunction(signatureString);
JetTypeReference newTypeRef = function.setReturnTypeRef(patternFunction.getReturnTypeRef()); JetTypeReference newTypeRef = function.setTypeReference(patternFunction.getTypeReference());
if (newTypeRef != null) { if (newTypeRef != null) {
ShortenReferences.INSTANCE$.process(newTypeRef); ShortenReferences.INSTANCE$.process(newTypeRef);
} }
@@ -81,7 +81,7 @@ public class ChangeVariableTypeFix extends JetIntentionAction<JetVariableDeclara
@Override @Override
public void invoke(@NotNull Project project, Editor editor, JetFile file) throws IncorrectOperationException { public void invoke(@NotNull Project project, Editor editor, JetFile file) throws IncorrectOperationException {
element.setTypeRef(null); element.setTypeReference(null);
PsiElement nameIdentifier = element.getNameIdentifier(); PsiElement nameIdentifier = element.getNameIdentifier();
assert nameIdentifier != null : "ChangeVariableTypeFix applied to variable without name"; assert nameIdentifier != null : "ChangeVariableTypeFix applied to variable without name";
JetPsiFactory psiFactory = JetPsiFactory(file); JetPsiFactory psiFactory = JetPsiFactory(file);
@@ -109,7 +109,7 @@ public class RemovePartsFromPropertyFix extends JetIntentionAction<JetProperty>
assert nextSibling != null; assert nextSibling != null;
newElement.deleteChildRange(nextSibling, initializer); newElement.deleteChildRange(nextSibling, initializer);
if (newElement.getTypeRef() == null && type != null) { if (newElement.getTypeReference() == null && type != null) {
typeToAdd = type; typeToAdd = type;
} }
} }
@@ -379,7 +379,7 @@ class CallableBuilder(val config: CallableBuilderConfiguration) {
} }
if (returnTypeExpression != null) { if (returnTypeExpression != null) {
val returnTypeRef = declaration.getReturnTypeRef() val returnTypeRef = declaration.getTypeReference()
if (returnTypeRef != null) { if (returnTypeRef != null) {
val returnType = returnTypeExpression.getTypeFromSelection( val returnType = returnTypeExpression.getTypeFromSelection(
returnTypeRef.getText() returnTypeRef.getText()
@@ -388,7 +388,7 @@ class CallableBuilder(val config: CallableBuilderConfiguration) {
if (returnType != null) { if (returnType != null) {
// user selected a given type // user selected a given type
replaceWithLongerName(returnTypeRef, returnType) replaceWithLongerName(returnTypeRef, returnType)
typeRefsToShorten.add(declaration.getReturnTypeRef()!!) typeRefsToShorten.add(declaration.getTypeReference()!!)
} }
} }
} }
@@ -420,7 +420,7 @@ class CallableBuilder(val config: CallableBuilderConfiguration) {
private fun setupFunctionBody(func: JetNamedFunction) { private fun setupFunctionBody(func: JetNamedFunction) {
val fileTemplate = FileTemplateManager.getInstance()!!.getCodeTemplate(TEMPLATE_FROM_USAGE_FUNCTION_BODY) val fileTemplate = FileTemplateManager.getInstance()!!.getCodeTemplate(TEMPLATE_FROM_USAGE_FUNCTION_BODY)
val properties = Properties() val properties = Properties()
properties.setProperty(FileTemplate.ATTRIBUTE_RETURN_TYPE, if (isUnit) "Unit" else func.getReturnTypeRef()!!.getText()) properties.setProperty(FileTemplate.ATTRIBUTE_RETURN_TYPE, if (isUnit) "Unit" else func.getTypeReference()!!.getText())
receiverClassDescriptor?.let { receiverClassDescriptor?.let {
properties.setProperty(FileTemplate.ATTRIBUTE_CLASS_NAME, DescriptorUtils.getFqName(it).asString()) properties.setProperty(FileTemplate.ATTRIBUTE_CLASS_NAME, DescriptorUtils.getFqName(it).asString())
properties.setProperty(FileTemplate.ATTRIBUTE_SIMPLE_CLASS_NAME, it.getName().asString()) properties.setProperty(FileTemplate.ATTRIBUTE_SIMPLE_CLASS_NAME, it.getName().asString())
@@ -444,7 +444,7 @@ class CallableBuilder(val config: CallableBuilderConfiguration) {
} }
private fun setupReturnTypeTemplate(builder: TemplateBuilder, declaration: JetCallableDeclaration): TypeExpression? { private fun setupReturnTypeTemplate(builder: TemplateBuilder, declaration: JetCallableDeclaration): TypeExpression? {
val returnTypeRef = declaration.getReturnTypeRef() ?: return null val returnTypeRef = declaration.getTypeReference() ?: return null
val candidates = typeCandidates[config.callableInfo.returnTypeInfo]!! val candidates = typeCandidates[config.callableInfo.returnTypeInfo]!!
return when (candidates.size) { return when (candidates.size) {
0 -> null 0 -> null
@@ -476,7 +476,7 @@ class CallableBuilder(val config: CallableBuilderConfiguration) {
typeParameterMap[it.renderedType!!] = it.typeParameterNames!! typeParameterMap[it.renderedType!!] = it.typeParameterNames!!
} }
if (declaration.getReturnTypeRef() != null) { if (declaration.getTypeReference() != null) {
typeCandidates[config.callableInfo.returnTypeInfo]!!.forEach { typeCandidates[config.callableInfo.returnTypeInfo]!!.forEach {
typeParameterMap[it.renderedType!!] = it.typeParameterNames!! typeParameterMap[it.renderedType!!] = it.typeParameterNames!!
} }
@@ -124,7 +124,7 @@ private class TypeParameterListExpression(private val typeParameterNamesFromRece
} }
} }
} }
val returnTypeRef = func.getReturnTypeRef() val returnTypeRef = func.getTypeReference()
if (returnTypeRef != null) { if (returnTypeRef != null) {
val typeParameterNamesFromReturnType = parameterTypeToTypeParameterNamesMap[returnTypeRef.getText()] val typeParameterNamesFromReturnType = parameterTypeToTypeParameterNamesMap[returnTypeRef.getText()]
if (typeParameterNamesFromReturnType != null) { if (typeParameterNamesFromReturnType != null) {
@@ -97,7 +97,7 @@ fun JetExpression.guessTypes(context: BindingContext): Array<JetType> {
} }
this is JetMultiDeclarationEntry -> { this is JetMultiDeclarationEntry -> {
// expression is on the lhs of a multi-declaration // expression is on the lhs of a multi-declaration
val typeRef = getTypeRef() val typeRef = getTypeReference()
if (typeRef != null) { if (typeRef != null) {
// and has a specified type // and has a specified type
array(context[BindingContext.TYPE, typeRef]!!) array(context[BindingContext.TYPE, typeRef]!!)
@@ -122,7 +122,7 @@ fun JetExpression.guessTypes(context: BindingContext): Array<JetType> {
getParent() is JetVariableDeclaration -> { getParent() is JetVariableDeclaration -> {
// the expression is the RHS of a variable assignment with a specified type // the expression is the RHS of a variable assignment with a specified type
val variable = getParent() as JetVariableDeclaration val variable = getParent() as JetVariableDeclaration
val typeRef = variable.getTypeRef() val typeRef = variable.getTypeReference()
if (typeRef != null) { if (typeRef != null) {
// and has a specified type // and has a specified type
array(context[BindingContext.TYPE, typeRef]!!) array(context[BindingContext.TYPE, typeRef]!!)
@@ -57,12 +57,12 @@ public class JetFunctionDefinitionUsage extends JetUsageInfo<PsiElement> {
} }
} }
if (changeInfo.isReturnTypeChanged()) { if (changeInfo.isReturnTypeChanged()) {
function.setReturnTypeRef(null); function.setTypeReference(null);
String returnTypeText = changeInfo.getNewReturnTypeText(); String returnTypeText = changeInfo.getNewReturnTypeText();
//TODO use ChangeFunctionReturnTypeFix.invoke when JetTypeCodeFragment.getType() is ready //TODO use ChangeFunctionReturnTypeFix.invoke when JetTypeCodeFragment.getType() is ready
if (!KotlinBuiltIns.getInstance().getUnitType().toString().equals(returnTypeText)) { if (!KotlinBuiltIns.getInstance().getUnitType().toString().equals(returnTypeText)) {
function.setReturnTypeRef(JetPsiFactory(function).createType(returnTypeText)); function.setTypeReference(JetPsiFactory(function).createType(returnTypeText));
} }
} }
} }
@@ -241,7 +241,7 @@ private fun makeCall(
block.addBefore(newLine, anchorInBlock) block.addBefore(newLine, anchorInBlock)
} }
val entries = declarationsToMerge.map { p -> p.getName() + (p.getTypeRef()?.let { ": ${it.getText()}" } ?: "") } val entries = declarationsToMerge.map { p -> p.getName() + (p.getTypeReference()?.let { ": ${it.getText()}" } ?: "") }
anchorInBlock?.replace( anchorInBlock?.replace(
psiFactory.createDeclaration("${if (isVar) "var" else "val"} (${entries.joinToString()}) = $callText") psiFactory.createDeclaration("${if (isVar) "var" else "val"} (${entries.joinToString()}) = $callText")
) )
@@ -121,7 +121,7 @@ public class KotlinInplaceVariableIntroducer extends InplaceVariableIntroducer<J
PsiDocumentManager.getInstance(myProject).commitDocument(myEditor.getDocument()); PsiDocumentManager.getInstance(myProject).commitDocument(myEditor.getDocument());
} }
else { else {
myProperty.setTypeRef(null); myProperty.setTypeReference(null);
} }
} }
}.execute(); }.execute();
@@ -468,7 +468,7 @@ public class JetPsiUnifier(
desc2: CallableDescriptor): Status? { desc2: CallableDescriptor): Status? {
fun needToCompareReturnTypes(): Boolean { fun needToCompareReturnTypes(): Boolean {
if (decl1 !is JetCallableDeclaration) return true if (decl1 !is JetCallableDeclaration) return true
return decl1.getReturnTypeRef() != null || (decl2 as JetCallableDeclaration).getReturnTypeRef() != null return decl1.getTypeReference() != null || (decl2 as JetCallableDeclaration).getTypeReference() != null
} }
if (desc1 is VariableDescriptor && desc1.isVar() != (desc2 as VariableDescriptor).isVar()) return UNMATCHED if (desc1 is VariableDescriptor && desc1.isVar() != (desc2 as VariableDescriptor).isVar()) return UNMATCHED