Repository navigation
Fixing compilation errors after platform localization. Some refactoring #59
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,6 +19,7 @@ | |
| import consulo.annotation.component.ExtensionImpl; | ||
| import consulo.language.psi.PsiElement; | ||
| import consulo.application.util.matcher.NameUtil; | ||
| import consulo.localize.LocalizeValue; | ||
| import consulo.usage.UsageViewNodeTextLocation; | ||
| import consulo.usage.UsageViewShortNameLocation; | ||
| import consulo.usage.UsageViewTypeLocation; | ||
|
|
@@ -35,36 +36,40 @@ | |
|
|
||
| /** | ||
| * @author gregory | ||
| * Date: 2011-07-17 | ||
| * @since 2011-07-17 | ||
| */ | ||
| @ExtensionImpl | ||
| public class BnfDescriptionProvider implements ElementDescriptionProvider { | ||
| @Override | ||
| @RequiredReadAction | ||
| public String getElementDescription(@Nonnull PsiElement psiElement, @Nonnull ElementDescriptionLocation location) { | ||
| public LocalizeValue getElementDescription(@Nonnull PsiElement psiElement, @Nonnull ElementDescriptionLocation location) { | ||
| if (location == UsageViewNodeTextLocation.INSTANCE && psiElement instanceof BnfComposite) { | ||
| return getElementDescription(psiElement, UsageViewTypeLocation.INSTANCE) + " " + | ||
| "'" + getElementDescription(psiElement, UsageViewShortNameLocation.INSTANCE) + "'"; | ||
| return LocalizeValue.of( | ||
| getElementDescription(psiElement, UsageViewTypeLocation.INSTANCE).get() + " " + | ||
| "'" + getElementDescription(psiElement, UsageViewShortNameLocation.INSTANCE).get() + "'" | ||
| ); | ||
| } | ||
| if (psiElement instanceof BnfRule rule) { | ||
| if (location == UsageViewTypeLocation.INSTANCE) { | ||
| return "Grammar Rule"; | ||
| return LocalizeValue.localizeTODO("Grammar Rule"); | ||
| } | ||
| return rule.getName(); | ||
| return LocalizeValue.of(rule.getName()); | ||
| } | ||
| else if (psiElement instanceof BnfAttr attr) { | ||
| if (location == UsageViewTypeLocation.INSTANCE) { | ||
| BnfRule rule = PsiTreeUtil.getParentOfType(psiElement, BnfRule.class); | ||
| return (rule == null ? "Grammar " : "Rule ") + "Attribute"; | ||
| return rule == null ? LocalizeValue.localizeTODO("Grammar Attribute") : LocalizeValue.localizeTODO("Rule Attribute"); | ||
| } | ||
| return attr.getName(); | ||
| return LocalizeValue.of(attr.getName()); | ||
| } | ||
| else if (psiElement instanceof BnfComposite) { | ||
| if (location == UsageViewTypeLocation.INSTANCE) { | ||
| return StringUtil.join(NameUtil.nameToWords(psiElement.getNode().getElementType().toString()), " "); | ||
| return LocalizeValue.of(StringUtil.join(NameUtil.nameToWords(psiElement.getNode().getElementType().toString()), " ")); | ||
| } | ||
| return psiElement instanceof PsiNamedElement namedElement ? namedElement.getName() : psiElement.getClass().getSimpleName(); | ||
| return psiElement instanceof PsiNamedElement namedElement | ||
| ? LocalizeValue.ofNullable(namedElement.getName()) | ||
| : LocalizeValue.of(psiElement.getClass().getSimpleName()); | ||
| } | ||
| return null; | ||
| return LocalizeValue.empty(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This provider is a global |
||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -30,6 +30,7 @@ | |||||
| import consulo.language.icon.IconDescriptorUpdaters; | ||||||
| import consulo.language.psi.PsiElement; | ||||||
| import consulo.language.psi.PsiFile; | ||||||
| import consulo.localize.LocalizeValue; | ||||||
| import consulo.platform.base.icon.PlatformIconGroup; | ||||||
| import consulo.ui.image.Image; | ||||||
| import consulo.util.collection.ContainerUtil; | ||||||
|
|
@@ -86,7 +87,7 @@ public boolean isAlwaysShowsPlus(StructureViewTreeElement element) { | |||||
|
|
||||||
| @Override | ||||||
| public boolean isAlwaysLeaf(StructureViewTreeElement element) { | ||||||
| final Object value = element.getValue(); | ||||||
| Object value = element.getValue(); | ||||||
| return value instanceof BnfRule || value instanceof BnfAttr; | ||||||
| } | ||||||
|
|
||||||
|
|
@@ -102,25 +103,25 @@ protected boolean isSuitable(PsiElement element) { | |||||
| } | ||||||
|
|
||||||
| public static class MyElement extends PsiTreeElementBase<PsiElement> implements SortableTreeElement { | ||||||
|
|
||||||
| public MyElement(PsiElement element) { | ||||||
| super(element); | ||||||
| } | ||||||
|
|
||||||
| @Override | ||||||
| @RequiredReadAction | ||||||
| public String getAlphaSortKey() { | ||||||
| return getPresentableText(); | ||||||
| return getPresentableText().get(); | ||||||
| } | ||||||
|
|
||||||
| @Nonnull | ||||||
| @Override | ||||||
| @RequiredReadAction | ||||||
| public Collection<StructureViewTreeElement> getChildrenBase() { | ||||||
| PsiElement element = getElement(); | ||||||
| if (element instanceof BnfRule || element instanceof BnfAttr) { | ||||||
| return Collections.emptyList(); | ||||||
| } | ||||||
| final ArrayList<StructureViewTreeElement> result = new ArrayList<>(); | ||||||
| List<StructureViewTreeElement> result = new ArrayList<>(); | ||||||
| if (element instanceof BnfFile bnfFile) { | ||||||
| for (BnfAttrs o : bnfFile.getAttributes()) { | ||||||
| result.add(new MyElement(o)); | ||||||
|
|
@@ -139,33 +140,33 @@ else if (element instanceof BnfAttrs bnfAttrs) { | |||||
|
|
||||||
| @Override | ||||||
| @RequiredReadAction | ||||||
| public String getPresentableText() { | ||||||
| public LocalizeValue getPresentableText() { | ||||||
| PsiElement element = getElement(); | ||||||
| if (element instanceof BnfRule rule) { | ||||||
| return rule.getName(); | ||||||
| return LocalizeValue.of(rule.getName()); | ||||||
| } | ||||||
| else if (element instanceof BnfAttr attr) { | ||||||
| return getAttrDisplayName(attr); | ||||||
| return LocalizeValue.of(getAttrDisplayName(attr)); | ||||||
| } | ||||||
| else if (element instanceof BnfAttrs attrs) { | ||||||
| List<BnfAttr> attrList = attrs.getAttrList(); | ||||||
| final BnfAttr firstAttr = ContainerUtil.getFirstItem(attrList); | ||||||
| BnfAttr firstAttr = ContainerUtil.getFirstItem(attrList); | ||||||
| if (firstAttr == null) { | ||||||
| return "Attributes { <empty> }"; | ||||||
| return LocalizeValue.localizeTODO("Attributes { <empty> }"); | ||||||
| } | ||||||
| String suffix = attrList.size() > 1 ? " & " + attrList.size() + " more..." : " "; | ||||||
| return "Attributes { " + getAttrDisplayName(firstAttr) + suffix + "}"; | ||||||
| return LocalizeValue.localizeTODO("Attributes { " + getAttrDisplayName(firstAttr) + suffix + "}"); | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: most of this string is user data (the attribute name and value), and the rest is formatting.
Suggested change
|
||||||
| } | ||||||
| else if (element instanceof BnfFileImpl file) { | ||||||
| return file.getName(); | ||||||
| return LocalizeValue.of(file.getName()); | ||||||
| } | ||||||
| return "" + element; | ||||||
| return LocalizeValue.of(String.valueOf(element)); | ||||||
| } | ||||||
|
|
||||||
| @RequiredReadAction | ||||||
| private static String getAttrDisplayName(BnfAttr attr) { | ||||||
| final BnfAttrPattern attrPattern = attr.getAttrPattern(); | ||||||
| final BnfExpression attrValue = attr.getExpression(); | ||||||
| BnfAttrPattern attrPattern = attr.getAttrPattern(); | ||||||
| BnfExpression attrValue = attr.getExpression(); | ||||||
| String attrValueText = attrValue == null ? "" : attrValue instanceof BnfValueList ? "[ ... ]" : attrValue.getText(); | ||||||
| return attr.getName() + (attrPattern == null ? "" : attrPattern.getText()) + " = " + attrValueText; | ||||||
| } | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -35,6 +35,7 @@ | |
| import consulo.language.psi.PsiErrorElement; | ||
| import consulo.language.psi.PsiFile; | ||
| import consulo.language.psi.PsiWhiteSpace; | ||
| import consulo.localize.LocalizeValue; | ||
| import consulo.ui.ex.ColoredItemPresentation; | ||
| import consulo.ui.image.Image; | ||
| import consulo.util.lang.StringUtil; | ||
|
|
@@ -44,7 +45,8 @@ | |
| import org.intellij.grammar.psi.BnfRule; | ||
|
|
||
| import jakarta.annotation.Nonnull; | ||
| import jakarta.annotation.Nullable; | ||
| import org.jspecify.annotations.Nullable; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the only |
||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.Collection; | ||
| import java.util.Collections; | ||
|
|
@@ -132,42 +134,41 @@ public Collection<StructureViewTreeElement> getChildrenBase() { | |
| @Override | ||
| @RequiredReadAction | ||
| public String getAlphaSortKey() { | ||
| return getPresentableText(); | ||
| return getPresentableText().get(); | ||
| } | ||
|
|
||
| @Nonnull | ||
| @Override | ||
| @RequiredReadAction | ||
| public String getPresentableText() { | ||
| public LocalizeValue getPresentableText() { | ||
| PsiElement element = getElement(); | ||
| ASTNode node = element != null ? element.getNode() : null; | ||
| IElementType elementType = node != null ? node.getElementType() : null; | ||
| if (element instanceof LeafPsiElement) { | ||
| return elementType + ": '" + element.getText() + "'"; | ||
| return LocalizeValue.of(elementType + ": '" + element.getText() + "'"); | ||
| } | ||
| else if (element instanceof PsiErrorElement errorElem) { | ||
| return "PsiErrorElement: '" + errorElem.getErrorDescription() + "'"; | ||
| return LocalizeValue.of("PsiErrorElement: '" + errorElem.getErrorDescription() + "'"); | ||
| } | ||
| else if (elementType instanceof LivePreviewElementType.RuleType ruleType) { | ||
| BnfRule rule = ruleType.getRule(element.getProject()); | ||
| if (rule != null) { | ||
| BnfFile file = (BnfFile)rule.getContainingFile(); | ||
| String className = getRulePsiClassName(rule, getPsiClassFormat(file)); | ||
| return className + ": '" + StringUtil.first(element.getText(), 30, true) + "'"; | ||
| return LocalizeValue.of(className + ": '" + StringUtil.first(element.getText(), 30, true) + "'"); | ||
| } | ||
| } | ||
| return elementType + ""; | ||
| return LocalizeValue.of(String.valueOf(elementType)); | ||
| } | ||
|
|
||
| @Nullable | ||
| @Override | ||
| public String getLocationString() { | ||
| public @Nullable String getLocationString() { | ||
| return null; | ||
| } | ||
|
|
||
| @Nullable | ||
| @Override | ||
| public Image getIcon() { | ||
| @RequiredReadAction | ||
| public @Nullable Image getIcon() { | ||
| PsiElement element = getElement(); | ||
| if (element instanceof PsiErrorElement) { | ||
| return null; //AllIcons.General.Error; | ||
|
|
@@ -183,9 +184,9 @@ else if (element instanceof LeafPsiElement) { | |
| return null; | ||
| } | ||
|
|
||
| @Nullable | ||
| @Override | ||
| public TextAttributesKey getTextAttributesKey() { | ||
| @RequiredReadAction | ||
| public @Nullable TextAttributesKey getTextAttributesKey() { | ||
| return getElement() instanceof PsiErrorElement ? CodeInsightColors.ERRORS_ATTRIBUTES : null; | ||
| } | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The recursive
getElementDescription(...)calls now returnLocalizeValue, so this concatenation goes throughLocalizeValue.toString()without saying so. IftoString()ever gives something other than the resolved text, the usage-view node text breaks without any error. I'd call.get()explicitly so the intent is clear and the result doesn't depend ontoString():