com.intellij.codeInspection.LocalInspectionTool Java Examples

The following examples show how to use com.intellij.codeInspection.LocalInspectionTool. 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: LocalInspectionToolWrapper.java    From consulo with Apache License 2.0 6 votes vote down vote up
public static InspectionToolWrapper findTool2RunInBatch(@Nonnull Project project, @Nullable PsiElement element, @Nonnull String name) {
  final InspectionProfile inspectionProfile = InspectionProjectProfileManager.getInstance(project).getInspectionProfile();
  final InspectionToolWrapper toolWrapper = element == null
                                            ? inspectionProfile.getInspectionTool(name, project)
                                            : inspectionProfile.getInspectionTool(name, element);
  if (toolWrapper instanceof LocalInspectionToolWrapper && ((LocalInspectionToolWrapper)toolWrapper).isUnfair()) {
    final LocalInspectionTool inspectionTool = ((LocalInspectionToolWrapper)toolWrapper).getTool();
    if (inspectionTool instanceof PairedUnfairLocalInspectionTool) {
      final String oppositeShortName = ((PairedUnfairLocalInspectionTool)inspectionTool).getInspectionForBatchShortName();
      return element == null
             ? inspectionProfile.getInspectionTool(oppositeShortName, project)
             : inspectionProfile.getInspectionTool(oppositeShortName, element);
    }
    return null;
  }
  return toolWrapper;
}
 
Example #2
Source File: FileModifier.java    From consulo with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the equivalent file modifier that could be applied to the
 * non-physical copy of the file used to preview the modification.
 * May return itself if the action doesn't depend on the file.
 *
 * @param target target non-physical file
 * @return the action that could be applied to the non-physical copy of the file.
 * Returns null if operation is not supported.
 */
@Nullable
default FileModifier getFileModifierForPreview(@Nonnull PsiFile target) {
  if (!startInWriteAction()) return null;
  for (Field field : ReflectionUtil.collectFields(((Object)this).getClass())) {
    if (Modifier.isStatic(field.getModifiers())) continue;
    Class<?> type = field.getType();
    if (field.getAnnotation(SafeFieldForPreview.class) != null) continue;
    while (type.isArray()) type = type.getComponentType();
    if (type.isPrimitive() || type.isEnum() || type.equals(String.class) || type.equals(Class.class) || type.equals(Integer.class) || type.equals(Boolean.class) ||
        // Back-link to the parent inspection looks safe, as inspection should not depend on the file
        (field.isSynthetic() && field.getName().equals("this$0") && LocalInspectionTool.class.isAssignableFrom(type))) {
      continue;
    }
    return null;
  }
  // No PSI-specific state: it's safe to apply this action to a file copy
  return this;
}
 
Example #3
Source File: PhpStanAnnotatorQualityToolAnnotator.java    From idea-php-generics-plugin with MIT License 5 votes vote down vote up
@Nullable
protected QualityToolConfiguration getConfiguration(@NotNull Project project, @NotNull LocalInspectionTool inspection) {
    try {
        return PhpStanValidatorProjectConfiguration.getInstance(project).findSelectedConfiguration(project);
    } catch (QualityToolValidationException e) {
        return null;
    }
}
 
Example #4
Source File: GlobalInspectionToolWrapper.java    From consulo with Apache License 2.0 5 votes vote down vote up
@javax.annotation.Nullable
public LocalInspectionToolWrapper getSharedLocalInspectionToolWrapper() {
  final LocalInspectionTool sharedTool = getTool().getSharedLocalInspectionTool();
  if (sharedTool == null) {
    return null;
  }
  return new LocalInspectionToolWrapper(sharedTool);
}
 
Example #5
Source File: LightIdeaTestFixtureImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void setUp() throws Exception {
  super.setUp();

  ApplicationStarter application = LightPlatformTestCase.initApplication();
  LightPlatformTestCase.doSetup(myProjectDescriptor, LocalInspectionTool.EMPTY_ARRAY, new THashMap<String, InspectionToolWrapper>());
  InjectedLanguageManagerImpl.pushInjectors(getProject());

 // application.setDataProvider(new TestDataProvider(getProject()));
}
 
Example #6
Source File: NamespacePrefixFromFileNameTest.java    From intellij-xquery with Apache License 2.0 5 votes vote down vote up
private void executeTest(String filename) {
    Collection<Class<? extends LocalInspectionTool>> inspections = new ArrayList<Class<? extends
            LocalInspectionTool>>();
    inspections.add(NamespacePrefixFromFileName.class);
    myFixture.enableInspections(inspections);

    myFixture.testHighlighting(true, false, false, filename);
}
 
Example #7
Source File: UnusedNamespaceDeclarationInspectionTest.java    From intellij-xquery with Apache License 2.0 5 votes vote down vote up
public void testRemoveUnusedNamespaceDeclarationQuickFix() {
    final String testName = getTestName();

    Collection<Class<? extends LocalInspectionTool>> inspections = new ArrayList<Class<? extends LocalInspectionTool>>();
    inspections.add(UnusedNamespaceDeclarationInspection.class);
    myFixture.enableInspections(inspections);
    myFixture.configureByFile(String.format("%s.xq", testName));

    List<IntentionAction> availableIntentions = myFixture.filterAvailableIntentions(REMOVE_UNUSED_NAMESPACE_DECLARATION_QUICKFIX_NAME);
    IntentionAction action = ContainerUtil.getFirstItem(availableIntentions);
    assertNotNull(action);
    myFixture.launchAction(action);

    myFixture.checkResultByFile(String.format("%s_after.xq", testName));
}
 
Example #8
Source File: DefaultFunctionNamespaceSameAsModuleNamespaceTest.java    From intellij-xquery with Apache License 2.0 5 votes vote down vote up
private void executeTest(String filename) {
    Collection<Class<? extends LocalInspectionTool>> inspections = new ArrayList<Class<? extends
            LocalInspectionTool>>();
    inspections.add(DefaultFunctionNamespaceSameAsModuleNamespace.class);
    myFixture.enableInspections(inspections);

    myFixture.testHighlighting(true, false, false, filename);
}
 
Example #9
Source File: UnusedImportsInspectionTest.java    From intellij-xquery with Apache License 2.0 5 votes vote down vote up
public void testRemoveUnusedImportQuickFix() {
    final String testName = getTestName();

    Collection<Class<? extends LocalInspectionTool>> inspections = new ArrayList<Class<? extends LocalInspectionTool>>();
    inspections.add(UnusedImportsInspection.class);
    myFixture.enableInspections(inspections);
    myFixture.configureByFile(String.format("%s.xq", testName));

    List<IntentionAction> availableIntentions = myFixture.filterAvailableIntentions(UnusedImportsInspection.REMOVE_UNUSED_IMPORT_QUICKFIX_NAME);
    IntentionAction action = ContainerUtil.getFirstItem(availableIntentions);
    assertNotNull(action);
    myFixture.launchAction(action);

    myFixture.checkResultByFile(String.format("%s_after.xq", testName));
}
 
Example #10
Source File: MarklogicExtendedSyntaxInspectionTest.java    From intellij-xquery with Apache License 2.0 5 votes vote down vote up
private void executeTest(String filename) {
    Collection<Class<? extends LocalInspectionTool>> inspections = new ArrayList<Class<? extends
            LocalInspectionTool>>();
    inspections.add(MarklogicExtendedSyntaxInspection.class);
    myFixture.enableInspections(inspections);

    myFixture.testHighlighting(true, false, false, filename);
}
 
Example #11
Source File: UnusedVariableInspectionTest.java    From intellij-xquery with Apache License 2.0 5 votes vote down vote up
private void executeTest(String filename) {
    Collection<Class<? extends LocalInspectionTool>> inspections = new ArrayList<Class<? extends
            LocalInspectionTool>>();
    inspections.add(UnusedVariableInspection.class);
    myFixture.enableInspections(inspections);

    myFixture.testHighlighting(true, false, false, filename);
}
 
Example #12
Source File: InvalidVersionInspectionTest.java    From intellij-xquery with Apache License 2.0 5 votes vote down vote up
private void executeTest(String filename) {
    Collection<Class<? extends LocalInspectionTool>> inspections = new ArrayList<Class<? extends
            LocalInspectionTool>>();
    inspections.add(InvalidVersionInspection.class);
    myFixture.enableInspections(inspections);

    myFixture.testHighlighting(false, false, true, filename);
}
 
Example #13
Source File: BashTestUtils.java    From BashSupport with Apache License 2.0 5 votes vote down vote up
public static InspectionProfileEntry findInspectionProfileEntry(Class<? extends LocalInspectionTool> clazz) {
    LocalInspectionEP[] extensions = Extensions.getExtensions(LocalInspectionEP.LOCAL_INSPECTION);
    for (LocalInspectionEP extension : extensions) {
        if (extension.implementationClass.equals(clazz.getCanonicalName())) {
            extension.enabledByDefault = true;

            return extension.instantiateTool();
        }
    }

    throw new IllegalStateException("Unable to find inspection profile entry for " + clazz);
}
 
Example #14
Source File: PsalmAnnotatorQualityToolAnnotator.java    From idea-php-generics-plugin with MIT License 5 votes vote down vote up
@Nullable
protected QualityToolConfiguration getConfiguration(@NotNull Project project, @NotNull LocalInspectionTool inspection) {
    try {
        return PsalmValidatorProjectConfiguration.getInstance(project).findSelectedConfiguration(project);
    } catch (QualityToolValidationException e) {
        return null;
    }
}
 
Example #15
Source File: EditInspectionToolsSettingsAction.java    From consulo with Apache License 2.0 4 votes vote down vote up
public EditInspectionToolsSettingsAction(@Nonnull LocalInspectionTool tool) {
  myShortName = tool.getShortName();
}
 
Example #16
Source File: DisableInspectionToolAction.java    From consulo with Apache License 2.0 4 votes vote down vote up
public DisableInspectionToolAction(LocalInspectionTool tool) {
  myToolId = tool.getShortName();
}
 
Example #17
Source File: LocalInspectionToolWrapper.java    From consulo with Apache License 2.0 4 votes vote down vote up
/** This should be used in tests primarily */
@TestOnly
public LocalInspectionToolWrapper(@Nonnull LocalInspectionTool tool) {
  super(tool, ourEPMap.getValue().get(tool.getShortName()));
}
 
Example #18
Source File: CreateReferenceIntentionActionTest.java    From intellij-swagger with MIT License 4 votes vote down vote up
@NotNull
@Override
protected LocalInspectionTool[] configureLocalInspectionTools() {
  return new LocalInspectionTool[] {new YamlReferenceInspection(indexFacade)};
}
 
Example #19
Source File: InspectionFixtureTestCase.java    From consulo with Apache License 2.0 4 votes vote down vote up
public void doTest(@NonNls String folderName, LocalInspectionTool tool) throws Exception {
  doTest(folderName, new LocalInspectionToolWrapper(tool));
}
 
Example #20
Source File: CreateReferenceIntentionActionTest.java    From intellij-swagger with MIT License 4 votes vote down vote up
@NotNull
@Override
protected LocalInspectionTool[] configureLocalInspectionTools() {
  return new LocalInspectionTool[] {new JsonReferenceInspection(indexFacade)};
}
 
Example #21
Source File: LightPlatformTestCase.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
protected LocalInspectionTool[] configureLocalInspectionTools() {
  return LocalInspectionTool.EMPTY_ARRAY;
}
 
Example #22
Source File: CypherFunctionCallInspectionTest.java    From jetbrains-plugin-graph-database-support with Apache License 2.0 4 votes vote down vote up
@Override
protected Set<Class<? extends LocalInspectionTool>> provideInspectionClasses() {
    return singleton(CypherFunctionCallInspection.class);
}
 
Example #23
Source File: CypherExplainWarningInspectionTest.java    From jetbrains-plugin-graph-database-support with Apache License 2.0 4 votes vote down vote up
@Override
protected Set<Class<? extends LocalInspectionTool>> provideInspectionClasses() {
    return singleton(CypherExplainWarningInspection.class);
}
 
Example #24
Source File: UnusedNamespaceDeclarationInspectionTest.java    From intellij-xquery with Apache License 2.0 4 votes vote down vote up
private void executeInspectionTest(String filename) {
    Collection<Class<? extends LocalInspectionTool>> inspections = new ArrayList<Class<? extends LocalInspectionTool>>();
    inspections.add(UnusedNamespaceDeclarationInspection.class);
    myFixture.enableInspections(inspections);
    myFixture.testHighlighting(true, false, false, filename);
}
 
Example #25
Source File: UnusedImportsInspectionTest.java    From intellij-xquery with Apache License 2.0 4 votes vote down vote up
private void executeInspectionTest(String filename) {
    Collection<Class<? extends LocalInspectionTool>> inspections = new ArrayList<Class<? extends LocalInspectionTool>>();
    inspections.add(UnusedImportsInspection.class);
    myFixture.enableInspections(inspections);
    myFixture.testHighlighting(true, false, false, filename, "file1.xq", "file3.xq");
}
 
Example #26
Source File: CodeInsightTestFixture.java    From consulo with Apache License 2.0 votes vote down vote up
void enableInspections(@Nonnull Collection<Class<? extends LocalInspectionTool>> inspections); 
Example #27
Source File: CodeInsightTestFixture.java    From consulo with Apache License 2.0 votes vote down vote up
void enableInspections(@Nonnull Class<? extends LocalInspectionTool>... inspections); 
Example #28
Source File: BaseInspectionTest.java    From jetbrains-plugin-graph-database-support with Apache License 2.0 votes vote down vote up
protected abstract Set<Class<? extends LocalInspectionTool>> provideInspectionClasses();