Examples of GoRefactoringException


Examples of ro.redeul.google.go.refactoring.GoRefactoringException

    @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);
        if (document == null) {
            return;
        }

        this.project = project;
        this.editor = editor;
        this.document = document;
        this.file = file;

        GoExpr[] occurrences = ExpressionOccurrenceManager.findOccurrences(e, getDefaultVisitStartElement());
        if (occurrences.length == 0) {
            throw new GoRefactoringException(GoBundle.message("error.invalid.expression"));
        }

        includeExpressionParenthesesIfPossible(occurrences);

        ReplaceChoicePass callback = new ReplaceChoicePass(e, occurrences);
View Full Code Here

Examples of ro.redeul.google.go.refactoring.GoRefactoringException

            return false;
        }

        List<String> resultNames = getFunctionResultNames(function);
        if (resultNames.isEmpty()) {
            throw new GoRefactoringException(
                GoBundle.message("error.expression.has.void.return.type"));
        }

        TextRange range = element.getTextRange();
        editor.getDocument()
View Full Code Here

Examples of ro.redeul.google.go.refactoring.GoRefactoringException

        RangeMarker[] exprRangeMarkers = new RangeMarker[occurrences.length];
        GoStatement[] statements = new GoStatement[occurrences.length];
        for (int i = 0; i < occurrences.length; i++) {
            statements[i] = findParentOfType(occurrences[i], GoStatement.class);
            if (statements[i] == null) {
                throw new GoRefactoringException("Cannot find corresponding statement");
            }
            exprRangeMarkers[i] = document.createRangeMarker(occurrences[i].getTextRange());
        }

        int insertionPoint = findInsertionPoint(statements);
View Full Code Here

Examples of ro.redeul.google.go.refactoring.GoRefactoringException

        if (parent != null && !(parent instanceof GoBlockStatement)) {
            parent = parent.getParent();
        }

        if (!(parent instanceof GoBlockStatement)) {
            throw new GoRefactoringException("Unknown case");
        }

        int minOffset = statements[0].getTextOffset();
        for (GoStatement statement : statements) {
            minOffset = Math.min(minOffset, statement.getTextOffset());
View Full Code Here

Examples of ro.redeul.google.go.refactoring.GoRefactoringException

        String name = ctx.identifierToInline.getName();
        PsiElement initializer = getInitializer(ctx.identifierToInline);
        boolean shouldHaveInitializer = identifierShouldHaveInitializer(ctx.identifierToInline);
        if (shouldHaveInitializer && initializer == null ||
                usage.writeUsages.length == 0 && !shouldHaveInitializer) {
            throw new GoRefactoringException(RefactoringBundle.message("variable.has.no.initializer", ctx.identifierToInline.getText()));
        }

        if (usage.readUsages.length == 0) {
            String messsage = GoBundle.message("error.variable.is.never.used", name);
            throw new GoRefactoringException(messsage);
        }

        if (usage.writeUsages.length == 1 && !shouldHaveInitializer) {
            if (usage.readUsages[0].getTextOffset() > usage.writeUsages[0].getTextOffset()) {
                String messsage = GoBundle.message("error.variable.is.used.before.modification", name);
                throw new GoRefactoringException(messsage);
            }

            initializer = getInitializer((GoLiteralIdentifier) usage.writeUsages[0]);
            if (initializer == null) {
                throw new GoRefactoringException(RefactoringBundle.message("variable.has.no.initializer", ctx.identifierToInline.getText()));
            }
        }

        if (usage.writeUsages.length >= 2 ||
                usage.writeUsages.length == 1 && shouldHaveInitializer) {
            throw new GoRefactoringException(RefactoringBundle.message("variable.is.accessed.for.writing", name));
        }

        while (initializer instanceof GoParenthesisedExpression) {
            initializer = ((GoParenthesisedExpression) initializer).getInnerExpression();
        }
View Full Code Here

Examples of ro.redeul.google.go.refactoring.GoRefactoringException

        int start = simpleStatement.getTextOffset();
        document.deleteString(start, endElement.getTextOffset());
    }

    private void unknownCase() throws GoRefactoringException {
        throw new GoRefactoringException(GoBundle.message("error.unknown.refactoring.case"));
    }
View Full Code Here

Examples of ro.redeul.google.go.refactoring.GoRefactoringException

abstract class GoIntroduceHandlerBase implements RefactoringActionHandler {
    @Override
    public void invoke(@NotNull final Project project, final Editor editor, PsiFile psiFile, DataContext dataContext) {
        try {
            if (!CommonRefactoringUtil.checkReadOnlyStatus(project, psiFile)) {
                throw new GoRefactoringException("It's a readonly file!");
            }

            if (!(psiFile instanceof GoFile)) {
                throw new GoRefactoringException("Only go file could be handled.");
            }

            final GoFile file = (GoFile) psiFile;

            PsiDocumentManager.getInstance(project).commitAllDocuments();
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.