Search in sources :

Example 11 with CodeGenerationTemplate

use of org.eclipse.jdt.ls.core.internal.preferences.CodeGenerationTemplate in project eclipse.jdt.ls by eclipse.

the class SnippetCompletionProposal method getClassSnippet.

private static CompletionItem getClassSnippet(SnippetCompletionContext scc, IProgressMonitor monitor) {
    ICompilationUnit cu = scc.getCompilationUnit();
    if (!accept(cu, scc.getCompletionContext(), true)) {
        return null;
    }
    if (monitor.isCanceled()) {
        return null;
    }
    final CompletionItem classSnippetItem = new CompletionItem();
    classSnippetItem.setLabel(CLASS_SNIPPET_LABEL);
    classSnippetItem.setFilterText(CLASS_SNIPPET_LABEL);
    classSnippetItem.setSortText(SortTextHelper.convertRelevance(1));
    try {
        CodeGenerationTemplate template = (scc.needsPublic(monitor)) ? CodeGenerationTemplate.CLASSSNIPPET_PUBLIC : CodeGenerationTemplate.CLASSSNIPPET_DEFAULT;
        classSnippetItem.setInsertText(getSnippetContent(scc, template, true));
    } catch (CoreException e) {
        JavaLanguageServerPlugin.log(e.getStatus());
        return null;
    }
    return classSnippetItem;
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) CoreException(org.eclipse.core.runtime.CoreException) CompletionItem(org.eclipse.lsp4j.CompletionItem) CodeGenerationTemplate(org.eclipse.jdt.ls.core.internal.preferences.CodeGenerationTemplate)

Aggregations

CodeGenerationTemplate (org.eclipse.jdt.ls.core.internal.preferences.CodeGenerationTemplate)11 Template (org.eclipse.jface.text.templates.Template)8 CodeTemplateContext (org.eclipse.jdt.ls.core.internal.corext.template.java.CodeTemplateContext)7 CoreException (org.eclipse.core.runtime.CoreException)6 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)4 BadLocationException (org.eclipse.jface.text.BadLocationException)3 TemplateBuffer (org.eclipse.jface.text.templates.TemplateBuffer)3 TemplateException (org.eclipse.jface.text.templates.TemplateException)3 CompletionItem (org.eclipse.lsp4j.CompletionItem)3 Document (org.eclipse.jface.text.Document)2 IDocument (org.eclipse.jface.text.IDocument)2 TemplateVariable (org.eclipse.jface.text.templates.TemplateVariable)2 IJavaProject (org.eclipse.jdt.core.IJavaProject)1 IType (org.eclipse.jdt.core.IType)1 ITypeParameter (org.eclipse.jdt.core.ITypeParameter)1 SingleVariableDeclaration (org.eclipse.jdt.core.dom.SingleVariableDeclaration)1 TypeParameter (org.eclipse.jdt.core.dom.TypeParameter)1 CodeTemplateContext (org.eclipse.jdt.internal.core.manipulation.CodeTemplateContext)1