use of com.intellij.codeInsight.daemon.HighlightDisplayKey in project intellij-community by JetBrains.
the class InspectionProfileImpl method addTool.
public void addTool(@Nullable Project project, @NotNull InspectionToolWrapper toolWrapper, @NotNull Map<String, List<String>> dependencies) {
final String shortName = toolWrapper.getShortName();
HighlightDisplayKey key = HighlightDisplayKey.find(shortName);
if (key == null) {
final InspectionEP extension = toolWrapper.getExtension();
Computable<String> computable = extension == null ? new Computable.PredefinedValueComputable<>(toolWrapper.getDisplayName()) : extension::getDisplayName;
if (toolWrapper instanceof LocalInspectionToolWrapper) {
key = HighlightDisplayKey.register(shortName, computable, toolWrapper.getID(), ((LocalInspectionToolWrapper) toolWrapper).getAlternativeID());
} else {
key = HighlightDisplayKey.register(shortName, computable);
}
}
if (key == null) {
LOG.error(shortName + " ; number of initialized tools: " + myTools.size());
return;
}
HighlightDisplayLevel baseLevel = myBaseProfile != null && myBaseProfile.getToolsOrNull(shortName, project) != null ? myBaseProfile.getErrorLevel(key, project) : HighlightDisplayLevel.DO_NOT_SHOW;
HighlightDisplayLevel defaultLevel = toolWrapper.getDefaultLevel();
HighlightDisplayLevel level = baseLevel.getSeverity().compareTo(defaultLevel.getSeverity()) > 0 ? baseLevel : defaultLevel;
boolean enabled = myBaseProfile != null ? myBaseProfile.isToolEnabled(key) : toolWrapper.isEnabledByDefault();
final ToolsImpl toolsList = new ToolsImpl(toolWrapper, level, !myLockedProfile && enabled, enabled);
final Element element = myUninitializedSettings.remove(shortName);
try {
if (element != null) {
getPathMacroManager().expandPaths(element);
toolsList.readExternal(element, getProfileManager(), dependencies);
} else if (!myUninitializedSettings.containsKey(InspectionElementsMergerBase.getMergedMarkerName(shortName))) {
final InspectionElementsMergerBase merger = getMerger(shortName);
Element merged = merger == null ? null : merger.merge(myUninitializedSettings);
if (merged != null) {
getPathMacroManager().expandPaths(merged);
toolsList.readExternal(merged, getProfileManager(), dependencies);
} else if (isProfileLocked()) {
// https://youtrack.jetbrains.com/issue/IDEA-158936
toolsList.setEnabled(false);
if (toolsList.getNonDefaultTools() == null) {
toolsList.getDefaultState().setEnabled(false);
}
}
}
} catch (InvalidDataException e) {
LOG.error("Can't read settings for " + toolWrapper, e);
}
myTools.put(shortName, toolsList);
}
use of com.intellij.codeInsight.daemon.HighlightDisplayKey in project kotlin by JetBrains.
the class AndroidLintExternalAnnotator method getIssuesFromInspections.
@NotNull
static List<Issue> getIssuesFromInspections(@NotNull Project project, @Nullable PsiElement context) {
final List<Issue> result = new ArrayList<Issue>();
final IssueRegistry fullRegistry = new IntellijLintIssueRegistry();
for (Issue issue : fullRegistry.getIssues()) {
final String inspectionShortName = AndroidLintInspectionBase.getInspectionShortNameByIssue(project, issue);
if (inspectionShortName == null) {
continue;
}
final HighlightDisplayKey key = HighlightDisplayKey.find(inspectionShortName);
if (key == null) {
continue;
}
final InspectionProfile profile = InspectionProjectProfileManager.getInstance(project).getInspectionProfile();
final boolean enabled = context != null ? profile.isToolEnabled(key, context) : profile.isToolEnabled(key);
if (!enabled) {
continue;
} else if (!issue.isEnabledByDefault()) {
// If an issue is marked as not enabled by default, lint won't run it, even if it's in the set
// of issues provided by an issue registry. Since in the IDE we're enforcing the enabled-state via
// inspection profiles, mark the issue as enabled to allow users to turn on a lint check directly
// via the inspections UI.
issue.setEnabledByDefault(true);
}
result.add(issue);
}
return result;
}
use of com.intellij.codeInsight.daemon.HighlightDisplayKey in project android by JetBrains.
the class ResourceTypeInspection method getSuppressActions.
@NotNull
@Override
public SuppressIntentionAction[] getSuppressActions(final PsiElement element) {
// The suppress actions are hardcoded to use the suppress id "ResourceType",
// e.g. the inspection id for the whole ResourceTypeInspection.
// However, we'd really like to have more specific resource id's instead;
// in particular, the same ones used by the command line version of the same
// check in lint (in SupportAnnotationDetector).
//
// We can't change the id used by the SuppressQuickFix, and we can't just
// replace the SuppressQuickFix array passed to convertBatchToSuppressIntentionActions
// because the SuppressQuickFix interface ony gives us the element, not the
// warning error message (and we need to use the error message to figure out
// the corresponding lint issue type for an inspection message).
//
// Therefore, we wrap the each SuppressIntentionAction with a delegator,
// and when the user actually invokes the SuppressIntentionAction, we
// look up the current message, and if we can find the corresponding
// lint issue we create a new SuppressQuickFix (with the right id),
// wrap it, and invoke that action instead.
String shortName = getShortName();
HighlightDisplayKey key = HighlightDisplayKey.find(shortName);
SuppressQuickFix[] actions = SuppressManager.getInstance().createBatchSuppressActions(key);
SuppressIntentionAction[] suppressActions = SuppressIntentionActionFromFix.convertBatchToSuppressIntentionActions(actions);
if (suppressActions.length == actions.length) {
int index = 0;
List<SuppressIntentionAction> replaced = Lists.newArrayListWithExpectedSize(suppressActions.length);
for (SuppressIntentionAction action : suppressActions) {
replaced.add(new MyDelegatingSuppressAction(action, actions[index++]));
}
return replaced.toArray(new SuppressIntentionAction[replaced.size()]);
}
return suppressActions;
}
use of com.intellij.codeInsight.daemon.HighlightDisplayKey in project android by JetBrains.
the class AndroidLintUtil method getHighlighLevelAndInspection.
@Nullable
public static Pair<AndroidLintInspectionBase, HighlightDisplayLevel> getHighlighLevelAndInspection(@NotNull Project project, @NotNull Issue issue, @NotNull PsiElement context) {
final String inspectionShortName = AndroidLintInspectionBase.getInspectionShortNameByIssue(project, issue);
if (inspectionShortName == null) {
return null;
}
final HighlightDisplayKey key = HighlightDisplayKey.find(inspectionShortName);
if (key == null) {
return null;
}
final InspectionProfile profile = InspectionProjectProfileManager.getInstance(context.getProject()).getCurrentProfile();
if (!profile.isToolEnabled(key, context)) {
if (!issue.isEnabledByDefault()) {
// Lint will skip issues (and not report them) for issues that have been disabled,
// except for those issues that are explicitly enabled via Gradle. Therefore, if
// we get this far, lint has found this issue to be explicitly enabled, so we let
// that setting override a local enabled/disabled state in the IDE profile.
} else {
return null;
}
}
final AndroidLintInspectionBase inspection = (AndroidLintInspectionBase) profile.getUnwrappedTool(inspectionShortName, context);
if (inspection == null)
return null;
final HighlightDisplayLevel errorLevel = profile.getErrorLevel(key, context);
return Pair.create(inspection, errorLevel != null ? errorLevel : HighlightDisplayLevel.WARNING);
}
use of com.intellij.codeInsight.daemon.HighlightDisplayKey in project android by JetBrains.
the class NlLintHighlightingPass method getAnnotations.
@NotNull
private static LintAnnotationsModel getAnnotations(@NotNull NlModel model, @NotNull ProgressIndicator progress) {
ApplicationManager.getApplication().assertReadAccessAllowed();
LintAnnotationsModel lintModel = new LintAnnotationsModel();
XmlFile xmlFile = model.getFile();
AndroidLintExternalAnnotator annotator = new AndroidLintExternalAnnotator();
State state = annotator.collectInformation(xmlFile);
if (state != null) {
state = annotator.doAnnotate(state);
}
if (state == null) {
return lintModel;
}
for (ProblemData problemData : state.getProblems()) {
if (progress.isCanceled()) {
break;
}
TextRange range = problemData.getTextRange();
final PsiElement startElement = xmlFile.findElementAt(range.getStartOffset());
final PsiElement endElement = xmlFile.findElementAt(range.getEndOffset());
if (startElement == null || endElement == null) {
continue;
}
NlComponent component = model.findViewByPsi(startElement);
if (component == null) {
continue;
}
Issue issue = problemData.getIssue();
Pair<AndroidLintInspectionBase, HighlightDisplayLevel> pair = AndroidLintUtil.getHighlighLevelAndInspection(xmlFile.getProject(), issue, xmlFile);
if (pair == null) {
continue;
}
AndroidLintInspectionBase inspection = pair.getFirst();
if (inspection == null) {
continue;
}
HighlightDisplayLevel level = pair.getSecond();
HighlightDisplayKey key = HighlightDisplayKey.find(inspection.getShortName());
if (key == null) {
continue;
}
lintModel.addIssue(component, issue, problemData.getMessage(), inspection, level, startElement, endElement);
}
return lintModel;
}
Aggregations