IDEA-149628 Slow performance when editing large HTML injected in Java: avoid CCE

This commit is contained in:
Gregory.Shrago
2016-06-03 14:43:05 +03:00
parent 14a7965d0c
commit 1285749ae6
@@ -54,10 +54,16 @@ public class StringLiteralManipulator extends AbstractElementManipulator<PsiLite
@NotNull
public static TextRange getValueRange(@NotNull PsiLiteralExpression element) {
int length = element.getTextLength();
IElementType type = ((PsiLiteralExpressionImpl)element).getLiteralElementType();
if (type != JavaTokenType.STRING_LITERAL && type != JavaTokenType.CHARACTER_LITERAL) {
return TextRange.from(0, length);
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;
}
return new TextRange(1, Math.max(1, length - 1));
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);
}
}