use of org.eclipse.jface.text.IDocument 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.jface.text.IDocument in project che by eclipse.
the class JavaContext method getKey.
/*
* @see org.eclipse.jdt.internal.corext.template.DocumentTemplateContext#getKey()
*/
@Override
public String getKey() {
if (getCompletionLength() == 0)
return super.getKey();
try {
IDocument document = getDocument();
int start = getStart();
int end = getCompletionOffset();
return start <= end ? document.get(start, end - start) : //$NON-NLS-1$
"";
} catch (BadLocationException e) {
return super.getKey();
}
}
use of org.eclipse.jface.text.IDocument in project che by eclipse.
the class JavaContext method getIndentation.
/**
* Returns the indentation level at the position of code completion.
*
* @return the indentation level at the position of the code completion
*/
private int getIndentation() {
int start = getStart();
IDocument document = getDocument();
try {
IRegion region = document.getLineInformationOfOffset(start);
String lineContent = document.get(region.getOffset(), region.getLength());
IJavaProject project = getJavaProject();
return Strings.computeIndentUnits(lineContent, project);
} catch (BadLocationException e) {
return 0;
}
}
use of org.eclipse.jface.text.IDocument in project che by eclipse.
the class JavaContext method getEnd.
/*
* @see org.eclipse.jdt.internal.corext.template.DocumentTemplateContext#getEnd()
*/
@Override
public int getEnd() {
if (fIsManaged || getCompletionLength() == 0)
return super.getEnd();
try {
IDocument document = getDocument();
int start = getCompletionOffset();
int end = getCompletionOffset() + getCompletionLength();
while (start != end && Character.isWhitespace(document.getChar(end - 1))) end--;
return end;
} catch (BadLocationException e) {
return super.getEnd();
}
}
use of org.eclipse.jface.text.IDocument in project che by eclipse.
the class JavaDocContext method getStart.
/*
* @see DocumentTemplateContext#getStart()
*/
@Override
public int getStart() {
if (fIsManaged && getCompletionLength() > 0)
return super.getStart();
try {
IDocument document = getDocument();
if (getCompletionLength() == 0) {
int start = getCompletionOffset();
if ((start != 0) && (document.getChar(start - 1) == HTML_TAG_END))
start--;
while ((start != 0) && Character.isUnicodeIdentifierPart(document.getChar(start - 1))) start--;
if ((start != 0) && Character.isUnicodeIdentifierStart(document.getChar(start - 1)))
start--;
// include html and javadoc tags
if ((start != 0) && ((document.getChar(start - 1) == HTML_TAG_BEGIN) || (document.getChar(start - 1) == JAVADOC_TAG_BEGIN))) {
start--;
}
return start;
}
int start = getCompletionOffset();
int end = getCompletionOffset() + getCompletionLength();
while (start != 0 && Character.isUnicodeIdentifierPart(document.getChar(start - 1))) start--;
while (start != end && Character.isWhitespace(document.getChar(start))) start++;
if (start == end)
start = getCompletionOffset();
return start;
} catch (BadLocationException e) {
return getCompletionOffset();
}
}
Aggregations