Skip to content

Commit

Permalink
deprecated annotation moved to inspection
Browse files Browse the repository at this point in the history
  • Loading branch information
1azyman committed Apr 16, 2024
1 parent 48520b7 commit 30706b5
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 82 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package com.evolveum.midpoint.studio.impl.lang.inspection;

import com.evolveum.midpoint.prism.PrismConstants;
import com.evolveum.midpoint.studio.util.PsiUtils;
import com.intellij.codeInspection.LocalInspectionTool;
import com.intellij.codeInspection.ProblemHighlightType;
import com.intellij.codeInspection.ProblemsHolder;
import com.intellij.lang.annotation.AnnotationHolder;
import com.intellij.lang.annotation.HighlightSeverity;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiElementVisitor;
import com.intellij.psi.xml.XmlElement;
import com.intellij.psi.xml.XmlTag;
import org.jetbrains.annotations.NotNull;

/**
* Created by Viliam Repan (lazyman).
*/
public class DeprecatedElementInspection extends LocalInspectionTool implements InspectionMixin {

@Override
public @NotNull PsiElementVisitor buildVisitor(@NotNull ProblemsHolder holder, boolean isOnTheFly) {
return new PsiElementVisitor() {

@Override
public void visitElement(@NotNull PsiElement element) {
super.visitElement(element);

if (!PsiUtils.isXmlElement(element)) {
return;
}

XmlElement xmlElement = (XmlElement) element;
XmlTag xsd = PsiUtils.getXsdReference(xmlElement);
if (xsd == null) {
return;
}

XmlTag deprecatedTag = PsiUtils.getAppinfoElement(xsd, PrismConstants.A_DEPRECATED);
XmlTag deprecatedSinceTag = PsiUtils.getAppinfoElement(xsd, PrismConstants.A_DEPRECATED_SINCE);

String deprecated = deprecatedTag != null ? deprecatedTag.getValue().getText() : null;
String deprecatedSince = deprecatedSinceTag != null ? deprecatedSinceTag.getValue().getText() : null;
if (deprecatedSince == null) {
deprecatedSince = "unknown";
}

if (!Boolean.valueOf(deprecated)) {
return;
}

String msg = "Element marked as deprecated (since <b>" + deprecatedSince + "</b>)";

if (xmlElement instanceof XmlTag tag) {
registerTagProblems(tag, holder, ProblemHighlightType.LIKE_DEPRECATED, msg);
} else {
registerTokenProblem(xmlElement, holder, ProblemHighlightType.LIKE_DEPRECATED, msg);
}
}
};
}

private void createNewAnnotation(XmlElement element, AnnotationHolder holder, String msg, String tooltip) {
holder.newAnnotation(HighlightSeverity.WARNING, msg)
.range(element.getTextRange())
.tooltip(tooltip)
.highlightType(ProblemHighlightType.LIKE_DEPRECATED)
.create();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,26 @@

import com.intellij.codeInspection.ProblemHighlightType;
import com.intellij.codeInspection.ProblemsHolder;
import com.intellij.psi.xml.XmlElement;
import com.intellij.psi.xml.XmlTag;
import com.intellij.psi.xml.XmlToken;
import com.intellij.xml.util.XmlTagUtil;

public interface InspectionMixin {

default void registerTagProblems(
XmlTag tag, ProblemsHolder holder, ProblemHighlightType highlightType, String msg) {
registerTagProblems(tag, holder, highlightType, msg, null);
}

default void registerTagProblems(
XmlTag tag, ProblemsHolder holder, ProblemHighlightType highlightType, String msg, String tooltip) {

registerNewProblem(XmlTagUtil.getStartTagNameElement(tag), holder, highlightType, msg, tooltip);
registerNewProblem(XmlTagUtil.getEndTagNameElement(tag), holder, highlightType, msg, tooltip);
registerTokenProblem(XmlTagUtil.getStartTagNameElement(tag), holder, highlightType, msg);
registerTokenProblem(XmlTagUtil.getEndTagNameElement(tag), holder, highlightType, msg);
}

default void registerNewProblem(
XmlToken token, ProblemsHolder holder, ProblemHighlightType highlightType, String msg, String tooltip) {
default void registerTokenProblem(
XmlElement token, ProblemsHolder holder, ProblemHighlightType highlightType, String msg) {

if (token == null) {
return;
}

if (tooltip == null) {
tooltip = msg;
}

holder.registerProblem(token, msg, highlightType);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import com.intellij.codeInspection.LocalInspectionTool;
import com.intellij.codeInspection.ProblemHighlightType;
import com.intellij.codeInspection.ProblemsHolder;
import com.intellij.openapi.progress.ProgressIndicatorProvider;
import com.intellij.openapi.project.Project;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiElementVisitor;
Expand All @@ -29,7 +28,7 @@ public class MissingNaturalKeyInspection extends LocalInspectionTool implements
return new PsiElementVisitor() {
@Override
public void visitElement(@NotNull PsiElement element) {
ProgressIndicatorProvider.checkCanceled();
super.visitElement(element);

Project project = element.getProject();
if (!MidPointUtils.hasMidPointFacet(project)) {
Expand Down
7 changes: 5 additions & 2 deletions studio-idea-plugin/src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -220,8 +220,6 @@
implementationClass="com.evolveum.midpoint.studio.impl.lang.annotation.RefOidAnnotator"/>
<annotator language="XML"
implementationClass="com.evolveum.midpoint.studio.impl.lang.annotation.ResourceTypeAnnotator"/>
<annotator language="XML"
implementationClass="com.evolveum.midpoint.studio.impl.lang.annotation.DeprecatedElementAnnotator"/>
<annotator language="XML"
implementationClass="com.evolveum.midpoint.studio.impl.lang.codeInsight.TaskHandlerAnnotatorCompletionProvider"/>
<annotator language="XML"
Expand Down Expand Up @@ -266,6 +264,11 @@
groupKey="MidpointInspectionGroup.title"
key="MissingNaturalKeyInspection.title"
implementationClass="com.evolveum.midpoint.studio.impl.lang.inspection.MissingNaturalKeyInspection"/>
<localInspection language="XML"
groupBundle="messages.MidPointStudio"
groupKey="MidpointInspectionGroup.title"
key="DeprecatedElementInspection.title"
implementationClass="com.evolveum.midpoint.studio.impl.lang.inspection.DeprecatedElementInspection"/>

<intentionAction>
<className>com.evolveum.midpoint.studio.impl.lang.intention.DownloadObjectIntention</className>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,5 @@ MissingRefAction.null=Undefined
MissingRefColumn.all=All
MissingRefColumn.root=Root
MidpointInspectionGroup.title=MidPoint
MissingNaturalKeyInspection.title=Missing natural key
MissingNaturalKeyInspection.title=Missing natural key
DeprecatedElementInspection.title=Deprecated element

0 comments on commit 30706b5

Please sign in to comment.