private static NLSLine scanCurrentLine(ICompilationUnit cu, int position) throws JavaModelException { try { Assert.isTrue(position >= 0 && position <= cu.getBuffer().getLength()); NLSLine[] allLines= NLSScanner.scan(cu); for (int i= 0; i < allLines.length; i++) { NLSLine line= allLines[i]; if (findElement(line, position) != null) return line; } return null; } catch (InvalidInputException e) { return null; } }
private static NLSLine scanCurrentLine(ICompilationUnit cu, int position) throws JavaModelException { try { Assert.isTrue(position >= 0 && position <= cu.getBuffer().getLength()); NLSLine[] allLines= NLSScanner.scan(cu); for (int i= 0; i < allLines.length; i++) { NLSLine line= allLines[i]; if (findElement(line, position) != null) return line; } return null; } catch (InvalidInputException e) { return null; } catch (BadLocationException e) { return null; } }
/** * 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); }
/** * 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); }
private static NLSLine scanCurrentLine(ICompilationUnit cu, int position) throws JavaModelException { try { Assert.isTrue(position >= 0 && position <= cu.getBuffer().getLength()); NLSLine[] allLines= NLSScanner.scan(cu); for (int i= 0; i < allLines.length; i++) { NLSLine line= allLines[i]; if (findElement(line, position) != null) return line; } return null; } catch (InvalidInputException e) { return null; } catch (BadLocationException e) { return null; } }
/** * 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); }