protected HighlightSeverity getSeverity(@NotNull RefElement element) {
    final PsiElement psiElement = element.getPointer().getContainingFile();
    if (psiElement != null) {
      final GlobalInspectionContextImpl context = getContext();
      final String shortName = getSeverityDelegateName();
      final Tools tools = context.getTools().get(shortName);
      if (tools != null) {
        for (ScopeToolState state : tools.getTools()) {
          InspectionToolWrapper toolWrapper = state.getTool();
          if (toolWrapper == getToolWrapper()) {
            return context
                .getCurrentProfile()
                .getErrorLevel(HighlightDisplayKey.find(shortName), psiElement)
                .getSeverity();
          }
        }
      }

      final InspectionProfile profile =
          InspectionProjectProfileManager.getInstance(context.getProject()).getInspectionProfile();
      final HighlightDisplayLevel level =
          profile.getErrorLevel(HighlightDisplayKey.find(shortName), psiElement);
      return level.getSeverity();
    }
    return null;
  }
コード例 #2
0
 protected void disableInspectionTool(@NotNull String shortName) {
   InspectionProfile profile =
       InspectionProjectProfileManager.getInstance(getProject()).getInspectionProfile();
   if (profile.getInspectionTool(shortName, getProject()) != null) {
     ((InspectionProfileImpl) profile).disableTool(shortName, getProject());
   }
 }
コード例 #3
0
  private void reportOneTagProblem(
      final XmlTag tag,
      final String name,
      final String localizedMessage,
      final IntentionAction basicIntention,
      final HighlightDisplayKey key,
      final XmlEntitiesInspection inspection,
      final int type) {
    boolean htmlTag = false;

    if (tag instanceof HtmlTag) {
      htmlTag = true;
      if (isAdditionallyDeclared(inspection.getAdditionalEntries(type), name)) return;
    }

    final InspectionProfile profile =
        InspectionProjectProfileManager.getInstance(tag.getProject()).getInspectionProfile();
    final IntentionAction intentionAction = inspection.getIntentionAction(name, type);
    if (htmlTag && profile.isToolEnabled(key, tag)) {
      addElementsForTagWithManyQuickFixes(
          tag,
          localizedMessage,
          isInjectedHtmlTagForWhichNoProblemsReporting((HtmlTag) tag)
              ? HighlightInfoType.INFORMATION
              : SeverityRegistrar.getInstance(tag.getProject())
                  .getHighlightInfoTypeBySeverity(profile.getErrorLevel(key, tag).getSeverity()),
          intentionAction,
          basicIntention);
    } else if (!htmlTag) {
      addElementsForTag(tag, localizedMessage, HighlightInfoType.ERROR, basicIntention);
    }
  }
コード例 #4
0
    @Override
    public void actionPerformed(AnActionEvent e) {
      final InspectionProjectProfileManager profileManager =
          InspectionProjectProfileManager.getInstance(myProject);
      final InspectionToolWrapper toolWrapper = myTree.getSelectedToolWrapper();
      InspectionProfile inspectionProfile = myInspectionProfile;
      final boolean profileIsDefined = isProfileDefined();
      if (!profileIsDefined) {
        inspectionProfile = guessProfileToSelect(profileManager);
      }

      if (toolWrapper != null) {
        final HighlightDisplayKey key =
            HighlightDisplayKey.find(
                toolWrapper.getShortName()); // do not search for dead code entry point tool
        if (key != null) {
          if (new EditInspectionToolsSettingsAction(key)
                  .editToolSettings(
                      myProject, (InspectionProfileImpl) inspectionProfile, profileIsDefined)
              && profileIsDefined) {
            updateCurrentProfile();
          }
          return;
        }
      }
      if (EditInspectionToolsSettingsAction.editToolSettings(
              myProject, inspectionProfile, profileIsDefined, null)
          && profileIsDefined) {
        updateCurrentProfile();
      }
    }
コード例 #5
0
 @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);
 }
コード例 #6
0
 public static InspectionToolWrapper findTool2RunInBatch(
     @NotNull Project project, @Nullable PsiElement element, @NotNull 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();
       if (oppositeShortName != null) {
         return element == null
             ? inspectionProfile.getInspectionTool(oppositeShortName, project)
             : inspectionProfile.getInspectionTool(oppositeShortName, element);
       }
     }
     return null;
   }
   return toolWrapper;
 }
  @Override
  public void computeUsages(List<PsiLiteralExpression> targets) {
    final Project project = myTarget.getProject();
    final PsiElement parent = myTarget.getParent().getParent();
    final LocalInspectionsPass pass =
        new LocalInspectionsPass(
            myFile,
            myFile.getViewProvider().getDocument(),
            parent.getTextRange().getStartOffset(),
            parent.getTextRange().getEndOffset(),
            LocalInspectionsPass.EMPTY_PRIORITY_RANGE,
            false,
            HighlightInfoProcessor.getEmpty());
    final InspectionProfile inspectionProfile =
        InspectionProjectProfileManager.getInstance(project).getInspectionProfile();
    for (PsiLiteralExpression target : targets) {
      final Object value = target.getValue();
      if (!(value instanceof String)) {
        continue;
      }
      InspectionToolWrapper toolWrapperById =
          ((InspectionProfileImpl) inspectionProfile).getToolById((String) value, target);
      if (!(toolWrapperById instanceof LocalInspectionToolWrapper)) {
        continue;
      }
      final LocalInspectionToolWrapper toolWrapper =
          ((LocalInspectionToolWrapper) toolWrapperById).createCopy();
      final InspectionManagerEx managerEx =
          (InspectionManagerEx) InspectionManager.getInstance(project);
      final GlobalInspectionContextImpl context = managerEx.createNewGlobalContext(false);
      toolWrapper.initialize(context);
      ((RefManagerImpl) context.getRefManager()).inspectionReadActionStarted();
      ProgressIndicator indicator = ProgressManager.getInstance().getProgressIndicator();
      Runnable inspect =
          new Runnable() {
            @Override
            public void run() {
              pass.doInspectInBatch(
                  context,
                  managerEx,
                  Collections.<LocalInspectionToolWrapper>singletonList(toolWrapper));
            }
          };
      if (indicator == null) {
        ProgressManager.getInstance()
            .executeProcessUnderProgress(inspect, new ProgressIndicatorBase());
      } else {
        inspect.run();
      }

      for (HighlightInfo info : pass.getInfos()) {
        final PsiElement element =
            CollectHighlightsUtil.findCommonParent(myFile, info.startOffset, info.endOffset);
        if (element != null) {
          addOccurrence(element);
        }
      }
    }
  }
コード例 #8
0
  private boolean checkFile(
      List<LocalInspectionTool> inspections,
      final MyValidatorProcessingItem item,
      final CompileContext context) {
    boolean hasErrors = false;
    if (!checkUnderReadAction(
        item,
        context,
        new Computable<Map<ProblemDescriptor, HighlightDisplayLevel>>() {
          @Override
          public Map<ProblemDescriptor, HighlightDisplayLevel> compute() {
            return myValidator.checkAdditionally(item.getPsiFile());
          }
        })) {
      hasErrors = true;
    }

    if (!checkUnderReadAction(
        item,
        context,
        new Computable<Map<ProblemDescriptor, HighlightDisplayLevel>>() {
          @Override
          public Map<ProblemDescriptor, HighlightDisplayLevel> compute() {
            final PsiFile file = item.getPsiFile();
            if (file instanceof XmlFile) {
              return runXmlFileSchemaValidation((XmlFile) file);
            }
            return Collections.emptyMap();
          }
        })) {
      hasErrors = true;
    }

    final InspectionProfile inspectionProfile = myProfileManager.getInspectionProfile();
    for (final LocalInspectionTool inspectionTool : inspections) {
      if (!checkUnderReadAction(
          item,
          context,
          new Computable<Map<ProblemDescriptor, HighlightDisplayLevel>>() {
            @Override
            public Map<ProblemDescriptor, HighlightDisplayLevel> compute() {
              final PsiFile file = item.getPsiFile();
              if (file != null
                  && getHighlightDisplayLevel(inspectionTool, inspectionProfile, file)
                      != HighlightDisplayLevel.DO_NOT_SHOW) {
                return runInspectionTool(
                    file,
                    inspectionTool,
                    getHighlightDisplayLevel(inspectionTool, inspectionProfile, file));
              }
              return Collections.emptyMap();
            }
          })) {
        hasErrors = true;
      }
    }
    return !hasErrors;
  }
コード例 #9
0
 private InspectionProfile guessProfileToSelect(
     final InspectionProjectProfileManager profileManager) {
   final Set<InspectionProfile> profiles = new HashSet<InspectionProfile>();
   final RefEntity[] selectedElements = myTree.getSelectedElements();
   for (RefEntity selectedElement : selectedElements) {
     if (selectedElement instanceof RefElement) {
       final RefElement refElement = (RefElement) selectedElement;
       final PsiElement element = refElement.getElement();
       if (element != null) {
         profiles.add(profileManager.getInspectionProfile());
       }
     }
   }
   if (profiles.isEmpty()) {
     return (InspectionProfile) profileManager.getProjectProfileImpl();
   }
   return profiles.iterator().next();
 }
コード例 #10
0
 public MyVisitor(@NotNull ProblemsHolder holder) {
   myHolder = holder;
   InspectionProfile profile =
       InspectionProjectProfileManager.getInstance(holder.getProject()).getInspectionProfile();
   UnusedDeclarationInspectionBase tool =
       (UnusedDeclarationInspectionBase)
           profile.getUnwrappedTool(
               UnusedDeclarationInspectionBase.SHORT_NAME, holder.getFile());
   myDeadCodeInspection = tool == null ? new UnusedDeclarationInspectionBase() : tool;
 }
コード例 #11
0
  protected InspectionTool[] getInspectionTools(PsiElement psiElement, InspectionManager manager) {
    final ModifiableModel model =
        InspectionProjectProfileManager.getInstance(manager.getProject())
            .getInspectionProfile()
            .getModifiableModel();
    InspectionProfileWrapper profile = new InspectionProfileWrapper((InspectionProfile) model);
    profile.init(manager.getProject());

    return profile.getInspectionTools(psiElement);
  }
コード例 #12
0
 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();
 }
コード例 #13
0
 @Override
 @NotNull
 public HighlightSeverity getSeverity(final PsiElement psiElement) {
   InspectionProfile profile =
       psiElement == null
           ? (InspectionProfile) InspectionProfileManager.getInstance().getRootProfile()
           : InspectionProjectProfileManager.getInstance(psiElement.getProject())
               .getInspectionProfile();
   HighlightDisplayLevel level = profile.getErrorLevel(myToolKey, psiElement);
   LOG.assertTrue(level != HighlightDisplayLevel.DO_NOT_SHOW);
   return level.getSeverity();
 }
コード例 #14
0
 private void onClose() {
   if (isModified()) {
     for (HectorComponentPanel panel : myAdditionalPanels) {
       try {
         panel.apply();
       } catch (ConfigurationException e) {
         // shouldn't be
       }
     }
     forceDaemonRestart();
     InspectionProjectProfileManager.getInstance(myFile.getProject()).updateStatusBar();
   }
 }
  @Override
  @Nullable
  public TextEditorHighlightingPass createHighlightingPass(
      @NotNull final PsiFile file, @NotNull final Editor editor) {
    TextRange textRange = FileStatusMap.getDirtyTextRange(editor, Pass.LOCAL_INSPECTIONS);
    if (textRange == null
        || !InspectionProjectProfileManager.getInstance(file.getProject()).isProfileLoaded()
        || myFileTools.containsKey(file) && !myFileTools.get(file)) {
      return null;
    }

    return new LocalInspectionsPass(
        file,
        editor.getDocument(),
        0,
        file.getTextLength(),
        LocalInspectionsPass.EMPTY_PRIORITY_RANGE,
        true,
        new DefaultHighlightInfoProcessor()) {
      @NotNull
      @Override
      List<LocalInspectionToolWrapper> getInspectionTools(
          @NotNull InspectionProfileWrapper profile) {
        List<LocalInspectionToolWrapper> tools = super.getInspectionTools(profile);
        List<LocalInspectionToolWrapper> result =
            new ArrayList<LocalInspectionToolWrapper>(tools.size());
        for (LocalInspectionToolWrapper tool : tools) {
          if (tool.runForWholeFile()) result.add(tool);
        }
        myFileTools.put(file, !result.isEmpty());
        return result;
      }

      @Override
      protected String getPresentableName() {
        return DaemonBundle.message("pass.whole.inspections");
      }

      @Override
      void inspectInjectedPsi(
          @NotNull List<PsiElement> elements,
          boolean onTheFly,
          @NotNull ProgressIndicator indicator,
          @NotNull InspectionManager iManager,
          boolean inVisibleRange,
          boolean checkDumbAwareness,
          @NotNull List<LocalInspectionToolWrapper> wrappers) {
        // already inspected in LIP
      }
    };
  }
コード例 #16
0
 @NotNull
 @Override
 public Collection<BooleanOptionDescription> getOptions(@Nullable Project project) {
   if (project == null) return ContainerUtil.emptyList();
   List<BooleanOptionDescription> result = ContainerUtil.newArrayList();
   List<Tools> tools =
       InspectionProjectProfileManager.getInstance(project)
           .getCurrentProfile()
           .getAllEnabledInspectionTools(project);
   for (Tools tool : tools) {
     result.add(new ToolOptionDescription(tool, project));
   }
   return result;
 }
コード例 #17
0
 public boolean canCleanup(@NotNull PsiElement element) {
   if (myCanCleanup == null) {
     InspectionProfile profile =
         InspectionProjectProfileManager.getInstance(element.getProject())
             .getInspectionProfile();
     final HighlightDisplayKey key = myKey;
     if (key == null) {
       myCanCleanup = false;
     } else {
       InspectionToolWrapper toolWrapper = profile.getInspectionTool(key.toString(), element);
       myCanCleanup = toolWrapper != null && toolWrapper.isCleanupTool();
     }
   }
   return myCanCleanup;
 }
 private static boolean isAvailable(PyCallExpression node) {
   final InspectionProfile profile =
       InspectionProjectProfileManager.getInstance(node.getProject()).getInspectionProfile();
   final InspectionToolWrapper inspectionTool =
       profile.getInspectionTool("PyCompatibilityInspection", node.getProject());
   if (inspectionTool != null) {
     final InspectionProfileEntry inspection = inspectionTool.getTool();
     if (inspection instanceof PyCompatibilityInspection) {
       final JDOMExternalizableStringList versions =
           ((PyCompatibilityInspection) inspection).ourVersions;
       for (String s : versions) {
         if (!LanguageLevel.fromPythonVersion(s).supportsSetLiterals()) return false;
       }
     }
   }
   return LanguageLevel.forElement(node).supportsSetLiterals();
 }
コード例 #19
0
  private void checkRequiredAttributes(
      XmlTag tag, String name, XmlElementDescriptor elementDescriptor) {
    XmlAttributeDescriptor[] attributeDescriptors = elementDescriptor.getAttributesDescriptors(tag);
    Set<String> requiredAttributes = null;

    for (XmlAttributeDescriptor attribute : attributeDescriptors) {
      if (attribute != null && attribute.isRequired()) {
        if (requiredAttributes == null) {
          requiredAttributes = new HashSet<String>();
        }
        requiredAttributes.add(attribute.getName(tag));
      }
    }

    if (requiredAttributes != null) {
      for (final String attrName : requiredAttributes) {
        if (tag.getAttribute(attrName, "") == null
            && !XmlExtension.getExtension(tag.getContainingFile())
                .isRequiredAttributeImplicitlyPresent(tag, attrName)) {

          final InsertRequiredAttributeFix insertRequiredAttributeIntention =
              new InsertRequiredAttributeFix(tag, attrName, null);
          final String localizedMessage =
              XmlErrorMessages.message("element.doesnt.have.required.attribute", name, attrName);
          final InspectionProfile profile =
              InspectionProjectProfileManager.getInstance(tag.getProject()).getInspectionProfile();
          final LocalInspectionToolWrapper toolWrapper =
              (LocalInspectionToolWrapper)
                  profile.getInspectionTool(RequiredAttributesInspection.SHORT_NAME, tag);
          if (toolWrapper != null) {
            RequiredAttributesInspection inspection =
                (RequiredAttributesInspection) toolWrapper.getTool();
            reportOneTagProblem(
                tag,
                attrName,
                localizedMessage,
                insertRequiredAttributeIntention,
                HighlightDisplayKey.find(RequiredAttributesInspection.SHORT_NAME),
                inspection,
                XmlEntitiesInspection.NOT_REQUIRED_ATTRIBUTE);
          }
        }
      }
    }
  }
コード例 #20
0
  @Override
  public void projectOpened() {
    final ProfileChangeAdapter myProfilesListener =
        new ProfileChangeAdapter() {
          @Override
          public void profileChanged(Profile profile) {
            myFileTools.clear();
          }

          @Override
          public void profileActivated(Profile oldProfile, Profile profile) {
            myFileTools.clear();
          }
        };
    myProfileManager.addProfilesListener(myProfilesListener);
    Disposer.register(
        myProject,
        new Disposable() {
          public void dispose() {
            myProfileManager.removeProfilesListener(myProfilesListener);
            myFileTools.clear();
          }
        });
  }
コード例 #21
0
    @Nullable
    public List<IntentionAction> getOptions(@NotNull PsiElement element, @Nullable Editor editor) {
      if (editor != null
          && Boolean.FALSE.equals(
              editor.getUserData(IntentionManager.SHOW_INTENTION_OPTIONS_KEY))) {
        return null;
      }
      List<IntentionAction> options = myOptions;
      HighlightDisplayKey key = myKey;
      if (options != null || key == null) {
        return options;
      }
      List<IntentionAction> newOptions =
          IntentionManager.getInstance().getStandardIntentionOptions(key, element);
      InspectionProfile profile =
          InspectionProjectProfileManager.getInstance(element.getProject()).getInspectionProfile();
      InspectionProfileEntry tool = profile.getInspectionTool(key.toString(), element);
      if (!(tool instanceof LocalInspectionToolWrapper)) {
        HighlightDisplayKey idkey = HighlightDisplayKey.findById(key.toString());
        if (idkey != null) {
          tool = profile.getInspectionTool(idkey.toString(), element);
        }
      }
      InspectionProfileEntry wrappedTool = tool;
      if (tool instanceof LocalInspectionToolWrapper) {
        wrappedTool = ((LocalInspectionToolWrapper) tool).getTool();
        Class aClass = myAction.getClass();
        if (myAction instanceof QuickFixWrapper) {
          aClass = ((QuickFixWrapper) myAction).getFix().getClass();
        }
        newOptions.add(new CleanupInspectionIntention((LocalInspectionToolWrapper) tool, aClass));
      } else if (tool instanceof GlobalInspectionToolWrapper) {
        wrappedTool = ((GlobalInspectionToolWrapper) tool).getTool();
        if (wrappedTool instanceof GlobalSimpleInspectionTool
            && (myAction instanceof LocalQuickFix || myAction instanceof QuickFixWrapper)) {
          Class aClass = myAction.getClass();
          if (myAction instanceof QuickFixWrapper) {
            aClass = ((QuickFixWrapper) myAction).getFix().getClass();
          }
          newOptions.add(
              new CleanupInspectionIntention((GlobalInspectionToolWrapper) tool, aClass));
        }
      }

      if (wrappedTool instanceof CustomSuppressableInspectionTool) {
        final IntentionAction[] suppressActions =
            ((CustomSuppressableInspectionTool) wrappedTool).getSuppressActions(element);
        if (suppressActions != null) {
          ContainerUtil.addAll(newOptions, suppressActions);
        }
      }
      if (wrappedTool instanceof BatchSuppressableTool) {
        final SuppressQuickFix[] suppressActions =
            ((BatchSuppressableTool) wrappedTool).getBatchSuppressActions(element);
        ContainerUtil.addAll(
            newOptions,
            ContainerUtil.map(
                suppressActions,
                new Function<SuppressQuickFix, IntentionAction>() {
                  @Override
                  public IntentionAction fun(SuppressQuickFix fix) {
                    return InspectionManagerEx.convertBatchToSuppressIntentionAction(fix);
                  }
                }));
      }

      synchronized (this) {
        options = myOptions;
        if (options == null) {
          myOptions = options = newOptions;
        }
        myKey = null;
      }
      return options;
    }
コード例 #22
0
ファイル: LightPlatformTestCase.java プロジェクト: jexp/idea2
  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());
  }
コード例 #23
0
 @NotNull
 public static SeverityRegistrar getSeverityRegistrar(@Nullable Project project) {
   return project == null
       ? InspectionProfileManager.getInstance().getSeverityRegistrar()
       : InspectionProjectProfileManager.getInstance(project).getSeverityRegistrar();
 }
コード例 #24
0
 private static boolean isInspectionEnabled(PsiFile file, Project project) {
   final InspectionProfile profile =
       InspectionProjectProfileManager.getInstance(project).getInspectionProfile();
   final HighlightDisplayKey unusedDefKey = HighlightDisplayKey.find(SHORT_NAME);
   return profile.isToolEnabled(unusedDefKey, file);
 }
コード例 #25
0
 private static GrUnresolvedAccessInspection getInstance(PsiFile file, Project project) {
   final InspectionProfile profile =
       InspectionProjectProfileManager.getInstance(project).getInspectionProfile();
   return (GrUnresolvedAccessInspection) profile.getUnwrappedTool(SHORT_NAME, file);
 }
コード例 #26
0
 private static HighlightDisplayLevel getHighlightDisplayLevel(
     Project project, GrReferenceElement ref) {
   final InspectionProfile profile =
       InspectionProjectProfileManager.getInstance(project).getInspectionProfile();
   return profile.getErrorLevel(HighlightDisplayKey.find(SHORT_NAME), ref);
 }
コード例 #27
0
    @Nullable
    public List<IntentionAction> getOptions(@NotNull PsiElement element, @Nullable Editor editor) {
      if (editor != null
          && Boolean.FALSE.equals(
              editor.getUserData(IntentionManager.SHOW_INTENTION_OPTIONS_KEY))) {
        return null;
      }
      List<IntentionAction> options = myOptions;
      HighlightDisplayKey key = myKey;
      if (myProblemGroup != null) {
        String problemName = myProblemGroup.getProblemName();
        HighlightDisplayKey problemGroupKey =
            problemName != null ? HighlightDisplayKey.findById(problemName) : null;
        if (problemGroupKey != null) {
          key = problemGroupKey;
        }
      }
      if (options != null || key == null) {
        return options;
      }
      IntentionManager intentionManager = IntentionManager.getInstance();
      List<IntentionAction> newOptions = intentionManager.getStandardIntentionOptions(key, element);
      InspectionProfile profile =
          InspectionProjectProfileManager.getInstance(element.getProject()).getInspectionProfile();
      InspectionToolWrapper toolWrapper = profile.getInspectionTool(key.toString(), element);
      if (!(toolWrapper instanceof LocalInspectionToolWrapper)) {
        HighlightDisplayKey idkey = HighlightDisplayKey.findById(key.toString());
        if (idkey != null) {
          toolWrapper = profile.getInspectionTool(idkey.toString(), element);
        }
      }
      if (toolWrapper != null) {

        myCanCleanup = toolWrapper.isCleanupTool();

        ContainerUtil.addIfNotNull(
            newOptions, intentionManager.createFixAllIntention(toolWrapper, myAction));
        InspectionProfileEntry wrappedTool =
            toolWrapper instanceof LocalInspectionToolWrapper
                ? ((LocalInspectionToolWrapper) toolWrapper).getTool()
                : ((GlobalInspectionToolWrapper) toolWrapper).getTool();
        if (wrappedTool instanceof CustomSuppressableInspectionTool) {
          final IntentionAction[] suppressActions =
              ((CustomSuppressableInspectionTool) wrappedTool).getSuppressActions(element);
          if (suppressActions != null) {
            ContainerUtil.addAll(newOptions, suppressActions);
          }
        } else {
          SuppressQuickFix[] suppressFixes = wrappedTool.getBatchSuppressActions(element);
          if (suppressFixes.length > 0) {
            ContainerUtil.addAll(
                newOptions,
                ContainerUtil.map(
                    suppressFixes,
                    new Function<SuppressQuickFix, IntentionAction>() {
                      @Override
                      public IntentionAction fun(SuppressQuickFix fix) {
                        return SuppressIntentionActionFromFix.convertBatchToSuppressIntentionAction(
                            fix);
                      }
                    }));
          }
        }
      }
      if (myProblemGroup instanceof SuppressableProblemGroup) {
        final IntentionAction[] suppressActions =
            ((SuppressableProblemGroup) myProblemGroup).getSuppressActions(element);
        ContainerUtil.addAll(newOptions, suppressActions);
      }

      synchronized (this) {
        options = myOptions;
        if (options == null) {
          myOptions = options = newOptions;
        }
        myKey = null;
      }
      return options;
    }
  private void exportResults(
      @NotNull final CommonProblemDescriptor[] descriptors,
      @NotNull RefEntity refEntity,
      @NotNull Element parentNode) {
    for (CommonProblemDescriptor descriptor : descriptors) {
      @NonNls final String template = descriptor.getDescriptionTemplate();
      int line =
          descriptor instanceof ProblemDescriptor
              ? ((ProblemDescriptor) descriptor).getLineNumber()
              : -1;
      final PsiElement psiElement =
          descriptor instanceof ProblemDescriptor
              ? ((ProblemDescriptor) descriptor).getPsiElement()
              : null;
      @NonNls
      String problemText =
          StringUtil.replace(
              StringUtil.replace(
                  template,
                  "#ref",
                  psiElement != null
                      ? ProblemDescriptorUtil.extractHighlightedText(descriptor, psiElement)
                      : ""),
              " #loc ",
              " ");

      Element element = refEntity.getRefManager().export(refEntity, parentNode, line);
      if (element == null) return;
      @NonNls
      Element problemClassElement =
          new Element(InspectionsBundle.message("inspection.export.results.problem.element.tag"));
      problemClassElement.addContent(myToolWrapper.getDisplayName());

      final HighlightSeverity severity;
      if (refEntity instanceof RefElement) {
        final RefElement refElement = (RefElement) refEntity;
        severity = getSeverity(refElement);
      } else {
        final InspectionProfile profile =
            InspectionProjectProfileManager.getInstance(getContext().getProject())
                .getInspectionProfile();
        final HighlightDisplayLevel level =
            profile.getErrorLevel(
                HighlightDisplayKey.find(myToolWrapper.getShortName()), psiElement);
        severity = level.getSeverity();
      }

      if (severity != null) {
        ProblemHighlightType problemHighlightType =
            descriptor instanceof ProblemDescriptor
                ? ((ProblemDescriptor) descriptor).getHighlightType()
                : ProblemHighlightType.GENERIC_ERROR_OR_WARNING;
        final String attributeKey =
            getTextAttributeKey(getRefManager().getProject(), severity, problemHighlightType);
        problemClassElement.setAttribute("severity", severity.myName);
        problemClassElement.setAttribute("attribute_key", attributeKey);
      }

      element.addContent(problemClassElement);
      if (myToolWrapper instanceof GlobalInspectionToolWrapper) {
        final GlobalInspectionTool globalInspectionTool =
            ((GlobalInspectionToolWrapper) myToolWrapper).getTool();
        final QuickFix[] fixes = descriptor.getFixes();
        if (fixes != null) {
          @NonNls Element hintsElement = new Element("hints");
          for (QuickFix fix : fixes) {
            final String hint = globalInspectionTool.getHint(fix);
            if (hint != null) {
              @NonNls Element hintElement = new Element("hint");
              hintElement.setAttribute("value", hint);
              hintsElement.addContent(hintElement);
            }
          }
          element.addContent(hintsElement);
        }
      }
      try {
        Element descriptionElement =
            new Element(InspectionsBundle.message("inspection.export.results.description.tag"));
        descriptionElement.addContent(problemText);
        element.addContent(descriptionElement);
      } catch (IllegalDataException e) {
        //noinspection HardCodedStringLiteral,UseOfSystemOutOrSystemErr
        System.out.println(
            "Cannot save results for "
                + refEntity.getName()
                + ", inspection which caused problem: "
                + myToolWrapper.getShortName());
      }
    }
  }