mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Cleanup (warnings, formatting)
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2009 JetBrains s.r.o.
|
||||
* Copyright 2000-2017 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.
|
||||
@@ -15,56 +15,39 @@
|
||||
*/
|
||||
package com.intellij.refactoring.actions;
|
||||
|
||||
import com.intellij.ide.DataManager;
|
||||
import com.intellij.lang.Language;
|
||||
import com.intellij.lang.java.JavaLanguage;
|
||||
import com.intellij.openapi.actionSystem.CommonDataKeys;
|
||||
import com.intellij.openapi.actionSystem.DataContext;
|
||||
import com.intellij.openapi.actionSystem.PlatformDataKeys;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.refactoring.RefactoringActionHandler;
|
||||
import com.intellij.refactoring.typeCook.TypeCookHandler;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class TypeCookAction extends BaseRefactoringAction {
|
||||
import java.util.Arrays;
|
||||
|
||||
public class TypeCookAction extends BaseRefactoringAction {
|
||||
@Override
|
||||
protected boolean isAvailableInEditorOnly() {
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAvailableForLanguage(Language language) {
|
||||
return language.equals(JavaLanguage.INSTANCE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabledOnElements(@NotNull PsiElement[] elements) {
|
||||
Project project = CommonDataKeys.PROJECT.getData(DataManager.getInstance().getDataContext());
|
||||
|
||||
if (project == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (int i = 0; i < elements.length; i++) {
|
||||
PsiElement element = elements[i];
|
||||
|
||||
if (
|
||||
!(element instanceof PsiClass ||
|
||||
element instanceof PsiJavaFile ||
|
||||
element instanceof PsiDirectory ||
|
||||
element instanceof PsiPackage
|
||||
)
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
return elements.length > 0 && Arrays.stream(elements).allMatch(
|
||||
e -> e instanceof PsiClass || e instanceof PsiJavaFile || e instanceof PsiDirectory || e instanceof PsiPackage);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RefactoringActionHandler getHandler(@NotNull DataContext dataContext) {
|
||||
return getHandler();
|
||||
}
|
||||
|
||||
public RefactoringActionHandler getHandler() {
|
||||
return new TypeCookHandler();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2014 JetBrains s.r.o.
|
||||
* Copyright 2000-2017 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.
|
||||
@@ -27,7 +27,6 @@ package com.intellij.refactoring.memberPullUp;
|
||||
import com.intellij.openapi.actionSystem.CommonDataKeys;
|
||||
import com.intellij.openapi.actionSystem.DataContext;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.editor.Caret;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.editor.ScrollType;
|
||||
@@ -53,8 +52,8 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class JavaPullUpHandler implements RefactoringActionHandler, PullUpDialog.Callback, ElementsHandler {
|
||||
private static final Logger LOG = Logger.getInstance("#com.intellij.refactoring.memberPullUp.JavaPullUpHandler");
|
||||
public static final String REFACTORING_NAME = RefactoringBundle.message("pull.members.up.title");
|
||||
|
||||
private PsiClass mySubclass;
|
||||
private Project myProject;
|
||||
|
||||
@@ -75,8 +74,7 @@ public class JavaPullUpHandler implements RefactoringActionHandler, PullUpDialog
|
||||
}
|
||||
}
|
||||
if (elements.isEmpty()) {
|
||||
String message = RefactoringBundle
|
||||
.getCannotRefactorMessage(RefactoringBundle.message("the.caret.should.be.positioned.inside.a.class.to.pull.members.from"));
|
||||
String message = RefactoringBundle.getCannotRefactorMessage(RefactoringBundle.message("the.caret.should.be.positioned.inside.a.class.to.pull.members.from"));
|
||||
CommonRefactoringUtil.showErrorHint(project, editor, message, REFACTORING_NAME, HelpID.MEMBERS_PULL_UP);
|
||||
}
|
||||
else {
|
||||
@@ -86,11 +84,8 @@ public class JavaPullUpHandler implements RefactoringActionHandler, PullUpDialog
|
||||
|
||||
@Override
|
||||
public void invoke(@NotNull final Project project, @NotNull PsiElement[] elements, DataContext dataContext) {
|
||||
|
||||
myProject = project;
|
||||
|
||||
PsiClass aClass = PsiTreeUtil.getParentOfType(PsiTreeUtil.findCommonParent(elements), PsiClass.class, false);
|
||||
|
||||
invoke(project, dataContext, aClass, elements);
|
||||
}
|
||||
|
||||
@@ -131,31 +126,26 @@ public class JavaPullUpHandler implements RefactoringActionHandler, PullUpDialog
|
||||
}
|
||||
}
|
||||
|
||||
final PullUpDialog dialog = new PullUpDialog(project, aClass, bases, memberInfoStorage, this);
|
||||
|
||||
|
||||
dialog.show();
|
||||
new PullUpDialog(project, aClass, bases, memberInfoStorage, this).show();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public boolean checkConflicts(final PullUpDialog dialog) {
|
||||
final List<MemberInfo> infos = dialog.getSelectedMemberInfos();
|
||||
final MemberInfo[] memberInfos = infos.toArray(new MemberInfo[infos.size()]);
|
||||
final PsiClass superClass = dialog.getSuperClass();
|
||||
if (!checkWritable(superClass, memberInfos)) return false;
|
||||
if (superClass == null || !checkWritable(superClass, memberInfos)) return false;
|
||||
final MultiMap<PsiElement, String> conflicts = new MultiMap<>();
|
||||
if (!ProgressManager.getInstance().runProcessWithProgressSynchronously(() -> ApplicationManager.getApplication().runReadAction(() -> {
|
||||
final PsiDirectory targetDirectory = superClass.getContainingFile().getContainingDirectory();
|
||||
final PsiPackage targetPackage = targetDirectory != null ? JavaDirectoryService.getInstance().getPackage(targetDirectory) : null;
|
||||
conflicts
|
||||
.putAllValues(PullUpConflictsUtil.checkConflicts(memberInfos, mySubclass, superClass, targetPackage, targetDirectory, dialog.getContainmentVerifier()));
|
||||
if (targetDirectory != null && targetPackage != null) {
|
||||
conflicts.putAllValues(PullUpConflictsUtil.checkConflicts(memberInfos, mySubclass, superClass, targetPackage, targetDirectory, dialog.getContainmentVerifier()));
|
||||
}
|
||||
}), RefactoringBundle.message("detecting.possible.conflicts"), true, myProject)) return false;
|
||||
if (!conflicts.isEmpty()) {
|
||||
ConflictsDialog conflictsDialog = new ConflictsDialog(myProject, conflicts);
|
||||
conflictsDialog.show();
|
||||
final boolean ok = conflictsDialog.isOK();
|
||||
boolean ok = conflictsDialog.showAndGet();
|
||||
if (!ok && conflictsDialog.isShowConflicts()) dialog.close(DialogWrapper.CANCEL_EXIT_CODE);
|
||||
return ok;
|
||||
}
|
||||
@@ -173,20 +163,7 @@ public class JavaPullUpHandler implements RefactoringActionHandler, PullUpDialog
|
||||
|
||||
@Override
|
||||
public boolean isEnabledOnElements(PsiElement[] elements) {
|
||||
/*
|
||||
if (elements.length == 1) {
|
||||
return elements[0] instanceof PsiClass || elements[0] instanceof PsiField || elements[0] instanceof PsiMethod;
|
||||
}
|
||||
else if (elements.length > 1){
|
||||
for (int idx = 0; idx < elements.length; idx++) {
|
||||
PsiElement element = elements[idx];
|
||||
if (!(element instanceof PsiField || element instanceof PsiMethod)) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
*/
|
||||
// todo: multiple selection etc
|
||||
return elements.length == 1 && elements[0] instanceof PsiClass;
|
||||
}
|
||||
}
|
||||
}
|
||||
+5
-15
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2009 JetBrains s.r.o.
|
||||
* Copyright 2000-2017 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.
|
||||
@@ -43,9 +43,10 @@ import java.util.List;
|
||||
public class JavaPushDownHandler implements RefactoringActionHandler, ElementsHandler {
|
||||
public static final String REFACTORING_NAME = RefactoringBundle.message("push.members.down.title");
|
||||
|
||||
@Override
|
||||
public void invoke(@NotNull Project project, Editor editor, PsiFile file, DataContext dataContext) {
|
||||
editor.getScrollingModel().scrollToCaret(ScrollType.MAKE_VISIBLE);
|
||||
ArrayList<PsiElement> elements = new ArrayList<>();
|
||||
List<PsiElement> elements = new ArrayList<>();
|
||||
String errorMessage = null;
|
||||
for (Caret caret : editor.getCaretModel().getAllCarets()) {
|
||||
int offset = caret.getOffset();
|
||||
@@ -83,6 +84,7 @@ public class JavaPushDownHandler implements RefactoringActionHandler, ElementsHa
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invoke(@NotNull final Project project, @NotNull PsiElement[] elements, DataContext dataContext) {
|
||||
PsiClass aClass = PsiTreeUtil.getParentOfType(PsiTreeUtil.findCommonParent(elements), PsiClass.class, false);
|
||||
if (aClass == null) return;
|
||||
@@ -114,20 +116,8 @@ public class JavaPushDownHandler implements RefactoringActionHandler, ElementsHa
|
||||
dialog.show();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabledOnElements(PsiElement[] elements) {
|
||||
/*
|
||||
if (elements.length == 1) {
|
||||
return elements[0] instanceof PsiClass || elements[0] instanceof PsiField || elements[0] instanceof PsiMethod;
|
||||
}
|
||||
else if (elements.length > 1){
|
||||
for (int idx = 0; idx < elements.length; idx++) {
|
||||
PsiElement element = elements[idx];
|
||||
if (!(element instanceof PsiField || element instanceof PsiMethod)) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
*/
|
||||
// todo: multiple selection etc
|
||||
return elements.length == 1 && elements[0] instanceof PsiClass;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2009 JetBrains s.r.o.
|
||||
* Copyright 2000-2017 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.
|
||||
@@ -21,19 +21,18 @@ import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.refactoring.RefactoringActionHandler;
|
||||
import com.intellij.refactoring.util.CommonRefactoringUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class TypeCookHandler implements RefactoringActionHandler {
|
||||
|
||||
@Override
|
||||
public void invoke(@NotNull Project project, Editor editor, PsiFile file, DataContext dataContext) {
|
||||
invoke(project, new PsiElement[]{file}, dataContext);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invoke(@NotNull Project project, @NotNull PsiElement[] elements, DataContext dataContext) {
|
||||
if (elements.length == 0) return;
|
||||
|
||||
new TypeCookDialog(project, elements).show();
|
||||
if (elements.length != 0) {
|
||||
new TypeCookDialog(project, elements).show();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user