Examples of GoType


Examples of ro.redeul.google.go.lang.psi.typing.GoType

        assertNotSame(GoPsiType.EMPTY_ARRAY, baseTypes);

        for (GoType[] exprTypes : expressionsTypes) {
            for (int i = 0; i < baseTypes.length; i++) {
                GoType baseType = baseTypes[i];
                GoType exprType = exprTypes[i];

                assertNotNull(baseType);
                assertNotNull(exprType);

                assertTrue(
                        String.format("%s should be the same as %s",
                                GoTypes.getRepresentation(baseType.underlyingType(), (GoFile) myFile),
                                GoTypes.getRepresentation(exprType.underlyingType(), (GoFile) myFile)),

                        baseType.underlyingType().isIdentical(exprType.underlyingType()));
            }
        }
    }
View Full Code Here

Examples of ro.redeul.google.go.lang.psi.typing.GoType

        return Op.None;
    }

    @Override
    protected GoType computeConstant(@NotNull GoTypeConstant left, @NotNull GoTypeConstant right) {
        GoType builtinBool = GoTypes.getInstance(getProject()).getBuiltin(GoTypes.Builtin.Bool);

        if ( left.getKind() != GoTypeConstant.Kind.Boolean || right.getKind() != GoTypeConstant.Kind.Boolean)
            return builtinBool;

        Boolean leftValue = left.getValueAs(Boolean.class);
View Full Code Here

Examples of ro.redeul.google.go.lang.psi.typing.GoType

    }

    @Override
    protected GoType computeConstant(@NotNull GoTypeConstant left, @NotNull GoTypeConstant right) {

        GoType builtinBool = GoTypes.getInstance(getProject()).getBuiltin(GoTypes.Builtin.Bool);

        if ( left.getKind() != GoTypeConstant.Kind.Boolean || right.getKind() != GoTypeConstant.Kind.Boolean)
            return builtinBool;

        Boolean leftValue = left.getValueAs(Boolean.class);
View Full Code Here

Examples of ro.redeul.google.go.lang.psi.typing.GoType

            return checkIsInterface(((GoPsiTypeChannel) psiType).getElementType());
        return false;
    }

    public static boolean checkParametersExp(GoPsiType psiType, GoExpr expr) {
        GoType type = GoTypes.fromPsi(psiType);

        GoPsiType resolved = resolveToFinalType(psiType);
        if (resolved instanceof GoPsiTypeInterface)
            return true;
View Full Code Here

Examples of ro.redeul.google.go.lang.psi.typing.GoType

                                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);
View Full Code Here

Examples of ro.redeul.google.go.lang.psi.typing.GoType

        GoLiteralExpression literalExpression = getAs(GoLiteralExpression.class, selectorExpression.getBaseExpression());

        if ( literalExpression == null )
            return null;

        GoType types[] = literalExpression.getType();

        if ( types.length == 0 || types[0] == null || !(types[0] instanceof GoTypePackage) )
            return null;

        GoTypePackage typePackage = (GoTypePackage)types[0];
View Full Code Here

Examples of ro.redeul.google.go.lang.psi.typing.GoType

                    }

                    @Override
                    public void visitVarDeclaration(GoVarDeclaration declaration) {
                        if (resolvedIdent != null) {
                            GoType identifierType = declaration.getIdentifierType(resolvedIdent);

                            if (identifierType != null)
                                setData(new GoType[]{identifierType});
                        }
                    }

                    @Override
                    public void visitConstDeclaration(GoConstDeclaration declaration) {
                        if (resolvedIdent != null) {
                            GoType declaredType = types.fromPsiType(declaration.getIdentifiersType());
                            GoExpr expr = declaration.getExpression(resolvedIdent);

                            if (expr != null) {
                                GoType[] exprType = expr.getType();
View Full Code Here

Examples of ro.redeul.google.go.lang.psi.typing.GoType

        while ( ! typeNamesToExplore.isEmpty() ) {
            GoTypeName currentTypeName = typeNamesToExplore.poll();

            receiverTypes.add(currentTypeName);

            GoType underlyingType = currentTypeName.underlyingType();
            if ( !(underlyingType instanceof GoTypeStruct) )
                continue;

            GoTypeStruct typeStruct = (GoTypeStruct) underlyingType;
            for (GoTypeStructAnonymousField field : typeStruct.getPsiType().getAnonymousFields()) {
                GoPsiType psiType = field.getType();
                if ( psiType == null)
                    continue;
                if ( psiType instanceof GoPsiTypePointer) {
                    psiType = ((GoPsiTypePointer) psiType).getTargetType();
                }

                GoType embeddedType = GoTypes.fromPsi(psiType);
                if (!(embeddedType instanceof GoTypeName))
                    continue;

                GoTypeName embeddedTypeName = (GoTypeName) embeddedType;
                if (! receiverTypes.contains(embeddedTypeName) )
View Full Code Here

Examples of ro.redeul.google.go.lang.psi.typing.GoType

                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;
            }

            GoType desiredType = function.getParameterType(pos);

            if ( desiredType instanceof GoTypeFunction ) {
                GoTypeFunction typeFunction = (GoTypeFunction) desiredType;
                int i = 0;

                stringBuilder.append("(");
                GoType parameterType = null;
                while ( (parameterType = typeFunction.getParameterType(i)) != null) {
                    stringList.add(String.format("arg%d", i));

                    if ( i > 0 )
                        stringBuilder.append(",");

                    stringBuilder.append(String.format("$v%d$ ", i));
                    stringBuilder.append(GoTypes.getRepresentation(parameterType, currentFile));
                    i++;
                }
                stringBuilder.append(")");

                GoType[] results = typeFunction.getResultTypes();
                if ( results.length > 1 ) stringBuilder.append("(");
                for (int i1 = 0; i1 < results.length; i1++) {
                    GoType goType = results[i1];
                    if( i1 > 0)
                        stringBuilder.append(",");
                    stringBuilder.append(GoTypes.getRepresentation(goType, currentFile));
                }
                if ( results.length > 1 ) stringBuilder.append(")");
View Full Code Here

Examples of ro.redeul.google.go.lang.psi.typing.GoType

            @Override
            public void visitConstDeclaration(GoConstDeclaration declaration) {
                String referenceName = reference.name();

                GoType identifiersType = GoTypes.fromPsi(declaration.getIdentifiersType());

                for (GoLiteralIdentifier identifier : declaration.getIdentifiers()) {

                    if (!reference.canSee(identifier, referenceName))
                        continue;

                    GoType identifierType = identifiersType;
                    if (identifierType == GoType.Unknown) {
                        GoExpr expr = declaration.getExpression(identifier);
                        if (expr != null) {
                            GoType[] exprType = expr.getType();
                            if (exprType.length > 0 && exprType[0] != 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.