test_class.declarator: INPUT_FILE = new File("src/test/resource/resfilter/amdjs/input.js")
test_class.modifier: private static final
test_class.original_string: private static final File INPUT_FILE = new File("src/test/resource/resfilter/amdjs/input.js");
test_class.type: File
test_class.var_name: INPUT_FILE
test_class.declarator: EXPECTED_WRITE_FILE = new File("src/test/resource/resfilter/amdjs/write-output.js")
test_class.modifier: private static final
test_class.original_string: private static final File EXPECTED_WRITE_FILE = new File("src/test/resource/resfilter/amdjs/write-output.js");
test_class.type: File
test_class.var_name: EXPECTED_WRITE_FILE
test_class.declarator: MERGE_INPUT_1_FILE = new File("src/test/resource/resfilter/amdjs/merge-input-1.js")
test_class.modifier: private static final
test_class.original_string: private static final File MERGE_INPUT_1_FILE = new File("src/test/resource/resfilter/amdjs/merge-input-1.js");
test_class.type: File
test_class.var_name: MERGE_INPUT_1_FILE
test_class.declarator: MERGE_INPUT_2_FILE = new File("src/test/resource/resfilter/amdjs/merge-input-2.js")
test_class.modifier: private static final
test_class.original_string: private static final File MERGE_INPUT_2_FILE = new File("src/test/resource/resfilter/amdjs/merge-input-2.js");
test_class.type: File
test_class.var_name: MERGE_INPUT_2_FILE
test_class.declarator: MERGE_INPUT_3_FILE = new File("src/test/resource/resfilter/amdjs/merge-input-3.js")
test_class.modifier: private static final
test_class.original_string: private static final File MERGE_INPUT_3_FILE = new File("src/test/resource/resfilter/amdjs/merge-input-3.js");
test_class.type: File
test_class.var_name: MERGE_INPUT_3_FILE
test_class.declarator: EXPECTED_MERGE_1_FILE = new File("src/test/resource/resfilter/amdjs/merge-output-1.js")
test_class.modifier: private static final
test_class.original_string: private static final File EXPECTED_MERGE_1_FILE = new File("src/test/resource/resfilter/amdjs/merge-output-1.js");
test_class.type: File
test_class.var_name: EXPECTED_MERGE_1_FILE
test_class.declarator: EXPECTED_MERGE_2_FILE = new File("src/test/resource/resfilter/amdjs/merge-output-2.js")
test_class.modifier: private static final
test_class.original_string: private static final File EXPECTED_MERGE_2_FILE = new File("src/test/resource/resfilter/amdjs/merge-output-2.js");
test_class.type: File
test_class.var_name: EXPECTED_MERGE_2_FILE
test_class.declarator: EXPECTED_MERGE_3_FILE = new File("src/test/resource/resfilter/amdjs/merge-output-3.js")
test_class.modifier: private static final
test_class.original_string: private static final File EXPECTED_MERGE_3_FILE = new File("src/test/resource/resfilter/amdjs/merge-output-3.js");
test_class.type: File
test_class.var_name: EXPECTED_MERGE_3_FILE
test_class.declarator: EXPECTED_INPUT_RES_LIST
test_class.modifier: private static final
test_class.original_string: private static final Collection<ResourceString> EXPECTED_INPUT_RES_LIST;
test_class.type: Collection<ResourceString>
test_class.var_name: EXPECTED_INPUT_RES_LIST
test_class.declarator: WRITE_BUNDLE
test_class.modifier: private static
test_class.original_string: private static LanguageBundle WRITE_BUNDLE;
test_class.type: LanguageBundle
test_class.var_name: WRITE_BUNDLE
test_class.declarator: MERGE_BUNDLE
test_class.modifier: private static
test_class.original_string: private static LanguageBundle MERGE_BUNDLE;
test_class.type: LanguageBundle
test_class.var_name: MERGE_BUNDLE
test_class.declarator: res = new AmdJsResource()
test_class.modifier: private static final
test_class.original_string: private static final AmdJsResource res = new AmdJsResource();
test_class.type: AmdJsResource
test_class.var_name: res
test_class.file: gp-res-filter/src/test/java/com/ibm/g11n/pipeline/resfilter/impl/AmdJsResourceTest.java
test_class.identifier: AmdJsResourceTest
test_case.body: @Test
      public void testMerge() throws IOException, ResourceFilterException {
          File tempFile;
  
          tempFile = File.createTempFile(this.getClass().getSimpleName(), ".js");
          tempFile.deleteOnExit();
  
          try (OutputStream os = new FileOutputStream(tempFile);
                  InputStream is = new FileInputStream(MERGE_INPUT_1_FILE)) {
              res.merge(is, os, MERGE_BUNDLE, new FilterOptions(Locale.ENGLISH));
              os.flush();
              assertTrue(ResourceTestUtil.compareFiles(EXPECTED_MERGE_1_FILE, tempFile));
          }
  
          tempFile = File.createTempFile(this.getClass().getSimpleName(), ".js");
          tempFile.deleteOnExit();
  
          try (OutputStream os = new FileOutputStream(tempFile);
                  InputStream is = new FileInputStream(MERGE_INPUT_2_FILE)) {
              res.merge(is, os, MERGE_BUNDLE, new FilterOptions(Locale.ENGLISH));
              os.flush();
              assertTrue(ResourceTestUtil.compareFiles(EXPECTED_MERGE_2_FILE, tempFile));
          }
  
          tempFile = File.createTempFile(this.getClass().getSimpleName(), ".js");
          tempFile.deleteOnExit();
  
          try (OutputStream os = new FileOutputStream(tempFile);
                  InputStream is = new FileInputStream(MERGE_INPUT_3_FILE)) {
              res.merge(is, os, MERGE_BUNDLE, new FilterOptions(Locale.JAPANESE));
              os.flush();
              assertTrue(ResourceTestUtil.compareFiles(EXPECTED_MERGE_3_FILE, tempFile));
          }
      }
test_case.class_method_signature: AmdJsResourceTest.testMerge()
test_case.full_signature: @Test public void testMerge()
test_case.identifier: testMerge
test_case.invocations: createTempFile getSimpleName getClass deleteOnExit merge flush assertTrue compareFiles createTempFile getSimpleName getClass deleteOnExit merge flush assertTrue compareFiles createTempFile getSimpleName getClass deleteOnExit merge flush assertTrue compareFiles
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void testMerge()
focal_class.file: gp-res-filter/src/main/java/com/ibm/g11n/pipeline/resfilter/impl/AmdJsResource.java
focal_class.identifier: AmdJsResource
focal_class.class_method_signature: AmdJsResource.parse(InputStream inStream, FilterOptions options)
focal_class.full_signature: @Override public LanguageBundle parse(InputStream inStream, FilterOptions options)
focal_class.identifier: parse
focal_class.modifiers: @Override public
focal_class.parameters: (InputStream inStream, FilterOptions options)
focal_class.return: LanguageBundle
focal_class.signature: LanguageBundle parse(InputStream inStream, FilterOptions options)
focal_class.class_method_signature: AmdJsResource.write(OutputStream outStream, LanguageBundle languageBundle,
              FilterOptions options)
focal_class.full_signature: @Override public void write(OutputStream outStream, LanguageBundle languageBundle,
              FilterOptions options)
focal_class.identifier: write
focal_class.modifiers: @Override public
focal_class.parameters: (OutputStream outStream, LanguageBundle languageBundle,
              FilterOptions options)
focal_class.return: void
focal_class.signature: void write(OutputStream outStream, LanguageBundle languageBundle,
              FilterOptions options)
focal_class.class_method_signature: AmdJsResource.merge(InputStream baseStream, OutputStream outStream, LanguageBundle languageBundle,
              FilterOptions options)
focal_class.full_signature: @Override public void merge(InputStream baseStream, OutputStream outStream, LanguageBundle languageBundle,
              FilterOptions options)
focal_class.identifier: merge
focal_class.modifiers: @Override public
focal_class.parameters: (InputStream baseStream, OutputStream outStream, LanguageBundle languageBundle,
              FilterOptions options)
focal_class.return: void
focal_class.signature: void merge(InputStream baseStream, OutputStream outStream, LanguageBundle languageBundle,
              FilterOptions options)
focal_class.class_method_signature: AmdJsResource.escapeString(String str, Character quoteChar)
focal_class.full_signature: static String escapeString(String str, Character quoteChar)
focal_class.identifier: escapeString
focal_class.modifiers: static
focal_class.parameters: (String str, Character quoteChar)
focal_class.return: String
focal_class.signature: String escapeString(String str, Character quoteChar)
focal_class.superclass: extends ResourceFilter
focal_method.body: @Override
      public void merge(InputStream baseStream, OutputStream outStream, LanguageBundle languageBundle,
              FilterOptions options) throws IOException, ResourceFilterException {
  
          // Load entire base content to CharSequence
          CharArrayWriter caw = new CharArrayWriter();
          try (InputStreamReader reader = new InputStreamReader(new BomInputStream(baseStream), "UTF-8")) {
              char[] buf = new char[1024];
              int len;
              while ((len = reader.read(buf)) >= 0) {
                  caw.write(buf, 0, len);
              }
          }
  
          char[] baseContent = caw.toCharArray();
          CharArrayReader car = new CharArrayReader(baseContent);
  
          // Parse base JS and extract key-value data
          AstRoot root = new Parser().parse(car,  null , 1);
          KeyValueVisitor visitor = new KeyValueVisitor();
          root.visitAll(visitor);
          LinkedHashMap<String, ValueData> baseKVMap = visitor.elements;
  
          // Merge translated value
          Map<String, String> kvMap = Utils.createKeyValueMap(languageBundle.getResourceStrings());
  
          try (OutputStreamWriter writer = new OutputStreamWriter(new BufferedOutputStream(outStream), StandardCharsets.UTF_8)) {
              int idx = 0;    // current index in baseContent
              for (Entry<String, ValueData> baseEntry : baseKVMap.entrySet()) {
                  String key = baseEntry.getKey();
                  ValueData valData = baseEntry.getValue();
                  int start = valData.getStart();
                  int end = valData.getEnd();
  
                  if (idx < start) {
                      // write out text up to the start of the original key-value expression
                      writer.write(baseContent, idx, start - idx);
                      idx = start;
                  }
  
                  String translatedValue = kvMap.get(key);
                  if (translatedValue == null) {
                      // use original value
                      writer.write(baseContent, idx, end - idx);
                  } else {
                      // use translated value
  
                      // opening quote
                      char quote = baseContent[idx];
                      writer.write(quote);
  
                      // translation value
                      writer.write(escapeString(translatedValue, quote));
  
                      // closing quote
                      assert quote == baseContent[end - 1];
                      writer.write(quote);
                  }
                  idx = end;
              }
              if (idx < baseContent.length) {
                  writer.write(baseContent, idx, baseContent.length - idx);
              }
          }
      }
focal_method.class_method_signature: AmdJsResource.merge(InputStream baseStream, OutputStream outStream, LanguageBundle languageBundle,
              FilterOptions options)
focal_method.full_signature: @Override public void merge(InputStream baseStream, OutputStream outStream, LanguageBundle languageBundle,
              FilterOptions options)
focal_method.identifier: merge
focal_method.invocations: read write toCharArray parse visitAll createKeyValueMap getResourceStrings entrySet getKey getValue getStart getEnd write get write write write escapeString write write
focal_method.modifiers: @Override public
focal_method.parameters: (InputStream baseStream, OutputStream outStream, LanguageBundle languageBundle,
              FilterOptions options)
focal_method.return: void
focal_method.signature: void merge(InputStream baseStream, OutputStream outStream, LanguageBundle languageBundle,
              FilterOptions options)