Search in sources :

Example 1 with GoGetPackageFix

use of com.goide.codeInsight.imports.GoGetPackageFix in project go-lang-idea-plugin by go-lang-plugin-org.

the class GoImportReference method getQuickFixes.

@Override
public LocalQuickFix[] getQuickFixes() {
    if (GoPackageUtil.isBuiltinPackage(resolve())) {
        return new LocalQuickFix[] { new GoDeleteImportQuickFix() };
    }
    List<LocalQuickFix> result = ContainerUtil.newArrayList();
    FileReferenceSet fileReferenceSet = getFileReferenceSet();
    if (fileReferenceSet instanceof GoImportReferenceSet && !((GoImportReferenceSet) fileReferenceSet).isRelativeImport() && !fileReferenceSet.isAbsolutePathReference()) {
        result.add(new GoGetPackageFix(fileReferenceSet.getPathString()));
    }
    String fileNameToCreate = getFileNameToCreate();
    for (PsiFileSystemItem context : getContexts()) {
        if (context instanceof PsiDirectory) {
            try {
                ((PsiDirectory) context).checkCreateSubdirectory(fileNameToCreate);
                String targetPath = context.getVirtualFile().getPath();
                result.add(new CreateFileFix(true, fileNameToCreate, (PsiDirectory) context) {

                    @NotNull
                    @Override
                    public String getText() {
                        return "Create Directory " + fileNameToCreate + " at " + targetPath;
                    }
                });
            } catch (IncorrectOperationException ignore) {
            }
        }
    }
    return result.toArray(new LocalQuickFix[result.size()]);
}
Also used : GoDeleteImportQuickFix(com.goide.quickfix.GoDeleteImportQuickFix) LocalQuickFix(com.intellij.codeInspection.LocalQuickFix) FileReferenceSet(com.intellij.psi.impl.source.resolve.reference.impl.providers.FileReferenceSet) NotNull(org.jetbrains.annotations.NotNull) CreateFileFix(com.intellij.codeInsight.daemon.quickFix.CreateFileFix) IncorrectOperationException(com.intellij.util.IncorrectOperationException) GoGetPackageFix(com.goide.codeInsight.imports.GoGetPackageFix)

Aggregations

GoGetPackageFix (com.goide.codeInsight.imports.GoGetPackageFix)1 GoDeleteImportQuickFix (com.goide.quickfix.GoDeleteImportQuickFix)1 CreateFileFix (com.intellij.codeInsight.daemon.quickFix.CreateFileFix)1 LocalQuickFix (com.intellij.codeInspection.LocalQuickFix)1 FileReferenceSet (com.intellij.psi.impl.source.resolve.reference.impl.providers.FileReferenceSet)1 IncorrectOperationException (com.intellij.util.IncorrectOperationException)1 NotNull (org.jetbrains.annotations.NotNull)1