From 4358cf961a3c3758b34ed45bc99728b7b4da2912 Mon Sep 17 00:00:00 2001 From: irengrig Date: Wed, 12 Sep 2012 18:41:09 +0400 Subject: [PATCH 01/12] IDEA-91360 Changes | Repository view: context menu item is not fully visible --- .../openapi/vcs/changes/committed/ClearCommittedAction.java | 5 +++++ 1 file changed, 5 insertions(+) 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); From dc7fe587d8059b8bc0f55db2dc7e19c7047256d7 Mon Sep 17 00:00:00 2001 From: irengrig Date: Wed, 12 Sep 2012 19:00:54 +0400 Subject: [PATCH 02/12] vcs: correct empty text for repository tab after cleanup action --- .../changes/committed/CommittedChangesPanel.java | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) 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); } From f66949fa6bd20321cd3293eb63eefdd6d737953c Mon Sep 17 00:00:00 2001 From: Anna Kozlova Date: Thu, 13 Sep 2012 16:59:55 +0400 Subject: [PATCH 03/12] treat captured wildcards depends on nested level (IDEA-91481) --- .../intellij/psi/util/TypesDistinctProver.java | 14 +++++++++----- .../genericsHighlighting/WildcardTypes.java | 15 +++++++++++++++ 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/java/java-psi-api/src/com/intellij/psi/util/TypesDistinctProver.java b/java/java-psi-api/src/com/intellij/psi/util/TypesDistinctProver.java index 89e6caad21ad..62914df25d0b 100644 --- a/java/java-psi-api/src/com/intellij/psi/util/TypesDistinctProver.java +++ b/java/java-psi-api/src/com/intellij/psi/util/TypesDistinctProver.java @@ -32,6 +32,10 @@ public class TypesDistinctProver { } public static boolean provablyDistinct(PsiType type1, PsiType type2) { + return provablyDistinct(type1, type2, 0); + } + + private static boolean provablyDistinct(PsiType type1, PsiType type2, int level) { if (type1 instanceof PsiClassType && ((PsiClassType)type1).resolve() instanceof PsiTypeParameter) return false; if (type2 instanceof PsiClassType && ((PsiClassType)type2).resolve() instanceof PsiTypeParameter) return false; if (type1 instanceof PsiWildcardType) { @@ -40,7 +44,7 @@ public class TypesDistinctProver { } if (type2 instanceof PsiCapturedWildcardType) { - return ((PsiWildcardType)type1).isExtends() || + return ((PsiWildcardType)type1).isExtends() && level > 0 || provablyDistinct((PsiWildcardType)type1, ((PsiCapturedWildcardType)type2).getWildcard()); } @@ -75,9 +79,9 @@ public class TypesDistinctProver { return proveArrayTypeDistinct(((PsiWildcardType)type1).getManager().getProject(), (PsiArrayType)type2, type1); } } - if (type1 instanceof PsiCapturedWildcardType) return provablyDistinct(((PsiCapturedWildcardType)type1).getWildcard(), type2); + if (type1 instanceof PsiCapturedWildcardType) return provablyDistinct(((PsiCapturedWildcardType)type1).getWildcard(), type2, level +1); - if (type2 instanceof PsiWildcardType || type2 instanceof PsiCapturedWildcardType) return provablyDistinct(type2, type1); + if (type2 instanceof PsiWildcardType || type2 instanceof PsiCapturedWildcardType) return provablyDistinct(type2, type1, level +1); final PsiClassType.ClassResolveResult classResolveResult1 = PsiUtil.resolveGenericsClassInType(type1); @@ -94,7 +98,7 @@ public class TypesDistinctProver { if (!TypeConversionUtil.isAssignable(type, substitutedType1 != null ? substitutedType1 : substitutedType2, false)) return true; } } else { - if (provablyDistinct(substitutedType1, substitutedType2)) return true; + if (provablyDistinct(substitutedType1, substitutedType2, level + 1)) return true; if (substitutedType1 instanceof PsiWildcardType && !((PsiWildcardType)substitutedType1).isBounded()) return true; } } @@ -121,7 +125,7 @@ public class TypesDistinctProver { if (boundClass1 != null && boundClass2 != null) { return proveExtendsBoundsDistinct(type1, type2, boundClass1, boundClass2); } - return provablyDistinct(extendsBound1, extendsBound2); + return provablyDistinct(extendsBound1, extendsBound2, 1); } if (type2.isExtends()) return provablyDistinct(type2, type1); if (type1.isExtends() && type2.isSuper()) { diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/WildcardTypes.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/WildcardTypes.java index 1a586323851c..f5483d41ed6f 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/WildcardTypes.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/WildcardTypes.java @@ -216,4 +216,19 @@ class IDEA73377 { //noinspection unchecked return (Iterator, ?>>)map.entrySet().iterator(); } +} + +class IDEA91481 { + void bar(){ + BeanBuilder builder = (BeanBuilder) builder(); + System.out.println(builder); + } + + BeanBuilder builder() { + return null; + } + + class BeanBuilder<T> {} + class Bean {} + class DirectBean extends Bean {} } \ No newline at end of file From 53271f96da5ecdb537c3312f99281353ffbbce20 Mon Sep 17 00:00:00 2001 From: peter Date: Thu, 13 Sep 2012 15:02:10 +0200 Subject: [PATCH 04/12] handle custom vcs exceptions in changes update in tests --- .../vcs/changes/ChangeListManagerImpl.java | 42 ++++++++++++------- .../vcs/impl/AbstractVcsHelperImpl.java | 20 +++++---- 2 files changed, 40 insertions(+), 22 deletions(-) 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/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() { From 904a27b36e9091357508e487cc37b451b967019e Mon Sep 17 00:00:00 2001 From: Max Medvedev Date: Thu, 13 Sep 2012 12:16:48 +0400 Subject: [PATCH 05/12] IDEA-90422 Groovy: Smart completion after "new " statement for variables without declared type --- .../GroovyExpectedTypesProvider.java | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) 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) { From 9ce7b737139d53deddd1c89616ecb92a97869573 Mon Sep 17 00:00:00 2001 From: Max Medvedev Date: Thu, 13 Sep 2012 14:04:57 +0400 Subject: [PATCH 06/12] test refactoring --- .../AddConstructorMatchingSuperTest.groovy | 11 ++-- .../intentions/AddReturnTypeFixTest.groovy | 15 ++--- .../ConvertConcatenationToGstringTest.groovy | 57 +++++++++---------- .../ConvertStringToMultilineTest.groovy | 3 +- .../GrBreakStringOnLineBreaksTest.groovy | 8 ++- .../intentions/GrIntentionTestCase.groovy | 31 ++++++---- .../groovy/intentions/InvertIfTest.groovy | 42 +++++++------- .../RemoveUnnecessarySemicolonTest.groovy | 5 +- .../ReplaceTernaryWithIfElseTest.groovy | 45 +++++++-------- 9 files changed, 107 insertions(+), 110 deletions(-) diff --git a/plugins/groovy/test/org/jetbrains/plugins/groovy/intentions/AddConstructorMatchingSuperTest.groovy b/plugins/groovy/test/org/jetbrains/plugins/groovy/intentions/AddConstructorMatchingSuperTest.groovy index 8c22c373be8a..7dc8e6ca6e83 100644 --- a/plugins/groovy/test/org/jetbrains/plugins/groovy/intentions/AddConstructorMatchingSuperTest.groovy +++ b/plugins/groovy/test/org/jetbrains/plugins/groovy/intentions/AddConstructorMatchingSuperTest.groovy @@ -26,11 +26,12 @@ import org.jetbrains.plugins.groovy.util.TestUtils public class AddConstructorMatchingSuperTest extends GrIntentionTestCase { private static final String HINT = "Create constructor matching super" - @Override - protected String getBasePath() { - return "${TestUtils.testDataPath}intentions/constructorMatchingSuper/" + AddConstructorMatchingSuperTest() { + super(HINT) } + final String basePath = TestUtils.testDataPath + 'intentions/constructorMatchingSuper/' + void testGroovyToGroovy() { doTextTest('''\ class Base { @@ -39,7 +40,7 @@ class Base { class Derived extends 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/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... inspections) { + protected void doTextTest(String before, String hint = myHint, String after, Class... 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... inspections) { + protected void doAntiTest(String before, String hint = myHint, Class... 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/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) { From f23c56fdea66b3679c993aea5cde095945ce1470 Mon Sep 17 00:00:00 2001 From: Max Medvedev Date: Thu, 13 Sep 2012 15:49:08 +0400 Subject: [PATCH 07/12] IDEA-90738 Split declaration handles tuple assignments without explicit tuple initializer --- .../GrSplitDeclarationIntention.java | 116 +++++++++++++----- .../impl/statements/GrVariableBaseImpl.java | 2 +- .../statements/GrVariableDeclarationBase.java | 11 ++ .../intentions/ConvertMapToClassTest.java | 2 +- .../intentions/GrSplitDeclarationTest.groovy | 68 ++++++++++ 5 files changed, 168 insertions(+), 31 deletions(-) create mode 100644 plugins/groovy/test/org/jetbrains/plugins/groovy/intentions/GrSplitDeclarationTest.groovy 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/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 GrStubElementBase list = 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 +''') + } + +} From 845e6995f01ab32e7767584d99491092b9c41c4d Mon Sep 17 00:00:00 2001 From: Roman Shevchenko Date: Wed, 12 Sep 2012 21:11:14 +0400 Subject: [PATCH 08/12] Cleanup --- .../openapi/vfs/impl/local/FileWatcher.java | 21 +++--- .../vfs/local/SymlinkHandlingTest.java | 31 +------- .../openapi/vfs/local/SymlinkTestCase.java | 74 +++++++++++++++++++ .../intellij/openapi/util/io/IoTestUtil.java | 8 ++ 4 files changed, 95 insertions(+), 39 deletions(-) create mode 100644 platform/platform-tests/testSrc/com/intellij/openapi/vfs/local/SymlinkTestCase.java diff --git a/platform/platform-impl/src/com/intellij/openapi/vfs/impl/local/FileWatcher.java b/platform/platform-impl/src/com/intellij/openapi/vfs/impl/local/FileWatcher.java index 6c58ea680f1e..e21c0819ae1b 100644 --- a/platform/platform-impl/src/com/intellij/openapi/vfs/impl/local/FileWatcher.java +++ b/platform/platform-impl/src/com/intellij/openapi/vfs/impl/local/FileWatcher.java @@ -41,6 +41,9 @@ import javax.swing.event.HyperlinkEvent; import java.io.*; import java.util.*; +import static com.intellij.util.containers.ContainerUtil.newArrayList; +import static com.intellij.util.containers.ContainerUtil.newArrayListWithExpectedSize; + /** * @author max */ @@ -63,17 +66,17 @@ public class FileWatcher { private final Object LOCK = new Object(); - private List myDirtyPaths = new ArrayList(); - private List myDirtyRecursivePaths = new ArrayList(); - private List myDirtyDirs = new ArrayList(); - private List myManualWatchRoots = new ArrayList(); + private List myDirtyPaths = newArrayList(); + private List myDirtyRecursivePaths = newArrayList(); + private List myDirtyDirs = newArrayList(); - private final List> myMapping = new ArrayList>(); - private List myRecursiveWatchRoots = new ArrayList(); - private List myFlatWatchRoots = new ArrayList(); + private List myManualWatchRoots = newArrayList(); + private List myRecursiveWatchRoots = newArrayList(); + private List myFlatWatchRoots = newArrayList(); - private final Collection myAllPaths = new ArrayList(2); - private final Collection myWatchedPaths = new ArrayList(2); + private final List> myMapping = newArrayList(); + private final Collection 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/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); + } + } + } } From bb101a434a672897494a66722475e7b6479f493c Mon Sep 17 00:00:00 2001 From: Roman Shevchenko Date: Thu, 13 Sep 2012 14:11:45 +0400 Subject: [PATCH 09/12] Tune inspection settings --- .idea/inspectionProfiles/idea_default.xml | 4 ++++ .idea/inspectionProfiles/idea_default_no_spellchecker.xml | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/.idea/inspectionProfiles/idea_default.xml b/.idea/inspectionProfiles/idea_default.xml index c56a697395e0..b559f6f3967f 100644 --- a/.idea/inspectionProfiles/idea_default.xml +++ b/.idea/inspectionProfiles/idea_default.xml @@ -578,6 +578,10 @@ + +