/* * Copyright 2000-2013 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.editorActions import com.intellij.openapi.editor.impl.AbstractEditorTest /** * @author Denis Zhdanov * @since 9/20/12 6:17 PM */ class FixDocCommentTest extends AbstractEditorTest { void testGenerateMethodDoc() { doTest( initial: '''\ class Test { String test(int i) { return "s"; } }''', expected: '''\ class Test { /** * @param i * @return */ String test(int i) { return "s"; } }''' ) } void testGenerateFieldDoc() { doTest( initial: '''\ class Test { int i; }''', expected: '''\ class Test { /** * */ int i; }''' ) } void testGenerateClassDoc() { doTest( initial: '''\ class Test { void test1() {} void test2() {} }''', expected: '''\ /** * */ class Test { void test1() {} void test2() {} }''' ) } void testRemoveOneParameterFromMany() { doTest( initial: '''\ class Test { /** * @param i * @param j * @param k */ void test(int i, int j) { } }''', expected: '''\ class Test { /** * @param i * @param j */ void test(int i, int j) { } }''' ) } void testRemoveTheOnlyParameter() { doTest( initial: '''\ class Test { /** * My description * @param i */ void test() { } }''', expected: '''\ class Test { /** * My description */ void test() { } }''' ) } void testRemoveReturn() { doTest( initial: '''\ class Test { /** * My description * @return data */ void test() { } }''', expected: '''\ class Test { /** * My description */ void test() { } }''' ) } void testRemoveOneThrowsFromMany() { doTest( initial: '''\ class MyException1 extends Exception {} class MyException2 extends Exception {} class Test { /** * @param i my arg * @throws MyException1 text1 * @throws MyException2 text2 */ void test(int i) throws MyException2 { } }''', expected: '''\ class MyException1 extends Exception {} class MyException2 extends Exception {} class Test { /** * @param i my arg * @throws MyException2 text2 */ void test(int i) throws MyException2 { } }''' ) } void testRemoveTheOnlyThrows() { doTest( initial: '''\ class MyException extends Exception {} class Test { /** * @param i my arg * @throws MyException text */ void test(int i) { } }''', expected: '''\ class MyException extends Exception {} class Test { /** * @param i my arg */ void test(int i) { } }''' ) } void testRemoveOneTypeParameterFromMany() { doTest( initial: '''\ /** * @param tDescription * @param vDescription */ class Test { }''', expected: '''\ /** * @param vDescription */ class Test { }''' ) } void testRemoveMultipleTypeParameter() { doTest( initial: '''\ /** * @param tDescription * @param vDescription */ class Test { }''', expected: '''\ /** */ class Test { }''' ) } void testAddFirstParameter() { doTest( initial: '''\ class Test { /** */ void test(int i) { } }''', expected: '''\ class Test { /** * @param i */ void test(int i) { } }''' ) } void testAddMultipleParameter() { doTest( initial: '''\ class Test { /** * @param i */ void test(int i, int j, int k) { } }''', expected: '''\ class Test { /** * @param i * @param j * @param k */ void test(int i, int j, int k) { } }''' ) } void testAddReturn() { doTest( initial: '''\ class Test { /** */ int test() { } }''', expected: '''\ class Test { /** * @return */ int test() { } }''' ) } void testAddFirstThrows() { doTest( initial: '''\ class MyException extends Exception {} class Test { /** * @param i my arg */ void test(int i) throws MyException { } }''', expected: '''\ class MyException extends Exception {} class Test { /** * @param i my arg * @throws MyException */ void test(int i) throws MyException { } }''') } void testAddNonFirstThrows() { doTest( initial: '''\ class MyException1 extends Exception {} class MyException2 extends Exception {} class MyException3 extends Exception {} class Test { /** * @param i my arg * @throws MyException1 */ void test(int i) throws MyException1, MyException2, MyException3 { } }''', expected: '''\ class MyException1 extends Exception {} class MyException2 extends Exception {} class MyException3 extends Exception {} class Test { /** * @param i my arg * @throws MyException1 * @throws MyException2 * @throws MyException3 */ void test(int i) throws MyException1, MyException2, MyException3 { } }''') } void testAddFirstThrowsWhenEmptyReturnIsAvailable() { doTest( initial: '''\ class MyException extends Exception {} class Test { /** * @return */ int test() throws MyException { return 1; } }''', expected: '''\ class MyException extends Exception {} class Test { /** * @return * @throws MyException */ int test() throws MyException { return 1; } }''') } void testAddFirstTypeParameter() { doTest( initial: '''\ /** * My description * @author me */ class Test { }''', expected: '''\ /** * My description * @author me * @param */ class Test { }''') } void testAddNonFirstTypeParameter() { doTest( initial: '''\ /** * My description * @author me * @param type description */ class Test { }''', expected: '''\ /** * My description * @author me * @param type description * @param */ class Test { }''') } void testCorrectParametersOrder() { doTest( initial: '''\ class Test { /** * @param j * @param k single line description * @param i multi-line * description */ public void test(int i, int j, int k) { } }''', expected: '''\ class Test { /** * @param i multi-line * description * @param j * @param k single line description */ public void test(int i, int j, int k) { } }''' ) } void testCorrectParametersDescriptionWhenIndentIsDefines() { doTest( initial: '''\ class Test { /** * @param j * @param i */ public void test(int i, int j) { } }''', expected: '''\ class Test { /** * @param i * @param j */ public void test(int i, int j) { } }''' ) } void testCorrectMethodTypeParametersOrder() { doTest( initial: '''\ class Test { /** * @param * @param A description */ void test() { } }''', expected: '''\ class Test { /** * @param A description * @param */ void test() { } }''' ) } void testCorrectClassTypeParametersOrder() { doTest( initial: '''\ /** * Class description * @author Zigmund * @param multi-line * description * @param */ class Test { }''', expected: '''\ /** * Class description * @author Zigmund * @param * @param multi-line * description */ class Test { }''' ) } void testAllesZusammen() { doTest( initial: '''\ class MyException1 extends Exception {} class MyException2 extends Exception {} class Test { /** * Method description * @param j j description (single line) * @param s s description * @param k * k description (single line but located at another line) * @throws MyException2 * @return some value */ void test(int i, int j, int k) throws MyException1 { } }''', expected: '''\ class MyException1 extends Exception {} class MyException2 extends Exception {} class Test { /** * Method description * @param i * @param j j description (single line) * @param k * k description (single line but located at another line) * @throws MyException1 */ void test(int i, int j, int k) throws MyException1 { } }''' ) } void testNavigateToMissingParamDescription() { doTest( initial: '''\ class Test { /** * @param i */ void test(int i) { } }''', expected: '''\ class Test { /** * @param i */ void test(int i) { } }''' ) } private def doTest(Map args) { configureFromFileText("${getTestName(false)}.java", args.initial) myEditor.settings.virtualSpace = false executeAction(FixDocCommentAction.ACTION_ID) checkResultByText(args.expected) } }