org.eclipse.jdt.ui.text.java.ContentAssistInvocationContext Java Examples

The following examples show how to use org.eclipse.jdt.ui.text.java.ContentAssistInvocationContext. 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: JavaCompletionProposalComputer1.java    From ContentAssist with MIT License 6 votes vote down vote up
public List<ICompletionProposal> computeCompletionProposals(ContentAssistInvocationContext context, IProgressMonitor monitor) {
    List<ICompletionProposal> propList = new ArrayList<ICompletionProposal>();
    List<ICompletionProposal> newpropList = new ArrayList<ICompletionProposal>();
    List<IContextInformation> propList2 = new ArrayList<IContextInformation>();

    ICompletionProposal first;
    DataManager datamanger = new DataManager(context,monitor);
    Activator.applyoperationlist.add(new ApplyOperation(ConsoleOperationListener2.ope.getStart(), ConsoleOperationListener2.ope.getAuthor(), ConsoleOperationListener2.ope.getFilePath(), propList));
    List<String> list = new ArrayList();
    CompletionProposal proposal;
    propList = datamanger.JavaDefaultProposal();
    propList2 = datamanger.ContextInformation();
    ApplyOperation ao = new ApplyOperation(ConsoleOperationListener2.ope.getStart(), ConsoleOperationListener2.ope.getAuthor(), ConsoleOperationListener2.ope.getFilePath(), propList);
    System.out.println(ao.toString());
    return newpropList;
}
 
Example #3
Source File: ContentAssistProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Collects the proposals.
 *
 * @param viewer the text viewer
 * @param offset the offset
 * @param monitor the progress monitor
 * @param context the code assist invocation context
 * @return the list of proposals
 */
private List<ICompletionProposal> collectProposals(ITextViewer viewer, int offset, IProgressMonitor monitor, ContentAssistInvocationContext context) {
	boolean needsSortingAfterFiltering= false;
	List<ICompletionProposal> proposals= new ArrayList<ICompletionProposal>();
	List<CompletionProposalCategory> providers= getCategories();
	for (CompletionProposalCategory cat : providers) {
		List<ICompletionProposal> computed= cat.computeCompletionProposals(context, fPartition, new SubProgressMonitor(monitor, 1));
		proposals.addAll(computed);
		needsSortingAfterFiltering= needsSortingAfterFiltering || (cat.isSortingAfterFilteringNeeded() && !computed.isEmpty());
		if (fErrorMessage == null)
			fErrorMessage= cat.getErrorMessage();
	}
	if (fNeedsSortingAfterFiltering && !needsSortingAfterFiltering)
		fAssistant.setSorter(null);
	fNeedsSortingAfterFiltering= needsSortingAfterFiltering;
	return proposals;
}
 
Example #4
Source File: HTMLTagCompletionProposalComputer.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
public List<ICompletionProposal> computeCompletionProposals(ContentAssistInvocationContext context, IProgressMonitor monitor) {
	if (!(context instanceof JavadocContentAssistInvocationContext))
		return Collections.emptyList();

	JavadocContentAssistInvocationContext docContext= (JavadocContentAssistInvocationContext) context;
	int flags= docContext.getFlags();
	fCurrentPos= docContext.getInvocationOffset();
	fCurrentLength= docContext.getSelectionLength();
	fRestrictToMatchingCase= (flags & IJavadocCompletionProcessor.RESTRICT_TO_MATCHING_CASE) != 0;

	ICompilationUnit cu= docContext.getCompilationUnit();
	if (cu == null)
		return Collections.emptyList();
	fDocument= docContext.getDocument();
	if (fDocument == null) {
		return Collections.emptyList();
	}

	try {
		fResult= new ArrayList<ICompletionProposal>(100);
		evalProposals();
		return fResult;
	} finally {
		fResult= null;
	}
}
 
Example #5
Source File: LegacyJavadocCompletionProposalComputer.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public List<ICompletionProposal> computeCompletionProposals(ContentAssistInvocationContext context, IProgressMonitor monitor) {
	if (context instanceof JavadocContentAssistInvocationContext) {
		JavadocContentAssistInvocationContext javaContext= (JavadocContentAssistInvocationContext) context;

		ICompilationUnit cu= javaContext.getCompilationUnit();
		int offset= javaContext.getInvocationOffset();
		int length= javaContext.getSelectionLength();
		Point selection= javaContext.getViewer().getSelectedRange();
		if (selection.y > 0) {
			offset= selection.x;
			length= selection.y;
		}

		ArrayList<ICompletionProposal> result= new ArrayList<ICompletionProposal>();

		IJavadocCompletionProcessor[] processors= getContributedProcessors();
		for (int i= 0; i < processors.length; i++) {
			IJavadocCompletionProcessor curr= processors[i];
			IJavaCompletionProposal[] proposals= curr.computeCompletionProposals(cu, offset, length, javaContext.getFlags());
			if (proposals != null) {
				for (int k= 0; k < proposals.length; k++) {
					result.add(proposals[k]);
				}
			}
		}
		return result;
	}
	return Collections.emptyList();
}
 
Example #6
Source File: CompletionProposalCategory.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Safely computes completion proposals of all computers of this category through their
 * extension. If an extension is disabled, throws an exception or otherwise does not adhere to
 * the contract described in {@link IJavaCompletionProposalComputer}, it is disabled.
 *
 * @param context the invocation context passed on to the extension
 * @param partition the partition type where to invocation occurred
 * @param monitor the progress monitor passed on to the extension
 * @return the list of computed completion proposals (element type:
 *         {@link org.eclipse.jface.text.contentassist.ICompletionProposal})
 */
public List<ICompletionProposal> computeCompletionProposals(ContentAssistInvocationContext context, String partition, SubProgressMonitor monitor) {
	fLastError= null;
	List<ICompletionProposal> result= new ArrayList<ICompletionProposal>();
	List<CompletionProposalComputerDescriptor> descriptors= new ArrayList<CompletionProposalComputerDescriptor>(fRegistry.getProposalComputerDescriptors(partition));
	for (CompletionProposalComputerDescriptor desc : descriptors) {
		if (desc.getCategory() == this)
			result.addAll(desc.computeCompletionProposals(context, monitor));
		if (fLastError == null && desc.getErrorMessage() != null)
			fLastError= desc.getErrorMessage();
	}
	return result;
}
 
Example #7
Source File: JavaCompletionProposalComputer.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public List<ICompletionProposal> computeCompletionProposals(ContentAssistInvocationContext context, IProgressMonitor monitor) {
	if (context instanceof JavaContentAssistInvocationContext) {
		JavaContentAssistInvocationContext javaContext= (JavaContentAssistInvocationContext) context;
		return internalComputeCompletionProposals(context.getInvocationOffset(), javaContext);
	}
	return Collections.emptyList();
}
 
Example #8
Source File: JavaCompletionProposalComputer.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public List<IContextInformation> computeContextInformation(ContentAssistInvocationContext context, IProgressMonitor monitor) {
	if (context instanceof JavaContentAssistInvocationContext) {
		JavaContentAssistInvocationContext javaContext= (JavaContentAssistInvocationContext) context;

		int contextInformationPosition= guessContextInformationPosition(javaContext);
		List<IContextInformation> result= addContextInformations(javaContext, contextInformationPosition);
		return result;
	}
	return Collections.emptyList();
}
 
Example #9
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 #10
Source File: CompletionProposalCategory.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Safely computes context information objects of all computers of this category through their
 * extension. If an extension is disabled, throws an exception or otherwise does not adhere to
 * the contract described in {@link IJavaCompletionProposalComputer}, it is disabled.
 *
 * @param context the invocation context passed on to the extension
 * @param partition the partition type where to invocation occurred
 * @param monitor the progress monitor passed on to the extension
 * @return the list of computed context information objects (element type:
 *         {@link org.eclipse.jface.text.contentassist.IContextInformation})
 */
public List<IContextInformation> computeContextInformation(ContentAssistInvocationContext context, String partition, SubProgressMonitor monitor) {
	fLastError= null;
	List<IContextInformation> result= new ArrayList<IContextInformation>();
	List<CompletionProposalComputerDescriptor> descriptors= new ArrayList<CompletionProposalComputerDescriptor>(fRegistry.getProposalComputerDescriptors(partition));
	for (CompletionProposalComputerDescriptor desc : descriptors) {
		if (desc.getCategory() == this && (isIncluded() || isSeparateCommand()))
			result.addAll(desc.computeContextInformation(context, monitor));
		if (fLastError == null)
			fLastError= desc.getErrorMessage();
	}
	return result;
}
 
Example #11
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 #12
Source File: LegacyJavadocCompletionProposalComputer.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public List<IContextInformation> computeContextInformation(ContentAssistInvocationContext context, IProgressMonitor monitor) {
	if (context instanceof JavaContentAssistInvocationContext) {
		JavaContentAssistInvocationContext javaContext= (JavaContentAssistInvocationContext) context;

		ICompilationUnit cu= javaContext.getCompilationUnit();
		int offset= javaContext.getInvocationOffset();

		ArrayList<IContextInformation> result= new ArrayList<IContextInformation>();

		IJavadocCompletionProcessor[] processors= getContributedProcessors();
		String error= null;
		for (int i= 0; i < processors.length; i++) {
			IJavadocCompletionProcessor curr= processors[i];
			IContextInformation[] contextInfos= curr.computeContextInformation(cu, offset);
			if (contextInfos != null) {
				for (int k= 0; k < contextInfos.length; k++) {
					result.add(contextInfos[k]);
				}
			} else if (error == null) {
				error= curr.getErrorMessage();
			}
		}
		fErrorMessage= error;
		return result;
	}
	return Collections.emptyList();
}
 
Example #13
Source File: ContentAssistProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private List<IContextInformation> collectContextInformation(ITextViewer viewer, int offset, IProgressMonitor monitor) {
	List<IContextInformation> proposals= new ArrayList<IContextInformation>();
	ContentAssistInvocationContext context= createContext(viewer, offset);

	List<CompletionProposalCategory> providers= getCategories();
	for (CompletionProposalCategory cat : providers) {
		List<IContextInformation> computed= cat.computeContextInformation(context, fPartition, new SubProgressMonitor(monitor, 1));
		proposals.addAll(computed);
		if (fErrorMessage == null)
			fErrorMessage= cat.getErrorMessage();
	}

	return proposals;
}
 
Example #14
Source File: ContentAssistProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public final ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int offset) {
	long start= DEBUG ? System.currentTimeMillis() : 0;

	clearState();

	IProgressMonitor monitor= createProgressMonitor();
	monitor.beginTask(JavaTextMessages.ContentAssistProcessor_computing_proposals, fCategories.size() + 1);

	ContentAssistInvocationContext context= createContext(viewer, offset);
	long setup= DEBUG ? System.currentTimeMillis() : 0;

	monitor.subTask(JavaTextMessages.ContentAssistProcessor_collecting_proposals);
	List<ICompletionProposal> proposals= collectProposals(viewer, offset, monitor, context);
	long collect= DEBUG ? System.currentTimeMillis() : 0;

	monitor.subTask(JavaTextMessages.ContentAssistProcessor_sorting_proposals);
	if (fNeedsSortingAfterFiltering)
		setContentAssistSorter();
	else
		proposals= sortProposals(proposals, monitor, context);
	fNumberOfComputedResults= proposals.size();
	long filter= DEBUG ? System.currentTimeMillis() : 0;

	ICompletionProposal[] result= proposals.toArray(new ICompletionProposal[proposals.size()]);
	monitor.done();

	if (DEBUG) {
		System.err.println("Code Assist Stats (" + result.length + " proposals)"); //$NON-NLS-1$ //$NON-NLS-2$
		System.err.println("Code Assist (setup):\t" + (setup - start) ); //$NON-NLS-1$
		System.err.println("Code Assist (collect):\t" + (collect - setup) ); //$NON-NLS-1$
		System.err.println("Code Assist (sort):\t" + (filter - collect) ); //$NON-NLS-1$
	}

	return result;
}
 
Example #15
Source File: ContractInputCompletionProposalComputer.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
protected List<ContractInput> getContractInputs(final ContentAssistInvocationContext context) {
    final ITextViewer viewer = context.getViewer();
    List<ContractInput> inputs = (List<ContractInput>) viewer.getTextWidget().getData(INPUTS);
    if (inputs == null) {
        inputs = new ArrayList<ContractInput>();
    }
    return inputs;
}
 
Example #16
Source File: ContractInputProposalsCodeVisitorSupport.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
protected List<ICompletionProposal> getInputProposals(final ContentAssistInvocationContext context, final List<ContractInput> inputs,
        final CharSequence computeIdentifierPrefix) {
    final List<ICompletionProposal> result = new ArrayList<ICompletionProposal>();
    for (final ContractInput input : inputs) {
        if (computeIdentifierPrefix.toString().isEmpty() || input.getName().startsWith(computeIdentifierPrefix.toString())) {
            result.add(createProposalFor(context, computeIdentifierPrefix, input));
        }
    }
    return result;
}
 
Example #17
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 #18
Source File: HTMLTagCompletionProposalComputer.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
public List<IContextInformation> computeContextInformation(ContentAssistInvocationContext context, IProgressMonitor monitor) {
	return Collections.emptyList();
}
 
Example #19
Source File: JavadocCompletionProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
@Override
protected ContentAssistInvocationContext createContext(ITextViewer viewer, int offset) {
	return new JavadocContentAssistInvocationContext(viewer, offset, fEditor, fSubProcessorFlags);
}
 
Example #20
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();
}
 
Example #21
Source File: WordCompletionProposalComputer.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
public List<IContextInformation> computeContextInformation(ContentAssistInvocationContext context, IProgressMonitor monitor) {
	return Collections.emptyList();
}
 
Example #22
Source File: ExtendedJavaCompletionProcessor.java    From bonita-studio with GNU General Public License v2.0 4 votes vote down vote up
@Override
protected ContentAssistInvocationContext createContext(final ITextViewer viewer, final int offset) {
    return new ExtendedJavaContentAssistInvocationContext(viewer, offset, fEditor);
}
 
Example #23
Source File: ContractInputCompletionProposalComputer.java    From bonita-studio with GNU General Public License v2.0 4 votes vote down vote up
@Override
public List<ICompletionProposal> computeCompletionProposals(final ContentAssistInvocationContext context,
        final IProgressMonitor monitor) {
    if (!(context instanceof JavaContentAssistInvocationContext)
            || context instanceof JavaContentAssistInvocationContext
                    && !(((JavaContentAssistInvocationContext) context)
                            .getCompilationUnit() instanceof GroovyCompilationUnit)) {
        return Collections.emptyList();
    }
    final List<ContractInput> inputs = getContractInputs(context);
    if (inputs.isEmpty()) {
        return Collections.emptyList();
    }
    final JavaContentAssistInvocationContext javaContext = (JavaContentAssistInvocationContext) context;
    GroovyCompilationUnit compilationUnit = (GroovyCompilationUnit) javaContext.getCompilationUnit();
    if (compilationUnit.getModuleNode() == null) {
        return Collections.emptyList();
    }
    final ContentAssistContext contentAssistContext = createContentAssistContext(
            compilationUnit,
            context.getInvocationOffset(), context.getDocument());
    if (contentAssistContext == null) {
        return Collections.emptyList();
    }
    CharSequence computeIdentifierPrefix = "";
    try {
        computeIdentifierPrefix = javaContext.computeIdentifierPrefix();
    } catch (final BadLocationException e) {
        BonitaStudioLog.error("Failed to compute identifier prefix in ContractConstraint expression editor", e,
                ContractPlugin.PLUGIN_ID);
        return Collections.emptyList();
    }
    final CodeVisitorSupportContext codeVisitorSupportContext = new CodeVisitorSupportContext(
            computeIdentifierPrefix.toString(),
            (JavaContentAssistInvocationContext) context,
            contentAssistContext,
            getProjectClassloader(compilationUnit),
            new GroovyCompletionProposalComputer(),
            createMethodProposalCreator(),
            compilationUnit.getModuleNode());
    final ContractInputProposalsCodeVisitorSupport codeVistor = new ContractInputProposalsCodeVisitorSupport(inputs,
            codeVisitorSupportContext,
            monitor);
    final ASTNode completionNode = contentAssistContext.getPerceivedCompletionNode();
    if (completionNode != null) {
        completionNode.visit(codeVistor);
    }
    final List<ICompletionProposal> proposals = codeVistor.getProposals();
    if (proposals == null || proposals.isEmpty()) {
        return super.computeCompletionProposals(context, monitor);
    }
    return proposals;
}
 
Example #24
Source File: HippieProposalComputer.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
public List<IContextInformation> computeContextInformation(ContentAssistInvocationContext context, IProgressMonitor monitor) {
	return Arrays.asList(fProcessor.computeContextInformation(context.getViewer(), context.getInvocationOffset()));
}
 
Example #25
Source File: HippieProposalComputer.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) {
	return Arrays.asList(fProcessor.computeCompletionProposals(context.getViewer(), context.getInvocationOffset()));
}
 
Example #26
Source File: JavaCompletionProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
@Override
protected ContentAssistInvocationContext createContext(ITextViewer viewer, int offset) {
	return new JavaContentAssistInvocationContext(viewer, offset, fEditor);
}
 
Example #27
Source File: JavaCompletionProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
@Override
protected List<ICompletionProposal> sortProposals(List<ICompletionProposal> proposals, IProgressMonitor monitor, ContentAssistInvocationContext context) {
	ProposalSorterRegistry.getDefault().getCurrentSorter().sortProposals(context, proposals);
	return proposals;
}
 
Example #28
Source File: JavaNoTypeCompletionProposalComputer.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
@Override
protected int guessContextInformationPosition(ContentAssistInvocationContext context) {
	return guessMethodContextInformationPosition(context);
}
 
Example #29
Source File: AbstractTemplateCompletionProposalComputer.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
public List<IContextInformation> computeContextInformation(ContentAssistInvocationContext context, IProgressMonitor monitor) {
	return Collections.emptyList();
}
 
Example #30
Source File: AbstractTemplateCompletionProposalComputer.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 (!(context instanceof JavaContentAssistInvocationContext))
		return Collections.emptyList();

	JavaContentAssistInvocationContext javaContext= (JavaContentAssistInvocationContext) context;
	ICompilationUnit unit= javaContext.getCompilationUnit();
	if (unit == null)
		return Collections.emptyList();

	fEngine= computeCompletionEngine(javaContext);
	if (fEngine == null)
		return Collections.emptyList();

	fEngine.reset();
	fEngine.complete(javaContext.getViewer(), javaContext.getInvocationOffset(), unit);

	TemplateProposal[] templateProposals= fEngine.getResults();
	List<ICompletionProposal> result= new ArrayList<ICompletionProposal>(Arrays.asList(templateProposals));

	IJavaCompletionProposal[] keyWordResults= javaContext.getKeywordProposals();
	if (keyWordResults.length == 0)
		return result;

	/* Update relevance of template proposals that match with a keyword
	 * give those templates slightly more relevance than the keyword to
	 * sort them first.
	 */
	for (int k= 0; k < templateProposals.length; k++) {
		TemplateProposal curr= templateProposals[k];
		String name= curr.getTemplate().getPattern();
		for (int i= 0; i < keyWordResults.length; i++) {
			String keyword= keyWordResults[i].getDisplayString();
			if (name.startsWith(keyword)) {
				String content= curr.getTemplate().getPattern();
				if (content.startsWith(keyword)) {
					curr.setRelevance(keyWordResults[i].getRelevance() + 1);
					break;
				}
			}
		}
	}
	return result;
}