Examples of GoCallOrConvExpression


Examples of ro.redeul.google.go.lang.psi.expressions.primary.GoCallOrConvExpression

                      "package main\n" +
                      "func main() {" +
                      " f()" +
                      "}"));

        GoCallOrConvExpression expr =
            getAs(GoCallOrConvExpression.class,
                  castAs(GoExpressionStatement.class, 0,
                         get(
                             get(
                                 file.getMainFunction()
                             ).getBlock()
                         ).getStatements()
                  ).getExpression()
            );

        assertEquals("f", get(expr.getBaseExpression()).getText());
        assertEquals(0, expr.getArguments().length);
    }
View Full Code Here

Examples of ro.redeul.google.go.lang.psi.expressions.primary.GoCallOrConvExpression

                      "package main\n" +
                      "func main() {" +
                      " f(1)" +
                      "}"));

        GoCallOrConvExpression expr =
            getAs(GoCallOrConvExpression.class,
                  castAs(GoExpressionStatement.class, 0,
                         get(
                             get(
                                 file.getMainFunction()
                             ).getBlock()
                         ).getStatements()
                  ).getExpression()
            );

        assertEquals("f", get(expr.getBaseExpression()).getText());
        assertEquals(1, expr.getArguments().length);
        assertEquals("1", childAt(0, expr.getArguments()).getText());
    }
View Full Code Here

Examples of ro.redeul.google.go.lang.psi.expressions.primary.GoCallOrConvExpression

                      "package main\n" +
                      "func main() {" +
                      " f(1, 2)" +
                      "}"));

        GoCallOrConvExpression expr =
            getAs(GoCallOrConvExpression.class,
                  castAs(GoExpressionStatement.class, 0,
                         get(
                             get(
                                 file.getMainFunction()
                             ).getBlock()
                         ).getStatements()
                  ).getExpression()
            );

        assertEquals("f", get(expr.getBaseExpression()).getText());
        assertEquals(2, expr.getArguments().length);
        assertEquals("1", childAt(0, expr.getArguments()).getText());
        assertEquals("2", childAt(1, expr.getArguments()).getText());
    }
View Full Code Here

Examples of ro.redeul.google.go.lang.psi.expressions.primary.GoCallOrConvExpression

                      "package main\n" +
                      "func main() {" +
                      " f(nil, 2)" +
                      "}"));

        GoCallOrConvExpression expr =
            getAs(GoCallOrConvExpression.class,
                  castAs(GoExpressionStatement.class, 0,
                         get(
                             get(
                                 file.getMainFunction()
                             ).getBlock()
                         ).getStatements()
                  ).getExpression()
            );

        assertEquals("f", get(expr.getBaseExpression()).getText());
        assertEquals(2, expr.getArguments().length);
        assertEquals("nil", childAt(0, expr.getArguments()).getText());
        assertEquals("2", childAt(1, expr.getArguments()).getText());
    }
View Full Code Here

Examples of ro.redeul.google.go.lang.psi.expressions.primary.GoCallOrConvExpression

                      "import \"fmt\"\n" +
                      "func main() {\n" +
                      "     fmt.Fprintf(nil, \"/*begin*/%f/*end.Missing parameter*/\\n\")\n" +
                      "}"));

        GoCallOrConvExpression expr =
            getAs(GoCallOrConvExpression.class,
                  castAs(GoExpressionStatement.class, 0,
                         get(
                             get(
                                 file.getMainFunction()
                             ).getBlock()
                         ).getStatements()
                  ).getExpression()
            );

        assertEquals("fmt.Fprintf", get(expr.getBaseExpression()).getText());
        assertEquals(2, expr.getArguments().length);
        assertEquals("nil", childAt(0, expr.getArguments()).getText());
        assertEquals("\"/*begin*/%f/*end.Missing parameter*/\\n\"", childAt(1, expr.getArguments()).getText());
    }
View Full Code Here

Examples of ro.redeul.google.go.lang.psi.expressions.primary.GoCallOrConvExpression

    public static String getNameLocalOrGlobal(GoType type, GoFile currentFile) {
        return GoTypes.getRepresentation(type, currentFile);
    }

    public static boolean isFunctionNameIdentifier(PsiElement e) {
        GoCallOrConvExpression callOrConvExpression = findParentOfType(e, GoCallOrConvExpression.class);

        return callOrConvExpression != null && callOrConvExpression.getTextOffset() == e.getTextOffset();
    }
View Full Code Here

Examples of ro.redeul.google.go.lang.psi.expressions.primary.GoCallOrConvExpression

                    PsiElement.class);
            if (reference != null && reference.getParent() instanceof GoFunctionDeclaration){
                return (GoFunctionDeclaration) reference.getParent();
            }
        }
        GoCallOrConvExpression callExpr = findParentOfType(element, GoCallOrConvExpression.class);
        return getFunctionDeclaration(getCallFunctionIdentifier(callExpr));
    }
View Full Code Here

Examples of ro.redeul.google.go.lang.psi.expressions.primary.GoCallOrConvExpression

        int arg = 0;
        final GoFile currentFile = (GoFile) e.getContainingFile();


        if (GoUtil.isFunctionNameIdentifier(e)) {
            GoCallOrConvExpression callOrConvExpression = findParentOfType(e, GoCallOrConvExpression.class);
            stringBuilder.append("(");
            for (GoExpr argument : callOrConvExpression.getArguments()) {
                if (arg != 0)
                    stringBuilder.append(',');

                stringBuilder.append(String.format("$v%d$ ", arg));
                stringList.add(String.format("arg%d", arg));

                PsiElement firstChildExp = argument.getFirstChild();
                GoType[] goTypes = argument.getType();

                if (goTypes.length > 0 && goTypes[0] != null) {
                    GoType goType = goTypes[0];
                    stringBuilder.append(GoTypes.getRepresentation(goType, currentFile));

                } else if (firstChildExp instanceof GoLiteral) {
                    /*
                     * Resolves the type of a literal
                     */
                    stringBuilder.append(((GoLiteral) firstChildExp).getType().name().toLowerCase());
                } else {

                    /*
                     * This block try to resolve the return type of a closure being called on the paramenter list
                     * ex: unresolvedFn(func()int{return 25*4}())
                     * will generate:
                     * func unresolvedFn(arg0 int){}
                     * @note i think any one will do that, but we never know :D
                     */
                    PsiElement firstChild = firstChildExp.getFirstChild();
                    if (firstChild instanceof GoLiteralFunction) {

                        GoType[] returnType = ((GoLiteralFunction) firstChild).getReturnTypes();
                        if (returnType.length > 0) {
                            stringBuilder.append("<berila>");
                        } else {
                            stringBuilder.append("interface{}");
                        }
                    } else if (firstChild instanceof GoLiteral) {
                        GoLiteral.Type type = ((GoLiteral) firstChild).getType();
                        //Fix TEST PR ##321 this only happens on test. i don't know why
                        if (type == GoLiteral.Type.Float || type == GoLiteral.Type.ImaginaryFloat) {
                            stringBuilder.append("float32");
                        } else {
                            stringBuilder.append(type.name().toLowerCase());
                        }
                    } else {
                        stringBuilder.append("interface{}");
                    }
                }
                arg++;
            }
            stringBuilder.append(")");
        } else {
            /*
             * Try to resolve the type declaration for the generated function based on called function
             * ex: when http.HandleFunc("/",myIndexHandle)
             * will generate:
             *          func myIndexHandle(arg0 http.ResponseWriter, arg1 *http.Request){}
             */

            GoCallOrConvExpression callExpression = findParentOfType(e, GoCallOrConvExpression.class);
            GoType[] type = callExpression.getBaseExpression().getType();

            if ( type.length != 1 || ! (type[0] instanceof GoTypeFunction) )
                return "";

            GoTypeFunction function = (GoTypeFunction) type[0];

            int pos = -1;
            for (GoExpr expr : callExpression.getArguments()) {
                pos++;
                if ( expr.getTextOffset() == e.getTextOffset() && expr.getTextLength() == e.getTextLength() )
                    break;
            }

View Full Code Here

Examples of ro.redeul.google.go.lang.psi.expressions.primary.GoCallOrConvExpression

        oldPi.currentIndex = pi.currentIndex;
        return pi.call;
    }

    private GoCallOrConvExpression findFunctionCallParent(PsiElement element, int offset) {
        GoCallOrConvExpression call = findParentOfType(element, GoCallOrConvExpression.class);
        if (call == null) {
            return null;
        }

        List<GoExpr> exprs = findChildrenOfType(call, GoExpr.class);
        if (exprs.isEmpty()) {
            return null;
        }

        PsiElement child = exprs.get(0);
        if (!(child instanceof GoLiteralExpression)) {
            return null;
        }

        // If the caret is on function name, current function parameters info shouldn't be shown.
        // Let's see if the function call is a parameter of another function call.
        if (child.getTextRange().contains(offset)) {
            return findFunctionCallParent(call.getParent(), offset);
        }
        return call;
    }
View Full Code Here

Examples of ro.redeul.google.go.lang.psi.expressions.primary.GoCallOrConvExpression

        return call;
    }

    private ParameterInfo findAnchorElement(int offset, PsiFile file) {
        PsiElement element = file.findElementAt(offset);
        GoCallOrConvExpression call = findFunctionCallParent(element, offset);
        GoFunctionDeclaration func = resolveToFunctionDeclaration(call);
        if (func == null) {
            return null;
        }
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.