diff options
Diffstat (limited to 'java/java-tests/testSrc/com')
20 files changed, 540 insertions, 238 deletions
diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/AddAnnotationFixTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/AddAnnotationFixTest.java index 231a0cd45c0a..ec8b8dd49284 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/AddAnnotationFixTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/AddAnnotationFixTest.java @@ -27,7 +27,6 @@ import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.application.Result; import com.intellij.openapi.application.ex.PathManagerEx; import com.intellij.openapi.command.WriteCommandAction; -import com.intellij.openapi.editor.CaretModel; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.fileEditor.FileDocumentManager; import com.intellij.openapi.module.Module; @@ -51,6 +50,7 @@ import com.intellij.testFramework.PsiTestUtil; import com.intellij.testFramework.UsefulTestCase; import com.intellij.testFramework.builders.JavaModuleFixtureBuilder; import com.intellij.testFramework.fixtures.*; +import com.intellij.util.ObjectUtils; import com.intellij.util.messages.MessageBusConnection; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; @@ -122,13 +122,7 @@ public class AddAnnotationFixTest extends UsefulTestCase { @NotNull private PsiModifierListOwner getOwner() { - CaretModel caretModel = myFixture.getEditor().getCaretModel(); - int position = caretModel.getOffset(); - PsiElement element = myFixture.getFile().findElementAt(position); - assert element != null; - PsiModifierListOwner container = AddAnnotationPsiFix.getContainer(element); - assert container != null; - return container; + return ObjectUtils.assertNotNull(AddAnnotationPsiFix.getContainer(myFixture.getFile(), myFixture.getCaretOffset())); } private void startListening(@NotNull final List<Trinity<PsiModifierListOwner, String, Boolean>> expectedSequence) { diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/ImplementMethodsTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/ImplementMethodsTest.java index b5ab59a09c2a..6fd655344758 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/ImplementMethodsTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/ImplementMethodsTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2013 JetBrains s.r.o. + * Copyright 2000-2014 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,13 +15,12 @@ */ package com.intellij.codeInsight; -import com.intellij.codeInsight.daemon.quickFix.LightQuickFixAvailabilityTestCase; +import com.intellij.codeInsight.daemon.quickFix.LightQuickFixParameterizedTestCase; /** - * User: anna - * Date: 10/7/11 + * @author anna */ -public class ImplementMethodsTest extends LightQuickFixAvailabilityTestCase { +public class ImplementMethodsTest extends LightQuickFixParameterizedTestCase { public void test() throws Exception { doAllTests(); } diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/completion/JavaAutoPopupTest.groovy b/java/java-tests/testSrc/com/intellij/codeInsight/completion/JavaAutoPopupTest.groovy index 4e8961dbe192..0b12b544bbfd 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/completion/JavaAutoPopupTest.groovy +++ b/java/java-tests/testSrc/com/intellij/codeInsight/completion/JavaAutoPopupTest.groovy @@ -52,6 +52,7 @@ import com.intellij.psi.PsiFile import com.intellij.psi.PsiJavaFile import com.intellij.psi.statistics.StatisticsManager import com.intellij.psi.statistics.impl.StatisticsManagerImpl +import com.intellij.testFramework.EditorTestUtil import com.intellij.util.containers.ContainerUtil import org.jetbrains.annotations.NotNull @@ -1141,6 +1142,56 @@ class Foo {{ }}''' } + public void testMulticaret() { + doTestMulticaret """ +class Foo {{ + <selection>t<caret></selection>x; + <selection>t<caret></selection>x; +}}""", '\n', ''' +class Foo {{ + toString()<caret>x; + toString()<caret>x; +}}''' + } + + public void testMulticaretTab() { + doTestMulticaret """ +class Foo {{ + <selection>t<caret></selection>x; + <selection>t<caret></selection>x; +}}""", '\t', ''' +class Foo {{ + toString()<caret>; + toString()<caret>; +}}''' + } + + public void testMulticaretBackspace() { + doTestMulticaret """ +class Foo {{ + <selection>t<caret></selection>; + <selection>t<caret></selection>; +}}""", '\b\t', ''' +class Foo {{ + toString()<caret>; + toString()<caret>; +}}''' + } + + private doTestMulticaret(final String textBefore, final String toType, final String textAfter) { + EditorTestUtil.enableMultipleCarets() + try { + myFixture.configureByText "a.java", textBefore + type 'toStr' + assert lookup + type toType + myFixture.checkResult textAfter + } + finally { + EditorTestUtil.disableMultipleCarets() + } + } + private doTestBlockSelection(final String textBefore, final String toType, final String textAfter) { myFixture.configureByText "a.java", textBefore edt { diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/completion/NormalCompletionTest.groovy b/java/java-tests/testSrc/com/intellij/codeInsight/completion/NormalCompletionTest.groovy index f07a9635da0c..35b71f8cc33b 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/completion/NormalCompletionTest.groovy +++ b/java/java-tests/testSrc/com/intellij/codeInsight/completion/NormalCompletionTest.groovy @@ -1403,6 +1403,33 @@ class Foo {{ } } + public void testPrimitiveSquareBracketWhenMultipleCaretsAreEnabled() { + EditorTestUtil.enableMultipleCarets() + try { + configureByFile("PrimitiveSquareBracket.java"); + type('['); + checkResultByFile("PrimitiveSquareBracket_after.java"); + } + finally { + EditorTestUtil.disableMultipleCarets() + } + } + + public void testMulticaretTyping() { + EditorTestUtil.enableMultipleCarets() + try { + configure() + assert lookup + type('p') + assert lookup + type('\n') + checkResult() + } + finally { + EditorTestUtil.disableMultipleCarets() + } + } + public void "test complete lowercase class name"() { myFixture.addClass("package foo; public class myClass {}") myFixture.configureByText "a.java", """ diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/AnnotationsHighlightingTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/AnnotationsHighlightingTest.java index 1868d2196d7c..964566fcf5ff 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/AnnotationsHighlightingTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/AnnotationsHighlightingTest.java @@ -39,6 +39,8 @@ public class AnnotationsHighlightingTest extends LightDaemonAnalyzerTestCase { public void testInapplicable() { doTest(false); } public void testDuplicateAttribute() { doTest(false); } public void testDuplicateTarget() { doTest(false); } + public void testPingPongAnnotationTypesDependencies() { doTest(false);} + public void testClashMethods() { doTest(false);} public void testInvalidPackageAnnotationTarget() { doTest(BASE_PATH + "/" + getTestName(true) + "/package-info.java", false, false); } public void testPackageAnnotationNotInPackageInfo() { doTest(BASE_PATH + "/" + getTestName(true) + "/notPackageInfo.java", false, false); } @@ -46,9 +48,6 @@ public class AnnotationsHighlightingTest extends LightDaemonAnalyzerTestCase { public void testTypeAnnotations() { doTest8(false); } public void testRepeatable() { doTest8(false); } - public void testPingPongAnnotationTypesDependencies() { doTest(false);} - public void testClashMethods() { doTest(false);} - private void doTest(boolean checkWarnings) { setLanguageLevel(LanguageLevel.JDK_1_7); doTest(BASE_PATH + "/" + getTestName(true) + ".java", checkWarnings, false); diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/ImportHelperTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/ImportHelperTest.java index b50052b71750..80448f9d3a96 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/ImportHelperTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/ImportHelperTest.java @@ -368,7 +368,7 @@ public class ImportHelperTest extends DaemonAnalyzerTestCase { public void testAutoImportOfGenericReference() throws Throwable { - @NonNls final String text = "class S {{ new ArrayList<caret><> }}"; + @NonNls final String text = "class S {{ new ArrayList<caret><String> }}"; configureByText(StdFileTypes.JAVA, text); boolean old = CodeInsightSettings.getInstance().ADD_UNAMBIGIOUS_IMPORTS_ON_THE_FLY; CodeInsightSettings.getInstance().ADD_UNAMBIGIOUS_IMPORTS_ON_THE_FLY = true; diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/FunctionalTypeWildcardParameterizationTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/FunctionalTypeWildcardParameterizationTest.java new file mode 100644 index 000000000000..599ae74cd00d --- /dev/null +++ b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/FunctionalTypeWildcardParameterizationTest.java @@ -0,0 +1,48 @@ +/* + * Copyright 2000-2014 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.codeInsight.daemon.lambda; + +import com.intellij.codeInsight.daemon.LightDaemonAnalyzerTestCase; +import com.intellij.openapi.projectRoots.JavaSdkVersion; +import com.intellij.openapi.projectRoots.Sdk; +import com.intellij.testFramework.IdeaTestUtil; +import org.jetbrains.annotations.NonNls; + +public class FunctionalTypeWildcardParameterizationTest extends LightDaemonAnalyzerTestCase { + @NonNls static final String BASE_PATH = "/codeInsight/daemonCodeAnalyzer/lambda/wildcardParametrization"; + + public void testNonWildcardParametrization() throws Exception { + doTest(); + } + + public void testLambdaFormalParamTypesParametrization() throws Exception { + doTest(); + } + + public void testPrimitiveParameterTypes() throws Exception { + doTest(); + } + + private void doTest() { + IdeaTestUtil.setTestVersion(JavaSdkVersion.JDK_1_8, getModule(), getTestRootDisposable()); + doTestNewInference(BASE_PATH + "/" + getTestName(false) + ".java", false, false); + } + + @Override + protected Sdk getProjectJDK() { + return IdeaTestUtil.getMockJdk18(); + } +} diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/GraphInferenceHighlightingTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/GraphInferenceHighlightingTest.java index 1119a0d6d4df..8af0821571d6 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/GraphInferenceHighlightingTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/GraphInferenceHighlightingTest.java @@ -28,7 +28,7 @@ public class GraphInferenceHighlightingTest extends LightDaemonAnalyzerTestCase doTest(); } - public void _testNestedCallsSameMethod() throws Exception { + public void testNestedCallsSameMethod() throws Exception { doTest(); } @@ -160,6 +160,14 @@ public class GraphInferenceHighlightingTest extends LightDaemonAnalyzerTestCase doTest(); } + public void testLiftedCaptureToOuterCall() throws Exception { + doTest(); + } + + public void testSiteSubstitutionForReturnConstraint() throws Exception { + doTest(); + } + private void doTest() throws Exception { doTest(false); } diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/NewLambdaHighlightingTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/NewLambdaHighlightingTest.java index 89ddef20df0e..826193c90f90 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/NewLambdaHighlightingTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/NewLambdaHighlightingTest.java @@ -138,6 +138,14 @@ public class NewLambdaHighlightingTest extends LightDaemonAnalyzerTestCase { doTest(); } + public void testDiamondInLambdaReturn() throws Exception { + doTest(); + } + + public void testIDEA118965() throws Exception { + doTest(); + } + private void doTest() { doTest(false); } diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/NewMethodRefHighlightingTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/NewMethodRefHighlightingTest.java index e944269c098b..83f0dfac5c1e 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/NewMethodRefHighlightingTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/NewMethodRefHighlightingTest.java @@ -173,6 +173,14 @@ public class NewMethodRefHighlightingTest extends LightDaemonAnalyzerTestCase { doTest(); } + public void testReturnTypeCheckForRawReceiver() throws Exception { + doTest(); + } + + public void testStaticNonStaticReferenceTypeAmbiguity() throws Exception { + doTest(); + } + private void doTest() { doTest(false); } diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/navigation/JavaGotoSuperTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/navigation/JavaGotoSuperTest.java new file mode 100644 index 000000000000..313720456ae5 --- /dev/null +++ b/java/java-tests/testSrc/com/intellij/codeInsight/navigation/JavaGotoSuperTest.java @@ -0,0 +1,52 @@ +package com.intellij.codeInsight.navigation; + +import com.intellij.JavaTestUtil; +import com.intellij.codeInsight.CodeInsightActionHandler; +import com.intellij.codeInsight.daemon.LightDaemonAnalyzerTestCase; +import com.intellij.codeInsight.daemon.LineMarkerInfo; +import com.intellij.codeInsight.daemon.impl.DaemonCodeAnalyzerImpl; +import com.intellij.lang.CodeInsightActions; +import com.intellij.lang.java.JavaLanguage; +import com.intellij.openapi.editor.Document; +import org.jetbrains.annotations.NotNull; + +import java.util.List; + +public class JavaGotoSuperTest extends LightDaemonAnalyzerTestCase { + @NotNull + @Override + protected String getTestDataPath() { + return JavaTestUtil.getJavaTestDataPath(); + } + + protected String getBasePath() { + return "/codeInsight/gotosuper/"; + } + + public void testLambda() throws Throwable { + doTest(); + } + + public void testLambdaMarker() throws Exception { + configureByFile(getBasePath() + getTestName(false) + ".java"); + int offset = myEditor.getCaretModel().getOffset(); + + doHighlighting(); + Document document = getEditor().getDocument(); + List<LineMarkerInfo> markers = DaemonCodeAnalyzerImpl.getLineMarkers(document, getProject()); + for (LineMarkerInfo info : markers) { + if (info.endOffset >= offset && info.startOffset <= offset) { + assertEquals("<html><body>Overrides method in 'I'</body></html>", info.getLineMarkerTooltip()); + return; + } + } + fail("Gutter expected"); + } + + private void doTest() throws Throwable { + configureByFile(getBasePath() + getTestName(false) + ".java"); + final CodeInsightActionHandler handler = CodeInsightActions.GOTO_SUPER.forLanguage(JavaLanguage.INSTANCE); + handler.invoke(getProject(), getEditor(), getFile()); + checkResultByFile(getBasePath() + getTestName(false) + ".after.java"); + } +} diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/psi/AnnotatedTypeTest.groovy b/java/java-tests/testSrc/com/intellij/codeInsight/psi/AnnotatedTypeTest.groovy index f186f9e8f5c8..6373bc3ce307 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/psi/AnnotatedTypeTest.groovy +++ b/java/java-tests/testSrc/com/intellij/codeInsight/psi/AnnotatedTypeTest.groovy @@ -1,5 +1,5 @@ /* - * Copyright 2000-2013 JetBrains s.r.o. + * Copyright 2000-2014 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,15 +15,22 @@ */ package com.intellij.codeInsight.psi -import com.intellij.psi.PsiElement -import com.intellij.psi.PsiFile +import com.intellij.pom.java.LanguageLevel +import com.intellij.psi.* +import com.intellij.psi.impl.source.PsiImmediateClassType import com.intellij.testFramework.LightIdeaTestCase -@SuppressWarnings(["GrUnresolvedAccess", "GroovyAssignabilityCheck"]) +@SuppressWarnings("GroovyAssignabilityCheck") class AnnotatedTypeTest extends LightIdeaTestCase { + private PsiFile context + private PsiElementFactory factory + + public void setUp() throws Exception { + super.setUp() + factory = javaFacade.elementFactory + context = createFile("typeCompositionTest.java", """ +package pkg; - public void testTypeComposition() { - PsiFile context = createFile("typeCompositionTest.java", """ import java.lang.annotation.*; import static java.lang.annotation.ElementType.*; @@ -33,31 +40,55 @@ import static java.lang.annotation.ElementType.*; class E1 extends Exception { } class E2 extends Exception { } """) - PsiElement psi + } + + public void testPrimitiveArrayType() { + doTest("@A @TA(1) int @TA(2) [] a", "@pkg.TA(1) int @pkg.TA(2) []", "int[]") + } - psi = javaFacade.elementFactory.createStatementFromText("@A @TA(1) int @TA(2) [] a", context) - assertEquals("@TA(1) int @TA(2) []", psi.declaredElements[0].type.presentableText) + public void testEllipsisType() { + def psi = factory.createParameterFromText("@TA int @TA ... p", context) + assertTypeText(psi.type, "@pkg.TA int @pkg.TA ...", "int...") + } - psi = javaFacade.elementFactory.createStatementFromText("try { } catch (@A @TA(1) E1 | @TA(2) E2 e) { }", context) - assertEquals("@TA(1) E1 | @TA(2) E2", psi.catchBlockParameters[0].type.presentableText) + public void testClassReferenceType() { + doTest("@A @TA(1) String s", "java.lang.@pkg.TA(1) String", "java.lang.String") + doTest("@A java.lang.@TA(1) String s", "java.lang.@pkg.TA(1) String", "java.lang.String") + } - psi = javaFacade.elementFactory.createStatementFromText("@A @TA(1) String @TA(2) [] f @TA(3) []", context) - assertEquals("@TA(1) String @TA(2) [] @TA(3) []", psi.declaredElements[0].type.presentableText) + public void testCStyleArrayType() { + doTest("@A @TA(1) String @TA(2) [] f @TA(3) []", "java.lang.@pkg.TA(1) String @pkg.TA(2) [] @pkg.TA(3) []", "java.lang.String[][]") + } - psi = javaFacade.elementFactory.createStatementFromText("Class<@TA(1) ?> c", context) - assertEquals("Class<@TA(1) ?>", psi.declaredElements[0].type.presentableText) + public void testWildcardType() { + doTest("Class<@TA(1) ?> c", "java.lang.Class<@pkg.TA(1) ?>", "java.lang.Class<?>") + } - psi = javaFacade.elementFactory.createStatementFromText("Class<@TA String> cs = new Class<>()", context) - assertEquals("Class<@TA String>", psi.declaredElements[0].initializer.type.presentableText) + public void testDisjunctionType() { + def psi = factory.createStatementFromText("try { } catch (@A @TA(1) E1 | @TA(2) E2 e) { }", context) + assertTypeText(psi.catchBlockParameters[0].type, "pkg.@pkg.TA(1) E1 | pkg.@pkg.TA(2) E2", "pkg.E1 | pkg.E2") + } - psi = javaFacade.elementFactory.createStatementFromText("@A @TA(1) String s", context) - assertEquals("@TA(1) String", psi.declaredElements[0].type.presentableText) + public void testDiamondType() { + def psi = factory.createStatementFromText("Class<@TA String> cs = new Class<>()", context) + assertTypeText(psi.declaredElements[0].initializer.type, "java.lang.Class<java.lang.@pkg.TA String>", "java.lang.Class<java.lang.String>") + } - psi = javaFacade.elementFactory.createStatementFromText("@A java.lang.@TA(1) String s", context) - assertEquals("@TA(1) String", psi.declaredElements[0].type.presentableText) + public void testImmediateClassType() { + def aClass = javaFacade.findClass(CommonClassNames.JAVA_LANG_OBJECT) + def statement = factory.createStatementFromText("@TA int x", context) + def annotations = statement.declaredElements[0].modifierList.annotations + def type = new PsiImmediateClassType(aClass, PsiSubstitutor.EMPTY, LanguageLevel.JDK_1_8, annotations) + assertTypeText(type, "java.lang.@pkg.TA Object", CommonClassNames.JAVA_LANG_OBJECT) + } - psi = javaFacade.elementFactory.createStatementFromText("Collection<? extends> s", context) - assertEquals("Collection<?>", psi.declaredElements[0].type.presentableText) + private void doTest(String text, String annotated, String canonical) { + def psi = factory.createStatementFromText(text, context) + assertTypeText(psi.declaredElements[0].type, annotated, canonical) } + private static void assertTypeText(PsiType type, String annotated, String canonical) { + assert type.getCanonicalText(true) == annotated + assert type.getCanonicalText(false) == canonical + } } diff --git a/java/java-tests/testSrc/com/intellij/find/FindManagerTest.java b/java/java-tests/testSrc/com/intellij/find/FindManagerTest.java index c2cef13e6ea8..bfd1de796f90 100644 --- a/java/java-tests/testSrc/com/intellij/find/FindManagerTest.java +++ b/java/java-tests/testSrc/com/intellij/find/FindManagerTest.java @@ -194,7 +194,7 @@ public class FindManagerTest extends DaemonAnalyzerTestCase { PsiDirectory psiDirectory = FindInProjectUtil.getPsiDirectory(findModel, myProject); List<UsageInfo> result = new ArrayList<UsageInfo>(); final CommonProcessors.CollectProcessor<UsageInfo> collector = new CommonProcessors.CollectProcessor<UsageInfo>(result); - FindInProjectUtil.findUsages(findModel, psiDirectory, myProject, true, collector, new FindUsagesProcessPresentation(FindInProjectUtil.setupViewPresentation(true, findModel))); + FindInProjectUtil.findUsages(findModel, psiDirectory, myProject, collector, new FindUsagesProcessPresentation(FindInProjectUtil.setupViewPresentation(true, findModel))); return result; } diff --git a/java/java-tests/testSrc/com/intellij/index/IndexTest.java b/java/java-tests/testSrc/com/intellij/index/IndexTest.java index fba5b6e5265d..7770c5e4a1f9 100644 --- a/java/java-tests/testSrc/com/intellij/index/IndexTest.java +++ b/java/java-tests/testSrc/com/intellij/index/IndexTest.java @@ -34,6 +34,7 @@ import com.intellij.testFramework.SkipSlowTestLocally; import com.intellij.util.indexing.MapIndexStorage; import com.intellij.util.indexing.StorageException; import com.intellij.util.io.*; +import org.jetbrains.annotations.NotNull; import java.io.DataInput; import java.io.DataOutput; @@ -113,7 +114,7 @@ public class IndexTest extends IdeaTestCase { private PersistentHashMap<Integer, Collection<String>> createMetaIndex(File metaIndexFile) throws IOException { return new PersistentHashMap<Integer, Collection<String>>(metaIndexFile, new EnumeratorIntegerDescriptor(), new DataExternalizer<Collection<String>>() { @Override - public void save(DataOutput out, Collection<String> value) throws IOException { + public void save(@NotNull DataOutput out, Collection<String> value) throws IOException { DataInputOutputUtil.writeINT(out, value.size()); for (String key : value) { out.writeUTF(key); @@ -121,7 +122,7 @@ public class IndexTest extends IdeaTestCase { } @Override - public Collection<String> read(DataInput in) throws IOException { + public Collection<String> read(@NotNull DataInput in) throws IOException { final int size = DataInputOutputUtil.readINT(in); final List<String> list = new ArrayList<String>(); for (int idx = 0; idx < size; idx++) { diff --git a/java/java-tests/testSrc/com/intellij/index/StringIndex.java b/java/java-tests/testSrc/com/intellij/index/StringIndex.java index a12f58fbf137..7d2dd108ceac 100644 --- a/java/java-tests/testSrc/com/intellij/index/StringIndex.java +++ b/java/java-tests/testSrc/com/intellij/index/StringIndex.java @@ -1,3 +1,18 @@ +/* + * Copyright 2000-2014 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.index; import com.intellij.openapi.util.Factory; @@ -28,7 +43,7 @@ public class StringIndex { myIndex.setInputIdToDataKeysIndex(factory); } - public List<String> getFilesByWord(String word) throws StorageException { + public List<String> getFilesByWord(@NotNull String word) throws StorageException { return myIndex.getData(word).toValueList(); } diff --git a/java/java-tests/testSrc/com/intellij/openapi/editor/impl/JavaFileEditorManagerTest.java b/java/java-tests/testSrc/com/intellij/openapi/editor/impl/JavaFileEditorManagerTest.java new file mode 100644 index 000000000000..2a985b873ee3 --- /dev/null +++ b/java/java-tests/testSrc/com/intellij/openapi/editor/impl/JavaFileEditorManagerTest.java @@ -0,0 +1,54 @@ +/* + * Copyright 2000-2014 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.editor.impl; + +import com.intellij.openapi.fileEditor.FileEditorManagerTestCase; +import com.intellij.testFramework.PlatformTestUtil; +import org.jdom.JDOMException; + +import java.io.File; +import java.io.IOException; +import java.util.concurrent.ExecutionException; + +/** + * @author Dmitry Avdeev + */ +public class JavaFileEditorManagerTest extends FileEditorManagerTestCase { + + public void testAsyncOpening() throws JDOMException, ExecutionException, InterruptedException, IOException { + openFiles("<component name=\"FileEditorManager\">\n" + + " <leaf>\n" + + " <file leaf-file-name=\"Bar.java\" pinned=\"false\" current=\"true\" current-in-tab=\"true\">\n" + + " <entry file=\"file://$PROJECT_DIR$/src/Bar.java\">\n" + + " <provider selected=\"true\" editor-type-id=\"text-editor\">\n" + + " <state vertical-scroll-proportion=\"0.032882012\" vertical-offset=\"0\" max-vertical-offset=\"517\">\n" + + " <caret line=\"1\" column=\"26\" selection-start=\"45\" selection-end=\"45\" />\n" + + " <folding>\n" + + " <element signature=\"e#69#70#0\" expanded=\"true\" />\n" + + " </folding>\n" + + " </state>\n" + + " </provider>\n" + + " </entry>\n" + + " </file>\n" + + " </leaf>\n" + + " </component>"); + } + + @Override + protected String getTestDataPath() { + return PlatformTestUtil.getCommunityPath().replace(File.separatorChar, '/') + "/java/java-tests/testData/fileEditorManager"; + } +} diff --git a/java/java-tests/testSrc/com/intellij/psi/formatter/java/AbstractJavaFormatterTest.java b/java/java-tests/testSrc/com/intellij/psi/formatter/java/AbstractJavaFormatterTest.java index 58c02ef225b3..ab057c436baa 100644 --- a/java/java-tests/testSrc/com/intellij/psi/formatter/java/AbstractJavaFormatterTest.java +++ b/java/java-tests/testSrc/com/intellij/psi/formatter/java/AbstractJavaFormatterTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2010 JetBrains s.r.o. + * Copyright 2000-2014 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. @@ -42,6 +42,7 @@ import java.io.ByteArrayInputStream; import java.io.File; import java.io.IOException; import java.util.EnumMap; +import java.util.List; import java.util.Map; /** @@ -51,13 +52,20 @@ import java.util.Map; * @since Apr 27, 2010 6:26:29 PM */ public abstract class AbstractJavaFormatterTest extends LightIdeaTestCase { - @NotNull - public static String shiftIndentInside(@NotNull String initial, final int i, boolean shiftEmptyLines) throws IOException { + public static String shiftIndentInside(@NotNull String initial, final int i, boolean shiftEmptyLines) { StringBuilder result = new StringBuilder(initial.length()); - LineReader reader = new LineReader(new ByteArrayInputStream(initial.getBytes())); + List<byte[]> lines; + try { + LineReader reader = new LineReader(new ByteArrayInputStream(initial.getBytes("UTF-8"))); + lines = reader.readLines(); + } + catch (IOException e) { + throw new RuntimeException(e); + } + boolean first = true; - for (byte[] line : reader.readLines()) { + for (byte[] line : lines) { try { if (!first) result.append('\n'); if (line.length > 0 || shiftEmptyLines) { @@ -75,7 +83,6 @@ public abstract class AbstractJavaFormatterTest extends LightIdeaTestCase { protected enum Action {REFORMAT, INDENT} - public static JavaCodeStyleSettings getJavaSettings() { return getSettings().getRootSettings().getCustomSettings(JavaCodeStyleSettings.class); } @@ -116,20 +123,15 @@ public abstract class AbstractJavaFormatterTest extends LightIdeaTestCase { return rootSettings.getCommonSettings(JavaLanguage.INSTANCE); } - //public static JavaCodeStyleSettings getJavaSettings() { - // CodeStyleSettings rootSettings = CodeStyleSettingsManager.getSettings(getProject()); - // return rootSettings.getCustomSettings(JavaCodeStyleSettings.class); - //} - // public static CommonCodeStyleSettings.IndentOptions getIndentOptions() { return getSettings().getRootSettings().getIndentOptions(StdFileTypes.JAVA); } - public void doTest() throws Exception { + public void doTest() { doTest(getTestName(false) + ".java", getTestName(false) + "_after.java"); } - public void doTest(@NonNls String fileNameBefore, @NonNls String fileNameAfter) throws Exception { + public void doTest(@NonNls String fileNameBefore, @NonNls String fileNameAfter) { doTextTest(Action.REFORMAT, loadFile(fileNameBefore), loadFile(fileNameAfter)); } @@ -137,7 +139,7 @@ public abstract class AbstractJavaFormatterTest extends LightIdeaTestCase { doTextTest(Action.REFORMAT, text, textAfter); } - public void doTextTest(@NotNull final Action action, @NotNull final String text, @NotNull String textAfter) throws IncorrectOperationException { + public void doTextTest(@NotNull final Action action, @NotNull String text, @NotNull String textAfter) throws IncorrectOperationException { final PsiFile file = createFile("A.java", text); final PsiDocumentManager manager = PsiDocumentManager.getInstance(getProject()); final Document document = manager.getDocument(file); @@ -204,7 +206,7 @@ public abstract class AbstractJavaFormatterTest extends LightIdeaTestCase { return document.getText(); } - public void doMethodTest(@NonNls final String before, @NonNls final String after) throws Exception { + public void doMethodTest(@NonNls final String before, @NonNls final String after) { doTextTest( Action.REFORMAT, "class Foo{\n" + " void foo() {\n" + before + '\n' + " }\n" + "}", @@ -212,7 +214,7 @@ public abstract class AbstractJavaFormatterTest extends LightIdeaTestCase { ); } - public void doClassTest(@NonNls final String before, @NonNls final String after) throws Exception { + public void doClassTest(@NonNls final String before, @NonNls final String after) { doTextTest( Action.REFORMAT, "class Foo{\n" + before + '\n' + "}", @@ -220,10 +222,14 @@ public abstract class AbstractJavaFormatterTest extends LightIdeaTestCase { ); } - private static String loadFile(String name) throws Exception { + private static String loadFile(String name) { String fullName = BASE_PATH + File.separatorChar + name; - String text = FileUtil.loadFile(new File(fullName)); - text = StringUtil.convertLineSeparators(text); - return text; + try { + String text = FileUtil.loadFile(new File(fullName)); + return StringUtil.convertLineSeparators(text); + } + catch (IOException e) { + throw new RuntimeException(e); + } } } diff --git a/java/java-tests/testSrc/com/intellij/psi/formatter/java/JavaFormatterNewLineTest.java b/java/java-tests/testSrc/com/intellij/psi/formatter/java/JavaFormatterNewLineTest.java index 038b1d01f0e1..a7473f61e5a4 100644 --- a/java/java-tests/testSrc/com/intellij/psi/formatter/java/JavaFormatterNewLineTest.java +++ b/java/java-tests/testSrc/com/intellij/psi/formatter/java/JavaFormatterNewLineTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2012 JetBrains s.r.o. + * Copyright 2000-2014 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. @@ -28,7 +28,7 @@ import com.intellij.util.IncorrectOperationException; */ public class JavaFormatterNewLineTest extends AbstractJavaFormatterTest { - public void testAutomaticElseWrapping() throws Exception { + public void testAutomaticElseWrapping() { getSettings().ELSE_ON_NEW_LINE = true; doMethodTest( @@ -43,7 +43,7 @@ public class JavaFormatterNewLineTest extends AbstractJavaFormatterTest { ); } - public void testAutomaticElseUnwrapping() throws Exception { + public void testAutomaticElseUnwrapping() { getSettings().ELSE_ON_NEW_LINE = false; getSettings().KEEP_LINE_BREAKS = true; @@ -60,7 +60,7 @@ public class JavaFormatterNewLineTest extends AbstractJavaFormatterTest { ); } - public void testAutomaticCatchWrapping() throws Exception { + public void testAutomaticCatchWrapping() { getSettings().CATCH_ON_NEW_LINE = true; doMethodTest( @@ -75,7 +75,7 @@ public class JavaFormatterNewLineTest extends AbstractJavaFormatterTest { ); } - public void testAutomaticCatchUnwrapping() throws Exception { + public void testAutomaticCatchUnwrapping() { getSettings().CATCH_ON_NEW_LINE = false; getSettings().KEEP_LINE_BREAKS = true; @@ -92,7 +92,7 @@ public class JavaFormatterNewLineTest extends AbstractJavaFormatterTest { ); } - public void testAutomaticFinallyWrapping() throws Exception { + public void testAutomaticFinallyWrapping() { getSettings().FINALLY_ON_NEW_LINE = true; doMethodTest( @@ -107,7 +107,7 @@ public class JavaFormatterNewLineTest extends AbstractJavaFormatterTest { ); } - public void testAutomaticFinallyUnwrapping() throws Exception { + public void testAutomaticFinallyUnwrapping() { getSettings().FINALLY_ON_NEW_LINE = false; getSettings().KEEP_LINE_BREAKS = true; @@ -124,7 +124,7 @@ public class JavaFormatterNewLineTest extends AbstractJavaFormatterTest { ); } - public void testAutomaticCatchFinallyUnwrapping() throws Exception { + public void testAutomaticCatchFinallyUnwrapping() { // Inspired by IDEA-47809 getSettings().CATCH_ON_NEW_LINE = false; getSettings().FINALLY_ON_NEW_LINE = false; @@ -144,8 +144,8 @@ public class JavaFormatterNewLineTest extends AbstractJavaFormatterTest { "}" ); } - - public void testClassInitializationBlockBracesPlacement() throws Exception { + + public void testClassInitializationBlockBracesPlacement() { // Inspired by IDEA-54191 getSettings().getRootSettings().getIndentOptions(StdFileTypes.JAVA).INDENT_SIZE = 4; getSettings().KEEP_SIMPLE_BLOCKS_IN_ONE_LINE = false; @@ -161,7 +161,7 @@ public class JavaFormatterNewLineTest extends AbstractJavaFormatterTest { ); } - public void testBlockOfMethodWithAnnotatedParameter() throws Exception { + public void testBlockOfMethodWithAnnotatedParameter() { // Inspired by IDEA-17870 doClassTest("public Test(@Qualifier(\"blah\") AType blah){}", "public Test(@Qualifier(\"blah\") AType blah) {\n" + "}"); } @@ -193,7 +193,7 @@ public class JavaFormatterNewLineTest extends AbstractJavaFormatterTest { ); } - public void testSimpleAnnotatedMethodAndBraceOnNextLineStyle() throws Exception { + public void testSimpleAnnotatedMethodAndBraceOnNextLineStyle() { // Inspired by IDEA-53542 getSettings().METHOD_BRACE_STYLE = CommonCodeStyleSettings.NEXT_LINE; getSettings().KEEP_SIMPLE_METHODS_IN_ONE_LINE = true; diff --git a/java/java-tests/testSrc/com/intellij/psi/impl/source/tree/java/ShortenClassReferencesTest.java b/java/java-tests/testSrc/com/intellij/psi/impl/source/tree/java/ShortenClassReferencesTest.java index e21c18022e1e..4554f93fb20d 100644 --- a/java/java-tests/testSrc/com/intellij/psi/impl/source/tree/java/ShortenClassReferencesTest.java +++ b/java/java-tests/testSrc/com/intellij/psi/impl/source/tree/java/ShortenClassReferencesTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2013 JetBrains s.r.o. + * Copyright 2000-2014 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. @@ -61,6 +61,7 @@ public class ShortenClassReferencesTest extends LightCodeInsightFixtureTestCase public void testSCR37254() { doTest(); } public void testTypeAnnotatedRef() { + myFixture.configureByFile("pkg/TA.java"); doTest(); for (PsiParameter parameter : PsiTreeUtil.findChildrenOfType(myFixture.getFile(), PsiParameter.class)) { PsiTypeElement typeElement = parameter.getTypeElement(); diff --git a/java/java-tests/testSrc/com/intellij/refactoring/ChangeSignatureTest.java b/java/java-tests/testSrc/com/intellij/refactoring/ChangeSignatureTest.java index 51905419d22c..4f6c44824ab6 100644 --- a/java/java-tests/testSrc/com/intellij/refactoring/ChangeSignatureTest.java +++ b/java/java-tests/testSrc/com/intellij/refactoring/ChangeSignatureTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2011 JetBrains s.r.o. + * Copyright 2000-2014 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. @@ -34,360 +34,388 @@ import java.util.HashSet; * @author dsl */ public class ChangeSignatureTest extends LightRefactoringTestCase { - public void testSimple() throws Exception { + private PsiElementFactory myFactory; + + public void setUp() throws Exception { + super.setUp(); + myFactory = JavaPsiFacade.getInstance(getProject()).getElementFactory(); + } + + public void testSimple() { doTest(null, null, null, new ParameterInfoImpl[0], new ThrownExceptionInfo[0], false); } - public void testParameterReorder() throws Exception { + public void testParameterReorder() { doTest(null, new ParameterInfoImpl[]{new ParameterInfoImpl(1), new ParameterInfoImpl(0)}, false); } - public void testWarnAboutContract() throws Exception { + public void testWarnAboutContract() { try { doTest(null, new ParameterInfoImpl[]{new ParameterInfoImpl(1), new ParameterInfoImpl(0)}, false); fail("Conflict expected"); } - catch (BaseRefactoringProcessor.ConflictsInTestsException ignored) { - } + catch (BaseRefactoringProcessor.ConflictsInTestsException ignored) { } } - public void testGenericTypes() throws Exception { + public void testGenericTypes() { doTest(null, null, "T", new GenParams() { @Override public ParameterInfoImpl[] genParams(PsiMethod method) throws IncorrectOperationException { - final PsiElementFactory factory = JavaPsiFacade.getInstance(getProject()).getElementFactory(); return new ParameterInfoImpl[]{ - new ParameterInfoImpl(-1, "x", factory.createTypeFromText("T", method.getParameterList()), "null"), - new ParameterInfoImpl(-1, "y", factory.createTypeFromText("C<T>", method.getParameterList()), "null") + new ParameterInfoImpl(-1, "x", myFactory.createTypeFromText("T", method.getParameterList()), "null"), + new ParameterInfoImpl(-1, "y", myFactory.createTypeFromText("C<T>", method.getParameterList()), "null") }; } }, false); } - public void testGenericTypesInOldParameters() throws Exception { + public void testGenericTypesInOldParameters() { doTest(null, null, null, new GenParams() { @Override public ParameterInfoImpl[] genParams(PsiMethod method) throws IncorrectOperationException { - final PsiElementFactory factory = JavaPsiFacade.getInstance(getProject()).getElementFactory(); - return new ParameterInfoImpl[] { - new ParameterInfoImpl(0, "t", factory.createTypeFromText("T", method), null) + return new ParameterInfoImpl[]{ + new ParameterInfoImpl(0, "t", myFactory.createTypeFromText("T", method), null) }; } }, false); } - public void testTypeParametersInMethod() throws Exception { + public void testTypeParametersInMethod() { doTest(null, null, null, new GenParams() { - @Override - public ParameterInfoImpl[] genParams(PsiMethod method) throws IncorrectOperationException { - final PsiElementFactory factory = JavaPsiFacade.getInstance(getProject()).getElementFactory(); - return new ParameterInfoImpl[]{ - new ParameterInfoImpl(-1, "t", factory.createTypeFromText("T", method.getParameterList()), "null"), - new ParameterInfoImpl(-1, "u", factory.createTypeFromText("U", method.getParameterList()), "null"), - new ParameterInfoImpl(-1, "cu", factory.createTypeFromText("C<U>", method.getParameterList()), "null") - }; - } - }, false); + @Override + public ParameterInfoImpl[] genParams(PsiMethod method) throws IncorrectOperationException { + return new ParameterInfoImpl[]{ + new ParameterInfoImpl(-1, "t", myFactory.createTypeFromText("T", method.getParameterList()), "null"), + new ParameterInfoImpl(-1, "u", myFactory.createTypeFromText("U", method.getParameterList()), "null"), + new ParameterInfoImpl(-1, "cu", myFactory.createTypeFromText("C<U>", method.getParameterList()), "null") + }; + } + }, false); } - public void testDefaultConstructor() throws Exception { + public void testDefaultConstructor() { doTest(null, - new ParameterInfoImpl[] { - new ParameterInfoImpl(-1, "j", PsiType.INT, "27") - }, false); + new ParameterInfoImpl[]{ + new ParameterInfoImpl(-1, "j", PsiType.INT, "27") + }, false + ); } - public void testGenerateDelegate() throws Exception { + public void testGenerateDelegate() { doTest(null, - new ParameterInfoImpl[] { + new ParameterInfoImpl[]{ new ParameterInfoImpl(-1, "i", PsiType.INT, "27") - }, true); + }, true + ); } - public void testGenerateDelegateForAbstract() throws Exception { + public void testGenerateDelegateForAbstract() { doTest(null, - new ParameterInfoImpl[] { + new ParameterInfoImpl[]{ new ParameterInfoImpl(-1, "i", PsiType.INT, "27") - }, true); + }, true + ); } - public void testGenerateDelegateWithReturn() throws Exception { + public void testGenerateDelegateWithReturn() { doTest(null, - new ParameterInfoImpl[] { + new ParameterInfoImpl[]{ new ParameterInfoImpl(-1, "i", PsiType.INT, "27") - }, true); + }, true + ); } - public void testGenerateDelegateWithParametersReordering() throws Exception { + public void testGenerateDelegateWithParametersReordering() { doTest(null, - new ParameterInfoImpl[] { + new ParameterInfoImpl[]{ new ParameterInfoImpl(1), new ParameterInfoImpl(-1, "c", PsiType.CHAR, "'a'"), new ParameterInfoImpl(0, "j", PsiType.INT) - }, true); + }, true + ); } - public void testGenerateDelegateConstructor() throws Exception { + public void testGenerateDelegateConstructor() { doTest(null, new ParameterInfoImpl[0], true); } - public void testGenerateDelegateDefaultConstructor() throws Exception { - doTest(null, new ParameterInfoImpl[] { + public void testGenerateDelegateDefaultConstructor() { + doTest(null, new ParameterInfoImpl[]{ new ParameterInfoImpl(-1, "i", PsiType.INT, "27") }, true); } - public void testSCR40895() throws Exception { - doTest(null, new ParameterInfoImpl[] { + public void testSCR40895() { + doTest(null, new ParameterInfoImpl[]{ new ParameterInfoImpl(0, "y", PsiType.INT), new ParameterInfoImpl(1, "b", PsiType.BOOLEAN) }, false); } - public void testJavadocGenericsLink() throws Exception { - doTest(null, new ParameterInfoImpl[] { - new ParameterInfoImpl(-1, "y", JavaPsiFacade.getElementFactory(getProject()).createTypeFromText("java.util.List<java.lang.String>", null)), + public void testJavadocGenericsLink() { + doTest(null, new ParameterInfoImpl[]{ + new ParameterInfoImpl(-1, "y", myFactory.createTypeFromText("java.util.List<java.lang.String>", null)), new ParameterInfoImpl(0, "a", PsiType.BOOLEAN) }, false); } - public void testParamNameSameAsFieldName() throws Exception { - doTest(null, new ParameterInfoImpl[] { + public void testParamNameSameAsFieldName() { + doTest(null, new ParameterInfoImpl[]{ new ParameterInfoImpl(0, "fieldName", PsiType.INT) }, false); } - public void testParamNameNoConflict() throws Exception { + public void testParamNameNoConflict() { doTest(null, new ParameterInfoImpl[]{ new ParameterInfoImpl(0), new ParameterInfoImpl(-1, "b", PsiType.BOOLEAN) }, false); } - public void testParamJavadoc() throws Exception { - doTest(null, new ParameterInfoImpl[] { + public void testParamJavadoc() { + doTest(null, new ParameterInfoImpl[]{ new ParameterInfoImpl(1, "z", PsiType.INT), new ParameterInfoImpl(0, "y", PsiType.INT) }, false); } - public void testParamJavadoc0() throws Exception { - doTest(null, new ParameterInfoImpl[] { + public void testParamJavadoc0() { + doTest(null, new ParameterInfoImpl[]{ new ParameterInfoImpl(1, "z", PsiType.INT), new ParameterInfoImpl(0, "y", PsiType.INT) }, false); } - public void testParamJavadoc1() throws Exception { + public void testParamJavadoc1() { doTest(null, new ParameterInfoImpl[]{ new ParameterInfoImpl(0, "z", PsiType.BOOLEAN) }, false); } - public void testParamJavadoc2() throws Exception { + public void testParamJavadoc2() { doTest(null, new ParameterInfoImpl[]{ new ParameterInfoImpl(-1, "z", PsiType.BOOLEAN), new ParameterInfoImpl(0, "a", PsiType.BOOLEAN), }, false); } - public void testJavadocNoNewLineInserted() throws Exception { + public void testJavadocNoNewLineInserted() { doTest(null, new ParameterInfoImpl[]{ new ParameterInfoImpl(0, "newArgs", PsiType.DOUBLE), }, false); } - public void testSuperCallFromOtherMethod() throws Exception { - doTest(null, new ParameterInfoImpl[] { + public void testSuperCallFromOtherMethod() { + doTest(null, new ParameterInfoImpl[]{ new ParameterInfoImpl(-1, "nnn", PsiType.INT, "-222"), }, false); } - public void testUseAnyVariable() throws Exception { + public void testUseAnyVariable() { doTest(null, null, null, new GenParams() { @Override public ParameterInfoImpl[] genParams(PsiMethod method) throws IncorrectOperationException { - final PsiElementFactory factory = JavaPsiFacade.getInstance(method.getProject()).getElementFactory(); - return new ParameterInfoImpl[] { - new ParameterInfoImpl(-1, "l", factory.createTypeFromText("List", method), "null", true) + return new ParameterInfoImpl[]{ + new ParameterInfoImpl(-1, "l", myFactory.createTypeFromText("List", method), "null", true) }; } }, false); } - public void testUseThisAsAnyVariable() throws Exception { + public void testUseThisAsAnyVariable() { doTest(null, null, null, new GenParams() { @Override public ParameterInfoImpl[] genParams(PsiMethod method) throws IncorrectOperationException { - final PsiElementFactory factory = JavaPsiFacade.getInstance(method.getProject()).getElementFactory(); - return new ParameterInfoImpl[] { - new ParameterInfoImpl(-1, "l", factory.createTypeFromText("List", method), "null", true) + return new ParameterInfoImpl[]{ + new ParameterInfoImpl(-1, "l", myFactory.createTypeFromText("List", method), "null", true) }; } }, false); } - public void testUseAnyVariableAndDefault() throws Exception { + public void testUseAnyVariableAndDefault() { doTest(null, null, null, new GenParams() { @Override public ParameterInfoImpl[] genParams(PsiMethod method) throws IncorrectOperationException { - final PsiElementFactory factory = JavaPsiFacade.getInstance(method.getProject()).getElementFactory(); - return new ParameterInfoImpl[] { - new ParameterInfoImpl(-1, "c", factory.createTypeFromText("C", method), "null", true) + return new ParameterInfoImpl[]{ + new ParameterInfoImpl(-1, "c", myFactory.createTypeFromText("C", method), "null", true) }; } }, false); } - public void testRemoveVarargParameter() throws Exception { + public void testRemoveVarargParameter() { doTest(null, null, null, new ParameterInfoImpl[]{new ParameterInfoImpl(0)}, new ThrownExceptionInfo[0], false); } - public void testEnumConstructor() throws Exception { - doTest(null, new ParameterInfoImpl[] { + public void testEnumConstructor() { + doTest(null, new ParameterInfoImpl[]{ new ParameterInfoImpl(-1, "i", PsiType.INT, "10") }, false); } - public void testVarargs1() throws Exception { - doTest(null, new ParameterInfoImpl[] { + public void testVarargs1() { + doTest(null, new ParameterInfoImpl[]{ new ParameterInfoImpl(-1, "b", PsiType.BOOLEAN, "true"), new ParameterInfoImpl(0) }, false); } - public void testVarargs2() throws Exception { - doTest(null, new ParameterInfoImpl[] { + public void testVarargs2() { + doTest(null, new ParameterInfoImpl[]{ new ParameterInfoImpl(1, "i", PsiType.INT), new ParameterInfoImpl(0, "b", new PsiEllipsisType(PsiType.BOOLEAN)) }, false); } - public void testCovariantReturnType() throws Exception { + public void testCovariantReturnType() { doTest(CommonClassNames.JAVA_LANG_RUNNABLE, new ParameterInfoImpl[0], false); } - public void testReorderExceptions() throws Exception { + public void testReorderExceptions() { doTest(null, null, null, new SimpleParameterGen(new ParameterInfoImpl[0]), - new SimpleExceptionsGen(new ThrownExceptionInfo[]{new JavaThrownExceptionInfo(1), new JavaThrownExceptionInfo(0)}), - false); + new SimpleExceptionsGen(new ThrownExceptionInfo[]{new JavaThrownExceptionInfo(1), new JavaThrownExceptionInfo(0)}), false); } - public void testAlreadyHandled() throws Exception { + public void testAlreadyHandled() { doTest(null, null, null, new SimpleParameterGen(new ParameterInfoImpl[0]), new GenExceptions() { @Override public ThrownExceptionInfo[] genExceptions(PsiMethod method) { - return new ThrownExceptionInfo[] { - new JavaThrownExceptionInfo(-1, JavaPsiFacade.getInstance(method.getProject()).getElementFactory().createTypeByFQClassName("java.lang.Exception", method.getResolveScope())) + return new ThrownExceptionInfo[]{ + new JavaThrownExceptionInfo(-1, myFactory.createTypeByFQClassName("java.lang.Exception", method.getResolveScope())) }; } }, - false); + false + ); } - public void testConstructorException() throws Exception { + public void testConstructorException() { doTest(null, null, null, new SimpleParameterGen(new ParameterInfoImpl[0]), new GenExceptions() { @Override public ThrownExceptionInfo[] genExceptions(PsiMethod method) { - return new ThrownExceptionInfo[] { - new JavaThrownExceptionInfo(-1, JavaPsiFacade.getInstance(method.getProject()).getElementFactory().createTypeByFQClassName("java.io.IOException", method.getResolveScope())) + return new ThrownExceptionInfo[]{ + new JavaThrownExceptionInfo(-1, myFactory.createTypeByFQClassName("java.io.IOException", method.getResolveScope())) }; } }, - false); + false + ); } - public void testAddRuntimeException() throws Exception { + public void testAddRuntimeException() { doTest(null, null, null, new SimpleParameterGen(new ParameterInfoImpl[0]), new GenExceptions() { @Override public ThrownExceptionInfo[] genExceptions(PsiMethod method) { - return new ThrownExceptionInfo[] { - new JavaThrownExceptionInfo(-1, JavaPsiFacade.getInstance(method.getProject()).getElementFactory().createTypeByFQClassName("java.lang.RuntimeException", method.getResolveScope())) + return new ThrownExceptionInfo[]{ + new JavaThrownExceptionInfo(-1, myFactory.createTypeByFQClassName("java.lang.RuntimeException", method.getResolveScope())) }; } }, - false); + false + ); } - public void testAddException() throws Exception { + public void testAddException() { doTest(null, null, null, new SimpleParameterGen(new ParameterInfoImpl[0]), new GenExceptions() { @Override public ThrownExceptionInfo[] genExceptions(PsiMethod method) { - return new ThrownExceptionInfo[] { - new JavaThrownExceptionInfo(-1, JavaPsiFacade.getInstance(method.getProject()).getElementFactory().createTypeByFQClassName("java.lang.Exception", method.getResolveScope())) + return new ThrownExceptionInfo[]{ + new JavaThrownExceptionInfo(-1, myFactory.createTypeByFQClassName("java.lang.Exception", method.getResolveScope())) }; } }, - false); + false + ); } - public void testReorderWithVarargs() throws Exception { // IDEADEV-26977 - final PsiElementFactory factory = JavaPsiFacade.getInstance(getProject()).getElementFactory(); - doTest(null, new ParameterInfoImpl[] { - new ParameterInfoImpl(1), - new ParameterInfoImpl(0, "s", factory.createTypeFromText("java.lang.String...", getFile())) + public void testReorderWithVarargs() { // IDEADEV-26977 + doTest(null, new ParameterInfoImpl[]{ + new ParameterInfoImpl(1), + new ParameterInfoImpl(0, "s", myFactory.createTypeFromText("java.lang.String...", getFile())) }, false); } - public void testIntroduceParameterWithDefaultValueInHierarchy() throws Exception { + public void testIntroduceParameterWithDefaultValueInHierarchy() { doTest(null, new ParameterInfoImpl[]{new ParameterInfoImpl(-1, "i", PsiType.INT, "0")}, false); } - public void testReorderMultilineMethodParameters() throws Exception { + public void testReorderMultilineMethodParameters() { // Inspired by IDEA-54902 - doTest(null, new ParameterInfoImpl[] {new ParameterInfoImpl(1), new ParameterInfoImpl(0)}, false); + doTest(null, new ParameterInfoImpl[]{new ParameterInfoImpl(1), new ParameterInfoImpl(0)}, false); } - public void testRemoveFirstParameter() throws Exception { + public void testRemoveFirstParameter() { doTest(null, new ParameterInfoImpl[]{new ParameterInfoImpl(1)}, false); } - public void testReplaceVarargWithArray() throws Exception { + public void testReplaceVarargWithArray() { doTest(null, null, null, new GenParams() { @Override public ParameterInfoImpl[] genParams(PsiMethod method) throws IncorrectOperationException { - final PsiElementFactory factory = JavaPsiFacade.getInstance(method.getProject()).getElementFactory(); - return new ParameterInfoImpl[] { - new ParameterInfoImpl(1, "l", factory.createTypeFromText("List<T>[]", method.getParameterList()), "null", false), - new ParameterInfoImpl(0, "s", factory.createTypeFromText("String", method.getParameterList())) + return new ParameterInfoImpl[]{ + new ParameterInfoImpl(1, "l", myFactory.createTypeFromText("List<T>[]", method.getParameterList()), "null", false), + new ParameterInfoImpl(0, "s", myFactory.createTypeFromText("String", method.getParameterList())) }; } }, false); } - public void testMethodParametersAlignmentAfterMethodNameChange() throws Exception { + public void testMethodParametersAlignmentAfterMethodNameChange() { getCurrentCodeStyleSettings().ALIGN_MULTILINE_PARAMETERS = true; getCurrentCodeStyleSettings().ALIGN_MULTILINE_PARAMETERS_IN_CALLS = true; doTest(null, "test123asd", null, new SimpleParameterGen(), new SimpleExceptionsGen(), false); } - public void testMethodParametersAlignmentAfterMethodVisibilityChange() throws Exception { + public void testMethodParametersAlignmentAfterMethodVisibilityChange() { getCurrentCodeStyleSettings().ALIGN_MULTILINE_PARAMETERS = true; getCurrentCodeStyleSettings().ALIGN_MULTILINE_PARAMETERS_IN_CALLS = true; doTest(PsiModifier.PROTECTED, null, null, new SimpleParameterGen(), new SimpleExceptionsGen(), false); } - public void testMethodParametersAlignmentAfterMethodReturnTypeChange() throws Exception { + public void testMethodParametersAlignmentAfterMethodReturnTypeChange() { getCurrentCodeStyleSettings().ALIGN_MULTILINE_PARAMETERS = true; getCurrentCodeStyleSettings().ALIGN_MULTILINE_PARAMETERS_IN_CALLS = true; doTest(null, null, "Exception", new SimpleParameterGen(), new SimpleExceptionsGen(), false); } - public void testVisibilityOfOverriddenMethod() throws Exception { + public void testVisibilityOfOverriddenMethod() { doTest(PsiModifier.PACKAGE_LOCAL, "foo", "void", new ParameterInfoImpl[0], new ThrownExceptionInfo[0], false); } - public void testRemoveExceptions() throws Exception { + public void testRemoveExceptions() { doTest(null, null, "void", new SimpleParameterGen(), new SimpleExceptionsGen(), false); } - private void doTest(@Nullable String newReturnType, - ParameterInfoImpl[] parameterInfos, - final boolean generateDelegate) throws Exception { + public void testPropagateParameter() { + String basePath = "/refactoring/changeSignature/" + getTestName(false); + configureByFile(basePath + ".java"); + final PsiElement targetElement = TargetElementUtilBase.findTargetElement(getEditor(), TargetElementUtilBase.ELEMENT_NAME_ACCEPTED); + assertTrue("<caret> is not on method name", targetElement instanceof PsiMethod); + PsiMethod method = (PsiMethod)targetElement; + final PsiClass containingClass = method.getContainingClass(); + assertTrue(containingClass != null); + final PsiMethod[] callers = containingClass.findMethodsByName("caller", false); + assertTrue(callers.length > 0); + final PsiMethod caller = callers[0]; + final HashSet<PsiMethod> propagateParametersMethods = new HashSet<PsiMethod>(); + propagateParametersMethods.add(caller); + final PsiParameter[] parameters = method.getParameterList().getParameters(); + new ChangeSignatureProcessor(getProject(), method, false, null, method.getName(), + CanonicalTypes.createTypeWrapper(PsiType.VOID), new ParameterInfoImpl[]{ + new ParameterInfoImpl(0, parameters[0].getName(), parameters[0].getType()), + new ParameterInfoImpl(-1, "b", PsiType.BOOLEAN)}, null, propagateParametersMethods, null + ).run(); + checkResultByFile(basePath + "_after.java"); + } + + /* workers */ + + private void doTest(@Nullable String newReturnType, ParameterInfoImpl[] parameterInfos, boolean generateDelegate) { doTest(null, null, newReturnType, parameterInfos, new ThrownExceptionInfo[0], generateDelegate); } @@ -396,14 +424,15 @@ public class ChangeSignatureTest extends LightRefactoringTestCase { @Nullable String newReturnType, ParameterInfoImpl[] parameterInfo, ThrownExceptionInfo[] exceptionInfo, - final boolean generateDelegate) throws Exception { + boolean generateDelegate) { doTest(newVisibility, newName, newReturnType, new SimpleParameterGen(parameterInfo), new SimpleExceptionsGen(exceptionInfo), generateDelegate); } private void doTest(@PsiModifier.ModifierConstant @Nullable String newVisibility, @Nullable String newName, @Nullable @NonNls String newReturnType, - GenParams gen, final boolean generateDelegate) throws Exception { + GenParams gen, + boolean generateDelegate) { doTest(newVisibility, newName, newReturnType, gen, new SimpleExceptionsGen(), generateDelegate); } @@ -412,45 +441,17 @@ public class ChangeSignatureTest extends LightRefactoringTestCase { @Nullable String newReturnType, GenParams genParams, GenExceptions genExceptions, - final boolean generateDelegate) throws Exception { + boolean generateDelegate) { String basePath = "/refactoring/changeSignature/" + getTestName(false); - @NonNls final String filePath = basePath + ".java"; - configureByFile(filePath); - final PsiElement targetElement = TargetElementUtilBase.findTargetElement(getEditor(), TargetElementUtilBase.ELEMENT_NAME_ACCEPTED); + configureByFile(basePath + ".java"); + PsiElement targetElement = TargetElementUtilBase.findTargetElement(getEditor(), TargetElementUtilBase.ELEMENT_NAME_ACCEPTED); assertTrue("<caret> is not on method name", targetElement instanceof PsiMethod); - PsiMethod method = (PsiMethod) targetElement; - final PsiElementFactory factory = JavaPsiFacade.getInstance(getProject()).getElementFactory(); - PsiType newType = newReturnType != null ? factory.createTypeFromText(newReturnType, method) : method.getReturnType(); + PsiMethod method = (PsiMethod)targetElement; + PsiType newType = newReturnType != null ? myFactory.createTypeFromText(newReturnType, method) : method.getReturnType(); new ChangeSignatureProcessor(getProject(), method, generateDelegate, newVisibility, newName != null ? newName : method.getName(), newType, genParams.genParams(method), genExceptions.genExceptions(method)).run(); - @NonNls String after = basePath + "_after.java"; - checkResultByFile(after); - } - - public void testPropagateParameter() throws Exception { - String basePath = "/refactoring/changeSignature/" + getTestName(false); - @NonNls final String filePath = basePath + ".java"; - configureByFile(filePath); - final PsiElement targetElement = TargetElementUtilBase.findTargetElement(getEditor(), TargetElementUtilBase.ELEMENT_NAME_ACCEPTED); - assertTrue("<caret> is not on method name", targetElement instanceof PsiMethod); - PsiMethod method = (PsiMethod) targetElement; - final PsiClass containingClass = method.getContainingClass(); - assertTrue(containingClass != null); - final PsiMethod[] callers = containingClass.findMethodsByName("caller", false); - assertTrue(callers.length > 0); - final PsiMethod caller = callers[0]; - final HashSet<PsiMethod> propagateParametersMethods = new HashSet<PsiMethod>(); - propagateParametersMethods.add(caller); - final PsiParameter[] parameters = method.getParameterList().getParameters(); - new ChangeSignatureProcessor(getProject(), method, false, null, - method.getName(), - CanonicalTypes.createTypeWrapper(PsiType.VOID), new ParameterInfoImpl[]{ - new ParameterInfoImpl(0, parameters[0].getName(), parameters[0].getType()), - new ParameterInfoImpl(-1, "b", PsiType.BOOLEAN)}, null, - propagateParametersMethods, null).run(); - @NonNls String after = basePath + "_after.java"; - checkResultByFile(after); + checkResultByFile(basePath + "_after.java"); } private interface GenParams { @@ -460,8 +461,7 @@ public class ChangeSignatureTest extends LightRefactoringTestCase { private static class SimpleParameterGen implements GenParams { private ParameterInfoImpl[] myInfos; - private SimpleParameterGen() { - } + private SimpleParameterGen() { } private SimpleParameterGen(ParameterInfoImpl[] infos) { myInfos = infos; |