add kotlin specific key annotator
This commit is contained in:
parent
0618b4686f
commit
72beddda6e
@ -0,0 +1,38 @@
|
|||||||
|
package de.marhali.easyi18n.editor.kotlin;
|
||||||
|
|
||||||
|
import com.intellij.lang.annotation.AnnotationHolder;
|
||||||
|
import com.intellij.lang.annotation.HighlightSeverity;
|
||||||
|
import com.intellij.openapi.project.Project;
|
||||||
|
|
||||||
|
import de.marhali.easyi18n.model.LocalizedNode;
|
||||||
|
import de.marhali.easyi18n.service.DataStore;
|
||||||
|
import de.marhali.easyi18n.service.SettingsService;
|
||||||
|
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author marhali
|
||||||
|
*/
|
||||||
|
public class KeyAnnotator {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds annotations for i18n keys with content preview for preferred locale.
|
||||||
|
* @param key I18n key extracted by psi element
|
||||||
|
* @param project Project instance
|
||||||
|
* @param holder Annotation holder
|
||||||
|
*/
|
||||||
|
protected void annotate(@NotNull String key, @NotNull Project project, @NotNull AnnotationHolder holder) {
|
||||||
|
String previewLocale = SettingsService.getInstance(project).getState().getPreviewLocale();
|
||||||
|
LocalizedNode node = DataStore.getInstance(project).getTranslations().getNode(key);
|
||||||
|
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,30 @@
|
|||||||
|
package de.marhali.easyi18n.editor.kotlin;
|
||||||
|
|
||||||
|
import com.intellij.lang.annotation.AnnotationHolder;
|
||||||
|
import com.intellij.lang.annotation.Annotator;
|
||||||
|
import com.intellij.psi.PsiElement;
|
||||||
|
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.kotlin.psi.KtLiteralStringTemplateEntry;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Kotlin specific translation key annotator
|
||||||
|
* @author marhali
|
||||||
|
*/
|
||||||
|
public class KotlinKeyAnnotator extends KeyAnnotator implements Annotator {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void annotate(@NotNull PsiElement element, @NotNull AnnotationHolder holder) {
|
||||||
|
if(!(element instanceof KtLiteralStringTemplateEntry)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
String value = element.getText();
|
||||||
|
|
||||||
|
if(value == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
annotate(value, element.getProject(), holder);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,5 @@
|
|||||||
|
<idea-plugin>
|
||||||
|
<extensions defaultExtensionNs="com.intellij">
|
||||||
|
<annotator language="kotlin" implementationClass="de.marhali.easyi18n.editor.kotlin.KotlinKeyAnnotator" />
|
||||||
|
</extensions>
|
||||||
|
</idea-plugin>
|
Loading…
x
Reference in New Issue
Block a user