private void deleteTag(NLSSubstitution substitution, TextChange change) { Region textRegion = substitution.getNLSElement().getTagPosition(); TextChangeCompatibility.addTextEdit( change, NLSMessages.NLSSourceModifier_remove_tag, new DeleteEdit(textRegion.getOffset(), textRegion.getLength())); }
private void replaceValue(NLSSubstitution substitution, TextChange change) { Region region = substitution.getNLSElement().getPosition(); String[] args = {substitution.getInitialValue(), substitution.getValueNonEmpty()}; TextChangeCompatibility.addTextEdit( change, Messages.format(NLSMessages.NLSSourceModifier_replace_value, args), new ReplaceEdit( region.getOffset(), region.getLength(), '\"' + unwindEscapeChars(substitution.getValueNonEmpty()) + '\"')); // }
private void addNLS(NLSSubstitution sub, TextChange change, String accessorName) { if (sub.getState() == NLSSubstitution.INTERNALIZED) return; NLSElement element = sub.getNLSElement(); addAccessor(sub, change, accessorName); if (!fIsEclipseNLS || sub.getState() == NLSSubstitution.IGNORED) { // Add $NON-NLS-n tag String arg = sub.getState() == NLSSubstitution.EXTERNALIZED ? sub.getKey() : sub.getValueNonEmpty(); String name = Messages.format(NLSMessages.NLSSourceModifier_add_tag, arg); TextChangeCompatibility.addTextEdit(change, name, createAddTagChange(element)); } }
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 replaceKey(NLSSubstitution substitution, TextChange change) { Region region = substitution.getNLSElement().getPosition(); String[] args = { substitution.getInitialKey(), BasicElementLabels.getJavaElementName(substitution.getKey()) }; ReplaceEdit replaceEdit; if (fIsEclipseNLS) replaceEdit = new ReplaceEdit(region.getOffset(), region.getLength(), substitution.getKey()); else replaceEdit = new ReplaceEdit( region.getOffset(), region.getLength(), '\"' + unwindEscapeChars(substitution.getKey()) + '\"'); // TextChangeCompatibility.addTextEdit( change, Messages.format(NLSMessages.NLSSourceModifier_replace_key, args), replaceEdit); }
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); } }