Examples of GoFunctionDeclaration


Examples of ro.redeul.google.go.lang.psi.toplevel.GoFunctionDeclaration

    public void testMultipleResults() throws Exception{ doTest(); }

    @Override
    protected void invoke(Project project, Editor editor, GoFile file) {
        PsiElement element = file.findElementAt(editor.getSelectionModel().getSelectionStart());
        GoFunctionDeclaration function = findParentOfType(element, GoFunctionDeclaration.class);
        assertNotNull(function);

        new RemoveFunctionResultFix(function).invoke(project, file, editor, function, function);
    }
View Full Code Here

Examples of ro.redeul.google.go.lang.psi.toplevel.GoFunctionDeclaration

        }.visitFunctionDeclaration(function);
    }

    public static HighlightExitPointsHandler createForElement(Editor editor, PsiFile file, PsiElement element) {
        element = findParentOfType(element, GoPsiElement.class);
        GoFunctionDeclaration function = findParentOfType(element, GoFunctionDeclaration.class);
        if (function == null) {
            return null;
        }

        if (element instanceof GoReturnStatement || isPanicCall(element)) {
View Full Code Here

Examples of ro.redeul.google.go.lang.psi.toplevel.GoFunctionDeclaration

    // If it's possible to analyse the result information (like result count or even result names)
    // of the expression, we introduce variables according to the information, and return true.
    // otherwise, return false.
    private boolean introduceExpressionStatement(PsiElement element, String declaration)
        throws GoRefactoringException {
        GoFunctionDeclaration function = resolveToFunctionDeclaration(element);
        if (function == null) {
            return false;
        }

        List<String> resultNames = getFunctionResultNames(function);
View Full Code Here

Examples of ro.redeul.google.go.lang.psi.toplevel.GoFunctionDeclaration

    }

    @Override
    public Result calculateResult(@NotNull Expression[] params, ExpressionContext context) {
        String separator = readFirstParamValue(context, params, "%#v");
        GoFunctionDeclaration fd = findElementOfType(context, GoFunctionDeclaration.class);
        if (fd == null) {
            return new TextResult("");
        }

        StringBuilder sb = new StringBuilder();
        for (GoFunctionParameter fp : fd.getParameters()) {
            for (GoLiteralIdentifier id : fp.getIdentifiers()) {
                if (id != null && !id.isBlank()) {
                    String name = id.getName();
                    if (name != null) {
                        sb.append(name).append(" = [").append(separator).append("], ");
View Full Code Here

Examples of ro.redeul.google.go.lang.psi.toplevel.GoFunctionDeclaration

    }

    @Override
    public Result calculateResult(@NotNull Expression[] params, ExpressionContext context) {
        String separator = readFirstParamValue(context, params, ", ");
        GoFunctionDeclaration fd = findElementOfType(context, GoFunctionDeclaration.class);
        if (fd == null) {
            return new TextResult("");
        }

        StringBuilder sb = new StringBuilder();
        for (GoFunctionParameter fp : fd.getParameters()) {
            for (GoLiteralIdentifier id : fp.getIdentifiers()) {
                if (id != null && !id.isBlank()) {
                    String name = id.getName();
                    if (name != null) {
                        sb.append(separator).append(name);
View Full Code Here

Examples of ro.redeul.google.go.lang.psi.toplevel.GoFunctionDeclaration

        }

        int templateStartOffset = context.getTemplateStartOffset();
        final int offset = templateStartOffset > 0 ? context.getTemplateStartOffset() - 1 : context.getTemplateStartOffset();

        GoFunctionDeclaration fd = findParentOfType(file.findElementAt(offset), GoFunctionDeclaration.class);
        String name = fd == null ? "" : fd.getFunctionName();
        return new TextResult(name == null ? "" : name);
    }
View Full Code Here

Examples of ro.redeul.google.go.lang.psi.toplevel.GoFunctionDeclaration

public class ReturnInsertHandler implements InsertHandler<LookupElement> {
    @Override
    public void handleInsert(InsertionContext context, LookupElement item) {
        int offset = context.getTailOffset();
        PsiElement element = context.getFile().findElementAt(offset);
        GoFunctionDeclaration function = findParentOfType(element, GoFunctionDeclaration.class);
        if (function == null) {
            return;
        }

        int count = getFunctionResultCount(function);
View Full Code Here

Examples of ro.redeul.google.go.lang.psi.toplevel.GoFunctionDeclaration

    private static boolean isFunctionWithoutParameters(Object object) {
        if (!(object instanceof PsiElement)) {
            return false;
        }

        GoFunctionDeclaration declaration = findParentOfType((PsiElement) object, GoFunctionDeclaration.class);
        return declaration != null && declaration.getParameters().length == 0;
    }
View Full Code Here

Examples of ro.redeul.google.go.lang.psi.toplevel.GoFunctionDeclaration

            return checkValidLiteralIntExpr(((GoParenthesisedExpression) expr).getInnerExpression());
        return false;
    }

    public static void checkFunctionTypeArguments(GoCallOrConvExpression call, InspectionResult result) {
        GoFunctionDeclaration goFunctionDeclaration = GoExpressionUtils.resolveToFunctionDeclaration(call);
        GoExpr[] goExprs = call.getArguments();
        int index = 0;

        if (goFunctionDeclaration == null)
            return;

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

Examples of ro.redeul.google.go.lang.psi.toplevel.GoFunctionDeclaration

    }

    public static boolean checkFunctionTypeReturns(GoReturnStatement statement, InspectionResult result) {
        int index = 0;

        GoFunctionDeclaration containingFunction = GoPsiUtils.findParentOfType(statement, GoFunctionDeclaration.class);
        if (containingFunction == null)
            return true;

        GoType[] returnTypes = containingFunction.getReturnTypes();

        GoType[] valueTypes = GoType.EMPTY_ARRAY;

        GoExpr[] expressions = statement.getExpressions();
        if (expressions.length == 1 && expressions[0] instanceof GoCallOrConvExpression) {
            GoFunctionDeclaration calledFunction = GoExpressionUtils.resolveToFunctionDeclaration(expressions[0]);
            if ( calledFunction != null )
                valueTypes = calledFunction.getReturnTypes();
        }

        if ( valueTypes.length != returnTypes.length )
            result.addProblem(
                    statement,
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.