private static CompletionItem getInterfaceSnippet(ICompilationUnit cu, CompletionContext completionContext, boolean needsPublic, IProgressMonitor monitor) { if (!accept(cu, completionContext, false)) { return null; } if (monitor.isCanceled()) { return null; } final CompletionItem interfaceSnippetItem = new CompletionItem(); interfaceSnippetItem.setFilterText(INTERFACE_SNIPPET_LABEL); interfaceSnippetItem.setLabel(INTERFACE_SNIPPET_LABEL); interfaceSnippetItem.setSortText(SortTextHelper.convertRelevance(0)); try { if (needsPublic) { interfaceSnippetItem.setInsertText(getSnippetContent(cu, CodeGenerationTemplate.INTERFACESNIPPET_PUBLIC, cu.findRecommendedLineSeparator(), true)); } else { interfaceSnippetItem.setInsertText(getSnippetContent(cu, CodeGenerationTemplate.INTERFACESNIPPET_DEFAULT, cu.findRecommendedLineSeparator(), true)); } setFields(interfaceSnippetItem, cu); } catch (CoreException e) { JavaLanguageServerPlugin.log(e.getStatus()); return null; } return interfaceSnippetItem; }
if (!isSnippetStringSupported() || UNSUPPORTED_RESOURCES.contains(cu.getResource().getName())) { return Collections.emptyList(); boolean needsPublic = needsPublic(cu, completionContext, monitor); if (monitor.isCanceled()) { return Collections.emptyList(); CompletionItem classSnippet = getClassSnippet(cu, completionContext, needsPublic, monitor); if (classSnippet != null) { res.add(classSnippet); CompletionItem interfaceSnippet = getInterfaceSnippet(cu, completionContext, needsPublic, monitor); if (interfaceSnippet != null) { res.add(interfaceSnippet);
List<IType> types = Arrays.asList(cu.getAllTypes()); int postfix = 0; while (types != null && !types.isEmpty() && types.stream().filter(isTypeExists(typeName)).findFirst().isPresent()) { typeName = "Inner" + JavaCore.removeJavaLikeExtension(cu.getElementName()) + (postfix == 0 ? "" : "_" + postfix); postfix++;
unit.codeComplete(offset, collector, subMonitor); proposals.addAll(collector.getCompletionItems()); proposals.addAll(SnippetCompletionProposal.getSnippets(unit, collector.getContext(), subMonitor)); proposals.addAll(new JavadocCompletionProposal().getProposals(unit, offset, collector, subMonitor)); } catch (OperationCanceledException e) {
private static CompletionItem getClassSnippet(ICompilationUnit cu, CompletionContext completionContext, boolean needsPublic, IProgressMonitor monitor) { if (!accept(cu, completionContext, 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 { if (needsPublic) { classSnippetItem.setInsertText(getSnippetContent(cu, CodeGenerationTemplate.CLASSSNIPPET_PUBLIC, cu.findRecommendedLineSeparator(), true)); } else { classSnippetItem.setInsertText(getSnippetContent(cu, CodeGenerationTemplate.CLASSSNIPPET_DEFAULT, cu.findRecommendedLineSeparator(), true)); } setFields(classSnippetItem, cu); } catch (CoreException e) { JavaLanguageServerPlugin.log(e.getStatus()); return null; } return classSnippetItem; }