2 * Copyright 2000-2015 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.jetbrains.python.refactoring;
18 import com.intellij.lang.Language;
19 import com.intellij.openapi.actionSystem.DataContext;
20 import com.intellij.openapi.editor.Editor;
21 import com.intellij.psi.PsiElement;
22 import com.intellij.psi.PsiFile;
23 import com.intellij.refactoring.actions.BaseRefactoringAction;
24 import com.jetbrains.python.PythonLanguage;
25 import org.jetbrains.annotations.NotNull;
28 * @author Mikhail Golubev
30 public abstract class PyBaseRefactoringAction extends BaseRefactoringAction {
32 protected abstract boolean isEnabledOnElementInsideEditor(@NotNull PsiElement element,
33 @NotNull Editor editor,
34 @NotNull PsiFile file,
35 @NotNull DataContext context);
38 protected final boolean isAvailableOnElementInEditorAndFile(@NotNull PsiElement element,
39 @NotNull Editor editor,
40 @NotNull PsiFile file,
41 @NotNull DataContext context) {
42 return isEnabledOnElementInsideEditor(element, editor, file, context);
45 protected abstract boolean isEnabledOnElementsOutsideEditor(@NotNull PsiElement[] elements);
48 protected final boolean isEnabledOnElements(@NotNull PsiElement[] elements) {
49 return isEnabledOnElementsOutsideEditor(elements);
53 protected final boolean isAvailableForLanguage(Language language) {
54 return language.isKindOf(PythonLanguage.getInstance());
58 protected boolean isAvailableForFile(PsiFile file) {
59 return isAvailableForLanguage(file.getLanguage());