mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
injection in case of string literal with slash before line feed
This commit is contained in:
+4
-8
@@ -15,11 +15,11 @@
|
||||
*/
|
||||
package com.intellij.psi.impl.source.tree.injected;
|
||||
|
||||
import com.intellij.openapi.util.ProperTextRange;
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.psi.LiteralTextEscaper;
|
||||
import com.intellij.psi.PsiLanguageInjectionHost;
|
||||
import com.intellij.psi.impl.source.tree.java.PsiLiteralExpressionImpl;
|
||||
import com.intellij.psi.LiteralTextEscaper;
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.openapi.util.ProperTextRange;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
@@ -37,11 +37,7 @@ public class StringLiteralEscaper<T extends PsiLanguageInjectionHost> extends Li
|
||||
ProperTextRange.assertProperRange(rangeInsideHost);
|
||||
String subText = rangeInsideHost.substring(myHost.getText());
|
||||
outSourceOffsets = new int[subText.length()+1];
|
||||
return PsiLiteralExpressionImpl.parseStringCharacters(subText, outChars, outSourceOffsets, isStrictBackSlash());
|
||||
}
|
||||
|
||||
protected boolean isStrictBackSlash() {
|
||||
return true;
|
||||
return PsiLiteralExpressionImpl.parseStringCharacters(subText, outChars, outSourceOffsets);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+1
-13
@@ -229,16 +229,7 @@ public class PsiLiteralExpressionImpl
|
||||
return success ? outChars.toString() : null;
|
||||
}
|
||||
|
||||
public static boolean parseStringCharacters(@NotNull String chars,
|
||||
@NotNull StringBuilder outChars,
|
||||
@Nullable int[] sourceOffsets) {
|
||||
return parseStringCharacters(chars, outChars, sourceOffsets, true);
|
||||
}
|
||||
|
||||
public static boolean parseStringCharacters(@NotNull String chars,
|
||||
@NotNull StringBuilder outChars,
|
||||
@Nullable int[] sourceOffsets,
|
||||
final boolean strictBackSlash) {
|
||||
public static boolean parseStringCharacters(@NotNull String chars, @NotNull StringBuilder outChars, @Nullable int[] sourceOffsets) {
|
||||
assert sourceOffsets == null || sourceOffsets.length == chars.length()+1;
|
||||
if (chars.indexOf('\\') < 0) {
|
||||
outChars.append(chars);
|
||||
@@ -354,9 +345,6 @@ public class PsiLiteralExpressionImpl
|
||||
break;
|
||||
|
||||
default:
|
||||
if (!strictBackSlash) {
|
||||
break;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
if (sourceOffsets != null) {
|
||||
|
||||
+21
-2
@@ -16,17 +16,36 @@
|
||||
|
||||
package org.jetbrains.plugins.groovy.lang.psi.impl.statements.expressions.literals;
|
||||
|
||||
import com.intellij.openapi.util.ProperTextRange;
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.psi.LiteralTextEscaper;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.impl.source.tree.injected.StringLiteralEscaper;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.plugins.groovy.lang.lexer.GroovyTokenTypes;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.util.GrStringUtil;
|
||||
|
||||
public class GrLiteralEscaper extends StringLiteralEscaper<GrLiteralImpl> {
|
||||
public class GrLiteralEscaper extends LiteralTextEscaper<GrLiteralImpl> {
|
||||
private int[] outSourceOffsets;
|
||||
|
||||
public GrLiteralEscaper(final GrLiteralImpl literal) {
|
||||
super(literal);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean decode(@NotNull TextRange rangeInsideHost, @NotNull StringBuilder outChars) {
|
||||
ProperTextRange.assertProperRange(rangeInsideHost);
|
||||
String subText = rangeInsideHost.substring(myHost.getText());
|
||||
outSourceOffsets = new int[subText.length() + 1];
|
||||
return GrStringUtil.parseStringCharacters(subText, outChars, outSourceOffsets, isStrictBackSlash());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getOffsetInHost(int offsetInDecoded, @NotNull final TextRange rangeInsideHost) {
|
||||
int result = offsetInDecoded < outSourceOffsets.length ? outSourceOffsets[offsetInDecoded] : -1;
|
||||
if (result == -1) return -1;
|
||||
return (result <= rangeInsideHost.getLength() ? result : rangeInsideHost.getLength()) + rangeInsideHost.getStartOffset();
|
||||
}
|
||||
|
||||
protected boolean isStrictBackSlash() {
|
||||
PsiElement child = myHost.getFirstChild();
|
||||
return child == null || child.getNode().getElementType() != GroovyTokenTypes.mREGEX_LITERAL;
|
||||
|
||||
Reference in New Issue
Block a user