コード例 #1
0
  @Nullable
  public static JetChangeSignatureDialog createDialog(
      @NotNull PsiElement element, PsiElement context, Project project, Editor editor) {
    if (!CommonRefactoringUtil.checkReadOnlyStatus(project, element)) return null;
    BindingContext bindingContext =
        AnalyzerFacadeWithCache.analyzeFileWithCache((JetFile) element.getContainingFile())
            .getBindingContext();
    DeclarationDescriptor descriptor =
        bindingContext.get(BindingContext.DECLARATION_TO_DESCRIPTOR, element);

    if (descriptor instanceof ClassDescriptor) {
      descriptor = ((ClassDescriptor) descriptor).getUnsubstitutedPrimaryConstructor();
    }
    if (descriptor instanceof FunctionDescriptorImpl) {
      for (ValueParameterDescriptor parameter :
          ((FunctionDescriptor) descriptor).getValueParameters()) {
        if (parameter.getVarargElementType() != null) {
          String message = JetRefactoringBundle.message("error.cant.refactor.vararg.functions");
          CommonRefactoringUtil.showErrorHint(
              project, editor, message, REFACTORING_NAME, HelpID.CHANGE_SIGNATURE);
          return null;
        }
      }

      return new JetChangeSignatureDialog(
          project,
          new JetFunctionPlatformDescriptorImpl((FunctionDescriptor) descriptor, element),
          context);
    } else {
      String message =
          RefactoringBundle.getCannotRefactorMessage(
              JetRefactoringBundle.message(
                  "error.wrong.caret.position.function.or.constructor.name"));
      CommonRefactoringUtil.showErrorHint(
          project, editor, message, REFACTORING_NAME, HelpID.CHANGE_SIGNATURE);
      return null;
    }
  }
コード例 #2
0
 @Nullable
 @Override
 public String getTargetNotFoundMessage() {
   return JetRefactoringBundle.message("error.wrong.caret.position.function.or.constructor.name");
 }