diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/PsiElementFactoryImpl.java b/java/java-psi-impl/src/com/intellij/psi/impl/PsiElementFactoryImpl.java index 3e1b6d9472c7..9c9862303e4b 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/PsiElementFactoryImpl.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/PsiElementFactoryImpl.java @@ -20,9 +20,7 @@ import com.intellij.lang.java.parser.JavaParser; import com.intellij.lang.java.parser.JavaParserUtil; import com.intellij.lexer.JavaLexer; import com.intellij.lexer.Lexer; -import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.project.Project; -import com.intellij.openapi.util.text.StringUtil; import com.intellij.pom.java.LanguageLevel; import com.intellij.psi.*; import com.intellij.psi.codeStyle.CodeStyleManager; @@ -49,8 +47,6 @@ import java.util.Map; import static com.intellij.openapi.util.text.StringUtil.join; public class PsiElementFactoryImpl extends PsiJavaParserFacadeImpl implements PsiElementFactory { - private static final Logger LOG = Logger.getInstance("#com.intellij.psi.impl.PsiElementFactoryImpl"); - private PsiClass myArrayClass; private PsiClass myArrayClass15; @@ -172,7 +168,9 @@ public class PsiElementFactoryImpl extends PsiJavaParserFacadeImpl implements Ps @NotNull @Override public PsiTypeParameterList createTypeParameterList() { - return createMethodFromText("void foo()", null).getTypeParameterList(); + final PsiTypeParameterList parameterList = createMethodFromText("void foo()", null).getTypeParameterList(); + assert parameterList != null; + return parameterList; } @NotNull @@ -733,7 +731,7 @@ public class PsiElementFactoryImpl extends PsiJavaParserFacadeImpl implements Ps if (!(exceptionType instanceof PsiClassType || exceptionType instanceof PsiDisjunctionType)) { throw new IncorrectOperationException("Unexpected type:" + exceptionType); } - final String text = StringUtil.join("catch (", exceptionType.getCanonicalText(), " ", exceptionName, ") {}"); + final String text = join("catch (", exceptionType.getCanonicalText(), " ", exceptionName, ") {}"); final DummyHolder holder = DummyHolderFactory.createHolder(myManager, new JavaDummyElement(text, CATCH_SECTION, level(context)), context); final PsiElement element = SourceTreeToPsiMap.treeElementToPsi(holder.getTreeElement().getFirstChildNode()); if (!(element instanceof PsiCatchSection)) { diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/GenerateConstructorTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/GenerateConstructorTest.java index c04ab6a28d4c..17fdce4e9d24 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/GenerateConstructorTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/GenerateConstructorTest.java @@ -1,17 +1,32 @@ /* - * @author ven + * 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.codeInsight; import com.intellij.codeInsight.generation.ClassMember; import com.intellij.codeInsight.generation.GenerateConstructorHandler; import com.intellij.openapi.project.Project; -import com.intellij.psi.codeStyle.CodeStyleSettings; import com.intellij.psi.codeStyle.CodeStyleSettingsManager; +import com.intellij.psi.codeStyle.CommonCodeStyleSettings; import com.intellij.testFramework.LightCodeInsightTestCase; import java.util.List; +/** + * @author ven + */ public class GenerateConstructorTest extends LightCodeInsightTestCase { public void testAbstractClass() throws Exception { doTest(); } public void testPackageLocalClass() throws Exception { doTest(); } @@ -22,25 +37,22 @@ public class GenerateConstructorTest extends LightCodeInsightTestCase { public void testNoMoreConstructorsCanBeGenerated() throws Exception { doTest(); } public void testImmediatelyAfterRBrace() throws Exception { // IDEADEV-28811 - final CodeStyleSettings settings = CodeStyleSettingsManager.getInstance(getProject()).getCurrentSettings(); - final int old = settings.CLASS_BRACE_STYLE; - settings.CLASS_BRACE_STYLE = CodeStyleSettings.NEXT_LINE; - try { - doTest(); - } - finally { - settings.CLASS_BRACE_STYLE = old; - } - } - - public void testBoundCommentsKeepsBlankLine() throws Exception { - CodeStyleSettingsManager styleSettingsManager = CodeStyleSettingsManager.getInstance(getProject()); - final CodeStyleSettings settings = styleSettingsManager.getCurrentSettings(); - settings.BLANK_LINES_AFTER_CLASS_HEADER = 1; + CodeStyleSettingsManager.getInstance(getProject()).getCurrentSettings().CLASS_BRACE_STYLE = CommonCodeStyleSettings.NEXT_LINE; doTest(); } - public void testFinalFieldPreselection() throws Exception { + public void testBoundCommentsKeepsBlankLine() throws Exception { + CodeStyleSettingsManager.getInstance(getProject()).getCurrentSettings().BLANK_LINES_AFTER_CLASS_HEADER = 1; + doTest(); + } + + public void testFinalFieldPreselection() throws Exception { doTest(true); } + + private void doTest() throws Exception { + doTest(false); + } + + private void doTest(final boolean preSelect) throws Exception { String name = getTestName(false); configureByFile("/codeInsight/generateConstructor/before" + name + ".java"); new GenerateConstructorHandler() { @@ -49,30 +61,15 @@ public class GenerateConstructorTest extends LightCodeInsightTestCase { boolean allowEmptySelection, boolean copyJavadocCheckbox, Project project) { - final List preselection = GenerateConstructorHandler.preselect(members); - return preselection.toArray(new ClassMember[preselection.size()]); + if (preSelect) { + final List preselection = GenerateConstructorHandler.preselect(members); + return preselection.toArray(new ClassMember[preselection.size()]); + } + else { + return members; + } } }.invoke(getProject(), getEditor(), getFile()); - checkResultByFile("/codeInsight/generateConstructor/after" + name +".java"); - } - - private void doTest() throws Exception { - String name = getTestName(false); - configureByFile("/codeInsight/generateConstructor/before" + - name + - ".java"); - new GenerateConstructorHandler(){ - @Override - protected ClassMember[] chooseMembers(ClassMember[] members, - boolean allowEmptySelection, - boolean copyJavadocCheckbox, - Project project) { - return members; - } - }.invoke(getProject(), getEditor(), getFile()); - checkResultByFile("/codeInsight/generateConstructor/after" + - name + - ".java"); - + checkResultByFile("/codeInsight/generateConstructor/after" + name + ".java"); } } diff --git a/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/actions/generate/GroovyGenerateMembersTest.groovy b/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/actions/generate/GroovyGenerateMembersTest.groovy index 21407c5013d4..7bc45e844461 100644 --- a/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/actions/generate/GroovyGenerateMembersTest.groovy +++ b/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/actions/generate/GroovyGenerateMembersTest.groovy @@ -1,10 +1,20 @@ /* - * Copyright (c) 2000-2005 by JetBrains s.r.o. All Rights Reserved. - * Use is subject to license terms. + * 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.lang.actions.generate; - import com.intellij.openapi.application.Result import com.intellij.openapi.application.RunResult import com.intellij.openapi.command.WriteCommandAction @@ -23,20 +33,19 @@ import com.intellij.psi.impl.source.PostprocessReformattingAspect * @author peter */ public class GroovyGenerateMembersTest extends LightCodeInsightFixtureTestCase { - - public void testConstructorAtOffset() throws Throwable { + public void testConstructorAtOffset() { doConstructorTest(); } - public void testConstructorAtEnd() throws Throwable { - doConstructorTest(); - } - - public void testLonelyConstructor() throws Throwable { + public void testConstructorAtEnd() { doConstructorTest(); } - public void testExplicitArgumentTypes() throws Exception { + public void testLonelyConstructor() { + doConstructorTest(); + } + + public void testExplicitArgumentTypes() { myFixture.configureByText("a.groovy", """ class Super { def Super(a, int b) {} @@ -117,14 +126,14 @@ class Test { } void testGetter2() { - myFixture.configureByText 'a.groovy', ''' + myFixture.configureByText 'a.groovy', ''' class Test { int foo }''' - generateGetter() + generateGetter() - myFixture.checkResult ''' + myFixture.checkResult ''' class Test { int foo @@ -132,7 +141,7 @@ class Test { return foo } }''' - } + } void testGetter3() { myFixture.configureByText 'a.groovy', ''' @@ -140,9 +149,9 @@ class Test { static foo }''' - generateGetter() + generateGetter() - myFixture.checkResult ''' + myFixture.checkResult ''' class Test { static foo @@ -150,7 +159,7 @@ class Test { return foo } }''' - } + } void testGetter4() { myFixture.addFileToProject('org/jetbrains/annotations/Nullable.java', 'package org.jetbrains.annotations; public @interface Nullable {}') @@ -163,9 +172,9 @@ class Test { def foo }''' - generateGetter() + generateGetter() - myFixture.checkResult ''' + myFixture.checkResult ''' import org.jetbrains.annotations.Nullable class Test { @@ -176,7 +185,7 @@ class Test { return foo } }''' - } + } void testSetter1() { myFixture.configureByText 'a.groovy', ''' @@ -195,7 +204,6 @@ class Test { this.foo = foo } }''' - } void testSetter2() { @@ -215,7 +223,6 @@ class Test { this.foo = foo } }''' - } void testSetter3() { @@ -236,7 +243,6 @@ class Test { Test.foo = foo } }''' - } void testSetter4() { @@ -264,7 +270,6 @@ class Test { this.foo = foo } }''' - } void testConstructorInTheMiddle() { @@ -272,11 +277,8 @@ class Test { class Foo { def foo() {} - - - def bar() {} }""") generateConstructor() @@ -323,7 +325,7 @@ class Foo { }.execute() } - private void doConstructorTest() throws Throwable { + private void doConstructorTest() { myFixture.configureByFile(getTestName(false) + ".groovy"); generateConstructor(); myFixture.checkResultByFile(getTestName(false) + "_after.groovy"); @@ -338,7 +340,6 @@ class Foo { members << new PsiMethodMember(aClass.superClass.constructors[0]) return members as ClassMember[] } - }.invoke(project, myFixture.editor, myFixture.file); PostprocessReformattingAspect.getInstance(project).doPostponedFormatting() }