use of org.eclipse.jdt.internal.ui.text.JavaHeuristicScanner in project che by eclipse.
the class JavaCompletionProposalComputer method guessMethodContextInformationPosition.
protected final int guessMethodContextInformationPosition(ContentAssistInvocationContext context) {
final int contextPosition = context.getInvocationOffset();
IDocument document = context.getDocument();
JavaHeuristicScanner scanner = new JavaHeuristicScanner(document);
int bound = Math.max(-1, contextPosition - 2000);
// try the innermost scope of parentheses that looks like a method call
int pos = contextPosition - 1;
do {
int paren = scanner.findOpeningPeer(pos, bound, '(', ')');
if (paren == JavaHeuristicScanner.NOT_FOUND)
break;
int token = scanner.previousToken(paren - 1, bound);
// constructor call of a parameterized type.
if (token == Symbols.TokenIDENT || token == Symbols.TokenGREATERTHAN)
return paren + 1;
pos = paren - 1;
} while (true);
return contextPosition;
}
use of org.eclipse.jdt.internal.ui.text.JavaHeuristicScanner in project che by eclipse.
the class JavaTypeCompletionProposalComputer method guessContextInformationPosition.
@Override
protected int guessContextInformationPosition(ContentAssistInvocationContext context) {
final int contextPosition = context.getInvocationOffset();
IDocument document = context.getDocument();
JavaHeuristicScanner scanner = new JavaHeuristicScanner(document);
int bound = Math.max(-1, contextPosition - 200);
// try the innermost scope of angle brackets that looks like a generic type argument list
try {
int pos = contextPosition - 1;
do {
int angle = scanner.findOpeningPeer(pos, bound, '<', '>');
if (angle == JavaHeuristicScanner.NOT_FOUND)
break;
int token = scanner.previousToken(angle - 1, bound);
// next token must be a method name that is a generic type
if (token == Symbols.TokenIDENT) {
int off = scanner.getPosition() + 1;
int end = angle;
String ident = document.get(off, end - off).trim();
if (JavaHeuristicScanner.isGenericStarter(ident))
return angle + 1;
}
pos = angle - 1;
} while (true);
} catch (BadLocationException x) {
}
return super.guessContextInformationPosition(context);
}
use of org.eclipse.jdt.internal.ui.text.JavaHeuristicScanner in project che by eclipse.
the class IndentUtil method indentLines.
/**
* Indents the line range specified by <code>lines</code> in
* <code>document</code>. The passed Java project may be
* <code>null</code>, it is used solely to obtain formatter preferences.
*
* @param document the document to be changed
* @param lines the line range to be indented
* @param project the Java project to get the formatter preferences from, or
* <code>null</code> if global preferences should be used
* @param result the result from a previous call to <code>indentLines</code>,
* in order to maintain comment line properties, or <code>null</code>.
* Note that the passed result may be changed by the call.
* @return an indent result that may be queried for changes and can be
* reused in subsequent indentation operations
* @throws BadLocationException if <code>lines</code> is not a valid line
* range on <code>document</code>
*/
public static IndentResult indentLines(IDocument document, ILineRange lines, IJavaProject project, IndentResult result) throws BadLocationException {
int numberOfLines = lines.getNumberOfLines();
if (numberOfLines < 1)
return new IndentResult(null);
result = reuseOrCreateToken(result, numberOfLines);
JavaHeuristicScanner scanner = new JavaHeuristicScanner(document);
JavaIndenter indenter = new JavaIndenter(document, scanner, project);
boolean changed = false;
int tabSize = CodeFormatterUtil.getTabWidth(project);
for (int line = lines.getStartLine(), last = line + numberOfLines, i = 0; line < last; line++) {
changed |= indentLine(document, line, indenter, scanner, result.commentLinesAtColumnZero, i++, tabSize);
}
result.hasChanged = changed;
return result;
}
use of org.eclipse.jdt.internal.ui.text.JavaHeuristicScanner in project che by eclipse.
the class IndentUtil method shiftLines.
/**
* Shifts the line range specified by <code>lines</code> in
* <code>document</code>. The amount that the lines get shifted
* are determined by the first line in the range, all subsequent
* lines are adjusted accordingly. The passed Java project may be
* <code>null</code>, it is used solely to obtain formatter
* preferences.
*
* @param document the document to be changed
* @param lines the line range to be shifted
* @param project the Java project to get the formatter preferences
* from, or <code>null</code> if global preferences should
* be used
* @param result the result from a previous call to
* <code>shiftLines</code>, in order to maintain comment
* line properties, or <code>null</code>. Note that the
* passed result may be changed by the call.
* @return an indent result that may be queried for changes and can
* be reused in subsequent indentation operations
* @throws BadLocationException if <code>lines</code> is not a
* valid line range on <code>document</code>
*/
public static IndentResult shiftLines(IDocument document, ILineRange lines, IJavaProject project, IndentResult result) throws BadLocationException {
int numberOfLines = lines.getNumberOfLines();
if (numberOfLines < 1)
return new IndentResult(null);
result = reuseOrCreateToken(result, numberOfLines);
result.hasChanged = false;
JavaHeuristicScanner scanner = new JavaHeuristicScanner(document);
JavaIndenter indenter = new JavaIndenter(document, scanner, project);
String current = getCurrentIndent(document, lines.getStartLine());
StringBuffer correct = indenter.computeIndentation(document.getLineOffset(lines.getStartLine()));
if (correct == null)
// bail out
return result;
int tabSize = CodeFormatterUtil.getTabWidth(project);
StringBuffer addition = new StringBuffer();
int difference = subtractIndent(correct, current, addition, tabSize);
if (difference == 0)
return result;
if (result.leftmostLine == -1)
result.leftmostLine = getLeftMostLine(document, lines, tabSize);
int maxReduction = computeVisualLength(getCurrentIndent(document, result.leftmostLine + lines.getStartLine()), tabSize);
if (difference > 0) {
for (int line = lines.getStartLine(), last = line + numberOfLines, i = 0; line < last; line++) addIndent(document, line, addition, result.commentLinesAtColumnZero, i++);
} else {
int reduction = Math.min(-difference, maxReduction);
for (int line = lines.getStartLine(), last = line + numberOfLines, i = 0; line < last; line++) cutIndent(document, line, reduction, tabSize, result.commentLinesAtColumnZero, i++);
}
result.hasChanged = true;
return result;
}
Aggregations