com.intellij.codeInspection.LocalQuickFix Java Examples
The following examples show how to use
com.intellij.codeInspection.LocalQuickFix.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: InvalidVersionInspection.java From intellij-xquery with Apache License 2.0 | 6 votes |
@Override public ProblemDescriptor[] checkFile(@NotNull PsiFile file, @NotNull InspectionManager manager, boolean isOnTheFly) { if (!(file instanceof XQueryFile)) { return null; } XQueryVersionDecl versionDecl = PsiTreeUtil.findChildOfType(file, XQueryVersionDecl.class); XQueryVersion version = versionDecl != null ? versionDecl.getVersion() : null; if (version != null) { String versionString = version.getVersionString(); XQueryLanguageVersion languageVersion = XQueryLanguageVersion.valueFor(versionString); if (languageVersion == null) { ProblemDescriptor problem = manager.createProblemDescriptor(versionDecl.getVersion(), getDescription(versionString), (LocalQuickFix) null, WEAK_WARNING, true); return new ProblemDescriptor[]{problem}; } } return null; }
Example #2
Source File: NamespacePrefixFromFileName.java From intellij-xquery with Apache License 2.0 | 6 votes |
@Override public ProblemDescriptor[] checkFile(PsiFile file, InspectionManager manager, boolean isOnTheFly) { if (!(file instanceof XQueryFile)) { return null; } final XQueryModuleDecl moduleDeclaration = ((XQueryFile) file).getModuleDeclaration(); if (moduleDeclaration != null && moduleDeclaration.getNamespacePrefix() != null && moduleDeclaration.getURILiteral() != null && !namespacePrefixIsDerivedFromFileName(moduleDeclaration)) { ProblemDescriptor[] problemDescriptors = new ProblemDescriptor[1]; problemDescriptors[0] = manager.createProblemDescriptor(moduleDeclaration.getNamespacePrefix(), "Namespace prefix should be derived from file name part in URI", (LocalQuickFix) null, GENERIC_ERROR_OR_WARNING, true); return problemDescriptors; } else { return null; } }
Example #3
Source File: BuildFileTypeInspection.java From intellij-pants-plugin with Apache License 2.0 | 6 votes |
@Override @Nullable public ProblemDescriptor[] checkFile(@NotNull PsiFile file, @NotNull InspectionManager manager, boolean isOnTheFly) { if (PantsUtil.isBUILDFileName(file.getName()) && PantsUtil.isPythonAvailable() && PantsUtil.isPantsProject(file.getProject())) { if (file.getFileType() != PythonFileType.INSTANCE) { LocalQuickFix[] fixes = new LocalQuickFix[]{new TypeAssociationFix()}; ProblemDescriptor descriptor = manager.createProblemDescriptor( file.getNavigationElement(), PantsBundle.message("pants.info.mistreated.build.file"), isOnTheFly, fixes, ProblemHighlightType.GENERIC_ERROR_OR_WARNING ); return new ProblemDescriptor[]{descriptor}; } } return null; }
Example #4
Source File: PythonPluginInspection.java From intellij-pants-plugin with Apache License 2.0 | 6 votes |
@Override @Nullable public ProblemDescriptor[] checkFile(@NotNull PsiFile file, @NotNull InspectionManager manager, boolean isOnTheFly) { if (PantsUtil.isBUILDFileName(file.getName()) && !PantsUtil.isPythonAvailable() && PantsUtil.isPantsProject(file.getProject())) { LocalQuickFix[] fixes = new LocalQuickFix[]{new AddPythonPluginQuickFix()}; ProblemDescriptor descriptor = manager.createProblemDescriptor( file.getNavigationElement(), PantsBundle.message("pants.info.python.plugin.missing"), isOnTheFly, fixes, ProblemHighlightType.GENERIC_ERROR_OR_WARNING ); return new ProblemDescriptor[]{descriptor}; } return null; }
Example #5
Source File: PythonFacetInspection.java From intellij-pants-plugin with Apache License 2.0 | 6 votes |
@Override @Nullable public ProblemDescriptor[] checkFile(@NotNull PsiFile file, @NotNull InspectionManager manager, boolean isOnTheFly) { if (shouldAddPythonSdk(file)) { LocalQuickFix[] fixes = new LocalQuickFix[]{new AddPythonFacetQuickFix()}; ProblemDescriptor descriptor = manager.createProblemDescriptor( file.getNavigationElement(), PantsBundle.message("pants.info.python.facet.missing"), isOnTheFly, fixes, ProblemHighlightType.GENERIC_ERROR_OR_WARNING ); return new ProblemDescriptor[]{descriptor}; } return null; }
Example #6
Source File: IntentionManagerImpl.java From consulo with Apache License 2.0 | 5 votes |
@Override @Nonnull public LocalQuickFix convertToFix(@Nonnull final IntentionAction action) { if (action instanceof LocalQuickFix) { return (LocalQuickFix)action; } return new LocalQuickFix() { @Override @Nonnull public String getName() { return action.getText(); } @Override @Nonnull public String getFamilyName() { return action.getFamilyName(); } @Override public void applyFix(@Nonnull final Project project, @Nonnull final ProblemDescriptor descriptor) { final PsiFile psiFile = descriptor.getPsiElement().getContainingFile(); try { action.invoke(project, new LazyEditor(psiFile), psiFile); } catch (IncorrectOperationException e) { LOG.error(e); } } }; }
Example #7
Source File: PsiDynaReference.java From consulo with Apache License 2.0 | 5 votes |
@Override public LocalQuickFix[] getQuickFixes() { final ArrayList<LocalQuickFix> list = new ArrayList<LocalQuickFix>(); for (Object ref: myReferences) { if (ref instanceof LocalQuickFixProvider) { ContainerUtil.addAll(list, ((LocalQuickFixProvider)ref).getQuickFixes()); } } return list.toArray(new LocalQuickFix[list.size()]); }
Example #8
Source File: QuickFixWrapper.java From consulo with Apache License 2.0 | 5 votes |
@Override public void invoke(@Nonnull Project project, Editor editor, PsiFile file) throws IncorrectOperationException { //if (!CodeInsightUtil.prepareFileForWrite(file)) return; // consider all local quick fixes do it themselves final PsiElement element = myDescriptor.getPsiElement(); final PsiFile fileForUndo = element == null ? null : element.getContainingFile(); LocalQuickFix fix = getFix(); fix.applyFix(project, myDescriptor); DaemonCodeAnalyzer.getInstance(project).restart(); if (fileForUndo != null && !fileForUndo.equals(file)) { UndoUtil.markPsiFileForUndo(fileForUndo); } }
Example #9
Source File: FileReference.java From consulo with Apache License 2.0 | 5 votes |
@Override public LocalQuickFix[] getQuickFixes() { final List<LocalQuickFix> result = new ArrayList<>(); for (final FileReferenceHelper helper : getHelpers()) { result.addAll(helper.registerFixes(this)); } return result.toArray(new LocalQuickFix[result.size()]); }
Example #10
Source File: PsiQuickFixFactory.java From lombok-intellij-plugin with BSD 3-Clause "New" or "Revised" License | 5 votes |
public static LocalQuickFix createAddAnnotationQuickFix(@NotNull PsiClass psiClass, @NotNull String annotationFQN, @Nullable String annotationParam) { PsiElementFactory elementFactory = JavaPsiFacade.getElementFactory(psiClass.getProject()); PsiAnnotation newAnnotation = elementFactory.createAnnotationFromText("@" + annotationFQN + "(" + StringUtil.notNullize(annotationParam) + ")", psiClass); final PsiNameValuePair[] attributes = newAnnotation.getParameterList().getAttributes(); return new AddAnnotationFix(annotationFQN, psiClass, attributes); }
Example #11
Source File: QuickFixWrapper.java From consulo with Apache License 2.0 | 5 votes |
@Override public boolean isAvailable(@Nonnull Project project, Editor editor, PsiFile file) { PsiElement psiElement = myDescriptor.getPsiElement(); if (psiElement == null || !psiElement.isValid()) return false; final LocalQuickFix fix = getFix(); return !(fix instanceof IntentionAction) || ((IntentionAction)fix).isAvailable(project, editor, file); }
Example #12
Source File: InternalVariableInspection.java From BashSupport with Apache License 2.0 | 5 votes |
@NotNull @Override public PsiElementVisitor buildVisitor(@NotNull final ProblemsHolder holder, boolean isOnTheFly) { return new BashVisitor() { @Override public void visitVarDef(BashVarDef varDef) { String name = varDef.getName(); if (LanguageBuiltins.readonlyShellVars.contains(name)) { holder.registerProblem(varDef, "Built-in shell variable", LocalQuickFix.EMPTY_ARRAY); } } }; }
Example #13
Source File: MethodUsagesInspection.java From intellij-latte with MIT License | 5 votes |
private void processFunction( LattePhpMethod element, @NotNull List<ProblemDescriptor> problems, @NotNull final InspectionManager manager, final boolean isOnTheFly ) { String name = element.getMethodName(); if (name == null) { return; } LatteFunctionSettings customFunction = LatteConfiguration.getInstance(element.getProject()).getFunction(name); if (customFunction != null) { return; } Collection<Function> existing = LattePhpUtil.getFunctionByName(element.getProject(), name); if (existing.size() == 0) { LocalQuickFix addFunctionFix = IntentionManager.getInstance().convertToFix(new AddCustomLatteFunction(name)); addProblem(manager, problems, getElementToLook(element), "Function '" + name + "' not found", isOnTheFly, addFunctionFix); } else { for (Function function : existing) { if (function.isDeprecated()) { addDeprecated(manager, problems, getElementToLook(element), "Function '" + name + "' is deprecated", isOnTheFly); } if (function.isInternal()) { addDeprecated(manager, problems, getElementToLook(element), "Function '" + name + "' is internal", isOnTheFly); } } } }
Example #14
Source File: EqualsAndHashCodeProcessor.java From lombok-intellij-plugin with BSD 3-Clause "New" or "Revised" License | 5 votes |
private void validateCallSuperParam(@NotNull PsiAnnotation psiAnnotation, @NotNull PsiClass psiClass, @NotNull ProblemBuilder builder, LocalQuickFix... quickFixes) { final Boolean declaredBooleanAnnotationValue = PsiAnnotationUtil.getDeclaredBooleanAnnotationValue(psiAnnotation, "callSuper"); if (null == declaredBooleanAnnotationValue) { final String configProperty = configDiscovery.getStringLombokConfigProperty(ConfigKey.EQUALSANDHASHCODE_CALL_SUPER, psiClass); if (!"CALL".equalsIgnoreCase(configProperty) && !"SKIP".equalsIgnoreCase(configProperty) && PsiClassUtil.hasSuperClass(psiClass) && !hasOneOfMethodsDefined(psiClass)) { builder.addWarning("Generating equals/hashCode implementation but without a call to superclass, " + "even though this class does not extend java.lang.Object. If this is intentional, add '(callSuper=false)' to your type.", quickFixes); } } }
Example #15
Source File: Annotation.java From consulo with Apache License 2.0 | 5 votes |
/** * Register a quickfix which would be available onTheFly and in the batch mode. Should implement both IntentionAction and LocalQuickFix. */ public <T extends IntentionAction & LocalQuickFix> void registerUniversalFix(@Nonnull T fix, @javax.annotation.Nullable TextRange range, @javax.annotation.Nullable final HighlightDisplayKey key) { registerBatchFix(fix, range, key); registerFix(fix, range, key); }
Example #16
Source File: DefaultFunctionNamespaceSameAsModuleNamespace.java From intellij-xquery with Apache License 2.0 | 5 votes |
private ProblemDescriptor[] createProblemDescriptor(InspectionManager manager, XQueryURILiteral defaultNamespaceFunctionDeclarationURILiteral) { ProblemDescriptor[] problemDescriptors = new ProblemDescriptor[1]; problemDescriptors[0] = manager.createProblemDescriptor(defaultNamespaceFunctionDeclarationURILiteral, "Default function namespace should be same as module namespace", (LocalQuickFix) null, GENERIC_ERROR_OR_WARNING, true); return problemDescriptors; }
Example #17
Source File: UnusedVariableInspection.java From intellij-xquery with Apache License 2.0 | 5 votes |
private ProblemDescriptor[] buildProblemDescriptionsForUnusedVariables(InspectionManager manager, List<XQueryVarName> unusedVariables) { ProblemDescriptor[] problemDescriptors = new ProblemDescriptor[unusedVariables.size()]; int ind = 0; for (XQueryVarName varName : unusedVariables) { final ProblemDescriptor problemDescriptor = manager.createProblemDescriptor(varName, getDescription(varName), (LocalQuickFix) null, LIKE_UNUSED_SYMBOL, true); problemDescriptors[ind++] = problemDescriptor; } return problemDescriptors; }
Example #18
Source File: CsvValidationInspection.java From intellij-csv-validator with Apache License 2.0 | 5 votes |
private boolean registerError(@NotNull final ProblemsHolder holder, @NotNull PsiElement element, @NotNull String descriptionTemplate, @Nullable LocalQuickFix fix) { if (element != null && this.isSuppressedFor(element)) { return false; } holder.registerProblem(element, descriptionTemplate, fix); return true; }
Example #19
Source File: PriorityLocalQuickFixWrapper.java From consulo with Apache License 2.0 | 4 votes |
private PriorityLocalQuickFixWrapper(@Nonnull LocalQuickFix fix) { this.fix = fix; }
Example #20
Source File: PriorityLocalQuickFixWrapper.java From consulo with Apache License 2.0 | 4 votes |
protected HighPriorityLocalQuickFixWrapper(@Nonnull LocalQuickFix fix) { super(fix); }
Example #21
Source File: FileReferenceHelper.java From consulo with Apache License 2.0 | 4 votes |
@Nonnull public List<? extends LocalQuickFix> registerFixes(FileReference reference) { return Collections.emptyList(); }
Example #22
Source File: PriorityLocalQuickFixWrapper.java From consulo with Apache License 2.0 | 4 votes |
@Nonnull public static LocalQuickFix lowPriority(@Nonnull LocalQuickFix fix) { return new LowPriorityLocalQuickFixWrapper(fix); }
Example #23
Source File: PriorityLocalQuickFixWrapper.java From consulo with Apache License 2.0 | 4 votes |
protected NormalPriorityLocalQuickFixWrapper(@Nonnull LocalQuickFix fix) { super(fix); }
Example #24
Source File: MarklogicExtendedSyntaxInspection.java From intellij-xquery with Apache License 2.0 | 4 votes |
private ProblemDescriptor createProblem(InspectionManager manager, PsiElement element) { return manager.createProblemDescriptor(element, "MarkLogic extended syntax used when version is not set to 'MarkLogic extended'.", (LocalQuickFix) null, ProblemHighlightType.GENERIC_ERROR, true); }
Example #25
Source File: PsiQuickFixFactory.java From lombok-intellij-plugin with BSD 3-Clause "New" or "Revised" License | 4 votes |
public static LocalQuickFix createChangeAnnotationParameterFix(@NotNull PsiAnnotation psiAnnotation, @NotNull String name, @Nullable String newValue) { return new ChangeAnnotationParameterQuickFix(psiAnnotation, name, newValue); }
Example #26
Source File: PsiFileReferenceHelper.java From consulo with Apache License 2.0 | 4 votes |
@Nonnull @Override public List<? extends LocalQuickFix> registerFixes(FileReference reference) { return FileReferenceQuickFixProvider.registerQuickFix(reference); }
Example #27
Source File: PsiQuickFixFactory.java From lombok-intellij-plugin with BSD 3-Clause "New" or "Revised" License | 4 votes |
public static LocalQuickFix createNewFieldFix(@NotNull PsiClass psiClass, @NotNull String name, @NotNull PsiType psiType, @Nullable String initializerText, String... modifiers) { return new CreateFieldQuickFix(psiClass, name, psiType, initializerText, modifiers); }
Example #28
Source File: PsiQuickFixFactory.java From lombok-intellij-plugin with BSD 3-Clause "New" or "Revised" License | 4 votes |
public static LocalQuickFix createModifierListFix(@NotNull PsiModifierListOwner owner, @NotNull String modifier, boolean shouldHave, final boolean showContainingClass) { return new ModifierFix(owner, modifier, shouldHave, showContainingClass); }
Example #29
Source File: ProblemNewBuilder.java From lombok-intellij-plugin with BSD 3-Clause "New" or "Revised" License | 4 votes |
public void addWarning(String message, LocalQuickFix... quickFixes) { addProblem(message, ProblemHighlightType.GENERIC_ERROR_OR_WARNING, quickFixes); }
Example #30
Source File: UnusedImportsInspection.java From needsmoredojo with Apache License 2.0 | 4 votes |
@Override public ProblemDescriptor[] checkFile(@NotNull PsiFile file, @NotNull final InspectionManager manager, boolean isOnTheFly) { if(!isEnabled(file.getProject())) { return new ProblemDescriptor[0]; } final List<ProblemDescriptor> descriptors = new ArrayList<ProblemDescriptor>(); UnusedImportsRemover detector = new UnusedImportsRemover(); List<UnusedImportBlockEntry> results = detector.filterUsedModules(file, ServiceManager.getService(file.getProject(), DojoSettings.class).getRuiImportExceptions()); for(UnusedImportBlockEntry result : results) { List<PsiElement> defines = result.getDefines(); List<PsiElement> parameters = result.getParameters(); LocalQuickFix[] fixes = new LocalQuickFix[0]; for(int i=0;i<parameters.size();i++) { PsiElement define = null; if(i < defines.size()) { define = defines.get(i); } PsiElement parameter = null; if(i < parameters.size()) { parameter = parameters.get(i); } if(parameter != null && define != null) { fixes = new LocalQuickFix[] { new RemoveImportQuickFix(define, parameter), new IgnoreImportQuickFix(define, parameter), new RemoveUnusedImportsQuickFix(define, parameter)}; } else { fixes = new LocalQuickFix[0]; } if (parameter != null) { descriptors.add(manager.createProblemDescriptor(parameter, String.format("Unused AMD import: %s", parameter.getText()), fixes, ProblemHighlightType.LIKE_DEPRECATED, true, false)); } if (define != null) { descriptors.add(manager.createProblemDescriptor(define, String.format("Unused AMD import: %s", define.getText()), fixes, ProblemHighlightType.LIKE_DEPRECATED, true, false)); } } } return descriptors.toArray(new ProblemDescriptor[0]); }