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;
}
}
}
}
};
}
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()]);
}
Aggregations