JetParameter made JetCallableDeclaration
This commit is contained in:
@@ -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<PsiJetParameterStub> {
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class JetParameter extends JetNamedDeclarationStub<PsiJetParameterStub> implements JetCallableDeclaration {
|
||||
|
||||
public JetParameter(@NotNull ASTNode node) {
|
||||
super(node);
|
||||
@@ -41,14 +44,15 @@ public class JetParameter extends JetNamedDeclarationStub<PsiJetParameterStub> {
|
||||
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<PsiJetParameterStub> {
|
||||
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<JetTypeConstraint> getTypeConstraints() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public List<JetTypeParameter> getTypeParameters() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -65,6 +65,6 @@ public class ChangeParameterTypeFix extends JetIntentionAction<JetParameter> {
|
||||
|
||||
@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));
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -139,7 +139,7 @@ public class JetFunctionDefinitionUsage extends JetUsageInfo<PsiElement> {
|
||||
|
||||
if (parameterInfo.isTypeChanged()) {
|
||||
JetTypeReference newTypeRef = psiFactory.createType(parameterInfo.getTypeText());
|
||||
parameter.setTypeRef(newTypeRef);
|
||||
parameter.setTypeReference(newTypeRef);
|
||||
}
|
||||
|
||||
PsiElement identifier = parameter.getNameIdentifier();
|
||||
|
||||
Reference in New Issue
Block a user