myAllPaths = newArrayListWithExpectedSize(2);
+ private final Collection myWatchedPaths = newArrayListWithExpectedSize(2);
private File executable;
private volatile Process notifierProcess;
diff --git a/platform/platform-tests/testSrc/com/intellij/openapi/vfs/local/SymlinkHandlingTest.java b/platform/platform-tests/testSrc/com/intellij/openapi/vfs/local/SymlinkHandlingTest.java
index 2ccaf209d938..d555ca58b96f 100644
--- a/platform/platform-tests/testSrc/com/intellij/openapi/vfs/local/SymlinkHandlingTest.java
+++ b/platform/platform-tests/testSrc/com/intellij/openapi/vfs/local/SymlinkHandlingTest.java
@@ -24,7 +24,6 @@ import com.intellij.openapi.vfs.LocalFileSystem;
import com.intellij.openapi.vfs.VfsUtilCore;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.openapi.vfs.VirtualFileVisitor;
-import com.intellij.testFramework.LightPlatformLangTestCase;
import com.intellij.util.Function;
import com.intellij.util.containers.ContainerUtil;
import com.intellij.util.containers.HashSet;
@@ -37,29 +36,8 @@ import java.util.Set;
import static com.intellij.openapi.util.io.FileUtil.createTempDirectory;
import static com.intellij.openapi.util.io.FileUtil.createTempFile;
import static com.intellij.openapi.util.io.IoTestUtil.createTempLink;
-import static com.intellij.openapi.util.io.IoTestUtil.createTestDir;
-
-public class SymlinkHandlingTest extends LightPlatformLangTestCase {
- private LocalFileSystem myFileSystem;
- private File myTempDir;
-
- @Override
- protected void setUp() throws Exception {
- super.setUp();
- myFileSystem = LocalFileSystem.getInstance();
- myTempDir = createTestDir("temp");
- }
-
- @Override
- protected void runTest() throws Throwable {
- if (SystemInfo.areSymLinksSupported) {
- super.runTest();
- }
- else {
- System.err.println("Skipped: " + getName());
- }
- }
+public class SymlinkHandlingTest extends SymlinkTestCase {
public void testMissingLink() throws Exception {
final File missingFile = new File(myTempDir, "missing_file");
assertTrue(missingFile.getPath(), !missingFile.exists() || missingFile.delete());
@@ -357,13 +335,6 @@ public class SymlinkHandlingTest extends LightPlatformLangTestCase {
return myFileSystem.findFileByPath(ioFile.getPath());
}
- private void refresh() {
- final String tempPath = FileUtil.getTempDirectory();
- final VirtualFile tempDir = myFileSystem.findFileByPath(tempPath);
- assertNotNull(tempPath, tempDir);
- tempDir.refresh(false, true);
- }
-
private static void assertBrokenLink(@NotNull final VirtualFile link) {
assertTrue(link.isSymLink());
assertEquals(0, link.getLength());
diff --git a/platform/platform-tests/testSrc/com/intellij/openapi/vfs/local/SymlinkTestCase.java b/platform/platform-tests/testSrc/com/intellij/openapi/vfs/local/SymlinkTestCase.java
new file mode 100644
index 000000000000..43ea8f829ae8
--- /dev/null
+++ b/platform/platform-tests/testSrc/com/intellij/openapi/vfs/local/SymlinkTestCase.java
@@ -0,0 +1,74 @@
+/*
+ * Copyright 2000-2012 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.openapi.vfs.local;
+
+import com.intellij.openapi.util.SystemInfo;
+import com.intellij.openapi.util.io.IoTestUtil;
+import com.intellij.openapi.vfs.LocalFileSystem;
+import com.intellij.openapi.vfs.VfsUtilCore;
+import com.intellij.openapi.vfs.VirtualFile;
+import com.intellij.openapi.vfs.VirtualFileVisitor;
+import com.intellij.testFramework.LightPlatformLangTestCase;
+
+import java.io.File;
+
+import static com.intellij.openapi.util.io.IoTestUtil.createTestDir;
+
+public abstract class SymlinkTestCase extends LightPlatformLangTestCase {
+ protected LocalFileSystem myFileSystem;
+ protected File myTempDir;
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ myFileSystem = LocalFileSystem.getInstance();
+ myTempDir = createTestDir("temp");
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ try {
+ IoTestUtil.delete(myTempDir);
+ }
+ finally {
+ super.tearDown();
+ }
+ }
+
+ @Override
+ protected void runTest() throws Throwable {
+ if (SystemInfo.areSymLinksSupported) {
+ super.runTest();
+ }
+ else {
+ System.err.println("Skipped: " + getName());
+ }
+ }
+
+ protected void refresh() {
+ refresh(false);
+ }
+
+ protected void refresh(boolean recursive) {
+ final VirtualFile tempDir = myFileSystem.findFileByIoFile(myTempDir);
+ assertNotNull(myTempDir.getPath(), tempDir);
+ tempDir.getChildren();
+ tempDir.refresh(false, true);
+ if (recursive) {
+ VfsUtilCore.visitChildrenRecursively(tempDir, new VirtualFileVisitor() { });
+ }
+ }
+}
diff --git a/platform/util-rt/src/com/intellij/util/Function.java b/platform/util-rt/src/com/intellij/util/Function.java
index fef2a94aaf2d..f3828f1f8867 100644
--- a/platform/util-rt/src/com/intellij/util/Function.java
+++ b/platform/util-rt/src/com/intellij/util/Function.java
@@ -25,19 +25,21 @@ import java.util.Collection;
public interface Function {
Result fun(Param param);
- /**
- * @see FunctionUtil#id()
- */
Function ID = new Function() {
public Object fun(final Object o) {
return o;
}
};
- /**
- * @see FunctionUtil#nullConstant()
- */
+
Function NULL = NullableFunction.NULL;
+ Function TO_STRING = new Function() {
+ @Override
+ public Object fun(Object o) {
+ return String.valueOf(o);
+ }
+ };
+
final class Self implements Function
{
@Override
public R fun(P p) {
diff --git a/platform/util/src/com/intellij/util/FunctionUtil.java b/platform/util/src/com/intellij/util/FunctionUtil.java
index 4faee47c5951..f3da5c8042f2 100644
--- a/platform/util/src/com/intellij/util/FunctionUtil.java
+++ b/platform/util/src/com/intellij/util/FunctionUtil.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2000-2011 JetBrains s.r.o.
+ * Copyright 2000-2012 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,20 +21,27 @@ import org.jetbrains.annotations.NotNull;
* @author nik
*/
public class FunctionUtil {
- private FunctionUtil() {
- }
+ private FunctionUtil() { }
@NotNull
public static Function id() {
- //noinspection unchecked
- return Function.ID;
+ @SuppressWarnings("unchecked") Function id = Function.ID;
+ return id;
}
+ @NotNull
public static NullableFunction nullConstant() {
- //noinspection unchecked
- return NullableFunction.NULL;
+ @SuppressWarnings("unchecked") NullableFunction function = NullableFunction.NULL;
+ return function;
}
+ @NotNull
+ public static Function string() {
+ @SuppressWarnings("unchecked") Function function = Function.TO_STRING;
+ return function;
+ }
+
+ @NotNull
public static Function constant(final B b) {
return new Function() {
@Override
@@ -54,5 +61,4 @@ public class FunctionUtil {
}
};
}
-
}
diff --git a/platform/util/testSrc/com/intellij/openapi/util/io/IoTestUtil.java b/platform/util/testSrc/com/intellij/openapi/util/io/IoTestUtil.java
index 218cce18738c..d18657bbef43 100644
--- a/platform/util/testSrc/com/intellij/openapi/util/io/IoTestUtil.java
+++ b/platform/util/testSrc/com/intellij/openapi/util/io/IoTestUtil.java
@@ -231,4 +231,12 @@ public class IoTestUtil {
assertTrue(file.getPath(), file.createNewFile());
return file;
}
+
+ public static void delete(final File... files) {
+ for (File file : files) {
+ if (file != null) {
+ FileUtil.delete(file);
+ }
+ }
+ }
}
diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ChangeListManagerImpl.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ChangeListManagerImpl.java
index 36d03cd5f7d4..d2e70bbcfd82 100644
--- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ChangeListManagerImpl.java
+++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ChangeListManagerImpl.java
@@ -37,6 +37,7 @@ import com.intellij.openapi.vcs.changes.conflicts.ChangelistConflictTracker;
import com.intellij.openapi.vcs.changes.ui.CommitHelper;
import com.intellij.openapi.vcs.checkin.CheckinEnvironment;
import com.intellij.openapi.vcs.checkin.CheckinHandler;
+import com.intellij.openapi.vcs.impl.AbstractVcsHelperImpl;
import com.intellij.openapi.vcs.impl.ContentRevisionCache;
import com.intellij.openapi.vcs.impl.ProjectLevelVcsManagerImpl;
import com.intellij.openapi.vcs.impl.VcsInitObject;
@@ -631,21 +632,7 @@ public class ChangeListManagerImpl extends ChangeListManagerEx implements Projec
changeProvider.getChanges(scope, builder, myUpdateChangesProgressIndicator, gate);
}
catch (final VcsException e) {
- LOG.info(e);
- if (e instanceof VcsConnectionProblem) {
- ApplicationManager.getApplication().invokeLater(new Runnable() {
- @Override
- public void run() {
- ((VcsConnectionProblem)e).attemptQuickFix(false);
- }
- });
- }
- if (myUpdateException == null) {
- if (ApplicationManager.getApplication().isUnitTestMode()) {
- e.printStackTrace();
- }
- myUpdateException = e;
- }
+ handleUpdateException(e);
}
}
} catch (Throwable t) {
@@ -658,6 +645,31 @@ public class ChangeListManagerImpl extends ChangeListManagerEx implements Projec
}
}
+ private void handleUpdateException(final VcsException e) {
+ LOG.info(e);
+
+ if (e instanceof VcsConnectionProblem) {
+ ApplicationManager.getApplication().invokeLater(new Runnable() {
+ @Override
+ public void run() {
+ ((VcsConnectionProblem)e).attemptQuickFix(false);
+ }
+ });
+ }
+
+ if (myUpdateException == null) {
+ if (ApplicationManager.getApplication().isUnitTestMode()) {
+ AbstractVcsHelper helper = AbstractVcsHelper.getInstance(myProject);
+ if (helper instanceof AbstractVcsHelperImpl && ((AbstractVcsHelperImpl)helper).handleCustom(e)) {
+ return;
+ }
+ //noinspection CallToPrintStackTrace
+ e.printStackTrace();
+ }
+ myUpdateException = e;
+ }
+ }
+
private void checkIfDisposed() {
if (myUpdater.isStopped()) throw new DisposedException();
}
diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/committed/ClearCommittedAction.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/committed/ClearCommittedAction.java
index e0a238ef34f8..39b068aabd28 100644
--- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/committed/ClearCommittedAction.java
+++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/committed/ClearCommittedAction.java
@@ -15,6 +15,7 @@
*/
package com.intellij.openapi.vcs.changes.committed;
+import com.intellij.icons.AllIcons;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.PlatformDataKeys;
@@ -30,6 +31,10 @@ import com.intellij.openapi.vcs.changes.ui.ChangesViewContentManager;
* Time: 4:53 PM
*/
public class ClearCommittedAction extends AnAction implements DumbAware {
+ public ClearCommittedAction() {
+ super("Clear", "Clears cached revisions", AllIcons.Vcs.Remove);
+ }
+
public void actionPerformed(AnActionEvent e) {
Project project = e.getData(PlatformDataKeys.PROJECT);
CommittedChangesPanel panel = ChangesViewContentManager.getInstance(project).getActiveComponent(CommittedChangesPanel.class);
diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/committed/CommittedChangesPanel.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/committed/CommittedChangesPanel.java
index a7f10368a98f..eb2fdf808f48 100644
--- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/committed/CommittedChangesPanel.java
+++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/committed/CommittedChangesPanel.java
@@ -193,7 +193,7 @@ public class CommittedChangesPanel extends JPanel implements TypeSafeDataProvide
ApplicationManager.getApplication().invokeLater(new Runnable() {
@Override
public void run() {
- updateFilteredModel(Collections.emptyList());
+ updateFilteredModel(Collections.emptyList(), true);
}
}, ModalityState.NON_MODAL, myProject.getDisposed());
}
@@ -214,7 +214,7 @@ public class CommittedChangesPanel extends JPanel implements TypeSafeDataProvide
cache.getProjectChangesAsync(mySettings, myMaxCount, cacheOnly,
new Consumer>() {
public void consume(final List committedChangeLists) {
- updateFilteredModel(committedChangeLists);
+ updateFilteredModel(committedChangeLists, false);
}
},
new Consumer>() {
@@ -254,11 +254,17 @@ public class CommittedChangesPanel extends JPanel implements TypeSafeDataProvide
}
}
- private void updateFilteredModel(List committedChangeLists) {
+ private void updateFilteredModel(List committedChangeLists, final boolean reset) {
if (committedChangeLists == null) {
return;
}
- myBrowser.getEmptyText().setText(VcsBundle.message("committed.changes.empty.message"));
+ final String emptyText;
+ if (reset) {
+ emptyText = VcsBundle.message("committed.changes.not.loaded.message");
+ } else {
+ emptyText = VcsBundle.message("committed.changes.empty.message");
+ }
+ myBrowser.getEmptyText().setText(emptyText);
myBrowser.setItems(committedChangeLists, CommittedChangesBrowserUseCase.COMMITTED);
}
diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/impl/AbstractVcsHelperImpl.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/impl/AbstractVcsHelperImpl.java
index aca2fdae7b63..c4703f55cab9 100644
--- a/platform/vcs-impl/src/com/intellij/openapi/vcs/impl/AbstractVcsHelperImpl.java
+++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/impl/AbstractVcsHelperImpl.java
@@ -92,12 +92,7 @@ public class AbstractVcsHelperImpl extends AbstractVcsHelper {
private static final Logger LOG = Logger.getInstance("#com.intellij.openapi.vcs.impl.AbstractVcsHelperImpl");
private final Project myProject;
- private Consumer myCustomHandler = new Consumer() {
- @Override
- public void consume(VcsException e) {
- throw new RuntimeException(e);
- }
- };
+ private Consumer myCustomHandler = null;
public AbstractVcsHelperImpl(Project project) {
myProject = project;
@@ -256,7 +251,10 @@ public class AbstractVcsHelperImpl extends AbstractVcsHelper {
final Consumer viewFiller) {
if (ApplicationManager.getApplication().isUnitTestMode()) {
if (!isEmpty) {
- myCustomHandler.consume(firstGetter.get());
+ VcsException exception = firstGetter.get();
+ if (!handleCustom(exception)) {
+ throw new RuntimeException(exception);
+ }
}
return;
}
@@ -276,6 +274,14 @@ public class AbstractVcsHelperImpl extends AbstractVcsHelper {
});
}
+ public boolean handleCustom(VcsException exception) {
+ if (myCustomHandler != null) {
+ myCustomHandler.consume(exception);
+ return true;
+ }
+ return false;
+ }
+
@Override
public void showErrors(final Map> exceptionGroups, @NotNull final String tabDisplayName) {
showErrorsImpl(exceptionGroups.isEmpty(), new Getter() {
diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/intentions/conversions/GrSplitDeclarationIntention.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/intentions/conversions/GrSplitDeclarationIntention.java
index 4f9f22dabd46..b508f5466d4c 100644
--- a/plugins/groovy/src/org/jetbrains/plugins/groovy/intentions/conversions/GrSplitDeclarationIntention.java
+++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/intentions/conversions/GrSplitDeclarationIntention.java
@@ -24,7 +24,10 @@ import org.jetbrains.plugins.groovy.intentions.GroovyIntentionsBundle;
import org.jetbrains.plugins.groovy.intentions.base.Intention;
import org.jetbrains.plugins.groovy.intentions.base.PsiElementPredicate;
import org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElementFactory;
+import org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.GrListOrMap;
+import org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.GrModifier;
import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrStatement;
+import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrTupleDeclaration;
import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrVariable;
import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrVariableDeclaration;
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression;
@@ -35,40 +38,84 @@ import org.jetbrains.plugins.groovy.refactoring.GroovyRefactoringUtil;
* @author Max Medvedev
*/
public class GrSplitDeclarationIntention extends Intention {
+
+
@Override
protected void processIntention(@NotNull PsiElement element, Project project, Editor editor) throws IncorrectOperationException {
- if (element instanceof GrVariableDeclaration) {
- GrVariable[] variables = ((GrVariableDeclaration)element).getVariables();
- if (variables.length == 1) {
- GrVariable var = variables[0];
- GrExpression initializer = var.getInitializerGroovy();
- if (initializer != null) {
- GrExpression assignment = GroovyPsiElementFactory.getInstance(project)
- .createExpressionFromText(var.getName() + " = " + initializer.getText());
- initializer.delete();
- element = GroovyRefactoringUtil.addBlockIntoParent(element);
- element.getParent().addAfter(assignment, element);
- }
+ if (!(element instanceof GrVariableDeclaration)) return;
+
+ GrVariableDeclaration declaration = (GrVariableDeclaration)element;
+
+ GrVariable[] variables = declaration.getVariables();
+ if (variables.length == 1) {
+ processSingleVar(project, declaration, variables[0]);
+ }
+ else if (variables.length > 1) {
+ GrTupleDeclaration tuple = declaration.getTupleDeclaration();
+ if (tuple == null || tuple.getInitializerGroovy() instanceof GrListOrMap) {
+ processMultipleVars(project, declaration);
}
- else if (variables.length > 1) {
- String modifiers = ((GrVariableDeclaration)element).getModifierList().getText();
- GrStatement[] sts = new GrStatement[variables.length];
- for (int i = 0; i < variables.length; i++) {
- sts[i] = createVarDeclaration(project, variables[i], modifiers);
- }
-
- element = GroovyRefactoringUtil.addBlockIntoParent(element);
-
- for (int i = sts.length - 1; i >= 0; i--) {
- element.getParent().addAfter(sts[i], element);
- }
-
- element.delete();
+ else {
+ processTuple(project, declaration);
}
}
}
- private static GrStatement createVarDeclaration(Project project, GrVariable variable, String modifiers) {
+ private static void processTuple(Project project, GrVariableDeclaration declaration) {
+ GrTupleDeclaration tuple = declaration.getTupleDeclaration();
+ assert tuple != null;
+ GrExpression initializer = tuple.getInitializerGroovy();
+ assert initializer != null;
+
+ GroovyPsiElementFactory factory = GroovyPsiElementFactory.getInstance(project);
+
+ GrVariable[] variables = declaration.getVariables();
+
+ StringBuilder assignmentBuilder = new StringBuilder();
+ assignmentBuilder.append('(');
+ for (GrVariable variable : variables) {
+ assignmentBuilder.append(variable.getName()).append(',');
+ }
+ assignmentBuilder.replace(assignmentBuilder.length() - 1, assignmentBuilder.length(), ")=");
+ assignmentBuilder.append(initializer.getText());
+
+ GrStatement assignment = factory.createStatementFromText(assignmentBuilder.toString());
+
+ declaration = GroovyRefactoringUtil.addBlockIntoParent(declaration);
+ declaration.getParent().addAfter(assignment, declaration);
+
+ initializer.delete();
+ }
+
+ private static void processMultipleVars(Project project, GrVariableDeclaration declaration) {
+ GrVariable[] variables = declaration.getVariables();
+ String modifiers = declaration.getModifierList().getText();
+ GrStatement[] sts = new GrStatement[variables.length];
+ for (int i = 0; i < variables.length; i++) {
+ sts[i] = createVarDeclaration(project, variables[i], modifiers, declaration.getTupleDeclaration() != null);
+ }
+
+ declaration = GroovyRefactoringUtil.addBlockIntoParent(declaration);
+
+ for (int i = sts.length - 1; i >= 0; i--) {
+ declaration.getParent().addAfter(sts[i], declaration);
+ }
+
+ declaration.delete();
+ }
+
+ private static void processSingleVar(Project project, GrVariableDeclaration declaration, GrVariable variable) {
+ GrExpression initializer = variable.getInitializerGroovy();
+ if (initializer != null) {
+ GroovyPsiElementFactory factory = GroovyPsiElementFactory.getInstance(project);
+ GrExpression assignment = factory.createExpressionFromText(variable.getName() + " = " + initializer.getText());
+ initializer.delete();
+ declaration = GroovyRefactoringUtil.addBlockIntoParent(declaration);
+ declaration.getParent().addAfter(assignment, declaration);
+ }
+ }
+
+ private static GrStatement createVarDeclaration(Project project, GrVariable variable, String modifiers, boolean isTuple) {
StringBuilder builder = new StringBuilder();
builder.append(modifiers).append(' ');
GrTypeElement typeElement = variable.getTypeElementGroovy();
@@ -80,7 +127,12 @@ public class GrSplitDeclarationIntention extends Intention {
if (initializer != null) {
builder.append('=').append(initializer.getText());
}
- return GroovyPsiElementFactory.getInstance(project).createStatementFromText(builder.toString());
+ GrVariableDeclaration var =
+ (GrVariableDeclaration)GroovyPsiElementFactory.getInstance(project).createStatementFromText(builder.toString());
+ if (isTuple && (variable.getDeclaredType() != null || var.getModifierList().getModifiers().length > 1)) {
+ ((GrVariableDeclaration)var).getModifierList().setModifierProperty(GrModifier.DEF, false);
+ }
+ return var;
}
private String myText = "";
@@ -100,7 +152,13 @@ public class GrSplitDeclarationIntention extends Intention {
if (element instanceof GrVariableDeclaration) {
GrVariable[] variables = ((GrVariableDeclaration)element).getVariables();
if (variables.length > 1 && GroovyRefactoringUtil.isLocalVariable(variables[0])) {
- myText = GroovyIntentionsBundle.message("split.into.separate.declaration");
+ GrTupleDeclaration tuple = ((GrVariableDeclaration)element).getTupleDeclaration();
+ if (tuple == null || tuple.getInitializerGroovy() instanceof GrListOrMap) {
+ myText = GroovyIntentionsBundle.message("split.into.separate.declaration");
+ }
+ else {
+ myText = GroovyIntentionsBundle.message("split.into.declaration.and.assignment");
+ }
return true;
}
else if (variables.length == 1 &&
diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/expectedTypes/GroovyExpectedTypesProvider.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/expectedTypes/GroovyExpectedTypesProvider.java
index 56b7fc306555..a10faba9c449 100644
--- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/expectedTypes/GroovyExpectedTypesProvider.java
+++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/expectedTypes/GroovyExpectedTypesProvider.java
@@ -48,8 +48,8 @@ import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrAn
import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMethod;
import org.jetbrains.plugins.groovy.lang.psi.api.types.GrTypeElement;
import org.jetbrains.plugins.groovy.lang.psi.controlFlow.Instruction;
-import org.jetbrains.plugins.groovy.lang.psi.impl.PsiImplUtil;
import org.jetbrains.plugins.groovy.lang.psi.dataFlow.types.TypeInferenceHelper;
+import org.jetbrains.plugins.groovy.lang.psi.impl.PsiImplUtil;
import org.jetbrains.plugins.groovy.lang.psi.impl.signatures.GrClosureSignatureUtil;
import org.jetbrains.plugins.groovy.lang.psi.impl.statements.expressions.TypesUtil;
import org.jetbrains.plugins.groovy.lang.psi.util.GroovyCommonClassNames;
@@ -443,13 +443,24 @@ public class GroovyExpectedTypesProvider {
public void visitAssignmentExpression(GrAssignmentExpression expression) {
GrExpression rValue = expression.getRValue();
+ GrExpression lValue = expression.getLValue();
if (myExpression.equals(rValue)) {
- PsiType lType = expression.getLValue().getType();
+ PsiType lType = lValue.getNominalType();
if (lType != null) {
myResult = new TypeConstraint[]{SubtypeConstraint.create(lType)};
}
+ else if (lValue instanceof GrReferenceExpression) {
+ GroovyResolveResult result = ((GrReferenceExpression)lValue).advancedResolve();
+ PsiElement resolved = result.getElement();
+ if (resolved instanceof GrVariable) {
+ PsiType type = ((GrVariable)resolved).getTypeGroovy();
+ if (type != null) {
+ myResult = new TypeConstraint[]{SubtypeConstraint.create(result.getSubstitutor().substitute(type))};
+ }
+ }
+ }
}
- else if (myExpression.equals(expression.getLValue())) {
+ else if (myExpression.equals(lValue)) {
if (rValue != null) {
PsiType rType = rValue.getType();
if (rType != null) {
diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/GrVariableBaseImpl.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/GrVariableBaseImpl.java
index a1928c7b87bf..643ea11bb143 100644
--- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/GrVariableBaseImpl.java
+++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/GrVariableBaseImpl.java
@@ -317,7 +317,7 @@ public abstract class GrVariableBaseImpl extends GrStubEl
public void deleteChildInternal(@NotNull ASTNode child) {
final PsiElement psi = child.getPsi();
if (psi == getInitializerGroovy()) {
- deleteChildInternal(findChildByType(GroovyTokenTypes.mASSIGN).getNode());
+ deleteChildInternal(findNotNullChildByType(GroovyTokenTypes.mASSIGN).getNode());
}
super.deleteChildInternal(child);
}
diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/GrVariableDeclarationBase.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/GrVariableDeclarationBase.java
index 9362d1839b36..c84b1389fd6b 100644
--- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/GrVariableDeclarationBase.java
+++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/GrVariableDeclarationBase.java
@@ -14,6 +14,7 @@ import com.intellij.util.IncorrectOperationException;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.plugins.groovy.lang.GrReferenceAdjuster;
+import org.jetbrains.plugins.groovy.lang.lexer.GroovyTokenTypes;
import org.jetbrains.plugins.groovy.lang.parser.GroovyElementTypes;
import org.jetbrains.plugins.groovy.lang.psi.GroovyElementVisitor;
import org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElementFactory;
@@ -111,6 +112,16 @@ public abstract class GrVariableDeclarationBase extends GrStubElementBaseds Base {
}
-''', HINT, '''\
+''', '''\
class Base {
Base(int p, @Anno int x) throws Exception {}
}
@@ -61,7 +62,7 @@ class Base {
doTextTest('''\
class Derived extends Base {
}
-''', HINT, '''\
+''', '''\
class Derived extends Base {
def Derived(int p, @Anno int x) throws Exception {
super(p, x)
diff --git a/plugins/groovy/test/org/jetbrains/plugins/groovy/intentions/AddReturnTypeFixTest.groovy b/plugins/groovy/test/org/jetbrains/plugins/groovy/intentions/AddReturnTypeFixTest.groovy
index 62b3aec044cd..1903b19533c1 100644
--- a/plugins/groovy/test/org/jetbrains/plugins/groovy/intentions/AddReturnTypeFixTest.groovy
+++ b/plugins/groovy/test/org/jetbrains/plugins/groovy/intentions/AddReturnTypeFixTest.groovy
@@ -21,24 +21,25 @@ import org.jetbrains.plugins.groovy.util.TestUtils;
* @author Max Medvedev
*/
public class AddReturnTypeFixTest extends GrIntentionTestCase {
- @Override
- protected String getBasePath() {
- return "${TestUtils.testDataPath}intentions/addReturnType/";
+ AddReturnTypeFixTest() {
+ super('Add return type')
}
+ final String basePath = TestUtils.testDataPath + 'intentions/addReturnType/'
+
void testSimple() {
- doTextTest('def foo() {}', 'Add return type', 'def void foo() {}')
+ doTextTest('def foo() {}', 'def void foo() {}')
}
void testTypePrams() {
- doTextTest('def foo() {}', 'Add return type', 'def void foo() {}')
+ doTextTest('def foo() {}', 'def void foo() {}')
}
void testReturnPrimitive() {
- doTextTest('def foo() {return 2}', 'Add return type', 'def int foo() {return 2}')
+ doTextTest('def foo() {return 2}', 'def int foo() {return 2}')
}
void testReturn() {
- doTextTest('def foo() {return "2"}', 'Add return type', 'def String foo() {return "2"}')
+ doTextTest('def foo() {return "2"}', 'def String foo() {return "2"}')
}
}
diff --git a/plugins/groovy/test/org/jetbrains/plugins/groovy/intentions/ConvertConcatenationToGstringTest.groovy b/plugins/groovy/test/org/jetbrains/plugins/groovy/intentions/ConvertConcatenationToGstringTest.groovy
index 4b5f76dd12e7..a5f6bfb901e8 100644
--- a/plugins/groovy/test/org/jetbrains/plugins/groovy/intentions/ConvertConcatenationToGstringTest.groovy
+++ b/plugins/groovy/test/org/jetbrains/plugins/groovy/intentions/ConvertConcatenationToGstringTest.groovy
@@ -33,49 +33,44 @@ import org.jetbrains.plugins.groovy.util.TestUtils
* @author Maxim.Medvedev
*/
public class ConvertConcatenationToGstringTest extends GrIntentionTestCase {
-
- private static final String CONVERT_TO_GSTRING = "Convert to GString";
+ ConvertConcatenationToGstringTest() {
+ super("Convert to GString")
+ }
@NotNull
- @Override
- protected LightProjectDescriptor getProjectDescriptor() {
- return new DefaultLightProjectDescriptor() {
- @Override
- public void configureModule(Module module, ModifiableRootModel model, ContentEntry contentEntry) {
- final Library.ModifiableModel modifiableModel = model.moduleLibraryTable.createLibrary("GROOVY").modifiableModel;
- final VirtualFile groovyJar = JarFileSystem.instance.refreshAndFindFileByPath(TestUtils.mockGroovy1_7LibraryName + "!/");
- modifiableModel.addRoot(groovyJar, OrderRootType.CLASSES);
- modifiableModel.commit();
- }
- };
+ final LightProjectDescriptor projectDescriptor = new DefaultLightProjectDescriptor() {
+ @Override
+ public void configureModule(Module module, ModifiableRootModel model, ContentEntry contentEntry) {
+ final Library.ModifiableModel modifiableModel = model.moduleLibraryTable.createLibrary("GROOVY").modifiableModel;
+ final VirtualFile groovyJar = JarFileSystem.instance.refreshAndFindFileByPath(TestUtils.mockGroovy1_7LibraryName + "!/");
+ modifiableModel.addRoot(groovyJar, OrderRootType.CLASSES);
+ modifiableModel.commit();
+ }
+ }
+
+ final String basePath = TestUtils.testDataPath + 'intentions/convertConcatenationToGstring/'
+
+ public void testSimpleCase() {
+ doTest(true);
}
- @Override
- protected String getBasePath() {
- return "${TestUtils.testDataPath}intentions/convertConcatenationToGstring/";
+ public void testVeryComplicatedCase() {
+ doTest(true);
}
- public void testSimpleCase() throws Exception {
- doTest(CONVERT_TO_GSTRING, true);
+ public void testQuotes() {
+ doTest(true);
}
- public void testVeryComplicatedCase() throws Exception {
- doTest(CONVERT_TO_GSTRING, true);
+ public void testQuotes2() {
+ doTest(true);
}
- public void testQuotes() throws Exception {
- doTest(CONVERT_TO_GSTRING, true);
- }
-
- public void testQuotes2() throws Exception {
- doTest(CONVERT_TO_GSTRING, true);
- }
-
- public void testQuotesInMultilineString() throws Exception {
- doTest(CONVERT_TO_GSTRING, true);
+ public void testQuotesInMultilineString() {
+ doTest(true);
}
public void testDot() {
- doTest(CONVERT_TO_GSTRING, true);
+ doTest(true);
}
}
diff --git a/plugins/groovy/test/org/jetbrains/plugins/groovy/intentions/ConvertMapToClassTest.java b/plugins/groovy/test/org/jetbrains/plugins/groovy/intentions/ConvertMapToClassTest.java
index 662f0611e98c..89edcef5a611 100644
--- a/plugins/groovy/test/org/jetbrains/plugins/groovy/intentions/ConvertMapToClassTest.java
+++ b/plugins/groovy/test/org/jetbrains/plugins/groovy/intentions/ConvertMapToClassTest.java
@@ -64,7 +64,7 @@ public class ConvertMapToClassTest extends GrIntentionTestCase {
doTest(true);
}
- private void doTest(boolean exists) {
+ protected void doTest(boolean exists) {
myFixture.configureByFile(getTestName(true) + "/Test.groovy");
String hint = GroovyIntentionsBundle.message("convert.map.to.class.intention.name");
final List list = myFixture.filterAvailableIntentions(hint);
diff --git a/plugins/groovy/test/org/jetbrains/plugins/groovy/intentions/ConvertStringToMultilineTest.groovy b/plugins/groovy/test/org/jetbrains/plugins/groovy/intentions/ConvertStringToMultilineTest.groovy
index ca1ce6ca1693..fde5b3670775 100644
--- a/plugins/groovy/test/org/jetbrains/plugins/groovy/intentions/ConvertStringToMultilineTest.groovy
+++ b/plugins/groovy/test/org/jetbrains/plugins/groovy/intentions/ConvertStringToMultilineTest.groovy
@@ -24,8 +24,7 @@ import org.jetbrains.plugins.groovy.intentions.conversions.strings.ConvertString
* @author Max Medvedev
*/
public class ConvertStringToMultilineTest extends LightGroovyTestCase {
- @Override
- protected String getBasePath() {''}
+ final String basePath = ''
void testPlainString() {
doTest("print 'abc'", "print '''abc'''")
diff --git a/plugins/groovy/test/org/jetbrains/plugins/groovy/intentions/GrBreakStringOnLineBreaksTest.groovy b/plugins/groovy/test/org/jetbrains/plugins/groovy/intentions/GrBreakStringOnLineBreaksTest.groovy
index 8f4c5afd3604..e61f7675f5ee 100644
--- a/plugins/groovy/test/org/jetbrains/plugins/groovy/intentions/GrBreakStringOnLineBreaksTest.groovy
+++ b/plugins/groovy/test/org/jetbrains/plugins/groovy/intentions/GrBreakStringOnLineBreaksTest.groovy
@@ -22,18 +22,20 @@ import org.jetbrains.plugins.groovy.util.TestUtils
* @author Max Medvedev
*/
public class GrBreakStringOnLineBreaksTest extends GrIntentionTestCase {
- private static final String message = GroovyIntentionsBundle.message('gr.break.string.on.line.breaks.intention.name')
+ GrBreakStringOnLineBreaksTest() {
+ super(GroovyIntentionsBundle.message('gr.break.string.on.line.breaks.intention.name'))
+ }
final String basePath = TestUtils.testDataPath + "intentions/breakStringOnLineBreaks/"
void testSimple() {
- doTextTest('''print 'abc\\ncde\'''', message, '''\
+ doTextTest('''print 'abc\\ncde\'''', '''\
print 'abc\\n' +
'cde\'''')
}
void testGString() {
- doTextTest('''print "a\\n$x bc\\n"''', message, '''\
+ doTextTest('''print "a\\n$x bc\\n"''', '''\
print "a\\n" +
"$x bc\\n"''')
}
diff --git a/plugins/groovy/test/org/jetbrains/plugins/groovy/intentions/GrIntentionTestCase.groovy b/plugins/groovy/test/org/jetbrains/plugins/groovy/intentions/GrIntentionTestCase.groovy
index becb31f9c61e..9d674e7eb16e 100644
--- a/plugins/groovy/test/org/jetbrains/plugins/groovy/intentions/GrIntentionTestCase.groovy
+++ b/plugins/groovy/test/org/jetbrains/plugins/groovy/intentions/GrIntentionTestCase.groovy
@@ -19,14 +19,27 @@ package org.jetbrains.plugins.groovy.intentions;
import com.intellij.codeInsight.intention.IntentionAction
import com.intellij.codeInspection.LocalInspectionTool
+import com.intellij.openapi.util.text.StringUtil
import com.intellij.psi.impl.source.PostprocessReformattingAspect
import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase
+import com.intellij.util.Function
+import org.jetbrains.annotations.NotNull
+import org.jetbrains.annotations.Nullable
/**
* @author Maxim.Medvedev
*/
public abstract class GrIntentionTestCase extends LightCodeInsightFixtureTestCase {
- protected void doTest(String hint, boolean intentionExists) {
+
+ @Nullable
+ protected final String myHint;
+
+ GrIntentionTestCase(@Nullable String hint = null) {
+ myHint = hint
+ }
+
+ protected void doTest(@NotNull String hint = myHint, boolean intentionExists) {
+ assertNotNull(hint)
myFixture.configureByFile(getTestName(false) + ".groovy");
final List list = myFixture.filterAvailableIntentions(hint);
if (intentionExists) {
@@ -34,18 +47,13 @@ public abstract class GrIntentionTestCase extends LightCodeInsightFixtureTestCas
PostprocessReformattingAspect.getInstance(project).doPostponedFormatting();
myFixture.checkResultByFile(getTestName(false) + "_after.groovy");
}
- else {
- if (list.size() > 0) {
- StringBuilder text = new StringBuilder("available intentions:");
- for (IntentionAction intentionAction : list) {
- text.append(intentionAction.familyName).append(", ");
- }
- fail(text.toString());
- }
+ else if (list.size() > 0) {
+ fail StringUtil.join(list, {it.familyName} as Function, ',')
}
}
- protected void doTextTest(String before, String hint, String after, Class extends LocalInspectionTool>... inspections) {
+ protected void doTextTest(String before, String hint = myHint, String after, Class extends LocalInspectionTool>... inspections) {
+ assertNotNull(hint)
myFixture.configureByText("a.groovy", before);
myFixture.enableInspections(inspections)
final List list = myFixture.filterAvailableIntentions(hint);
@@ -54,7 +62,8 @@ public abstract class GrIntentionTestCase extends LightCodeInsightFixtureTestCas
myFixture.checkResult(after);
}
- protected void doAntiTest(String before, String hint, Class extends LocalInspectionTool>... inspections) {
+ protected void doAntiTest(String before, String hint = myHint, Class extends LocalInspectionTool>... inspections) {
+ assertNotNull(hint)
myFixture.configureByText("a.groovy", before);
myFixture.enableInspections(inspections)
assertEmpty(myFixture.filterAvailableIntentions(hint));
diff --git a/plugins/groovy/test/org/jetbrains/plugins/groovy/intentions/GrSplitDeclarationTest.groovy b/plugins/groovy/test/org/jetbrains/plugins/groovy/intentions/GrSplitDeclarationTest.groovy
new file mode 100644
index 000000000000..25762628636e
--- /dev/null
+++ b/plugins/groovy/test/org/jetbrains/plugins/groovy/intentions/GrSplitDeclarationTest.groovy
@@ -0,0 +1,68 @@
+/*
+ * Copyright 2000-2012 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.intentions;
+
+/**
+ * @author Max Medvedev
+ */
+public class GrSplitDeclarationTest extends GrIntentionTestCase {
+
+ void testSingleVar() {
+ doTextTest('''\
+def abc = 5
+''', GroovyIntentionsBundle.message('split.into.declaration.and.assignment'), '''\
+def abc
+abc = 5
+''')
+ }
+
+ void testMultiVar() {
+ doTextTest('''\
+def abc = 5, cde = 7
+''', GroovyIntentionsBundle.message('split.into.separate.declaration'), '''\
+def abc = 5
+def cde = 7
+''')
+ }
+
+ void testTupleAssignment() {
+ doTextTest('''\
+def (abc, cde) = foo()
+''', GroovyIntentionsBundle.message('split.into.declaration.and.assignment'), '''\
+def (abc, cde)
+(abc, cde) = foo()
+''')
+ }
+
+ void testSimpleTupleAssignment() {
+ doTextTest('''\
+def (abc, cde) = [1, 2]
+''', GroovyIntentionsBundle.message('split.into.separate.declaration'), '''\
+def abc = 1
+def cde = 2
+''')
+ }
+
+ void testSimpleTupleAssignmentWithExplicitTypes() {
+ doTextTest('''\
+def (int abc, int cde) = [1, 2]
+''', GroovyIntentionsBundle.message('split.into.separate.declaration'), '''\
+int abc = 1
+int cde = 2
+''')
+ }
+
+}
diff --git a/plugins/groovy/test/org/jetbrains/plugins/groovy/intentions/InvertIfTest.groovy b/plugins/groovy/test/org/jetbrains/plugins/groovy/intentions/InvertIfTest.groovy
index a982565a217c..bc882de554a3 100644
--- a/plugins/groovy/test/org/jetbrains/plugins/groovy/intentions/InvertIfTest.groovy
+++ b/plugins/groovy/test/org/jetbrains/plugins/groovy/intentions/InvertIfTest.groovy
@@ -5,27 +5,23 @@ package org.jetbrains.plugins.groovy.intentions
*/
class InvertIfTest extends GrIntentionTestCase {
- String intentionName = GroovyIntentionsBundle.message("invert.if.intention.name")
+ InvertIfTest() {
+ super(GroovyIntentionsBundle.message("invert.if.intention.name"))
+ }
- public void testDoNotTriggerOnIncompleteIf() throws Exception {
+ public void testDoNotTriggerOnIncompleteIf() {
doAntiTest '''
if () {
succes
} else {
no_succes
}
-''', intentionName
+'''
}
- private void doTest(String before, String after) {
-
- doTextTest before, intentionName, after
- }
-
- public void testSimpleCondition() throws Exception {
-
- doTest '''
+ public void testSimpleCondition() {
+ doTextTest '''
if (a) {
succes
} else {
@@ -39,9 +35,9 @@ if (a) {
'''
}
- public void testCallCondition() throws Exception {
+ public void testCallCondition() {
- doTest '''
+ doTextTest '''
if (func()) {
succes
} else {
@@ -55,8 +51,8 @@ if (func()) {
'''
}
- public void testComplexCondition() throws Exception {
- doTest '''
+ public void testComplexCondition() {
+ doTextTest '''
if (a && b) {
succes
} else {
@@ -70,8 +66,8 @@ if (a && b) {
'''
}
- public void testNegatedComplexCondition() throws Exception {
- doTest '''
+ public void testNegatedComplexCondition() {
+ doTextTest '''
if (!(a && b)) {
succes
} else {
@@ -85,8 +81,8 @@ if (!(a && b)) {
'''
}
- public void testNegatedSimpleCondition() throws Exception {
- doTest '''
+ public void testNegatedSimpleCondition() {
+ doTextTest '''
if (!a) {
succes
} else {
@@ -100,8 +96,8 @@ if (!a) {
'''
}
- public void testNoElseBlock() throws Exception {
- doTest '''
+ public void testNoElseBlock() {
+ doTextTest '''
if (a) {
succes
}
@@ -112,8 +108,8 @@ if (a) {
'''
}
- public void testEmptyThenBlockIsRemoved() throws Exception {
- doTest '''
+ public void testEmptyThenBlockIsRemoved() {
+ doTextTest '''
if (a) {
} else {
no_succes
diff --git a/plugins/groovy/test/org/jetbrains/plugins/groovy/intentions/RemoveUnnecessarySemicolonTest.groovy b/plugins/groovy/test/org/jetbrains/plugins/groovy/intentions/RemoveUnnecessarySemicolonTest.groovy
index 8955a0e2b6f7..8df308826ace 100644
--- a/plugins/groovy/test/org/jetbrains/plugins/groovy/intentions/RemoveUnnecessarySemicolonTest.groovy
+++ b/plugins/groovy/test/org/jetbrains/plugins/groovy/intentions/RemoveUnnecessarySemicolonTest.groovy
@@ -25,10 +25,7 @@ import org.jetbrains.plugins.groovy.util.TestUtils
class RemoveUnnecessarySemicolonTest extends LightCodeInsightFixtureTestCase {
private static final String hint = GroovyIntentionsBundle.message('remove.unnecessary.semicolons.name');
- @Override
- protected String getBasePath() {
- return "${TestUtils.testDataPath}intentions/removeUnnecessaryBraces/";
- }
+ final String basePath = TestUtils.testDataPath + 'intentions/removeUnnecessaryBraces/'
void testSimpleCase1() {
doTest('print 2;\nprint 3', 'print 2\nprint 3')
diff --git a/plugins/groovy/test/org/jetbrains/plugins/groovy/intentions/ReplaceTernaryWithIfElseTest.groovy b/plugins/groovy/test/org/jetbrains/plugins/groovy/intentions/ReplaceTernaryWithIfElseTest.groovy
index 76ebf65914d2..e6af2156271c 100644
--- a/plugins/groovy/test/org/jetbrains/plugins/groovy/intentions/ReplaceTernaryWithIfElseTest.groovy
+++ b/plugins/groovy/test/org/jetbrains/plugins/groovy/intentions/ReplaceTernaryWithIfElseTest.groovy
@@ -19,10 +19,11 @@ package org.jetbrains.plugins.groovy.intentions
* @author Andreas Arledal
*/
class ReplaceTernaryWithIfElseTest extends GrIntentionTestCase {
+ ReplaceTernaryWithIfElseTest() {
+ super(GroovyIntentionsBundle.message("replace.ternary.with.if.else.intention.name"))
+ }
- String intentionName = GroovyIntentionsBundle.message("replace.ternary.with.if.else.intention.name")
-
-// public void testDoNotTriggerOnIncompleteIf() throws Exception {
+// public void testDoNotTriggerOnIncompleteIf() {
// doAntiTest '''
//if () {
// succes
@@ -33,20 +34,16 @@ class ReplaceTernaryWithIfElseTest extends GrIntentionTestCase {
//
// }
- public void testDoNotTriggerOnIncompleteTernary() throws Exception {
+ public void testDoNotTriggerOnIncompleteTernary() {
doAntiTest '''
return aaa ? bbb
-''', intentionName
+'''
}
- private void doTest(String before, String after) {
+
+ public void testSimpleCondition() {
- doTextTest before, intentionName, after
- }
-
- public void testSimpleCondition() throws Exception {
-
- doTest '''
+ doTextTest '''
return aaa ? bbb : ccc
''', '''\
if (aaa) {
@@ -57,9 +54,9 @@ if (aaa) {
'''
}
- public void testCaretAfterQuestionMark() throws Exception {
+ public void testCaretAfterQuestionMark() {
- doTest '''
+ doTextTest '''
return aaa ? bbb : ccc
''', '''\
if (aaa) {
@@ -70,9 +67,9 @@ if (aaa) {
'''
}
- public void testCaretInfrontOfConditional() throws Exception {
+ public void testCaretInfrontOfConditional() {
- doTest '''
+ doTextTest '''
return aaa ? bbb : ccc
''', '''\
if (aaa) {
@@ -83,9 +80,9 @@ if (aaa) {
'''
}
- public void testCaretInfrontOfElse() throws Exception {
+ public void testCaretInfrontOfElse() {
- doTest '''
+ doTextTest '''
return aaa ? bbb : ccc
''', '''\
if (aaa) {
@@ -96,9 +93,9 @@ if (aaa) {
'''
}
- public void testCaretAfterElse() throws Exception {
+ public void testCaretAfterElse() {
- doTest '''
+ doTextTest '''
return aaa ? bbb : ccc
''', '''\
if (aaa) {
@@ -109,9 +106,9 @@ if (aaa) {
'''
}
- public void testCaretBeforeElseReturn() throws Exception {
+ public void testCaretBeforeElseReturn() {
- doTest '''
+ doTextTest '''
return aaa ? bbb : ccc
''', '''\
if (aaa) {
@@ -122,9 +119,9 @@ if (aaa) {
'''
}
- public void testCaretBeforeReturnStatement() throws Exception {
+ public void testCaretBeforeReturnStatement() {
- doTest '''
+ doTextTest '''
return aaa ? bbb : ccc
''', '''\
if (aaa) {