Weaken parameter requirements
This commit is contained in:
+3
-3
@@ -23,7 +23,7 @@ import com.intellij.openapi.application.Result;
|
||||
import com.intellij.openapi.command.WriteCommandAction;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.PsiAnnotation;
|
||||
import com.intellij.psi.PsiMethod;
|
||||
import com.intellij.psi.PsiModifierListOwner;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import static org.jetbrains.jet.plugin.codeInsight.ktSignature.KotlinSignatureUtil.*;
|
||||
@@ -33,9 +33,9 @@ import static org.jetbrains.jet.plugin.codeInsight.ktSignature.KotlinSignatureUt
|
||||
* @since 5 Sep 12
|
||||
*/
|
||||
public class DeleteSignatureAction extends AnAction {
|
||||
private final PsiMethod annotationOwner;
|
||||
private final PsiModifierListOwner annotationOwner;
|
||||
|
||||
public DeleteSignatureAction(@NotNull PsiMethod elementInEditor) {
|
||||
public DeleteSignatureAction(@NotNull PsiModifierListOwner elementInEditor) {
|
||||
super("Delete");
|
||||
this.annotationOwner = getAnnotationOwner(elementInEditor);
|
||||
getTemplatePresentation().setVisible(isAnnotationEditable(elementInEditor));
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
|
||||
package org.jetbrains.jet.plugin.codeInsight.ktSignature;
|
||||
|
||||
import com.intellij.codeInsight.ExternalAnnotationsManager;
|
||||
import com.intellij.codeInsight.navigation.NavigationUtil;
|
||||
import com.intellij.openapi.actionSystem.AnAction;
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||
@@ -38,9 +37,9 @@ import static org.jetbrains.jet.plugin.codeInsight.ktSignature.KotlinSignatureUt
|
||||
* @since 5 Sep 12
|
||||
*/
|
||||
public class EditSignatureAction extends AnAction {
|
||||
private final PsiMethod elementInEditor;
|
||||
private final PsiModifierListOwner elementInEditor;
|
||||
|
||||
public EditSignatureAction(@NotNull PsiMethod elementInEditor) {
|
||||
public EditSignatureAction(@NotNull PsiModifierListOwner elementInEditor) {
|
||||
super(isAnnotationEditable(elementInEditor) ? "Edit" : "View");
|
||||
this.elementInEditor = elementInEditor;
|
||||
}
|
||||
@@ -56,7 +55,7 @@ public class EditSignatureAction extends AnAction {
|
||||
invokeEditSignature(elementInEditor, editor, point);
|
||||
}
|
||||
|
||||
static void invokeEditSignature(@NotNull PsiMethod elementInEditor, @NotNull Editor editor, @Nullable Point point) {
|
||||
static void invokeEditSignature(@NotNull PsiElement elementInEditor, @NotNull Editor editor, @Nullable Point point) {
|
||||
PsiAnnotation annotation = findKotlinSignatureAnnotation(elementInEditor);
|
||||
assert annotation != null;
|
||||
if (annotation.getContainingFile() == elementInEditor.getContainingFile()) {
|
||||
@@ -80,7 +79,7 @@ public class EditSignatureAction extends AnAction {
|
||||
}
|
||||
}
|
||||
else {
|
||||
PsiMethod annotationOwner = getAnnotationOwner(elementInEditor);
|
||||
PsiModifierListOwner annotationOwner = getAnnotationOwner(elementInEditor);
|
||||
boolean editable = isAnnotationEditable(elementInEditor);
|
||||
EditSignatureBalloon balloon = new EditSignatureBalloon(annotationOwner, getKotlinSignature(annotation), editable);
|
||||
balloon.show(point, editor, elementInEditor);
|
||||
|
||||
@@ -38,7 +38,7 @@ import com.intellij.openapi.wm.IdeFocusManager;
|
||||
import com.intellij.psi.PsiDocumentManager;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.PsiMethod;
|
||||
import com.intellij.psi.PsiModifierListOwner;
|
||||
import com.intellij.testFramework.LightVirtualFile;
|
||||
import com.intellij.ui.awt.RelativePoint;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -63,17 +63,17 @@ import static org.jetbrains.jet.plugin.codeInsight.ktSignature.KotlinSignatureUt
|
||||
*/
|
||||
class EditSignatureBalloon implements Disposable {
|
||||
private final Editor editor;
|
||||
private final PsiMethod method;
|
||||
private final PsiModifierListOwner annotatedElement;
|
||||
private final Project project;
|
||||
private final String previousSignature;
|
||||
private final MyPanel panel;
|
||||
private final Balloon balloon;
|
||||
private final boolean editable;
|
||||
|
||||
public EditSignatureBalloon(@NotNull PsiMethod method, @NotNull String previousSignature, boolean editable) {
|
||||
this.method = method;
|
||||
public EditSignatureBalloon(@NotNull PsiModifierListOwner annotatedElement, @NotNull String previousSignature, boolean editable) {
|
||||
this.annotatedElement = annotatedElement;
|
||||
this.editable = editable;
|
||||
project = method.getProject();
|
||||
project = annotatedElement.getProject();
|
||||
this.previousSignature = previousSignature;
|
||||
|
||||
editor = createEditor();
|
||||
@@ -183,7 +183,7 @@ class EditSignatureBalloon implements Disposable {
|
||||
@Override
|
||||
protected void run(Result result) throws Throwable {
|
||||
ExternalAnnotationsManager.getInstance(project).editExternalAnnotation(
|
||||
method, KOTLIN_SIGNATURE_ANNOTATION, signatureToNameValuePairs(project, newSignature));
|
||||
annotatedElement, KOTLIN_SIGNATURE_ANNOTATION, signatureToNameValuePairs(project, newSignature));
|
||||
}
|
||||
}.execute();
|
||||
}
|
||||
|
||||
+9
-9
@@ -22,14 +22,14 @@ import com.intellij.codeInsight.daemon.LineMarkerInfo;
|
||||
import com.intellij.codeInsight.daemon.LineMarkerProvider;
|
||||
import com.intellij.ide.DataManager;
|
||||
import com.intellij.ide.util.PropertiesComponent;
|
||||
import com.intellij.openapi.actionSystem.*;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.actionSystem.ActionGroup;
|
||||
import com.intellij.openapi.actionSystem.DefaultActionGroup;
|
||||
import com.intellij.openapi.editor.markup.GutterIconRenderer;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.psi.PsiAnnotation;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiMethod;
|
||||
import com.intellij.psi.PsiModifierListOwner;
|
||||
import com.intellij.util.Function;
|
||||
import com.intellij.util.ui.UIUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -62,9 +62,9 @@ public class KotlinSignatureInJavaMarkerProvider implements LineMarkerProvider {
|
||||
}
|
||||
};
|
||||
|
||||
private static final GutterIconNavigationHandler<PsiMethod> NAVIGATION_HANDLER = new GutterIconNavigationHandler<PsiMethod>() {
|
||||
private static final GutterIconNavigationHandler<PsiModifierListOwner> NAVIGATION_HANDLER = new GutterIconNavigationHandler<PsiModifierListOwner>() {
|
||||
@Override
|
||||
public void navigate(MouseEvent e, PsiMethod element) {
|
||||
public void navigate(MouseEvent e, PsiModifierListOwner element) {
|
||||
if (UIUtil.isActionClick(e, MouseEvent.MOUSE_RELEASED)) {
|
||||
new EditSignatureAction(element).actionPerformed(DataManager.getInstance().getDataContext(e.getComponent()), e.getPoint());
|
||||
}
|
||||
@@ -94,19 +94,19 @@ public class KotlinSignatureInJavaMarkerProvider implements LineMarkerProvider {
|
||||
refreshMarkers(project);
|
||||
}
|
||||
|
||||
private static class MyLineMarkerInfo extends LineMarkerInfo<PsiMethod> {
|
||||
private static class MyLineMarkerInfo extends LineMarkerInfo<PsiModifierListOwner> {
|
||||
public MyLineMarkerInfo(PsiElement element) {
|
||||
super((PsiMethod) element, element.getTextOffset(), JetIcons.SMALL_LOGO, Pass.UPDATE_ALL, TOOLTIP_PROVIDER, NAVIGATION_HANDLER);
|
||||
super((PsiModifierListOwner) element, element.getTextOffset(), JetIcons.SMALL_LOGO, Pass.UPDATE_ALL, TOOLTIP_PROVIDER, NAVIGATION_HANDLER);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public GutterIconRenderer createGutterRenderer() {
|
||||
return new LineMarkerGutterIconRenderer<PsiMethod>(this) {
|
||||
return new LineMarkerGutterIconRenderer<PsiModifierListOwner>(this) {
|
||||
@Nullable
|
||||
@Override
|
||||
public ActionGroup getPopupMenuActions() {
|
||||
PsiMethod element = getElement();
|
||||
PsiModifierListOwner element = getElement();
|
||||
assert element != null;
|
||||
|
||||
return new DefaultActionGroup(new EditSignatureAction(element), new DeleteSignatureAction(element));
|
||||
|
||||
@@ -40,10 +40,10 @@ class KotlinSignatureUtil {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
static PsiMethod getAnnotationOwner(@NotNull PsiElement element) {
|
||||
PsiMethod annotationOwner = element.getOriginalElement() instanceof PsiMethod
|
||||
? (PsiMethod) element.getOriginalElement()
|
||||
: (PsiMethod) element;
|
||||
static PsiModifierListOwner getAnnotationOwner(@NotNull PsiElement element) {
|
||||
PsiModifierListOwner annotationOwner = element.getOriginalElement() instanceof PsiModifierListOwner
|
||||
? (PsiModifierListOwner) element.getOriginalElement()
|
||||
: (PsiModifierListOwner) element;
|
||||
if (!annotationOwner.isPhysical()) {
|
||||
// this is fake PsiFile which is mirror for ClsFile without sources
|
||||
ASTNode node = SourceTreeToPsiMap.psiElementToTree(element);
|
||||
@@ -82,8 +82,8 @@ class KotlinSignatureUtil {
|
||||
|
||||
@Nullable
|
||||
static PsiAnnotation findKotlinSignatureAnnotation(@NotNull PsiElement element) {
|
||||
if (!(element instanceof PsiMethod)) return null;
|
||||
PsiMethod annotationOwner = getAnnotationOwner(element);
|
||||
if (!(element instanceof PsiModifierListOwner)) return null;
|
||||
PsiModifierListOwner annotationOwner = getAnnotationOwner(element);
|
||||
PsiAnnotation annotation = JavaDescriptorResolver.findAnnotation(annotationOwner, KOTLIN_SIGNATURE_ANNOTATION);
|
||||
if (annotation == null) return null;
|
||||
if (annotation.getParameterList().getAttributes().length == 0) return null;
|
||||
@@ -94,8 +94,8 @@ class KotlinSignatureUtil {
|
||||
DaemonCodeAnalyzer.getInstance(project).restart();
|
||||
}
|
||||
|
||||
static boolean isAnnotationEditable(@NotNull PsiMethod element) {
|
||||
PsiMethod annotationOwner = getAnnotationOwner(element);
|
||||
static boolean isAnnotationEditable(@NotNull PsiElement element) {
|
||||
PsiModifierListOwner annotationOwner = getAnnotationOwner(element);
|
||||
PsiAnnotation annotation = findKotlinSignatureAnnotation(element);
|
||||
assert annotation != null;
|
||||
if (annotation.getContainingFile() != annotationOwner.getContainingFile()) {
|
||||
|
||||
Reference in New Issue
Block a user