List of usage examples for org.eclipse.jdt.core CompletionProposal METHOD_REF_WITH_CASTED_RECEIVER
int METHOD_REF_WITH_CASTED_RECEIVER
To view the source code for org.eclipse.jdt.core CompletionProposal METHOD_REF_WITH_CASTED_RECEIVER.
Click Source Link
From source file:edu.brown.cs.bubbles.bedrock.BedrockUtil.java
License:Open Source License
/********************************************************************************/ static void outputCompletion(CompletionProposal cp, IvyXmlWriter xw) { xw.begin("COMPLETION"); fieldValue(xw, "ACCESSIBILITY", cp.getAccessibility(), accessibility_types); if (cp.isConstructor()) xw.field("CONSTRUCTOR", true); xw.field("TEXT", cp.getCompletion()); xw.field("INDEX", cp.getCompletionLocation()); xw.field("DECLKEY", cp.getDeclarationKey()); switch (cp.getKind()) { case CompletionProposal.ANNOTATION_ATTRIBUTE_REF: case CompletionProposal.ANONYMOUS_CLASS_DECLARATION: case CompletionProposal.FIELD_IMPORT: case CompletionProposal.FIELD_REF: case CompletionProposal.FIELD_REF_WITH_CASTED_RECEIVER: case CompletionProposal.METHOD_IMPORT: case CompletionProposal.METHOD_REF: case CompletionProposal.METHOD_REF_WITH_CASTED_RECEIVER: case CompletionProposal.METHOD_DECLARATION: case CompletionProposal.POTENTIAL_METHOD_DECLARATION: xw.field("DECLSIGN", cp.getDeclarationSignature()); break;/*from w ww. j a va 2 s . co m*/ case CompletionProposal.PACKAGE_REF: case CompletionProposal.TYPE_IMPORT: case CompletionProposal.TYPE_REF: xw.field("DOTNAME", cp.getDeclarationSignature()); break; } fieldFlags(xw, "ACCESS", cp.getFlags(), access_flags); xw.field("FLAGS", cp.getFlags()); xw.field("KEY", cp.getKey()); xw.field("NAME", cp.getName()); xw.field("RELEVANCE", cp.getRelevance()); xw.field("REPLACE_START", cp.getReplaceStart()); xw.field("REPLACE_END", cp.getReplaceEnd()); xw.field("SIGNATURE", cp.getSignature()); xw.field("TOKEN_START", cp.getTokenStart()); xw.field("TOKEN_END", cp.getTokenEnd()); fieldValue(xw, "KIND", cp.getKind(), completion_types); if (cp instanceof ICompletionProposalExtension4) { ICompletionProposalExtension4 icp4 = (ICompletionProposalExtension4) cp; xw.field("AUTO", icp4.isAutoInsertable()); } if (CompletionFlags.isStaticImport(cp.getAdditionalFlags())) xw.field("STATICIMPORT", true); if (cp.getKind() == CompletionProposal.FIELD_REF_WITH_CASTED_RECEIVER || cp.getKind() == CompletionProposal.METHOD_REF_WITH_CASTED_RECEIVER) { xw.field("RECEIVER_SIGN", cp.getReceiverSignature()); xw.field("RECEIVER_START", cp.getReceiverStart()); xw.field("RECEIVER_END", cp.getReceiverEnd()); } xw.field("RCVR", cp.getReceiverSignature()); xw.cdataElement("DESCRIPTION", cp.toString()); CompletionProposal[] rq = cp.getRequiredProposals(); if (rq != null) { xw.begin("REQUIRED"); for (CompletionProposal xcp : rq) outputCompletion(xcp, xw); xw.end("REQUIRED"); } xw.end("COMPLETION"); }
From source file:org.eclipse.flux.jdt.services.CompletionProposalDescriptionProvider.java
License:Open Source License
/** * Creates a display label with styles for a given <code>CompletionProposal</code>. * * @param proposal the completion proposal to create the display label for * @return the display label for <code>proposal</code> * * @since 3.4//from www .j av a 2 s .c o m */ public StringBuilder createDescription(CompletionProposal proposal) { switch (proposal.getKind()) { case CompletionProposal.METHOD_NAME_REFERENCE: case CompletionProposal.METHOD_REF: case CompletionProposal.CONSTRUCTOR_INVOCATION: case CompletionProposal.METHOD_REF_WITH_CASTED_RECEIVER: case CompletionProposal.POTENTIAL_METHOD_DECLARATION: if (fContext != null && fContext.isInJavadoc()) return createJavadocMethodProposalLabel(proposal); return createMethodProposalLabel(proposal); case CompletionProposal.METHOD_DECLARATION: return createOverrideMethodProposalLabel(proposal); case CompletionProposal.ANONYMOUS_CLASS_DECLARATION: case CompletionProposal.ANONYMOUS_CLASS_CONSTRUCTOR_INVOCATION: return createAnonymousTypeLabel(proposal); case CompletionProposal.TYPE_REF: return createTypeProposalLabel(proposal); case CompletionProposal.JAVADOC_TYPE_REF: return createJavadocTypeProposalLabel(proposal); case CompletionProposal.JAVADOC_FIELD_REF: case CompletionProposal.JAVADOC_VALUE_REF: case CompletionProposal.JAVADOC_BLOCK_TAG: case CompletionProposal.JAVADOC_INLINE_TAG: case CompletionProposal.JAVADOC_PARAM_REF: return createJavadocSimpleProposalLabel(proposal); case CompletionProposal.JAVADOC_METHOD_REF: return createJavadocMethodProposalLabel(proposal); case CompletionProposal.PACKAGE_REF: return createPackageProposalLabel(proposal); case CompletionProposal.ANNOTATION_ATTRIBUTE_REF: case CompletionProposal.FIELD_REF: case CompletionProposal.FIELD_REF_WITH_CASTED_RECEIVER: return createLabelWithTypeAndDeclaration(proposal); case CompletionProposal.LOCAL_VARIABLE_REF: case CompletionProposal.VARIABLE_DECLARATION: return createSimpleLabelWithType(proposal); case CompletionProposal.KEYWORD: case CompletionProposal.LABEL_REF: return createSimpleLabel(proposal); default: Assert.isTrue(false); return null; } }
From source file:org.eclipse.flux.jdt.services.CompletionProposalReplacementProvider.java
License:Open Source License
private void appendMethodNameReplacement(StringBuilder buffer, CompletionProposal proposal) { if (proposal.getKind() == CompletionProposal.METHOD_REF_WITH_CASTED_RECEIVER) { String coreCompletion = String.valueOf(proposal.getCompletion()); // String lineDelimiter = TextUtilities.getDefaultLineDelimiter(getTextViewer().getDocument()); // String replacement= CodeFormatterUtil.format(CodeFormatter.K_EXPRESSION, coreCompletion, 0, lineDelimiter, fInvocationContext.getProject()); // buffer.append(replacement.substring(0, replacement.lastIndexOf('.') + 1)); buffer.append(coreCompletion);/*from w w w. ja v a 2 s .c o m*/ } if (proposal.getKind() != CompletionProposal.CONSTRUCTOR_INVOCATION) buffer.append(proposal.getName()); buffer.append(LPAREN); }
From source file:org.eclipse.objectteams.otdt.tests.model.CompletionTestsRequestor2.java
License:Open Source License
protected StringBuffer printProposal(CompletionProposal proposal, int tab, StringBuffer buffer) { for (int i = 0; i < tab; i++) { buffer.append(" "); //$NON-NLS-1$ }/*from w ww. java2s . co m*/ buffer.append(getElementName(proposal)); buffer.append('['); switch (proposal.getKind()) { case CompletionProposal.ANONYMOUS_CLASS_DECLARATION: buffer.append("ANONYMOUS_CLASS_DECLARATION"); //$NON-NLS-1$ break; case CompletionProposal.FIELD_REF: buffer.append("FIELD_REF"); //$NON-NLS-1$ break; case CompletionProposal.FIELD_REF_WITH_CASTED_RECEIVER: buffer.append("FIELD_REF_WITH_CASTED_RECEIVER"); //$NON-NLS-1$ break; case CompletionProposal.KEYWORD: buffer.append("KEYWORD"); //$NON-NLS-1$ break; case CompletionProposal.LABEL_REF: buffer.append("LABEL_REF"); //$NON-NLS-1$ break; case CompletionProposal.LOCAL_VARIABLE_REF: buffer.append("LOCAL_VARIABLE_REF"); //$NON-NLS-1$ break; case CompletionProposal.METHOD_DECLARATION: buffer.append("METHOD_DECLARATION"); //$NON-NLS-1$ if (proposal.isConstructor()) { buffer.append("<CONSTRUCTOR>"); //$NON-NLS-1$ } break; case CompletionProposal.METHOD_REF: buffer.append("METHOD_REF"); //$NON-NLS-1$ if (proposal.isConstructor()) { buffer.append("<CONSTRUCTOR>"); //$NON-NLS-1$ } break; case CompletionProposal.METHOD_REF_WITH_CASTED_RECEIVER: buffer.append("METHOD_REF_WITH_CASTED_RECEIVER"); //$NON-NLS-1$ if (proposal.isConstructor()) { buffer.append("<CONSTRUCTOR>"); //$NON-NLS-1$ } break; case CompletionProposal.PACKAGE_REF: buffer.append("PACKAGE_REF"); //$NON-NLS-1$ break; case CompletionProposal.TYPE_REF: buffer.append("TYPE_REF"); //$NON-NLS-1$ break; case CompletionProposal.VARIABLE_DECLARATION: buffer.append("VARIABLE_DECLARATION"); //$NON-NLS-1$ break; case CompletionProposal.POTENTIAL_METHOD_DECLARATION: buffer.append("POTENTIAL_METHOD_DECLARATION"); //$NON-NLS-1$ break; case CompletionProposal.METHOD_NAME_REFERENCE: //{ObjectTeams: original "METHOD_IMPORT" is now misleading (used for rhs short method spec, too) buffer.append("METHOD_NAME_REF"); //$NON-NLS-1$ // SH} break; //{ObjectTeams: new kinds: case CompletionProposal.OT_METHOD_SPEC: buffer.append("METHOD_SPEC"); //$NON-NLS-1$ break; case CompletionProposal.OT_FIELD_SPEC: buffer.append("FIELD_SPEC"); //$NON-NLS-1$ break; case CompletionProposal.OT_CALLOUT_GET: buffer.append("CALLOUT_GET"); //$NON-NLS-1$ break; case CompletionProposal.OT_CALLOUT_SET: buffer.append("CALLOUT_SET"); //$NON-NLS-1$ break; case CompletionProposal.OT_CALLOUT_DECLARATION: buffer.append("CALLOUT_DECLARATION"); //$NON-NLS-1$ break; case CompletionProposal.OT_CALLOUT_OVERRIDE_DECLARATION: buffer.append("CALLOUT_OVERRIDE_DECLARATION"); //$NON-NLS-1$ break; case CompletionProposal.OT_CALLIN_DECLARATION: buffer.append("CALLIN_DECLARATION"); //$NON-NLS-1$ break; // SH} case CompletionProposal.ANNOTATION_ATTRIBUTE_REF: buffer.append("ANNOTATION_ATTRIBUTE_REF"); //$NON-NLS-1$ break; case CompletionProposal.JAVADOC_BLOCK_TAG: buffer.append("JAVADOC_BLOCK_TAG"); //$NON-NLS-1$ break; case CompletionProposal.JAVADOC_INLINE_TAG: buffer.append("JAVADOC_INLINE_TAG"); //$NON-NLS-1$ break; case CompletionProposal.JAVADOC_FIELD_REF: buffer.append("JAVADOC_FIELD_REF"); //$NON-NLS-1$ break; case CompletionProposal.JAVADOC_METHOD_REF: buffer.append("JAVADOC_METHOD_REF"); //$NON-NLS-1$ break; case CompletionProposal.JAVADOC_TYPE_REF: buffer.append("JAVADOC_TYPE_REF"); //$NON-NLS-1$ break; case CompletionProposal.JAVADOC_PARAM_REF: buffer.append("JAVADOC_PARAM_REF"); //$NON-NLS-1$ break; case CompletionProposal.JAVADOC_VALUE_REF: buffer.append("JAVADOC_VALUE_REF"); //$NON-NLS-1$ break; case CompletionProposal.FIELD_IMPORT: buffer.append("FIELD_IMPORT"); //$NON-NLS-1$ break; case CompletionProposal.METHOD_IMPORT: buffer.append("METHOD_IMPORT"); //$NON-NLS-1$ break; case CompletionProposal.TYPE_IMPORT: buffer.append("TYPE_IMPORT"); //$NON-NLS-1$ break; default: buffer.append("PROPOSAL"); //$NON-NLS-1$ break; } buffer.append("]{"); buffer.append(proposal.getCompletion() == null ? NULL_LITERAL : proposal.getCompletion()); buffer.append(", "); buffer.append( proposal.getDeclarationSignature() == null ? NULL_LITERAL : proposal.getDeclarationSignature()); buffer.append(", "); buffer.append(proposal.getSignature() == null ? NULL_LITERAL : proposal.getSignature()); char[] receiverSignature = proposal.getReceiverSignature(); if (receiverSignature != null) { buffer.append(", "); buffer.append(receiverSignature); } if (this.showUniqueKeys) { buffer.append(", "); buffer.append(proposal.getDeclarationKey() == null ? NULL_LITERAL : proposal.getDeclarationKey()); buffer.append(", "); buffer.append(proposal.getKey() == null ? NULL_LITERAL : proposal.getKey()); } buffer.append(", "); buffer.append(proposal.getName() == null ? NULL_LITERAL : proposal.getName()); if (this.showParameterNames) { char[][] parameterNames = proposal.findParameterNames(null); buffer.append(", "); if (parameterNames == null || parameterNames.length <= 0) { buffer.append(NULL_LITERAL); } else { buffer.append("("); for (int i = 0; i < parameterNames.length; i++) { if (i > 0) buffer.append(", "); buffer.append(parameterNames[i]); } buffer.append(")"); } } if (this.showPositions) { buffer.append(", "); if (this.showTokenPositions || receiverSignature != null) buffer.append("replace"); buffer.append("["); buffer.append(proposal.getReplaceStart()); buffer.append(", "); buffer.append(proposal.getReplaceEnd()); buffer.append("]"); } if (this.showTokenPositions) { buffer.append(", token["); buffer.append(proposal.getTokenStart()); buffer.append(", "); buffer.append(proposal.getTokenEnd()); buffer.append("]"); } if (this.showPositions && receiverSignature != null) { buffer.append(", receiver["); buffer.append(proposal.getReceiverStart()); buffer.append(", "); buffer.append(proposal.getReceiverEnd()); buffer.append("]"); } buffer.append(", "); buffer.append(proposal.getRelevance()); buffer.append('}'); if (this.showMissingTypes) { CompletionProposal[] requiredProposals = proposal.getRequiredProposals(); if (requiredProposals != null) { int length = requiredProposals.length; System.arraycopy(requiredProposals, 0, requiredProposals = new CompletionProposal[length], 0, length); quickSort(requiredProposals, 0, length - 1); for (int i = 0; i < length; i++) { buffer.append('\n'); printProposal(requiredProposals[i], tab + 1, buffer); } } } return buffer; }
From source file:org.eclipse.objectteams.otdt.tests.model.CompletionTestsRequestor2.java
License:Open Source License
protected String getElementName(CompletionProposal proposal) { switch (proposal.getKind()) { case CompletionProposal.ANONYMOUS_CLASS_DECLARATION: return new String(Signature.getSignatureSimpleName(proposal.getDeclarationSignature())); case CompletionProposal.TYPE_REF: case CompletionProposal.TYPE_IMPORT: case CompletionProposal.JAVADOC_TYPE_REF: return new String(Signature.getSignatureSimpleName(proposal.getSignature())); case CompletionProposal.FIELD_REF: case CompletionProposal.FIELD_REF_WITH_CASTED_RECEIVER: case CompletionProposal.KEYWORD: case CompletionProposal.LABEL_REF: case CompletionProposal.LOCAL_VARIABLE_REF: case CompletionProposal.METHOD_REF: case CompletionProposal.METHOD_REF_WITH_CASTED_RECEIVER: case CompletionProposal.METHOD_DECLARATION: case CompletionProposal.VARIABLE_DECLARATION: case CompletionProposal.POTENTIAL_METHOD_DECLARATION: case CompletionProposal.METHOD_NAME_REFERENCE: //{ObjectTeams: new kinds: case CompletionProposal.OT_METHOD_SPEC: case CompletionProposal.OT_FIELD_SPEC: case CompletionProposal.OT_CALLOUT_GET: case CompletionProposal.OT_CALLOUT_SET: case CompletionProposal.OT_CALLOUT_DECLARATION: case CompletionProposal.OT_CALLOUT_OVERRIDE_DECLARATION: case CompletionProposal.OT_CALLIN_DECLARATION: // SH}//from ww w .j a v a2s . com case CompletionProposal.ANNOTATION_ATTRIBUTE_REF: case CompletionProposal.JAVADOC_BLOCK_TAG: case CompletionProposal.JAVADOC_INLINE_TAG: case CompletionProposal.JAVADOC_FIELD_REF: case CompletionProposal.JAVADOC_METHOD_REF: case CompletionProposal.JAVADOC_PARAM_REF: case CompletionProposal.JAVADOC_VALUE_REF: case CompletionProposal.FIELD_IMPORT: case CompletionProposal.METHOD_IMPORT: return new String(proposal.getName()); case CompletionProposal.PACKAGE_REF: return new String(proposal.getDeclarationSignature()); } return ""; }
From source file:org.eclipse.recommenders.calls.rcp.CallCompletionSessionProcessor.java
License:Open Source License
@Override public void process(final IProcessableProposal proposal) { if (isEmpty(recommendations)) { return;/*from w w w . j av a2s.c om*/ } final CompletionProposal coreProposal = proposal.getCoreProposal().or(NULL_PROPOSAL); switch (coreProposal.getKind()) { case CompletionProposal.METHOD_REF: case CompletionProposal.METHOD_REF_WITH_CASTED_RECEIVER: case CompletionProposal.METHOD_NAME_REFERENCE: final ProposalMatcher matcher = new ProposalMatcher(coreProposal); for (final Recommendation<IMethodName> call : recommendations) { final IMethodName crMethod = call.getProposal(); if (!matcher.match(crMethod)) { continue; } int percentage = (int) rint(call.getRelevance() * 100); int increment = 0; if (updateProposalRelevance) { increment = 200 + percentage; } String label = ""; if (decorateProposalText) { label = percentage + " %"; } if (updateProposalRelevance || decorateProposalText) { proposal.getProposalProcessorManager() .addProcessor(new SimpleProposalProcessor(increment, label)); } // we found the proposal we are looking for. So quit. break; } } }
From source file:org.eclipse.recommenders.completion.rcp.utils.ProposalUtils.java
License:Open Source License
private static boolean isKindSupported(CompletionProposal proposal) { switch (proposal.getKind()) { case CompletionProposal.METHOD_REF: return true; case CompletionProposal.METHOD_REF_WITH_CASTED_RECEIVER: return true; case CompletionProposal.METHOD_DECLARATION: return true; case CompletionProposal.CONSTRUCTOR_INVOCATION: return true; default:/*from ww w .j a v a 2 s . c o m*/ return false; } }
From source file:org.eclipse.recommenders.internal.calls.rcp.CallCompletionSessionProcessor.java
License:Open Source License
@Override public void process(final IProcessableProposal proposal) { final CompletionProposal coreProposal = proposal.getCoreProposal().or(NULL_PROPOSAL); switch (coreProposal.getKind()) { case CompletionProposal.METHOD_REF: case CompletionProposal.METHOD_REF_WITH_CASTED_RECEIVER: case CompletionProposal.METHOD_NAME_REFERENCE: IMethodName proposedMethod = methodNameProvider.toMethodName(coreProposal).orNull(); if (proposedMethod == null) { return; }/*from w w w. j a v a 2 s. co m*/ final ProposalMatcher matcher = new ProposalMatcher(proposedMethod); if (prefs.highlightUsedProposals && handleAlreadyUsedProposal(proposal, matcher)) { return; } handleRecommendation(proposal, matcher); } }
From source file:org.eclipse.recommenders.internal.subwords.rcp.SubwordsSessionProcessor.java
License:Open Source License
private String computeCompletionIdentifier(IJavaCompletionProposal javaProposal, CompletionProposal coreProposal) { String completionIdentifier;/*from w w w .j a v a2s.com*/ if (javaProposal instanceof LazyJavaCompletionProposal && coreProposal != null) { switch (coreProposal.getKind()) { case CompletionProposal.CONSTRUCTOR_INVOCATION: { // result: ClassSimpleName(Lsome/Param;I)V completionIdentifier = new StringBuilder().append(coreProposal.getName()).append(' ') .append(coreProposal.getSignature()).append(coreProposal.getDeclarationSignature()) .toString(); break; } case CompletionProposal.JAVADOC_TYPE_REF: { // result: ClassSimpleName fully.qualified.ClassSimpleName javadoc char[] signature = coreProposal.getSignature(); char[] simpleName = Signature.getSignatureSimpleName(signature); int indexOf = CharOperation.lastIndexOf('.', simpleName); simpleName = CharOperation.subarray(simpleName, indexOf + 1, simpleName.length); completionIdentifier = new StringBuilder().append(simpleName).append(' ').append(signature) .append(" javadoc").toString(); //$NON-NLS-1$ break; } case CompletionProposal.TYPE_REF: { // result: ClassSimpleName fully.qualified.ClassSimpleName char[] signature = coreProposal.getSignature(); char[] simpleName = Signature.getSignatureSimpleName(signature); int indexOf = CharOperation.lastIndexOf('.', simpleName); simpleName = CharOperation.subarray(simpleName, indexOf + 1, simpleName.length); completionIdentifier = new StringBuilder().append(simpleName).append(' ').append(signature) .toString(); break; } case CompletionProposal.PACKAGE_REF: // result: org.eclipse.my.package completionIdentifier = new String(coreProposal.getDeclarationSignature()); break; case CompletionProposal.METHOD_REF: case CompletionProposal.METHOD_REF_WITH_CASTED_RECEIVER: case CompletionProposal.METHOD_NAME_REFERENCE: { // result: myMethodName(Lsome/Param;I)V completionIdentifier = new StringBuilder().append(coreProposal.getName()).append(' ') .append(coreProposal.getSignature()).append(coreProposal.getDeclarationSignature()) .toString(); break; } case CompletionProposal.JAVADOC_METHOD_REF: { // result: myMethodName(Lsome/Param;I)V completionIdentifier = new StringBuilder().append(coreProposal.getName()).append(' ') .append(coreProposal.getSignature()).append(coreProposal.getDeclarationSignature()) .append(" javadoc").toString(); //$NON-NLS-1$ break; } case CompletionProposal.JAVADOC_PARAM_REF: case CompletionProposal.JAVADOC_BLOCK_TAG: case CompletionProposal.JAVADOC_INLINE_TAG: { completionIdentifier = javaProposal.getDisplayString(); break; } default: // result: display string. This should not happen. We should issue a warning here... completionIdentifier = javaProposal.getDisplayString(); Logs.log(ERROR_UNEXPECTED_FALL_THROUGH, coreProposal.getKind(), javaProposal.getClass()); break; } } else { completionIdentifier = javaProposal.getDisplayString(); } return completionIdentifier; }
From source file:org.eclipse.recommenders.internal.subwords.rcp.SubwordsSessionProcessor.java
License:Open Source License
@Override public void process(final IProcessableProposal proposal) { String completionIdentifier = computeCompletionIdentifier(proposal, proposal.getCoreProposal().orNull()); final String matchingArea = CompletionContexts.getPrefixMatchingArea(completionIdentifier); proposal.getProposalProcessorManager().addProcessor(new ProposalProcessor() { int[] bestSequence = EMPTY_SEQUENCE; String prefix;/*from w w w .j ava 2 s . c o m*/ @Override public boolean isPrefix(String prefix) { if (this.prefix != prefix) { this.prefix = prefix; CompletionProposal coreProposal = proposal.getCoreProposal().orNull(); if (coreProposal != null && (coreProposal .getKind() == CompletionProposal.FIELD_REF_WITH_CASTED_RECEIVER || coreProposal.getKind() == CompletionProposal.METHOD_REF_WITH_CASTED_RECEIVER)) { // This covers the case where the user starts with a prefix of "receiver.ge" and continues // typing 't' from there: In this case, prefix == "receiver.get" rather than "get". // I have only ever encountered this with proposal kinds of *_REF_WITH_CASTED_RECEIVER. int lastIndexOfDot = prefix.lastIndexOf('.'); bestSequence = LCSS.bestSubsequence(matchingArea, prefix.substring(lastIndexOfDot + 1)); } else { int lastIndexOfHash = prefix.lastIndexOf('#'); if (lastIndexOfHash >= 0) { // This covers the case where the user starts with a prefix of "Collections#" and continues // from there. bestSequence = LCSS.bestSubsequence(matchingArea, prefix.substring(lastIndexOfHash + 1)); } else { // Besides the obvious, this also covers the case where the user starts with a prefix of // "Collections#e", which manifests itself as just "e". bestSequence = LCSS.bestSubsequence(matchingArea, prefix); } } } return prefix.isEmpty() || bestSequence.length > 0; } @Override public void modifyDisplayString(StyledString displayString) { final int highlightAdjustment; CompletionProposal coreProposal = proposal.getCoreProposal().orNull(); if (coreProposal == null) { // HTML tag proposals are non-lazy(!) JavaCompletionProposals that don't have a core proposal. if (proposal instanceof JavaCompletionProposal && displayString.toString().startsWith("</")) { //$NON-NLS-1$ highlightAdjustment = 2; } else if (proposal instanceof JavaCompletionProposal && displayString.toString().startsWith("<")) { //$NON-NLS-1$ highlightAdjustment = 1; } else { highlightAdjustment = 0; } } else { switch (coreProposal.getKind()) { case CompletionProposal.JAVADOC_FIELD_REF: case CompletionProposal.JAVADOC_METHOD_REF: case CompletionProposal.JAVADOC_VALUE_REF: highlightAdjustment = displayString.toString().lastIndexOf('#') + 1; break; case CompletionProposal.JAVADOC_TYPE_REF: highlightAdjustment = JAVADOC_TYPE_REF_HIGHLIGHT_ADJUSTMENT; break; default: highlightAdjustment = 0; } } for (int index : bestSequence) { displayString.setStyle(index + highlightAdjustment, 1, StyledString.COUNTER_STYLER); } } /** * Since we may simulate completion triggers at positions before the actual triggering, we don't get JDT's * additional relevance for exact prefix matches. So we add the additional relevance ourselves, if is not * already supplied by the JDT which it does, if the prefix is shorter than the configured minimum prefix * length. * * The boost is the same one as JDT adds at * {@link org.eclipse.jdt.internal.codeassist.CompletionEngine#computeRelevanceForCaseMatching} * * The boost is further multiplied by 16 which reflects the same thing happening in * {@link org.eclipse.jdt.internal.ui.text.java.LazyJavaCompletionProposal#computeRelevance} */ @Override public int modifyRelevance() { if (ArrayUtils.isEmpty(bestSequence)) { proposal.setTag(IS_PREFIX_MATCH, true); return 0; } int relevanceBoost = 0; if (minPrefixLengthForTypes < prefix.length() && StringUtils.equalsIgnoreCase(matchingArea, prefix)) { relevanceBoost += 16 * RelevanceConstants.R_EXACT_NAME; proposal.setTag(IS_EXACT_MATCH, true); } // We only apply case matching to genuine Java proposals, i.e., proposals link HTML tags are ranked // together with the case in-sensitive matches. if (StringUtils.startsWith(matchingArea, prefix) && isFromJavaCompletionProposalComputer(proposal)) { proposal.setTag(SUBWORDS_SCORE, null); proposal.setTag(IS_PREFIX_MATCH, true); // Don't adjust relevance. } else if (startsWithIgnoreCase(matchingArea, prefix)) { proposal.setTag(SUBWORDS_SCORE, null); proposal.setTag(IS_CASE_INSENSITIVE_PREFIX_MATCH, true); relevanceBoost = IGNORE_CASE_RANGE_START + relevanceBoost; } else if (CharOperation.camelCaseMatch(prefix.toCharArray(), matchingArea.toCharArray()) && isFromJavaCompletionProposalComputer(proposal)) { proposal.setTag(IS_PREFIX_MATCH, false); proposal.setTag(IS_CAMEL_CASE_MATCH, true); relevanceBoost = CAMEL_CASE_RANGE_START + relevanceBoost; } else { int score = LCSS.scoreSubsequence(bestSequence); proposal.setTag(IS_PREFIX_MATCH, false); proposal.setTag(SUBWORDS_SCORE, score); relevanceBoost = SUBWORDS_RANGE_START + relevanceBoost + score; } return relevanceBoost; } /** * Some {@link IProcessableProposal}s are not produced by the {@link JavaCompletionProposalComputer}, but by * some other {@link IJavaCompletionProposalComputer}, e.g., the {@link HTMLTagCompletionProposalComputer}. * These proposals do not have a core proposal. */ private boolean isFromJavaCompletionProposalComputer(final IProcessableProposal proposal) { return proposal.getCoreProposal().isPresent(); } }); }