mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-67494 Freemarker/Velocity: make StringLiterals injectable
This commit is contained in:
+3
-2
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
package com.intellij.psi.impl.source.tree.injected;
|
||||
|
||||
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;
|
||||
@@ -24,10 +25,10 @@ import org.jetbrains.annotations.NotNull;
|
||||
/**
|
||||
* @author cdr
|
||||
*/
|
||||
public class StringLiteralEscaper extends LiteralTextEscaper<PsiLiteralExpressionImpl> {
|
||||
public class StringLiteralEscaper<T extends PsiLanguageInjectionHost> extends LiteralTextEscaper<T> {
|
||||
private int[] outSourceOffsets;
|
||||
|
||||
public StringLiteralEscaper(PsiLiteralExpressionImpl host) {
|
||||
public StringLiteralEscaper(T host) {
|
||||
super(host);
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -547,7 +547,7 @@ public class PsiLiteralExpressionImpl
|
||||
|
||||
@NotNull
|
||||
public LiteralTextEscaper<PsiLiteralExpressionImpl> createLiteralTextEscaper() {
|
||||
return new StringLiteralEscaper(this);
|
||||
return new StringLiteralEscaper<PsiLiteralExpressionImpl>(this);
|
||||
}
|
||||
|
||||
public void processInjectedPsi(@NotNull InjectedPsiVisitor visitor) {
|
||||
|
||||
+2
-20
@@ -16,32 +16,14 @@
|
||||
|
||||
package org.jetbrains.plugins.groovy.lang.psi.impl.statements.expressions.literals;
|
||||
|
||||
import com.intellij.psi.LiteralTextEscaper;
|
||||
import com.intellij.psi.impl.source.tree.java.PsiLiteralExpressionImpl;
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.openapi.util.ProperTextRange;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import com.intellij.psi.impl.source.tree.injected.StringLiteralEscaper;
|
||||
|
||||
public class GrLiteralEscaper extends LiteralTextEscaper<GrLiteralImpl> {
|
||||
private int[] outSourceOffsets;
|
||||
public class GrLiteralEscaper extends StringLiteralEscaper<GrLiteralImpl> {
|
||||
|
||||
public GrLiteralEscaper(final GrLiteralImpl literal) {
|
||||
super(literal);
|
||||
}
|
||||
|
||||
public boolean decode(@NotNull final TextRange rangeInsideHost, @NotNull StringBuilder outChars) {
|
||||
ProperTextRange.assertProperRange(rangeInsideHost);
|
||||
String subText = rangeInsideHost.substring(myHost.getText());
|
||||
outSourceOffsets = new int[subText.length() + 1];
|
||||
return PsiLiteralExpressionImpl.parseStringCharacters(subText, outChars, outSourceOffsets);
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
public boolean isOneLine() {
|
||||
final Object value = myHost.getValue();
|
||||
return value instanceof String && ((String)value).indexOf('\n') < 0;
|
||||
|
||||
Reference in New Issue
Block a user