Skip to content

Commit

Permalink
Avoid exception from StringLiteral.getLiteralValue()
Browse files Browse the repository at this point in the history
  • Loading branch information
BoykoAlex committed Nov 27, 2024
1 parent ec2cae8 commit 93d8989
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 2 deletions.
5 changes: 5 additions & 0 deletions headless-services/commons/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,11 @@
<artifactId>org.eclipse.jgit</artifactId>
<version>${jgit-version}</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-text</artifactId>
<version>1.12.0</version>
</dependency>
</dependencies>
</dependencyManagement>

Expand Down
5 changes: 5 additions & 0 deletions headless-services/spring-boot-language-server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,11 @@
<artifactId>json</artifactId>
<version>20231013</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-text</artifactId>
</dependency>


<dependency>
<groupId>org.eclipse.lemminx</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import java.util.ArrayList;
import java.util.List;

import org.apache.commons.text.StringEscapeUtils;
import org.eclipse.jdt.core.dom.StringLiteral;
import org.springframework.ide.vscode.commons.util.text.IRegion;
import org.springframework.ide.vscode.commons.util.text.Region;
Expand All @@ -31,8 +32,12 @@ public class StringLiteralLanguageSnippet implements EmbeddedLanguageSnippet {
*/
private transient List<Region> specialRegions;

private static String getLiteralValueStr(String escaped) {
return StringEscapeUtils.unescapeJava(escaped.substring(1, escaped.length() - 1));
}

public StringLiteralLanguageSnippet(StringLiteral literal) {
this(literal.getEscapedValue(), literal.getLiteralValue(), literal.getStartPosition());
this(literal.getEscapedValue(), getLiteralValueStr(literal.getEscapedValue()), literal.getStartPosition());
}

public StringLiteralLanguageSnippet(String escapedValue, String literalValue, int literalOffset) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import java.util.ArrayList;
import java.util.List;

import org.apache.commons.text.StringEscapeUtils;
import org.eclipse.jdt.core.dom.TextBlock;
import org.springframework.ide.vscode.commons.util.text.IRegion;
import org.springframework.ide.vscode.commons.util.text.Region;
Expand All @@ -26,8 +27,12 @@ public class TextBlockLanguageSnippet implements EmbeddedLanguageSnippet {
private transient int startOffset;
private transient List<Region> specialRegions;

private static String getLiteralValueStr(String escaped) {
return StringEscapeUtils.unescapeJava(escaped.substring(3, escaped.length() - 3));
}

public TextBlockLanguageSnippet(TextBlock block) {
this(block.getEscapedValue(), block.getLiteralValue(), block.getStartPosition());
this(block.getEscapedValue(), getLiteralValueStr(block.getEscapedValue()), block.getStartPosition());
}

public TextBlockLanguageSnippet(String escapedValue, String literalValue, int literalOffset) {
Expand Down

0 comments on commit 93d8989

Please sign in to comment.