diff --git a/idea/src/org/jetbrains/jet/plugin/refactoring/safeDelete/KotlinSafeDeleteOverrideAnnotation.kt b/idea/src/org/jetbrains/jet/plugin/refactoring/safeDelete/KotlinSafeDeleteOverrideAnnotation.kt new file mode 100644 index 00000000000..79f465cc30b --- /dev/null +++ b/idea/src/org/jetbrains/jet/plugin/refactoring/safeDelete/KotlinSafeDeleteOverrideAnnotation.kt @@ -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) } + } +} diff --git a/idea/src/org/jetbrains/jet/plugin/refactoring/safeDelete/KotlinSafeDeleteOverridingUsageInfo.java b/idea/src/org/jetbrains/jet/plugin/refactoring/safeDelete/KotlinSafeDeleteOverridingUsageInfo.java deleted file mode 100644 index a1d60b4b4cc..00000000000 --- a/idea/src/org/jetbrains/jet/plugin/refactoring/safeDelete/KotlinSafeDeleteOverridingUsageInfo.java +++ /dev/null @@ -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(); - } - } -} diff --git a/idea/src/org/jetbrains/jet/plugin/refactoring/safeDelete/KotlinSafeDeleteOverrideAnnotation.java b/idea/src/org/jetbrains/jet/plugin/refactoring/safeDelete/KotlinSafeDeleteOverridingUsageInfo.kt similarity index 52% rename from idea/src/org/jetbrains/jet/plugin/refactoring/safeDelete/KotlinSafeDeleteOverrideAnnotation.java rename to idea/src/org/jetbrains/jet/plugin/refactoring/safeDelete/KotlinSafeDeleteOverridingUsageInfo.kt index 5fdbf32fca4..0ced9f24fc1 100644 --- a/idea/src/org/jetbrains/jet/plugin/refactoring/safeDelete/KotlinSafeDeleteOverrideAnnotation.java +++ b/idea/src/org/jetbrains/jet/plugin/refactoring/safeDelete/KotlinSafeDeleteOverridingUsageInfo.kt @@ -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() } } diff --git a/idea/src/org/jetbrains/jet/plugin/refactoring/safeDelete/KotlinSafeDeleteProcessor.java b/idea/src/org/jetbrains/jet/plugin/refactoring/safeDelete/KotlinSafeDeleteProcessor.java index ae1242ccd0b..a2cc05c2be2 100644 --- a/idea/src/org/jetbrains/jet/plugin/refactoring/safeDelete/KotlinSafeDeleteProcessor.java +++ b/idea/src/org/jetbrains/jet/plugin/refactoring/safeDelete/KotlinSafeDeleteProcessor.java @@ -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; diff --git a/idea/src/org/jetbrains/jet/plugin/refactoring/safeDelete/SafeDeleteImportDirectiveUsageInfo.java b/idea/src/org/jetbrains/jet/plugin/refactoring/safeDelete/SafeDeleteImportDirectiveUsageInfo.java deleted file mode 100644 index 99a28977330..00000000000 --- a/idea/src/org/jetbrains/jet/plugin/refactoring/safeDelete/SafeDeleteImportDirectiveUsageInfo.java +++ /dev/null @@ -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; - } -} diff --git a/idea/src/org/jetbrains/jet/plugin/refactoring/safeDelete/SafeDeleteImportDirectiveUsageInfo.kt b/idea/src/org/jetbrains/jet/plugin/refactoring/safeDelete/SafeDeleteImportDirectiveUsageInfo.kt new file mode 100644 index 00000000000..01e297dfc46 --- /dev/null +++ b/idea/src/org/jetbrains/jet/plugin/refactoring/safeDelete/SafeDeleteImportDirectiveUsageInfo.kt @@ -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 +} \ No newline at end of file diff --git a/idea/src/org/jetbrains/jet/plugin/refactoring/safeDelete/SafeDeleteTypeArgumentListUsageInfo.java b/idea/src/org/jetbrains/jet/plugin/refactoring/safeDelete/SafeDeleteTypeArgumentListUsageInfo.java deleted file mode 100644 index b9d8ebb653c..00000000000 --- a/idea/src/org/jetbrains/jet/plugin/refactoring/safeDelete/SafeDeleteTypeArgumentListUsageInfo.java +++ /dev/null @@ -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); - } - } -} diff --git a/idea/src/org/jetbrains/jet/plugin/refactoring/safeDelete/SafeDeleteTypeArgumentListUsageInfo.kt b/idea/src/org/jetbrains/jet/plugin/refactoring/safeDelete/SafeDeleteTypeArgumentListUsageInfo.kt new file mode 100644 index 00000000000..623beac6c7e --- /dev/null +++ b/idea/src/org/jetbrains/jet/plugin/refactoring/safeDelete/SafeDeleteTypeArgumentListUsageInfo.kt @@ -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) } + } +} diff --git a/idea/src/org/jetbrains/jet/plugin/refactoring/safeDelete/SafeDeleteValueArgumentListUsageInfo.java b/idea/src/org/jetbrains/jet/plugin/refactoring/safeDelete/SafeDeleteValueArgumentListUsageInfo.java deleted file mode 100644 index cd0e18468d8..00000000000 --- a/idea/src/org/jetbrains/jet/plugin/refactoring/safeDelete/SafeDeleteValueArgumentListUsageInfo.java +++ /dev/null @@ -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); - } - } -} diff --git a/idea/src/org/jetbrains/jet/plugin/refactoring/safeDelete/SafeDeleteValueArgumentListUsageInfo.kt b/idea/src/org/jetbrains/jet/plugin/refactoring/safeDelete/SafeDeleteValueArgumentListUsageInfo.kt new file mode 100644 index 00000000000..c4b23edbedf --- /dev/null +++ b/idea/src/org/jetbrains/jet/plugin/refactoring/safeDelete/SafeDeleteValueArgumentListUsageInfo.kt @@ -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) } + } +}