private void deleteAccessor(NLSSubstitution substitution, TextChange change, ICompilationUnit cu)
      throws CoreException {
    AccessorClassReference accessorClassRef = substitution.getAccessorClassReference();
    if (accessorClassRef != null) {
      Region region = accessorClassRef.getRegion();
      String[] args = {
        substitution.getValueNonEmpty(),
        BasicElementLabels.getJavaElementName(substitution.getKey())
      };
      String label = Messages.format(NLSMessages.NLSSourceModifier_remove_accessor, args);
      String replaceString = '\"' + unwindEscapeChars(substitution.getValueNonEmpty()) + '\"';
      TextChangeCompatibility.addTextEdit(
          change, label, new ReplaceEdit(region.getOffset(), region.getLength(), replaceString));
      if (fIsEclipseNLS && substitution.getState() != NLSSubstitution.INTERNALIZED) {

        Region position = substitution.getNLSElement().getPosition();
        int lineStart = getLineStart(cu.getBuffer(), position.getOffset());
        int lineEnd = getLineEnd(cu.getBuffer(), position.getOffset());
        String cuLine = cu.getBuffer().getText(lineStart, lineEnd - lineStart);
        StringBuffer buf = new StringBuffer(cuLine);
        buf.replace(
            region.getOffset() - lineStart,
            region.getOffset() + region.getLength() - lineStart,
            replaceString);
        try {
          NLSLine[] allLines = NLSScanner.scan(buf.toString());

          NLSLine nlsLine = allLines[0];
          NLSElement element =
              findElement(
                  nlsLine,
                  position.getOffset() - lineStart - accessorClassRef.getName().length() - 1);
          if (element == null || element.hasTag()) return;

          NLSElement[] elements = nlsLine.getElements();
          int indexInElementList = Arrays.asList(elements).indexOf(element);
          String editText =
              ' ' + NLSElement.createTagText(indexInElementList + 1); // tags are 1-based
          TextChangeCompatibility.addTextEdit(change, label, new InsertEdit(lineEnd, editText));

        } catch (InvalidInputException e) {
        } catch (BadLocationException e) {
        }
      }
    }
  }
  private void addAccessor(NLSSubstitution sub, TextChange change, String accessorName) {
    if (sub.getState() == NLSSubstitution.EXTERNALIZED) {
      NLSElement element = sub.getNLSElement();
      Region position = element.getPosition();
      String[] args = {sub.getValueNonEmpty(), BasicElementLabels.getJavaElementName(sub.getKey())};
      String text = Messages.format(NLSMessages.NLSSourceModifier_externalize, args);

      String resourceGetter = createResourceGetter(sub.getKey(), accessorName);

      TextEdit edit = new ReplaceEdit(position.getOffset(), position.getLength(), resourceGetter);
      if (fIsEclipseNLS && element.getTagPosition() != null) {
        MultiTextEdit multiEdit = new MultiTextEdit();
        multiEdit.addChild(edit);
        Region tagPosition = element.getTagPosition();
        multiEdit.addChild(new DeleteEdit(tagPosition.getOffset(), tagPosition.getLength()));
        edit = multiEdit;
      }
      TextChangeCompatibility.addTextEdit(change, text, edit);
    }
  }
 private TextEdit createAddTagChange(NLSElement element) {
   int offset = element.getTagPosition().getOffset(); // to be changed
   String text = ' ' + element.getTagText();
   return new InsertEdit(offset, text);
 }
 private static boolean isPositionInElement(NLSElement element, int position) {
   Region elementPosition = element.getPosition();
   return (elementPosition.getOffset() <= position
       && position <= elementPosition.getOffset() + elementPosition.getLength());
 }