Search in sources :

Example 1 with JstdTestCaseStructure

use of com.google.jstestdriver.idea.assertFramework.jstd.JstdTestCaseStructure in project intellij-plugins by JetBrains.

the class JstdGenerateNewTestAction method buildGenerator.

@Nullable
private static Runnable buildGenerator(@NotNull JstdTestFileStructure fileStructure, @NotNull GenerateActionContext context) {
    int caretOffset = context.getDocumentCaretOffset();
    JstdTestCaseStructure jstdTestCaseStructure = fileStructure.findEnclosingTestCaseByOffset(caretOffset);
    if (jstdTestCaseStructure != null) {
        JSObjectLiteralExpression testsObjectLiteral = jstdTestCaseStructure.getTestsObjectsLiteral();
        if (testsObjectLiteral != null) {
            return new TestGeneratorOnObjectLiteral(testsObjectLiteral, context);
        } else {
            if (jstdTestCaseStructure.getTestCount() == 0) {
                JSCallExpression callExpression = jstdTestCaseStructure.getEnclosingCallExpression();
                JSArgumentList argumentList = callExpression.getArgumentList();
                JSExpression[] arguments = JsPsiUtils.getArguments(argumentList);
                if (arguments.length == 1 && arguments[0] != null) {
                    return new TestGeneratorOnNewlyCreatedObjectLiteral(argumentList, context);
                }
            }
        }
    } else {
        for (JstdTestCaseStructure testCaseStructure : fileStructure.getTestCaseStructures()) {
            JSObjectLiteralExpression testsObjectLiteral = testCaseStructure.getTestsObjectsLiteral();
            if (testsObjectLiteral != null && JsPsiUtils.containsOffsetStrictly(testsObjectLiteral.getTextRange(), caretOffset)) {
                return new TestGeneratorOnObjectLiteral(testsObjectLiteral, context);
            }
        }
    }
    return null;
}
Also used : JSCallExpression(com.intellij.lang.javascript.psi.JSCallExpression) JSArgumentList(com.intellij.lang.javascript.psi.JSArgumentList) JstdTestCaseStructure(com.google.jstestdriver.idea.assertFramework.jstd.JstdTestCaseStructure) JSObjectLiteralExpression(com.intellij.lang.javascript.psi.JSObjectLiteralExpression) JSExpression(com.intellij.lang.javascript.psi.JSExpression) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with JstdTestCaseStructure

use of com.google.jstestdriver.idea.assertFramework.jstd.JstdTestCaseStructure in project intellij-plugins by JetBrains.

the class AbstractJstdCreateStaticMethodAction method buildGenerator.

@Nullable
private Runnable buildGenerator(@NotNull GenerateActionContext context, @NotNull JstdTestFileStructure fileStructure) {
    if (fileStructure.getTestCaseCount() == 0) {
        return null;
    }
    int caretOffset = context.getDocumentCaretOffset();
    JstdTestCaseStructure testCaseStructure = fileStructure.findEnclosingTestCaseByOffset(caretOffset);
    if (testCaseStructure != null) {
        JSObjectLiteralExpression testsObjectLiteral = testCaseStructure.getTestsObjectsLiteral();
        if (testsObjectLiteral != null) {
            if (!findMethod(testsObjectLiteral)) {
                return new StaticMethodGenerator(testsObjectLiteral, context);
            }
        } else {
            JSCallExpression callExpression = testCaseStructure.getEnclosingCallExpression();
            JSArgumentList argumentList = callExpression.getArgumentList();
            JSExpression[] arguments = JsPsiUtils.getArguments(argumentList);
            if (arguments.length == 1 && arguments[0] != null) {
                return new StaticMethodGeneratorOnNewlyCreatedObjectLiteral(argumentList, context);
            }
        }
    } else {
        for (JstdTestCaseStructure testCase : fileStructure.getTestCaseStructures()) {
            JSObjectLiteralExpression testsObjectLiteral = testCase.getTestsObjectsLiteral();
            if (testsObjectLiteral != null && JsPsiUtils.containsOffsetStrictly(testsObjectLiteral.getTextRange(), caretOffset)) {
                if (!findMethod(testsObjectLiteral)) {
                    return new StaticMethodGenerator(testsObjectLiteral, context);
                }
            }
        }
    }
    return null;
}
Also used : JstdTestCaseStructure(com.google.jstestdriver.idea.assertFramework.jstd.JstdTestCaseStructure) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

JstdTestCaseStructure (com.google.jstestdriver.idea.assertFramework.jstd.JstdTestCaseStructure)2 Nullable (org.jetbrains.annotations.Nullable)2 JSArgumentList (com.intellij.lang.javascript.psi.JSArgumentList)1 JSCallExpression (com.intellij.lang.javascript.psi.JSCallExpression)1 JSExpression (com.intellij.lang.javascript.psi.JSExpression)1 JSObjectLiteralExpression (com.intellij.lang.javascript.psi.JSObjectLiteralExpression)1