use new unified method to create annotations
This commit is contained in:
parent
72beddda6e
commit
151b324564
@ -1,49 +0,0 @@
|
||||
package de.marhali.easyi18n.editor;
|
||||
|
||||
import com.intellij.lang.annotation.AnnotationHolder;
|
||||
import com.intellij.lang.annotation.Annotator;
|
||||
import com.intellij.lang.annotation.HighlightSeverity;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiLiteralValue;
|
||||
|
||||
import de.marhali.easyi18n.model.LocalizedNode;
|
||||
import de.marhali.easyi18n.service.DataStore;
|
||||
import de.marhali.easyi18n.service.SettingsService;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* Translation key annotator.
|
||||
* @author marhali
|
||||
*/
|
||||
public class I18nKeyAnnotator implements Annotator {
|
||||
|
||||
@Override
|
||||
public void annotate(@NotNull PsiElement element, @NotNull AnnotationHolder holder) {
|
||||
if(!(element instanceof PsiLiteralValue)) {
|
||||
return;
|
||||
}
|
||||
|
||||
PsiLiteralValue literalValue = (PsiLiteralValue) element;
|
||||
String value = literalValue.getValue() instanceof String ? (String) literalValue.getValue() : null;
|
||||
|
||||
if(value == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
Project project = element.getProject();
|
||||
String previewLocale = SettingsService.getInstance(project).getState().getPreviewLocale();
|
||||
|
||||
LocalizedNode node = DataStore.getInstance(project).getTranslations().getNode(value);
|
||||
|
||||
if(node == null) { // Unknown translation. Just ignore it
|
||||
return;
|
||||
}
|
||||
|
||||
String tooltip = node.isLeaf() ? "I18n(" + previewLocale + ": " + node.getValue().get(previewLocale) + ")"
|
||||
: "I18n ([])";
|
||||
|
||||
holder.newAnnotation(HighlightSeverity.INFORMATION, tooltip).create();
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package de.marhali.easyi18n.editor.kotlin;
|
||||
package de.marhali.easyi18n.editor;
|
||||
|
||||
import com.intellij.lang.annotation.AnnotationHolder;
|
||||
import com.intellij.lang.annotation.HighlightSeverity;
|
@ -0,0 +1,33 @@
|
||||
package de.marhali.easyi18n.editor.generic;
|
||||
|
||||
import com.intellij.lang.annotation.AnnotationHolder;
|
||||
import com.intellij.lang.annotation.Annotator;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiLiteralValue;
|
||||
|
||||
import de.marhali.easyi18n.editor.KeyAnnotator;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* Translation key annotator.
|
||||
* @author marhali
|
||||
*/
|
||||
public class GenericKeyAnnotator extends KeyAnnotator implements Annotator {
|
||||
|
||||
@Override
|
||||
public void annotate(@NotNull PsiElement element, @NotNull AnnotationHolder holder) {
|
||||
if(!(element instanceof PsiLiteralValue)) {
|
||||
return;
|
||||
}
|
||||
|
||||
PsiLiteralValue literalValue = (PsiLiteralValue) element;
|
||||
String value = literalValue.getValue() instanceof String ? (String) literalValue.getValue() : null;
|
||||
|
||||
if(value == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
annotate(value, element.getProject(), holder);
|
||||
}
|
||||
}
|
@ -4,6 +4,7 @@ import com.intellij.lang.annotation.AnnotationHolder;
|
||||
import com.intellij.lang.annotation.Annotator;
|
||||
import com.intellij.psi.PsiElement;
|
||||
|
||||
import de.marhali.easyi18n.editor.KeyAnnotator;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.kotlin.psi.KtLiteralStringTemplateEntry;
|
||||
|
||||
|
@ -16,6 +16,6 @@
|
||||
<completion.contributor language="any"
|
||||
implementationClass="de.marhali.easyi18n.editor.I18nCompletionContributor" />
|
||||
|
||||
<annotator language="" implementationClass="de.marhali.easyi18n.editor.I18nKeyAnnotator" />
|
||||
<annotator language="" implementationClass="de.marhali.easyi18n.editor.generic.GenericKeyAnnotator" />
|
||||
</extensions>
|
||||
</idea-plugin>
|
Loading…
x
Reference in New Issue
Block a user