From 3d9d563c43a6f8b573df66d0045fd1fc2920391e Mon Sep 17 00:00:00 2001 From: Anna Kozlova Date: Mon, 30 Dec 2013 20:11:42 +0100 Subject: [PATCH] quick documentation: fix formatting stripping html tags (IDEA-118673) --- .../javadoc/JavaDocInfoGenerator.java | 34 +++++++++++-------- .../javadocIG/methodFormatting.html | 3 ++ .../javadocIG/methodFormatting.java | 12 +++++++ .../javadoc/JavaDocInfoGeneratorTest.java | 4 +++ 4 files changed, 39 insertions(+), 14 deletions(-) create mode 100644 java/java-tests/testData/codeInsight/javadocIG/methodFormatting.html create mode 100644 java/java-tests/testData/codeInsight/javadocIG/methodFormatting.java diff --git a/java/java-psi-impl/src/com/intellij/codeInsight/javadoc/JavaDocInfoGenerator.java b/java/java-psi-impl/src/com/intellij/codeInsight/javadoc/JavaDocInfoGenerator.java index bd06902e8b2f..4cc3345ed3c0 100644 --- a/java/java-psi-impl/src/com/intellij/codeInsight/javadoc/JavaDocInfoGenerator.java +++ b/java/java-psi-impl/src/com/intellij/codeInsight/javadoc/JavaDocInfoGenerator.java @@ -71,7 +71,9 @@ public class JavaDocInfoGenerator { @NonNls private static final String INHERITDOC_TAG = "inheritDoc"; @NonNls private static final String DOCROOT_TAG = "docRoot"; @NonNls private static final String VALUE_TAG = "value"; - + private static final String LT = "<"; + private static final String GT = ">"; + private final Project myProject; private final PsiElement myElement; @@ -732,7 +734,7 @@ public class JavaDocInfoGenerator { } final String typeParamsString = generateTypeParameters(method); - indent += typeParamsString.length(); + indent += StringUtil.unescapeXml(StringUtil.stripHtml(typeParamsString, true)).length(); if (!typeParamsString.isEmpty()) { buffer.append(typeParamsString); buffer.append(" "); @@ -1083,8 +1085,8 @@ public class JavaDocInfoGenerator { } private static void appendPlainText(@NonNls String text, final StringBuilder buffer) { - text = text.replaceAll("<", "<"); - text = text.replaceAll(">", ">"); + text = text.replaceAll("<", LT); + text = text.replaceAll(">", GT); buffer.append(text); } @@ -1540,12 +1542,12 @@ public class JavaDocInfoGenerator { buffer.append(""); buffer.append(label); buffer.append(""); - return label.length(); + return StringUtil.stripHtml(label, true).length(); } generateLink(buffer, target, label, plainLink); - return label.length(); + return StringUtil.stripHtml(label, true).length(); } /** @@ -1605,9 +1607,10 @@ public class JavaDocInfoGenerator { PsiSubstitutor psiSubst = result.getSubstitutor(); if (psiClass == null) { - String text = "" + StringUtil.escapeXml(type.getCanonicalText()) + ""; + String canonicalText = type.getCanonicalText(); + String text = "" + StringUtil.escapeXml(canonicalText) + ""; buffer.append(text); - return text.length(); + return canonicalText.length(); } String qName = psiClass.getQualifiedName(); @@ -1632,7 +1635,8 @@ public class JavaDocInfoGenerator { PsiTypeParameter[] params = psiClass.getTypeParameters(); - subst.append("<"); + subst.append(LT); + length += 1; boolean goodSubst = true; for (int i = 0; i < params.length; i++) { PsiType t = psiSubst.substitute(params[i]); @@ -1649,7 +1653,8 @@ public class JavaDocInfoGenerator { } } - subst.append(">"); + subst.append(GT); + length += 1; if (goodSubst) { String text = subst.toString(); @@ -1662,9 +1667,10 @@ public class JavaDocInfoGenerator { if (type instanceof PsiDisjunctionType || type instanceof PsiIntersectionType) { if (!generateLink) { - final String text = StringUtil.escapeXml(type.getCanonicalText()); + String canonicalText = type.getCanonicalText(); + final String text = StringUtil.escapeXml(canonicalText); buffer.append(text); - return text.length(); + return canonicalText.length(); } else { final String separator = type instanceof PsiDisjunctionType ? " | " : " & "; @@ -1697,7 +1703,7 @@ public class JavaDocInfoGenerator { StringBuilder buffer = new StringBuilder(); - buffer.append("<"); + buffer.append(LT); for (int i = 0; i < parms.length; i++) { PsiTypeParameter p = parms[i]; @@ -1723,7 +1729,7 @@ public class JavaDocInfoGenerator { } } - buffer.append(">"); + buffer.append(GT); return buffer.toString(); } diff --git a/java/java-tests/testData/codeInsight/javadocIG/methodFormatting.html b/java/java-tests/testData/codeInsight/javadocIG/methodFormatting.html new file mode 100644 index 000000000000..9cb61794114c --- /dev/null +++ b/java/java-tests/testData/codeInsight/javadocIG/methodFormatting.html @@ -0,0 +1,3 @@ + Producer
<E extends Exception> void drainTo(Consumer<? super T, E> consumer,
+                                   Object someParameter)
+                           throws E
Throws:
E
\ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/javadocIG/methodFormatting.java b/java/java-tests/testData/codeInsight/javadocIG/methodFormatting.java new file mode 100644 index 000000000000..a6b81242d5bc --- /dev/null +++ b/java/java-tests/testData/codeInsight/javadocIG/methodFormatting.java @@ -0,0 +1,12 @@ +interface Producer { + + void drainTo( Consumer consumer, Object someParameter ) throws E; + +} + +interface Consumer { + + void consume( T message ) throws E; + +} + diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/javadoc/JavaDocInfoGeneratorTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/javadoc/JavaDocInfoGeneratorTest.java index 80d2e4ac2fb6..845ea765a843 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/javadoc/JavaDocInfoGeneratorTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/javadoc/JavaDocInfoGeneratorTest.java @@ -56,6 +56,10 @@ public class JavaDocInfoGeneratorTest extends CodeInsightTestCase { doTestMethod(); } + public void testMethodFormatting() throws Exception { + doTestMethod(); + } + public void testInitializerWithNew() throws Exception { doTestField(); }