Java Code Examples for org.eclipse.jdt.internal.compiler.util.Util#EMPTY_STRING
The following examples show how to use
org.eclipse.jdt.internal.compiler.util.Util#EMPTY_STRING .
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: CompilerOptions.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
public static String versionFromJdkLevel(long jdkLevel) { switch ((int)(jdkLevel>>16)) { case ClassFileConstants.MAJOR_VERSION_1_1 : if (jdkLevel == ClassFileConstants.JDK1_1) return VERSION_1_1; break; case ClassFileConstants.MAJOR_VERSION_1_2 : if (jdkLevel == ClassFileConstants.JDK1_2) return VERSION_1_2; break; case ClassFileConstants.MAJOR_VERSION_1_3 : if (jdkLevel == ClassFileConstants.JDK1_3) return VERSION_1_3; break; case ClassFileConstants.MAJOR_VERSION_1_4 : if (jdkLevel == ClassFileConstants.JDK1_4) return VERSION_1_4; break; case ClassFileConstants.MAJOR_VERSION_1_5 : if (jdkLevel == ClassFileConstants.JDK1_5) return VERSION_1_5; break; case ClassFileConstants.MAJOR_VERSION_1_6 : if (jdkLevel == ClassFileConstants.JDK1_6) return VERSION_1_6; break; case ClassFileConstants.MAJOR_VERSION_1_7 : if (jdkLevel == ClassFileConstants.JDK1_7) return VERSION_1_7; break; case ClassFileConstants.MAJOR_VERSION_1_8 : if (jdkLevel == ClassFileConstants.JDK1_8) return VERSION_1_8; break; } return Util.EMPTY_STRING; // unknown version }
Example 2
Source File: Scribe.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
public String getNewLine() { if (this.nlsTagCounter > 0) { return Util.EMPTY_STRING; } if (this.lastNumberOfNewLines >= 1) { this.column = 1; // ensure that the scribe is at the beginning of a new line return Util.EMPTY_STRING; } this.line++; this.lastNumberOfNewLines = 1; this.column = 1; this.needSpace = false; this.pendingSpace = false; return this.lineSeparator; }
Example 3
Source File: Scribe.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private String getPreserveEmptyLines(int count, int emptyLinesRules) { if (count == 0) { int currentIndentationLevel = this.indentationLevel; int useAlignmentBreakIndentation = useAlignmentBreakIndentation(emptyLinesRules); switch (useAlignmentBreakIndentation) { case PRESERVE_EMPTY_LINES_DO_NOT_USE_ANY_INDENTATION: return Util.EMPTY_STRING; default: // Return the new indented line StringBuffer buffer = new StringBuffer(getNewLine()); printIndentationIfNecessary(buffer); if (useAlignmentBreakIndentation == PRESERVE_EMPTY_LINES_USE_TEMPORARY_INDENTATION) { this.indentationLevel = currentIndentationLevel; } return buffer.toString(); } } if (this.blank_lines_between_import_groups >= 0) { useAlignmentBreakIndentation(emptyLinesRules); return getEmptyLines(this.blank_lines_between_import_groups); } if (this.formatter.preferences.number_of_empty_lines_to_preserve != 0) { useAlignmentBreakIndentation(emptyLinesRules); int linesToPreserve = Math.min(count, this.formatter.preferences.number_of_empty_lines_to_preserve); return getEmptyLines(linesToPreserve); } return getNewLine(); }
Example 4
Source File: AbortCompilation.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
public String getMessage() { String message = super.getMessage(); StringBuffer buffer = new StringBuffer(message == null ? Util.EMPTY_STRING : message); if (this.problem != null) { buffer.append(this.problem); } else if (this.exception != null) { message = this.exception.getMessage(); buffer.append(message == null ? Util.EMPTY_STRING : message); } else if (this.silentException != null) { message = this.silentException.getMessage(); buffer.append(message == null ? Util.EMPTY_STRING : message); } return String.valueOf(buffer); }
Example 5
Source File: DefaultCodeFormatter.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
public String createIndentationString(final int indentationLevel) { if (indentationLevel < 0) { throw new IllegalArgumentException(); } int tabs = 0; int spaces = 0; switch(this.preferences.tab_char) { case DefaultCodeFormatterOptions.SPACE : spaces = indentationLevel * this.preferences.tab_size; break; case DefaultCodeFormatterOptions.TAB : tabs = indentationLevel; break; case DefaultCodeFormatterOptions.MIXED : int tabSize = this.preferences.tab_size; if (tabSize != 0) { int spaceEquivalents = indentationLevel * this.preferences.indentation_size; tabs = spaceEquivalents / tabSize; spaces = spaceEquivalents % tabSize; } break; default: return Util.EMPTY_STRING; } if (tabs == 0 && spaces == 0) { return Util.EMPTY_STRING; } StringBuffer buffer = new StringBuffer(tabs + spaces); for(int i = 0; i < tabs; i++) { buffer.append('\t'); } for(int i = 0; i < spaces; i++) { buffer.append(' '); } return buffer.toString(); }
Example 6
Source File: IndentManipulation.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
/** * Returns the leading indentation string of the given line. Note that the returned string * need not be equal to the leading whitespace as odd spaces are not considered part of the * indentation. * * @param line the line to scan * @param tabWidth the size of one tab in space equivalents * @param indentWidth the width of one indentation unit in space equivalents * @return the indent part of <code>line</code>, but no odd spaces * @exception IllegalArgumentException if: * <ul> * <li>the given <code>indentWidth</code> is lower than zero</li> * <li>the given <code>tabWidth</code> is lower than zero</li> * <li>the given <code>line</code> is null</li> * </ul> */ public static String extractIndentString(String line, int tabWidth, int indentWidth) { if (tabWidth < 0 || indentWidth < 0 || line == null) { throw new IllegalArgumentException(); } int size = line.length(); int end = 0; int spaceEquivs = 0; int characters = 0; for (int i = 0; i < size; i++) { char c = line.charAt(i); if (c == '\t') { spaceEquivs = calculateSpaceEquivalents(tabWidth, spaceEquivs); characters++; } else if (isIndentChar(c)) { spaceEquivs++; characters++; } else { break; } if (spaceEquivs >= indentWidth) { end += characters; characters = 0; if(indentWidth == 0) { spaceEquivs = 0; } else { spaceEquivs = spaceEquivs % indentWidth; } } } if (end == 0) { return Util.EMPTY_STRING; } else if (end == size) { return line; } else { return line.substring(0, end); } }
Example 7
Source File: SelectionParser.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
public String toString() { String s = Util.EMPTY_STRING; s = s + "elementKindStack : int[] = {"; //$NON-NLS-1$ for (int i = 0; i <= this.elementPtr; i++) { s = s + String.valueOf(this.elementKindStack[i]) + ","; //$NON-NLS-1$ } s = s + "}\n"; //$NON-NLS-1$ s = s + "elementInfoStack : int[] = {"; //$NON-NLS-1$ for (int i = 0; i <= this.elementPtr; i++) { s = s + String.valueOf(this.elementInfoStack[i]) + ","; //$NON-NLS-1$ } s = s + "}\n"; //$NON-NLS-1$ return s + super.toString(); }
Example 8
Source File: TextElement.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
int memSize() { int size = BASE_NODE_SIZE + 1 * 4; if (this.text != Util.EMPTY_STRING) { // everything but our empty string costs size += stringSize(this.text); } return size; }
Example 9
Source File: ASTRewriteAnalyzer.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
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 10
Source File: IndentManipulation.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
/** * Removes the given number of indentation units from a given line. If the line * has less indent than the given indentUnitsToRemove, all the available indentation is removed. * If <code>indentsToRemove <= 0 or indent == 0</code> the line is returned. * * @param line the line to trim * @param tabWidth the width of one tab in space equivalents * @param indentWidth the width of one indentation unit in space equivalents * @return the trimmed string * @exception IllegalArgumentException if: * <ul> * <li>the given <code>indentWidth</code> is lower than zero</li> * <li>the given <code>tabWidth</code> is lower than zero</li> * <li>the given <code>line</code> is null</li> * </ul> */ public static String trimIndent(String line, int indentUnitsToRemove, int tabWidth, int indentWidth) { if (tabWidth < 0 || indentWidth < 0 || line == null) { throw new IllegalArgumentException(); } if (indentUnitsToRemove <= 0 || indentWidth == 0) { return line; } final int spaceEquivalentsToRemove= indentUnitsToRemove * indentWidth; int start= 0; int spaceEquivalents= 0; int size= line.length(); String prefix= null; for (int i= 0; i < size; i++) { char c= line.charAt(i); if (c == '\t') { spaceEquivalents = calculateSpaceEquivalents(tabWidth, spaceEquivalents); } else if (isIndentChar(c)) { spaceEquivalents++; } else { // Assert.isTrue(false, "Line does not have requested number of indents"); start= i; break; } if (spaceEquivalents == spaceEquivalentsToRemove) { start= i + 1; break; } if (spaceEquivalents > spaceEquivalentsToRemove) { // can happen if tabSize > indentSize, e.g tabsize==8, indent==4, indentsToRemove==1, line prefixed with one tab // this implements the third option start= i + 1; // remove the tab // and add the missing spaces char[] missing= new char[spaceEquivalents - spaceEquivalentsToRemove]; Arrays.fill(missing, ' '); prefix= new String(missing); break; } } String trimmed; if (start == size) trimmed= Util.EMPTY_STRING; else trimmed= line.substring(start); if (prefix == null) return trimmed; return prefix + trimmed; }
Example 11
Source File: Main.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
public static String[] tokenize(String commandLine) { int count = 0; String[] arguments = new String[10]; StringTokenizer tokenizer = new StringTokenizer(commandLine, " \"", true); //$NON-NLS-1$ String token = Util.EMPTY_STRING; boolean insideQuotes = false; boolean startNewToken = true; // take care to quotes on the command line // 'xxx "aaa bbb";ccc yyy' ---> {"xxx", "aaa bbb;ccc", "yyy" } // 'xxx "aaa bbb;ccc" yyy' ---> {"xxx", "aaa bbb;ccc", "yyy" } // 'xxx "aaa bbb";"ccc" yyy' ---> {"xxx", "aaa bbb;ccc", "yyy" } // 'xxx/"aaa bbb";"ccc" yyy' ---> {"xxx/aaa bbb;ccc", "yyy" } while (tokenizer.hasMoreTokens()) { token = tokenizer.nextToken(); if (token.equals(" ")) { //$NON-NLS-1$ if (insideQuotes) { arguments[count - 1] += token; startNewToken = false; } else { startNewToken = true; } } else if (token.equals("\"")) { //$NON-NLS-1$ if (!insideQuotes && startNewToken) { if (count == arguments.length) System.arraycopy(arguments, 0, (arguments = new String[count * 2]), 0, count); arguments[count++] = Util.EMPTY_STRING; } insideQuotes = !insideQuotes; startNewToken = false; } else { if (insideQuotes) { arguments[count - 1] += token; } else { if (token.length() > 0 && !startNewToken) { arguments[count - 1] += token; } else { if (count == arguments.length) System.arraycopy(arguments, 0, (arguments = new String[count * 2]), 0, count); String trimmedToken = token.trim(); if (trimmedToken.length() != 0) { arguments[count++] = trimmedToken; } } } startNewToken = false; } } System.arraycopy(arguments, 0, arguments = new String[count], 0, count); return arguments; }
Example 12
Source File: RecoveredTypeBinding.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
private String getTypeNameFrom(Type type) { if (type == null) return Util.EMPTY_STRING; switch(type.getNodeType0()) { case ASTNode.ARRAY_TYPE : ArrayType arrayType = (ArrayType) type; type = arrayType.getElementType(); return getTypeNameFrom(type); case ASTNode.PARAMETERIZED_TYPE : ParameterizedType parameterizedType = (ParameterizedType) type; StringBuffer buffer = new StringBuffer(getTypeNameFrom(parameterizedType.getType())); ITypeBinding[] tArguments = getTypeArguments(); final int typeArgumentsLength = tArguments.length; if (typeArgumentsLength != 0) { buffer.append('<'); for (int i = 0; i < typeArgumentsLength; i++) { if (i > 0) { buffer.append(','); } buffer.append(tArguments[i].getName()); } buffer.append('>'); } return String.valueOf(buffer); case ASTNode.PRIMITIVE_TYPE : PrimitiveType primitiveType = (PrimitiveType) type; return primitiveType.getPrimitiveTypeCode().toString(); case ASTNode.QUALIFIED_TYPE : QualifiedType qualifiedType = (QualifiedType) type; return qualifiedType.getName().getIdentifier(); case ASTNode.NAME_QUALIFIED_TYPE : NameQualifiedType nameQualifiedType = (NameQualifiedType) type; return nameQualifiedType.getName().getIdentifier(); case ASTNode.SIMPLE_TYPE : SimpleType simpleType = (SimpleType) type; Name name = simpleType.getName(); if (name.isQualifiedName()) { QualifiedName qualifiedName = (QualifiedName) name; return qualifiedName.getName().getIdentifier(); } return ((SimpleName) name).getIdentifier(); } return Util.EMPTY_STRING; }
Example 13
Source File: CharArrayBuffer.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
/** * Returns the contents of the buffer as a String, or * an empty string if the buffer is empty. */ public String toString() { char[] contents = getContents(); return (contents != null) ? new String(contents) : Util.EMPTY_STRING; }
Example 14
Source File: Scribe.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
private void printNewLinesBeforeDisablingComment() { // Get the beginning of comment line int linePtr = Arrays.binarySearch(this.lineEnds, this.scanner.startPosition); if (linePtr < 0) { linePtr = -linePtr - 1; } int indentation = 0; int beginningOfLine = getLineEnd(linePtr)+1; if (beginningOfLine == -1) { beginningOfLine = 0; } // If the comment is in the middle of the line, then there's nothing to do OptimizedReplaceEdit currentEdit = this.edits[this.editsIndex-1]; int offset = currentEdit.offset; if (offset >= beginningOfLine) return; // Compute the comment indentation int scannerStartPosition = this.scanner.startPosition; int scannerEofPosition = this.scanner.eofPosition; int scannerCurrentPosition = this.scanner.currentPosition; char scannerCurrentChar = this.scanner.currentCharacter; int length = currentEdit.length; this.scanner.resetTo(beginningOfLine, offset+length-1); try { while (!this.scanner.atEnd()) { char ch = (char) this.scanner.getNextChar(); switch (ch) { case '\t' : if (this.tabLength != 0) { int reminder = indentation % this.tabLength; if (reminder == 0) { indentation += this.tabLength; } else { indentation = ((indentation / this.tabLength) + 1) * this.tabLength; } } break; case ' ': indentation++; break; default: // Should not happen as the offset of the edit is before the beginning of line return; } } // Split the existing edit to keep the change before the beginning of the last line // but change the indentation after. Note that at this stage, the add*Edit methods // cannot be longer used as the edits are disabled String indentationString; int currentIndentation = getCurrentIndentation(this.scanner.currentPosition); if (currentIndentation > 0 && this.indentationLevel > 0) { int col = this.column; this.tempBuffer.setLength(0); printIndentationIfNecessary(this.tempBuffer); indentationString = this.tempBuffer.toString(); this.column = col; } else { indentationString = Util.EMPTY_STRING; } String replacement = currentEdit.replacement; if (replacement.length() == 0) { // previous edit was a delete, as we're sure to have a new line before // the comment, then the edit needs to be either replaced entirely with // the expected indentation this.edits[this.editsIndex-1] = new OptimizedReplaceEdit(beginningOfLine, offset+length-beginningOfLine, indentationString); } else { int idx = replacement.lastIndexOf(this.lineSeparator); if (idx >= 0) { // replace current edit if it contains a line separator int start = idx + this.lsLength; this.tempBuffer.setLength(0); this.tempBuffer.append(replacement.substring(0, start)); if (indentationString != Util.EMPTY_STRING) { this.tempBuffer.append(indentationString); } this.edits[this.editsIndex-1] = new OptimizedReplaceEdit(offset, length, this.tempBuffer.toString()); } } } finally { this.scanner.startPosition = scannerStartPosition; this.scanner.eofPosition = scannerEofPosition; this.scanner.currentPosition = scannerCurrentPosition; this.scanner.currentCharacter = scannerCurrentChar; } }
Example 15
Source File: Scribe.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
private void printEmptyLines(int linesNumber, int insertPosition) { final String buffer = getEmptyLines(linesNumber); if (Util.EMPTY_STRING == buffer) return; addInsertEdit(insertPosition, buffer); }
Example 16
Source File: Scribe.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
public String getEmptyLines(int linesNumber) { if (this.nlsTagCounter > 0) { return Util.EMPTY_STRING; } String emptyLines; if (this.lastNumberOfNewLines == 0) { linesNumber++; // add an extra line breaks if (this.indentEmptyLines) { this.tempBuffer.setLength(0); for (int i = 0; i < linesNumber; i++) { printIndentationIfNecessary(this.tempBuffer); this.tempBuffer.append(this.lineSeparator); this.column = 1; } emptyLines = this.tempBuffer.toString(); } else { emptyLines = getNewLineString(linesNumber); } this.lastNumberOfNewLines += linesNumber; this.line += linesNumber; this.column = 1; this.needSpace = false; this.pendingSpace = false; } else if (this.lastNumberOfNewLines == 1) { if (this.indentEmptyLines) { this.tempBuffer.setLength(0); for (int i = 0; i < linesNumber; i++) { printIndentationIfNecessary(this.tempBuffer); this.tempBuffer.append(this.lineSeparator); this.column = 1; } emptyLines = this.tempBuffer.toString(); } else { emptyLines = getNewLineString(linesNumber); } this.lastNumberOfNewLines += linesNumber; this.line += linesNumber; this.column = 1; this.needSpace = false; this.pendingSpace = false; } else { if ((this.lastNumberOfNewLines - 1) >= linesNumber) { // there is no need to add new lines return Util.EMPTY_STRING; } final int realNewLineNumber = linesNumber - this.lastNumberOfNewLines + 1; if (this.indentEmptyLines) { this.tempBuffer.setLength(0); for (int i = 0; i < realNewLineNumber; i++) { printIndentationIfNecessary(this.tempBuffer); this.tempBuffer.append(this.lineSeparator); this.column = 1; } emptyLines = this.tempBuffer.toString(); } else { emptyLines = getNewLineString(realNewLineNumber); } this.lastNumberOfNewLines += realNewLineNumber; this.line += realNewLineNumber; this.column = 1; this.needSpace = false; this.pendingSpace = false; } return emptyLines; }
Example 17
Source File: CodeFormatter.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 2 votes |
/** * Answers the string that corresponds to the indentation to the given indentation level or an empty string * if the indentation cannot be computed. * <p>This method needs to be overridden in a subclass.</p> * * <p>The default implementation returns an empty string.</p> * * @param indentationLevel the given indentation level * @return the string corresponding to the right indentation level * @exception IllegalArgumentException if the given indentation level is lower than zero * @since 3.2 */ public String createIndentationString(int indentationLevel) { return Util.EMPTY_STRING; }