List<? extends org.eclipse.lsp4j.TextEdit> formatting(DocumentFormattingParams params, IProgressMonitor monitor) { return format(params.getTextDocument().getUri(), params.getOptions(), (Range) null, monitor); }
List<? extends org.eclipse.lsp4j.TextEdit> rangeFormatting(DocumentRangeFormattingParams params, IProgressMonitor monitor) { return format(params.getTextDocument().getUri(), params.getOptions(), params.getRange(), monitor); }
private List<? extends org.eclipse.lsp4j.TextEdit> format(String uri, FormattingOptions options, Position position, String triggerChar, IProgressMonitor monitor) { if (!preferenceManager.getPreferences().isJavaFormatOnTypeEnabled()) { return Collections.emptyList(); } ICompilationUnit cu = JDTUtils.resolveCompilationUnit(uri); if (cu == null) { return Collections.emptyList(); } IRegion region = null; IDocument document = null; try { document = JsonRpcHelpers.toDocument(cu.getBuffer()); if (document != null && position != null) { region = getRegion(cu, document, position, triggerChar); } } catch (JavaModelException e) { JavaLanguageServerPlugin.logException(e.getMessage(), e); } if (region == null) { return Collections.emptyList(); } return format(cu, document, region, options, false, monitor); }
public List<? extends org.eclipse.lsp4j.TextEdit> onTypeFormatting(DocumentOnTypeFormattingParams params, IProgressMonitor monitor) { return format(params.getTextDocument().getUri(), params.getOptions(), params.getPosition(), params.getCh(), monitor); }
private List<org.eclipse.lsp4j.TextEdit> format(String uri, FormattingOptions options, Range range, IProgressMonitor monitor) { if (!preferenceManager.getPreferences().isJavaFormatEnabled()) { return Collections.emptyList(); } ICompilationUnit cu = JDTUtils.resolveCompilationUnit(uri); if (cu == null) { return Collections.emptyList(); } IRegion region = null; IDocument document = null; try { document = JsonRpcHelpers.toDocument(cu.getBuffer()); if (document != null) { region = (range == null ? new Region(0, document.getLength()) : getRegion(range, document)); } } catch (JavaModelException e) { JavaLanguageServerPlugin.logException(e.getMessage(), e); } if (region == null) { return Collections.emptyList(); } return format(cu, document, region, options, preferenceManager.getPreferences().isJavaFormatComments(), monitor); }