From ffa41c1c2779a7dea6d2478d14d4fd36be7b1b9c Mon Sep 17 00:00:00 2001 From: "Alexander.Podkhalyuzin" Date: Tue, 21 Feb 2012 18:08:03 +0400 Subject: [PATCH] Rename JetClass should rename file too. --- idea/src/META-INF/plugin.xml | 2 + .../rename/RenameJetClassProcessor.java | 54 +++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 idea/src/org/jetbrains/jet/plugin/refactoring/rename/RenameJetClassProcessor.java diff --git a/idea/src/META-INF/plugin.xml b/idea/src/META-INF/plugin.xml index dd50a0274df..310eca881ac 100644 --- a/idea/src/META-INF/plugin.xml +++ b/idea/src/META-INF/plugin.xml @@ -94,6 +94,8 @@ + + diff --git a/idea/src/org/jetbrains/jet/plugin/refactoring/rename/RenameJetClassProcessor.java b/idea/src/org/jetbrains/jet/plugin/refactoring/rename/RenameJetClassProcessor.java new file mode 100644 index 00000000000..8fb62469d23 --- /dev/null +++ b/idea/src/org/jetbrains/jet/plugin/refactoring/rename/RenameJetClassProcessor.java @@ -0,0 +1,54 @@ +/* + * Copyright 2000-2012 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.rename; + +import com.intellij.openapi.util.text.StringUtil; +import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.psi.PsiElement; +import com.intellij.psi.PsiFile; +import com.intellij.refactoring.rename.RenamePsiElementProcessor; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.jet.lang.psi.JetClassOrObject; +import org.jetbrains.jet.lang.psi.JetFile; + +import java.util.Map; + +/** + * User: Alefas + * Date: 21.02.12 + */ +public class RenameJetClassProcessor extends RenamePsiElementProcessor { + @Override + public boolean canProcessElement(@NotNull PsiElement element) { + return element instanceof JetClassOrObject; + } + + @Override + public void prepareRenaming(PsiElement element, String newName, Map allRenames) { + JetClassOrObject clazz = (JetClassOrObject) element; + JetFile file = (JetFile) clazz.getContainingFile(); + + VirtualFile virtualFile = file.getVirtualFile(); + if (virtualFile != null) { + String nameWithoutExtensions = virtualFile.getNameWithoutExtension(); + if (nameWithoutExtensions.equals(clazz.getName())) { + allRenames.put(file, newName + "." + virtualFile.getExtension()); + } + } + super.prepareRenaming(element, newName, allRenames); + } +}