Java Code Examples for org.eclipse.jdt.ui.text.java.ContentAssistInvocationContext#getInvocationOffset()

The following examples show how to use org.eclipse.jdt.ui.text.java.ContentAssistInvocationContext#getInvocationOffset() . 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: JavaCompletionProposalComputer.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
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);
		// next token must be a method name (identifier) or the closing angle of a
		// constructor call of a parameterized type.
		if (token == Symbols.TokenIDENT || token == Symbols.TokenGREATERTHAN)
			return paren + 1;
		pos= paren - 1;
	} while (true);

	return contextPosition;
}
 
Example 2
Source File: JavaAllCompletionProposalComputer.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected int guessContextInformationPosition(ContentAssistInvocationContext context) {
	int invocationOffset= context.getInvocationOffset();
	int typeContext= super.guessContextInformationPosition(context);
	int methodContext= guessMethodContextInformationPosition(context);
	if (typeContext != invocationOffset && typeContext > methodContext)
		return typeContext;
	else if (methodContext != invocationOffset)
		return methodContext;
	else
		return invocationOffset;
}
 
Example 3
Source File: JavaTypeCompletionProposalComputer.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@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);
}
 
Example 4
Source File: JavaCompletionProposalComputer.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
protected int guessContextInformationPosition(ContentAssistInvocationContext context) {
	return context.getInvocationOffset();
}
 
Example 5
Source File: WordCompletionProposalComputer.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
public List<ICompletionProposal> computeCompletionProposals(ContentAssistInvocationContext context, IProgressMonitor monitor) {
	if (contributes()) {
		try {
			IDocument document= context.getDocument();
			final int offset= context.getInvocationOffset();

			final IRegion region= document.getLineInformationOfOffset(offset);
			final String content= document.get(region.getOffset(), region.getLength());

			int index= offset - region.getOffset() - 1;
			while (index >= 0 && Character.isLetter(content.charAt(index)))
				index--;

			final int start= region.getOffset() + index + 1;
			final String candidate= content.substring(index + 1, offset - region.getOffset());

			if (candidate.length() > 0) {

				final ISpellCheckEngine engine= SpellCheckEngine.getInstance();
				final ISpellChecker checker= engine.getSpellChecker();

				if (checker != null) {

					final List<RankedWordProposal> proposals= new ArrayList<RankedWordProposal>(checker.getProposals(candidate, Character.isUpperCase(candidate.charAt(0))));
					final List<ICompletionProposal> result= new ArrayList<ICompletionProposal>(proposals.size());

					for (Iterator<RankedWordProposal> it= proposals.iterator(); it.hasNext();) {
						RankedWordProposal word= it.next();
						String text= word.getText();
						if (text.startsWith(candidate))
							word.setRank(word.getRank() + PREFIX_RANK_SHIFT);

						result.add(new JavaCompletionProposal(text, start, candidate.length(), JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_RENAME), text, word.getRank()) {
							/*
							 * @see org.eclipse.jdt.internal.ui.text.java.JavaCompletionProposal#validate(org.eclipse.jface.text.IDocument, int, org.eclipse.jface.text.DocumentEvent)
							 */
							@Override
							public boolean validate(IDocument doc, int validate_offset, DocumentEvent event) {
								return offset == validate_offset;
							}
						});
					}

					return result;
				}
			}
		} catch (BadLocationException exception) {
			// log & ignore
			JavaPlugin.log(exception);
		}
	}
	return Collections.emptyList();
}