Search in sources :

Example 1 with ScratchFileType

use of com.intellij.ide.scratch.ScratchFileType in project go-lang-idea-plugin by go-lang-plugin-org.

the class GoMultiplePackagesInspection method checkFile.

@Override
protected void checkFile(@NotNull GoFile file, @NotNull ProblemsHolder problemsHolder) {
    if (((ScratchFileType) ScratchFileType.INSTANCE).isMyFileType(file.getVirtualFile()))
        return;
    GoPackageClause packageClause = file.getPackage();
    if (packageClause != null) {
        String packageName = file.getPackageName();
        if (packageName == null || packageName.equals(GoConstants.DOCUMENTATION))
            return;
        PsiDirectory dir = file.getContainingDirectory();
        Collection<String> packages = GoPackageUtil.getAllPackagesInDirectory(dir, null, true);
        packages.remove(GoConstants.DOCUMENTATION);
        if (packages.size() > 1) {
            Collection<LocalQuickFix> fixes = ContainerUtil.newArrayList();
            if (problemsHolder.isOnTheFly()) {
                fixes.add(new GoMultiplePackagesQuickFix(packageClause, packageName, packages, true));
            } else {
                for (String name : packages) {
                    fixes.add(new GoMultiplePackagesQuickFix(packageClause, name, packages, false));
                }
            }
            problemsHolder.registerProblem(packageClause, "Multiple packages in directory", fixes.toArray(new LocalQuickFix[fixes.size()]));
        }
    }
}
Also used : PsiDirectory(com.intellij.psi.PsiDirectory) GoPackageClause(com.goide.psi.GoPackageClause) ScratchFileType(com.intellij.ide.scratch.ScratchFileType) LocalQuickFix(com.intellij.codeInspection.LocalQuickFix) GoMultiplePackagesQuickFix(com.goide.quickfix.GoMultiplePackagesQuickFix)

Aggregations

GoPackageClause (com.goide.psi.GoPackageClause)1 GoMultiplePackagesQuickFix (com.goide.quickfix.GoMultiplePackagesQuickFix)1 LocalQuickFix (com.intellij.codeInspection.LocalQuickFix)1 ScratchFileType (com.intellij.ide.scratch.ScratchFileType)1 PsiDirectory (com.intellij.psi.PsiDirectory)1