protected boolean isValidPrefix(String prefix) { if (super.isValidPrefix(prefix)) return true; String word= getDisplayString(); if (isInJavadoc()) { int idx = word.indexOf("{@link "); //$NON-NLS-1$ if (idx==0) { word = word.substring(7); } else { idx = word.indexOf("{@value "); //$NON-NLS-1$ if (idx==0) { word = word.substring(8); } } } return isPrefix(prefix, word); } }
/** * Returns <code>true</code> if the method being inserted has at least one parameter. Note * that this does not say anything about whether the argument list should be inserted. This * depends on the position in the document and the kind of proposal; see * {@link #hasArgumentList() }. * * @return <code>true</code> if the method has any parameters, <code>false</code> if it has * no parameters */ protected final boolean hasParameters() { if (!fHasParametersComputed) { fHasParametersComputed= true; fHasParameters= computeHasParameters(); } return fHasParameters; }
public CharSequence getPrefixCompletionText(IDocument document, int completionOffset) { if (hasArgumentList()) { String completion= String.valueOf(fProposal.getName()); if (isCamelCaseMatching()) { String prefix= getPrefix(document, completionOffset); return getCamelCaseCompound(prefix, completion); } return completion; } return super.getPrefixCompletionText(document, completionOffset); }
@Override public void apply(IDocument document, char trigger, int offset) { if (trigger == ' ' || trigger == '(') trigger= '\0'; super.apply(document, trigger, offset); if (needsLinkedMode()) { setUpLinkedMode(document, ')'); } else if (!fProposal.isConstructor() && getReplacementString().endsWith(";")) { //$NON-NLS-1$ setUpLinkedMode(document, ';'); } }
@Override protected String computeReplacementString() { if (!hasArgumentList()) return super.computeReplacementString(); appendMethodNameReplacement(buffer); FormatterPrefs prefs= getFormatterPrefs(); if (hasParameters()) { setCursorPosition(buffer.length()); if (canAutomaticallyAppendSemicolon()) buffer.append(SEMICOLON);
protected String computeReplacementString() { if (!hasArgumentList()) return super.computeReplacementString(); buffer.append(fProposal.getName()); FormatterPrefs prefs= getFormatterPrefs(); if (prefs.beforeOpeningParen) buffer.append(SPACE); buffer.append(LPAREN); if (hasParameters()) { setCursorPosition(buffer.length());
protected String computeReplacementString() { if (!hasParameters() || !hasArgumentList()) return super.computeReplacementString(); long millis= DEBUG ? System.currentTimeMillis() : 0; String replacement; try { replacement= computeGuessingCompletion(); } catch (JavaModelException x) { fPositions= null; fChoices= null; JavaPlugin.log(x); openErrorDialog(x); return super.computeReplacementString(); } if (DEBUG) System.err.println("Parameter Guessing: " + (System.currentTimeMillis() - millis)); //$NON-NLS-1$ return replacement; }
public void apply(IDocument document, char trigger, int offset) { super.apply(document, trigger, offset); int baseOffset= getReplacementOffset(); String replacement= getReplacementString();
@Override protected IContextInformation computeContextInformation() { // no context information for METHOD_NAME_REF proposals (e.g. for static imports) // https://bugs.eclipse.org/bugs/show_bug.cgi?id=94654 if ((fProposal.getKind() == CompletionProposal.METHOD_REF || fProposal.getKind() == CompletionProposal.CONSTRUCTOR_INVOCATION) && hasParameters() && (getReplacementString().endsWith(RPAREN) || getReplacementString().endsWith(SEMICOLON) || getReplacementString().length() == 0)) { ProposalContextInformation contextInformation= new ProposalContextInformation(fProposal); if (fContextInformationPosition != 0 && fProposal.getCompletion().length == 0) contextInformation.setContextInformationPosition(fContextInformationPosition); return contextInformation; } return super.computeContextInformation(); }
/** * Appends everything up to the method name including * the opening parenthesis. * <p> * In case of {@link CompletionProposal#METHOD_REF_WITH_CASTED_RECEIVER} * it add cast. * </p> * * @param buffer the string buffer * @since 3.4 */ protected void appendMethodNameReplacement(StringBuffer buffer) { if (fProposal.getKind() == CompletionProposal.METHOD_REF_WITH_CASTED_RECEIVER) { String coreCompletion= String.valueOf(fProposal.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)); } if (fProposal.getKind() != CompletionProposal.CONSTRUCTOR_INVOCATION) buffer.append(fProposal.getName()); FormatterPrefs prefs= getFormatterPrefs(); if (prefs.beforeOpeningParen) buffer.append(SPACE); buffer.append(LPAREN); }
@Override public boolean isPrefix(final String prefix, final String completion) { lastPrefix = prefix; if (mgr.prefixChanged(prefix)) { return true; } return super.isPrefix(prefix, completion); }
private IJavaCompletionProposal createMethodReferenceProposal(CompletionProposal methodProposal) { LazyJavaCompletionProposal proposal= new JavaMethodCompletionProposal(methodProposal, getInvocationContext()); adaptLength(proposal, methodProposal); return proposal; }
@Override protected String computeReplacementString() { if (!hasArgumentList()) return super.computeReplacementString(); appendMethodNameReplacement(buffer); FormatterPrefs prefs= getFormatterPrefs(); if (hasParameters()) { setCursorPosition(buffer.length()); if (canAutomaticallyAppendSemicolon()) buffer.append(SEMICOLON);
@Override protected String computeReplacementString() { if (!hasParameters() || !hasArgumentList()) return super.computeReplacementString(); long millis= JavaPlugin.DEBUG_RESULT_COLLECTOR ? System.currentTimeMillis() : 0; String replacement; try { replacement= computeGuessingCompletion(); } catch (JavaModelException x) { fPositions= null; fChoices= null; JavaPlugin.log(x); openErrorDialog(x); return super.computeReplacementString(); } if (JavaPlugin.DEBUG_RESULT_COLLECTOR) System.err.println("Parameter Guessing: " + (System.currentTimeMillis() - millis)); //$NON-NLS-1$ return replacement; }
@Override public void apply(IDocument document, char trigger, int offset) { super.apply(document, trigger, offset); int baseOffset= getReplacementOffset(); String replacement= getReplacementString();
@Override public void apply(IDocument document, char trigger, int offset) { if (trigger == ' ' || trigger == '(') trigger= '\0'; super.apply(document, trigger, offset); if (needsLinkedMode()) { setUpLinkedMode(document, ')'); } else if (!fProposal.isConstructor() && getReplacementString().endsWith(";")) { //$NON-NLS-1$ setUpLinkedMode(document, ';'); } }
@Override protected IContextInformation computeContextInformation() { // no context information for METHOD_NAME_REF proposals (e.g. for static imports) // https://bugs.eclipse.org/bugs/show_bug.cgi?id=94654 if ((fProposal.getKind() == CompletionProposal.METHOD_REF || fProposal.getKind() == CompletionProposal.CONSTRUCTOR_INVOCATION) && hasParameters() && (getReplacementString().endsWith(RPAREN) || getReplacementString().endsWith(SEMICOLON) || getReplacementString().length() == 0)) { ProposalContextInformation contextInformation= new ProposalContextInformation(fProposal); if (fContextInformationPosition != 0 && fProposal.getCompletion().length == 0) contextInformation.setContextInformationPosition(fContextInformationPosition); return contextInformation; } return super.computeContextInformation(); }
/** * Appends everything up to the method name including * the opening parenthesis. * <p> * In case of {@link CompletionProposal#METHOD_REF_WITH_CASTED_RECEIVER} * it add cast. * </p> * * @param buffer the string buffer * @since 3.4 */ protected void appendMethodNameReplacement(StringBuffer buffer) { if (fProposal.getKind() == CompletionProposal.METHOD_REF_WITH_CASTED_RECEIVER) { String coreCompletion= String.valueOf(fProposal.getCompletion()); String lineDelimiter= TextUtilities.getDefaultLineDelimiter(getTextViewer().getDocument()); String replacement= CodeFormatterUtil.format(CodeFormatter.K_EXPRESSION, coreCompletion, 0, lineDelimiter, FormatterProfileManager.getProjectSettings(fInvocationContext.getProject())); buffer.append(replacement.substring(0, replacement.lastIndexOf('.') + 1)); } if (fProposal.getKind() != CompletionProposal.CONSTRUCTOR_INVOCATION) buffer.append(fProposal.getName()); FormatterPrefs prefs= getFormatterPrefs(); if (prefs.beforeOpeningParen) buffer.append(SPACE); buffer.append(LPAREN); }
@Override public boolean isPrefix(final String prefix, final String completion) { lastPrefix = prefix; if (mgr.prefixChanged(prefix)) { return true; } return super.isPrefix(prefix, completion); }
private IJavaCompletionProposal createMethodReferenceProposal(CompletionProposal methodProposal) { LazyJavaCompletionProposal proposal= new JavaMethodCompletionProposal(methodProposal, getInvocationContext()); adaptLength(proposal, methodProposal); return proposal; }