Class PatternCompileTransformer

java.lang.Object
org.teavm.classlib.impl.regex.PatternCompileTransformer
All Implemented Interfaces:
org.teavm.model.ClassHolderTransformer

public class PatternCompileTransformer extends Object implements org.teavm.model.ClassHolderTransformer
Replaces calls to Pattern.compile(String) and Pattern.compile(String, int) with constant arguments by code that directly constructs the compiled pattern. The pattern is compiled at build time by running classlib's regex engine in the compiler's JVM, and the resulting object graph is turned into calls to factory methods by TPatternWriter and PatternProgramBuilder.

Also handles class library methods that compile a regular expression passed as argument, like String.split(String) or String.replaceAll(String, String). When regular expression is a constant, such calls are expanded into their implementation that takes pre-compiled pattern. Unlike Pattern.compile, which must return a new instance every time, these methods don't expose pattern instance, so it is created once and cached in a static field.

  • Constructor Details

    • PatternCompileTransformer

      public PatternCompileTransformer()
  • Method Details

    • transformClass

      public void transformClass(org.teavm.model.ClassHolder cls, org.teavm.model.ClassHolderTransformerContext context)
      Specified by:
      transformClass in interface org.teavm.model.ClassHolderTransformer