use of com.intellij.psi.impl.source.tree.java.PsiLiteralExpressionImpl in project intellij-community by JetBrains.
the class LiteralExpressionTokenizer method tokenize.
@Override
public void tokenize(@NotNull PsiLiteralExpression element, TokenConsumer consumer) {
PsiLiteralExpressionImpl literalExpression = (PsiLiteralExpressionImpl) element;
// not a string literal
if (literalExpression.getLiteralElementType() != JavaTokenType.STRING_LITERAL)
return;
String text = literalExpression.getInnerText();
if (StringUtil.isEmpty(text) || text.length() <= 2) {
// optimisation to avoid expensive injection check
return;
}
if (InjectedLanguageUtil.hasInjections(literalExpression))
return;
final PsiModifierListOwner listOwner = PsiTreeUtil.getParentOfType(element, PsiModifierListOwner.class);
if (listOwner != null && AnnotationUtil.isAnnotated(listOwner, Collections.singleton(AnnotationUtil.NON_NLS), false, false)) {
return;
}
if (!text.contains("\\")) {
consumer.consumeToken(element, PlainTextSplitter.getInstance());
} else {
processTextWithEscapeSequences(element, text, consumer);
}
}
use of com.intellij.psi.impl.source.tree.java.PsiLiteralExpressionImpl in project intellij-community by JetBrains.
the class StringLiteralManipulator method getValueRange.
@NotNull
public static TextRange getValueRange(@NotNull PsiLiteralExpression element) {
int length = element.getTextLength();
boolean isQuoted;
if (element instanceof PsiLiteralExpressionImpl) {
// avoid calling getValue(): it allocates new string, it returns null for invalid escapes
IElementType type = ((PsiLiteralExpressionImpl) element).getLiteralElementType();
isQuoted = type == JavaTokenType.STRING_LITERAL || type == JavaTokenType.CHARACTER_LITERAL;
} else {
final Object value = element.getValue();
isQuoted = value instanceof String || value instanceof Character;
}
return isQuoted ? new TextRange(1, Math.max(1, length - 1)) : TextRange.from(0, length);
}
Aggregations