/** * @see java.io.Reader#read() */ @Override public int read() { if (fCurrPos < fEndPos) { char ch= getChar(fCurrPos++); if (fWasNewLine && !IndentManipulation.isLineDelimiterChar(ch)) { while (fCurrPos < fEndPos && Character.isWhitespace(ch)) { ch= getChar(fCurrPos++); } if (ch == '*') { if (fCurrPos < fEndPos) { do { ch= getChar(fCurrPos++); } while (ch == '*'); } else { return -1; } } } fWasNewLine= IndentManipulation.isLineDelimiterChar(ch); return ch; } return -1; }
/** @see java.io.Reader#read() */ @Override public int read() { if (fCurrPos < fEndPos) { char ch = fBuffer.getChar(fCurrPos++); if (fWasNewLine && !IndentManipulation.isLineDelimiterChar(ch)) { while (fCurrPos < fEndPos && Character.isWhitespace(ch)) { ch = fBuffer.getChar(fCurrPos++); } if (ch == '*') { if (fCurrPos < fEndPos) { do { ch = fBuffer.getChar(fCurrPos++); } while (ch == '*'); } else { return -1; } } } fWasNewLine = IndentManipulation.isLineDelimiterChar(ch); return ch; } return -1; }
/** * @see java.io.Reader#read() */ @Override public int read() { if (fCurrPos < fEndPos) { char ch= fBuffer.getChar(fCurrPos++); if (fWasNewLine && !IndentManipulation.isLineDelimiterChar(ch)) { while (fCurrPos < fEndPos && Character.isWhitespace(ch)) { ch= fBuffer.getChar(fCurrPos++); } if (ch == '*') { if (fCurrPos < fEndPos) { do { ch= fBuffer.getChar(fCurrPos++); } while (ch == '*'); } else { return -1; } } } fWasNewLine= IndentManipulation.isLineDelimiterChar(ch); return ch; } return -1; }
/** * Removes leading tabs and spaces from the given string. If the string * doesn't contain any leading tabs or spaces then the string itself is * returned. * @param line the line * @return the trimmed line */ public static String trimLeadingTabsAndSpaces(String line) { int size= line.length(); int start= size; for (int i= 0; i < size; i++) { char c= line.charAt(i); if (!IndentManipulation.isIndentChar(c)) { start= i; break; } } if (start == 0) return line; else if (start == size) return ""; //$NON-NLS-1$ else return line.substring(start); }
public static String trimTrailingTabsAndSpaces(String line) { int size= line.length(); int end= size; for (int i= size - 1; i >= 0; i--) { char c= line.charAt(i); if (IndentManipulation.isIndentChar(c)) { end= i; } else { break; } } if (end == size) return line; else if (end == 0) return ""; //$NON-NLS-1$ else return line.substring(0, end); }
private String removeIndentAndNewLines(String code, ICompilationUnit cu) throws JavaModelException { IJavaProject project = cu.getJavaProject(); Map options = project.getOptions(true/*inherit JavaCore options*/); int tabWidth = IndentManipulation.getTabWidth(options); int indentWidth = IndentManipulation.getIndentWidth(options); int indent = IndentManipulation.measureIndentUnits(code, tabWidth, indentWidth); int firstNonWhiteSpace = -1; int length = code.length(); while (firstNonWhiteSpace < length-1) if (!ScannerHelper.isWhitespace(code.charAt(++firstNonWhiteSpace))) break; int lastNonWhiteSpace = length; while (lastNonWhiteSpace > 0) if (!ScannerHelper.isWhitespace(code.charAt(--lastNonWhiteSpace))) break; String lineDelimiter = cu.findRecommendedLineSeparator(); return IndentManipulation.changeIndent(code.substring(firstNonWhiteSpace, lastNonWhiteSpace+1), indent, tabWidth, indentWidth, "", lineDelimiter); //$NON-NLS-1$ }
private static String getIndentAt(IDocument document, int offset, CodeGenerationSettings settings) { try { IRegion region= document.getLineInformationOfOffset(offset); return IndentManipulation.extractIndentString(document.get(region.getOffset(), region.getLength()), settings.tabWidth, settings.indentWidth); } catch (BadLocationException e) { return ""; //$NON-NLS-1$ } }
private static int getIndentUsed(IBuffer buffer, int offset, IJavaProject project) { int i= offset; // find beginning of line while (i > 0 && !IndentManipulation.isLineDelimiterChar(buffer.getChar(i - 1))) { i--; } return Strings.computeIndentUnits(buffer.getText(i, offset - i), project); }
/** * Removes leading tabs and spaces from the given string. If the string doesn't contain any * leading tabs or spaces then the string itself is returned. * * @param line the line * @return the trimmed line */ public static String trimLeadingTabsAndSpaces(String line) { int size = line.length(); int start = size; for (int i = 0; i < size; i++) { char c = line.charAt(i); if (!IndentManipulation.isIndentChar(c)) { start = i; break; } } if (start == 0) return line; else if (start == size) return ""; // $NON-NLS-1$ else return line.substring(start); }
public static String trimTrailingTabsAndSpaces(String line) { int size = line.length(); int end = size; for (int i = size - 1; i >= 0; i--) { char c = line.charAt(i); if (IndentManipulation.isIndentChar(c)) { end = i; } else { break; } } if (end == size) return line; else if (end == 0) return ""; // $NON-NLS-1$ else return line.substring(0, end); }
public static int getIndentUsed(IBuffer buffer, int offset, IJavaProject project) { int i = offset; // find beginning of line while (i > 0 && !IndentManipulation.isLineDelimiterChar(buffer.getChar(i - 1))) { i--; } return Strings.computeIndentUnits(buffer.getText(i, offset - i), project); }
private static String getIndentAt( IDocument document, int offset, CodeGenerationSettings settings) { try { IRegion region = document.getLineInformationOfOffset(offset); return IndentManipulation.extractIndentString( document.get(region.getOffset(), region.getLength()), settings.tabWidth, settings.indentWidth); } catch (BadLocationException e) { return ""; // $NON-NLS-1$ } }
/** * Returns the indentation units for a given project, document, line and line * offset. */ static int measureIndentationUnits(IDocument document, int lineOfInvocationOffset, int lineOffset, IJavaProject project) throws BadLocationException { Map<?, ?> options = project.getOptions(true); String lineText = document.get(lineOffset, document.getLineLength(lineOfInvocationOffset)); int indentationUnits = IndentManipulation.measureIndentUnits(lineText, IndentManipulation.getTabWidth(options), IndentManipulation.getIndentWidth(options)); return indentationUnits; }
private static int findLineEnd(ICompilationUnit cu, int position) throws JavaModelException { IBuffer buffer= cu.getBuffer(); int length= buffer.getLength(); for (int i= position; i < length; i++) { if (IndentManipulation.isLineDelimiterChar(buffer.getChar(i))) { return i; } } return length; }
public static int getIndentUsed(IBuffer buffer, int offset, IJavaProject project) { int i= offset; // find beginning of line while (i > 0 && !IndentManipulation.isLineDelimiterChar(buffer.getChar(i - 1))) { i--; } return Strings.computeIndentUnits(buffer.getText(i, offset - i), project); }
private SearchPatternData trySimpleTextSelection(ITextSelection selection) { String selectedText= selection.getText(); if (selectedText != null && selectedText.length() > 0) { int i= 0; while (i < selectedText.length() && !IndentManipulation.isLineDelimiterChar(selectedText.charAt(i))) { i++; } if (i > 0) { return new SearchPatternData(TYPE, REFERENCES, 0, fIsCaseSensitive, selectedText.substring(0, i), null, JavaSearchScopeFactory.ALL); } } return null; }
/** * @param element either an ICompilationUnit or an IClassFile * @param lineNumber the line number, starting at 0 * @param lineStartOffset the start offset of the line * @throws CoreException thrown when accessing of the buffer failed */ public JavaElementLine(ITypeRoot element, int lineNumber, int lineStartOffset) throws CoreException { fElement= element; fFlags= 0; IBuffer buffer= element.getBuffer(); if (buffer == null) { throw new CoreException(new Status(IStatus.ERROR, JavaUI.ID_PLUGIN, Messages.format( SearchMessages.JavaElementLine_error_nobuffer, BasicElementLabels.getFileName(element)))); } int length= buffer.getLength(); int i= lineStartOffset; char ch= buffer.getChar(i); while (lineStartOffset < length && IndentManipulation.isIndentChar(ch)) { ch= buffer.getChar(++i); } fLineStartOffset= i; StringBuffer buf= new StringBuffer(); while (i < length && !IndentManipulation.isLineDelimiterChar(ch)) { if (Character.isISOControl(ch)) { buf.append(' '); } else { buf.append(ch); } i++; if (i < length) ch= buffer.getChar(i); } fLineContents= buf.toString(); fLineNumber= lineNumber; }
final private String getIndentOfLine(int pos) { int line= getLineInformation().getLineOfOffset(pos); if (line >= 0) { char[] cont= getContent(); int lineStart= getLineInformation().getLineOffset(line); int i= lineStart; while (i < cont.length && IndentManipulation.isIndentChar(this.content[i])) { i++; } return new String(cont, lineStart, i - lineStart); } return Util.EMPTY_STRING; }
private boolean needsNewLineForLineComment(ASTNode node, String formatted, int offset) { if (!this.lineCommentEndOffsets.isEndOfLineComment(getExtendedEnd(node), this.content)) { return false; } // copied code ends with a line comment, but doesn't contain the new line return offset < formatted.length() && !IndentManipulation.isLineDelimiterChar(formatted.charAt(offset)); }
private int getCurrentLineStart(String str, int pos) { for (int i= pos - 1; i>= 0; i--) { char ch= str.charAt(i); if (IndentManipulation.isLineDelimiterChar(ch)) { return i+1; } } return 0; }
private int findTagNameEnd(TagElement tagNode) { if (tagNode.getTagName() != null) { char[] cont= getContent(); int len= cont.length; int i= tagNode.getStartPosition(); while (i < len && !IndentManipulation.isIndentChar(cont[i])) { i++; } return i; } return tagNode.getStartPosition(); }
public ASTRewriteFormatter(NodeInfoStore placeholders, RewriteEventStore eventStore, Map options, String lineDelimiter) { this.placeholders= placeholders; this.eventStore= eventStore; this.options= options == null ? JavaCore.getOptions() : (Map) new HashMap(options); this.options.put( DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_RESOURCES_IN_TRY, DefaultCodeFormatterConstants.createAlignmentValue(true, DefaultCodeFormatterConstants.WRAP_NEXT_PER_LINE, DefaultCodeFormatterConstants.INDENT_DEFAULT)); this.lineDelimiter= lineDelimiter; this.tabWidth= IndentManipulation.getTabWidth(options); this.indentWidth= IndentManipulation.getIndentWidth(options); }
public ReplaceEdit[] getModifications(String source) { List result= new ArrayList(); int destIndentLevel= IndentManipulation.measureIndentUnits(this.destinationIndent, this.tabWidth, this.indentWidth); if (destIndentLevel == this.sourceIndentLevel) { return (ReplaceEdit[])result.toArray(new ReplaceEdit[result.size()]); } return IndentManipulation.getChangeIndentEdits(source, this.sourceIndentLevel, this.tabWidth, this.indentWidth, this.destinationIndent); }
/** * @param element either an ICompilationUnit or an IClassFile * @param lineNumber the line number * @param lineStartOffset the start offset of the line * @throws CoreException thrown when accessing of the buffer failed */ public JavaElementLine(ITypeRoot element, int lineNumber, int lineStartOffset) throws CoreException { fElement= element; fFlags= 0; IBuffer buffer= element.getBuffer(); if (buffer == null) { throw new CoreException(new Status(IStatus.ERROR, JavaUI.ID_PLUGIN, Messages.format( SearchMessages.JavaElementLine_error_nobuffer, BasicElementLabels.getFileName(element)))); } int length= buffer.getLength(); int i= lineStartOffset; char ch= buffer.getChar(i); while (lineStartOffset < length && IndentManipulation.isIndentChar(ch)) { ch= buffer.getChar(++i); } fLineStartOffset= i; StringBuffer buf= new StringBuffer(); while (i < length && !IndentManipulation.isLineDelimiterChar(ch)) { if (Character.isISOControl(ch)) { buf.append(' '); } else { buf.append(ch); } i++; if (i < length) ch= buffer.getChar(i); } fLineContents= buf.toString(); fLineNumber= lineNumber; }
public AbstractSourceFileLocator(IPackageFragmentRoot root) { this.root = root; final Map<?, ?> options = root.getJavaProject().getOptions(true); this.tabWidth = IndentManipulation.getTabWidth(options); }