Work around the bug in Java "Safe Delete" (can't delete override annotations in Kotlin from Java code)
This commit is contained in:
+36
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Copyright 2010-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.plugin.refactoring.safeDelete;
|
||||
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.refactoring.safeDelete.usageInfo.SafeDeleteCustomUsageInfo;
|
||||
import com.intellij.refactoring.safeDelete.usageInfo.SafeDeleteUsageInfo;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
|
||||
public class KotlinSafeDeleteOverrideAnnotation extends SafeDeleteUsageInfo implements SafeDeleteCustomUsageInfo {
|
||||
public KotlinSafeDeleteOverrideAnnotation(PsiElement element, PsiElement referencedElement) {
|
||||
super(element, referencedElement);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void performRefactoring() throws IncorrectOperationException {
|
||||
PsiElement element = getElement();
|
||||
if (element != null) {
|
||||
KotlinSafeDeleteProcessor.removeOverrideModifier(element);
|
||||
}
|
||||
}
|
||||
}
|
||||
+9
-2
@@ -29,6 +29,7 @@ import com.intellij.psi.search.searches.ReferencesSearch;
|
||||
import com.intellij.psi.util.*;
|
||||
import com.intellij.refactoring.safeDelete.JavaSafeDeleteProcessor;
|
||||
import com.intellij.refactoring.safeDelete.NonCodeUsageSearchInfo;
|
||||
import com.intellij.refactoring.safeDelete.usageInfo.SafeDeleteOverrideAnnotation;
|
||||
import com.intellij.refactoring.safeDelete.usageInfo.SafeDeleteOverridingMethodUsageInfo;
|
||||
import com.intellij.refactoring.safeDelete.usageInfo.SafeDeleteReferenceSimpleDeleteUsageInfo;
|
||||
import com.intellij.usageView.UsageInfo;
|
||||
@@ -179,6 +180,12 @@ public class KotlinSafeDeleteProcessor extends JavaSafeDeleteProcessor {
|
||||
overrideUsageInfo.getSmartPointer().getElement(), overrideUsageInfo.getReferencedElement()
|
||||
);
|
||||
}
|
||||
else if (usageInfo instanceof SafeDeleteOverrideAnnotation) {
|
||||
SafeDeleteOverrideAnnotation overrideAnnotationUsageInfo = (SafeDeleteOverrideAnnotation) usageInfo;
|
||||
usageInfo = new KotlinSafeDeleteOverrideAnnotation(
|
||||
overrideAnnotationUsageInfo.getSmartPointer().getElement(), overrideAnnotationUsageInfo.getReferencedElement()
|
||||
);
|
||||
}
|
||||
result.add(usageInfo);
|
||||
}
|
||||
|
||||
@@ -501,7 +508,7 @@ public class KotlinSafeDeleteProcessor extends JavaSafeDeleteProcessor {
|
||||
return result.toArray(new UsageInfo[result.size()]);
|
||||
}
|
||||
|
||||
private static void removeOverrideModifier(@NotNull PsiElement element) {
|
||||
static void removeOverrideModifier(@NotNull PsiElement element) {
|
||||
if (element instanceof JetNamedFunction || element instanceof JetProperty) {
|
||||
JetModifierList modifierList = ((JetModifierListOwner) element).getModifierList();
|
||||
if (modifierList == null) return;
|
||||
@@ -563,7 +570,7 @@ public class KotlinSafeDeleteProcessor extends JavaSafeDeleteProcessor {
|
||||
return method1.equals(method2);
|
||||
}
|
||||
|
||||
private static void cleanUpOverrides(PsiMethod method) {
|
||||
public static void cleanUpOverrides(PsiMethod method) {
|
||||
Collection<PsiMethod> superMethods = Arrays.asList(method.findSuperMethods(true));
|
||||
Collection<PsiMethod> overridingMethods = OverridingMethodsSearch.search(method, true).findAll();
|
||||
overrideLoop:
|
||||
|
||||
Reference in New Issue
Block a user