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

Examples of ro.redeul.google.go.lang.psi.GoFile


                                GoTestUtils.MARKER_CARET)));
    }

    private String processFile(String fileText, boolean addCaretMarker) throws IOException {
        addPackageBuiltin();
        final GoFile goFile = createGoFile(fileText);

        final Editor myEditor = myFixture.getEditor();
        CodeStyleSettings settings =
                CodeStyleSettingsManager.getInstance(getProject()).getCurrentSettings();
        CommonCodeStyleSettings commonSettings =
View Full Code Here


                caretOffset) + GoTestUtils.MARKER_CARET + result
                .substring(caretOffset);
    }

    private GoFile createGoFile(String fileText) {
        GoFile goFile;
        int startOffset = fileText.indexOf(GoTestUtils.MARKER_BEGIN);
        if (startOffset != -1) {
            fileText = GoTestUtils.removeBeginMarker(fileText);
            int endOffset = fileText.indexOf(GoTestUtils.MARKER_END);
            fileText = GoTestUtils.removeEndMarker(fileText);
View Full Code Here

        if ( element == null )
            return null;

        GoPackages goPackages = getInstance(element.getProject());

        GoFile goFile = getAs(GoFile.class, element.getContainingFile());

        if ( goFile == null )
            return null;

        String packageImportPath = goFile.getPackageImportPath();

        return goPackages.getPackage(packageImportPath);
    }
View Full Code Here

        CommonProcessors.CollectUniquesProcessor<String> localPackages = new CommonProcessors.CollectUniquesProcessor<String>();

        Function<VirtualFile, String> convertor = new Function<VirtualFile, String>() {
            public String fun(VirtualFile virtualFile) {

                GoFile goFile = (GoFile) psiManager.findFile(virtualFile);
                if (goFile == null) {
                    return "";
                }

                String packageName = goFile.getPackage().getPackageName();

                // in the same folder as the target file we just import the package
                if (targetFile.getParent().equals(virtualFile.getParent())) {
                    return packageName;
                }

                String importName = VfsUtil.getRelativePath(virtualFile.getParent(), targetFile.getParent(), '/');
                if (!virtualFile.getParent().getName().equals(packageName)) {
                    importName += "/" + packageName;
                }

                return importName;
            }
        };

        Processor<VirtualFile> processor = new AdapterProcessor<VirtualFile, String>(localPackages, convertor) {
            @Override
            public boolean process(VirtualFile file) {
                if (file.getFileType() == GoFileType.INSTANCE) {
                    GoFile goFile = (GoFile) psiManager.findFile(file);

                    if (goFile != null && !goFile.getPackage().isMainPackage()) {
                        super.process(file);
                    }

                    return true;
                }
View Full Code Here

            if (packageName.equals(id.getPackageAlias())) {
                return;
            }
        }

        GoFile goFile = (GoFile) file;
        GoNamesCache namesCache = GoNamesCache.getInstance(context.getProject());
        List<String> sdkPackages = getPackagesByName(namesCache.getSdkPackages(), packageName);
        List<String> projectPackages = getPackagesByName(namesCache.getProjectPackages(), packageName);
        new AddImportFix(sdkPackages, projectPackages, goFile, context.getEditor()).execute();
    }
View Full Code Here

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

            final GoFile file = (GoFile) psiFile;

            PsiDocumentManager.getInstance(project).commitAllDocuments();

            final SelectionModel sm = editor.getSelectionModel();
            if (sm.hasSelection()) {
                introduce(project, editor, file, sm.getSelectionStart(), sm.getSelectionEnd());
                return;
            }

            // If nothing is selected in editor, find all potential expressions.
            int offset = editor.getCaretModel().getOffset();
            PsiElement element = getPrevSiblingIfItsWhiteSpaceOrComment(file.findElementAt(offset));
            if (element != null) {
                offset = Math.min(offset, element.getTextRange().getEndOffset() - 1);
            }
            List<GoExpr> expressions = collectExpressions(file, offset);
            if (expressions.isEmpty()) {
View Full Code Here

    private void checkIndexExpression(GoIndexExpression expression, final InspectionResult result) {
        final GoExpr indexExpr = expression.getIndex();
        if (indexExpr == null)
            return;

        final GoFile goFile = getAs(GoFile.class, indexExpr.getContainingFile());
        if (goFile == null)
            return;

        final GoType[] indexTypes = indexExpr.getType();
View Full Code Here

        Set<String> packages = new HashSet<String>();

        for (PsiFile child : childs) {
            if (child instanceof GoFile) {
                GoFile goFile = (GoFile) child;

                if ( ! goFile.getPackage().isMainPackage() ) {
                    packages.add(goFile.getPackage().getPackageName());
                }
            }
        }

        builder.addKind("New library", GoIcons.GO_ICON_16x16, "multiple");
View Full Code Here

                        String text = element.getLastChild().getText();
                        if (text.length() != 0 && Character.isUpperCase(text.charAt(0))) {
                             /*
                             * We can also resolve nested packages
                             */
                            final GoFile containingFile = (GoFile) element.getContainingFile();
                            final GoImportDeclarations[] importDeclarations = containingFile.getImportDeclarations();

                            for (GoImportDeclarations goImportDeclarations : importDeclarations) {
                                final GoImportDeclaration[] declarations = goImportDeclarations.getDeclarations();
                                for (final GoImportDeclaration declaration : declarations) {

View Full Code Here

    public Runnable processFile(PsiFile file) {
        if (!(file instanceof GoFile)) {
            return EmptyRunnable.getInstance();
        }

        final GoFile goFile = (GoFile) file;
        return new Runnable() {
            @Override
            public void run() {
                optimize(goFile);
            }
View Full Code Here

TOP

Related Classes of ro.redeul.google.go.lang.psi.GoFile

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.