Search in sources :

Example 86 with HighlightInfo

use of com.intellij.codeInsight.daemon.impl.HighlightInfo in project intellij-community by JetBrains.

the class ModuleHighlightUtil method checkPackageStatement.

static HighlightInfo checkPackageStatement(@NotNull PsiPackageStatement statement, @NotNull PsiFile file, @Nullable PsiJavaModule module) {
    if (PsiUtil.isModuleFile(file)) {
        String message = JavaErrorMessages.message("module.no.package");
        HighlightInfo info = HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(statement).descriptionAndTooltip(message).create();
        QuickFixAction.registerQuickFixAction(info, factory().createDeleteFix(statement));
        return info;
    }
    if (module != null) {
        String packageName = statement.getPackageName();
        if (packageName != null) {
            PsiJavaModule origin = JavaModuleGraphUtil.findOrigin(module, packageName);
            if (origin != null) {
                String message = JavaErrorMessages.message("module.conflicting.packages", packageName, origin.getName());
                return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(statement).descriptionAndTooltip(message).create();
            }
        }
    }
    return null;
}
Also used : HighlightInfo(com.intellij.codeInsight.daemon.impl.HighlightInfo)

Example 87 with HighlightInfo

use of com.intellij.codeInsight.daemon.impl.HighlightInfo in project intellij-community by JetBrains.

the class ModuleHighlightUtil method checkFileDuplicates.

@Nullable
static HighlightInfo checkFileDuplicates(@NotNull PsiJavaModule element, @NotNull PsiFile file) {
    Module module = findModule(file);
    if (module != null) {
        Project project = file.getProject();
        Collection<VirtualFile> others = FilenameIndex.getVirtualFilesByName(project, MODULE_INFO_FILE, module.getModuleScope(false));
        if (others.size() > 1) {
            String message = JavaErrorMessages.message("module.file.duplicate");
            HighlightInfo info = HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(range(element)).descriptionAndTooltip(message).create();
            others.stream().map(f -> PsiManager.getInstance(project).findFile(f)).filter(f -> f != file).findFirst().ifPresent(duplicate -> QuickFixAction.registerQuickFixAction(info, new GoToSymbolFix(duplicate, JavaErrorMessages.message("module.open.duplicate.text"))));
            return info;
        }
    }
    return null;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) JavaErrorMessages(com.intellij.codeInsight.daemon.JavaErrorMessages) Trinity(com.intellij.openapi.util.Trinity) java.util(java.util) JBIterable(com.intellij.util.containers.JBIterable) HighlightInfo(com.intellij.codeInsight.daemon.impl.HighlightInfo) VirtualFile(com.intellij.openapi.vfs.VirtualFile) ProjectFileIndex(com.intellij.openapi.roots.ProjectFileIndex) FilenameIndex(com.intellij.psi.search.FilenameIndex) ContainerUtil(com.intellij.util.containers.ContainerUtil) Function(java.util.function.Function) PsiTreeUtil(com.intellij.psi.util.PsiTreeUtil) InheritanceUtil(com.intellij.psi.util.InheritanceUtil) Project(com.intellij.openapi.project.Project) PsiUtil(com.intellij.psi.util.PsiUtil) PropertyKey(org.jetbrains.annotations.PropertyKey) Module(com.intellij.openapi.module.Module) QuickFixBundle(com.intellij.codeInsight.daemon.QuickFixBundle) ModuleUtilCore(com.intellij.openapi.module.ModuleUtilCore) StringUtil(com.intellij.openapi.util.text.StringUtil) QuickFixFactory(com.intellij.codeInsight.intention.QuickFixFactory) HighlightInfoType(com.intellij.codeInsight.daemon.impl.HighlightInfoType) TextRange(com.intellij.openapi.util.TextRange) Collectors(java.util.stream.Collectors) MODULE_INFO_FILE(com.intellij.psi.PsiJavaModule.MODULE_INFO_FILE) com.intellij.codeInsight.daemon.impl.quickfix(com.intellij.codeInsight.daemon.impl.quickfix) LightJavaModule(com.intellij.psi.impl.light.LightJavaModule) Nullable(org.jetbrains.annotations.Nullable) Stream(java.util.stream.Stream) ClassUtil(com.intellij.psi.util.ClassUtil) JarFileSystem(com.intellij.openapi.vfs.JarFileSystem) ApplicationManager(com.intellij.openapi.application.ApplicationManager) Role(com.intellij.psi.PsiPackageAccessibilityStatement.Role) ObjectUtils(com.intellij.util.ObjectUtils) com.intellij.psi(com.intellij.psi) NotNull(org.jetbrains.annotations.NotNull) Project(com.intellij.openapi.project.Project) HighlightInfo(com.intellij.codeInsight.daemon.impl.HighlightInfo) Module(com.intellij.openapi.module.Module) LightJavaModule(com.intellij.psi.impl.light.LightJavaModule) Nullable(org.jetbrains.annotations.Nullable)

Example 88 with HighlightInfo

use of com.intellij.codeInsight.daemon.impl.HighlightInfo in project intellij-community by JetBrains.

the class DaemonAnalyzerTestCase method findAndInvokeIntentionAction.

protected static void findAndInvokeIntentionAction(@NotNull Collection<HighlightInfo> infos, @NotNull String intentionActionName, @NotNull Editor editor, @NotNull PsiFile file) {
    List<IntentionAction> actions = getIntentionActions(infos, editor, file);
    IntentionAction intentionAction = LightQuickFixTestCase.findActionWithText(actions, intentionActionName);
    if (intentionAction == null) {
        fail(String.format("Could not find action by name %s.\n" + "Actions: [%s]\n" + "HighlightInfos: [%s]", intentionActionName, StringUtil.join(ContainerUtil.map(actions, c -> c.getText()), ", "), StringUtil.join(infos, ", ")));
    }
    CodeInsightTestFixtureImpl.invokeIntention(intentionAction, file, editor, intentionActionName);
}
Also used : InjectedLanguageManager(com.intellij.lang.injection.InjectedLanguageManager) InspectionToolProvider(com.intellij.codeInspection.InspectionToolProvider) HighlightSeverity(com.intellij.lang.annotation.HighlightSeverity) Document(com.intellij.openapi.editor.Document) InspectionProfileImpl(com.intellij.codeInspection.ex.InspectionProfileImpl) PsiManagerEx(com.intellij.psi.impl.PsiManagerEx) StartupManagerEx(com.intellij.ide.startup.StartupManagerEx) InspectionProfileEntry(com.intellij.codeInspection.InspectionProfileEntry) PathManagerEx(com.intellij.openapi.application.ex.PathManagerEx) StartupManagerImpl(com.intellij.ide.startup.impl.StartupManagerImpl) WriteCommandAction(com.intellij.openapi.command.WriteCommandAction) ReferenceProvidersRegistry(com.intellij.psi.impl.source.resolve.reference.ReferenceProvidersRegistry) LanguageAnnotators(com.intellij.lang.LanguageAnnotators) FileUtil(com.intellij.openapi.util.io.FileUtil) Module(com.intellij.openapi.module.Module) TIntArrayList(gnu.trove.TIntArrayList) LightQuickFixTestCase(com.intellij.codeInsight.daemon.quickFix.LightQuickFixTestCase) Extensions(com.intellij.openapi.extensions.Extensions) Collection(java.util.Collection) TextRange(com.intellij.openapi.util.TextRange) JavaFileType(com.intellij.ide.highlighter.JavaFileType) XmlFileNSInfoProvider(com.intellij.psi.xml.XmlFileNSInfoProvider) Pass(com.intellij.codeHighlighting.Pass) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) ModuleRootManager(com.intellij.openapi.roots.ModuleRootManager) IntentionAction(com.intellij.codeInsight.intention.IntentionAction) StdLanguages(com.intellij.lang.StdLanguages) com.intellij.psi(com.intellij.psi) IndexPatternBuilder(com.intellij.psi.impl.search.IndexPatternBuilder) NotNull(org.jetbrains.annotations.NotNull) InspectionProjectProfileManager(com.intellij.profile.codeInspection.InspectionProjectProfileManager) CodeInsightTestCase(com.intellij.codeInsight.CodeInsightTestCase) HighlightInfo(com.intellij.codeInsight.daemon.impl.HighlightInfo) NonNls(org.jetbrains.annotations.NonNls) ContainerUtil(com.intellij.util.containers.ContainerUtil) DaemonCodeAnalyzerEx(com.intellij.codeInsight.daemon.impl.DaemonCodeAnalyzerEx) ExpectedHighlightingData(com.intellij.testFramework.ExpectedHighlightingData) HighlightTestInfo(com.intellij.testFramework.HighlightTestInfo) Retention(java.lang.annotation.Retention) ArrayList(java.util.ArrayList) StartupManager(com.intellij.openapi.startup.StartupManager) IntentionManager(com.intellij.codeInsight.intention.IntentionManager) Project(com.intellij.openapi.project.Project) JavaLanguage(com.intellij.lang.java.JavaLanguage) FileTreeAccessFilter(com.intellij.testFramework.FileTreeAccessFilter) CodeInsightTestFixtureImpl(com.intellij.testFramework.fixtures.impl.CodeInsightTestFixtureImpl) StringUtil(com.intellij.openapi.util.text.StringUtil) IOException(java.io.IOException) Target(java.lang.annotation.Target) ElementType(java.lang.annotation.ElementType) Editor(com.intellij.openapi.editor.Editor) File(java.io.File) ExternalAnnotatorsFilter(com.intellij.lang.ExternalAnnotatorsFilter) InspectionsKt(com.intellij.testFramework.InspectionsKt) Result(com.intellij.openapi.application.Result) XmlSchemaProvider(com.intellij.xml.XmlSchemaProvider) Pair(com.intellij.openapi.util.Pair) com.intellij.openapi.vfs(com.intellij.openapi.vfs) LocalInspectionTool(com.intellij.codeInspection.LocalInspectionTool) DaemonCodeAnalyzerImpl(com.intellij.codeInsight.daemon.impl.DaemonCodeAnalyzerImpl) RetentionPolicy(java.lang.annotation.RetentionPolicy) IntentionAction(com.intellij.codeInsight.intention.IntentionAction)

Example 89 with HighlightInfo

use of com.intellij.codeInsight.daemon.impl.HighlightInfo in project intellij-community by JetBrains.

the class EditorFixture method requireHighlights.

@NotNull
public EditorFixture requireHighlights(HighlightSeverity severity, String... highlights) {
    List<String> infos = new ArrayList<>();
    for (HighlightInfo info : getCurrentFileFixture().getHighlightInfos(severity)) {
        infos.add(info.getDescription());
    }
    assertThat(infos).containsOnly(highlights);
    return this;
}
Also used : ArrayList(java.util.ArrayList) HighlightInfo(com.intellij.codeInsight.daemon.impl.HighlightInfo) AttributedString(java.text.AttributedString) NotNull(org.jetbrains.annotations.NotNull)

Example 90 with HighlightInfo

use of com.intellij.codeInsight.daemon.impl.HighlightInfo in project intellij-community by JetBrains.

the class FileFixture method waitForCodeAnalysisHighlightCount.

@NotNull
public FileFixture waitForCodeAnalysisHighlightCount(@NotNull final HighlightSeverity severity, final int expected) {
    final Document document = getNotNullDocument();
    pause(new Condition("Waiting for code analysis " + severity + " count to reach " + expected) {

        @Override
        public boolean test() {
            Collection<HighlightInfo> highlightInfos = execute(new GuiQuery<Collection<HighlightInfo>>() {

                @Override
                protected Collection<HighlightInfo> executeInEDT() throws Throwable {
                    CommonProcessors.CollectProcessor<HighlightInfo> processor = new CommonProcessors.CollectProcessor<HighlightInfo>();
                    DaemonCodeAnalyzerEx.processHighlights(document, myProject, severity, 0, document.getTextLength(), processor);
                    return processor.getResults();
                }
            });
            assertNotNull(highlightInfos);
            return highlightInfos.size() == expected;
        }
    }, SHORT_TIMEOUT);
    return this;
}
Also used : Condition(org.fest.swing.timing.Condition) GuiQuery(org.fest.swing.edt.GuiQuery) HighlightInfo(com.intellij.codeInsight.daemon.impl.HighlightInfo) Collection(java.util.Collection) Document(com.intellij.openapi.editor.Document) CommonProcessors(com.intellij.util.CommonProcessors) Assert.assertNotNull(junit.framework.Assert.assertNotNull) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

HighlightInfo (com.intellij.codeInsight.daemon.impl.HighlightInfo)221 Nullable (org.jetbrains.annotations.Nullable)51 TextRange (com.intellij.openapi.util.TextRange)33 IntentionAction (com.intellij.codeInsight.intention.IntentionAction)30 VirtualFile (com.intellij.openapi.vfs.VirtualFile)28 NotNull (org.jetbrains.annotations.NotNull)17 HighlightInfoType (com.intellij.codeInsight.daemon.impl.HighlightInfoType)16 Document (com.intellij.openapi.editor.Document)12 ArrayList (java.util.ArrayList)11 PsiElement (com.intellij.psi.PsiElement)10 File (java.io.File)8 TextAttributes (com.intellij.openapi.editor.markup.TextAttributes)7 WriteCommandAction (com.intellij.openapi.command.WriteCommandAction)6 Pair (com.intellij.openapi.util.Pair)6 PsiFile (com.intellij.psi.PsiFile)6 Editor (com.intellij.openapi.editor.Editor)5 NonNls (org.jetbrains.annotations.NonNls)5 StringUtil (com.intellij.openapi.util.text.StringUtil)4 IElementType (com.intellij.psi.tree.IElementType)4 ContainerUtil (com.intellij.util.containers.ContainerUtil)4