Search in sources :

Example 1 with Signature

use of org.eclipse.jdt.core.Signature in project eclipse.jdt.ls by eclipse.

the class CompletionProposalReplacementProvider method appendMethodOverrideReplacement.

/**
 * @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());
        if (replacement != null) {
            completionBuffer.append(replacement);
        }
    } catch (BadLocationException | CoreException e) {
        JavaLanguageServerPlugin.logException("Failed to compute override replacement", e);
    }
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) JsonRpcHelpers(org.eclipse.jdt.ls.core.internal.handlers.JsonRpcHelpers) Signature(org.eclipse.jdt.core.Signature) SignatureUtil(org.eclipse.jdt.internal.corext.template.java.SignatureUtil) JavaModelException(org.eclipse.jdt.core.JavaModelException) HashMap(java.util.HashMap) CoreException(org.eclipse.core.runtime.CoreException) Range(org.eclipse.lsp4j.Range) ArrayList(java.util.ArrayList) ASTRequestor(org.eclipse.jdt.core.dom.ASTRequestor) CompletionContext(org.eclipse.jdt.core.CompletionContext) IDocument(org.eclipse.jface.text.IDocument) IBuffer(org.eclipse.jdt.core.IBuffer) ClientPreferences(org.eclipse.jdt.ls.core.internal.preferences.ClientPreferences) Map(java.util.Map) IASTSharedValues(org.eclipse.jdt.internal.corext.dom.IASTSharedValues) Either(org.eclipse.lsp4j.jsonrpc.messages.Either) BadLocationException(org.eclipse.jface.text.BadLocationException) CompletionUtils(org.eclipse.jdt.ls.core.internal.CompletionUtils) IRegion(org.eclipse.jface.text.IRegion) JDTUtils(org.eclipse.jdt.ls.core.internal.JDTUtils) InsertTextFormat(org.eclipse.lsp4j.InsertTextFormat) IJavaProject(org.eclipse.jdt.core.IJavaProject) JavaCore(org.eclipse.jdt.core.JavaCore) ImportRewrite(org.eclipse.jdt.core.dom.rewrite.ImportRewrite) Assert(org.eclipse.core.runtime.Assert) JavaLanguageServerPlugin(org.eclipse.jdt.ls.core.internal.JavaLanguageServerPlugin) TextEdit(org.eclipse.text.edits.TextEdit) IBinding(org.eclipse.jdt.core.dom.IBinding) CompletionEngine(org.eclipse.jdt.internal.codeassist.CompletionEngine) TextEditConverter(org.eclipse.jdt.ls.core.internal.TextEditConverter) CharOperation(org.eclipse.jdt.core.compiler.CharOperation) ITypeBinding(org.eclipse.jdt.core.dom.ITypeBinding) CompletionProposal(org.eclipse.jdt.core.CompletionProposal) IType(org.eclipse.jdt.core.IType) CompletionItem(org.eclipse.lsp4j.CompletionItem) List(java.util.List) Stream(java.util.stream.Stream) IJavaElement(org.eclipse.jdt.core.IJavaElement) ASTParser(org.eclipse.jdt.core.dom.ASTParser) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) Preferences(org.eclipse.jdt.ls.core.internal.preferences.Preferences) ChangeUtil(org.eclipse.jdt.ls.core.internal.ChangeUtil) TypeProposalUtils.isImplicitImport(org.eclipse.jdt.ls.core.internal.contentassist.TypeProposalUtils.isImplicitImport) ITypeParameter(org.eclipse.jdt.core.ITypeParameter) CoreException(org.eclipse.core.runtime.CoreException) IDocument(org.eclipse.jface.text.IDocument) BadLocationException(org.eclipse.jface.text.BadLocationException)

Aggregations

ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Stream (java.util.stream.Stream)1 Assert (org.eclipse.core.runtime.Assert)1 CoreException (org.eclipse.core.runtime.CoreException)1 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)1 CompletionContext (org.eclipse.jdt.core.CompletionContext)1 CompletionProposal (org.eclipse.jdt.core.CompletionProposal)1 IBuffer (org.eclipse.jdt.core.IBuffer)1 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)1 IJavaElement (org.eclipse.jdt.core.IJavaElement)1 IJavaProject (org.eclipse.jdt.core.IJavaProject)1 IType (org.eclipse.jdt.core.IType)1 ITypeParameter (org.eclipse.jdt.core.ITypeParameter)1 JavaCore (org.eclipse.jdt.core.JavaCore)1 JavaModelException (org.eclipse.jdt.core.JavaModelException)1 Signature (org.eclipse.jdt.core.Signature)1 CharOperation (org.eclipse.jdt.core.compiler.CharOperation)1