コード例 #1
0
 private void replaceAccessor(NLSSubstitution substitution, TextChange change) {
   AccessorClassReference accessorClassRef = substitution.getAccessorClassReference();
   if (accessorClassRef != null) {
     Region region = accessorClassRef.getRegion();
     int len = accessorClassRef.getName().length();
     String[] args = {
       BasicElementLabels.getJavaElementName(accessorClassRef.getName()),
       BasicElementLabels.getJavaElementName(substitution.getUpdatedAccessor())
     };
     TextChangeCompatibility.addTextEdit(
         change,
         Messages.format(NLSMessages.NLSSourceModifier_replace_accessor, args),
         new ReplaceEdit(region.getOffset(), len, substitution.getUpdatedAccessor())); //
   }
 }
コード例 #2
0
  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) {
        }
      }
    }
  }