From 93efcd637e6e96d1f5da811c6a1feeb65a51e4de Mon Sep 17 00:00:00 2001 From: Valentin Kipyatkov Date: Tue, 7 Oct 2014 13:00:44 +0400 Subject: [PATCH] JetParameter made JetCallableDeclaration --- .../jetbrains/jet/lang/psi/JetParameter.java | 34 ++++++++++++-- .../SpecifyTypeExplicitlyAction.java | 44 +++---------------- .../quickfix/ChangeParameterTypeFix.java | 2 +- .../usages/JetFunctionDefinitionUsage.java | 2 +- 4 files changed, 40 insertions(+), 42 deletions(-) diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetParameter.java b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetParameter.java index ccc808dfa22..a199e7f7d2e 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetParameter.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetParameter.java @@ -26,7 +26,10 @@ import org.jetbrains.jet.lang.psi.stubs.elements.JetStubElementTypes; import org.jetbrains.jet.lang.psi.typeRefHelpers.TypeRefHelpersPackage; import org.jetbrains.jet.lexer.JetTokens; -public class JetParameter extends JetNamedDeclarationStub { +import java.util.Collections; +import java.util.List; + +public class JetParameter extends JetNamedDeclarationStub implements JetCallableDeclaration { public JetParameter(@NotNull ASTNode node) { super(node); @@ -41,14 +44,15 @@ public class JetParameter extends JetNamedDeclarationStub { return visitor.visitParameter(this, data); } - //TODO: rename it to getTypeRef for consistency + @Override @Nullable public JetTypeReference getTypeReference() { return getStubOrPsiChild(JetStubElementTypes.TYPE_REFERENCE); } + @Override @Nullable - public JetTypeReference setTypeRef(@Nullable JetTypeReference typeRef) { + public JetTypeReference setTypeReference(@Nullable JetTypeReference typeRef) { return TypeRefHelpersPackage.setTypeReference(this, getNameIdentifier(), typeRef); } @@ -121,4 +125,28 @@ public class JetParameter extends JetNamedDeclarationStub { public boolean isLoopParameter() { return getParent() instanceof JetForExpression; } + + @Nullable + @Override + public JetParameterList getValueParameterList() { + return null; + } + + @Nullable + @Override + public JetTypeReference getReceiverTypeReference() { + return null; + } + + @NotNull + @Override + public List getTypeConstraints() { + return Collections.emptyList(); + } + + @NotNull + @Override + public List getTypeParameters() { + return Collections.emptyList(); + } } diff --git a/idea/src/org/jetbrains/jet/plugin/intentions/SpecifyTypeExplicitlyAction.java b/idea/src/org/jetbrains/jet/plugin/intentions/SpecifyTypeExplicitlyAction.java index adcc8be7598..b2a4e6ad87a 100644 --- a/idea/src/org/jetbrains/jet/plugin/intentions/SpecifyTypeExplicitlyAction.java +++ b/idea/src/org/jetbrains/jet/plugin/intentions/SpecifyTypeExplicitlyAction.java @@ -83,7 +83,7 @@ public class SpecifyTypeExplicitlyAction extends PsiElementBaseIntentionAction { addTypeAnnotation(project, editor, parameter, type); } else { - parameter.setTypeRef(null); + parameter.setTypeReference(null); } } else if (parent instanceof JetNamedFunction) { @@ -200,17 +200,17 @@ public class SpecifyTypeExplicitlyAction extends PsiElementBaseIntentionAction { addTypeAnnotationWithTemplate(project, editor, parameter, exprType); } else { - parameter.setTypeRef(anyTypeRef(project)); + parameter.setTypeReference(anyTypeRef(project)); } } private static void addTypeAnnotationWithTemplate( @NotNull Project project, @NotNull Editor editor, - @NotNull final JetNamedDeclaration namedDeclaration, + @NotNull final JetCallableDeclaration declaration, @NotNull JetType exprType ) { - assert !exprType.isError() : "Unexpected error type: " + namedDeclaration.getText(); + assert !exprType.isError() : "Unexpected error type: " + declaration.getText(); ClassifierDescriptor descriptor = exprType.getConstructor().getDeclarationDescriptor(); boolean isAnonymous = descriptor != null && DescriptorUtils.isAnonymousObject(descriptor); @@ -235,12 +235,12 @@ public class SpecifyTypeExplicitlyAction extends PsiElementBaseIntentionAction { } }; - setTypeRef(namedDeclaration, anyTypeRef(project)); + declaration.setTypeReference(anyTypeRef(project)); PsiDocumentManager.getInstance(project).commitAllDocuments(); PsiDocumentManager.getInstance(project).doPostponedOperationsAndUnblockDocument(editor.getDocument()); - JetTypeReference newTypeRef = getTypeRef(namedDeclaration); + JetTypeReference newTypeRef = declaration.getTypeReference(); assert newTypeRef != null; TemplateBuilderImpl builder = new TemplateBuilderImpl(newTypeRef); builder.replaceElement(newTypeRef, expression); @@ -251,7 +251,7 @@ public class SpecifyTypeExplicitlyAction extends PsiElementBaseIntentionAction { manager.startTemplate(editor, builder.buildInlineTemplate(), new TemplateEditingAdapter() { @Override public void templateFinished(Template template, boolean brokenOff) { - JetTypeReference typeRef = getTypeRef(namedDeclaration); + JetTypeReference typeRef = declaration.getTypeReference(); assert typeRef != null; ShortenReferences.INSTANCE$.process(typeRef); } @@ -261,34 +261,4 @@ public class SpecifyTypeExplicitlyAction extends PsiElementBaseIntentionAction { private static JetTypeReference anyTypeRef(@NotNull Project project) { return JetPsiFactory(project).createType("Any"); } - - @Nullable - private static JetTypeReference getTypeRef(@NotNull JetNamedDeclaration namedDeclaration) { - if (namedDeclaration instanceof JetProperty) { - return ((JetProperty) namedDeclaration).getTypeReference(); - } - else if (namedDeclaration instanceof JetParameter) { - return ((JetParameter) namedDeclaration).getTypeReference(); - } - else if (namedDeclaration instanceof JetFunction) { - return ((JetFunction) namedDeclaration).getTypeReference(); - } - assert false : "Wrong namedDeclaration: " + namedDeclaration.getText(); - return null; - } - - @Nullable - private static JetTypeReference setTypeRef(@NotNull JetNamedDeclaration namedDeclaration, @Nullable JetTypeReference typeRef) { - if (namedDeclaration instanceof JetProperty) { - return ((JetProperty) namedDeclaration).setTypeReference(typeRef); - } - else if (namedDeclaration instanceof JetParameter) { - return ((JetParameter) namedDeclaration).setTypeRef(typeRef); - } - else if (namedDeclaration instanceof JetFunction) { - return ((JetFunction) namedDeclaration).setTypeReference(typeRef); - } - assert false : "Wrong namedDeclaration: " + namedDeclaration.getText(); - return null; - } } diff --git a/idea/src/org/jetbrains/jet/plugin/quickfix/ChangeParameterTypeFix.java b/idea/src/org/jetbrains/jet/plugin/quickfix/ChangeParameterTypeFix.java index 1430f55dcc0..41403dee588 100644 --- a/idea/src/org/jetbrains/jet/plugin/quickfix/ChangeParameterTypeFix.java +++ b/idea/src/org/jetbrains/jet/plugin/quickfix/ChangeParameterTypeFix.java @@ -65,6 +65,6 @@ public class ChangeParameterTypeFix extends JetIntentionAction { @Override public void invoke(@NotNull Project project, Editor editor, JetFile file) throws IncorrectOperationException { - element.setTypeRef(JetPsiFactory(file).createType(renderedType)); + element.setTypeReference(JetPsiFactory(file).createType(renderedType)); } } diff --git a/idea/src/org/jetbrains/jet/plugin/refactoring/changeSignature/usages/JetFunctionDefinitionUsage.java b/idea/src/org/jetbrains/jet/plugin/refactoring/changeSignature/usages/JetFunctionDefinitionUsage.java index 2543e7548b4..718e94e45db 100644 --- a/idea/src/org/jetbrains/jet/plugin/refactoring/changeSignature/usages/JetFunctionDefinitionUsage.java +++ b/idea/src/org/jetbrains/jet/plugin/refactoring/changeSignature/usages/JetFunctionDefinitionUsage.java @@ -139,7 +139,7 @@ public class JetFunctionDefinitionUsage extends JetUsageInfo { if (parameterInfo.isTypeChanged()) { JetTypeReference newTypeRef = psiFactory.createType(parameterInfo.getTypeText()); - parameter.setTypeRef(newTypeRef); + parameter.setTypeReference(newTypeRef); } PsiElement identifier = parameter.getNameIdentifier();