/** * Returns the accessor binding info or <code>null</code> if this element is not a nls'ed entry * * @param astRoot the ast root * @param nlsElement the nls element * @return the accessor class reference or <code>null</code> if this element is not a nls'ed entry */ public static AccessorClassReference getAccessorClassReference(CompilationUnit astRoot, NLSElement nlsElement) { IRegion region= nlsElement.getPosition(); return getAccessorClassReference(astRoot, region); }
private TextEdit createAddTagChange(NLSElement element) { int offset= element.getTagPosition().getOffset(); //to be changed String text= ' ' + element.getTagText(); return new InsertEdit(offset, text); }
private static NLSElement findPreviousTagged(int startIndex, NLSElement[] elements){ int i= startIndex - 1; while (i >= 0){ if (elements[i].hasTag()) return elements[i]; i--; } return null; }
private NLSSubstitution[] createSubstitutions(NLSLine[] lines, Properties props, CompilationUnit astRoot) { List<NLSSubstitution> result= new ArrayList<>(); for (int i= 0; i < lines.length; i++) { NLSElement[] elements= lines[i].getElements(); for (int j= 0; j < elements.length; j++) { NLSElement nlsElement= elements[j]; if (nlsElement.hasTag()) { AccessorClassReference accessorClassReference= NLSHintHelper.getAccessorClassReference(astRoot, nlsElement); if (accessorClassReference == null) { // no accessor class => not translated result.add(new NLSSubstitution(NLSSubstitution.IGNORED, stripQuotes(nlsElement.getValue()), nlsElement)); } else { String key= stripQuotes(nlsElement.getValue()); String value= props.getProperty(key); result.add(new NLSSubstitution(NLSSubstitution.EXTERNALIZED, key, value, nlsElement, accessorClassReference)); } } else if (nlsElement.isEclipseNLS()) { String key= nlsElement.getValue(); result.add(new NLSSubstitution(NLSSubstitution.EXTERNALIZED, key, props.getProperty(key), nlsElement, nlsElement.getAccessorClassReference())); } else { result.add(new NLSSubstitution(NLSSubstitution.INTERNALIZED, stripQuotes(nlsElement.getValue()), nlsElement)); } } } return result.toArray(new NLSSubstitution[result.size()]); }
for (int j= 0; j < elements.length; j++) { NLSElement element= elements[j]; if (!element.hasTag()) { for (int k= 0; k < positions.length; k++) { if (isPositionInElement(element, positions[k])) { if (j==0) { if (elements.length > j+1) { editOffset= elements[j+1].getTagPosition().getOffset(); } else { editOffset= findLineEnd(cu, element.getPosition().getOffset()); Region previousPosition= elements[j-1].getTagPosition(); editOffset= previousPosition.getOffset() + previousPosition.getLength(); String editText= ' ' + NLSElement.createTagText(j + 1); //tags are 1-based result.add(new InsertEdit(editOffset, editText));
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()); if (element == null || element.hasTag()) return; String editText= ' ' + NLSElement.createTagText(indexInElementList + 1); //tags are 1-based TextChangeCompatibility.addTextEdit(change, label, new InsertEdit(lineEnd, editText));
NLSElement element= new NLSElement(node.getName().getIdentifier(), name.getStartPosition(), name.getLength(), nlsLine.size() - 1, true); nlsLine.add(element); element.setAccessorClassReference(new AccessorClassReference(type, bundleName, new Region(node.getStartPosition(), node.getLength()))); firstAccessor[0]= element.getAccessorClassReference();
private static int computeInsertOffset(NLSElement[] elements, int index, ICompilationUnit cu) throws CoreException { NLSElement previousTagged= findPreviousTagged(index, elements); if (previousTagged != null) return previousTagged.getTagPosition().getOffset() + previousTagged.getTagPosition().getLength(); NLSElement nextTagged= findNextTagged(index, elements); if (nextTagged != null) return nextTagged.getTagPosition().getOffset(); return findLineEnd(cu, elements[index].getPosition().getOffset()); }
private static void setTagPositions(IDocument document, NLSLine line) throws BadLocationException { IRegion info= document.getLineInformation(line.getLineNumber()); int defaultValue= info.getOffset() + info.getLength(); NLSElement[] elements= line.getElements(); for (int i= 0; i < elements.length; i++) { NLSElement element= elements[i]; if (!element.hasTag()) { element.setTagPosition(computeInsertOffset(elements, i, defaultValue), 0); } } }
/** * Creates and returns an NLS tag edit for a string that is at the specified position in * a compilation unit. Returns <code>null</code> if the string is already NLSed * or the edit could not be created for some other reason. * @throws CoreException */ public static TextEdit createNLSEdit(ICompilationUnit cu, int position) throws CoreException { NLSLine nlsLine= scanCurrentLine(cu, position); if (nlsLine == null) return null; NLSElement element= findElement(nlsLine, position); if (element.hasTag()) return null; NLSElement[] elements= nlsLine.getElements(); int indexInElementList= Arrays.asList(elements).indexOf(element); int editOffset= computeInsertOffset(elements, indexInElementList, cu); String editText= ' ' + NLSElement.createTagText(indexInElementList + 1); //tags are 1-based return new InsertEdit(editOffset, editText); }
private static int computeInsertOffset(NLSElement[] elements, int index, int defaultValue) { NLSElement previousTagged= findPreviousTagged(index, elements); if (previousTagged != null) return previousTagged.getTagPosition().getOffset() + previousTagged.getTagPosition().getLength(); NLSElement nextTagged= findNextTagged(index, elements); if (nextTagged != null) return nextTagged.getTagPosition().getOffset(); return defaultValue; }
new NLSElement( value, scanner.getCurrentTokenStartPosition(),
result.append("public class ").append(fAccessorClassName).append(" extends NLS {"); //$NON-NLS-1$ //$NON-NLS-2$ result.append("private static final String ").append(NLSRefactoring.BUNDLE_NAME).append(" = \"").append(getResourceBundleName()).append("\"; "); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ result.append(NLSElement.createTagText(1)).append(lineDelim); result.append("public class ").append(fAccessorClassName).append(" {"); //$NON-NLS-1$ //$NON-NLS-2$ result.append("private static final String ").append(NLSRefactoring.BUNDLE_NAME); //$NON-NLS-1$ result.append(" = \"").append(getResourceBundleName()).append("\"; ").append(NLSElement.createTagText(1)).append(lineDelim); //$NON-NLS-1$ //$NON-NLS-2$
private NLSSubstitution[] createSubstitutions(NLSLine[] lines, Properties props, CompilationUnit astRoot) { List<NLSSubstitution> result= new ArrayList<>(); for (int i= 0; i < lines.length; i++) { NLSElement[] elements= lines[i].getElements(); for (int j= 0; j < elements.length; j++) { NLSElement nlsElement= elements[j]; if (nlsElement.hasTag()) { AccessorClassReference accessorClassReference= NLSHintHelper.getAccessorClassReference(astRoot, nlsElement); if (accessorClassReference == null) { // no accessor class => not translated result.add(new NLSSubstitution(NLSSubstitution.IGNORED, stripQuotes(nlsElement.getValue()), nlsElement)); } else { String key= stripQuotes(nlsElement.getValue()); String value= props.getProperty(key); result.add(new NLSSubstitution(NLSSubstitution.EXTERNALIZED, key, value, nlsElement, accessorClassReference)); } } else if (nlsElement.isEclipseNLS()) { String key= nlsElement.getValue(); result.add(new NLSSubstitution(NLSSubstitution.EXTERNALIZED, key, props.getProperty(key), nlsElement, nlsElement.getAccessorClassReference())); } else { result.add(new NLSSubstitution(NLSSubstitution.INTERNALIZED, stripQuotes(nlsElement.getValue()), nlsElement)); } } } return result.toArray(new NLSSubstitution[result.size()]); }
for (int j= 0; j < elements.length; j++) { NLSElement element= elements[j]; if (!element.hasTag()) { for (int k= 0; k < positions.length; k++) { if (isPositionInElement(element, positions[k])) { if (j==0) { if (elements.length > j+1) { editOffset= elements[j+1].getTagPosition().getOffset(); } else { editOffset= findLineEnd(cu, element.getPosition().getOffset()); Region previousPosition= elements[j-1].getTagPosition(); editOffset= previousPosition.getOffset() + previousPosition.getLength(); String editText= ' ' + NLSElement.createTagText(j + 1); //tags are 1-based result.add(new InsertEdit(editOffset, editText));
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()); if (element == null || element.hasTag()) return; String editText= ' ' + NLSElement.createTagText(indexInElementList + 1); //tags are 1-based TextChangeCompatibility.addTextEdit(change, label, new InsertEdit(lineEnd, editText));
NLSElement element= new NLSElement(node.getName().getIdentifier(), name.getStartPosition(), name.getLength(), nlsLine.size() - 1, true); nlsLine.add(element); element.setAccessorClassReference(new AccessorClassReference(type, bundleName, new Region(node.getStartPosition(), node.getLength()))); firstAccessor[0]= element.getAccessorClassReference();
private static int computeInsertOffset(NLSElement[] elements, int index, ICompilationUnit cu) throws CoreException { NLSElement previousTagged= findPreviousTagged(index, elements); if (previousTagged != null) return previousTagged.getTagPosition().getOffset() + previousTagged.getTagPosition().getLength(); NLSElement nextTagged= findNextTagged(index, elements); if (nextTagged != null) return nextTagged.getTagPosition().getOffset(); return findLineEnd(cu, elements[index].getPosition().getOffset()); }
private static void setTagPositions(IDocument document, NLSLine line) throws BadLocationException { IRegion info= document.getLineInformation(line.getLineNumber()); int defaultValue= info.getOffset() + info.getLength(); NLSElement[] elements= line.getElements(); for (int i= 0; i < elements.length; i++) { NLSElement element= elements[i]; if (!element.hasTag()) { element.setTagPosition(computeInsertOffset(elements, i, defaultValue), 0); } } }
/** * Creates and returns an NLS tag edit for a string that is at the specified position in a * compilation unit. * * @param cu the compilation unit * @param position position of the string * @return the edit, or <code>null</code> if the string is already NLSed or the edit could not * be created for some other reason. * @throws CoreException if scanning fails */ public static TextEdit createNLSEdit(ICompilationUnit cu, int position) throws CoreException { NLSLine nlsLine= scanCurrentLine(cu, position); if (nlsLine == null) return null; NLSElement element= findElement(nlsLine, position); if (element.hasTag()) return null; NLSElement[] elements= nlsLine.getElements(); int indexInElementList= Arrays.asList(elements).indexOf(element); int editOffset= computeInsertOffset(elements, indexInElementList, cu); String editText= ' ' + NLSElement.createTagText(indexInElementList + 1); //tags are 1-based return new InsertEdit(editOffset, editText); }