Extracted KotlinSignatureUtil.isAnnotationEditable method. Made it work in the case of internal internal annotation.

This commit is contained in:
Evgeny Gerashchenko
2012-09-14 15:11:48 +04:00
parent 0665ad409a
commit 812b9453d1
3 changed files with 18 additions and 9 deletions
@@ -38,9 +38,7 @@ public class DeleteSignatureAction extends AnAction {
public DeleteSignatureAction(@NotNull PsiMethod elementInEditor) { public DeleteSignatureAction(@NotNull PsiMethod elementInEditor) {
super("Delete"); super("Delete");
this.annotationOwner = getAnnotationOwner(elementInEditor); this.annotationOwner = getAnnotationOwner(elementInEditor);
boolean editable = ExternalAnnotationsManager.getInstance(annotationOwner.getProject()) getTemplatePresentation().setVisible(isAnnotationEditable(elementInEditor));
.isExternalAnnotationWritable(annotationOwner, KOTLIN_SIGNATURE_ANNOTATION);
getTemplatePresentation().setVisible(editable);
} }
@Override @Override
@@ -41,10 +41,8 @@ public class EditSignatureAction extends AnAction {
private final PsiMethod elementInEditor; private final PsiMethod elementInEditor;
public EditSignatureAction(@NotNull PsiMethod elementInEditor) { public EditSignatureAction(@NotNull PsiMethod elementInEditor) {
super(isAnnotationEditable(elementInEditor) ? "Edit" : "View");
this.elementInEditor = elementInEditor; this.elementInEditor = elementInEditor;
boolean editable = ExternalAnnotationsManager.getInstance(elementInEditor.getProject())
.isExternalAnnotationWritable(getAnnotationOwner(elementInEditor), KOTLIN_SIGNATURE_ANNOTATION);
getTemplatePresentation().setText(editable ? "Edit" : "View");
} }
@Override @Override
@@ -83,9 +81,9 @@ public class EditSignatureAction extends AnAction {
} }
else { else {
PsiMethod annotationOwner = getAnnotationOwner(elementInEditor); PsiMethod annotationOwner = getAnnotationOwner(elementInEditor);
boolean editable = ExternalAnnotationsManager.getInstance(elementInEditor.getProject()) boolean editable = isAnnotationEditable(elementInEditor);
.isExternalAnnotationWritable(annotationOwner, KOTLIN_SIGNATURE_ANNOTATION); EditSignatureBalloon balloon = new EditSignatureBalloon(annotationOwner, getKotlinSignature(annotation), editable);
new EditSignatureBalloon(annotationOwner, getKotlinSignature(annotation), editable).show(point, editor, elementInEditor); balloon.show(point, editor, elementInEditor);
} }
} }
} }
@@ -16,6 +16,7 @@
package org.jetbrains.jet.plugin.codeInsight.ktSignature; package org.jetbrains.jet.plugin.codeInsight.ktSignature;
import com.intellij.codeInsight.ExternalAnnotationsManager;
import com.intellij.codeInsight.daemon.DaemonCodeAnalyzer; import com.intellij.codeInsight.daemon.DaemonCodeAnalyzer;
import com.intellij.lang.ASTNode; import com.intellij.lang.ASTNode;
import com.intellij.openapi.project.Project; import com.intellij.openapi.project.Project;
@@ -92,4 +93,16 @@ class KotlinSignatureUtil {
static void refreshMarkers(@NotNull Project project) { static void refreshMarkers(@NotNull Project project) {
DaemonCodeAnalyzer.getInstance(project).restart(); DaemonCodeAnalyzer.getInstance(project).restart();
} }
static boolean isAnnotationEditable(@NotNull PsiMethod element) {
PsiMethod annotationOwner = getAnnotationOwner(element);
PsiAnnotation annotation = findKotlinSignatureAnnotation(element);
assert annotation != null;
if (annotation.getContainingFile() != annotationOwner.getContainingFile()) {
return annotation.isWritable();
} else {
ExternalAnnotationsManager annotationsManager = ExternalAnnotationsManager.getInstance(element.getProject());
return annotationsManager.isExternalAnnotationWritable(annotationOwner, KOTLIN_SIGNATURE_ANNOTATION);
}
}
} }