Examples of GoExpr


Examples of ro.redeul.google.go.lang.psi.expressions.GoExpr

            if (!(element instanceof GoExpr) ) {
                fail("The maker was not positioned on an expression");
            }

            GoExpr expr = (GoExpr) element;
            expressionsTypes.add(expr.getType());
        }
    }
View Full Code Here

Examples of ro.redeul.google.go.lang.psi.expressions.GoExpr

    public void testOther3()        { doTest("a == 3 || a > 5 && a % 2 == 0", "a != 3 && (a <= 5 || a % 2 != 0)"); }

    private void doTest(String expressionToFlip, String expectedResult) {
        String text = String.format("package main\nvar a=%s", expressionToFlip);
        GoFile file = (GoFile) myFixture.configureByText(GoFileType.INSTANCE, text);
        GoExpr expr = file.getGlobalVariables()[0].getDeclarations()[0].getExpressions()[0];
        Assert.assertEquals(expectedResult, FlipBooleanExpression.flip(expr));
    }
View Full Code Here

Examples of ro.redeul.google.go.lang.psi.expressions.GoExpr

    }

    @NotNull
    @Override
    protected GoType[] resolveTypes() {
        GoExpr leftOperand = getLeftOperand();
        GoExpr rightOperand = getRightOperand();

        if (leftOperand == null && rightOperand == null)
            return GoType.EMPTY_ARRAY;

        if (leftOperand == null)
            return rightOperand.getType();

        if (rightOperand == null)
            return leftOperand.getType();

        GoType[] leftTypes = leftOperand.getType();
        GoType[] rightTypes = rightOperand.getType();

        if (leftTypes.length != 1 || rightTypes.length != 1 || leftTypes[0] == null || rightTypes[0] == null )
            return GoType.EMPTY_ARRAY;

        GoType leftType = leftTypes[0];
View Full Code Here

Examples of ro.redeul.google.go.lang.psi.expressions.GoExpr

    }

    @Override
    protected synchronized void doIntroduce(Project project, Editor editor, GoFile file, int start, int end)
            throws GoRefactoringException {
        final GoExpr e = CodeInsightUtilBase.findElementInRange(file, start, end, GoExpr.class, GoLanguage.INSTANCE);
        if (!isExpressionValid(e)) {
            throw new GoRefactoringException(GoBundle.message("error.invalid.expression"));
        }

        Document document = PsiDocumentManager.getInstance(project).getDocument(file);
View Full Code Here

Examples of ro.redeul.google.go.lang.psi.expressions.GoExpr

        if (call instanceof GoBuiltinCallOrConversionExpression) {
            GoPsiType[] builtinTypes = ((GoBuiltinCallOrConversionExpression) call).getArgumentsType();
            if (builtinTypes.length > 0 && goExprs.length == builtinTypes.length) {
                for (; index < goExprs.length; index++) {
                    GoExpr goExpr = goExprs[index];
                    GoPsiType type = builtinTypes[index];
                    if (!checkParametersExp(type, goExpr)){
                        result.addProblem(
                                goExpr,
                                GoBundle.message("warning.functioncall.type.mismatch", type.getText()),
                                ProblemHighlightType.GENERIC_ERROR_OR_WARNING, new CastTypeFix(goExpr, GoTypes.fromPsi(type)));
                        return;
                    }
                }
            }
            return;
        }

        for (GoFunctionParameter functionParameter : goFunctionDeclaration.getParameters()) {
            if (index >= goExprs.length)
                return;
            GoPsiType type = functionParameter.getType();
            String typeName = type != null ? type.getText() : "";
            if (functionParameter.isVariadic()) {
                if (call.isCallWithVariadicParameter()){
                    GoExpr goExpr = goExprs[index];
                    GoType[] types = goExpr.getType();
                    if (types.length!=1){
                        result.addProblem(
                                goExpr,
                                GoBundle.message("warning.functioncall.type.mismatch", "[]"+typeName),
                                ProblemHighlightType.GENERIC_ERROR_OR_WARNING);
                        return;
                    }
                    GoType exprType = types[0].underlyingType();
                    if (!(exprType instanceof GoTypeSlice)){
                        result.addProblem(
                                goExpr,
                                GoBundle.message("warning.functioncall.type.mismatch", "[]"+typeName),
                                ProblemHighlightType.GENERIC_ERROR_OR_WARNING);
                        return;
                    }

                    //TODO test with assignable
                    if (!((GoTypeSlice) exprType).getElementType().isIdentical(GoTypes.fromPsi(type)) ) {
                        result.addProblem(
                                goExpr,
                                GoBundle.message("warning.functioncall.type.mismatch", "[]"+typeName),
                                ProblemHighlightType.GENERIC_ERROR_OR_WARNING);
                        return;
                    }
                }else {
                    for (; index < goExprs.length; index++) {
                        GoExpr goExpr = goExprs[index];
                        if (!checkParametersExp(functionParameter.getType(), goExpr)) {
                            result.addProblem(
                                    goExpr,
                                    GoBundle.message("warning.functioncall.type.mismatch", typeName),
                                    ProblemHighlightType.GENERIC_ERROR_OR_WARNING, new CastTypeFix(goExpr, GoTypes.fromPsi(type)));
                            return;
                        }
                    }
                }
            } else {
                GoLiteralIdentifier[] identifiers = functionParameter.getIdentifiers();
                if (identifiers.length < 2) {
                    GoExpr goExpr = goExprs[index];
                    if (!checkParametersExp(functionParameter.getType(), goExpr)) {
                        result.addProblem(
                                goExpr,
                                GoBundle.message("warning.functioncall.type.mismatch", typeName),
                                ProblemHighlightType.GENERIC_ERROR_OR_WARNING, new CastTypeFix(goExpr, GoTypes.fromPsi(type)));
                        return;
                    }
                    index++;
                } else {
                    for (GoLiteralIdentifier goLiteralIdentifier : identifiers) {
                        GoExpr goExpr = goExprs[index];
                        if (!checkParametersExp(functionParameter.getType(), goExpr)) {
                            result.addProblem(
                                    goExpr,
                                    GoBundle.message("warning.functioncall.type.mismatch", typeName),
                                    ProblemHighlightType.GENERIC_ERROR_OR_WARNING, new CastTypeFix(goExpr, GoTypes.fromPsi(type)));
View Full Code Here

Examples of ro.redeul.google.go.lang.psi.expressions.GoExpr

        }.visitFile(file);
    }

    private void checkIndexExpression(GoIndexExpression expression, final InspectionResult result) {
        final GoExpr indexExpr = expression.getIndex();
        if (indexExpr == null)
            return;

        final GoFile goFile = getAs(GoFile.class, indexExpr.getContainingFile());
        if (goFile == null)
            return;

        final GoType[] indexTypes = indexExpr.getType();

        if (indexTypes.length != 1 || indexTypes[0] == null)
            return;
        final GoType indexType = indexTypes[0];

        GoType[] expressionTypes = expression.getBaseExpression().getType();
        if (expressionTypes.length != 1 || expressionTypes[0] == null)
            return;

        final BigInteger intConstant = getIntegerConstant(indexType);

        expressionTypes[0].underlyingType().accept(new UpdatingTypeVisitor<InspectionResult>() {
            @Override
            public void visitArray(GoTypeArray type, InspectionResult result, TypeVisitor<InspectionResult> visitor) {
                checkUnsignedIntegerConstantInRange(indexExpr, indexType, type.getLength(), result);
            }

            @Override
            public void visitSlice(GoTypeSlice type, InspectionResult result, TypeVisitor<InspectionResult> visitor) {
                checkUnsignedIntegerConstantInRange(indexExpr, indexType, Integer.MAX_VALUE, result);
            }

            @Override
            public void visitPrimitive(GoTypePrimitive type, InspectionResult data, TypeVisitor<InspectionResult> visitor) {
                switch (type.getType()) {
                    case String:
                        checkUnsignedIntegerConstantInRange(indexExpr, indexType, Integer.MAX_VALUE, result);
                        break;
                    default:
                        result.addProblem(
                                indexExpr,
                                GoBundle.message("warning.functioncall.type.mismatch", GoTypes.getRepresentation(indexType, goFile))
                        );
                }
            }

            @Override
            public void visitPointer(GoTypePointer type, InspectionResult data, TypeVisitor<InspectionResult> visitor) {
                type.getTargetType().underlyingType().accept(visitor);
            }

            @Override
            public void visitConstant(GoTypeConstant type, InspectionResult data, TypeVisitor<InspectionResult> visitor) {
                switch (type.getKind()) {
                    case String:
                        String stringValue = type.getValueAs(String.class);
                        checkUnsignedIntegerConstantInRange(indexExpr, indexType, stringValue != null ? stringValue.length() : Integer.MAX_VALUE, result);
                    default:
                        result.addProblem(
                                indexExpr,
                                GoBundle.message("warning.functioncall.type.mismatch", GoTypes.getRepresentation(indexType, goFile))
                        );
                }
            }

            @Override
            public void visitMap(GoTypeMap type, InspectionResult data, TypeVisitor<InspectionResult> visitor) {
                GoType keyType = type.getKeyType();
                if (!keyType.isAssignableFrom(indexType)) {
                    result.addProblem(
                            indexExpr,
                            GoBundle.message("warn.index.map.invalid.type",
                                    indexExpr.getText(),
                                    GoTypes.getRepresentation(indexType, goFile),
                                    GoTypes.getRepresentation(keyType, goFile)),
                            new CastTypeFix(indexExpr, keyType));
                }
            }
View Full Code Here

Examples of ro.redeul.google.go.lang.psi.expressions.GoExpr

        if (args.length < 1) {
            return;
        }

        GoExpr fmtExpr = args[0];
        if (!(fmtExpr instanceof GoLiteralExpression)) {
            return;
        }

        GoLiteralExpression literalExpression = (GoLiteralExpression)fmtExpr;
View Full Code Here

Examples of ro.redeul.google.go.lang.psi.expressions.GoExpr

            return null;
        }

        for (int i = 0; i < ids.length; i++) {
            if (name.equals(ids[i].getName())) {
                GoExpr expr = exprs[i];
                if (!(expr instanceof GoLiteralExpression)) {
                    return null;
                }

                PsiElement child = expr.getFirstChild();
                if (!(child instanceof GoLiteralString)) {
                    return null;
                }

                return (GoLiteralString) child;
View Full Code Here

Examples of ro.redeul.google.go.lang.psi.expressions.GoExpr

            }
        }
    }

    private static void assertPtrParameter(Context ctx) {
        GoExpr expr = ctx.getNextParameter();
        if (expr != null) {
            // TODO: should be pointer
        }
    }
View Full Code Here

Examples of ro.redeul.google.go.lang.psi.expressions.GoExpr

            // TODO: should be pointer
        }
    }

    private static void assertStrParameter(Context ctx) {
        GoExpr expr = ctx.getNextParameter();
        if (expr != null) {
            // TODO: should be str or byte slice
        }
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.