List of usage examples for org.eclipse.jdt.core.formatter IndentManipulation isLineDelimiterChar
public static boolean isLineDelimiterChar(char ch)
true
if the given character is a line delimiter character. From source file:at.bestsolution.fxide.jdt.corext.javadoc.JavaDocCommentReader.java
License:Open Source License
/** * @see java.io.Reader#read()//from ww w . j a va 2 s .com */ @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; }
From source file:com.siteview.mde.internal.ui.editor.contentassist.display.JavaDocCommentReader.java
License:Open Source License
/** * @see java.io.Reader#read()//from w w w. j ava 2 s . c o m */ public int read() { if (fCurrPos < fEndPos) { char ch; if (fWasNewLine) { do { ch = fBuffer.getChar(fCurrPos++); } while (fCurrPos < fEndPos && Character.isWhitespace(ch)); if (ch == '*') { if (fCurrPos < fEndPos) { do { ch = fBuffer.getChar(fCurrPos++); } while (ch == '*'); } else { return -1; } } } else { ch = fBuffer.getChar(fCurrPos++); } fWasNewLine = IndentManipulation.isLineDelimiterChar(ch); return ch; } return -1; }
From source file:org.eclim.plugin.jdt.util.JavaUtils.java
License:Open Source License
/** * Format a region in the supplied source file. * * @param src The ICompilationUnit.//from ww w . ja va2 s. com * @param kind The kind of code snippet to format. * @param offset The starting offset of the region to format. * @param length The length of the region to format. */ public static void format(ICompilationUnit src, int kind, int offset, int length) throws Exception { IBuffer buffer = src.getBuffer(); String contents = buffer.getContents(); String delimiter = StubUtility.getLineDelimiterUsed(src); DefaultCodeFormatter formatter = new DefaultCodeFormatter(src.getJavaProject().getOptions(true)); // when the eclipse indent settings differ from vim (tabs vs spaces) then // the inserted method's indent may be a bit off. this is a workaround to // force reformatting of the code from the start of the line to the start of // the next set of code following the new method. Doesn't quite fix indent // formatting of methods in nested classes. while (offset > 0 && !IndentManipulation.isLineDelimiterChar(buffer.getChar(offset - 1))) { offset--; length++; } while ((offset + length) < contents.length() && IndentManipulation.isLineDelimiterChar(buffer.getChar(offset + length))) { length++; } TextEdit edits = formatter.format(kind, contents, offset, length, 0, delimiter); if (edits != null) { int oldLength = contents.length(); Document document = new Document(contents); edits.apply(document); String formatted = document.get(); // jdt formatter can introduce trailing whitespace (javadoc comments), so // we'll remove all trailing whitespace from the formatted section (unless // the user has configured eclim not to do so). length += formatted.length() - oldLength; if (offset < (offset + length)) { String stripTrailingWhitespace = Preferences.getInstance().getValue( src.getJavaProject().getProject(), "org.eclim.java.format.strip_trialing_whitespace"); if ("true".equals(stripTrailingWhitespace)) { String pre = formatted.substring(0, offset); StringBuffer section = new StringBuffer(formatted.substring(offset, offset + length)); StringBuffer post = new StringBuffer(formatted.substring(offset + length)); // account for section not ending at a line delimiter while (!section.toString().endsWith(delimiter) && post.length() > 0) { section.append(post.charAt(0)); post.deleteCharAt(0); } Matcher matcher = TRAILING_WHITESPACE.matcher(section); String stripped = matcher.replaceAll(StringUtils.EMPTY); src.getBuffer().setContents(pre + stripped + post); } else { src.getBuffer().setContents(formatted); } } else { src.getBuffer().setContents(formatted); } if (src.isWorkingCopy()) { src.commitWorkingCopy(true, null); } src.save(null, false); } }