@Override public void invoke(@NotNull Project project, Editor editor, JetFile file) throws IncorrectOperationException { JetType type = QuickFixUtil.getDeclarationReturnType(element); JetProperty newElement = (JetProperty) element.copy(); JetPropertyAccessor getter = newElement.getGetter(); if (removeGetter && getter != null) { newElement.deleteChildInternal(getter.getNode()); } JetPropertyAccessor setter = newElement.getSetter(); if (removeSetter && setter != null) { newElement.deleteChildInternal(setter.getNode()); } JetExpression initializer = newElement.getInitializer(); JetType typeToAdd = null; if (removeInitializer && initializer != null) { PsiElement nameIdentifier = newElement.getNameIdentifier(); assert nameIdentifier != null; PsiElement nextSibling = nameIdentifier.getNextSibling(); assert nextSibling != null; newElement.deleteChildRange(nextSibling, initializer); if (newElement.getTypeRef() == null && type != null) { typeToAdd = type; } } element = (JetProperty) element.replace(newElement); if (typeToAdd != null) { SpecifyTypeExplicitlyAction.addTypeAnnotation(project, editor, element, typeToAdd); } }
@Override public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) { JetType type = QuickFixUtil.getDeclarationReturnType(element); return super.isAvailable(project, editor, file) && type != null && !ErrorUtils.isErrorType(type); }