Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import consulo.annotation.access.RequiredReadAction;
import consulo.language.editor.localize.CodeInsightLocalize;
import consulo.language.psi.PsiElement;
import consulo.localize.LocalizeValue;
import consulo.util.io.URLUtil;
import consulo.util.lang.StringUtil;
import org.jspecify.annotations.Nullable;
Expand Down Expand Up @@ -235,7 +236,7 @@ else if (StringUtil.containsAnyChar(remainingLineContent, JSDocumentationProvide
null,
getSeeAlsoLink(remainingLineContent),
result,
remainingLineContent,
LocalizeValue.of(remainingLineContent),
null
);
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.intellij.javascript.documentation;

import com.intellij.lang.javascript.JSTokenTypes;
Expand Down Expand Up @@ -76,7 +75,7 @@ public class JSDocumentationProvider implements CodeDocumentationProvider, Langu
private DocumentationProvider getCssProvider(Project project) throws Exception {
if (cssProvider == null) {
Class<?> aClass = Class.forName("com.intellij.psi.css.impl.util.CssDocumentationProvider");
cssProvider = (DocumentationProvider)aClass.getConstructor(new Class[]{}).newInstance(new Object[]{});
cssProvider = (DocumentationProvider) aClass.getConstructor(new Class[]{}).newInstance(new Object[]{});
}

return cssProvider;
Expand Down Expand Up @@ -114,18 +113,17 @@ else if (element instanceof JSNamespaceDeclaration namespaceDeclaration) {

@RequiredReadAction
private static String createQuickNavigateForAnnotationDerived(PsiElement element) {
JSAttributeNameValuePair valuePair = (JSAttributeNameValuePair)element;
JSAttribute parent = (JSAttribute)valuePair.getParent();
JSAttributeNameValuePair valuePair = (JSAttributeNameValuePair) element;
JSAttribute parent = (JSAttribute) valuePair.getParent();
StringBuilder builder = new StringBuilder();
JSClass clazz = PsiTreeUtil.getParentOfType(valuePair, JSClass.class);
appendParentInfo(clazz != null ? clazz : parent.getContainingFile(), builder, parent);
builder.append(parent.getName()).append(" ").append(valuePair.getSimpleValue());
return builder.toString();
}

@Nullable
@RequiredReadAction
private static String createQuickNavigateForFunction(JSFunction function) {
private static @Nullable String createQuickNavigateForFunction(JSFunction function) {
PsiElement parent = JSResolveUtil.findParent(function);
StringBuilder result = new StringBuilder();

Expand Down Expand Up @@ -218,9 +216,8 @@ else if (parent instanceof JSFile) {
}
}

@Nullable
@RequiredReadAction
private static String createQuickNavigateForVariable(JSVariable variable) {
private static @Nullable String createQuickNavigateForVariable(JSVariable variable) {
PsiElement parent = JSResolveUtil.findParent(variable);
StringBuilder result = new StringBuilder();

Expand Down Expand Up @@ -254,9 +251,8 @@ private static void appendVarType(JSVariable variable, StringBuilder builder) {
}
}

@Nullable
@RequiredReadAction
private static String createQuickNavigateForClazz(JSClass jsClass) {
private static @Nullable String createQuickNavigateForClazz(JSClass jsClass) {
String qName = jsClass.getQualifiedName();
if (qName == null) {
return null;
Expand Down Expand Up @@ -289,9 +285,8 @@ private static String createQuickNavigateForClazz(JSClass jsClass) {
return result.toString();
}

@Nullable
@RequiredReadAction
private static String createQuickNavigateForNamespace(JSNamespaceDeclaration ns) {
private static @Nullable String createQuickNavigateForNamespace(JSNamespaceDeclaration ns) {
String qName = ns.getQualifiedName();
if (qName == null) {
return null;
Expand Down Expand Up @@ -346,9 +341,8 @@ private static void appendAttrList(JSAttributeListOwner jsClass, StringBuilder r
}
}

@Nullable
@RequiredReadAction
private static String generateReferenceTargetList(@Nullable JSReferenceList implementsList, String packageName) {
private static @Nullable String generateReferenceTargetList(@Nullable JSReferenceList implementsList, String packageName) {
if (implementsList == null) {
return null;
}
Expand Down Expand Up @@ -384,7 +378,7 @@ public List<String> getUrlFor(PsiElement element, PsiElement originalElement) {
Object o = method.invoke(null, new Object[]{possibleCssName});

if (o instanceof String) {
return Collections.singletonList((String)o);
return Collections.singletonList((String) o);
}
}
catch (Exception ignored) {
Expand All @@ -399,13 +393,13 @@ public String generateDoc(PsiElement _element, PsiElement originalElement) {
if (_element instanceof JSReferenceExpression expression) {
StringBuilder buffer = null;

// ambigious reference
// ambiguous reference
for (ResolveResult r : expression.multiResolve(false)) {
if (buffer == null) {
buffer = new StringBuilder();
}
PsiElement element = r.getElement();
ItemPresentation presentation = ((NavigationItem)element).getPresentation();
ItemPresentation presentation = ((NavigationItem) element).getPresentation();

JSDocumentationUtils.appendHyperLinkToElement(
element,
Expand Down Expand Up @@ -437,7 +431,7 @@ public String generateDoc(PsiElement _element, PsiElement originalElement) {
JSDocumentationBuilder builder = new JSDocumentationBuilder(element, originalElement);
JSDocumentationUtils.processDocumentationTextFromComment(docComment.getNode(), builder);

return parameterDoc ? builder.getParameterDoc(((JSParameter)_element).getName()) : builder.getDoc();
return parameterDoc ? builder.getParameterDoc(((JSParameter) _element).getName()) : builder.getDoc();
}

element = findTargetElement(_element, element);
Expand All @@ -462,7 +456,7 @@ public String generateDoc(PsiElement _element, PsiElement originalElement) {
Object o = declaredMethod.invoke(null, possibleCssName, null);

if (o instanceof String) {
return (String)o;
return (String) o;
}
}
catch (Exception ignored) {
Expand Down Expand Up @@ -549,6 +543,7 @@ private static String findPossibleCssName(PsiElement _element) {
}

@Override
@RequiredReadAction
public PsiElement getDocumentationElementForLookupItem(PsiManager psiManager, Object object, PsiElement element) {
PsiElement psiElement = findElementForWhichPreviousCommentWillBeSearched(object);
if (psiElement != null && JSDocumentationUtils.findDocComment(psiElement) != null) {
Expand Down Expand Up @@ -598,7 +593,7 @@ else if (parent instanceof JSAssignmentExpression assignment) {
return psiElement;
}
else if (object instanceof JSProperty || object instanceof JSStatement || object instanceof JSClass) {
return (PsiElement)object;
return (PsiElement) object;
}
else if (object instanceof PsiElement psiElement) {
PsiElement parent = psiElement.getParent();
Expand Down Expand Up @@ -633,14 +628,14 @@ else if (parent instanceof JSSuppressionHolder suppressionHolder) {
return null;
}

@Nullable
@Override
public PsiElement getDocumentationElementForLink(PsiManager psiManager, String link, PsiElement context) {
@RequiredReadAction
public @Nullable PsiElement getDocumentationElementForLink(PsiManager psiManager, String link, PsiElement context) {
return getDocumentationElementForLinkStatic(psiManager, link, context);
}

@Nullable
private static PsiElement getDocumentationElementForLinkStatic(PsiManager psiManager, String link, PsiElement context) {
@RequiredReadAction
private static @Nullable PsiElement getDocumentationElementForLinkStatic(PsiManager psiManager, String link, PsiElement context) {
int delimiterIndex = link.lastIndexOf(':');

String attributeType = null;
Expand All @@ -663,16 +658,16 @@ private static PsiElement getDocumentationElementForLinkStatic(PsiManager psiMan
}
else if (attributeType != null) {
PsiElement clazz = JSResolveUtil.findClassByQName(link, context.getResolveScope(), psiManager.getProject());
if (!(clazz instanceof JSClass)) {
if (!(clazz instanceof JSClass jsClass)) {
return null;
}
return findNamedAttribute((JSClass)clazz, attributeType, attributeName);
return findNamedAttribute(jsClass, attributeType, attributeName);
}
else {
PsiElement clazz = JSResolveUtil.findClassByQName(link, context.getResolveScope(), psiManager.getProject());
if (clazz == null && link.contains(".")) {
String qname = link.substring(0, link.lastIndexOf('.'));
clazz = JSResolveUtil.findClassByQName(qname, context.getResolveScope(), psiManager.getProject());
String qName = link.substring(0, link.lastIndexOf('.'));
clazz = JSResolveUtil.findClassByQName(qName, context.getResolveScope(), psiManager.getProject());
if (clazz instanceof JSClass jsClass) {
String member = link.substring(link.lastIndexOf('.') + 1);

Expand Down Expand Up @@ -713,9 +708,8 @@ else if (attributeType != null) {
}
}

@Nullable
@RequiredReadAction
protected static JSAttributeNameValuePair findNamedAttribute(JSClass clazz, String type, String name) {
protected static @Nullable JSAttributeNameValuePair findNamedAttribute(JSClass clazz, String type, String name) {
SimpleReference<JSAttributeNameValuePair> attribute = new SimpleReference<>();
JSResolveUtil.processMetaAttributesForClass(clazz, new JSResolveUtil.MetaDataProcessor() {
@Override
Expand All @@ -732,7 +726,11 @@ public boolean process(JSAttribute jsAttribute) {
}

@Override
public boolean handleOtherElement(PsiElement el, PsiElement context, @Nullable SimpleReference<PsiElement> continuePassElement) {
public boolean handleOtherElement(
PsiElement el,
PsiElement context,
@Nullable SimpleReference<PsiElement> continuePassElement
) {
return true;
}
});
Expand All @@ -755,22 +753,19 @@ private static PsiElement findMethod(JSClass jsClass, String name) {
return result;
}

@Nullable
@Override
public PsiComment findExistingDocComment(PsiComment contextElement) {
public @Nullable PsiComment findExistingDocComment(PsiComment contextElement) {
return contextElement;
}

@Nullable
@Override
public Pair<PsiElement, PsiComment> parseContext(PsiElement element) {
public @Nullable Pair<PsiElement, PsiComment> parseContext(PsiElement element) {
return null;
}

@Nullable
@Override
@RequiredReadAction
public String generateDocumentationContentStub(PsiComment contextComment) {
public @Nullable String generateDocumentationContentStub(PsiComment contextComment) {
for (PsiElement el = contextComment.getParent(); el != null; el = el.getNextSibling()) {
if (el instanceof JSProperty property) {
if (property.getValue() instanceof JSFunction function) {
Expand Down Expand Up @@ -827,9 +822,8 @@ private static String doGenerateDoc(JSFunction function) {
return builder.toString();
}

@Nullable
@RequiredReadAction
protected static String getSeeAlsoLinkResolved(PsiElement originElement, String link) {
protected static @Nullable String getSeeAlsoLinkResolved(PsiElement originElement, String link) {
JSQualifiedNamedElement qualifiedElement = findParentQualifiedElement(originElement);
if (qualifiedElement == null) {
return null;
Expand All @@ -842,27 +836,28 @@ protected static String getSeeAlsoLinkResolved(PsiElement originElement, String
return null;
}

@RequiredReadAction
private static String getLinkToResolve(JSQualifiedNamedElement origin, String link) {
String originQname = origin.getQualifiedName();
String originQName = origin.getQualifiedName();
if (link.length() == 0) {
return originQname;
return originQName;
}
else if (StringUtil.startsWithChar(link, '#')) {
if (origin instanceof JSClass) {
return originQname + "." + link.substring(1);
return originQName + "." + link.substring(1);
}
else {
String aPackage = StringUtil.getPackageName(originQname);
String aPackage = StringUtil.getPackageName(originQName);
return aPackage + "." + link.substring(1);
}
}
else {
String linkFile = link.contains("#") ? link.substring(0, link.lastIndexOf('#')) : link;
String linkAnchor = link.contains("#") ? link.substring(link.lastIndexOf('#') + 1) : null;

String qname;
String qName;
if (StringUtil.endsWithIgnoreCase(linkFile, HTML_EXTENSION)) {
String prefix = StringUtil.getPackageName(originQname);
String prefix = StringUtil.getPackageName(originQName);
while (linkFile.startsWith("../")) {
linkFile = linkFile.substring("../".length());
prefix = StringUtil.getPackageName(prefix);
Expand All @@ -877,23 +872,22 @@ else if (StringUtil.startsWithChar(link, '#')) {
linkFilename = linkFile.substring(0, linkFile.lastIndexOf("."));
}
if (linkFilename.length() > 0) {
qname = (prefix.length() > 0 ? prefix + "." : prefix) + linkFilename.replaceAll("/", ".");
qName = (prefix.length() > 0 ? prefix + "." : prefix) + linkFilename.replaceAll("/", ".");
}
else {
qname = prefix;
qName = prefix;
}
}
else {
qname = linkFile;
qName = linkFile;
}

return linkAnchor != null ? (qname.length() > 0 ? qname + "." : qname) + linkAnchor : qname;
return linkAnchor != null ? (qName.length() > 0 ? qName + "." : qName) + linkAnchor : qName;
}
}

@Nullable
@RequiredReadAction
protected static JSQualifiedNamedElement findParentQualifiedElement(PsiElement element) {
protected static @Nullable JSQualifiedNamedElement findParentQualifiedElement(PsiElement element) {
if (element instanceof JSClass jsClass) {
return jsClass;
}
Expand All @@ -912,7 +906,7 @@ else if (parent instanceof JSFile) {
attribute = jsAttribute;
}
else if (element instanceof JSAttributeNameValuePair nameValuePair) {
attribute = (JSAttribute)nameValuePair.getParent();
attribute = (JSAttribute) nameValuePair.getParent();
}

if (attribute != null && DOCUMENTED_ATTRIBUTES.containsKey(attribute.getName())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import consulo.language.editor.documentation.DocumentationManagerUtil;
import consulo.language.psi.*;
import consulo.language.psi.util.PsiTreeUtil;
import consulo.localize.LocalizeValue;
import consulo.util.lang.StringUtil;
import consulo.util.lang.ref.SimpleReference;
import org.jspecify.annotations.Nullable;
Expand Down Expand Up @@ -689,7 +690,7 @@ public static void appendHyperLinkToElement(
@Nullable PsiElement element,
String elementName,
StringBuilder buffer,
String presentableName,
LocalizeValue presentableName,
@Nullable String presentableFileName
) {
PsiFile containingFile = element != null ? element.getContainingFile() : null;
Expand All @@ -701,9 +702,8 @@ public static void appendHyperLinkToElement(

DocumentationManagerUtil.createHyperlink(
buffer,
(fileName != null ? fileName + ":" : "") + elementName + (element != null ? ":" + element
.getTextOffset() : ""),
presentableName + (presentableFileName != null ? " in " + presentableFileName : ""),
(fileName != null ? fileName + ":" : "") + elementName + (element != null ? ":" + element.getTextOffset() : ""),
presentableName.get() + (presentableFileName != null ? " in " + presentableFileName : ""),
true
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import consulo.component.util.Iconable;
import consulo.language.icon.IconDescriptorUpdaters;
import consulo.language.psi.PsiFile;
import consulo.localize.LocalizeValue;
import consulo.navigation.ItemPresentation;
import consulo.ui.annotation.RequiredUIAccess;
import consulo.ui.image.Image;
Expand All @@ -42,8 +43,9 @@ public JSItemPresentation(JSNamedElement elementProxy) {
}

@Override
public String getPresentableText() {
return myElement.getName();
@RequiredReadAction
public LocalizeValue getPresentableText() {
return LocalizeValue.ofNullable(myElement.getName());
}

@Nullable
Expand Down
Loading
Loading