コード例 #1
0
 @Nullable
 private static JstdTestCaseStructure createTestCaseStructure(
     @NotNull JstdTestFileStructure jsTestFileStructure,
     @NotNull JSCallExpression testCaseCallExpression) {
   JSReferenceExpression referenceExpression =
       ObjectUtils.tryCast(
           testCaseCallExpression.getMethodExpression(), JSReferenceExpression.class);
   if (referenceExpression != null) {
     String referenceName = referenceExpression.getReferencedName();
     if (TEST_CASE_NAME.equals(referenceName) || ASYNC_TEST_CASE_NAME.equals(referenceName)) {
       JSExpression[] arguments = JsPsiUtils.getArguments(testCaseCallExpression);
       if (arguments.length >= 1) {
         String testCaseName = JsPsiUtils.extractStringValue(arguments[0]);
         if (testCaseName != null) {
           JSObjectLiteralExpression testsObjectLiteral = null;
           if (arguments.length >= 2) {
             testsObjectLiteral = JsPsiUtils.extractObjectLiteralExpression(arguments[1]);
           }
           JstdTestCaseStructure testCaseStructure =
               new JstdTestCaseStructure(
                   jsTestFileStructure, testCaseName, testCaseCallExpression, testsObjectLiteral);
           jsTestFileStructure.addTestCaseStructure(testCaseStructure);
           if (testsObjectLiteral != null) {
             fillTestCaseStructureByObjectLiteral(testCaseStructure, testsObjectLiteral);
           }
           return testCaseStructure;
         }
       }
     }
   }
   return null;
 }
  @Override
  public void invoke(@NotNull final Project project, final Editor editor, final PsiFile file)
      throws IncorrectOperationException {
    JSCallExpression jsCallExpression = SignalsUtils.getCallExpressionFromCaret(editor, file);
    JSArgumentList argumentList = jsCallExpression.getArgumentList();

    PsiElement signal = SignalsUtils.getSignalFromCallExpression(jsCallExpression);

    JSArgumentList signalParams =
        SignalsUtils.getStringParametersFromSignalReference(signal.getReference());
    String signalHandlerName = replaceParamsWithArgs(project, argumentList, signal);

    PsiElement psiElement =
        generateHandlerFromParams(project, (JSFile) file, signalHandlerName, signalParams);
    moveCursorInsideMethod(editor, psiElement);
  }
  @Override
  public boolean isAvailable(@NotNull Project project, Editor editor, @NotNull PsiElement element) {
    JSCallExpression jsCallExpression =
        PsiTreeUtil.getParentOfType(element, JSCallExpression.class);

    if (jsCallExpression == null) {
      return false;
    }

    JSExpression methodExpression = jsCallExpression.getMethodExpression();
    if (methodExpression instanceof JSReferenceExpression) {
      String referencedName = ((JSReferenceExpression) methodExpression).getReferencedName();
      return "add".equals(referencedName);
    }

    return false;
  }
 @Override
 protected boolean isSuitableElement(
     @NotNull JSFile jsFile, @NotNull JSCallExpression callExpression) {
   JstdTestFileStructure structure =
       JstdTestFileStructureBuilder.getInstance().fetchCachedTestFileStructure(jsFile);
   String name = structure.getNameByPsiElement(callExpression.getMethodExpression());
   return name != null;
 }