I have added Manifold.systems Java library to our Maven Java project pom.xml:
<dependency> <groupId>systems.manifold</groupId> <artifactId>manifold-ext</artifactId> <version>${manifold-version}</version> </dependency>
After this the compilation of the following line:
String foo = "$HIS";
fails compilation:
[ERROR] COMPILATION ERROR : [INFO] ------------------------------------------------------------- [ERROR] /c:/workspaces/dev/src/main/java/com/foo/bar/MyClass.java:[26,24] cannot find symbol symbol: variable HIS location: class com.foo.bar.MyClass [INFO] 1 error
Obviously, this is Manifold String templates trying to find a variable named $HIS, which is not defined in scope. So, I need to escape the $ sign, because I need it to be part of the String literal. How can I do it? If I use $ then IntelliJ screams “Illegal escape character in string literal”.
Advertisement
Answer
The most elegant way I found was to use annotation @DisableStringLiteralTemplates from the same Manifold library:
import manifold.rt.api.DisableStringLiteralTemplates; public class FooExample { @DisableStringLiteralTemplates public void sampleMethod() { String foo = "$HIS"; System.out.println("Foo is " + foo); } }
Escaping the dollar with $ also works, just the IntelliJ Manifold.systems plugin is required for the IDE to recognize all functions of the Manifold Java library.
A detailed description of Manifold String templates can be found here: https://github.com/manifold-systems/manifold/tree/master/manifold-deps-parent/manifold-strings