-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
deprecated annotation moved to inspection
- Loading branch information
Showing
6 changed files
with
83 additions
and
82 deletions.
There are no files selected for viewing
63 changes: 0 additions & 63 deletions
63
...in/java/com/evolveum/midpoint/studio/impl/lang/annotation/DeprecatedElementAnnotator.java
This file was deleted.
Oops, something went wrong.
70 changes: 70 additions & 0 deletions
70
...n/java/com/evolveum/midpoint/studio/impl/lang/inspection/DeprecatedElementInspection.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters