1
2
3
4
5
6
7
8
9
10 package de.funfried.netbeans.plugins.external.formatter.sql.dbeaver;
11
12 import java.util.Properties;
13
14 import org.netbeans.api.annotations.common.CheckForNull;
15
16 import com.diffplug.spotless.sql.dbeaver.DBeaverSQLFormatterConfiguration;
17 import com.diffplug.spotless.sql.dbeaver.SQLTokenizedFormatter;
18
19 import de.funfried.netbeans.plugins.external.formatter.exceptions.FormattingFailedException;
20
21
22
23
24
25
26 public final class DBeaverFormatterWrapper {
27
28
29
30 DBeaverFormatterWrapper() {
31 }
32
33
34
35
36
37
38
39
40
41
42
43
44 @CheckForNull
45 public String format(String code, Properties properties) throws FormattingFailedException {
46 if (code == null) {
47 return null;
48 }
49
50 try {
51 DBeaverSQLFormatterConfiguration configuration = new DBeaverSQLFormatterConfiguration(properties);
52 SQLTokenizedFormatter sqlTokenizedFormatter = new SQLTokenizedFormatter(configuration);
53 return sqlTokenizedFormatter.format(code);
54 } catch (Exception ex) {
55 throw new FormattingFailedException(ex);
56 }
57 }
58 }