diff --git a/java/java-impl/src/com/intellij/psi/impl/source/codeStyle/javadoc/CommentFormatter.java b/java/java-impl/src/com/intellij/psi/impl/source/codeStyle/javadoc/CommentFormatter.java index 624c5370c4ad..aaf47cfb0a7d 100644 --- a/java/java-impl/src/com/intellij/psi/impl/source/codeStyle/javadoc/CommentFormatter.java +++ b/java/java-impl/src/com/intellij/psi/impl/source/codeStyle/javadoc/CommentFormatter.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * 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. @@ -20,6 +20,7 @@ import com.intellij.lang.ASTNode; import com.intellij.lang.java.JavaLanguage; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.project.Project; +import com.intellij.openapi.roots.LanguageLevelProjectExtension; import com.intellij.openapi.util.text.LineTokenizer; import com.intellij.openapi.util.text.StringUtil; import com.intellij.psi.*; @@ -45,7 +46,7 @@ public class CommentFormatter { public CommentFormatter(@NotNull Project project) { mySettings = CodeStyleSettingsManager.getSettings(project); - myParser = new JDParser(mySettings); + myParser = new JDParser(mySettings, LanguageLevelProjectExtension.getInstance(project).getLanguageLevel()); myProject = project; } diff --git a/java/java-impl/src/com/intellij/psi/impl/source/codeStyle/javadoc/JDParser.java b/java/java-impl/src/com/intellij/psi/impl/source/codeStyle/javadoc/JDParser.java index f4ba00070611..5dbc02583aa7 100644 --- a/java/java-impl/src/com/intellij/psi/impl/source/codeStyle/javadoc/JDParser.java +++ b/java/java-impl/src/com/intellij/psi/impl/source/codeStyle/javadoc/JDParser.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * 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. @@ -17,6 +17,7 @@ package com.intellij.psi.impl.source.codeStyle.javadoc; import com.intellij.openapi.util.Pair; import com.intellij.openapi.util.text.StringUtil; +import com.intellij.pom.java.LanguageLevel; import com.intellij.psi.codeStyle.CodeStyleSettings; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -39,9 +40,11 @@ public class JDParser { private static final String SELF_CLOSED_P_TAG = "
"; private final CodeStyleSettings mySettings; + private final LanguageLevel myLanguageLevel; - public JDParser(@NotNull CodeStyleSettings settings) { + public JDParser(@NotNull CodeStyleSettings settings, @NotNull LanguageLevel languageLevel) { mySettings = settings; + myLanguageLevel = languageLevel; } private static final char lineSeparator = '\n'; @@ -514,7 +517,13 @@ public class JDParser { if (line.length() == 0 && !mySettings.JD_KEEP_EMPTY_LINES) continue; if (i != 0) sb.append(prefix); if (line.length() == 0 && mySettings.JD_P_AT_EMPTY_LINES && !insidePreTag) { - sb.append(SELF_CLOSED_P_TAG); + if (myLanguageLevel.isAtLeast(LanguageLevel.JDK_1_8)) { + //Self-closing elements are not allowed for javadoc tool from JDK8 + sb.append(P_START_TAG); + } + else { + sb.append(SELF_CLOSED_P_TAG); + } } else { sb.append(line); diff --git a/java/java-tests/testSrc/com/intellij/psi/formatter/java/JavadocFormatterTest.java b/java/java-tests/testSrc/com/intellij/psi/formatter/java/JavadocFormatterTest.java index 24adb297bce6..d4c7274c1cca 100644 --- a/java/java-tests/testSrc/com/intellij/psi/formatter/java/JavadocFormatterTest.java +++ b/java/java-tests/testSrc/com/intellij/psi/formatter/java/JavadocFormatterTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2011 JetBrains s.r.o. + * 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. @@ -17,6 +17,8 @@ package com.intellij.psi.formatter.java; import com.intellij.lang.java.JavaLanguage; +import com.intellij.openapi.roots.LanguageLevelProjectExtension; +import com.intellij.pom.java.LanguageLevel; import com.intellij.psi.codeStyle.CommonCodeStyleSettings; /** @@ -95,6 +97,7 @@ public class JavadocFormatterTest extends AbstractJavaFormatterTest { getSettings().getRootSettings().ENABLE_JAVADOC_FORMATTING = true; getSettings().getRootSettings().WRAP_COMMENTS = true; getSettings().getRootSettings().RIGHT_MARGIN = 20; + LanguageLevelProjectExtension.getInstance(getProject()).setLanguageLevel(LanguageLevel.JDK_1_7); doTextTest("/**\n" + " * \n" + " * Another paragraph of the description placed after blank line.\n" + " */\n" + "class A{}", "/**\n" + @@ -107,11 +110,31 @@ public class JavadocFormatterTest extends AbstractJavaFormatterTest { "class A {\n" + "}"); } - + + public void testSCR2632_JDK8_LanguageLevel() throws Exception { + getSettings().getRootSettings().ENABLE_JAVADOC_FORMATTING = true; + getSettings().getRootSettings().WRAP_COMMENTS = true; + getSettings().getRootSettings().RIGHT_MARGIN = 20; + LanguageLevelProjectExtension.getInstance(getProject()).setLanguageLevel(LanguageLevel.JDK_1_8); + + doTextTest("/**\n" + " * \n" + " * Another paragraph of the description placed after blank line.\n" + " */\n" + "class A{}", + "/**\n" + + " *\n" + + " * Another paragraph\n" + + " * of the description\n" + + " * placed after\n" + + " * blank line.\n" + + " */\n" + + "class A {\n" + + "}"); + } + + public void testParagraphTagGeneration() { // Inspired by IDEA-61811 getSettings().getRootSettings().ENABLE_JAVADOC_FORMATTING = true; getSettings().getRootSettings().JD_P_AT_EMPTY_LINES = true; + LanguageLevelProjectExtension.getInstance(getProject()).setLanguageLevel(LanguageLevel.JDK_1_7); doTextTest( "/**\n" + " * line 1\n" + @@ -618,4 +641,47 @@ public class JavadocFormatterTest extends AbstractJavaFormatterTest { "}"; doTextTest(before, before); } + + + public void testNotGenerateSelfClosingPTagIfLanguageLevelJava8() throws Exception { + getSettings().getRootSettings().JD_P_AT_EMPTY_LINES = true; + getSettings().getRootSettings().ENABLE_JAVADOC_FORMATTING = true; + String before = "/**\n" + + " * Super method\n" + + " *\n" + + " * Super multiple times\n" + + " */\n" + + "public void voo() {\n" + + "}\n"; + String after = "/**\n" + + " * Super method\n" + + " *
\n" + + " * Super multiple times\n" + + " */\n" + + "public void voo() {\n" + + "}\n"; + doClassTest(before, after); + } + + public void testGenerateSelfClosingPTagIfLanguageLevelNotJava8() throws Exception { + getSettings().getRootSettings().JD_P_AT_EMPTY_LINES = true; + getSettings().getRootSettings().ENABLE_JAVADOC_FORMATTING = true; + LanguageLevelProjectExtension.getInstance(getProject()).setLanguageLevel(LanguageLevel.JDK_1_7); + String before = "/**\n" + + " * Super method\n" + + " *\n" + + " * Super multiple times\n" + + " */\n" + + "public void voo() {\n" + + "}\n"; + String after = "/**\n" + + " * Super method\n" + + " *
\n" + + " * Super multiple times\n" + + " */\n" + + "public void voo() {\n" + + "}\n"; + doClassTest(before, after); + } + } \ No newline at end of file