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 @@ -22,6 +22,7 @@
import consulo.language.psi.ElementDescriptionProvider;
import consulo.language.psi.PsiElement;
import consulo.language.psi.PsiNamedElement;
import consulo.localize.LocalizeValue;
import consulo.usage.UsageViewLongNameLocation;

/**
Expand All @@ -31,8 +32,11 @@
public class PyElementDescriptionProvider implements ElementDescriptionProvider {
@Override
@RequiredReadAction
public String getElementDescription(PsiElement element, ElementDescriptionLocation location) {
return location instanceof UsageViewLongNameLocation && element instanceof PsiNamedElement namedElem && namedElem instanceof PyElement
? namedElem.getName() : null;
public LocalizeValue getElementDescription(PsiElement element, ElementDescriptionLocation location) {
return location instanceof UsageViewLongNameLocation
&& element instanceof PsiNamedElement namedElem
&& namedElem instanceof PyElement
? LocalizeValue.ofNullable(namedElem.getName())
: LocalizeValue.empty();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,19 +57,20 @@
import consulo.language.psi.util.PsiTreeUtil;
import consulo.language.psi.util.QualifiedName;
import consulo.language.util.IncorrectOperationException;
import consulo.localize.LocalizeValue;
import consulo.navigation.ItemPresentation;
import consulo.util.collection.ArrayFactory;
import consulo.util.collection.ContainerUtil;
import consulo.util.collection.SmartList;
import consulo.util.lang.Comparing;
import consulo.util.lang.StringUtil;
import consulo.util.lang.ref.SimpleReference;
import org.jspecify.annotations.Nullable;

import java.util.*;
import java.util.function.Function;
import java.util.function.Predicate;

import static consulo.util.lang.StringUtil.join;
import static consulo.util.lang.StringUtil.notNullize;

/**
Expand Down Expand Up @@ -370,22 +371,26 @@ public PyClass[] getSuperClasses(@Nullable TypeEvalContext context) {
@Override
public ItemPresentation getPresentation() {
return new PyElementPresentation(this) {
@Nullable
@Override
@RequiredReadAction
public String getPresentableText() {
public LocalizeValue getPresentableText() {
PyPsiUtils.assertValid(PyClassImpl.this);
StringBuilder result = new StringBuilder(notNullize(getName(), PyNames.UNNAMED_ELEMENT));
StringBuilder result = new StringBuilder(notNullize(getName(), PyNames.UNNAMED_ELEMENT.get()));
PyExpression[] superClassExpressions = getSuperClassExpressions();
if (superClassExpressions.length > 0) {
result.append("(");
result.append(join(Arrays.asList(superClassExpressions), expr -> {
String name = expr.getText();
return notNullize(name, PyNames.UNNAMED_ELEMENT);
}, ", "));
StringUtil.join(
superClassExpressions,
expr -> {
String name = expr.getText();
return notNullize(name, PyNames.UNNAMED_ELEMENT.get());
},
", ",
result
);
result.append(")");
}
return result.toString();
return LocalizeValue.of(result.toString());
}
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
*/
package com.jetbrains.python.impl.psi.impl;

import consulo.annotation.access.RequiredReadAction;
import consulo.localize.LocalizeValue;
import org.jspecify.annotations.Nullable;

import consulo.ui.ex.ColoredItemPresentation;
Expand All @@ -30,56 +32,43 @@
/**
* @author vlan
*/
public class PyElementPresentation implements ColoredItemPresentation
{
private final PyElement myElement;
public class PyElementPresentation implements ColoredItemPresentation {
private final PyElement myElement;

public PyElementPresentation(PyElement element)
{
myElement = element;
}
public PyElementPresentation(PyElement element) {
myElement = element;
}

@Nullable
@Override
public TextAttributesKey getTextAttributesKey()
{
return null;
}
@Override
public @Nullable TextAttributesKey getTextAttributesKey() {
return null;
}

@Nullable
@Override
public String getPresentableText()
{
String name = myElement.getName();
return name != null ? name : PyNames.UNNAMED_ELEMENT;
}
@Override
public LocalizeValue getPresentableText() {
return LocalizeValue.ofNullable(myElement.getName()).orIfEmpty(PyNames.UNNAMED_ELEMENT);
}

@Nullable
@Override
public String getLocationString()
{
return "(" + getPackageForFile(myElement.getContainingFile()) + ")";
}
@Override
public @Nullable String getLocationString() {
return "(" + getPackageForFile(myElement.getContainingFile()) + ")";
}

@Nullable
@Override
public Image getIcon()
{
return IconDescriptorUpdaters.getIcon(myElement, 0);
}
@Override
@RequiredReadAction
public @Nullable Image getIcon() {
return IconDescriptorUpdaters.getIcon(myElement, 0);
}

public static String getPackageForFile(PsiFile containingFile)
{
VirtualFile vFile = containingFile.getVirtualFile();
public static String getPackageForFile(PsiFile containingFile) {
VirtualFile vFile = containingFile.getVirtualFile();

if(vFile != null)
{
String importableName = QualifiedNameFinder.findShortestImportableName(containingFile, vFile);
if(importableName != null)
{
return importableName;
}
}
return "";
}
if (vFile != null) {
String importableName = QualifiedNameFinder.findShortestImportableName(containingFile, vFile);
if (importableName != null) {
return importableName;
}
}
return "";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
import consulo.language.psi.util.PsiTreeUtil;
import consulo.language.psi.util.QualifiedName;
import consulo.language.util.IncorrectOperationException;
import consulo.localize.LocalizeValue;
import consulo.module.content.ProjectFileIndex;
import consulo.navigation.ItemPresentation;
import consulo.platform.base.icon.PlatformIconGroup;
Expand Down Expand Up @@ -773,8 +774,8 @@ public ItemPresentation getPresentation() {
return new ItemPresentation() {
@Override
@RequiredReadAction
public String getPresentableText() {
return getModuleName(PyFileImpl.this);
public LocalizeValue getPresentableText() {
return LocalizeValue.of(getModuleName(PyFileImpl.this));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
import consulo.language.psi.util.LanguageCachedValueUtil;
import consulo.language.psi.util.PsiTreeUtil;
import consulo.language.util.IncorrectOperationException;
import consulo.localize.LocalizeValue;
import consulo.navigation.ItemPresentation;
import consulo.platform.base.icon.PlatformIconGroup;
import consulo.python.impl.icon.PythonImplIconGroup;
Expand Down Expand Up @@ -288,11 +289,13 @@ private PyType analyzeCallType(
@Override
public ItemPresentation getPresentation() {
return new PyElementPresentation(this) {
@Nullable
@Override
@RequiredReadAction
public String getPresentableText() {
return notNullize(getName(), PyNames.UNNAMED_ELEMENT) + getParameterList().getPresentableText(true);
public LocalizeValue getPresentableText() {
return LocalizeValue.join(
LocalizeValue.ofNullable(getName()).orIfEmpty(PyNames.UNNAMED_ELEMENT),
getParameterList().getPresentableText(true)
);
}

@Nullable
Expand Down
Loading
Loading