mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-161410 Quick Documentation: double opening angle brackets are printed as single brackets
This commit is contained in:
@@ -549,13 +549,24 @@ public class JavaDocumentationProvider extends DocumentationProviderEx implement
|
||||
|
||||
@Nullable
|
||||
public static String generateExternalJavadoc(@NotNull final PsiElement element) {
|
||||
List<String> docURLs = getExternalJavaDocUrl(element);
|
||||
return generateExternalJavadoc(element, docURLs);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static String generateExternalJavadoc(@NotNull final PsiElement element, @Nullable List<String> docURLs) {
|
||||
final JavaDocInfoGenerator javaDocInfoGenerator = JavaDocInfoGeneratorFactory.create(element.getProject(), element);
|
||||
return generateExternalJavadoc(element, javaDocInfoGenerator);
|
||||
return generateExternalJavadoc(javaDocInfoGenerator, docURLs);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static String generateExternalJavadoc(@NotNull final PsiElement element, @NotNull JavaDocInfoGenerator generator) {
|
||||
final List<String> docURLs = getExternalJavaDocUrl(element);
|
||||
return generateExternalJavadoc(generator, docURLs);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static String generateExternalJavadoc(@NotNull JavaDocInfoGenerator generator, @Nullable List<String> docURLs) {
|
||||
return JavaDocExternalFilter.filterInternalDocInfo(generator.generateDocInfo(docURLs));
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
<html><head><base href="placeholder"> <style type="text/css"> #error { background-color: #eeeeee; margin-bottom: 10px; } p { margin: 5px 0; } </style></head><body><PRE>class <b>C</b>
|
||||
extends <a href="psi_element://java.lang.Object"><code>Object</code></a></PRE>
|
||||
a << b</body></html>
|
||||
@@ -0,0 +1,4 @@
|
||||
/**
|
||||
* a << b
|
||||
*/
|
||||
class C {}
|
||||
+13
-3
@@ -176,6 +176,10 @@ public class JavaDocInfoGeneratorTest extends CodeInsightTestCase {
|
||||
doTestField();
|
||||
}
|
||||
|
||||
public void testDoubleLt() throws Exception {
|
||||
doTestClass();
|
||||
}
|
||||
|
||||
public void testEnumConstantOrdinal() throws Exception {
|
||||
PsiClass psiClass = getTestClass();
|
||||
PsiField field = psiClass.getFields() [0];
|
||||
@@ -224,6 +228,11 @@ public class JavaDocInfoGeneratorTest extends CodeInsightTestCase {
|
||||
doTestLambdaParameter();
|
||||
}
|
||||
|
||||
private void doTestClass() throws Exception {
|
||||
PsiClass psiClass = getTestClass();
|
||||
verifyJavaDoc(psiClass);
|
||||
}
|
||||
|
||||
private void doTestField() throws Exception {
|
||||
PsiClass psiClass = getTestClass();
|
||||
PsiField field = psiClass.getFields() [0];
|
||||
@@ -253,7 +262,7 @@ public class JavaDocInfoGeneratorTest extends CodeInsightTestCase {
|
||||
}
|
||||
|
||||
private void verifyJavaDoc(final PsiElement field, List<String> docUrls) throws IOException {
|
||||
String docInfo = JavaDocInfoGeneratorFactory.create(getProject(), field).generateDocInfo(docUrls);
|
||||
String docInfo = JavaDocumentationProvider.generateExternalJavadoc(field, docUrls);
|
||||
assertNotNull(docInfo);
|
||||
assertEquals(exampleHtmlFileText(getTestName(true)), replaceEnvironmentDependentContent(docInfo));
|
||||
}
|
||||
@@ -262,7 +271,8 @@ public class JavaDocInfoGeneratorTest extends CodeInsightTestCase {
|
||||
final String path = JavaTestUtil.getJavaTestDataPath() + TEST_DATA_FOLDER;
|
||||
final String packageInfo = path + getTestName(true);
|
||||
PsiTestUtil.createTestProjectStructure(myProject, myModule, path, myFilesToDelete);
|
||||
final String info = JavaDocInfoGeneratorFactory.create(getProject(), JavaPsiFacade.getInstance(getProject()).findPackage(getTestName(true))).generateDocInfo(null);
|
||||
PsiPackage psiPackage = JavaPsiFacade.getInstance(getProject()).findPackage(getTestName(true));
|
||||
final String info = JavaDocumentationProvider.generateExternalJavadoc(psiPackage, (List<String>)null);
|
||||
String htmlText = FileUtil.loadFile(new File(packageInfo + File.separator + "packageInfo.html"));
|
||||
assertNotNull(info);
|
||||
assertEquals(StringUtil.convertLineSeparators(htmlText.trim()), replaceEnvironmentDependentContent(info));
|
||||
@@ -307,7 +317,7 @@ public class JavaDocInfoGeneratorTest extends CodeInsightTestCase {
|
||||
private void verifyJavadocFor(String className) throws IOException {
|
||||
PsiClass psiClass = JavaPsiFacade.getInstance(myProject).findClass(className, GlobalSearchScope.allScope(myProject));
|
||||
assertNotNull(psiClass);
|
||||
String doc = JavaDocInfoGeneratorFactory.create(myProject, psiClass).generateDocInfo(null);
|
||||
String doc = JavaDocumentationProvider.generateExternalJavadoc(psiClass, (List<String>)null);
|
||||
assertNotNull(doc);
|
||||
PsiDirectory dir = (PsiDirectory)psiClass.getParent().getParent();
|
||||
PsiFile htmlFile = dir.findFile(psiClass.getName() + ".html");
|
||||
|
||||
+5
-29
@@ -25,17 +25,13 @@ import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.regex.PatternSyntaxException;
|
||||
|
||||
public class PlatformDocumentationUtil {
|
||||
private static final Logger LOG = Logger.getInstance("#com.intellij.codeInsight.documentation.PlatformDocumentationUtil");
|
||||
|
||||
private static final @NonNls Pattern ourLtFixupPattern = Pattern.compile("<([^/^\\w^!])");
|
||||
private static final @NonNls Pattern ourLtFixupPattern = Pattern.compile("<(?=[^/!\\p{Alpha}])");
|
||||
private static final @NonNls Pattern ourToQuote = Pattern.compile("[\\\\\\.\\^\\$\\?\\*\\+\\|\\)\\}\\]\\{\\(\\[]");
|
||||
private static final @NonNls String LT_ENTITY = "<";
|
||||
|
||||
@@ -76,30 +72,10 @@ public class PlatformDocumentationUtil {
|
||||
return x;
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates HTML contents for display in JEditorPane, which treats invalid HTML somewhat differently than popular browsers.
|
||||
*/
|
||||
public static String fixupText(@NotNull CharSequence docText) {
|
||||
Matcher fixupMatcher = ourLtFixupPattern.matcher(docText);
|
||||
LinkedList<String> secondSymbols = new LinkedList<String>();
|
||||
|
||||
while (fixupMatcher.find()) {
|
||||
String s = fixupMatcher.group(1);
|
||||
|
||||
//[db] that's workaround to avoid internal bug
|
||||
if (!s.equals("\\") && !secondSymbols.contains(s)) {
|
||||
secondSymbols.addFirst(s);
|
||||
}
|
||||
}
|
||||
|
||||
for (String s : secondSymbols) {
|
||||
String pattern = "<" + quote(s);
|
||||
|
||||
try {
|
||||
docText = Pattern.compile(pattern).matcher(docText).replaceAll(LT_ENTITY + pattern);
|
||||
}
|
||||
catch (PatternSyntaxException e) {
|
||||
LOG.error("Pattern syntax exception on " + pattern);
|
||||
}
|
||||
}
|
||||
|
||||
return docText.toString();
|
||||
return ourLtFixupPattern.matcher(docText).replaceAll(LT_ENTITY);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user