Translate "Safe Delete" usage info classes to Kotlin
This commit is contained in:
+30
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* 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
|
||||
|
||||
[suppress("DIFFERENT_NAMES_FOR_THE_SAME_PARAMETER_IN_SUPERTYPES")]
|
||||
public class KotlinSafeDeleteOverrideAnnotation(
|
||||
element: PsiElement, referencedElement: PsiElement
|
||||
) : SafeDeleteUsageInfo(element, referencedElement), SafeDeleteCustomUsageInfo {
|
||||
public override fun performRefactoring() {
|
||||
getElement()?.let { element -> KotlinSafeDeleteProcessor.removeOverrideModifier(element) }
|
||||
}
|
||||
}
|
||||
-41
@@ -1,41 +0,0 @@
|
||||
/*
|
||||
* 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;
|
||||
import org.jetbrains.jet.lang.psi.JetPsiUtil;
|
||||
|
||||
public class KotlinSafeDeleteOverridingUsageInfo extends SafeDeleteUsageInfo implements SafeDeleteCustomUsageInfo {
|
||||
public KotlinSafeDeleteOverridingUsageInfo(PsiElement overridingElement, PsiElement superElement) {
|
||||
super(overridingElement, superElement);
|
||||
}
|
||||
|
||||
public PsiElement getOverridingElement() {
|
||||
return getElement();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void performRefactoring() throws IncorrectOperationException {
|
||||
PsiElement element = JetPsiUtil.ascendIfPropertyAccessor(getElement());
|
||||
if (element != null) {
|
||||
element.delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
+12
-15
@@ -14,23 +14,20 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.plugin.refactoring.safeDelete;
|
||||
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;
|
||||
import com.intellij.psi.PsiElement
|
||||
import com.intellij.refactoring.safeDelete.usageInfo.SafeDeleteCustomUsageInfo
|
||||
import com.intellij.refactoring.safeDelete.usageInfo.SafeDeleteUsageInfo
|
||||
import org.jetbrains.jet.lang.psi.JetPsiUtil
|
||||
|
||||
public class KotlinSafeDeleteOverrideAnnotation extends SafeDeleteUsageInfo implements SafeDeleteCustomUsageInfo {
|
||||
public KotlinSafeDeleteOverrideAnnotation(PsiElement element, PsiElement referencedElement) {
|
||||
super(element, referencedElement);
|
||||
}
|
||||
[suppress("DIFFERENT_NAMES_FOR_THE_SAME_PARAMETER_IN_SUPERTYPES")]
|
||||
public class KotlinSafeDeleteOverridingUsageInfo(
|
||||
overridingElement: PsiElement, superElement: PsiElement
|
||||
) : SafeDeleteUsageInfo(overridingElement, superElement), SafeDeleteCustomUsageInfo {
|
||||
public val overridingElement: PsiElement get() = getElement()!!
|
||||
|
||||
@Override
|
||||
public void performRefactoring() throws IncorrectOperationException {
|
||||
PsiElement element = getElement();
|
||||
if (element != null) {
|
||||
KotlinSafeDeleteProcessor.removeOverrideModifier(element);
|
||||
}
|
||||
public override fun performRefactoring(): Unit {
|
||||
JetPsiUtil.ascendIfPropertyAccessor(getElement())?.delete()
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -655,7 +655,7 @@ public class KotlinSafeDeleteProcessor extends JavaSafeDeleteProcessor {
|
||||
return result.toArray(new UsageInfo[result.size()]);
|
||||
}
|
||||
|
||||
static void removeOverrideModifier(@NotNull PsiElement element) {
|
||||
public static void removeOverrideModifier(@NotNull PsiElement element) {
|
||||
if (element instanceof JetNamedFunction || element instanceof JetProperty) {
|
||||
JetModifierList modifierList = ((JetModifierListOwner) element).getModifierList();
|
||||
if (modifierList == null) return;
|
||||
|
||||
-54
@@ -1,54 +0,0 @@
|
||||
/*
|
||||
* 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.refactoring.safeDelete.usageInfo.SafeDeleteReferenceSimpleDeleteUsageInfo;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||
import org.jetbrains.jet.plugin.project.AnalyzerFacadeWithCache;
|
||||
|
||||
public class SafeDeleteImportDirectiveUsageInfo extends SafeDeleteReferenceSimpleDeleteUsageInfo {
|
||||
public SafeDeleteImportDirectiveUsageInfo(@NotNull JetImportDirective importDirective, @NotNull JetDeclaration declaration) {
|
||||
super(importDirective, declaration, isSafeToDelete(declaration, importDirective));
|
||||
}
|
||||
|
||||
private static boolean isSafeToDelete(@NotNull JetDeclaration declaration, @NotNull JetImportDirective importDirective) {
|
||||
JetExpression importExpr = importDirective.getImportedReference();
|
||||
|
||||
JetReferenceExpression importReference = null;
|
||||
if (importExpr instanceof JetSimpleNameExpression) {
|
||||
importReference = (JetReferenceExpression) importExpr;
|
||||
}
|
||||
else if (importExpr instanceof JetDotQualifiedExpression) {
|
||||
JetExpression selector = ((JetDotQualifiedExpression) importExpr).getSelectorExpression();
|
||||
if (selector instanceof JetSimpleNameExpression) {
|
||||
importReference = (JetReferenceExpression) selector;
|
||||
}
|
||||
}
|
||||
if (importReference == null) return false;
|
||||
|
||||
BindingContext bindingContext =
|
||||
AnalyzerFacadeWithCache.analyzeFileWithCache((JetFile) declaration.getContainingFile()).getBindingContext();
|
||||
|
||||
DeclarationDescriptor referenceDescriptor = bindingContext.get(BindingContext.REFERENCE_TARGET, importReference);
|
||||
DeclarationDescriptor declarationDescriptor = bindingContext.get(BindingContext.DECLARATION_TO_DESCRIPTOR, declaration);
|
||||
|
||||
return referenceDescriptor == declarationDescriptor;
|
||||
}
|
||||
}
|
||||
+49
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* 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.refactoring.safeDelete.usageInfo.SafeDeleteReferenceSimpleDeleteUsageInfo
|
||||
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor
|
||||
import org.jetbrains.jet.lang.psi.*
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext
|
||||
import org.jetbrains.jet.plugin.project.AnalyzerFacadeWithCache
|
||||
|
||||
public class SafeDeleteImportDirectiveUsageInfo(
|
||||
importDirective: JetImportDirective, declaration: JetDeclaration
|
||||
) : SafeDeleteReferenceSimpleDeleteUsageInfo(importDirective, declaration, importDirective.isSafeToDelete(declaration))
|
||||
|
||||
fun JetImportDirective.isSafeToDelete(declaration: JetDeclaration): Boolean {
|
||||
val importExpr = getImportedReference()
|
||||
val importReference: JetReferenceExpression? = when (importExpr) {
|
||||
is JetSimpleNameExpression ->
|
||||
importExpr
|
||||
is JetDotQualifiedExpression ->
|
||||
importExpr.getSelectorExpression()?.let { selector ->
|
||||
if (selector is JetSimpleNameExpression) selector else null
|
||||
}
|
||||
else -> null
|
||||
}
|
||||
|
||||
if (importReference != null) {
|
||||
val bindingContext =
|
||||
AnalyzerFacadeWithCache.analyzeFileWithCache(declaration.getContainingFile() as JetFile).getBindingContext()
|
||||
val referenceDescriptor = bindingContext.get(BindingContext.REFERENCE_TARGET, importReference)
|
||||
val declarationDescriptor = bindingContext.get(BindingContext.DECLARATION_TO_DESCRIPTOR, declaration)
|
||||
return referenceDescriptor == declarationDescriptor
|
||||
}
|
||||
return false
|
||||
}
|
||||
-37
@@ -1,37 +0,0 @@
|
||||
/*
|
||||
* 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.SafeDeleteReferenceSimpleDeleteUsageInfo;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
|
||||
public class SafeDeleteTypeArgumentListUsageInfo extends SafeDeleteReferenceSimpleDeleteUsageInfo {
|
||||
public SafeDeleteTypeArgumentListUsageInfo(@NotNull JetTypeProjection typeProjection, @NotNull JetTypeParameter parameter) {
|
||||
super(typeProjection, parameter, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteElement() throws IncorrectOperationException {
|
||||
PsiElement element = getElement();
|
||||
if (element != null) {
|
||||
KotlinSafeDeleteProcessor.deleteElementAndCleanParent(element);
|
||||
}
|
||||
}
|
||||
}
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* 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.SafeDeleteReferenceSimpleDeleteUsageInfo
|
||||
import com.intellij.util.IncorrectOperationException
|
||||
import org.jetbrains.jet.lang.psi.*
|
||||
|
||||
public class SafeDeleteTypeArgumentListUsageInfo(
|
||||
typeProjection: JetTypeProjection, parameter: JetTypeParameter
|
||||
) : SafeDeleteReferenceSimpleDeleteUsageInfo(typeProjection, parameter, true) {
|
||||
public override fun deleteElement() {
|
||||
getElement()?.let { element -> KotlinSafeDeleteProcessor.deleteElementAndCleanParent(element) }
|
||||
}
|
||||
}
|
||||
-39
@@ -1,39 +0,0 @@
|
||||
/*
|
||||
* 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.SafeDeleteReferenceSimpleDeleteUsageInfo;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.psi.JetParameter;
|
||||
import org.jetbrains.jet.lang.psi.JetPsiUtil;
|
||||
import org.jetbrains.jet.lang.psi.JetValueArgument;
|
||||
|
||||
public class SafeDeleteValueArgumentListUsageInfo extends SafeDeleteReferenceSimpleDeleteUsageInfo {
|
||||
public SafeDeleteValueArgumentListUsageInfo(@NotNull JetValueArgument valueArgument, @NotNull PsiElement parameter) {
|
||||
super(valueArgument, parameter, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteElement() throws IncorrectOperationException {
|
||||
PsiElement element = getElement();
|
||||
if (element != null) {
|
||||
JetPsiUtil.deleteElementWithDelimiters(element);
|
||||
}
|
||||
}
|
||||
}
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* 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.SafeDeleteReferenceSimpleDeleteUsageInfo
|
||||
import com.intellij.util.IncorrectOperationException
|
||||
import org.jetbrains.jet.lang.psi.JetParameter
|
||||
import org.jetbrains.jet.lang.psi.JetPsiUtil
|
||||
import org.jetbrains.jet.lang.psi.JetValueArgument
|
||||
|
||||
public class SafeDeleteValueArgumentListUsageInfo(
|
||||
valueArgument: JetValueArgument, parameter: PsiElement
|
||||
) : SafeDeleteReferenceSimpleDeleteUsageInfo(valueArgument, parameter, true) {
|
||||
public override fun deleteElement() {
|
||||
getElement()?.let { element -> JetPsiUtil.deleteElementWithDelimiters(element) }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user