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) {
super("Delete");
this.annotationOwner = getAnnotationOwner(elementInEditor);
boolean editable = ExternalAnnotationsManager.getInstance(annotationOwner.getProject())
.isExternalAnnotationWritable(annotationOwner, KOTLIN_SIGNATURE_ANNOTATION);
getTemplatePresentation().setVisible(editable);
getTemplatePresentation().setVisible(isAnnotationEditable(elementInEditor));
}
@Override
@@ -41,10 +41,8 @@ public class EditSignatureAction extends AnAction {
private final PsiMethod elementInEditor;
public EditSignatureAction(@NotNull PsiMethod elementInEditor) {
super(isAnnotationEditable(elementInEditor) ? "Edit" : "View");
this.elementInEditor = elementInEditor;
boolean editable = ExternalAnnotationsManager.getInstance(elementInEditor.getProject())
.isExternalAnnotationWritable(getAnnotationOwner(elementInEditor), KOTLIN_SIGNATURE_ANNOTATION);
getTemplatePresentation().setText(editable ? "Edit" : "View");
}
@Override
@@ -83,9 +81,9 @@ public class EditSignatureAction extends AnAction {
}
else {
PsiMethod annotationOwner = getAnnotationOwner(elementInEditor);
boolean editable = ExternalAnnotationsManager.getInstance(elementInEditor.getProject())
.isExternalAnnotationWritable(annotationOwner, KOTLIN_SIGNATURE_ANNOTATION);
new EditSignatureBalloon(annotationOwner, getKotlinSignature(annotation), editable).show(point, editor, elementInEditor);
boolean editable = isAnnotationEditable(elementInEditor);
EditSignatureBalloon balloon = new EditSignatureBalloon(annotationOwner, getKotlinSignature(annotation), editable);
balloon.show(point, editor, elementInEditor);
}
}
}
@@ -16,6 +16,7 @@
package org.jetbrains.jet.plugin.codeInsight.ktSignature;
import com.intellij.codeInsight.ExternalAnnotationsManager;
import com.intellij.codeInsight.daemon.DaemonCodeAnalyzer;
import com.intellij.lang.ASTNode;
import com.intellij.openapi.project.Project;
@@ -92,4 +93,16 @@ class KotlinSignatureUtil {
static void refreshMarkers(@NotNull Project project) {
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);
}
}
}