@Test public void testFindEndOfSchemaDeclaration() { String normal = "public static final org.apache.avro.Schema SCHEMA$ = whatever(\"{json}\"); fluff"; String huge = "public static final org.apache.avro.Schema SCHEMA$ = whatever(new StringBuilder().append(\"{json}\").append(\"{more json}\").toString());"; Assert.assertEquals(CodeTransformations.findEndOfSchemaDeclaration(normal), normal.length() - 6); Assert.assertEquals(CodeTransformations.findEndOfSchemaDeclaration(huge), huge.length()); }
static int findEndOfSchemaDeclaration(String code) { Matcher schema$Matcher = SCHEMA_DOLLAR_DECL_PATTERN.matcher(code); if (!schema$Matcher.find()) { throw new IllegalStateException("unable to locate SCHEMA$ in " + code); } int schema$Position = schema$Matcher.end(); Matcher schema$EndMatcher = END_OF_SCHEMA_DOLLAR_DECL_PATTERN.matcher(code); if (!schema$EndMatcher.find(schema$Position)) { throw new IllegalStateException("unable to locate SCHEMA$ ending in " + code); } return schema$EndMatcher.end(); }
CodeTransformations { static int findEndOfSchemaDeclaration(String code) { Matcher schema$Matcher = SCHEMA_DOLLAR_DECL_PATTERN.matcher(code); if (!schema$Matcher.find()) { throw new IllegalStateException("unable to locate SCHEMA$ in " + code); } int schema$Position = schema$Matcher.end(); Matcher schema$EndMatcher = END_OF_SCHEMA_DOLLAR_DECL_PATTERN.matcher(code); if (!schema$EndMatcher.find(schema$Position)) { throw new IllegalStateException("unable to locate SCHEMA$ ending in " + code); } return schema$EndMatcher.end(); } }
CodeTransformations { static int findEndOfSchemaDeclaration(String code) { Matcher schema$Matcher = SCHEMA_DOLLAR_DECL_PATTERN.matcher(code); if (!schema$Matcher.find()) { throw new IllegalStateException("unable to locate SCHEMA$ in " + code); } int schema$Position = schema$Matcher.end(); Matcher schema$EndMatcher = END_OF_SCHEMA_DOLLAR_DECL_PATTERN.matcher(code); if (!schema$EndMatcher.find(schema$Position)) { throw new IllegalStateException("unable to locate SCHEMA$ ending in " + code); } return schema$EndMatcher.end(); }  }
CodeTransformations { static int findEndOfSchemaDeclaration(String code) { Matcher schema$Matcher = SCHEMA_DOLLAR_DECL_PATTERN.matcher(code); if (!schema$Matcher.find()) { throw new IllegalStateException("unable to locate SCHEMA$ in " + code); } int schema$Position = schema$Matcher.end(); Matcher schema$EndMatcher = END_OF_SCHEMA_DOLLAR_DECL_PATTERN.matcher(code); if (!schema$EndMatcher.find(schema$Position)) { throw new IllegalStateException("unable to locate SCHEMA$ ending in " + code); } return schema$EndMatcher.end(); }  static String transformFixedClass(String code, AvroVersion minSupportedVersion, AvroVersion maxSupportedVersion); static String transformEnumClass(String code, AvroVersion minSupportedVersion, AvroVersion maxSupportedVersion); static String transformParseCalls(
      String code,
      AvroVersion generatedWith,
      AvroVersion minSupportedVersion,
      AvroVersion maxSupportedVersion
  ); static String addGetClassSchemaMethod(
      String code,
      AvroVersion generatedWith,
      AvroVersion minSupportedVersion,
      AvroVersion maxSupportedVersion
  ); static String removeBuilderSupport(String code, AvroVersion minSupportedVersion, AvroVersion maxSupportedVersion); static String removeBinaryMessageCodecSupport(String code, AvroVersion minSupportedVersion, AvroVersion maxSupportedVersion); static String removeAvroGeneratedAnnotation(String code, AvroVersion minSupportedVersion, AvroVersion maxSupportedVersion); static String transformExternalizableSupport(String code, AvroVersion minSupportedVersion, AvroVersion maxSupportedVersion); static String transformCustomCodersSupport(String code, AvroVersion minSupportedVersion, AvroVersion maxSupportedVersion); }
CodeTransformations { static int findEndOfSchemaDeclaration(String code) { Matcher schema$Matcher = SCHEMA_DOLLAR_DECL_PATTERN.matcher(code); if (!schema$Matcher.find()) { throw new IllegalStateException("unable to locate SCHEMA$ in " + code); } int schema$Position = schema$Matcher.end(); Matcher schema$EndMatcher = END_OF_SCHEMA_DOLLAR_DECL_PATTERN.matcher(code); if (!schema$EndMatcher.find(schema$Position)) { throw new IllegalStateException("unable to locate SCHEMA$ ending in " + code); } return schema$EndMatcher.end(); }  static String transformFixedClass(String code, AvroVersion minSupportedVersion, AvroVersion maxSupportedVersion); static String transformEnumClass(String code, AvroVersion minSupportedVersion, AvroVersion maxSupportedVersion); static String transformParseCalls(
      String code,
      AvroVersion generatedWith,
      AvroVersion minSupportedVersion,
      AvroVersion maxSupportedVersion
  ); static String addGetClassSchemaMethod(
      String code,
      AvroVersion generatedWith,
      AvroVersion minSupportedVersion,
      AvroVersion maxSupportedVersion
  ); static String removeBuilderSupport(String code, AvroVersion minSupportedVersion, AvroVersion maxSupportedVersion); static String removeBinaryMessageCodecSupport(String code, AvroVersion minSupportedVersion, AvroVersion maxSupportedVersion); static String removeAvroGeneratedAnnotation(String code, AvroVersion minSupportedVersion, AvroVersion maxSupportedVersion); static String transformExternalizableSupport(String code, AvroVersion minSupportedVersion, AvroVersion maxSupportedVersion); static String transformCustomCodersSupport(String code, AvroVersion minSupportedVersion, AvroVersion maxSupportedVersion);  }