KT-1386 Copy/Move classes delegates to Copy/Move files.
This commit is contained in:
@@ -79,6 +79,8 @@
|
|||||||
<lang.formatter language="jet" implementationClass="org.jetbrains.jet.plugin.formatter.JetFormattingModelBuilder"/>
|
<lang.formatter language="jet" implementationClass="org.jetbrains.jet.plugin.formatter.JetFormattingModelBuilder"/>
|
||||||
<lang.findUsagesProvider language="jet" implementationClass="org.jetbrains.jet.plugin.findUsages.JetFindUsagesProvider"/>
|
<lang.findUsagesProvider language="jet" implementationClass="org.jetbrains.jet.plugin.findUsages.JetFindUsagesProvider"/>
|
||||||
<lang.refactoringSupport language="jet" implementationClass="org.jetbrains.jet.plugin.refactoring.JetRefactoringSupportProvider"/>
|
<lang.refactoringSupport language="jet" implementationClass="org.jetbrains.jet.plugin.refactoring.JetRefactoringSupportProvider"/>
|
||||||
|
<refactoring.moveHandler implementation="org.jetbrains.jet.plugin.refactoring.move.JetMoveFilesOrDirectoriesHandler"/>
|
||||||
|
<refactoring.copyHandler implementation="org.jetbrains.jet.plugin.refactoring.copy.JetCopyClassHandler"/>
|
||||||
<treeStructureProvider implementation="org.jetbrains.jet.plugin.projectView.JetProjectViewProvider"/>
|
<treeStructureProvider implementation="org.jetbrains.jet.plugin.projectView.JetProjectViewProvider"/>
|
||||||
|
|
||||||
<codeStyleSettingsProvider implementation="org.jetbrains.jet.plugin.formatter.JetCodeStyleSettingsProvider"/>
|
<codeStyleSettingsProvider implementation="org.jetbrains.jet.plugin.formatter.JetCodeStyleSettingsProvider"/>
|
||||||
|
|||||||
@@ -0,0 +1,67 @@
|
|||||||
|
/*
|
||||||
|
* 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.copy;
|
||||||
|
|
||||||
|
import com.intellij.psi.PsiDirectory;
|
||||||
|
import com.intellij.psi.PsiElement;
|
||||||
|
import com.intellij.refactoring.copy.CopyFilesOrDirectoriesHandler;
|
||||||
|
import com.intellij.refactoring.copy.CopyHandlerDelegateBase;
|
||||||
|
import org.jetbrains.jet.lang.psi.JetClassOrObject;
|
||||||
|
import org.jetbrains.jet.plugin.refactoring.move.JetMoveFilesOrDirectoriesHandler;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Alefas
|
||||||
|
* @since 06.03.12
|
||||||
|
*/
|
||||||
|
public class JetCopyClassHandler extends CopyHandlerDelegateBase {
|
||||||
|
private CopyFilesOrDirectoriesHandler delegate = new CopyFilesOrDirectoriesHandler();
|
||||||
|
|
||||||
|
private static PsiElement[] replaceElements(PsiElement[] elements) {
|
||||||
|
ArrayList<PsiElement> result = new ArrayList<PsiElement>();
|
||||||
|
for (PsiElement element : elements) {
|
||||||
|
result.add(replaceElement(element));
|
||||||
|
}
|
||||||
|
return result.toArray(new PsiElement[result.size()]);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static PsiElement replaceElement(PsiElement element) {
|
||||||
|
if (element instanceof JetClassOrObject &&
|
||||||
|
JetMoveFilesOrDirectoriesHandler.isMovableClass((JetClassOrObject) element)) {
|
||||||
|
return element.getContainingFile();
|
||||||
|
} else {
|
||||||
|
return element;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean canCopy(PsiElement[] elements, boolean fromUpdate) {
|
||||||
|
return delegate.canCopy(replaceElements(elements), fromUpdate);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void doCopy(PsiElement[] elements, PsiDirectory defaultTargetDirectory) {
|
||||||
|
delegate.doCopy(replaceElements(elements), defaultTargetDirectory);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void doClone(PsiElement element) {
|
||||||
|
delegate.doClone(replaceElement(element));
|
||||||
|
}
|
||||||
|
}
|
||||||
+71
@@ -0,0 +1,71 @@
|
|||||||
|
/*
|
||||||
|
* 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.move;
|
||||||
|
|
||||||
|
import com.intellij.openapi.project.Project;
|
||||||
|
import com.intellij.psi.PsiDirectory;
|
||||||
|
import com.intellij.psi.PsiElement;
|
||||||
|
import com.intellij.psi.PsiFile;
|
||||||
|
import com.intellij.refactoring.move.moveFilesOrDirectories.MoveFilesOrDirectoriesHandler;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
import org.jetbrains.jet.lang.psi.JetClassOrObject;
|
||||||
|
import org.jetbrains.jet.lang.psi.JetDeclaration;
|
||||||
|
import org.jetbrains.jet.lang.psi.JetFile;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Alefas
|
||||||
|
* @since 06.03.12
|
||||||
|
*/
|
||||||
|
public class JetMoveFilesOrDirectoriesHandler extends MoveFilesOrDirectoriesHandler {
|
||||||
|
public static boolean isMovableClass(JetClassOrObject clazz) {
|
||||||
|
if (!(clazz.getParent() instanceof JetFile)) return false;
|
||||||
|
JetFile file = (JetFile) clazz.getContainingFile();
|
||||||
|
List<JetDeclaration> declarations = file.getDeclarations();
|
||||||
|
for (JetDeclaration declaration : declarations) {
|
||||||
|
if (declaration instanceof JetClassOrObject && declaration != clazz) return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean canMove(PsiElement[] elements, @Nullable PsiElement targetContainer) {
|
||||||
|
for (PsiElement element : elements) {
|
||||||
|
if (!(element instanceof PsiFile) && !(element instanceof PsiDirectory) &&
|
||||||
|
(!(element instanceof JetClassOrObject) ||
|
||||||
|
!isMovableClass((JetClassOrObject) element))) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PsiElement[] adjustForMove(Project project, PsiElement[] sourceElements, PsiElement targetElement) {
|
||||||
|
ArrayList<PsiElement> result = new ArrayList<PsiElement>();
|
||||||
|
for (PsiElement element : sourceElements) {
|
||||||
|
if (element instanceof JetClassOrObject) {
|
||||||
|
result.add(element.getContainingFile());
|
||||||
|
} else {
|
||||||
|
result.add(element);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result.toArray(new PsiElement[result.size()]);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user