@SuppressWarnings({"WeakerAccess", "UnusedReturnValue"}) // used in TeamCity
 public static InspectionResultsView showOfflineView(
     @NotNull Project project,
     @Nullable final String profileName,
     @NotNull final Map<String, Map<String, Set<OfflineProblemDescriptor>>> resMap,
     @NotNull String title) {
   InspectionProfileImpl profile;
   if (profileName != null) {
     profile = InspectionProjectProfileManager.getInstance(project).getProfile(profileName, false);
     if (profile == null) {
       profile = InspectionProfileManager.getInstance().getProfile(profileName, false);
     }
   } else {
     profile = null;
   }
   final InspectionProfileImpl inspectionProfile;
   if (profile != null) {
     inspectionProfile = profile;
   } else {
     inspectionProfile =
         new InspectionProfileImpl(profileName != null ? profileName : "Server Side") {
           @Override
           public HighlightDisplayLevel getErrorLevel(
               @NotNull final HighlightDisplayKey key, PsiElement element) {
             return InspectionProfileManager.getInstance()
                 .getCurrentProfile()
                 .getErrorLevel(key, element);
           }
         };
     for (String id : resMap.keySet()) {
       inspectionProfile.enableTool(id, project);
     }
   }
   return showOfflineView(project, resMap, inspectionProfile, title);
 }
 protected void disableInspectionTool(@NotNull String shortName) {
   InspectionProfile profile =
       InspectionProjectProfileManager.getInstance(getProject()).getInspectionProfile();
   if (profile.getInspectionTool(shortName, getProject()) != null) {
     ((InspectionProfileImpl) profile).disableTool(shortName, getProject());
   }
 }
 private void addRemoveTestsScope(Project project, boolean add) {
   final InspectionProjectProfileManager profileManager =
       InspectionProjectProfileManager.getInstance(project);
   final InspectionProfileImpl profile =
       (InspectionProfileImpl) profileManager.getCurrentProfile();
   final String shortName = myInspection.getShortName();
   final InspectionToolWrapper tool = profile.getInspectionTool(shortName, project);
   if (tool == null) {
     return;
   }
   if (add) {
     final NamedScope namedScope = NamedScopesHolder.getScope(project, "Tests");
     final HighlightDisplayKey key = HighlightDisplayKey.find(shortName);
     final HighlightDisplayLevel level = profile.getErrorLevel(key, namedScope, project);
     profile.addScope(tool, namedScope, level, false, project);
   } else {
     profile.removeScope(shortName, "Tests", project);
   }
   profile.scopesChanged();
 }
Example #4
0
  public static void doSetup(
      final LightProjectDescriptor descriptor,
      final LocalInspectionTool[] localInspectionTools,
      final Map<String, InspectionTool> availableInspectionTools)
      throws Exception {
    assertNull(
        "Previous test "
            + ourTestCase
            + " hasn't called tearDown(). Probably overriden without super call.",
        ourTestCase);
    IdeaLogger.ourErrorsOccurred = null;

    if (ourProject == null || !ourProjectDescriptor.equals(descriptor)) {
      initProject(descriptor);
    }

    ProjectManagerEx.getInstanceEx().setCurrentTestProject(ourProject);

    ((PsiDocumentManagerImpl) PsiDocumentManager.getInstance(getProject()))
        .clearUncommitedDocuments();

    for (LocalInspectionTool tool : localInspectionTools) {
      enableInspectionTool(availableInspectionTools, new LocalInspectionToolWrapper(tool));
    }

    final InspectionProfileImpl profile =
        new InspectionProfileImpl("Configurable") {
          @NotNull
          public InspectionProfileEntry[] getInspectionTools(PsiElement element) {
            if (availableInspectionTools != null) {
              final Collection<InspectionTool> tools = availableInspectionTools.values();
              return tools.toArray(new InspectionTool[tools.size()]);
            }
            return new InspectionTool[0];
          }

          @Override
          public List<ToolsImpl> getAllEnabledInspectionTools() {
            List<ToolsImpl> result = new ArrayList<ToolsImpl>();
            for (InspectionProfileEntry entry : getInspectionTools(null)) {
              result.add(new ToolsImpl(entry, entry.getDefaultLevel(), true));
            }
            return result;
          }

          public boolean isToolEnabled(HighlightDisplayKey key, PsiElement element) {
            return key != null && availableInspectionTools.containsKey(key.toString());
          }

          public HighlightDisplayLevel getErrorLevel(
              @NotNull HighlightDisplayKey key, PsiElement element) {
            InspectionTool localInspectionTool = availableInspectionTools.get(key.toString());
            return localInspectionTool != null
                ? localInspectionTool.getDefaultLevel()
                : HighlightDisplayLevel.WARNING;
          }

          public InspectionTool getInspectionTool(
              @NotNull String shortName, @NotNull PsiElement element) {
            if (availableInspectionTools.containsKey(shortName)) {
              return availableInspectionTools.get(shortName);
            }
            return null;
          }
        };
    final InspectionProfileManager inspectionProfileManager =
        InspectionProfileManager.getInstance();
    inspectionProfileManager.addProfile(profile);
    inspectionProfileManager.setRootProfile(profile.getName());
    InspectionProjectProfileManager.getInstance(getProject()).updateProfile(profile);
    InspectionProjectProfileManager.getInstance(getProject()).setProjectProfile(profile.getName());

    assertFalse(getPsiManager().isDisposed());

    CodeStyleSettingsManager.getInstance(getProject())
        .setTemporarySettings(new CodeStyleSettings());
  }