From ccbe8202588017ab4decef6baeba1eac14caec4c Mon Sep 17 00:00:00 2001 From: Roman Shevchenko Date: Mon, 22 Jun 2015 18:05:51 +0300 Subject: [PATCH] Cleanup (formatting) --- .../JavaDefaultLiveTemplatesProvider.java | 6 +- .../surroundWith/JavaSurroundWithTest.java | 44 +++++++------- .../template/LiveTemplateTest.groovy | 60 +++++++++---------- .../codeInsight/lookup/LookupElement.java | 7 ++- .../codeInsight/template/Expression.java | 5 +- .../codeInsight/template/TemplateBuilder.java | 9 ++- .../actions/IntroduceVariableAction.java | 6 +- 7 files changed, 64 insertions(+), 73 deletions(-) diff --git a/java/java-impl/src/com/intellij/codeInsight/template/impl/JavaDefaultLiveTemplatesProvider.java b/java/java-impl/src/com/intellij/codeInsight/template/impl/JavaDefaultLiveTemplatesProvider.java index 40832fe974cd..047c4cff1b3b 100644 --- a/java/java-impl/src/com/intellij/codeInsight/template/impl/JavaDefaultLiveTemplatesProvider.java +++ b/java/java-impl/src/com/intellij/codeInsight/template/impl/JavaDefaultLiveTemplatesProvider.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2015 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,11 @@ */ package com.intellij.codeInsight.template.impl; -import org.jetbrains.annotations.NonNls; - /** * @author yole */ public class JavaDefaultLiveTemplatesProvider implements DefaultLiveTemplatesProvider { - private static final @NonNls String[] DEFAULT_TEMPLATES = new String[]{ + private static final String[] DEFAULT_TEMPLATES = { "/liveTemplates/iterations", "/liveTemplates/other", "/liveTemplates/output", diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/generation/surroundWith/JavaSurroundWithTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/generation/surroundWith/JavaSurroundWithTest.java index a2a9ac9c59f9..8426d2d3fded 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/generation/surroundWith/JavaSurroundWithTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/generation/surroundWith/JavaSurroundWithTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 JetBrains s.r.o. + * Copyright 2000-2015 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. @@ -39,24 +39,23 @@ import org.jetbrains.annotations.Nullable; * @since 5/3/11 2:35 PM */ public class JavaSurroundWithTest extends LightCodeInsightTestCase { - private static final String BASE_PATH = "/codeInsight/generation/surroundWith/java/"; - + @SuppressWarnings({"UnusedDeclaration"}) private enum SurroundType { - IF(new JavaWithIfSurrounder()), IF_ELSE(new JavaWithIfElseSurrounder()), - - WHILE(new JavaWithWhileSurrounder()), DO_WHILE(new JavaWithDoWhileSurrounder()), - + IF(new JavaWithIfSurrounder()), + IF_ELSE(new JavaWithIfElseSurrounder()), + + WHILE(new JavaWithWhileSurrounder()), + DO_WHILE(new JavaWithDoWhileSurrounder()), FOR(new JavaWithForSurrounder()), - - TRY_CATCH(new JavaWithTryCatchSurrounder()), TRY_FINALLY(new JavaWithTryFinallySurrounder()), + + TRY_CATCH(new JavaWithTryCatchSurrounder()), + TRY_FINALLY(new JavaWithTryFinallySurrounder()), TRY_CATCH_FINALLY(new JavaWithTryCatchFinallySurrounder()), SYNCHRONIZED(new JavaWithSynchronizedSurrounder()), - RUNNABLE(new JavaWithRunnableSurrounder()), - CODE_BLOCK(new JavaWithBlockSurrounder()); private final Surrounder mySurrounder; @@ -68,7 +67,7 @@ public class JavaSurroundWithTest extends LightCodeInsightTestCase { public Surrounder getSurrounder() { return mySurrounder; } - + public String toFileName() { StringBuilder result = new StringBuilder(); boolean capitalize = true; @@ -88,7 +87,7 @@ public class JavaSurroundWithTest extends LightCodeInsightTestCase { return result.toString(); } } - + public void testCommentAsFirstSurroundStatement() throws Exception { String template = "CommentAsFirst%sSurroundStatement"; for (SurroundType type : SurroundType.values()) { @@ -135,7 +134,7 @@ public class JavaSurroundWithTest extends LightCodeInsightTestCase { TemplateManagerImpl.setTemplateTesting(getProject(), getTestRootDisposable()); doTest(new JavaWithNullCheckSurrounder()); } - + public void testSurroundExpressionWithIf() { TemplateManagerImpl.setTemplateTesting(getProject(), getTestRootDisposable()); doTest(new JavaWithIfExpressionSurrounder()); @@ -145,17 +144,17 @@ public class JavaSurroundWithTest extends LightCodeInsightTestCase { TemplateManagerImpl.setTemplateTesting(getProject(), getTestRootDisposable()); doTest(new JavaWithIfExpressionSurrounder()); } - + public void testSurroundExpressionWithNotForBoxedBooleans() { TemplateManagerImpl.setTemplateTesting(getProject(), getTestRootDisposable()); doTest(new JavaWithNotSurrounder()); } - + public void testSurroundExpressionWithElseIf() { TemplateManagerImpl.setTemplateTesting(getProject(), getTestRootDisposable()); doTest(new JavaWithIfExpressionSurrounder()); } - + public void testSurroundExpressionWithElseIfElse() { TemplateManagerImpl.setTemplateTesting(getProject(), getTestRootDisposable()); doTest(new JavaWithIfElseExpressionSurrounder()); @@ -194,7 +193,7 @@ public class JavaSurroundWithTest extends LightCodeInsightTestCase { doTest(new JavaWithBlockSurrounder()); } - public void testNoParenthesisSurrounderForLambdaParameter() throws Exception { + public void testNoParenthesisSurrounderForLambdaParameter() { configureByFile(BASE_PATH + getTestName(false) + ".java"); SurroundDescriptor item = ContainerUtil.getFirstItem(LanguageSurrounders.INSTANCE.allForLanguage(JavaLanguage.INSTANCE)); @@ -207,10 +206,10 @@ public class JavaSurroundWithTest extends LightCodeInsightTestCase { private void doTest(Surrounder surrounder) { doTest(getTestName(false), surrounder); } - - private void doTest(@NotNull String fileName, final Surrounder surrounder) { + + private void doTest(@NotNull String fileName, Surrounder surrounder) { configureByFile(BASE_PATH + fileName + ".java"); - + SurroundDescriptor item = ContainerUtil.getFirstItem(LanguageSurrounders.INSTANCE.allForLanguage(JavaLanguage.INSTANCE)); assertNotNull(item); SelectionModel selectionModel = getEditor().getSelectionModel(); @@ -221,8 +220,7 @@ public class JavaSurroundWithTest extends LightCodeInsightTestCase { checkResultByFile(BASE_PATH + fileName + "_after.java"); } - private void doTestWithTemplateFinish(@NotNull String fileName, final Surrounder surrounder, @Nullable String textToType) - throws Exception { + private void doTestWithTemplateFinish(@NotNull String fileName, Surrounder surrounder, @Nullable String textToType) { TemplateManagerImpl.setTemplateTesting(getProject(), getTestRootDisposable()); configureByFile(BASE_PATH + fileName + ".java"); SurroundWithHandler.invoke(getProject(), getEditor(), getFile(), surrounder); diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/template/LiveTemplateTest.groovy b/java/java-tests/testSrc/com/intellij/codeInsight/template/LiveTemplateTest.groovy index 6f1665b6203b..dc4fc95fc78a 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/template/LiveTemplateTest.groovy +++ b/java/java-tests/testSrc/com/intellij/codeInsight/template/LiveTemplateTest.groovy @@ -39,21 +39,21 @@ import static com.intellij.codeInsight.template.Template.Property.USE_STATIC_IMP /** * @author spleaner */ +@SuppressWarnings("SpellCheckingInspection") public class LiveTemplateTest extends LightCodeInsightFixtureTestCase { - @Override protected String getBasePath() { return JavaTestUtil.getRelativeJavaTestDataPath() + "/codeInsight/template/"; } @Override - protected void setUp() throws Exception { + protected void setUp() { super.setUp(); TemplateManagerImpl.setTemplateTesting(getProject(), getTestRootDisposable()); } @Override - protected void tearDown() throws Exception { + protected void tearDown() { CodeInsightSettings.instance.COMPLETION_CASE_SENSITIVE = CodeInsightSettings.FIRST_LETTER CodeInsightSettings.instance.SELECT_AUTOPOPUP_SUGGESTIONS_BY_CHARS = false if (state != null) { @@ -132,7 +132,7 @@ public class LiveTemplateTest extends LightCodeInsightFixtureTestCase { doTestTemplateWithArg("tst#", 'wrap($ARG$)', "tst# arg", "tst# arg"); } - public void testTemplateAtEndOfFile() throws Exception { + public void testTemplateAtEndOfFile() { configureFromFileText("empty.java", ""); final TemplateManager manager = TemplateManager.getInstance(getProject()); final Template template = manager.createTemplate("empty", "user", '$VAR$'); @@ -142,7 +142,7 @@ public class LiveTemplateTest extends LightCodeInsightFixtureTestCase { checkResultByText(""); } - public void testTemplateWithEnd() throws Exception { + public void testTemplateWithEnd() { configureFromFileText("empty.java", ""); final TemplateManager manager = TemplateManager.getInstance(getProject()); final Template template = manager.createTemplate("empty", "user", '$VAR$$END$'); @@ -153,8 +153,8 @@ public class LiveTemplateTest extends LightCodeInsightFixtureTestCase { myFixture.type("foo"); checkResultByText("foo"); } - - public void testTemplateWithIndentedEnd() throws Exception { + + public void testTemplateWithIndentedEnd() { configureFromFileText("empty.java", "class C {\n" + " bar() {\n" + " \n" + @@ -176,7 +176,7 @@ public class LiveTemplateTest extends LightCodeInsightFixtureTestCase { } - public void testTemplateWithEndOnEmptyLine() throws Exception { + public void testTemplateWithEndOnEmptyLine() { configureFromFileText("empty.java", "class C {\n" + " bar() {\n" + " \n" + @@ -205,7 +205,7 @@ public class LiveTemplateTest extends LightCodeInsightFixtureTestCase { myFixture.configureByText(name, text); } - public void testEndInTheMiddle() throws Exception { + public void testEndInTheMiddle() { configure(); final TemplateManager manager = TemplateManager.getInstance(getProject()); final Template template = manager.createTemplate("frm", "user", "javax.swing.JFrame frame = new javax.swing.JFrame();\n" + @@ -291,7 +291,7 @@ class Foo { state.gotoEnd(); checkResult(); } - + def startTemplate(String name, char expandKey) { myFixture.type(name) myFixture.type(expandKey) @@ -373,7 +373,7 @@ class Foo { checkResult(); } - public void _testIterForceBraces() { + public void "_testIterForceBraces"() { CodeStyleSettingsManager.getSettings(getProject()).IF_BRACE_FORCE = CommonCodeStyleSettings.FORCE_BRACES_ALWAYS; try { @@ -427,7 +427,7 @@ class Foo { checkResult(); } - public void testJavaStatementContext() throws Exception { + public void testJavaStatementContext() { final TemplateImpl template = TemplateSettings.getInstance().getTemplate("inst", "other"); assertFalse(isApplicable("class Foo {{ if (a inst) }}", template)); assertTrue(isApplicable("class Foo {{ inst }}", template)); @@ -441,7 +441,7 @@ class Foo { assertTrue(isApplicable("class Foo {{ Runnable r = () -> System.out.println(\"foo\"); ) }}", template)); } - public void testJavaExpressionContext() throws Exception { + public void testJavaExpressionContext() { final TemplateImpl template = TemplateSettings.getInstance().getTemplate("toar", "other"); assertFalse(isApplicable("class Foo {{ if (a toar) }}", template)); assertTrue(isApplicable("class Foo {{ toar }}", template)); @@ -451,7 +451,7 @@ class Foo { assertTrue(isApplicable("class Foo {{ Runnable r = () -> System.out.println(\"foo\"); ) }}", template)); } - public void testJavaDeclarationContext() throws Exception { + public void testJavaDeclarationContext() { final TemplateImpl template = TemplateSettings.getInstance().getTemplate("psvm", "other"); assertFalse(isApplicable("class Foo {{ xxx }}", template)); assertFalse(isApplicable("class Foo {{ xxx }}", template)); @@ -491,7 +491,7 @@ class Foo { } @Override - protected void invokeTestRunnable(@NotNull final Runnable runnable) throws Exception { + protected void invokeTestRunnable(@NotNull final Runnable runnable) { if (name in ["testNavigationActionsDontTerminateTemplate", "testTemplateWithEnd", "testDisappearingVar", "test do replace macro value with empty result", "test do not replace macro value with null result", @@ -683,8 +683,8 @@ class Outer { myFixture.configureByText 'a.java', ''' import java.util.*; class Foo { - List> foo() { - + List> foo() { + } } ''' @@ -748,8 +748,8 @@ class Foo { } public void "test reuse static import"() { - myFixture.addClass("""package foo; -public class Bar { + myFixture.addClass("""package foo; +public class Bar { public static void someMethod() {} public static void someMethod(int a) {} }""") @@ -869,7 +869,7 @@ class Foo { myFixture.checkResult """\ class Foo { { - a.java + a.java """ + """ } } """ @@ -883,7 +883,7 @@ class Foo { } """ } - + public void "test do replace macro value with empty result"() { myFixture.configureByText "a.java", """\ class Foo { @@ -903,7 +903,7 @@ class Foo { myFixture.checkResult """\ class Foo { { - + """ + """ } } """ @@ -920,7 +920,7 @@ class Foo { myFixture.checkResult """\ class Foo { { - + """ + """ } } """ @@ -946,7 +946,7 @@ class Foo { @Override Result calculateResult(@NotNull Expression[] params, ExpressionContext context) { def state = TemplateManagerImpl.getTemplateState(context.editor) - return state != null ? state.getVariableValue(myVariableName) : null + return state != null ? state.getVariableValue(myVariableName) : null } @Override @@ -982,10 +982,9 @@ class Foo { } } """) - } - - public void "test multicaret expanding with enter"() { + + public void "test multicaret expanding with enter"() { myFixture.configureByText "a.java", """\ class Foo { { @@ -1012,10 +1011,9 @@ class Foo { } } """) - } - - public void "test multicaret expanding with tab"() { + + public void "test multicaret expanding with tab"() { myFixture.configureByText "a.java", """\ class Foo { { @@ -1033,7 +1031,7 @@ class Foo { finally { TemplateSettings.instance.defaultShortcutChar = defaultShortcutChar } - + myFixture.checkResult("""\ class Foo { { diff --git a/platform/lang-api/src/com/intellij/codeInsight/lookup/LookupElement.java b/platform/lang-api/src/com/intellij/codeInsight/lookup/LookupElement.java index d6deb948dfcb..62a6281b3f99 100644 --- a/platform/lang-api/src/com/intellij/codeInsight/lookup/LookupElement.java +++ b/platform/lang-api/src/com/intellij/codeInsight/lookup/LookupElement.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 JetBrains s.r.o. + * Copyright 2000-2015 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. @@ -29,7 +29,7 @@ import java.util.Collections; import java.util.Set; /** - * A typical way to create lookup element is to use {@link com.intellij.codeInsight.lookup.LookupElementBuilder}. + * A typical way to create lookup element is to use {@link LookupElementBuilder}. * Another way is to subclass it. Use the latter way only if you need it to implement some additional interface, to modify equals/hashCode * or other advanced logic. * @@ -94,7 +94,7 @@ public abstract class LookupElement extends UserDataHolderBase { } /** - * use {@link #as(com.intellij.openapi.util.ClassConditionKey)} instead + * use {@link #as(ClassConditionKey)} instead */ @Deprecated @Nullable @@ -102,6 +102,7 @@ public abstract class LookupElement extends UserDataHolderBase { return as(ClassConditionKey.create(aClass)); } + @SuppressWarnings("unchecked") @Nullable public T as(ClassConditionKey conditionKey) { return conditionKey.isInstance(this) ? (T) this : null; diff --git a/platform/lang-api/src/com/intellij/codeInsight/template/Expression.java b/platform/lang-api/src/com/intellij/codeInsight/template/Expression.java index a5205581a1c2..2cf64cce2e1e 100644 --- a/platform/lang-api/src/com/intellij/codeInsight/template/Expression.java +++ b/platform/lang-api/src/com/intellij/codeInsight/template/Expression.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2015 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. @@ -13,14 +13,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package com.intellij.codeInsight.template; import com.intellij.codeInsight.lookup.LookupElement; import org.jetbrains.annotations.Nullable; public abstract class Expression { - @Nullable public abstract Result calculateResult(ExpressionContext context); @@ -35,4 +33,3 @@ public abstract class Expression { return null; } } - diff --git a/platform/lang-api/src/com/intellij/codeInsight/template/TemplateBuilder.java b/platform/lang-api/src/com/intellij/codeInsight/template/TemplateBuilder.java index 3d938c68a3c4..aceeeb8b7de9 100644 --- a/platform/lang-api/src/com/intellij/codeInsight/template/TemplateBuilder.java +++ b/platform/lang-api/src/com/intellij/codeInsight/template/TemplateBuilder.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2015 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. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package com.intellij.codeInsight.template; import com.intellij.openapi.editor.Editor; @@ -25,9 +24,9 @@ import org.jetbrains.annotations.NotNull; * Shows a live template-like chooser UI over a PSI element and offers the user to replace certain sub-elements of the * specified element with values of his/her choice. * - * @since 9.0 * @author yole - * @see com.intellij.codeInsight.template.TemplateBuilderFactory + * @see TemplateBuilderFactory + * @since 9.0 */ public interface TemplateBuilder { /** @@ -66,7 +65,7 @@ public interface TemplateBuilder { /** * Shows the live template and initiates editing process. - * @deprecated doesn't work correctly for files with multiple editors use #run(Editor, boolean) instead + * @deprecated does not work correctly for files with multiple editors use #run(Editor, boolean) instead */ @Deprecated void run(); diff --git a/platform/lang-impl/src/com/intellij/refactoring/actions/IntroduceVariableAction.java b/platform/lang-impl/src/com/intellij/refactoring/actions/IntroduceVariableAction.java index 8cb58e5010f3..0e81133d57f2 100644 --- a/platform/lang-impl/src/com/intellij/refactoring/actions/IntroduceVariableAction.java +++ b/platform/lang-impl/src/com/intellij/refactoring/actions/IntroduceVariableAction.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2011 JetBrains s.r.o. + * Copyright 2000-2015 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. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package com.intellij.refactoring.actions; import com.intellij.lang.refactoring.RefactoringSupportProvider; @@ -45,5 +44,6 @@ public class IntroduceVariableAction extends BasePlatformRefactoringAction { @Nullable @Override protected RefactoringActionHandler getRefactoringHandler(@NotNull RefactoringSupportProvider provider, PsiElement element) { - return provider.getIntroduceVariableHandler(element);} + return provider.getIntroduceVariableHandler(element); + } }