mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-92848 Html tags not parsed in description
reviewer: anton.makeev
This commit is contained in:
+89
@@ -0,0 +1,89 @@
|
||||
/*
|
||||
* Copyright 2000-2012 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 org.jetbrains.idea.maven.dom;
|
||||
|
||||
import com.intellij.lang.documentation.DocumentationProvider;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.PsiManager;
|
||||
import com.intellij.xml.util.documentation.XmlDocumentationProvider;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Sergey Evdokimov
|
||||
*/
|
||||
public class MavenPomXmlDocumentationProvider implements DocumentationProvider {
|
||||
|
||||
private final DocumentationProvider myDelegate = new XmlDocumentationProvider() {
|
||||
@Override
|
||||
protected String generateDoc(String str, String name, String typeName, String version) {
|
||||
if (str != null) {
|
||||
str = StringUtil.unescapeXml(str);
|
||||
}
|
||||
|
||||
return super.generateDoc(str, name, typeName, version);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
private static boolean isFromPomXml(PsiElement element) {
|
||||
if (element == null) return false;
|
||||
|
||||
PsiFile containingFile = element.getContainingFile();
|
||||
return containingFile != null && containingFile.getName().equals("maven-4.0.0.xsd");
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getQuickNavigateInfo(PsiElement element, PsiElement originalElement) {
|
||||
if (!isFromPomXml(element)) return null;
|
||||
|
||||
return myDelegate.getQuickNavigateInfo(element, originalElement);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public List<String> getUrlFor(PsiElement element, PsiElement originalElement) {
|
||||
if (!isFromPomXml(element)) return null;
|
||||
|
||||
return myDelegate.getUrlFor(element, originalElement);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String generateDoc(PsiElement element, @Nullable PsiElement originalElement) {
|
||||
if (!isFromPomXml(element)) return null;
|
||||
|
||||
return myDelegate.generateDoc(element, originalElement);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public PsiElement getDocumentationElementForLookupItem(PsiManager psiManager, Object object, PsiElement element) {
|
||||
if (!isFromPomXml(element)) return null;
|
||||
|
||||
return myDelegate.getDocumentationElementForLookupItem(psiManager, object, element);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public PsiElement getDocumentationElementForLink(PsiManager psiManager, String link, PsiElement context) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -73,6 +73,8 @@
|
||||
order="first"/>
|
||||
<lang.documentationProvider language="XML" implementationClass="org.jetbrains.idea.maven.dom.MavenPluginModelDocumentationProvider"
|
||||
order="first"/>
|
||||
<lang.documentationProvider language="XML" implementationClass="org.jetbrains.idea.maven.dom.MavenPomXmlDocumentationProvider"/>
|
||||
|
||||
<elementDescriptionProvider implementation="org.jetbrains.idea.maven.dom.MavenModelDocumentationProvider" order="first"/>
|
||||
|
||||
<localInspection language="XML" shortName="MavenModelInspection" bundle="MavenDomBundle" key="inspection.name" groupKey="inspection.group"
|
||||
|
||||
+52
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Copyright 2000-2012 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 org.jetbrains.idea.maven.dom
|
||||
|
||||
import com.intellij.codeInsight.documentation.DocumentationManager
|
||||
import com.intellij.lang.documentation.DocumentationProvider
|
||||
import com.intellij.psi.PsiElement
|
||||
|
||||
/**
|
||||
* @author Sergey Evdokimov
|
||||
*/
|
||||
class MavenPomXmlDocumentationTest extends MavenDomTestCase {
|
||||
|
||||
public void testDocumentation() {
|
||||
createProjectPom("""
|
||||
<groupId>test</groupId>
|
||||
<artifactId>project</artifactId>
|
||||
<version>1</version>
|
||||
<scm>
|
||||
<connection<caret>></connection>
|
||||
</scm>"""
|
||||
);
|
||||
|
||||
def expectedText = """Tag name: <b>connection</b><br>Description : The source control management system URL
|
||||
that describes the repository and how to connect to the
|
||||
repository. For more information, see the
|
||||
<a href="http://maven.apache.org/scm/scm-url-format.html">URL format</a>
|
||||
and <a href="http://maven.apache.org/scm/scms-overview.html">list of supported SCMs</a>.
|
||||
This connection is read-only.<br>Version : 4.0.0"""
|
||||
|
||||
PsiElement originalElement = getElementAtCaret(myProjectPom);
|
||||
PsiElement targetElement = DocumentationManager.getInstance(myProject).findTargetElement(getEditor(), getTestPsiFile(), originalElement);
|
||||
|
||||
DocumentationProvider provider = DocumentationManager.getProviderFromElement(targetElement);
|
||||
|
||||
assert expectedText.replaceAll(" +", " ") == provider.generateDoc(targetElement, originalElement).replaceAll(" +", " ")
|
||||
}
|
||||
|
||||
}
|
||||
@@ -166,7 +166,7 @@ public class HtmlDocumentationProvider implements DocumentationProvider {
|
||||
if (element instanceof XmlEntityDecl) {
|
||||
final XmlEntityDecl entityDecl = (XmlEntityDecl)element;
|
||||
|
||||
return XmlDocumentationProvider.findDocRightAfterElement(element, entityDecl.getName());
|
||||
return new XmlDocumentationProvider().findDocRightAfterElement(element, entityDecl.getName());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -237,7 +237,7 @@ public class XmlDocumentationProvider implements DocumentationProvider {
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
public static String findDocRightAfterElement(final PsiElement parent, final String referenceName) {
|
||||
public String findDocRightAfterElement(final PsiElement parent, final String referenceName) {
|
||||
// Check for comment right after the xml attlist decl
|
||||
PsiElement uncleElement = parent.getNextSibling();
|
||||
if (uncleElement instanceof PsiWhiteSpace && uncleElement.getText().indexOf('\n') == -1) uncleElement = uncleElement.getNextSibling();
|
||||
@@ -267,7 +267,7 @@ public class XmlDocumentationProvider implements DocumentationProvider {
|
||||
return curElement;
|
||||
}
|
||||
|
||||
private static String formatDocFromComment(final PsiElement curElement, final String name) {
|
||||
private String formatDocFromComment(final PsiElement curElement, final String name) {
|
||||
String text = curElement.getText();
|
||||
text = text.substring("<!--".length(),text.length()-"-->".length()).trim();
|
||||
text = escapeDocumentationTextText(text);
|
||||
@@ -317,7 +317,7 @@ public class XmlDocumentationProvider implements DocumentationProvider {
|
||||
return null;
|
||||
}
|
||||
|
||||
private static String generateDoc(String str, String name, String typeName, String version) {
|
||||
protected String generateDoc(String str, String name, String typeName, String version) {
|
||||
if (str == null) return null;
|
||||
StringBuilder buf = new StringBuilder(str.length() + 20);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user