cleanup TokenWrapper: deprecate getValue in favor of getText and nullability

GitOrigin-RevId: c9536c46aa96b682807ff7bf330d9dd647cb6887
This commit is contained in:
Max Medvedev
2024-12-19 21:11:53 +00:00
committed by intellij-monorepo-bot
parent e010925d13
commit 6eb2a8efd7
6 changed files with 25 additions and 12 deletions
@@ -57,7 +57,7 @@ public final class ManifestTokenType extends IElementType implements ILeafElemen
@NotNull
@Override
public ASTNode createLeafNode(CharSequence text) {
public ASTNode createLeafNode(@NotNull CharSequence text) {
return new ManifestTokenImpl(this, text);
}
}
@@ -635,6 +635,7 @@ c:com.intellij.lang.TokenWrapper
- com.intellij.psi.tree.IElementType
- <init>(com.intellij.psi.tree.IElementType,java.lang.CharSequence):V
- getDelegate():com.intellij.psi.tree.IElementType
- getText():java.lang.String
- getValue():java.lang.String
f:com.intellij.lang.WhitespacesBinders
- sf:DEFAULT_LEFT_BINDER:com.intellij.lang.WhitespacesAndCommentsBinder
@@ -16,7 +16,7 @@ public class ForeignLeafType extends TokenWrapper implements ILeafElementType {
}
@Override
public @NotNull ASTNode createLeafNode(CharSequence leafText) {
return new ForeignLeafPsiElement(this, getValue());
public @NotNull ASTNode createLeafNode(@NotNull CharSequence leafText) {
return new ForeignLeafPsiElement(this, getText());
}
}
@@ -8,22 +8,34 @@ package com.intellij.lang;
import com.intellij.psi.tree.IElementType;
import org.jetbrains.annotations.NotNull;
/**
* Allows replacing text in a given node.
* Useful for string-preprocessor-like macro support
*/
public class TokenWrapper extends IElementType {
private final IElementType myDelegate;
private final @NotNull String myValue;
private final @NotNull String myText;
public TokenWrapper(@NotNull IElementType delegate, @NotNull CharSequence value) {
public TokenWrapper(@NotNull IElementType delegate, @NotNull CharSequence text) {
super("Wrapper", delegate.getLanguage(), false);
myDelegate = delegate;
myValue = value.toString();
myText = text.toString();
}
public @NotNull IElementType getDelegate() {
return myDelegate;
}
/**
* @deprecated Use {@link #getText()} instead as it's name is more descriptive.
*/
@Deprecated
public @NotNull String getValue() {
return myValue;
return getText();
}
public @NotNull String getText() {
return myText;
}
@Override
@@ -499,7 +499,7 @@ public class PsiBuilderImpl extends UnprotectedUserDataHolder implements PsiBuil
public final @NotNull CharSequence getText() {
if (getTokenType() instanceof TokenWrapper) {
return ((TokenWrapper)getTokenType()).getValue();
return ((TokenWrapper)getTokenType()).getText();
}
return getBuilder().myText.subSequence(getStartOffsetInBuilder(), getEndOffsetInBuilder());
@@ -841,7 +841,7 @@ public class PsiBuilderImpl extends UnprotectedUserDataHolder implements PsiBuil
if (eof()) return null;
IElementType type = getTokenType();
if (type instanceof TokenWrapper) {
return ((TokenWrapper)type).getValue();
return ((TokenWrapper)type).getText();
}
return myText.subSequence(myLexStarts[myCurrentLexeme], myLexStarts[myCurrentLexeme + 1]).toString();
}
@@ -1415,7 +1415,7 @@ public class PsiBuilderImpl extends UnprotectedUserDataHolder implements PsiBuil
Token token = (Token)newNode;
if (oldNode instanceof ForeignLeafPsiElement) {
return type instanceof ForeignLeafType && ((ForeignLeafType)type).getValue().equals(oldNode.getText())
return type instanceof ForeignLeafType && ((ForeignLeafType)type).getText().equals(oldNode.getText())
? ThreeState.YES
: ThreeState.NO;
}
@@ -1499,7 +1499,7 @@ public class PsiBuilderImpl extends UnprotectedUserDataHolder implements PsiBuil
if (isForeign1 != isForeign2) return false;
if (isForeign1) {
return n1.getText().equals(((ForeignLeafType)n2.getTokenType()).getValue());
return n1.getText().equals(((ForeignLeafType)n2.getTokenType()).getText());
}
return ((LeafElement)n1).textMatches(((Token)n2).getText());
@@ -176,7 +176,7 @@ public abstract class LexerTestCase extends UsefulTestCase {
@NotNull
private static String getTokenText(IElementType tokenType, CharSequence sequence, int start, int end) {
return tokenType instanceof TokenWrapper
? ((TokenWrapper)tokenType).getValue()
? ((TokenWrapper)tokenType).getText()
: StringUtil.replace(sequence.subSequence(start, end).toString(), "\n", "\\n");
}