Java Code Examples for org.eclipse.jdt.core.formatter.IndentManipulation#isIndentChar()

The following examples show how to use org.eclipse.jdt.core.formatter.IndentManipulation#isIndentChar() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Strings.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * 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);
}
 
Example 2
Source File: Strings.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
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);
}
 
Example 3
Source File: JavaElementLine.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * @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;
}
 
Example 4
Source File: ASTRewriteAnalyzer.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
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;
}
 
Example 5
Source File: ASTRewriteAnalyzer.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
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();
}
 
Example 6
Source File: StringFix.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
private static ReplaceEdit getReplace(int offset, int length, IBuffer buffer, boolean removeLeadingIndents) {

		String replaceString= new String();
		boolean hasMoreInComment= false;

		// look after the tag
		int next= offset + length;
		while (next < buffer.getLength()) {
			char ch= buffer.getChar(next);
			if (IndentManipulation.isIndentChar(ch)) {
				next++; // remove all whitespace
			} else if (IndentManipulation.isLineDelimiterChar(ch)) {
				length= next - offset;
				break;
			} else if (ch == '/') {
				next++;
				if (next == buffer.getLength() || buffer.getChar(next) != '/') {
					replaceString= "//"; //$NON-NLS-1$
				} else {
					length= next - offset - 1;
				}
				hasMoreInComment= true;
				break;
			} else {
				replaceString= "//"; //$NON-NLS-1$
				hasMoreInComment= true;
				break;
			}
		}
		if (!hasMoreInComment && removeLeadingIndents) {
			while (offset > 0 && IndentManipulation.isIndentChar(buffer.getChar(offset - 1))) {
				offset--;
				length++;
			}
		}
		if (length > 0) {
			ReplaceEdit replaceEdit= new ReplaceEdit(offset, length, replaceString);
			return replaceEdit;
		} else {
			return null;
		}
	}