From 8d06f4b26511c1fcfac0a13f1f62805d069f2780 Mon Sep 17 00:00:00 2001 From: Alexey Kudravtsev Date: Fri, 8 Apr 2016 14:41:48 +0300 Subject: [PATCH] moved to community --- .../daemon/InspectionLIfeCycleTest.java | 93 +++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 java/java-tests/testSrc/com/intellij/codeInsight/daemon/InspectionLIfeCycleTest.java diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/InspectionLIfeCycleTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/InspectionLIfeCycleTest.java new file mode 100644 index 000000000000..b483d5974cf9 --- /dev/null +++ b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/InspectionLIfeCycleTest.java @@ -0,0 +1,93 @@ +/* + * Copyright 2000-2016 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.codeInsight.daemon; + +import com.intellij.codeInsight.daemon.impl.HighlightInfo; +import com.intellij.codeInspection.LocalInspectionTool; +import com.intellij.codeInspection.LocalInspectionToolSession; +import com.intellij.codeInspection.ProblemsHolder; +import com.intellij.openapi.util.Key; +import com.intellij.psi.PsiElementVisitor; +import org.jetbrains.annotations.Nls; +import org.jetbrains.annotations.NotNull; + +import java.util.List; +import java.util.concurrent.atomic.AtomicInteger; + +public class InspectionLIfeCycleTest extends LightDaemonAnalyzerTestCase { + public void testInspectionFinishedCalledOnce() throws Exception { + String text = "class LQF {\n" + + " int f;\n" + + " public void me() {\n" + + " \n" + + " }\n" + + "}"; + configureFromFileText("x.java", text); + + final AtomicInteger startedCount = new AtomicInteger(); + final AtomicInteger finishedCount = new AtomicInteger(); + final Key KEY = Key.create("just key"); + + LocalInspectionTool tool = new LocalInspectionTool() { + @Nls + @NotNull + @Override + public String getGroupDisplayName() { + return "fegna"; + } + + @Nls + @NotNull + @Override + public String getDisplayName() { + return getGroupDisplayName(); + } + + @NotNull + @Override + public String getShortName() { + return getGroupDisplayName(); + } + + @NotNull + @Override + public PsiElementVisitor buildVisitor(@NotNull ProblemsHolder holder, boolean isOnTheFly) { + return new PsiElementVisitor() { + }; + } + + @Override + public void inspectionStarted(@NotNull LocalInspectionToolSession session, boolean isOnTheFly) { + startedCount.incrementAndGet(); + session.putUserData(KEY, session); + } + + @Override + public void inspectionFinished(@NotNull LocalInspectionToolSession session, @NotNull ProblemsHolder problemsHolder) { + finishedCount.incrementAndGet(); + assertEmpty(problemsHolder.getResults()); + assertSame(session, session.getUserData(KEY)); + } + }; + enableInspectionTool(tool); + + List infos = highlightErrors(); + assertEmpty(infos); + + assertEquals(1, startedCount.get()); + assertEquals(1, finishedCount.get()); + } +}