Java Code Examples for org.eclipse.jdt.core.CompletionProposal#getRelevance()
The following examples show how to use
org.eclipse.jdt.core.CompletionProposal#getRelevance() .
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: CompletionProposalRequestor.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 6 votes |
@Override public int compare(CompletionProposal p1, CompletionProposal p2) { int res = p2.getRelevance() - p1.getRelevance(); if (res == 0) { res = p1.getKind() - p2.getKind(); } if (res == 0) { char[] completion1 = getCompletion(p1); char[] completion2 = getCompletion(p2); int p1Length = completion1.length; int p2Length = completion2.length; for (int i = 0; i < p1Length; i++) { if (i >= p2Length) { return -1; } res = Character.compare(completion1[i], completion2[i]); if (res != 0) { return res; } } res = p2Length - p1Length; } return res; }
Example 2
Source File: CompletionProposalRequestor.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 6 votes |
private void acceptPotentialMethodDeclaration(CompletionProposal proposal) { try { IJavaElement enclosingElement = null; if (response.getContext().isExtended()) { enclosingElement = response.getContext().getEnclosingElement(); } else if (unit != null) { // kept for backward compatibility: CU is not reconciled at this moment, information is missing (bug 70005) enclosingElement = unit.getElementAt(proposal.getCompletionLocation() + 1); } if (enclosingElement == null) { return; } IType type = (IType) enclosingElement.getAncestor(IJavaElement.TYPE); if (type != null) { String prefix = String.valueOf(proposal.getName()); int completionStart = proposal.getReplaceStart(); int completionEnd = proposal.getReplaceEnd(); int relevance = proposal.getRelevance() + 6; GetterSetterCompletionProposal.evaluateProposals(type, prefix, completionStart, completionEnd - completionStart, relevance, proposals); } } catch (CoreException e) { JavaLanguageServerPlugin.logException("Accept potential method declaration failed for completion ", e); } }
Example 3
Source File: CompletionProposalRequestor.java From java-debug with Eclipse Public License 1.0 | 5 votes |
private void acceptPotentialMethodDeclaration(CompletionProposal proposal) { try { IJavaElement enclosingElement = null; if (response.getContext().isExtended()) { enclosingElement = response.getContext().getEnclosingElement(); } else if (typeRoot != null) { // kept for backward compatibility: CU is not reconciled at this moment, // information is missing (bug 70005) enclosingElement = typeRoot.getElementAt(proposal.getCompletionLocation() + 1); } if (enclosingElement == null) { return; } IType type = (IType) enclosingElement.getAncestor(IJavaElement.TYPE); if (type != null) { String prefix = String.valueOf(proposal.getName()); int completionStart = proposal.getReplaceStart(); int completionEnd = proposal.getReplaceEnd(); int relevance = proposal.getRelevance() + 6; GetterSetterCompletionProposal.evaluateProposals(type, prefix, completionStart, completionEnd - completionStart, relevance, proposals); } } catch (CoreException e) { JavaLanguageServerPlugin.logException("Accept potential method declaration failed for completion ", e); } }
Example 4
Source File: SortTextHelper.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
/** * Computes the relevance for a given <code>CompletionProposal</code>. * * @param proposal the proposal to compute the relevance for * @return the relevance for <code>proposal</code> */ public static String computeSortText(CompletionProposal proposal) { final int baseRelevance= proposal.getRelevance() * 16; switch (proposal.getKind()) { case CompletionProposal.LABEL_REF: return convertRelevance( baseRelevance + 1); case CompletionProposal.KEYWORD: return convertRelevance(baseRelevance + 2); case CompletionProposal.TYPE_REF: case CompletionProposal.ANONYMOUS_CLASS_DECLARATION: case CompletionProposal.ANONYMOUS_CLASS_CONSTRUCTOR_INVOCATION: return convertRelevance(baseRelevance + 3); case CompletionProposal.METHOD_REF: case CompletionProposal.CONSTRUCTOR_INVOCATION: case CompletionProposal.METHOD_NAME_REFERENCE: case CompletionProposal.METHOD_DECLARATION: case CompletionProposal.ANNOTATION_ATTRIBUTE_REF: case CompletionProposal.POTENTIAL_METHOD_DECLARATION: return convertRelevance(baseRelevance + 4); case CompletionProposal.FIELD_REF: return convertRelevance(baseRelevance + 5); case CompletionProposal.LOCAL_VARIABLE_REF: case CompletionProposal.VARIABLE_DECLARATION: return convertRelevance(baseRelevance + 6); case CompletionProposal.PACKAGE_REF://intentional fall-through default: return convertRelevance(baseRelevance); } }
Example 5
Source File: CompletionProposalCollector.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
/** * Computes the relevance for a given <code>CompletionProposal</code>. * <p> * Subclasses may replace, but usually should not need to. * </p> * @param proposal the proposal to compute the relevance for * @return the relevance for <code>proposal</code> */ protected int computeRelevance(CompletionProposal proposal) { final int baseRelevance= proposal.getRelevance() * 16; switch (proposal.getKind()) { case CompletionProposal.PACKAGE_REF: return baseRelevance + 0; case CompletionProposal.LABEL_REF: return baseRelevance + 1; case CompletionProposal.KEYWORD: return baseRelevance + 2; case CompletionProposal.TYPE_REF: case CompletionProposal.ANONYMOUS_CLASS_DECLARATION: case CompletionProposal.ANONYMOUS_CLASS_CONSTRUCTOR_INVOCATION: return baseRelevance + 3; case CompletionProposal.METHOD_REF: case CompletionProposal.CONSTRUCTOR_INVOCATION: case CompletionProposal.METHOD_NAME_REFERENCE: case CompletionProposal.METHOD_DECLARATION: case CompletionProposal.ANNOTATION_ATTRIBUTE_REF: return baseRelevance + 4; case CompletionProposal.POTENTIAL_METHOD_DECLARATION: return baseRelevance + 4 /* + 99 */; case CompletionProposal.FIELD_REF: return baseRelevance + 5; case CompletionProposal.LOCAL_VARIABLE_REF: case CompletionProposal.VARIABLE_DECLARATION: return baseRelevance + 6; default: return baseRelevance; } }