use of com.intellij.codeInspection.InspectionManager in project intellij-community by JetBrains.
the class DomHighlightingLiteTest method testHighlightStatus_OtherInspections2.
public void testHighlightStatus_OtherInspections2() throws Throwable {
myElement.setFileDescription(new DomFileDescription<>(DomElement.class, "a"));
final MyDomElementsInspection inspection = new MyDomElementsInspection() {
@Override
public ProblemDescriptor[] checkFile(@NotNull final PsiFile file, @NotNull final InspectionManager manager, final boolean isOnTheFly) {
myAnnotationsManager.appendProblems(myElement, createHolder(), this.getClass());
return ProblemDescriptor.EMPTY_ARRAY;
}
@Override
public void checkFileElement(final DomFileElement fileElement, final DomElementAnnotationHolder holder) {
}
};
registerInspectionKey(inspection);
LocalInspectionToolWrapper toolWrapper = new LocalInspectionToolWrapper(inspection);
myInspectionProfile.setInspectionTools(toolWrapper);
myInspectionProfile.setEnabled(toolWrapper, false);
myAnnotationsManager.appendProblems(myElement, createHolder(), MockAnnotatingDomInspection.class);
assertEquals(DomHighlightStatus.INSPECTIONS_FINISHED, myAnnotationsManager.getHighlightStatus(myElement));
}
use of com.intellij.codeInspection.InspectionManager in project intellij-community by JetBrains.
the class DomHighlightingLiteTest method testHighlightStatus_OtherInspections.
public void testHighlightStatus_OtherInspections() throws Throwable {
myElement.setFileDescription(new DomFileDescription<>(DomElement.class, "a"));
final MyDomElementsInspection inspection = new MyDomElementsInspection() {
@Override
public ProblemDescriptor[] checkFile(@NotNull final PsiFile file, @NotNull final InspectionManager manager, final boolean isOnTheFly) {
myAnnotationsManager.appendProblems(myElement, createHolder(), this.getClass());
return ProblemDescriptor.EMPTY_ARRAY;
}
@Override
public void checkFileElement(final DomFileElement fileElement, final DomElementAnnotationHolder holder) {
}
};
registerInspectionKey(inspection);
myInspectionProfile.setInspectionTools(new LocalInspectionToolWrapper(inspection));
myAnnotationsManager.appendProblems(myElement, createHolder(), MockAnnotatingDomInspection.class);
assertEquals(DomHighlightStatus.ANNOTATORS_FINISHED, myAnnotationsManager.getHighlightStatus(myElement));
myAnnotationsManager.appendProblems(myElement, createHolder(), inspection.getClass());
assertEquals(DomHighlightStatus.INSPECTIONS_FINISHED, myAnnotationsManager.getHighlightStatus(myElement));
}
use of com.intellij.codeInspection.InspectionManager in project intellij-community by JetBrains.
the class CleanupIntention method invoke.
@Override
public void invoke(@NotNull final Project project, final Editor editor, final PsiFile file) throws IncorrectOperationException {
if (!FileModificationService.getInstance().preparePsiElementForWrite(file))
return;
final InspectionManager managerEx = InspectionManager.getInstance(project);
final GlobalInspectionContextBase globalContext = (GlobalInspectionContextBase) managerEx.createNewGlobalContext(false);
final AnalysisScope scope = getScope(project, file);
if (scope != null) {
globalContext.codeCleanup(scope, InspectionProjectProfileManager.getInstance(project).getCurrentProfile(), getText(), null, false);
}
}
use of com.intellij.codeInspection.InspectionManager in project intellij-community by JetBrains.
the class JavaDocCommentFixer method fixComment.
@Override
public void fixComment(@NotNull Project project, @NotNull Editor editor, @NotNull PsiComment comment) {
if (!(comment instanceof PsiDocComment)) {
return;
}
PsiDocComment docComment = (PsiDocComment) comment;
PsiJavaDocumentedElement owner = docComment.getOwner();
if (owner == null) {
return;
}
PsiFile file = comment.getContainingFile();
if (file == null) {
return;
}
JavaDocReferenceInspection referenceInspection = new JavaDocReferenceInspection();
JavaDocLocalInspection localInspection = getDocLocalInspection();
InspectionManager inspectionManager = InspectionManager.getInstance(project);
ProblemDescriptor[] referenceProblems = null;
ProblemDescriptor[] otherProblems = null;
if (owner instanceof PsiClass) {
referenceProblems = referenceInspection.checkClass(((PsiClass) owner), inspectionManager, false);
otherProblems = localInspection.checkClass(((PsiClass) owner), inspectionManager, false);
} else if (owner instanceof PsiField) {
referenceProblems = referenceInspection.checkField(((PsiField) owner), inspectionManager, false);
otherProblems = localInspection.checkField(((PsiField) owner), inspectionManager, false);
} else if (owner instanceof PsiMethod) {
referenceProblems = referenceInspection.checkMethod((PsiMethod) owner, inspectionManager, false);
otherProblems = localInspection.checkMethod((PsiMethod) owner, inspectionManager, false);
}
if (referenceProblems != null) {
fixReferenceProblems(referenceProblems, project);
}
if (otherProblems != null) {
fixCommonProblems(otherProblems, comment, editor.getDocument(), project);
}
PsiDocumentManager.getInstance(project).doPostponedOperationsAndUnblockDocument(editor.getDocument());
ensureContentOrdered(docComment, editor.getDocument());
locateCaret(docComment, editor, file);
}
use of com.intellij.codeInspection.InspectionManager in project intellij-community by JetBrains.
the class WholeFileLocalInspectionsPassFactory method createHighlightingPass.
@Override
@Nullable
public TextEditorHighlightingPass createHighlightingPass(@NotNull final PsiFile file, @NotNull final Editor editor) {
final Long appliedModificationCount = myPsiModificationCount.get(file);
if (appliedModificationCount != null && appliedModificationCount == PsiManager.getInstance(myProject).getModificationTracker().getModificationCount()) {
//optimization
return null;
}
if (!ProblemHighlightFilter.shouldHighlightFile(file)) {
return null;
}
if (myFileToolsCache.containsKey(file) && !myFileToolsCache.get(file)) {
return null;
}
ProperTextRange visibleRange = VisibleHighlightingPassFactory.calculateVisibleRange(editor);
return new LocalInspectionsPass(file, editor.getDocument(), 0, file.getTextLength(), visibleRange, true, new DefaultHighlightInfoProcessor()) {
@NotNull
@Override
List<LocalInspectionToolWrapper> getInspectionTools(@NotNull InspectionProfileWrapper profile) {
List<LocalInspectionToolWrapper> tools = super.getInspectionTools(profile);
List<LocalInspectionToolWrapper> result = tools.stream().filter(LocalInspectionToolWrapper::runForWholeFile).collect(Collectors.toList());
myFileToolsCache.put(file, !result.isEmpty());
return result;
}
@Override
protected String getPresentableName() {
return DaemonBundle.message("pass.whole.inspections");
}
@Override
void inspectInjectedPsi(@NotNull List<PsiElement> elements, boolean onTheFly, @NotNull ProgressIndicator indicator, @NotNull InspectionManager iManager, boolean inVisibleRange, @NotNull List<LocalInspectionToolWrapper> wrappers) {
// already inspected in LIP
}
@Override
protected void applyInformationWithProgress() {
super.applyInformationWithProgress();
myPsiModificationCount.put(file, PsiManager.getInstance(myProject).getModificationTracker().getModificationCount());
}
};
}
Aggregations