Package ro.redeul.google.go.lang.psi.toplevel

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


        if (ids.length == 0) {
            addImportUnderPackage(file, document, pathToImport);
            return;
        }

        GoImportDeclarations importDeclarations = ids[ids.length - 1];
        GoImportDeclaration[] imports = importDeclarations.getDeclarations();

        if (imports.length == 0) {
            addImportUnderPackage(file, document, pathToImport);
            return;
        }

        GoImportDeclaration lastImport = imports[imports.length - 1];

        PsiElement lastChild = getPrevSiblingIfItsWhiteSpaceOrComment(importDeclarations.getLastChild());
        if (lastChild == null) {
            addImportUnderPackage(file, document, pathToImport);
            return;
        }
View Full Code Here


        if (!(startElement instanceof GoImportDeclaration) || !(file instanceof GoFile)) {
            return;
        }

        GoImportDeclaration declaration = (GoImportDeclaration) startElement;
        final GoImportDeclarations declarations = (GoImportDeclarations) declaration.getParent();
        String removeImport = declaration.getText();
        if (removeImport == null) {
            return;
        }

        GoImportDeclaration[] da = declarations.getDeclarations();
        // if there are more than 2 imports, just remove current one.
        if (da.length > 2) {
            removeWholeElement(declaration);
            return;
        }

        // if there are exactly 2 imports, replace the whole import to import "theOther". i.e. remove parenthesis.
        if (da.length == 2) {
            final PsiElement newImport = getNewImport(da, startElement.getText(), (GoFile) file);
            if (newImport != null) {
                WriteCommandAction writeCommandAction = new WriteCommandAction(file.getProject()) {
                    @Override
                    protected void run(@NotNull Result result) throws Throwable {
                        declarations.replace(newImport);
                    }
                };
                writeCommandAction.execute();
                return;
            }
View Full Code Here

TOP

Related Classes of ro.redeul.google.go.lang.psi.toplevel.GoImportDeclarations

Copyright © 2018 www.massapicom. 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.