com.intellij.codeInspection.ProblemDescriptor Java Examples
The following examples show how to use
com.intellij.codeInspection.ProblemDescriptor.
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: UnusedVariableInspection.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; } List<XQueryVarName> unusedVariables = new ArrayList<XQueryVarName>(); XQueryFile xQueryFile = (XQueryFile) file; for (XQueryVarName varName : xQueryFile.getVariableNames()) { if (isReference(varName) || isPublicDeclaredVariable(varName)) continue; if (variableIsNotUsed(varName, xQueryFile)) unusedVariables.add(varName); } if (unusedVariables.size() > 0) { return buildProblemDescriptionsForUnusedVariables(manager, unusedVariables); } else { return null; } }
Example #2
Source File: IgnoreImportQuickFix.java From needsmoredojo with Apache License 2.0 | 6 votes |
@Override public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor problemDescriptor) { CommandProcessor.getInstance().executeCommand(project, new Runnable() { @Override public void run() { ApplicationManager.getApplication().runWriteAction(new Runnable() { @Override public void run() { addIgnoreStatement(); } }); } }, "Ignore unused import", "Ignore unused import"); }
Example #3
Source File: CsvValidationInspection.java From intellij-csv-validator with Apache License 2.0 | 6 votes |
@Override public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) { try { PsiElement element = descriptor.getPsiElement(); Document document = PsiDocumentManager.getInstance(project).getDocument(element.getContainingFile()); List<Integer> quotePositions = new ArrayList<>(); int quotePosition = CsvIntentionHelper.getOpeningQuotePosition(element); if (quotePosition != -1) { quotePositions.add(quotePosition); } PsiElement endSeparatorElement = CsvIntentionHelper.findQuotePositionsUntilSeparator(element, quotePositions, true); if (endSeparatorElement == null) { quotePositions.add(document.getTextLength()); } else { quotePositions.add(endSeparatorElement.getTextOffset()); } String text = CsvIntentionHelper.addQuotes(document.getText(), quotePositions); document.setText(text); } catch (IncorrectOperationException e) { LOG.error(e); } }
Example #4
Source File: DefaultFunctionNamespaceSameAsModuleNamespace.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; } XQueryFile xQueryFile = (XQueryFile) file; XQueryModuleDecl moduleDeclaration = xQueryFile.getModuleDeclaration(); XQueryDefaultFunctionNamespaceDecl defaultNamespaceFunctionDeclaration = xQueryFile.getDefaultNamespaceFunctionDeclaration(); if (moduleDeclaration != null && defaultNamespaceFunctionDeclaration != null) { String namespace = moduleDeclaration.getNamespace(); XQueryURILiteral uriLiteral = defaultNamespaceFunctionDeclaration.getURILiteral(); String defaultFunctionNamespace = uriLiteral != null ? removeQuotOrAposIfNeeded(uriLiteral.getText()) : null; if (!StringUtils.equals(defaultFunctionNamespace, namespace) && !FN.getNamespace().equals(defaultFunctionNamespace)) { return createProblemDescriptor(manager, uriLiteral); } } return null; }
Example #5
Source File: EventMethodCallInspection.java From idea-php-symfony2-plugin with MIT License | 6 votes |
@Nullable private String getEventTypeHint(@NotNull ProblemDescriptor problemDescriptor, @NotNull PhpClass phpClass) { String eventName = EventDispatcherSubscriberUtil.getEventNameFromScope(problemDescriptor.getPsiElement()); if (eventName == null) { return null; } String taggedEventMethodParameter = EventSubscriberUtil.getTaggedEventMethodParameter(problemDescriptor.getPsiElement().getProject(), eventName); if (taggedEventMethodParameter == null) { return null; } String qualifiedName = AnnotationBackportUtil.getQualifiedName(phpClass, taggedEventMethodParameter); if (qualifiedName != null && !qualifiedName.equals(StringUtils.stripStart(taggedEventMethodParameter, "\\"))) { // class already imported return qualifiedName; } return PhpElementsUtil.insertUseIfNecessary(phpClass, taggedEventMethodParameter); }
Example #6
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 #7
Source File: CreateMissingTranslationQuickFix.java From idea-php-typo3-plugin with MIT License | 6 votes |
/** * Called to apply the fix. * * @param project {@link Project} * @param descriptor problem reported by the tool which provided this quick fix action */ @Override public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) { PsiElement psiElement = descriptor.getPsiElement(); if (psiElement instanceof StringLiteralExpression) { StringLiteralExpression stringElement = (StringLiteralExpression) psiElement; String contents = stringElement.getContents(); String fileName = TranslationUtil.extractResourceFilenameFromTranslationString(contents); String key = TranslationUtil.extractTranslationKeyTranslationString(contents); if (fileName != null) { PsiElement[] elementsForKey = ResourcePathIndex.findElementsForKey(project, fileName); if (elementsForKey.length > 0) { // TranslationUtil.add(); } } } }
Example #8
Source File: UppercaseStatePropInspection.java From litho with Apache License 2.0 | 6 votes |
@Nullable @Override public ProblemDescriptor[] checkMethod( @NotNull PsiMethod method, @NotNull InspectionManager manager, boolean isOnTheFly) { if (!LithoPluginUtils.isLithoSpec(method.getContainingClass())) { return ProblemDescriptor.EMPTY_ARRAY; } return Optional.of(method) .map(PsiMethod::getParameterList) .map(PsiParameterList::getParameters) .map( psiParameters -> Stream.of(psiParameters) .filter(LithoPluginUtils::isPropOrState) .filter(UppercaseStatePropInspection::isFirstLetterCapital) .map(PsiParameter::getNameIdentifier) .filter(Objects::nonNull) .map(identifier -> createWarning(identifier, manager, isOnTheFly)) .toArray(ProblemDescriptor[]::new)) .orElse(ProblemDescriptor.EMPTY_ARRAY); }
Example #9
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 #10
Source File: HaxeUnresolvedSymbolInspection.java From intellij-haxe with Apache License 2.0 | 6 votes |
@Nullable @Override public ProblemDescriptor[] checkFile(@NotNull PsiFile file, @NotNull final InspectionManager manager, final boolean isOnTheFly) { if (!(file instanceof HaxeFile)) return null; final List<ProblemDescriptor> result = new ArrayList<ProblemDescriptor>(); new HaxeAnnotatingVisitor() { @Override protected void handleUnresolvedReference(HaxeReferenceExpression reference) { PsiElement nameIdentifier = reference.getReferenceNameElement(); if (nameIdentifier == null) return; result.add(manager.createProblemDescriptor( nameIdentifier, TextRange.from(0, nameIdentifier.getTextLength()), getDisplayName(), ProblemHighlightType.LIKE_UNKNOWN_SYMBOL, isOnTheFly )); } }.visitFile(file); return ArrayUtil.toObjectArray(result, ProblemDescriptor.class); }
Example #11
Source File: UnusedCppSymbolInspection.java From CppTools with Apache License 2.0 | 6 votes |
@Override @Nullable public ProblemDescriptor[] checkFile(@NotNull PsiFile file, @NotNull InspectionManager manager, boolean isOnTheFly) { if (file.getFileType() != CppSupportLoader.CPP_FILETYPE) return EMPTY; if (HighlightUtils.debug) { HighlightUtils.trace(file, null, "Inspections about to start:"); } final HighlightCommand command = HighlightUtils.getUpToDateHighlightCommand(file, file.getProject()); if (command.isUpToDate()) command.awaitInspections(file.getProject()); if (HighlightUtils.debug) { HighlightUtils.trace(file, null, "Adding inspection errors:"); } final ProblemDescriptor[] problemDescriptors = command.addInspectionErrors(manager); // System.out.println("Finished inspections--:" + getClass() + "," + (System.currentTimeMillis() - command.started)); return problemDescriptors; }
Example #12
Source File: MismatchedImportsInspection.java From needsmoredojo with Apache License 2.0 | 6 votes |
@Override public ProblemDescriptor[] checkFile(@NotNull PsiFile file, @NotNull final InspectionManager manager, boolean isOnTheFly) { if(!isEnabled(file.getProject())) { return new ProblemDescriptor[0]; } DefineResolver resolver = new DefineResolver(); final List<ProblemDescriptor> descriptors = new ArrayList<ProblemDescriptor>(); Set<JSCallExpression> expressions = resolver.getAllImportBlocks(file); for(JSCallExpression expression : expressions) { addProblemsForBlock(expression, descriptors, file, manager); } return descriptors.toArray(new ProblemDescriptor[0]); }
Example #13
Source File: ModifierNotAllowedInspection.java From intellij-latte with MIT License | 6 votes |
@Nullable @Override public ProblemDescriptor[] checkFile(@NotNull PsiFile file, @NotNull final InspectionManager manager, final boolean isOnTheFly) { if (!(file instanceof LatteFile)) { return null; } final List<ProblemDescriptor> problems = new ArrayList<>(); file.acceptChildren(new PsiRecursiveElementWalkingVisitor() { @Override public void visitElement(PsiElement element) { if (element instanceof LatteMacroTag) { checkClassicMacro((LatteMacroTag) element, problems, manager, isOnTheFly); } else { super.visitElement(element); } } }); return problems.toArray(new ProblemDescriptor[0]); }
Example #14
Source File: RemoveUnusedImportsQuickFix.java From needsmoredojo with Apache License 2.0 | 6 votes |
@Override public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor problemDescriptor) { CommandProcessor.getInstance().executeCommand(project, new Runnable() { @Override public void run() { ApplicationManager.getApplication().runWriteAction(new Runnable() { @Override public void run() { UnusedImportsAction.removeUnusedImports(define.getContainingFile()); } }); } }, "Remove unused imports", "Remove unused imports"); }
Example #15
Source File: MixinsAnnotationDeclaredOnMixinType.java From attic-polygene-java with Apache License 2.0 | 6 votes |
@Override public ProblemDescriptor[] checkClass( @NotNull PsiClass psiClass, @NotNull InspectionManager manager, boolean isOnTheFly ) { PsiAnnotation mixinsAnnotation = getMixinsAnnotation( psiClass ); if( mixinsAnnotation == null ) { return null; } if( psiClass.isInterface() ) { return null; } String message = message( "mixins.annotation.declared.on.mixin.type.error.declared.on.class" ); RemoveInvalidMixinClassReferenceFix fix = new RemoveInvalidMixinClassReferenceFix( mixinsAnnotation ); ProblemDescriptor problemDescriptor = manager.createProblemDescriptor( mixinsAnnotation, message, fix, GENERIC_ERROR_OR_WARNING ); return new ProblemDescriptor[]{ problemDescriptor }; }
Example #16
Source File: MismatchedImportsQuickFix.java From needsmoredojo with Apache License 2.0 | 6 votes |
@Override public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor problemDescriptor) { final RenameRefactoring refactoring = RefactoringFactory.getInstance(project) .createRename(parameter, this.newParameterName, false, false); CommandProcessor.getInstance().executeCommand(project, new Runnable() { @Override public void run() { ApplicationManager.getApplication().runWriteAction(new Runnable() { @Override public void run() { refactoring.run(); } }); } }, "Rename parameter to match define", "Rename parameter to match define"); }
Example #17
Source File: RemoveImportQuickFix.java From needsmoredojo with Apache License 2.0 | 6 votes |
@Override public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor problemDescriptor) { CommandProcessor.getInstance().executeCommand(project, new Runnable() { @Override public void run() { ApplicationManager.getApplication().runWriteAction(new Runnable() { @Override public void run() { AMDPsiUtil.removeSingleImport(new AMDImport((JSElement)define, (JSElement) parameter)); } }); } }, "Remove unused import", "Remove unused import"); }
Example #18
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 #19
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 #20
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 #21
Source File: UnusedImportsInspection.java From intellij-xquery with Apache License 2.0 | 5 votes |
@Override public ProblemDescriptor[] checkFile(PsiFile file, InspectionManager manager, boolean isOnTheFly) { if (! (file instanceof XQueryFile)) { return null; } List<ProblemDescriptor> problems = getUnusedImportProblems((XQueryFile) file, manager); return problems.toArray(new ProblemDescriptor[problems.size()]); }
Example #22
Source File: InspectionTree.java From consulo with Apache License 2.0 | 5 votes |
public CommonProblemDescriptor[] getSelectedDescriptors() { final InspectionToolWrapper toolWrapper = getSelectedToolWrapper(); if (getSelectionCount() == 0) return ProblemDescriptor.EMPTY_ARRAY; final TreePath[] paths = getSelectionPaths(); final LinkedHashSet<CommonProblemDescriptor> descriptors = new LinkedHashSet<CommonProblemDescriptor>(); for (TreePath path : paths) { Object node = path.getLastPathComponent(); traverseDescriptors((InspectionTreeNode)node, descriptors); } return descriptors.toArray(new CommonProblemDescriptor[descriptors.size()]); }
Example #23
Source File: GaugeInspectionProvider.java From Intellij-Plugin with Apache License 2.0 | 5 votes |
@Nullable @Override public ProblemDescriptor[] checkFile(@NotNull PsiFile file, @NotNull InspectionManager manager, boolean isOnTheFly) { if (isOnTheFly) return new ProblemDescriptor[0]; File dir = GaugeUtil.moduleDir(GaugeUtil.moduleForPsiElement(file)); if (dir == null) return new ProblemDescriptor[0]; return getDescriptors(GaugeErrors.get(dir.getAbsolutePath()), manager, file); }
Example #24
Source File: HaskellModuleNameFix.java From intellij-haskforce with Apache License 2.0 | 5 votes |
@Override public void applyFix(@NotNull final Project project, @NotNull ProblemDescriptor descriptor) { final PsiFile file = descriptor.getPsiElement().getContainingFile(); if (isAvailable(project, null, file)) { new WriteCommandAction(project) { @Override protected void run(@NotNull Result result) throws Throwable { invoke(project, null, file); } }.execute(); } }
Example #25
Source File: RenameFileReferenceIntentionAction.java From consulo with Apache License 2.0 | 5 votes |
@Override public void applyFix(@Nonnull final Project project, @Nonnull final ProblemDescriptor descriptor) { if (isAvailable(project, null, null)) { new WriteCommandAction(project) { @Override protected void run(Result result) throws Throwable { invoke(project, null, descriptor.getPsiElement().getContainingFile()); } }.execute(); } }
Example #26
Source File: MismatchedImportsInspection.java From needsmoredojo with Apache License 2.0 | 5 votes |
private List<ProblemDescriptor> addQuickFixToOtherMismatch(MismatchedImportsDetector.Mismatch mismatch, MismatchedImportsDetector.Mismatch secondMismatch, SwapImportsQuickFix quickFix, InspectionManager manager) { List<ProblemDescriptor> descriptors = new ArrayList<ProblemDescriptor>(); if(mismatch.getDefine() == null || mismatch.getParameter() == null) { return descriptors; } descriptors.add(manager.createProblemDescriptor(mismatch.getDefine(), String.format("Potentially swapped imports: %s and %s", mismatch.getDefine().getText(), secondMismatch.getDefine().getText()), true, ProblemHighlightType.ERROR, true, quickFix)); descriptors.add(manager.createProblemDescriptor(mismatch.getParameter(), String.format("Potentially swapped imports: %s and %s", mismatch.getDefine().getText(), secondMismatch.getDefine().getText()), true, ProblemHighlightType.ERROR, true, quickFix)); return descriptors; }
Example #27
Source File: UnusedNamespaceDeclarationInspection.java From intellij-xquery with Apache License 2.0 | 5 votes |
private List<ProblemDescriptor> getUnusedNamespaceDeclarationProblems(XQueryFile xQueryFile, InspectionManager manager) { Collection<XQueryNamespaceDecl> unusedNamespaceDeclarations = unusedNamespaceDeclarationsFinder.getUnusedNamespaceSources(xQueryFile); List<ProblemDescriptor> problems = new ArrayList<ProblemDescriptor>(); for (XQueryNamespaceDecl unused : unusedNamespaceDeclarations) { problems.add(manager.createProblemDescriptor(unused, UNUSED_NAMESPACE_DECLARATION, new RemoveElementQuickFix(REMOVE_UNUSED_NAMESPACE_DECLARATION_QUICKFIX_NAME), LIKE_UNUSED_SYMBOL, true)); } return problems; }
Example #28
Source File: ThriftUnresolvedSymbolInspection.java From intellij-thrift with Apache License 2.0 | 5 votes |
@Nullable @Override public ProblemDescriptor[] checkFile(@NotNull PsiFile file, @NotNull final InspectionManager manager, final boolean isOnTheFly) { final List<ProblemDescriptor> result = new ArrayList<ProblemDescriptor>(); new ThriftVisitor() { @Override public void visitCustomType(@NotNull ThriftCustomType type) { for (PsiReference reference : type.getReferences()) { if (reference.resolve() == null) { result.add(manager.createProblemDescriptor( reference.getElement(), reference.getRangeInElement(), getDisplayName(), ProblemHighlightType.ERROR, isOnTheFly )); } } } public void visitElement(PsiElement element) { super.visitElement(element); element.acceptChildren(this); } }.visitFile(file); return ArrayUtil.toObjectArray(result, ProblemDescriptor.class); }
Example #29
Source File: MarklogicExtendedSyntaxInspection.java From intellij-xquery with Apache License 2.0 | 5 votes |
@Override public ProblemDescriptor[] checkFile(@NotNull PsiFile file, @NotNull InspectionManager manager, boolean isOnTheFly) { if (!(file instanceof XQueryFile)) { return null; } if (((XQueryFile) file).versionIsNotMarklogicSpecific()) { return findMarklogicExtendedSyntax(((XQueryFile) file), manager); } return null; }
Example #30
Source File: CorrectClassNameCasingYamlLocalQuickFix.java From idea-php-symfony2-plugin with MIT License | 5 votes |
@Override public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) { PsiElement psiElement1 = descriptor.getPsiElement(); YAMLKeyValue replacement = YamlPsiElementFactory.createFromText( project, YAMLKeyValue.class, "class: " + replacementFQN ); if (replacement != null && replacement.getValue() != null) { psiElement1.replace(replacement.getValue()); } }