update copyright
[fedora-idea.git] / java / java-impl / src / com / intellij / refactoring / move / moveInstanceMethod / MoveInstanceMethodHandlerDelegate.java
blobbdfb83429f5132e3e9e758bd3c9bf6d0fcd11e64
1 /*
2 * Copyright 2000-2009 JetBrains s.r.o.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package com.intellij.refactoring.move.moveInstanceMethod;
18 import com.intellij.psi.*;
19 import com.intellij.psi.impl.source.jsp.jspJava.JspHolderMethod;
20 import com.intellij.refactoring.move.MoveHandlerDelegate;
21 import com.intellij.refactoring.move.MoveCallback;
22 import com.intellij.openapi.project.Project;
23 import com.intellij.openapi.actionSystem.DataContext;
24 import com.intellij.openapi.editor.Editor;
25 import org.jetbrains.annotations.Nullable;
27 public class MoveInstanceMethodHandlerDelegate extends MoveHandlerDelegate {
28 public boolean canMove(final PsiElement[] elements, @Nullable final PsiElement targetContainer) {
29 if (elements.length != 1) return false;
30 PsiElement element = elements [0];
31 if (!(element instanceof PsiMethod)) return false;
32 if (element instanceof JspHolderMethod) return false;
33 PsiMethod method = (PsiMethod) element;
34 if (method.hasModifierProperty(PsiModifier.STATIC)) return false;
35 return super.canMove(elements, targetContainer);
38 public boolean isValidTarget(final PsiElement psiElement) {
39 return psiElement instanceof PsiClass && !(psiElement instanceof PsiAnonymousClass);
42 public boolean tryToMove(final PsiElement element, final Project project, final DataContext dataContext, final PsiReference reference,
43 final Editor editor) {
44 if (element instanceof PsiMethod) {
45 PsiMethod method = (PsiMethod) element;
46 if (!method.hasModifierProperty(PsiModifier.STATIC)) {
47 new MoveInstanceMethodHandler().invoke(project, new PsiElement[]{method}, dataContext);
48 return true;
51 return false;
54 public void doMove(final Project project, final PsiElement[] elements, final PsiElement targetContainer, final MoveCallback callback) {
55 new MoveInstanceMethodHandler().invoke(project, elements, null);