Rename JetClass should rename file too.

This commit is contained in:
Alexander.Podkhalyuzin
2012-02-21 18:08:03 +04:00
parent 181f4d444d
commit ffa41c1c27
2 changed files with 56 additions and 0 deletions
+2
View File
@@ -94,6 +94,8 @@
<psi.referenceContributor language="jet" order="after JetCompletionContributor" implementation="org.jetbrains.jet.plugin.references.JetReferenceContributor"/>
<renamePsiElementProcessor implementation="org.jetbrains.jet.plugin.refactoring.rename.RenameJetClassProcessor"/>
<liveTemplateContext implementation="org.jetbrains.jet.plugin.liveTemplates.JetTemplateContextType$Generic"/>
<liveTemplateContext implementation="org.jetbrains.jet.plugin.liveTemplates.JetTemplateContextType$Namespace"/>
<liveTemplateContext implementation="org.jetbrains.jet.plugin.liveTemplates.JetTemplateContextType$Statement"/>
@@ -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<PsiElement, String> 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);
}
}