Search in sources :

Example 1 with CreateFileFix

use of com.intellij.codeInsight.daemon.quickFix.CreateFileFix in project intellij-plugins by JetBrains.

the class CfmlFileReferenceInspection method buildVisitor.

@NotNull
public PsiElementVisitor buildVisitor(@NotNull final ProblemsHolder holder, final boolean isOnTheFly) {
    return new PsiElementVisitor() {

        public void visitElement(final PsiElement element) {
            PsiElement tagParent = PsiTreeUtil.getParentOfType((element), CfmlTag.class);
            if ((element.getNode().getElementType() == CfmlTokenTypes.STRING_TEXT)) {
                if ((tagParent == null || (!((CfmlTag) tagParent).getTagName().equalsIgnoreCase("cfinclude") && !((CfmlTag) tagParent).getTagName().equalsIgnoreCase("cfmodule")))) {
                    PsiElement superParent = element.getParent() != null ? element.getParent().getParent() : null;
                    ASTNode superParentNode = superParent != null ? superParent.getNode() : null;
                    if ((superParentNode == null || superParentNode.getElementType() != CfmlElementTypes.INCLUDEEXPRESSION)) {
                        return;
                    }
                }
                final PsiReference[] refs = element.getParent().getReferences();
                for (int i = 0, refsLength = refs.length; i < refsLength; i++) {
                    PsiReference ref = refs[i];
                    if (!(ref instanceof FileReference))
                        continue;
                    if (ref.resolve() == null) {
                        PsiDirectory dir;
                        if (i > 0) {
                            final PsiElement target = refs[i - 1].resolve();
                            dir = target instanceof PsiDirectory ? (PsiDirectory) target : null;
                        } else {
                            dir = element.getContainingFile().getParent();
                        }
                        holder.registerProblem(ref.getElement(), ref.getRangeInElement(), isOnTheFly ? "Path '" + ref.getCanonicalText() + "' not found" : "Path not found", isOnTheFly && dir != null ? new LocalQuickFix[] { new CreateFileFix(i < refs.length - 1, ref.getCanonicalText(), dir) } : LocalQuickFix.EMPTY_ARRAY);
                        //                       ProblemHighlightType.ERROR);
                        break;
                    }
                }
            }
        }
    };
}
Also used : CreateFileFix(com.intellij.codeInsight.daemon.quickFix.CreateFileFix) PsiDirectory(com.intellij.psi.PsiDirectory) ASTNode(com.intellij.lang.ASTNode) PsiReference(com.intellij.psi.PsiReference) LocalQuickFix(com.intellij.codeInspection.LocalQuickFix) CfmlTag(com.intellij.coldFusion.model.psi.CfmlTag) PsiElementVisitor(com.intellij.psi.PsiElementVisitor) FileReference(com.intellij.psi.impl.source.resolve.reference.impl.providers.FileReference) PsiElement(com.intellij.psi.PsiElement) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with CreateFileFix

use of com.intellij.codeInsight.daemon.quickFix.CreateFileFix 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

CreateFileFix (com.intellij.codeInsight.daemon.quickFix.CreateFileFix)2 LocalQuickFix (com.intellij.codeInspection.LocalQuickFix)2 NotNull (org.jetbrains.annotations.NotNull)2 GoGetPackageFix (com.goide.codeInsight.imports.GoGetPackageFix)1 GoDeleteImportQuickFix (com.goide.quickfix.GoDeleteImportQuickFix)1 CfmlTag (com.intellij.coldFusion.model.psi.CfmlTag)1 ASTNode (com.intellij.lang.ASTNode)1 PsiDirectory (com.intellij.psi.PsiDirectory)1 PsiElement (com.intellij.psi.PsiElement)1 PsiElementVisitor (com.intellij.psi.PsiElementVisitor)1 PsiReference (com.intellij.psi.PsiReference)1 FileReference (com.intellij.psi.impl.source.resolve.reference.impl.providers.FileReference)1 FileReferenceSet (com.intellij.psi.impl.source.resolve.reference.impl.providers.FileReferenceSet)1 IncorrectOperationException (com.intellij.util.IncorrectOperationException)1