use of com.intellij.codeHighlighting.HighlightDisplayLevel in project intellij-community by JetBrains.
the class ToolsImpl method readExternal.
void readExternal(@NotNull Element toolElement, @NotNull InspectionProfileManager profileManager, Map<String, List<String>> dependencies) {
final String levelName = toolElement.getAttributeValue(LEVEL_ATTRIBUTE);
final SeverityRegistrar registrar = profileManager.getOwnSeverityRegistrar();
HighlightDisplayLevel level = levelName != null ? HighlightDisplayLevel.find(registrar.getSeverity(levelName)) : null;
if (level == null) {
level = HighlightDisplayLevel.WARNING;
}
myDefaultState.setLevel(level);
final String enabled = toolElement.getAttributeValue(ENABLED_ATTRIBUTE);
final boolean isEnabled = enabled != null && Boolean.parseBoolean(enabled);
final String enabledTool = toolElement.getAttributeValue(ENABLED_BY_DEFAULT_ATTRIBUTE);
myDefaultState.setEnabled(enabledTool != null ? Boolean.parseBoolean(enabledTool) : isEnabled);
final InspectionToolWrapper toolWrapper = myDefaultState.getTool();
final List<Element> scopeElements = toolElement.getChildren(ProfileEx.SCOPE);
if (!scopeElements.isEmpty()) {
final List<String> scopeNames = new SmartList<>();
for (Element scopeElement : scopeElements) {
final String scopeName = scopeElement.getAttributeValue(ProfileEx.NAME);
if (scopeName == null) {
continue;
}
final NamedScopesHolder scopesHolder = profileManager.getScopesManager();
NamedScope namedScope = null;
if (scopesHolder != null) {
namedScope = scopesHolder.getScope(scopeName);
}
final String errorLevel = scopeElement.getAttributeValue(LEVEL_ATTRIBUTE);
final String enabledInScope = scopeElement.getAttributeValue(ENABLED_ATTRIBUTE);
final InspectionToolWrapper copyToolWrapper = toolWrapper.createCopy();
// check if unknown children exists
if (scopeElement.getAttributes().size() > 3 || !scopeElement.getChildren().isEmpty()) {
copyToolWrapper.getTool().readSettings(scopeElement);
}
HighlightDisplayLevel scopeLevel = errorLevel != null ? HighlightDisplayLevel.find(registrar.getSeverity(errorLevel)) : null;
if (scopeLevel == null) {
scopeLevel = level;
}
if (namedScope != null) {
addTool(namedScope, copyToolWrapper, enabledInScope != null && Boolean.parseBoolean(enabledInScope), scopeLevel);
} else {
addTool(scopeName, copyToolWrapper, enabledInScope != null && Boolean.parseBoolean(enabledInScope), scopeLevel);
}
scopeNames.add(scopeName);
}
for (int i = 0; i < scopeNames.size(); i++) {
String scopeName = scopeNames.get(i);
List<String> order = dependencies.get(scopeName);
if (order == null) {
order = new ArrayList<>();
dependencies.put(scopeName, order);
}
for (int j = i + 1; j < scopeNames.size(); j++) {
order.add(scopeNames.get(j));
}
}
}
// check if unknown children exists
if (toolElement.getAttributes().size() > 4 || toolElement.getChildren().size() > scopeElements.size()) {
toolWrapper.getTool().readSettings(toolElement);
}
myEnabled = isEnabled;
}
use of com.intellij.codeHighlighting.HighlightDisplayLevel in project kotlin by JetBrains.
the class AndroidLintExternalAnnotator method apply.
@Override
public void apply(@NotNull PsiFile file, State state, @NotNull AnnotationHolder holder) {
if (state.isDirty()) {
return;
}
final Project project = file.getProject();
for (ProblemData problemData : state.getProblems()) {
final Issue issue = problemData.getIssue();
final String message = problemData.getMessage();
final TextRange range = problemData.getTextRange();
if (range.getStartOffset() == range.getEndOffset()) {
continue;
}
final Pair<AndroidLintInspectionBase, HighlightDisplayLevel> pair = AndroidLintUtil.getHighlighLevelAndInspection(project, issue, file);
if (pair == null) {
continue;
}
final AndroidLintInspectionBase inspection = pair.getFirst();
HighlightDisplayLevel displayLevel = pair.getSecond();
if (inspection != null) {
final HighlightDisplayKey key = HighlightDisplayKey.find(inspection.getShortName());
if (key != null) {
final PsiElement startElement = file.findElementAt(range.getStartOffset());
final PsiElement endElement = file.findElementAt(range.getEndOffset() - 1);
if (startElement != null && endElement != null && !inspection.isSuppressedFor(startElement)) {
if (problemData.getConfiguredSeverity() != null) {
HighlightDisplayLevel configuredLevel = AndroidLintInspectionBase.toHighlightDisplayLevel(problemData.getConfiguredSeverity());
if (configuredLevel != null) {
displayLevel = configuredLevel;
}
}
final Annotation annotation = createAnnotation(holder, message, range, displayLevel, issue);
for (AndroidLintQuickFix fix : inspection.getQuickFixes(startElement, endElement, message)) {
if (fix.isApplicable(startElement, endElement, AndroidQuickfixContexts.EditorContext.TYPE)) {
annotation.registerFix(new MyFixingIntention(fix, startElement, endElement));
}
}
for (IntentionAction intention : inspection.getIntentions(startElement, endElement)) {
annotation.registerFix(intention);
}
String id = key.getID();
if (IntellijLintIssueRegistry.CUSTOM_ERROR == issue || IntellijLintIssueRegistry.CUSTOM_WARNING == issue) {
Issue original = IntellijLintClient.findCustomIssue(message);
if (original != null) {
id = original.getId();
}
}
annotation.registerFix(new SuppressLintIntentionAction(id, startElement));
annotation.registerFix(new MyDisableInspectionFix(key));
annotation.registerFix(new MyEditInspectionToolsSettingsAction(key, inspection));
if (INCLUDE_IDEA_SUPPRESS_ACTIONS) {
final SuppressQuickFix[] suppressActions = inspection.getBatchSuppressActions(startElement);
for (SuppressQuickFix action : suppressActions) {
if (action.isAvailable(project, startElement)) {
ProblemHighlightType type = annotation.getHighlightType();
annotation.registerFix(action, null, key, InspectionManager.getInstance(project).createProblemDescriptor(startElement, endElement, message, type, true, LocalQuickFix.EMPTY_ARRAY));
}
}
}
}
}
}
}
}
use of com.intellij.codeHighlighting.HighlightDisplayLevel in project kotlin 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()).getInspectionProfile();
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.codeHighlighting.HighlightDisplayLevel in project intellij-community by JetBrains.
the class HtmlMissingClosingTagInspectionTest method highlightTest.
protected void highlightTest(@Language("HTML") String code) {
final LocalInspectionTool inspection = getInspection();
myFixture.enableInspections(inspection);
final HighlightDisplayKey displayKey = HighlightDisplayKey.find(inspection.getShortName());
final Project project = myFixture.getProject();
final InspectionProfileImpl currentProfile = ProjectInspectionProfileManager.getInstance(project).getCurrentProfile();
final HighlightDisplayLevel errorLevel = currentProfile.getErrorLevel(displayKey, null);
if (errorLevel == HighlightDisplayLevel.DO_NOT_SHOW) {
currentProfile.setErrorLevel(displayKey, HighlightDisplayLevel.WARNING, project);
}
myFixture.configureByText(HtmlFileType.INSTANCE, code);
myFixture.testHighlighting();
}
Aggregations