IDEA-164610 Quick documentation should escape angle brackets at the value of a String field referred via @value (javadoc tag)

also add quotes to string value, and convert value into a link to corresponding field's javadoc, like javadoc tool does
This commit is contained in:
Dmitry Batrak
2016-11-30 16:37:37 +03:00
parent 59c6fe0401
commit e6a6f609ea
6 changed files with 17 additions and 3 deletions

View File

@@ -1463,7 +1463,10 @@ public class JavaDocInfoGenerator {
}
if (value != null) {
buffer.append(value);
String valueText = StringUtil.escapeXml(value.toString());
if (value instanceof String) valueText = '"' + valueText + '"';
if (valueField.equals(myElement)) buffer.append(valueText); // don't generate link to itself
else generateLink(buffer, valueField, valueText, true);
}
else {
buffer.append(element.getText());

View File

@@ -0,0 +1 @@
<html><head><base href="placeholder"> <style type="text/css"> #error { background-color: #eeeeee; margin-bottom: 10px; } p { margin: 5px 0; } </style></head><body><small><b><a href="psi_element://A"><code>A</code></a></b></small><PRE>public static&nbsp;void&nbsp;<b>JAVADOC_ME</b>()</PRE> The value of B is <a href="psi_element://A#B">"a&lt;b"</a>.</body></html>

View File

@@ -0,0 +1,6 @@
class A {
public static String B = "a<b";
/** The value of B is {@value #B}. */
public static void JAVADOC_ME() { }
}

View File

@@ -1 +1 @@
<html><head><base href="placeholder"> <style type="text/css"> #error { background-color: #eeeeee; margin-bottom: 10px; } p { margin: 5px 0; } </style></head><body><small><b><a href="psi_element://A"><code>A</code></a></b></small><PRE>public static&nbsp;void&nbsp;<b>JAVADOC_ME</b>()</PRE> The value of A is 23.</body></html>
<html><head><base href="placeholder"> <style type="text/css"> #error { background-color: #eeeeee; margin-bottom: 10px; } p { margin: 5px 0; } </style></head><body><small><b><a href="psi_element://A"><code>A</code></a></b></small><PRE>public static&nbsp;void&nbsp;<b>JAVADOC_ME</b>()</PRE> The value of A is <a href="psi_element://A#A">23</a>.</body></html>

View File

@@ -1 +1 @@
<html><head><base href="placeholder"> <style type="text/css"> #error { background-color: #eeeeee; margin-bottom: 10px; } p { margin: 5px 0; } </style></head><body><small><b><a href="psi_element://A"><code>A</code></a></b></small><PRE>public static&nbsp;void&nbsp;<b>JAVADOC_ME</b>()</PRE> The value of A is 23.</body></html>
<html><head><base href="placeholder"> <style type="text/css"> #error { background-color: #eeeeee; margin-bottom: 10px; } p { margin: 5px 0; } </style></head><body><small><b><a href="psi_element://A"><code>A</code></a></b></small><PRE>public static&nbsp;void&nbsp;<b>JAVADOC_ME</b>()</PRE> The value of A is <a href="psi_element://A#A">23</a>.</body></html>

View File

@@ -65,6 +65,10 @@ public class JavaDocInfoGeneratorTest extends CodeInsightTestCase {
doTestMethod();
}
public void testEscapingStringValue() throws Exception {
doTestMethod();
}
public void testIdeadev2326() throws Exception {
doTestMethod();
}