Skip to content

Commit

Permalink
ReplaceShadowRef annotation implemented
Browse files Browse the repository at this point in the history
  • Loading branch information
1azyman committed Mar 4, 2024
1 parent b22d729 commit 6aada06
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package com.evolveum.midpoint.studio.impl.lang.intention;

import com.evolveum.midpoint.schema.SchemaConstantsGenerated;
import com.evolveum.midpoint.schema.constants.SchemaConstants;
import com.evolveum.midpoint.studio.client.MidPointObject;
import com.evolveum.midpoint.studio.impl.Environment;
import com.evolveum.midpoint.studio.impl.EnvironmentService;
import com.evolveum.midpoint.studio.impl.MidPointClient;
import com.evolveum.midpoint.studio.impl.SearchOptions;
import com.evolveum.midpoint.studio.impl.lang.annotation.ShadowRefAnnotator;
import com.evolveum.midpoint.studio.impl.psi.search.ObjectFileBasedIndexImpl;
import com.evolveum.midpoint.studio.impl.psi.search.OidNameValue;
import com.evolveum.midpoint.studio.util.MidPointUtils;
Expand All @@ -16,6 +16,9 @@
import com.evolveum.prism.xml.ns._public.query_3.SearchFilterType;
import com.intellij.codeInsight.intention.PsiElementBaseIntentionAction;
import com.intellij.codeInspection.util.IntentionFamilyName;
import com.intellij.lang.annotation.AnnotationHolder;
import com.intellij.lang.annotation.Annotator;
import com.intellij.lang.annotation.HighlightSeverity;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.command.WriteCommandAction;
import com.intellij.openapi.editor.Editor;
Expand All @@ -34,13 +37,16 @@
import java.util.List;
import java.util.Objects;

public class ReplaceShadowRefIntention extends PsiElementBaseIntentionAction {
public class ReplaceShadowRefAnnotatorIntention extends PsiElementBaseIntentionAction implements Annotator {

private static final String NAME = "Replace shadowRef";

public static final QName SHADOW_REF = new QName(SchemaConstants.NS_C, "shadowRef");

private static final String UNKNOWN_SHADOW_NAME = "Unknown";

public ReplaceShadowRefIntention() {

public ReplaceShadowRefAnnotatorIntention() {
setText(NAME);
}

Expand Down Expand Up @@ -166,7 +172,7 @@ private XmlTag getShadowRefTag(PsiElement element) {
return null;
}

if (!Objects.equals(ShadowRefAnnotator.SHADOW_REF, MidPointUtils.createQName(tag))) {
if (!Objects.equals(SHADOW_REF, MidPointUtils.createQName(tag))) {
return null;
}

Expand All @@ -183,4 +189,25 @@ private XmlTag getValueExpressionTag(PsiElement element) {

return Objects.equals(SchemaConstantsGenerated.C_VALUE, MidPointUtils.createQName(parent)) ? parent : null;
}

@Override
public void annotate(@NotNull PsiElement element, @NotNull AnnotationHolder holder) {
XmlTag shadowRef = getShadowRefTag(element);
if (shadowRef == null) {
return;
}

if (getValueExpressionTag(element) == null) {
return;
}

String msg = "shadowRef element could represent possible problem when moving this midPoint " +
"object to another environment. Reason is reference to specific oid which would " +
"be different in another environment.";

holder.newAnnotation(HighlightSeverity.WARNING, msg)
.range(element.getTextRange())
.tooltip(msg)
.create();
}
}
6 changes: 4 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 @@ -221,6 +221,8 @@
implementationClass="com.evolveum.midpoint.studio.impl.lang.annotation.DeprecatedElementAnnotator"/>
<annotator language="XML"
implementationClass="com.evolveum.midpoint.studio.impl.lang.codeInsight.TaskHandlerAnnotatorCompletionProvider"/>
<annotator language="XML"
implementationClass="com.evolveum.midpoint.studio.impl.lang.intention.ReplaceShadowRefAnnotatorIntention"/>

<completion.contributor language="XML"
implementationClass="com.evolveum.midpoint.studio.impl.lang.codeInsight.MidPointCompletionContributor"/>
Expand Down Expand Up @@ -264,11 +266,11 @@
<skipBeforeAfter>true</skipBeforeAfter>
</intentionAction>
<intentionAction>
<className>com.evolveum.midpoint.studio.impl.lang.intention.ReplaceShadowRefIntention</className>
<className>com.evolveum.midpoint.studio.impl.lang.intention.ReplaceShadowRefAnnotatorIntention</className>
<language>XML</language>
<bundleName>messages.MidPointStudio</bundleName>
<categoryKey>MidpointIntentionActionGroup.title</categoryKey>
<descriptionDirectoryName>ReplaceShadowRefIntention</descriptionDirectoryName>
<descriptionDirectoryName>ReplaceShadowRefAnnotatorIntention</descriptionDirectoryName>
<skipBeforeAfter>false</skipBeforeAfter>
</intentionAction>
</extensions>
Expand Down

0 comments on commit 6aada06

Please sign in to comment.