mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-08-18 16:17:00 +07:00
94 lines
3.7 KiB
Java
94 lines
3.7 KiB
Java
/*
|
|
* Copyright 2000-2017 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.codeInspection;
|
|
|
|
import com.intellij.JavaTestUtil;
|
|
import com.intellij.analysis.AnalysisScope;
|
|
import com.intellij.codeInsight.CodeInsightTestCase;
|
|
import com.intellij.codeInspection.actions.RunInspectionIntention;
|
|
import com.intellij.codeInspection.ex.*;
|
|
import com.intellij.codeInspection.ui.InspectionToolPresentation;
|
|
import com.intellij.codeInspection.visibility.VisibilityInspection;
|
|
import com.intellij.psi.PsiFile;
|
|
import com.intellij.testFramework.InspectionsKt;
|
|
import com.intellij.util.ui.UIUtil;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.Arrays;
|
|
|
|
public class GlobalInspectionContextTest extends CodeInsightTestCase {
|
|
public void testProblemDuplication() throws Exception {
|
|
String shortName = new VisibilityInspection().getShortName();
|
|
InspectionProfileImpl profile = new InspectionProfileImpl("Foo");
|
|
InspectionsKt.disableAllTools(profile);
|
|
profile.enableTool(shortName, getProject());
|
|
|
|
GlobalInspectionContextImpl context = ((InspectionManagerEx)InspectionManager.getInstance(getProject())).createNewGlobalContext(false);
|
|
context.setExternalProfile(profile);
|
|
configureByFile("Foo.java");
|
|
|
|
AnalysisScope scope = new AnalysisScope(getFile());
|
|
context.doInspections(scope);
|
|
UIUtil.dispatchAllInvocationEvents(); // wait for launchInspections in invoke later
|
|
|
|
Tools tools = context.getTools().get(shortName);
|
|
GlobalInspectionToolWrapper toolWrapper = (GlobalInspectionToolWrapper)tools.getTool();
|
|
InspectionToolPresentation presentation = context.getPresentation(toolWrapper);
|
|
assertEquals(1, presentation.getProblemDescriptors().size());
|
|
|
|
context.doInspections(scope);
|
|
UIUtil.dispatchAllInvocationEvents(); // wait for launchInspections in invoke later
|
|
|
|
tools = context.getTools().get(shortName);
|
|
toolWrapper = (GlobalInspectionToolWrapper)tools.getTool();
|
|
presentation = context.getPresentation(toolWrapper);
|
|
assertEquals(1, presentation.getProblemDescriptors().size());
|
|
}
|
|
|
|
public void testRunInspectionContext() throws Exception {
|
|
InspectionProfile profile = new InspectionProfileImpl("foo");
|
|
InspectionToolWrapper[] tools = profile.getInspectionTools(null);
|
|
PsiFile file = createDummyFile("xx.txt", "xxx");
|
|
for (InspectionToolWrapper toolWrapper : tools) {
|
|
if (!toolWrapper.isEnabledByDefault()) {
|
|
InspectionManagerEx instance = (InspectionManagerEx)InspectionManager.getInstance(myProject);
|
|
GlobalInspectionContextImpl context = RunInspectionIntention.createContext(toolWrapper, instance, file);
|
|
context.initializeTools(new ArrayList<>(), new ArrayList<>(), new ArrayList<>());
|
|
assertEquals(1, context.getTools().size());
|
|
return;
|
|
}
|
|
}
|
|
fail("No disabled tools found: " + Arrays.asList(tools));
|
|
}
|
|
|
|
@Override
|
|
public void setUp() throws Exception {
|
|
super.setUp();
|
|
InspectionProfileImpl.INIT_INSPECTIONS = true;
|
|
}
|
|
|
|
@Override
|
|
public void tearDown() throws Exception {
|
|
InspectionProfileImpl.INIT_INSPECTIONS = false;
|
|
super.tearDown();
|
|
}
|
|
|
|
@Override
|
|
protected String getTestDataPath() {
|
|
return JavaTestUtil.getJavaTestDataPath() + "/inspection/globalContext/";
|
|
}
|
|
}
|