Java Code Examples for org.eclipse.jdt.core.CompletionProposal#getCompletion()
The following examples show how to use
org.eclipse.jdt.core.CompletionProposal#getCompletion() .
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: CompletionProposalReplacementProvider.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 6 votes |
/** * @param completionBuffer * @param proposal */ private void appendMethodOverrideReplacement(StringBuilder completionBuffer, CompletionProposal proposal) { IDocument document; try { document = JsonRpcHelpers.toDocument(this.compilationUnit.getBuffer()); String signature = String.valueOf(proposal.getSignature()); String[] types = Stream.of(Signature.getParameterTypes(signature)).map(t -> Signature.toString(t)) .toArray(String[]::new); String methodName = String.valueOf(proposal.getName()); int offset = proposal.getReplaceStart(); String completion = new String(proposal.getCompletion()); OverrideCompletionProposal overrider = new OverrideCompletionProposal(compilationUnit, methodName, types, completion); String replacement = overrider.updateReplacementString(document, offset, importRewrite, client.isCompletionSnippetsSupported()); completionBuffer.append(replacement); } catch (BadLocationException | CoreException e) { JavaLanguageServerPlugin.logException("Failed to compute override replacement", e); } }
Example 2
Source File: ProposalGeneratingCompletionRequestor.java From gwt-eclipse-plugin with Eclipse Public License 1.0 | 6 votes |
protected ICompletionProposal createProposal(CompletionProposal javaProposal) { String completion = String.valueOf(javaProposal.getCompletion()); int kind = javaProposal.getKind(); if (kind == CompletionProposal.TYPE_REF) { // Make sure it is fully qualified completion = JavaContentAssistUtilities.getFullyQualifiedTypeName(javaProposal); } if (forceFullyQualifiedFieldNames && (kind == CompletionProposal.FIELD_IMPORT || kind == CompletionProposal.FIELD_REF)) { char[] decSig = javaProposal.getDeclarationSignature(); if (decSig != null && decSig.length > 2) { // declaration signatures for objects are like Ljava.lang.String;, so lop off first // and last chars completion = new String(decSig, 1, decSig.length - 2) + "." + new String(javaProposal.getCompletion()); completion = completion.replace('$', '.'); } } ICompletionProposal jdtCompletionProposal = JavaContentAssistUtilities.getJavaCompletionProposal( javaProposal, context, javaProject); return ReplacementCompletionProposal.fromExistingCompletionProposal(completion, replaceOffset, replaceLength, jdtCompletionProposal); }
Example 3
Source File: ProposalContextInformation.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
/** * Creates a new context information. * * @param proposal the JDT Core completion proposal */ public ProposalContextInformation(CompletionProposal proposal) { // don't cache the core proposal because the ContentAssistant might // hang on to the context info. CompletionProposalLabelProvider labelProvider= new CompletionProposalLabelProvider(); fInformationDisplayString= labelProvider.createParameterList(proposal); ImageDescriptor descriptor= labelProvider.createImageDescriptor(proposal); if (descriptor != null) fImage= JavaPlugin.getImageDescriptorRegistry().get(descriptor); else fImage= null; if (proposal.getCompletion().length == 0) fPosition= proposal.getCompletionLocation() + 1; else fPosition= -1; fContextDisplayString= labelProvider.createLabel(proposal); }
Example 4
Source File: FillArgumentNamesCompletionProposalCollector.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
IJavaCompletionProposal createTypeProposal(CompletionProposal typeProposal) { final ICompilationUnit cu= getCompilationUnit(); if (cu == null || getContext() != null && getContext().isInJavadoc()) return super.createJavaCompletionProposal(typeProposal); IJavaProject project= cu.getJavaProject(); if (!shouldProposeGenerics(project)) return super.createJavaCompletionProposal(typeProposal); char[] completion= typeProposal.getCompletion(); // don't add parameters for import-completions nor for proposals with an empty completion (e.g. inside the type argument list) if (completion.length > 0 && (completion[completion.length - 1] == ';' || completion[completion.length - 1] == '.')) return super.createJavaCompletionProposal(typeProposal); LazyJavaCompletionProposal newProposal= new LazyGenericTypeProposal(typeProposal, getInvocationContext()); return newProposal; }
Example 5
Source File: AnonymousTypeCompletionProposal.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
protected IContextInformation computeContextInformation() { try { fContextInformationPosition= getReplacementOffset() - 1; CompletionProposal proposal= ((MemberProposalInfo)getProposalInfo()).fProposal; // no context information for METHOD_NAME_REF proposals (e.g. for static imports) // https://bugs.eclipse.org/bugs/show_bug.cgi?id=94654 if (hasParameters() && (getReplacementString().endsWith(")") || getReplacementString().length() == 0)) { //$NON-NLS-1$ ProposalContextInformation contextInformation= new ProposalContextInformation(proposal); fContextInformationPosition= getReplacementOffset() + getCursorPosition(); if (fContextInformationPosition != 0 && proposal.getCompletion().length == 0) contextInformation.setContextInformationPosition(fContextInformationPosition); return contextInformation; } return null; } finally { fIsContextInformationComputed= true; } }
Example 6
Source File: CompletionProposalDescriptionProvider.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
private void createLabelWithTypeAndDeclaration(CompletionProposal proposal, CompletionItem item) { char[] name= proposal.getCompletion(); if (!isThisPrefix(name)) { name= proposal.getName(); } StringBuilder buf= new StringBuilder(); buf.append(name); item.setInsertText(buf.toString()); char[] typeName= Signature.getSignatureSimpleName(proposal.getSignature()); if (typeName.length > 0) { buf.append(VAR_TYPE_SEPARATOR); buf.append(typeName); } item.setLabel(buf.toString()); char[] declaration= proposal.getDeclarationSignature(); StringBuilder detailBuf = new StringBuilder(); if (declaration != null) { setDeclarationSignature(item, String.valueOf(declaration)); declaration= Signature.getSignatureSimpleName(declaration); if (declaration.length > 0) { if (proposal.getRequiredProposals() != null) { String declaringType= extractDeclaringTypeFQN(proposal); String qualifier= Signature.getQualifier(declaringType); if (qualifier.length() > 0) { detailBuf.append(qualifier); detailBuf.append('.'); } } detailBuf.append(declaration); } } if (detailBuf.length() > 0) { detailBuf.append('.'); } detailBuf.append(buf); item.setDetail(detailBuf.toString()); setName(item,String.valueOf(name)); }
Example 7
Source File: CompletionProposalReplacementProvider.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
protected boolean hasArgumentList(CompletionProposal proposal) { if (CompletionProposal.METHOD_NAME_REFERENCE == proposal.getKind()) { return false; } char[] completion= proposal.getCompletion(); return !isInJavadoc() && completion.length > 0 && completion[completion.length - 1] == RPAREN; }
Example 8
Source File: CompletionProposalReplacementProvider.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
private boolean isImportCompletion(CompletionProposal proposal) { char[] completion = proposal.getCompletion(); if (completion.length == 0) { return false; } char last = completion[completion.length - 1]; /* * Proposals end in a semicolon when completing types in normal imports * or when completing static members, in a period when completing types * in static imports. */ return last == SEMICOLON || last == '.'; }
Example 9
Source File: CompletionProposalLabelProvider.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
StyledString createLabelWithTypeAndDeclaration(CompletionProposal proposal) { char[] name= proposal.getCompletion(); if (!isThisPrefix(name)) name= proposal.getName(); StyledString buf= new StyledString(); buf.append(name); char[] typeName= Signature.getSignatureSimpleName(proposal.getSignature()); if (typeName.length > 0) { buf.append(VAR_TYPE_SEPARATOR); buf.append(typeName); } char[] declaration= proposal.getDeclarationSignature(); if (declaration != null) { declaration= Signature.getSignatureSimpleName(declaration); if (declaration.length > 0) { buf.append(QUALIFIER_SEPARATOR, StyledString.QUALIFIER_STYLER); if (proposal.getRequiredProposals() != null) { String declaringType= extractDeclaringTypeFQN(proposal); String qualifier= Signature.getQualifier(declaringType); if (qualifier.length() > 0) { buf.append(qualifier, StyledString.QUALIFIER_STYLER); buf.append('.', StyledString.QUALIFIER_STYLER); } } buf.append(declaration, StyledString.QUALIFIER_STYLER); } } return Strings.markJavaElementLabelLTR(buf); }
Example 10
Source File: CompletionProposalReplacementProvider.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 4 votes |
private boolean shouldAppendArguments(CompletionProposal proposal, char trigger) { /* * No argument list if there were any special triggers (for example a * period to qualify an inner type). */ if (trigger != '\0' && trigger != '<' && trigger != LPAREN) { return false; } /* * No argument list if the completion is empty (already within the * argument list). */ char[] completion = proposal.getCompletion(); if (completion.length == 0) { return false; } /* * No argument list if there already is a generic signature behind the * name. */ try { IDocument document = JsonRpcHelpers.toDocument(this.compilationUnit.getBuffer()); IRegion region= document.getLineInformationOfOffset(proposal.getReplaceEnd()); String line= document.get(region.getOffset(),region.getLength()); int index= proposal.getReplaceEnd() - region.getOffset(); while (index != line.length() && Character.isUnicodeIdentifierPart(line.charAt(index))) { ++index; } if (index == line.length()) { return true; } char ch= line.charAt(index); return ch != '<'; } catch (BadLocationException | JavaModelException e) { return true; } }