Package ro.redeul.google.go.lang.psi.statements.switches

Examples of ro.redeul.google.go.lang.psi.statements.switches.GoSwitchExpressionStatement


                      "             return 1\n" +
                      "     }\n" +
                      "     return nil\n" +
                      "}\n"));

        GoSwitchExpressionStatement exprSwitch =
            castAs(GoSwitchExpressionStatement.class, 0,
                   get(
                       get(
                           file.getMainFunction()
                       ).getBlock()
                   ).getStatements()
            );

        assertNull(exprSwitch.getExpression());
        assertNull(exprSwitch.getSimpleStatement());
        assertEquals(1, exprSwitch.getClauses().length);

        GoSwitchExpressionClause clause =
            childAt(0, exprSwitch.getClauses());

        assertEquals(true, clause.isDefault());

        assertEquals(1, clause.getStatements().length);
View Full Code Here


                      "             return x\n" +
                      "     }\n" +
                      "     return nil\n" +
                      "}\n"));

        GoSwitchExpressionStatement exprSwitch =
            castAs(GoSwitchExpressionStatement.class, 0,
                   get(
                       get(
                           file.getMainFunction()
                       ).getBlock()
                   ).getStatements()
            );

        assertEquals("x := 1", get(exprSwitch.getSimpleStatement()).getText());
        assertEquals("x", get(exprSwitch.getExpression()).getText());
    }
View Full Code Here

                      "             return x\n" +
                      "     }\n" +
                      "     return nil\n" +
                      "}\n"));

        GoSwitchExpressionStatement exprSwitch =
            castAs(GoSwitchExpressionStatement.class, 0,
                   get(
                       get(
                           file.getMainFunction()
                       ).getBlock()
                   ).getStatements()
            );

        assertEquals("x := 1", get(exprSwitch.getSimpleStatement()).getText());
        assertEquals("x", get(exprSwitch.getExpression()).getText());

        GoSwitchExpressionClause clause = childAt(0, exprSwitch.getClauses());

        assertEquals(1, clause.getExpressions().length);
        assertEquals("1", childAt(0, clause.getExpressions()).getText());
        assertFalse(clause.isDefault());

        clause = childAt(1, exprSwitch.getClauses());

        assertEquals(0, clause.getExpressions().length);
        assertTrue(clause.isDefault());
    }
View Full Code Here

                      "             return a\n" +
                      "     }\n" +
                      "     return nil\n" +
                      "}\n"));

        GoSwitchExpressionStatement exprSwitch =
            castAs(GoSwitchExpressionStatement.class, 0,
                   get(
                       get(
                           file.getMainFunction()
                       ).getBlock()
                   ).getStatements()
            );

        assertNull(exprSwitch.getSimpleStatement());
        assertNull(exprSwitch.getExpression());

        GoSwitchExpressionClause clause = childAt(0, exprSwitch.getClauses());

        assertEquals(3, clause.getExpressions().length);
        assertEquals("1", childAt(0, clause.getExpressions()).getText());
        assertEquals("2", childAt(1, clause.getExpressions()).getText());
        assertEquals("4", childAt(2, clause.getExpressions()).getText());
View Full Code Here

            return forStatement.getCondition() == null;
        }else if(statement instanceof GoForWithClausesStatement){
            GoForWithClausesStatement forStatement = (GoForWithClausesStatement)statement;
            return forStatement.getCondition() == null;
        }else if (statement instanceof GoSwitchExpressionStatement){
            GoSwitchExpressionStatement switchExpr = (GoSwitchExpressionStatement)statement;
            boolean hasDefalut = false;
            for (GoSwitchExpressionClause clause: switchExpr.getClauses()) {
                if (clause.isDefault()) {
                    hasDefalut = true;
                }
                GoStatement[] statmentsInClause = clause.getStatements();
View Full Code Here

    }

    @Override
    protected void processIntention(@NotNull PsiElement element, Editor editor)
            throws IntentionExecutionException {
        GoSwitchExpressionStatement se = findParentOfType(element, GoSwitchExpressionStatement.class);
        if (se == null) {
            return;
        }

        checkFallthrough(se);

        Document document = editor.getDocument();
        RangeMarker range = document.createRangeMarker(se.getTextRange());
        SwitchElements switchElements = SwitchElements.create(document, se);
        DocumentUtil.replaceElementWithText(document, se, switchElements.toIf());
        reformatPositions(se.getContainingFile(), range);
    }
View Full Code Here

        GoSimpleStatement ss = stmt.getSimpleStatement();
        return ss != null && ss.getTextRange().contains(element.getTextRange());
    }

    private static boolean isInSwitchStatement(PsiElement element) {
        GoSwitchExpressionStatement seStmt = findParentOfType(element, GoSwitchExpressionStatement.class);
        if (seStmt != null) {
            GoSimpleStatement ss = seStmt.getSimpleStatement();
            return ss != null && ss.getTextRange().contains(element.getTextRange());
        }

        GoSwitchTypeStatement stStmt = findParentOfType(element, GoSwitchTypeStatement.class);
        if (stStmt != null) {
View Full Code Here

        if (ifStatement != null) {
            moveSimpleStatementOut(editor, ifStatement);
            return;
        }

        GoSwitchExpressionStatement seStmt = findParentOfType(element, GoSwitchExpressionStatement.class);
        if (seStmt != null) {
            moveSimpleStatementOut(editor, seStmt);
            return;
        }
View Full Code Here

TOP

Related Classes of ro.redeul.google.go.lang.psi.statements.switches.GoSwitchExpressionStatement

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.