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
.moveMembers
;
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 MoveMembersHandler
extends MoveHandlerDelegate
{
28 public boolean canMove(final PsiElement
[] elements
, @Nullable final PsiElement targetContainer
) {
29 for(PsiElement element
: elements
) {
30 if (!isFieldOrStaticMethod(element
)) return false;
32 return super.canMove(elements
, targetContainer
);
35 public boolean isValidTarget(final PsiElement psiElement
) {
36 return psiElement
instanceof PsiClass
&& !(psiElement
instanceof PsiAnonymousClass
);
39 public void doMove(final Project project
, final PsiElement
[] elements
, final PsiElement targetContainer
, final MoveCallback callback
) {
40 MoveMembersImpl
.doMove(project
, elements
, targetContainer
, callback
);
43 public boolean tryToMove(final PsiElement element
, final Project project
, final DataContext dataContext
, final PsiReference reference
,
44 final Editor editor
) {
45 if (isFieldOrStaticMethod(element
)) {
46 MoveMembersImpl
.doMove(project
, new PsiElement
[]{element
}, null, null);
52 private static boolean isFieldOrStaticMethod(final PsiElement element
) {
53 if (element
instanceof PsiField
) return true;
54 if (element
instanceof PsiMethod
) {
55 if (element
instanceof JspHolderMethod
) return false;
56 return ((PsiMethod
) element
).hasModifierProperty(PsiModifier
.STATIC
);