mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Merge remote-tracking branch 'origin/master'
This commit is contained in:
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
+1314
-1120
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
+24
-25
@@ -50,6 +50,7 @@ import com.intellij.openapi.roots.ui.configuration.projectRoot.daemon.LibraryPro
|
||||
import com.intellij.openapi.roots.ui.configuration.projectRoot.daemon.ModuleProjectStructureElement;
|
||||
import com.intellij.openapi.roots.ui.configuration.projectRoot.daemon.ProjectStructureDaemonAnalyzer;
|
||||
import com.intellij.openapi.roots.ui.configuration.projectRoot.daemon.ProjectStructureElement;
|
||||
import com.intellij.openapi.ui.DialogBuilder;
|
||||
import com.intellij.openapi.ui.DialogWrapper;
|
||||
import com.intellij.openapi.ui.Messages;
|
||||
import com.intellij.openapi.ui.NamedConfigurable;
|
||||
@@ -64,6 +65,7 @@ import com.intellij.openapi.wm.WindowManager;
|
||||
import com.intellij.ui.navigation.Place;
|
||||
import com.intellij.util.Consumer;
|
||||
import com.intellij.util.Function;
|
||||
import com.intellij.util.PathUtil;
|
||||
import com.intellij.util.PlatformIcons;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.intellij.util.ui.tree.TreeUtil;
|
||||
@@ -783,27 +785,23 @@ public class ModuleStructureConfigurable extends BaseStructureConfigurable imple
|
||||
final NamedConfigurable namedConfigurable = getSelectedConfugurable();
|
||||
if (namedConfigurable instanceof ModuleConfigurable) {
|
||||
try {
|
||||
final ModuleEditor moduleEditor = ((ModuleConfigurable)namedConfigurable).getModuleEditor();
|
||||
final String modulePresentation = IdeBundle.message("project.new.wizard.module.identification");
|
||||
final NamePathComponent component = new NamePathComponent(IdeBundle.message("label.project.name"), IdeBundle.message(
|
||||
"label.component.file.location", StringUtil.capitalize(modulePresentation)), IdeBundle.message(
|
||||
"title.select.project.file.directory", modulePresentation), IdeBundle.message("description.select.project.file.directory",
|
||||
StringUtil.capitalize(modulePresentation)), true, false);
|
||||
final DialogWrapper copyModuleDialog = new DialogWrapper(myTree, false) {
|
||||
{
|
||||
setTitle(ProjectBundle.message("copy.module.dialog.title"));
|
||||
init();
|
||||
}
|
||||
final NamePathComponent component = new NamePathComponent(IdeBundle.message("label.module.name"), IdeBundle.message("label.component.file.location", StringUtil.capitalize(modulePresentation)), IdeBundle.message("title.select.project.file.directory", modulePresentation),
|
||||
IdeBundle.message("description.select.project.file.directory", StringUtil.capitalize(modulePresentation)), true,
|
||||
false);
|
||||
final Module originalModule = moduleEditor.getModule();
|
||||
if (originalModule != null) {
|
||||
component.setPath(PathUtil.getParentPath(originalModule.getModuleFilePath()));
|
||||
}
|
||||
|
||||
public JComponent getPreferredFocusedComponent() {
|
||||
return component.getNameComponent();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
protected JComponent createCenterPanel() {
|
||||
return component;
|
||||
}
|
||||
|
||||
protected void doOKAction() {
|
||||
final DialogBuilder dialogBuilder = new DialogBuilder(myTree);
|
||||
dialogBuilder.setTitle(ProjectBundle.message("copy.module.dialog.title"));
|
||||
dialogBuilder.setCenterPanel(component);
|
||||
dialogBuilder.setPreferedFocusComponent(component.getNameComponent());
|
||||
dialogBuilder.setOkOperation(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (component.getNameValue().length() == 0) {
|
||||
Messages.showErrorDialog(ProjectBundle.message("enter.module.copy.name.error.message"), CommonBundle.message("title.error"));
|
||||
return;
|
||||
@@ -815,16 +813,17 @@ public class ModuleStructureConfigurable extends BaseStructureConfigurable imple
|
||||
return;
|
||||
}
|
||||
if (!ProjectWizardUtil
|
||||
.createDirectoryIfNotExists(IdeBundle.message("directory.project.file.directory", modulePresentation), component.getPath(), true)) {
|
||||
.createDirectoryIfNotExists(IdeBundle.message("directory.project.file.directory", modulePresentation), component.getPath(),
|
||||
true)) {
|
||||
Messages.showErrorDialog(ProjectBundle.message("path.0.is.invalid.error.message", component.getPath()), CommonBundle.message("title.error"));
|
||||
return;
|
||||
}
|
||||
super.doOKAction();
|
||||
dialogBuilder.getDialogWrapper().close(DialogWrapper.OK_EXIT_CODE);
|
||||
}
|
||||
};
|
||||
copyModuleDialog.show();
|
||||
if (!copyModuleDialog.isOK()) return;
|
||||
final ModifiableRootModel rootModel = ((ModuleConfigurable)namedConfigurable).getModuleEditor().getModifiableRootModel();
|
||||
});
|
||||
if (dialogBuilder.show() != DialogWrapper.OK_EXIT_CODE) return;
|
||||
|
||||
final ModifiableRootModel rootModel = moduleEditor.getModifiableRootModel();
|
||||
final String path = component.getPath();
|
||||
final ModuleBuilder builder = new ModuleBuilder() {
|
||||
public void setupRootModel(final ModifiableRootModel modifiableRootModel) throws ConfigurationException {
|
||||
|
||||
@@ -0,0 +1,125 @@
|
||||
/*
|
||||
* Copyright 2000-2009 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 com.intellij.codeInsight.unwrap;
|
||||
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public abstract class AbstractUnwrapper<C extends AbstractUnwrapper.AbstractContext> implements Unwrapper {
|
||||
private final String myDescription;
|
||||
|
||||
public AbstractUnwrapper(String description) {
|
||||
myDescription = description;
|
||||
}
|
||||
|
||||
public abstract boolean isApplicableTo(PsiElement e);
|
||||
|
||||
public void collectElementsToIgnore(PsiElement element, Set<PsiElement> result) {
|
||||
}
|
||||
|
||||
public String getDescription(PsiElement e) {
|
||||
return myDescription;
|
||||
}
|
||||
|
||||
public PsiElement collectAffectedElements(PsiElement e, List<PsiElement> toExtract) {
|
||||
try {
|
||||
C c = createContext(false);
|
||||
doUnwrap(e, c);
|
||||
toExtract.addAll(c.myElementsToExtract);
|
||||
return e;
|
||||
}
|
||||
catch (IncorrectOperationException ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
public List<PsiElement> unwrap(Editor editor, PsiElement element) throws IncorrectOperationException {
|
||||
C c = createContext(true);
|
||||
doUnwrap(element, c);
|
||||
return c.myElementsToExtract;
|
||||
}
|
||||
|
||||
protected abstract void doUnwrap(PsiElement element, C context) throws IncorrectOperationException;
|
||||
|
||||
protected abstract C createContext(boolean isEffective);
|
||||
|
||||
public abstract static class AbstractContext {
|
||||
protected final List<PsiElement> myElementsToExtract = new ArrayList<PsiElement>();
|
||||
protected final boolean myIsEffective;
|
||||
|
||||
public AbstractContext(boolean isEffective) {
|
||||
myIsEffective = isEffective;
|
||||
}
|
||||
|
||||
public void addElementToExtract(PsiElement e) {
|
||||
myElementsToExtract.add(e);
|
||||
}
|
||||
|
||||
public void extractElement(PsiElement element, PsiElement from) throws IncorrectOperationException {
|
||||
extract(element, element, from);
|
||||
}
|
||||
|
||||
protected abstract boolean isWhiteSpace(PsiElement element);
|
||||
|
||||
protected void extract(PsiElement first, PsiElement last, PsiElement from) throws IncorrectOperationException {
|
||||
// trim leading empty spaces
|
||||
while (first != last && isWhiteSpace(first)) {
|
||||
//noinspection ConstantConditions
|
||||
first = first.getNextSibling();
|
||||
}
|
||||
|
||||
// trim trailing empty spaces
|
||||
while (last != first && isWhiteSpace(last)) {
|
||||
//noinspection ConstantConditions
|
||||
last = last.getPrevSibling();
|
||||
}
|
||||
|
||||
// nothing to extract
|
||||
if (first == null || last == null || first == last && isWhiteSpace(last)) return;
|
||||
|
||||
PsiElement toExtract = first;
|
||||
if (myIsEffective) {
|
||||
toExtract = from.getParent().addRangeBefore(first, last, from);
|
||||
}
|
||||
|
||||
do {
|
||||
if (toExtract != null) {
|
||||
addElementToExtract(toExtract);
|
||||
toExtract = toExtract.getNextSibling();
|
||||
}
|
||||
first = first.getNextSibling();
|
||||
}
|
||||
while (first != null && first.getPrevSibling() != last);
|
||||
}
|
||||
|
||||
public void delete(PsiElement e) throws IncorrectOperationException {
|
||||
if (myIsEffective) e.delete();
|
||||
}
|
||||
|
||||
public void deleteExactly(PsiElement e) throws IncorrectOperationException {
|
||||
if (myIsEffective) {
|
||||
// have to use 'parent.deleteChildRange' since 'e.delete' is too smart:
|
||||
// it attempts to remove not only the element but sometimes whole expression.
|
||||
e.getParent().deleteChildRange(e, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -29,19 +29,31 @@ import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class JavaUnwrapDescriptor implements UnwrapDescriptor {
|
||||
private static final Unwrapper[] UNWRAPPERS = new Unwrapper[] {
|
||||
new JavaMethodParameterUnwrapper(),
|
||||
new JavaElseUnwrapper(),
|
||||
new JavaElseRemover(),
|
||||
new JavaIfUnwrapper(),
|
||||
new JavaWhileUnwrapper(),
|
||||
new JavaForUnwrapper(),
|
||||
new JavaBracesUnwrapper(),
|
||||
new JavaTryUnwrapper(),
|
||||
new JavaCatchRemover(),
|
||||
new JavaSynchronizedUnwrapper(),
|
||||
new JavaAnonymousUnwrapper(),
|
||||
};
|
||||
private Unwrapper[] myUnwrappers;
|
||||
|
||||
public final Unwrapper[] getUnwrappers() {
|
||||
if (myUnwrappers == null) {
|
||||
myUnwrappers = createUnwrappers();
|
||||
}
|
||||
|
||||
return myUnwrappers;
|
||||
}
|
||||
|
||||
protected Unwrapper[] createUnwrappers() {
|
||||
return new Unwrapper[] {
|
||||
new JavaMethodParameterUnwrapper(),
|
||||
new JavaElseUnwrapper(),
|
||||
new JavaElseRemover(),
|
||||
new JavaIfUnwrapper(),
|
||||
new JavaWhileUnwrapper(),
|
||||
new JavaForUnwrapper(),
|
||||
new JavaBracesUnwrapper(),
|
||||
new JavaTryUnwrapper(),
|
||||
new JavaCatchRemover(),
|
||||
new JavaSynchronizedUnwrapper(),
|
||||
new JavaAnonymousUnwrapper(),
|
||||
};
|
||||
}
|
||||
|
||||
public List<Pair<PsiElement, Unwrapper>> collectUnwrappers(Project project, Editor editor, PsiFile file) {
|
||||
PsiElement e = findTargetElement(editor, file);
|
||||
@@ -49,7 +61,7 @@ public class JavaUnwrapDescriptor implements UnwrapDescriptor {
|
||||
List<Pair<PsiElement, Unwrapper>> result = new ArrayList<Pair<PsiElement, Unwrapper>>();
|
||||
Set<PsiElement> ignored = new HashSet<PsiElement>();
|
||||
while (e != null) {
|
||||
for (Unwrapper u : UNWRAPPERS) {
|
||||
for (Unwrapper u : getUnwrappers()) {
|
||||
if (u.isApplicableTo(e) && !ignored.contains(e)) {
|
||||
result.add(new Pair<PsiElement, Unwrapper>(e, u));
|
||||
u.collectElementsToIgnore(e, ignored);
|
||||
|
||||
@@ -15,60 +15,24 @@
|
||||
*/
|
||||
package com.intellij.codeInsight.unwrap;
|
||||
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public abstract class JavaUnwrapper implements Unwrapper {
|
||||
private final String myDescription;
|
||||
public abstract class JavaUnwrapper extends AbstractUnwrapper<JavaUnwrapper.Context> {
|
||||
|
||||
public JavaUnwrapper(String description) {
|
||||
myDescription = description;
|
||||
super(description);
|
||||
}
|
||||
|
||||
public abstract boolean isApplicableTo(PsiElement e);
|
||||
|
||||
public void collectElementsToIgnore(PsiElement element, Set<PsiElement> result) {
|
||||
@Override
|
||||
protected Context createContext(boolean isEffective) {
|
||||
return new Context(isEffective);
|
||||
}
|
||||
|
||||
public String getDescription(PsiElement e) {
|
||||
return myDescription;
|
||||
}
|
||||
|
||||
public PsiElement collectAffectedElements(PsiElement e, List<PsiElement> toExtract) {
|
||||
try {
|
||||
Context c = new Context(false);
|
||||
doUnwrap(e, c);
|
||||
toExtract.addAll(c.myElementsToExtract);
|
||||
return e;
|
||||
}
|
||||
catch (IncorrectOperationException ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
public List<PsiElement> unwrap(Editor editor, PsiElement element) throws IncorrectOperationException {
|
||||
Context c = new Context(true);
|
||||
doUnwrap(element, c);
|
||||
return c.myElementsToExtract;
|
||||
}
|
||||
|
||||
protected abstract void doUnwrap(PsiElement element, Context context) throws IncorrectOperationException;
|
||||
|
||||
protected static class Context {
|
||||
private final List<PsiElement> myElementsToExtract = new ArrayList<PsiElement>();
|
||||
private final boolean myIsEffective;
|
||||
protected static class Context extends AbstractUnwrapper.AbstractContext {
|
||||
|
||||
public Context(boolean isEffective) {
|
||||
myIsEffective = isEffective;
|
||||
}
|
||||
|
||||
public void addElementToExtract(PsiElement e) {
|
||||
myElementsToExtract.add(e);
|
||||
super(isEffective);
|
||||
}
|
||||
|
||||
public void extractFromBlockOrSingleStatement(PsiStatement block, PsiElement from) throws IncorrectOperationException {
|
||||
@@ -85,51 +49,6 @@ public abstract class JavaUnwrapper implements Unwrapper {
|
||||
extract(block.getFirstBodyElement(), block.getLastBodyElement(), from);
|
||||
}
|
||||
|
||||
public void extractElement(PsiElement element, PsiElement from) throws IncorrectOperationException {
|
||||
extract(element, element, from);
|
||||
}
|
||||
|
||||
private void extract(PsiElement first, PsiElement last, PsiElement from) throws IncorrectOperationException {
|
||||
// trim leading empty spaces
|
||||
while (first != last && first instanceof PsiWhiteSpace) {
|
||||
first = first.getNextSibling();
|
||||
}
|
||||
|
||||
// trim trailing empty spaces
|
||||
while (last != first && last instanceof PsiWhiteSpace) {
|
||||
last = last.getPrevSibling();
|
||||
}
|
||||
|
||||
// nothing to extract
|
||||
if (first == null || last == null || first == last && last instanceof PsiWhiteSpace) return;
|
||||
|
||||
PsiElement toExtract = first;
|
||||
if (myIsEffective) {
|
||||
toExtract = from.getParent().addRangeBefore(first, last, from);
|
||||
}
|
||||
|
||||
do {
|
||||
if (toExtract != null) {
|
||||
addElementToExtract(toExtract);
|
||||
toExtract = toExtract.getNextSibling();
|
||||
}
|
||||
first = first.getNextSibling();
|
||||
}
|
||||
while (first != null && first.getPrevSibling() != last);
|
||||
}
|
||||
|
||||
public void delete(PsiElement e) throws IncorrectOperationException {
|
||||
if (myIsEffective) e.delete();
|
||||
}
|
||||
|
||||
public void deleteExactly(PsiElement e) throws IncorrectOperationException {
|
||||
if (myIsEffective) {
|
||||
// have to use 'parent.deleteChildRange' since 'e.delete' is too smart:
|
||||
// it attempts to remove not only the element but sometimes whole expression.
|
||||
e.getParent().deleteChildRange(e, e);
|
||||
}
|
||||
}
|
||||
|
||||
public void setElseBranch(PsiIfStatement ifStatement, PsiStatement elseBranch) throws IncorrectOperationException {
|
||||
PsiStatement toExtract = elseBranch;
|
||||
if (myIsEffective) {
|
||||
@@ -139,6 +58,11 @@ public abstract class JavaUnwrapper implements Unwrapper {
|
||||
addElementToExtract(toExtract);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isWhiteSpace(PsiElement element) {
|
||||
return element instanceof PsiWhiteSpace;
|
||||
}
|
||||
|
||||
private static PsiStatement copyElement(PsiStatement e) throws IncorrectOperationException {
|
||||
// We cannot call el.copy() for 'else' since it sets context to parent 'if'.
|
||||
// This causes copy to be invalidated after parent 'if' is removed by setElseBranch method.
|
||||
|
||||
@@ -85,6 +85,6 @@ public class JavaCommenter implements CodeDocumentationAwareCommenterEx {
|
||||
public boolean isDocumentationCommentText(final PsiElement element) {
|
||||
if (element == null) return false;
|
||||
final ASTNode node = element.getNode();
|
||||
return node != null && node.getElementType() == JavaDocTokenType.DOC_COMMENT_DATA;
|
||||
return node != null && (node.getElementType() == JavaDocTokenType.DOC_COMMENT_DATA || node.getElementType() == JavaDocTokenType.DOC_TAG_VALUE_TOKEN);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ package com.intellij.openapi.util;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.progress.ProcessCanceledException;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
@@ -30,21 +31,23 @@ public class SimpleTimer {
|
||||
|
||||
private final Timer ourTimer;
|
||||
|
||||
private static final SimpleTimer ourInstance = new SimpleTimer();
|
||||
@NonNls private static final String THREAD_NAME = "SimpleTimer";
|
||||
private static final SimpleTimer ourInstance = newInstance("Shared SimpleTimer");
|
||||
|
||||
private long myNextScheduledTime = Long.MAX_VALUE;
|
||||
private TimerTask myNextProcessingTask;
|
||||
|
||||
private final Map<Long, ArrayList<SimpleTimerTask>> myTime2Task = new TreeMap<Long, ArrayList<SimpleTimerTask>>();
|
||||
private String myThreadName;
|
||||
|
||||
private SimpleTimer() {
|
||||
private SimpleTimer(@NotNull String threadName) {
|
||||
myThreadName = threadName;
|
||||
|
||||
final Thread thread = Thread.currentThread();
|
||||
final int currentPrio = thread.getPriority();
|
||||
try {
|
||||
// need this becase the timer's thread will inherit the priority on creation
|
||||
thread.setPriority(Thread.MIN_PRIORITY + 1);
|
||||
ourTimer = new Timer(THREAD_NAME, true);
|
||||
ourTimer = new Timer(threadName, true);
|
||||
}
|
||||
finally {
|
||||
thread.setPriority(currentPrio);
|
||||
@@ -54,6 +57,10 @@ public class SimpleTimer {
|
||||
public static SimpleTimer getInstance() {
|
||||
return ourInstance;
|
||||
}
|
||||
|
||||
public static SimpleTimer newInstance(@NotNull String name) {
|
||||
return new SimpleTimer(name);
|
||||
}
|
||||
|
||||
public SimpleTimerTask setUp(final Runnable runnable, long delay) {
|
||||
synchronized (myTime2Task) {
|
||||
@@ -150,7 +157,7 @@ public class SimpleTimer {
|
||||
}
|
||||
|
||||
public boolean isTimerThread(Thread thread) {
|
||||
return THREAD_NAME.equals(thread.getName());
|
||||
return myThreadName.equals(thread.getName());
|
||||
}
|
||||
|
||||
void onCancelled(SimpleTimerTask task) {
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
%startTest Generate actions
|
||||
|
||||
%include extract_Superclass.ijs
|
||||
%include newClass_projectView.ijs
|
||||
|
||||
%endTest
|
||||
@@ -1,12 +1,15 @@
|
||||
%startTest Create superclass
|
||||
%startTest Create superclass from popup menu
|
||||
|
||||
%%include ../include/project1Init.ijs
|
||||
%%action GotoClass
|
||||
%%PsiManager\n
|
||||
|
||||
%include ../include/init.ijs
|
||||
%include ../include/project1Init.ijs
|
||||
%action GotoClass
|
||||
FileEditorManager\n
|
||||
%call checkFocus(editorTab=FileEditorManager.java)
|
||||
%call contextMenu(Refactor|Extract Superclass)
|
||||
TestSuperclass\n
|
||||
%call checkFocus(dialog=Analyze and Replace Usages)
|
||||
%call waitForDialog(Analyze and Replace Usages)
|
||||
%[space]
|
||||
%call waitForDialog(Use Interface Where Possible)
|
||||
%[space]
|
||||
%call checkFocus(editorTab=FileEditorManager.java)
|
||||
|
||||
%endTest
|
||||
@@ -8,9 +8,9 @@ PsiManager\n
|
||||
%[left]
|
||||
%[left]
|
||||
%[down]
|
||||
%call checkFocus(navBar=module1>src>com>intellij>[testProject]>idea>PsiManager|navBarPopup=[fabrique]>idea>mps)
|
||||
%call checkFocus(navBar=module1>src>com>intellij>[testProject]>idea>PsiManager|navBarPopup=fabrique>[idea]>mps)
|
||||
\n
|
||||
%call flushUi()
|
||||
\n
|
||||
%call checkFocus(editorTab=ActiveLibrary.java)
|
||||
%call checkFocus(editorTab=FileEditorManager.java)
|
||||
|
||||
|
||||
@@ -79,7 +79,7 @@ public class TodoAttributes implements JDOMExternalizable, Cloneable {
|
||||
}
|
||||
|
||||
private static TextAttributes getDefaultColorSchemeTextAttributes() {
|
||||
return EditorColorsManager.getInstance().getGlobalScheme().getAttributes(CodeInsightColors.TODO_DEFAULT_ATTRIBUTES);
|
||||
return EditorColorsManager.getInstance().getGlobalScheme().getAttributes(CodeInsightColors.TODO_DEFAULT_ATTRIBUTES).clone();
|
||||
}
|
||||
|
||||
public void readExternal(Element element) throws InvalidDataException {
|
||||
|
||||
+8
-3
@@ -30,7 +30,6 @@ import com.intellij.openapi.ui.VerticalFlowLayout;
|
||||
import com.intellij.openapi.util.Disposer;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.openapi.util.Ref;
|
||||
import com.intellij.openapi.util.SystemInfo;
|
||||
import com.intellij.openapi.util.registry.Registry;
|
||||
import com.intellij.openapi.wm.IdeFocusManager;
|
||||
import com.intellij.psi.PsiCodeFragment;
|
||||
@@ -47,7 +46,7 @@ import com.intellij.ui.treeStructure.Tree;
|
||||
import com.intellij.util.Alarm;
|
||||
import com.intellij.util.Consumer;
|
||||
import com.intellij.util.PlatformIcons;
|
||||
import com.intellij.util.ui.MacUIUtil;
|
||||
import com.intellij.util.ui.UIUtil;
|
||||
import com.intellij.util.ui.table.JBListTable;
|
||||
import com.intellij.util.ui.table.JBTableRow;
|
||||
import com.intellij.util.ui.table.JBTableRowEditor;
|
||||
@@ -282,7 +281,13 @@ public abstract class ChangeSignatureDialogBase<P extends ParameterInfo, M exten
|
||||
tabbedPane.addTab(extraPanel.first, extraPanel.second);
|
||||
}
|
||||
main = new JPanel(new BorderLayout());
|
||||
main.add(tabbedPane.getComponent(), BorderLayout.CENTER);
|
||||
final JComponent tabs = tabbedPane.getComponent();
|
||||
main.add(tabs, BorderLayout.CENTER);
|
||||
//remove traversal policies
|
||||
for (JComponent c : UIUtil.findComponentsOfType(tabs, JComponent.class)) {
|
||||
c.setFocusCycleRoot(false);
|
||||
c.setFocusTraversalPolicy(null);
|
||||
}
|
||||
}
|
||||
final JPanel bottom = new JPanel(new BorderLayout());
|
||||
bottom.add(optionsPanel, BorderLayout.NORTH);
|
||||
|
||||
+4
-4
@@ -234,7 +234,7 @@ public class CopyFilesOrDirectoriesHandler implements CopyHandlerDelegate {
|
||||
if (elementToCopy instanceof PsiFile) {
|
||||
PsiFile file = (PsiFile)elementToCopy;
|
||||
String name = newName == null ? file.getName() : newName;
|
||||
if (checkFileExist(targetDirectory, choice, file, name)) return null;
|
||||
if (checkFileExist(targetDirectory, choice, file, name, "Copy")) return null;
|
||||
return targetDirectory.copyFileFrom(name, file);
|
||||
}
|
||||
else if (elementToCopy instanceof PsiDirectory) {
|
||||
@@ -267,12 +267,12 @@ public class CopyFilesOrDirectoriesHandler implements CopyHandlerDelegate {
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean checkFileExist(PsiDirectory targetDirectory, int[] choice, PsiFile file, String name) {
|
||||
public static boolean checkFileExist(PsiDirectory targetDirectory, int[] choice, PsiFile file, String name, final String title) {
|
||||
final PsiFile existing = targetDirectory.findFile(name);
|
||||
if (existing!=null) {
|
||||
if (existing != null && !existing.equals(file)) {
|
||||
int selection = choice == null || choice[0] == -1 ? Messages.showDialog(
|
||||
String.format("File '%s' already exists in directory '%s'", name, targetDirectory.getVirtualFile().getPath()),
|
||||
"Copy",
|
||||
title,
|
||||
choice == null ? new String[]{"Overwrite", "Skip"}
|
||||
: new String[]{"Overwrite", "Skip", "Overwrite for all", "Skip for all"}, 0, Messages.getQuestionIcon())
|
||||
: choice[0];
|
||||
|
||||
+1
-1
@@ -146,7 +146,7 @@ public class MoveFilesOrDirectoriesUtil {
|
||||
final boolean fileExist = ApplicationManager.getApplication().runWriteAction(new Computable<Boolean>() {
|
||||
@Override
|
||||
public Boolean compute() {
|
||||
return CopyFilesOrDirectoriesHandler.checkFileExist(targetDirectory, choice, file, file.getName());
|
||||
return CopyFilesOrDirectoriesHandler.checkFileExist(targetDirectory, choice, file, file.getName(), "Move");
|
||||
}
|
||||
});
|
||||
if (fileExist) continue;
|
||||
|
||||
@@ -307,7 +307,7 @@ public class RenameProcessor extends BaseRefactoringProcessor {
|
||||
if (entry.getKey() instanceof PsiFile) {
|
||||
final PsiFile file = (PsiFile)entry.getKey();
|
||||
final PsiDirectory containingDirectory = file.getContainingDirectory();
|
||||
if (CopyFilesOrDirectoriesHandler.checkFileExist(containingDirectory, choice, file, entry.getValue())) {
|
||||
if (CopyFilesOrDirectoriesHandler.checkFileExist(containingDirectory, choice, file, entry.getValue(), "Rename")) {
|
||||
iterator.remove();
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
package com.intellij.openapi.actionSystem;
|
||||
|
||||
import com.intellij.openapi.project.DumbAware;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* Represents a separator.
|
||||
@@ -28,7 +29,7 @@ public final class Separator extends AnAction implements DumbAware {
|
||||
public Separator() {
|
||||
}
|
||||
|
||||
public Separator(String text) {
|
||||
public Separator(@Nullable final String text) {
|
||||
myText = text;
|
||||
}
|
||||
|
||||
|
||||
@@ -94,8 +94,29 @@ public class FileChooser {
|
||||
@Nullable final VirtualFile toSelect,
|
||||
@NotNull final Consumer<VirtualFile[]> onChosenCallback
|
||||
) {
|
||||
if (SystemInfo.isMac && isNativeMacChooserEnabled()) descriptor.putUserData(MacFileChooserDialog.NATIVE_MAC_FILE_CHOOSER_ENABLED, Boolean.TRUE);
|
||||
final FileChooserDialog dialog = FileChooserFactory.getInstance().createFileChooser(descriptor, project);
|
||||
chooseFilesWithSlideEffect(descriptor, project, null, toSelect, onChosenCallback);
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows file/folder open dialog, allows user to choose files/folders and then passes result to callback in EDT.
|
||||
* On MacOS Open Dialog will be shown with slide effect if Macish UI is turned on.
|
||||
* @param descriptor File chooser descriptor
|
||||
* @param project project
|
||||
* @param parent parent component
|
||||
* @param toSelect file to preselect
|
||||
* @param onChosenCallback Callback will be invoked after user have closed dialog
|
||||
*/
|
||||
public static void chooseFilesWithSlideEffect(@NotNull final FileChooserDescriptor descriptor,
|
||||
@Nullable final Project project,
|
||||
@Nullable final Component parent,
|
||||
@Nullable final VirtualFile toSelect,
|
||||
@NotNull final Consumer<VirtualFile[]> onChosenCallback
|
||||
) {
|
||||
if (SystemInfo.isMac && isNativeMacChooserEnabled()) descriptor.putUserData(MacFileChooserDialog.NATIVE_MAC_FILE_CHOOSER_ENABLED, Boolean.TRUE);
|
||||
final FileChooserFactory factory = FileChooserFactory.getInstance();
|
||||
final FileChooserDialog dialog = parent != null
|
||||
? factory.createFileChooser(descriptor, parent)
|
||||
: factory.createFileChooser(descriptor, project);
|
||||
if (dialog instanceof MacFileChooserDialog) {
|
||||
((MacFileChooserDialog)dialog).chooseWithSheet(toSelect, project, new MacFileChooserDialog.MacFileChooserCallback() {
|
||||
public void onChosen(@NotNull final VirtualFile[] files) {
|
||||
|
||||
@@ -17,15 +17,28 @@ package com.intellij.openapi.util;
|
||||
|
||||
import com.intellij.util.ui.UIUtil;
|
||||
|
||||
public abstract class EdtRunnable implements Runnable {
|
||||
public abstract class EdtRunnable implements ExpirableRunnable {
|
||||
|
||||
private boolean myExpired;
|
||||
|
||||
public final void run() {
|
||||
UIUtil.invokeLaterIfNeeded(new Runnable() {
|
||||
public void run() {
|
||||
runEdt();
|
||||
if (!isExpired()) {
|
||||
runEdt();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void expire() {
|
||||
myExpired = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isExpired() {
|
||||
return myExpired;
|
||||
}
|
||||
|
||||
public abstract void runEdt();
|
||||
}
|
||||
@@ -319,10 +319,8 @@ public class DataManagerImpl extends DataManager implements ApplicationComponent
|
||||
myEventCount + "; current event count = " + currentEventCount
|
||||
);
|
||||
*/
|
||||
if (false) {
|
||||
LOG.error("cannot share data context between Swing events; initial event count = " + myEventCount + "; current event count = " +
|
||||
currentEventCount);
|
||||
}
|
||||
}
|
||||
|
||||
Component _component = myRef.get();
|
||||
|
||||
@@ -247,19 +247,25 @@ public class ProgressWindow extends BlockingProgressIndicator implements Disposa
|
||||
|
||||
super.stop();
|
||||
|
||||
if (myDialog != null) {
|
||||
myDialog.hide();
|
||||
if (myDialog.wasShown()) {
|
||||
myFocusTrackback.restoreFocus();
|
||||
}
|
||||
else {
|
||||
myFocusTrackback.consume();
|
||||
}
|
||||
}
|
||||
|
||||
myStoppedAlready = true;
|
||||
UIUtil.invokeLaterIfNeeded(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (myDialog != null) {
|
||||
myDialog.hide();
|
||||
if (myDialog.wasShown()) {
|
||||
myFocusTrackback.restoreFocus();
|
||||
}
|
||||
else {
|
||||
myFocusTrackback.consume();
|
||||
}
|
||||
}
|
||||
|
||||
Disposer.dispose(this);
|
||||
myStoppedAlready = true;
|
||||
|
||||
Disposer.dispose(ProgressWindow.this);
|
||||
}
|
||||
});
|
||||
|
||||
SwingUtilities.invokeLater(EmptyRunnable.INSTANCE); // Just to give blocking dispatching a chance to go out.
|
||||
}
|
||||
|
||||
+45
@@ -24,6 +24,9 @@ import com.intellij.openapi.ui.Queryable;
|
||||
import com.intellij.openapi.ui.playback.PlaybackContext;
|
||||
import com.intellij.openapi.util.ActionCallback;
|
||||
import com.intellij.openapi.util.AsyncResult;
|
||||
import com.intellij.openapi.util.Ref;
|
||||
import com.intellij.openapi.util.SimpleTimer;
|
||||
import com.intellij.openapi.util.registry.Registry;
|
||||
import com.intellij.openapi.wm.IdeFocusManager;
|
||||
import com.intellij.openapi.wm.IdeFrame;
|
||||
import com.intellij.openapi.wm.ToolWindow;
|
||||
@@ -34,8 +37,10 @@ import javax.swing.*;
|
||||
import javax.swing.event.ChangeEvent;
|
||||
import javax.swing.event.ChangeListener;
|
||||
import java.awt.*;
|
||||
import java.awt.event.AWTEventListener;
|
||||
import java.awt.event.InputEvent;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.event.WindowEvent;
|
||||
import java.util.*;
|
||||
|
||||
public class WindowSystemPlaybackCall {
|
||||
@@ -67,6 +72,46 @@ public class WindowSystemPlaybackCall {
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
public static AsyncResult<String> waitForDialog(final PlaybackContext context, final String title) {
|
||||
final AsyncResult<String> result = new AsyncResult<String>();
|
||||
|
||||
final Ref<AWTEventListener> listener = new Ref<AWTEventListener>();
|
||||
listener.set(new AWTEventListener() {
|
||||
@Override
|
||||
public void eventDispatched(AWTEvent event) {
|
||||
if (event.getID() == WindowEvent.WINDOW_ACTIVATED) {
|
||||
final Window wnd = ((WindowEvent)event).getWindow();
|
||||
if (wnd instanceof JDialog) {
|
||||
if (title.equals(((JDialog)wnd).getTitle())) {
|
||||
Toolkit.getDefaultToolkit().removeAWTEventListener(listener.get());
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
getUiReady(context).notify(result);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Toolkit.getDefaultToolkit().addAWTEventListener(listener.get(), WindowEvent.WINDOW_EVENT_MASK);
|
||||
|
||||
SimpleTimer.getInstance().setUp(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Toolkit.getDefaultToolkit().removeAWTEventListener(listener.get());
|
||||
if (!result.isProcessed()) {
|
||||
result.setRejected("Timed out waiting for window: " + title);
|
||||
}
|
||||
}
|
||||
}, Registry.intValue("actionSystem.commandProcessingTimeout"));
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public static AsyncResult<String> checkFocus(final PlaybackContext context, String expected) {
|
||||
final AsyncResult<String> result = new AsyncResult<String>();
|
||||
final Map<String, String> expectedMap = new LinkedHashMap<String, String>();
|
||||
|
||||
@@ -27,10 +27,7 @@ import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.application.ModalityState;
|
||||
import com.intellij.openapi.application.ex.ApplicationManagerEx;
|
||||
import com.intellij.openapi.ui.popup.JBPopup;
|
||||
import com.intellij.openapi.util.ActionCallback;
|
||||
import com.intellij.openapi.util.EdtRunnable;
|
||||
import com.intellij.openapi.util.Expirable;
|
||||
import com.intellij.openapi.util.ExpirableRunnable;
|
||||
import com.intellij.openapi.util.*;
|
||||
import com.intellij.openapi.util.registry.Registry;
|
||||
import com.intellij.openapi.wm.*;
|
||||
import com.intellij.openapi.wm.ex.IdeFocusTraversalPolicy;
|
||||
@@ -79,24 +76,11 @@ public class FocusManagerImpl extends IdeFocusManager implements Disposable {
|
||||
final EdtAlarm myFocusedComponentAlaram;
|
||||
private final EdtAlarm myForcedFocusRequestsAlarm;
|
||||
|
||||
private SimpleTimer myTimer = SimpleTimer.newInstance("FocusManager timer");
|
||||
|
||||
private final EdtAlarm myIdleAlarm;
|
||||
private final Set<Runnable> myIdleRequests = new LinkedHashSet<Runnable>();
|
||||
private final EdtRunnable myIdleRunnable = new EdtRunnable() {
|
||||
public void runEdt() {
|
||||
if (canFlushIdleRequests()) {
|
||||
flushIdleRequests();
|
||||
}
|
||||
else {
|
||||
if (processFocusRevalidation()) {
|
||||
if (isFocusTransferReady()) {
|
||||
flushIdleRequests();
|
||||
}
|
||||
}
|
||||
|
||||
restartIdleAlarm();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
private boolean myFlushWasDelayedToFixFocus;
|
||||
private ExpirableRunnable myFocusRevalidator;
|
||||
|
||||
@@ -106,6 +90,24 @@ public class FocusManagerImpl extends IdeFocusManager implements Disposable {
|
||||
private UiActivityMonitor myActivityMonitor;
|
||||
private boolean myTypeaheadEnabled = true;
|
||||
|
||||
|
||||
private class IdleRunnable extends EdtRunnable {
|
||||
public void runEdt() {
|
||||
if (canFlushIdleRequests()) {
|
||||
flushIdleRequests();
|
||||
}
|
||||
else {
|
||||
if (processFocusRevalidation()) {
|
||||
if (isFocusTransferReady()) {
|
||||
flushIdleRequests();
|
||||
}
|
||||
}
|
||||
|
||||
restartIdleAlarm();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean canFlushIdleRequests() {
|
||||
Component focusOwner = getFocusOwner();
|
||||
return isFocusTransferReady()
|
||||
@@ -128,9 +130,9 @@ public class FocusManagerImpl extends IdeFocusManager implements Disposable {
|
||||
myQueue = IdeEventQueue.getInstance();
|
||||
myActivityMonitor = UiActivityMonitor.getInstance();
|
||||
|
||||
myFocusedComponentAlaram = new EdtAlarm(this);
|
||||
myForcedFocusRequestsAlarm = new EdtAlarm(this);
|
||||
myIdleAlarm = new EdtAlarm(this);
|
||||
myFocusedComponentAlaram = new EdtAlarm();
|
||||
myForcedFocusRequestsAlarm = new EdtAlarm();
|
||||
myIdleAlarm = new EdtAlarm();
|
||||
|
||||
final AppListener myAppListener = new AppListener();
|
||||
myApp.getMessageBus().connect().subscribe(ApplicationActivationListener.TOPIC, myAppListener);
|
||||
@@ -183,6 +185,8 @@ public class FocusManagerImpl extends IdeFocusManager implements Disposable {
|
||||
|
||||
@NotNull
|
||||
public ActionCallback requestFocus(@NotNull final FocusCommand command, final boolean forced) {
|
||||
assertDispatchThread();
|
||||
|
||||
if (isInternalMode) {
|
||||
recordCommand(command, new Throwable(), forced);
|
||||
}
|
||||
@@ -460,7 +464,7 @@ public class FocusManagerImpl extends IdeFocusManager implements Disposable {
|
||||
|
||||
private void restartIdleAlarm() {
|
||||
myIdleAlarm.cancelAllRequests();
|
||||
myIdleAlarm.addRequest(myIdleRunnable, Registry.intValue("actionSystem.focusIdleTimeout"));
|
||||
myIdleAlarm.addRequest(new IdleRunnable(), Registry.intValue("actionSystem.focusIdleTimeout"));
|
||||
}
|
||||
|
||||
private void flushIdleRequests() {
|
||||
@@ -602,6 +606,8 @@ public class FocusManagerImpl extends IdeFocusManager implements Disposable {
|
||||
}
|
||||
|
||||
public boolean isFocusTransferReady() {
|
||||
assertDispatchThread();
|
||||
|
||||
if (myRunContext != null) return true;
|
||||
|
||||
invalidateFocusRequestsQueue();
|
||||
@@ -741,6 +747,8 @@ public class FocusManagerImpl extends IdeFocusManager implements Disposable {
|
||||
}
|
||||
|
||||
public void suspendKeyProcessingUntil(@NotNull final ActionCallback done) {
|
||||
assertDispatchThread();
|
||||
|
||||
requestFocus(new FocusCommand(done) {
|
||||
public ActionCallback run() {
|
||||
return done;
|
||||
@@ -749,6 +757,8 @@ public class FocusManagerImpl extends IdeFocusManager implements Disposable {
|
||||
}
|
||||
|
||||
public Expirable getTimestamp(final boolean trackOnlyForcedCommands) {
|
||||
assertDispatchThread();
|
||||
|
||||
return new Expirable() {
|
||||
long myOwnStamp = trackOnlyForcedCommands ? myForcedCmdTimestamp : myCmdTimestamp;
|
||||
|
||||
@@ -760,6 +770,8 @@ public class FocusManagerImpl extends IdeFocusManager implements Disposable {
|
||||
|
||||
@Override
|
||||
public FocusRequestor getFurtherRequestor() {
|
||||
assertDispatchThread();
|
||||
|
||||
FurtherRequestor requestor = new FurtherRequestor(this, getTimestamp(true));
|
||||
myValidFurtherRequestors.add(requestor);
|
||||
revalidateFurtherRequestors();
|
||||
@@ -789,6 +801,8 @@ public class FocusManagerImpl extends IdeFocusManager implements Disposable {
|
||||
|
||||
@Override
|
||||
public Component getFocusOwner() {
|
||||
assertDispatchThread();
|
||||
|
||||
Component result = null;
|
||||
if (myRunContext != null) {
|
||||
result = (Component)myRunContext.getData(PlatformDataKeys.CONTEXT_COMPONENT.getName());
|
||||
@@ -815,6 +829,8 @@ public class FocusManagerImpl extends IdeFocusManager implements Disposable {
|
||||
|
||||
@Override
|
||||
public void runOnOwnContext(DataContext context, Runnable runnable) {
|
||||
assertDispatchThread();
|
||||
|
||||
myRunContext = context;
|
||||
try {
|
||||
runnable.run();
|
||||
@@ -825,12 +841,16 @@ public class FocusManagerImpl extends IdeFocusManager implements Disposable {
|
||||
|
||||
@Override
|
||||
public Component getLastFocusedFor(IdeFrame frame) {
|
||||
assertDispatchThread();
|
||||
|
||||
WeakReference<Component> ref = myLastFocused.get(frame);
|
||||
return ref != null ? ref.get() : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toFront(JComponent c) {
|
||||
assertDispatchThread();
|
||||
|
||||
if (c == null) return;
|
||||
|
||||
final Window window = UIUtil.getParentOfType(Window.class, c);
|
||||
@@ -877,19 +897,20 @@ public class FocusManagerImpl extends IdeFocusManager implements Disposable {
|
||||
}
|
||||
|
||||
|
||||
static class EdtAlarm {
|
||||
private final Alarm myAlarm;
|
||||
|
||||
private EdtAlarm(Disposable parent) {
|
||||
myAlarm = new Alarm(Alarm.ThreadToUse.OWN_THREAD, parent);
|
||||
}
|
||||
class EdtAlarm {
|
||||
|
||||
private Set<EdtRunnable> myRequests = new HashSet<EdtRunnable>();
|
||||
|
||||
public void cancelAllRequests() {
|
||||
myAlarm.cancelAllRequests();
|
||||
for (EdtRunnable each : myRequests) {
|
||||
each.expire();
|
||||
}
|
||||
myRequests.clear();
|
||||
}
|
||||
|
||||
public void addRequest(EdtRunnable runnable, int delay) {
|
||||
myAlarm.addRequest(runnable, delay);
|
||||
myRequests.add(runnable);
|
||||
myTimer.setUp(runnable, delay);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1018,4 +1039,8 @@ public class FocusManagerImpl extends IdeFocusManager implements Disposable {
|
||||
public boolean isFocusTransferEnabled() {
|
||||
return myApp.isActive() || !Registry.is("actionSystem.suspendFocusTransferIfApplicationInactive");
|
||||
}
|
||||
|
||||
private void assertDispatchThread() {
|
||||
ApplicationManager.getApplication().assertIsDispatchThread();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,11 +56,13 @@ public abstract class JBListTable extends JPanel {
|
||||
mainTable = new JBTable(model) {
|
||||
@Override
|
||||
protected void processKeyEvent(KeyEvent e) {
|
||||
if (e.isAltDown()) return;
|
||||
if (e.getKeyCode() == KeyEvent.VK_ENTER && e.getModifiers() == 0) {
|
||||
if (!isEditing() && e.getID() == KeyEvent.KEY_PRESSED) {
|
||||
editCellAt(getSelectedRow(), getSelectedColumn());
|
||||
}
|
||||
e.consume();
|
||||
return;
|
||||
}
|
||||
//todo[kb] JBTabsImpl breaks focus traversal policy. Need a workaround here
|
||||
else if (e.getKeyCode() == KeyEvent.VK_TAB) {
|
||||
@@ -73,10 +75,9 @@ public abstract class JBListTable extends JPanel {
|
||||
}
|
||||
}
|
||||
e.consume();
|
||||
return;
|
||||
}
|
||||
else {
|
||||
super.processKeyEvent(e);
|
||||
}
|
||||
super.processKeyEvent(e);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -13,7 +13,7 @@ sm.test.runner.ui.tests.tree.presentation.labels.instantiating.tests=Instantiati
|
||||
sm.test.runner.ui.tests.tree.presentation.labels.not.test.results=No Test Results
|
||||
sm.test.runner.ui.tests.tree.presentation.labels.was.terminated=Terminated
|
||||
sm.test.runner.ui.tests.tree.presentation.labels.no.tests.were.found=No tests were found
|
||||
sm.test.runner.ui.tests.tree.presentation.labels.test.reporter.not.attached=Unable to attach test reporter to test framework
|
||||
sm.test.runner.ui.tests.tree.presentation.labels.test.reporter.not.attached=Unable to attach test reporter to test framework or test framework quit unexpectedly
|
||||
sm.test.runner.ui.tests.tree.presentation.labels.no.tests.were.found.with.errors=No tests were found. Errors occurred
|
||||
sm.test.runner.ui.tests.tree.presentation.labels.empty.test.suite=Empty test suite
|
||||
sm.test.runner.ui.tests.tree.presentation.labels.all.tests.passed=All Tests Passed
|
||||
|
||||
@@ -1175,6 +1175,76 @@
|
||||
<option name="ERROR_STRIPE_COLOR" value="ff" />
|
||||
</value>
|
||||
</option>
|
||||
<option name="CONSOLE_BLUE_OUTPUT">
|
||||
<value>
|
||||
<option name="FOREGROUND" value="ff" />
|
||||
<option name="BACKGROUND" />
|
||||
<option name="FONT_TYPE" value="0" />
|
||||
<option name="EFFECT_COLOR" />
|
||||
<option name="EFFECT_TYPE" value="0" />
|
||||
<option name="ERROR_STRIPE_COLOR" />
|
||||
</value>
|
||||
</option>
|
||||
<option name="CONSOLE_CYAN_OUTPUT">
|
||||
<value>
|
||||
<option name="FOREGROUND" value="b2b2" />
|
||||
<option name="BACKGROUND" />
|
||||
<option name="FONT_TYPE" value="0" />
|
||||
<option name="EFFECT_COLOR" />
|
||||
<option name="EFFECT_TYPE" value="0" />
|
||||
<option name="ERROR_STRIPE_COLOR" />
|
||||
</value>
|
||||
</option>
|
||||
<option name="CONSOLE_GRAY_OUTPUT">
|
||||
<value>
|
||||
<option name="FOREGROUND" value="595959" />
|
||||
<option name="BACKGROUND" />
|
||||
<option name="FONT_TYPE" value="0" />
|
||||
<option name="EFFECT_COLOR" />
|
||||
<option name="EFFECT_TYPE" value="0" />
|
||||
<option name="ERROR_STRIPE_COLOR" />
|
||||
</value>
|
||||
</option>
|
||||
<option name="CONSOLE_GREEN_OUTPUT">
|
||||
<value>
|
||||
<option name="FOREGROUND" value="8000" />
|
||||
<option name="BACKGROUND" />
|
||||
<option name="FONT_TYPE" value="0" />
|
||||
<option name="EFFECT_COLOR" />
|
||||
<option name="EFFECT_TYPE" value="0" />
|
||||
<option name="ERROR_STRIPE_COLOR" />
|
||||
</value>
|
||||
</option>
|
||||
<option name="CONSOLE_MAGENTA_OUTPUT">
|
||||
<value>
|
||||
<option name="FOREGROUND" value="ff00ff" />
|
||||
<option name="BACKGROUND" />
|
||||
<option name="FONT_TYPE" value="0" />
|
||||
<option name="EFFECT_COLOR" />
|
||||
<option name="EFFECT_TYPE" value="0" />
|
||||
<option name="ERROR_STRIPE_COLOR" />
|
||||
</value>
|
||||
</option>
|
||||
<option name="CONSOLE_RED_OUTPUT">
|
||||
<value>
|
||||
<option name="FOREGROUND" value="ff0000" />
|
||||
<option name="BACKGROUND" />
|
||||
<option name="FONT_TYPE" value="0" />
|
||||
<option name="EFFECT_COLOR" />
|
||||
<option name="EFFECT_TYPE" value="0" />
|
||||
<option name="ERROR_STRIPE_COLOR" />
|
||||
</value>
|
||||
</option>
|
||||
<option name="CONSOLE_YELLOW_OUTPUT">
|
||||
<value>
|
||||
<option name="FOREGROUND" value="ffcc00" />
|
||||
<option name="BACKGROUND" />
|
||||
<option name="FONT_TYPE" value="0" />
|
||||
<option name="EFFECT_COLOR" />
|
||||
<option name="EFFECT_TYPE" value="0" />
|
||||
<option name="ERROR_STRIPE_COLOR" />
|
||||
</value>
|
||||
</option>
|
||||
</attributes>
|
||||
|
||||
</scheme>
|
||||
|
||||
@@ -218,7 +218,8 @@
|
||||
<keyboard-shortcut first-keystroke="control ENTER"/>
|
||||
</action>
|
||||
<action id="EditorToggleColumnMode">
|
||||
<keyboard-shortcut first-keystroke="meta shift MULTIPLY"/>
|
||||
<keyboard-shortcut first-keystroke="shift meta 8" />
|
||||
<keyboard-shortcut first-keystroke="shift meta MULTIPLY" />
|
||||
</action>
|
||||
<action id="EditorLineEndWithSelection">
|
||||
<keyboard-shortcut first-keystroke="shift END"/>
|
||||
|
||||
@@ -19,6 +19,7 @@ import com.intellij.execution.Location;
|
||||
import com.intellij.execution.PsiLocation;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.editor.Document;
|
||||
import com.intellij.openapi.project.DumbAware;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
@@ -36,7 +37,7 @@ import java.util.List;
|
||||
/**
|
||||
* @author Roman Chernyatchik
|
||||
*/
|
||||
public class FileUrlProvider implements TestLocationProvider {
|
||||
public class FileUrlProvider implements TestLocationProvider, DumbAware {
|
||||
private static final Logger LOG = Logger.getInstance(FileUrlProvider.class.getName());
|
||||
|
||||
@NonNls private static final String FILE_PROTOCOL_ID = "file";
|
||||
|
||||
@@ -28,6 +28,7 @@ import com.intellij.execution.ui.ConsoleViewContentType;
|
||||
import com.intellij.ide.util.EditSourceUtil;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.extensions.Extensions;
|
||||
import com.intellij.openapi.project.DumbService;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Key;
|
||||
import com.intellij.pom.Navigatable;
|
||||
@@ -180,6 +181,8 @@ public class SMTestProxy extends AbstractTestProxy {
|
||||
final String protocolId = TestsLocationProviderUtil.extractProtocol(myLocationUrl);
|
||||
final String path = TestsLocationProviderUtil.extractPath(myLocationUrl);
|
||||
|
||||
final boolean isDumbMode = DumbService.isDumb(project);
|
||||
|
||||
if (protocolId != null && path != null) {
|
||||
if (myLocator != null) {
|
||||
List<Location> locations = myLocator.getLocation(protocolId, path, project);
|
||||
@@ -188,6 +191,9 @@ public class SMTestProxy extends AbstractTestProxy {
|
||||
}
|
||||
}
|
||||
for (TestLocationProvider provider : Extensions.getExtensions(TestLocationProvider.EP_NAME)) {
|
||||
if (isDumbMode && !DumbService.isDumbAware(provider)) {
|
||||
continue;
|
||||
}
|
||||
final List<Location> locations = provider.getLocation(protocolId, path, project);
|
||||
if (!locations.isEmpty()) {
|
||||
return locations.iterator().next();
|
||||
|
||||
+1
-1
@@ -547,7 +547,7 @@ public class TestsPresentationUtilTest extends BaseSMTRunnerTestCase {
|
||||
|
||||
assertEquals(PoolOfTestIcons.NOT_RAN, myRenderer.getIcon());
|
||||
assertOneElement(myFragContainer.getFragments());
|
||||
assertEquals("Unable to attach test reporter to test framework", myFragContainer.getTextAt(0));
|
||||
assertEquals("Unable to attach test reporter to test framework or test framework quit unexpectedly", myFragContainer.getTextAt(0));
|
||||
assertEquals(SimpleTextAttributes.ERROR_ATTRIBUTES, myFragContainer.getAttribsAt(0));
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2009 JetBrains s.r.o.
|
||||
* Copyright 2000-2011 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.
|
||||
@@ -135,8 +135,8 @@ public class CommitHelper {
|
||||
if (failed > 0) {
|
||||
text += ", " + failed + " " + StringUtil.pluralize("change", failed) + " failed to commit";
|
||||
}
|
||||
String content = StringUtil.isEmpty(myCommitMessage) ? text : text + ": " + myCommitMessage;
|
||||
VcsBalloonProblemNotifier.NOTIFICATION_GROUP.createNotification(content, NotificationType.INFORMATION).notify( myProject);
|
||||
String content = StringUtil.isEmpty(myCommitMessage) ? text : text + ": " + StringUtil.escapeXml(myCommitMessage);
|
||||
VcsBalloonProblemNotifier.NOTIFICATION_GROUP.createNotification(content, NotificationType.INFORMATION).notify(myProject);
|
||||
return new NotificationInfo("VCS Commit", "VCS Commit Finished", text, true);
|
||||
}
|
||||
};
|
||||
|
||||
+4
-3
@@ -34,7 +34,8 @@ public class XDebuggerHistoryManager {
|
||||
}
|
||||
|
||||
public void addRecentExpression(@NotNull @NonNls String id, @NotNull String expression) {
|
||||
if (expression.trim().length() == 0) return;
|
||||
final String trimmedExpression = expression.trim();
|
||||
if (trimmedExpression.length() == 0) return;
|
||||
|
||||
LinkedList<String> list = myRecentExpressions.get(id);
|
||||
if (list == null) {
|
||||
@@ -44,8 +45,8 @@ public class XDebuggerHistoryManager {
|
||||
if (list.size() == MAX_RECENT_EXPRESSIONS) {
|
||||
list.removeLast();
|
||||
}
|
||||
list.remove(expression);
|
||||
list.addFirst(expression);
|
||||
list.remove(trimmedExpression);
|
||||
list.addFirst(trimmedExpression);
|
||||
}
|
||||
|
||||
public List<String> getRecentExpressions(@NonNls String id) {
|
||||
|
||||
@@ -23,6 +23,7 @@ import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.vcs.AbstractVcs;
|
||||
import com.intellij.openapi.vcs.actions.VcsQuickListContentProvider;
|
||||
import git4idea.GitVcs;
|
||||
import git4idea.i18n.GitBundle;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -66,6 +67,14 @@ public class GitQuickListContentProvider implements VcsQuickListContentProvider
|
||||
add("Git.Stash", manager, actions);
|
||||
add("Git.Unstash", manager, actions);
|
||||
|
||||
// Github
|
||||
addSeparator(actions);
|
||||
final AnAction githubRebase = manager.getAction("Github.Rebase");
|
||||
if (githubRebase != null) {
|
||||
actions.add(new Separator(GitBundle.message("vcs.popup.git.github.section")));
|
||||
actions.add(githubRebase);
|
||||
}
|
||||
|
||||
return actions;
|
||||
}
|
||||
|
||||
@@ -81,7 +90,7 @@ public class GitQuickListContentProvider implements VcsQuickListContentProvider
|
||||
return true;
|
||||
}
|
||||
|
||||
private void addSeparator(List<AnAction> actions) {
|
||||
private void addSeparator(@NotNull final List<AnAction> actions) {
|
||||
actions.add(new Separator());
|
||||
}
|
||||
|
||||
|
||||
@@ -516,3 +516,5 @@ branch.delete.not_fully_merged.description.not_on_branch=You are currently not o
|
||||
branch.delete.merged_to.many=The branch <code><b>{0}</b></code> is however fully merged to the following branches: <code>{1}</code>.
|
||||
branch.delete.merged_to.one=The branch <code><b>{0}</b></code> is however fully merged to the branch <code>{1}</code>.
|
||||
branch.delete.warning=You may still delete the branch <code><b>{0}</b></code>, but beware that it cannot be undone.
|
||||
|
||||
vcs.popup.git.github.section=GitHub
|
||||
@@ -31,7 +31,7 @@ import java.util.List;
|
||||
* @date 12/10/10
|
||||
*/
|
||||
public class GithubRebase extends GitRebase {
|
||||
private String myParent;
|
||||
private String myOriginName;
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
@@ -39,7 +39,7 @@ public class GithubRebase extends GitRebase {
|
||||
@Nullable
|
||||
protected GitLineHandler createHandler(final Project project, final List<VirtualFile> gitRoots, final VirtualFile defaultRoot) {
|
||||
final GithubRebaseDialog dialog = new GithubRebaseDialog(project, gitRoots, defaultRoot);
|
||||
dialog.configure(myParent);
|
||||
dialog.configure(myOriginName);
|
||||
dialog.show();
|
||||
if (!dialog.isOK()) {
|
||||
return null;
|
||||
@@ -47,8 +47,8 @@ public class GithubRebase extends GitRebase {
|
||||
return dialog.handler();
|
||||
}
|
||||
|
||||
public void setRebaseOrigin(final String parent) {
|
||||
myParent = parent;
|
||||
public void setRebaseOrigin(final String originName) {
|
||||
myOriginName = originName;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -25,6 +25,7 @@ import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.ui.Messages;
|
||||
import com.intellij.openapi.util.Computable;
|
||||
import com.intellij.openapi.util.IconLoader;
|
||||
import com.intellij.openapi.util.Ref;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.openapi.vcs.VcsException;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
@@ -124,15 +125,15 @@ public class GithubRebaseAction extends DumbAwareAction {
|
||||
final String parentRepoUrl = "git://github.com/" + parentRepoSuffix;
|
||||
|
||||
// Check that corresponding remote branch is configured for the fork origin repo
|
||||
boolean remoteForParentSeen = false;
|
||||
final Ref<String> remoteForForkParentRepo = new Ref<String>();
|
||||
for (GitRemote gitRemote : gitRemotes) {
|
||||
final String fetchUrl = gitRemote.fetchUrl();
|
||||
if (fetchUrl.endsWith(parent + ".git")) {
|
||||
remoteForParentSeen = true;
|
||||
remoteForForkParentRepo.set(gitRemote.name());
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!remoteForParentSeen){
|
||||
if (remoteForForkParentRepo.isNull()){
|
||||
final int result = Messages.showYesNoDialog(project, "It is necessary to have '" +
|
||||
parentRepoUrl +
|
||||
"' as a configured remote. Add remote?", "Github Rebase",
|
||||
@@ -149,8 +150,9 @@ public class GithubRebaseAction extends DumbAwareAction {
|
||||
final GitSimpleHandler addRemoteHandler = new GitSimpleHandler(project, root, GitCommand.REMOTE);
|
||||
addRemoteHandler.setNoSSH(true);
|
||||
addRemoteHandler.setSilent(true);
|
||||
final String remoteName = parent.substring(0, parent.lastIndexOf('/'));
|
||||
addRemoteHandler.addParameters("add", remoteName, parentRepoUrl);
|
||||
|
||||
remoteForForkParentRepo.set("upstream");
|
||||
addRemoteHandler.addParameters("add", remoteForForkParentRepo.get(), parentRepoUrl);
|
||||
addRemoteHandler.run();
|
||||
if (addRemoteHandler.getExitCode() != 0) {
|
||||
showErrorMessageInEDT(project, "Failed to add GitHub remote: '" + parentRepoUrl + "'");
|
||||
@@ -180,7 +182,7 @@ public class GithubRebaseAction extends DumbAwareAction {
|
||||
|
||||
BasicAction.saveAll();
|
||||
final GithubRebase action = (GithubRebase) ActionManager.getInstance().getAction("Github.Rebase.Internal");
|
||||
action.setRebaseOrigin(parent);
|
||||
action.setRebaseOrigin(remoteForForkParentRepo.get());
|
||||
final AnActionEvent actionEvent =
|
||||
new AnActionEvent(e.getInputEvent(), e.getDataContext(), e.getPlace(), e.getPresentation(), e.getActionManager(), e.getModifiers());
|
||||
action.actionPerformed(actionEvent);
|
||||
|
||||
@@ -365,13 +365,20 @@ public class GithubUtil {
|
||||
|
||||
@Nullable
|
||||
public static GitRemote findGitHubRemoteBranch(final Project project, final VirtualFile root) {
|
||||
// i.e. find origin which points on my github repo
|
||||
try {
|
||||
// Check that given repository is properly configured git repository
|
||||
final String host = GithubSettings.getInstance().getHost();
|
||||
final GithubSettings githubSettings = GithubSettings.getInstance();
|
||||
final String host = githubSettings.getHost();
|
||||
final String username = githubSettings.getLogin();
|
||||
|
||||
final String userRepoMarkerSSHProtocol = host + ":" + username + "/";
|
||||
final String userRepoMarkerOtherProtocols = host + "/" + username + "/";
|
||||
|
||||
final List<GitRemote> gitRemotes = GitRemote.list(project, root);
|
||||
for (GitRemote gitRemote : gitRemotes) {
|
||||
final String pushUrl = gitRemote.pushUrl();
|
||||
if (pushUrl.contains(host)) {
|
||||
if (pushUrl.contains(userRepoMarkerSSHProtocol) || pushUrl.contains(userRepoMarkerOtherProtocols)) {
|
||||
return gitRemote;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,10 +16,13 @@
|
||||
package org.jetbrains.plugins.github.ui;
|
||||
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.vcs.VcsException;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import git4idea.GitBranch;
|
||||
import git4idea.rebase.GitRebaseDialog;
|
||||
import git4idea.ui.GitUIUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -35,14 +38,13 @@ public class GithubRebaseDialog extends GitRebaseDialog {
|
||||
super(project, roots, defaultRoot);
|
||||
}
|
||||
|
||||
public void configure(final String parent) {
|
||||
public void configure(final String originName) {
|
||||
setTitle("Rebase GitHub");
|
||||
|
||||
myShowRemoteBranchesCheckBox.setSelected(true);
|
||||
myShowRemoteBranchesCheckBox.getParent().remove(myShowRemoteBranchesCheckBox);
|
||||
myGitRootComboBox.setEnabled(false);
|
||||
myLocalBranches.clear();
|
||||
final String originName = parent.substring(0, parent.lastIndexOf('/'));
|
||||
final ArrayList<GitBranch> remoteCopy = new ArrayList<GitBranch>();
|
||||
remoteCopy.addAll(myRemoteBranches);
|
||||
myRemoteBranches.clear();
|
||||
@@ -55,14 +57,41 @@ public class GithubRebaseDialog extends GitRebaseDialog {
|
||||
updateOntoFrom();
|
||||
|
||||
// Preselect remote master
|
||||
final String preselected = "/" + originName + "/master";
|
||||
GitBranch remoteBranch = null;
|
||||
String currentLocalBranchName = null;
|
||||
try {
|
||||
final GitBranch currentBranch = GitBranch.current(myProject, gitRoot());
|
||||
if (currentBranch != null) {
|
||||
currentLocalBranchName = currentBranch.getName();
|
||||
}
|
||||
}
|
||||
catch (VcsException e) {
|
||||
// Do noting;
|
||||
}
|
||||
|
||||
if (currentLocalBranchName != null) {
|
||||
// try to find corresponding remote branch
|
||||
remoteBranch = findBranch("/" + originName + "/" + currentLocalBranchName);
|
||||
}
|
||||
if (remoteBranch == null) {
|
||||
// else use master
|
||||
remoteBranch = findBranch("/" + originName + "/master");
|
||||
}
|
||||
|
||||
if (remoteBranch != null) {
|
||||
myOntoComboBox.setSelectedItem(remoteBranch);
|
||||
GitUIUtil.getTextField(myOntoComboBox).setText(remoteBranch.getFullName());
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private GitBranch findBranch(@NotNull String preselected) {
|
||||
for (GitBranch remoteBranch : myRemoteBranches) {
|
||||
final String branchFullName = remoteBranch.getFullName();
|
||||
if (branchFullName.endsWith(preselected)){
|
||||
myOntoComboBox.setSelectedItem(remoteBranch);
|
||||
GitUIUtil.getTextField(myOntoComboBox).setText(branchFullName);
|
||||
break;
|
||||
return remoteBranch;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -255,6 +255,7 @@
|
||||
|
||||
<typeHierarchyProvider language="Groovy" implementationClass="org.jetbrains.plugins.groovy.lang.GroovyTypeHierarchyProvider"/>
|
||||
|
||||
<lang.unwrapDescriptor language="Groovy" implementationClass="org.jetbrains.plugins.groovy.unwrap.GroovyUnwrapDescriptor" />
|
||||
|
||||
<lang.elementManipulator forClass="org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.literals.GrLiteral"
|
||||
implementationClass="org.jetbrains.plugins.groovy.lang.resolve.GroovyStringLiteralManipulator"/>
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
* Copyright 2000-2009 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.plugins.groovy.unwrap;
|
||||
|
||||
import com.intellij.codeInsight.CodeInsightBundle;
|
||||
import com.intellij.codeInsight.unwrap.JavaUnwrapper;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrAnonymousClassDefinition;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class GroovyAnonymousUnwrapper extends GroovyUnwrapper {
|
||||
public GroovyAnonymousUnwrapper() {
|
||||
super(CodeInsightBundle.message("unwrap.anonymous"));
|
||||
}
|
||||
|
||||
public boolean isApplicableTo(PsiElement e) {
|
||||
return e instanceof GrAnonymousClassDefinition
|
||||
&& ((GrAnonymousClassDefinition)e).getMethods().length <= 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PsiElement collectAffectedElements(PsiElement e, List<PsiElement> toExtract) {
|
||||
super.collectAffectedElements(e, toExtract);
|
||||
return findElementToExtractFrom(e);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doUnwrap(PsiElement element, Context context) throws IncorrectOperationException {
|
||||
PsiElement from = findElementToExtractFrom(element);
|
||||
|
||||
for (PsiMethod m : ((PsiAnonymousClass)element).getMethods()) {
|
||||
//context.extractFromCodeBlock(m.getBody(), from);
|
||||
}
|
||||
|
||||
PsiElement next = from.getNextSibling();
|
||||
if (next instanceof PsiJavaToken && ((PsiJavaToken)next).getTokenType() == JavaTokenType.SEMICOLON) {
|
||||
context.deleteExactly(from.getNextSibling());
|
||||
}
|
||||
context.deleteExactly(from);
|
||||
}
|
||||
|
||||
private static PsiElement findElementToExtractFrom(PsiElement el) {
|
||||
if (el.getParent() instanceof PsiNewExpression) el = el.getParent();
|
||||
el = findTopmostParentOfType(el, PsiMethodCallExpression.class);
|
||||
el = findTopmostParentOfType(el, PsiAssignmentExpression.class);
|
||||
el = findTopmostParentOfType(el, PsiDeclarationStatement.class);
|
||||
|
||||
while (el.getParent() instanceof PsiExpressionStatement) {
|
||||
el = el.getParent();
|
||||
}
|
||||
|
||||
return el;
|
||||
}
|
||||
|
||||
private static PsiElement findTopmostParentOfType(PsiElement el, Class<? extends PsiElement> clazz) {
|
||||
while (true) {
|
||||
@SuppressWarnings({"unchecked"})
|
||||
PsiElement temp = PsiTreeUtil.getParentOfType(el, clazz, true, PsiAnonymousClass.class);
|
||||
if (temp == null || temp instanceof PsiFile) return el;
|
||||
el = temp;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Copyright 2000-2009 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.plugins.groovy.unwrap;
|
||||
|
||||
import com.intellij.codeInsight.CodeInsightBundle;
|
||||
import com.intellij.codeInsight.unwrap.JavaUnwrapper;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.formatter.GrControlStatement;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrBlockStatement;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrCatchClause;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrIfStatement;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrTryCatchStatement;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrClosableBlock;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrOpenBlock;
|
||||
|
||||
public class GroovyBracesUnwrapper extends GroovyUnwrapper {
|
||||
public GroovyBracesUnwrapper() {
|
||||
super(CodeInsightBundle.message("unwrap.braces"));
|
||||
}
|
||||
|
||||
public boolean isApplicableTo(PsiElement e) {
|
||||
if (e instanceof GrClosableBlock && !((GrClosableBlock)e).hasParametersSection()) {
|
||||
PsiElement parent = e.getParent();
|
||||
return parent instanceof GrOpenBlock || parent instanceof GrClosableBlock;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doUnwrap(PsiElement element, Context context) throws IncorrectOperationException {
|
||||
context.extractFromCodeBlock(((GrClosableBlock)element), element);
|
||||
context.delete(element);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Copyright 2000-2009 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.plugins.groovy.unwrap;
|
||||
|
||||
import com.intellij.codeInsight.CodeInsightBundle;
|
||||
import com.intellij.codeInsight.unwrap.JavaUnwrapper;
|
||||
import com.intellij.psi.PsiCatchSection;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiTryStatement;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrCatchClause;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrTryCatchStatement;
|
||||
|
||||
public class GroovyCatchRemover extends GroovyUnwrapper {
|
||||
public GroovyCatchRemover() {
|
||||
super(CodeInsightBundle.message("remove.catch"));
|
||||
}
|
||||
|
||||
public boolean isApplicableTo(PsiElement e) {
|
||||
return e instanceof GrCatchClause && tryHasSeveralCatches(e);
|
||||
}
|
||||
|
||||
private static boolean tryHasSeveralCatches(PsiElement el) {
|
||||
return ((GrTryCatchStatement)el.getParent()).getCatchClauses().length > 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doUnwrap(PsiElement element, Context context) throws IncorrectOperationException {
|
||||
context.delete(element);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright 2000-2009 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.plugins.groovy.unwrap;
|
||||
|
||||
import com.intellij.codeInsight.CodeInsightBundle;
|
||||
import com.intellij.codeInsight.unwrap.JavaUnwrapper;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrForStatement;
|
||||
|
||||
public class GroovyForUnwrapper extends GroovyUnwrapper {
|
||||
public GroovyForUnwrapper() {
|
||||
super(CodeInsightBundle.message("unwrap.for"));
|
||||
}
|
||||
|
||||
public boolean isApplicableTo(PsiElement e) {
|
||||
return e instanceof GrForStatement;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doUnwrap(PsiElement element, Context context) throws IncorrectOperationException {
|
||||
if (element instanceof GrForStatement) {
|
||||
context.extractFromBlockOrSingleStatement(((GrForStatement)element).getBody(), element);
|
||||
}
|
||||
|
||||
context.delete(element);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Copyright 2000-2009 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.plugins.groovy.unwrap;
|
||||
|
||||
import com.intellij.codeInsight.CodeInsightBundle;
|
||||
import com.intellij.codeInsight.unwrap.JavaUnwrapper;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiIfStatement;
|
||||
import com.intellij.psi.PsiStatement;
|
||||
import com.intellij.psi.util.PsiUtil;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrIfStatement;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrStatement;
|
||||
|
||||
public class GroovyIfUnwrapper extends GroovyUnwrapper {
|
||||
public GroovyIfUnwrapper() {
|
||||
super(CodeInsightBundle.message("unwrap.if"));
|
||||
}
|
||||
|
||||
public boolean isApplicableTo(PsiElement e) {
|
||||
return e instanceof GrIfStatement && !isElseBlock(e);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doUnwrap(PsiElement element, Context context) throws IncorrectOperationException {
|
||||
GrStatement then = ((GrIfStatement)element).getThenBranch();
|
||||
context.extractFromBlockOrSingleStatement(then, element);
|
||||
|
||||
context.delete(element);
|
||||
}
|
||||
}
|
||||
+59
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* Copyright 2000-2009 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.plugins.groovy.unwrap;
|
||||
|
||||
import com.intellij.codeInsight.CodeInsightBundle;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrArgumentList;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class GroovyMethodParameterUnwrapper extends GroovyUnwrapper {
|
||||
public GroovyMethodParameterUnwrapper() {
|
||||
super("");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription(PsiElement e) {
|
||||
String text = e.getText();
|
||||
if (text.length() > 20) text = text.substring(0, 17) + "...";
|
||||
return CodeInsightBundle.message("unwrap.method.parameter", text);
|
||||
}
|
||||
|
||||
public boolean isApplicableTo(PsiElement e) {
|
||||
return (e instanceof GrExpression) && e.getParent() instanceof GrArgumentList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PsiElement collectAffectedElements(PsiElement e, List<PsiElement> toExtract) {
|
||||
super.collectAffectedElements(e, toExtract);
|
||||
return e.getParent().getParent();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doUnwrap(PsiElement element, Context context) throws IncorrectOperationException {
|
||||
PsiElement methodCall = element.getParent().getParent();
|
||||
context.extractElement(element, methodCall);
|
||||
if (methodCall.getParent() instanceof GrArgumentList) {
|
||||
context.delete(methodCall);
|
||||
}
|
||||
else {
|
||||
context.deleteExactly(methodCall);
|
||||
}
|
||||
}
|
||||
}
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Copyright 2000-2009 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.plugins.groovy.unwrap;
|
||||
|
||||
import com.intellij.codeInsight.CodeInsightBundle;
|
||||
import com.intellij.codeInsight.unwrap.JavaUnwrapper;
|
||||
import com.intellij.psi.PsiCodeBlock;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiSynchronizedStatement;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrSynchronizedStatement;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrOpenBlock;
|
||||
|
||||
public class GroovySynchronizedUnwrapper extends GroovyUnwrapper {
|
||||
public GroovySynchronizedUnwrapper() {
|
||||
super(CodeInsightBundle.message("unwrap.synchronized"));
|
||||
}
|
||||
|
||||
public boolean isApplicableTo(PsiElement e) {
|
||||
return e instanceof GrSynchronizedStatement;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doUnwrap(PsiElement element, Context context) throws IncorrectOperationException {
|
||||
GrOpenBlock body = ((GrSynchronizedStatement)element).getBody();
|
||||
context.extractFromCodeBlock(body, element);
|
||||
|
||||
context.delete(element);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Copyright 2000-2009 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.plugins.groovy.unwrap;
|
||||
|
||||
import com.intellij.codeInsight.CodeInsightBundle;
|
||||
import com.intellij.codeInsight.unwrap.JavaUnwrapper;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiTryStatement;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrFinallyClause;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrTryCatchStatement;
|
||||
|
||||
public class GroovyTryUnwrapper extends GroovyUnwrapper {
|
||||
public GroovyTryUnwrapper() {
|
||||
super(CodeInsightBundle.message("unwrap.try"));
|
||||
}
|
||||
|
||||
public boolean isApplicableTo(PsiElement e) {
|
||||
return e instanceof GrTryCatchStatement;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doUnwrap(final PsiElement element, final Context context) throws IncorrectOperationException {
|
||||
GrTryCatchStatement trySt = (GrTryCatchStatement)element;
|
||||
|
||||
context.extractFromCodeBlock(trySt.getTryBlock(), trySt);
|
||||
|
||||
GrFinallyClause finallyClause = trySt.getFinallyClause();
|
||||
if (finallyClause != null) {
|
||||
context.extractFromCodeBlock(finallyClause.getBody(), trySt);
|
||||
}
|
||||
|
||||
context.delete(trySt);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Copyright 2000-2009 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.plugins.groovy.unwrap;
|
||||
|
||||
import com.intellij.codeInsight.unwrap.*;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.editor.SelectionModel;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class GroovyUnwrapDescriptor extends JavaUnwrapDescriptor {
|
||||
|
||||
@Override
|
||||
protected Unwrapper[] createUnwrappers() {
|
||||
return new Unwrapper[]{
|
||||
new GroovyIfUnwrapper(),
|
||||
new GroovyWhileUnwrapper(),
|
||||
new GroovyTryUnwrapper(),
|
||||
new GroovySynchronizedUnwrapper(),
|
||||
new GroovyMethodParameterUnwrapper(),
|
||||
new GroovyForUnwrapper(),
|
||||
new GroovyCatchRemover(),
|
||||
new GroovyBracesUnwrapper(),
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
/*
|
||||
* Copyright 2000-2009 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.plugins.groovy.unwrap;
|
||||
|
||||
import com.intellij.codeInsight.unwrap.AbstractUnwrapper;
|
||||
import com.intellij.codeInsight.unwrap.Unwrapper;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.plugins.groovy.lang.lexer.GroovyTokenTypes;
|
||||
import org.jetbrains.plugins.groovy.lang.lexer.TokenSets;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrBlockStatement;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrIfStatement;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrStatement;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrCodeBlock;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrOpenBlock;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.util.PsiUtil;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public abstract class GroovyUnwrapper extends AbstractUnwrapper<GroovyUnwrapper.Context> {
|
||||
public GroovyUnwrapper(String description) {
|
||||
super(description);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Context createContext(boolean isEffective) {
|
||||
return new Context(isEffective);
|
||||
}
|
||||
|
||||
public static boolean isElseBlock(@Nullable final PsiElement element) {
|
||||
if (element == null) return false;
|
||||
final PsiElement parent = element.getParent();
|
||||
return parent instanceof GrIfStatement && element == ((GrIfStatement)parent).getElseBranch();
|
||||
}
|
||||
|
||||
protected static class Context extends AbstractUnwrapper.AbstractContext {
|
||||
|
||||
public Context(boolean isEffective) {
|
||||
super(isEffective);
|
||||
}
|
||||
|
||||
public void extractFromBlockOrSingleStatement(GrStatement block, PsiElement from) throws IncorrectOperationException {
|
||||
if (block instanceof GrBlockStatement) {
|
||||
extractFromCodeBlock(((GrBlockStatement)block).getBlock(), from);
|
||||
}
|
||||
else if (block != null) {
|
||||
extract(block, block, from);
|
||||
}
|
||||
}
|
||||
|
||||
public void extractFromCodeBlock(GrCodeBlock block, PsiElement from) throws IncorrectOperationException {
|
||||
if (block == null) return;
|
||||
|
||||
PsiElement rBrace = block.getRBrace();
|
||||
PsiElement lBrace = block.getLBrace();
|
||||
|
||||
PsiElement firstBodyElement;
|
||||
if (lBrace == null) {
|
||||
firstBodyElement = null;
|
||||
}
|
||||
else {
|
||||
firstBodyElement = lBrace.getNextSibling();
|
||||
if (firstBodyElement == rBrace) {
|
||||
firstBodyElement = null;
|
||||
}
|
||||
}
|
||||
|
||||
PsiElement lastBodyElement;
|
||||
if (rBrace == null) {
|
||||
lastBodyElement = null;
|
||||
}
|
||||
else {
|
||||
lastBodyElement = rBrace.getPrevSibling();
|
||||
if (lastBodyElement == lBrace) {
|
||||
lastBodyElement = null;
|
||||
}
|
||||
}
|
||||
|
||||
extract(firstBodyElement, lastBodyElement, from);
|
||||
}
|
||||
|
||||
protected boolean isWhiteSpace(PsiElement element) {
|
||||
return PsiUtil.isLeafElementOfType(element, TokenSets.WHITE_SPACES_SET);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Copyright 2000-2009 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.plugins.groovy.unwrap;
|
||||
|
||||
import com.intellij.codeInsight.CodeInsightBundle;
|
||||
import com.intellij.psi.PsiDoWhileStatement;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiLoopStatement;
|
||||
import com.intellij.psi.PsiStatement;
|
||||
import com.intellij.psi.impl.source.tree.java.PsiWhileStatementImpl;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import org.jetbrains.plugins.groovy.lang.lexer.GroovyTokenTypes;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrStatement;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrWhileStatement;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.util.PsiUtil;
|
||||
|
||||
public class GroovyWhileUnwrapper extends GroovyUnwrapper {
|
||||
public GroovyWhileUnwrapper() {
|
||||
super(CodeInsightBundle.message("unwrap.while"));
|
||||
}
|
||||
|
||||
public boolean isApplicableTo(PsiElement e) {
|
||||
return e instanceof GrWhileStatement;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doUnwrap(PsiElement element, Context context) throws IncorrectOperationException {
|
||||
GrStatement body = ((GrWhileStatement)element).getBody();
|
||||
|
||||
context.extractFromBlockOrSingleStatement(body, element);
|
||||
context.delete(element);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user