Skip to content

Commit 66c2a4b

Browse files
jbduncannedtwigg
authored andcommitted
Reduce visibility of SQL-related classes and improve docs a bit
This builds upon @baptistemesta's great work on introducing a DBeaver-based SQL formatter step in spotless-lib, by: 1. Reducing the visibility of those classes that I consider to be implementation details, and annotating those classes which I cannot hide away as `@Internal`. 2. Adding warnings to those classes that are more difficult to change that they may disappear in future versions. 3. Changing the docs to make it clearer that we are including DBeaver sources in Spotless and that, as far as we know, we can legally include them in Spotless since both projects are licensed under the Apache 2.0 license. 4. And doing minor cleanups here and there, like removing redundant comments, renaming a class for clarity, and fixing up a claim that the DBeaver formatter step comes from Hibernate.
1 parent 7401807 commit 66c2a4b

13 files changed

+138
-44
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* Copyright 2016 DiffPlug
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.diffplug.spotless.annotations;
17+
18+
import java.lang.annotation.Documented;
19+
import java.lang.annotation.ElementType;
20+
import java.lang.annotation.Retention;
21+
import java.lang.annotation.RetentionPolicy;
22+
import java.lang.annotation.Target;
23+
24+
/**
25+
* Signifies that a `public` API is actually an implementation detail, and should be treated as if it
26+
* were `private`.
27+
*
28+
* The user of the API should be warned that it may unexpectedly disappear in future versions of
29+
* Spotless. Usually the best place to put this warning is in the API's class JavaDoc.
30+
*/
31+
@Retention(RetentionPolicy.CLASS)
32+
@Target({
33+
ElementType.ANNOTATION_TYPE,
34+
ElementType.CONSTRUCTOR,
35+
ElementType.FIELD,
36+
ElementType.METHOD,
37+
ElementType.TYPE
38+
})
39+
@Documented
40+
public @interface Internal {
41+
42+
}

lib/src/main/java/com/diffplug/spotless/sql/DBeaverSQLFormatter.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
import java.util.Properties;
1919

20-
import com.diffplug.spotless.sql.dbeaver.SQLFormatterConfiguration;
20+
import com.diffplug.spotless.sql.dbeaver.DBeaverSQLFormatterConfiguration;
2121
import com.diffplug.spotless.sql.dbeaver.SQLTokenizedFormatter;
2222

2323
/**
@@ -28,7 +28,7 @@ public class DBeaverSQLFormatter {
2828
private final SQLTokenizedFormatter sqlTokenizedFormatter;
2929

3030
DBeaverSQLFormatter(Properties properties) {
31-
SQLFormatterConfiguration configuration = new SQLFormatterConfiguration(properties);
31+
DBeaverSQLFormatterConfiguration configuration = new DBeaverSQLFormatterConfiguration(properties);
3232
sqlTokenizedFormatter = new SQLTokenizedFormatter(configuration);
3333
}
3434

lib/src/main/java/com/diffplug/spotless/sql/DBeaverSQLFormatterStep.java

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@
2323
import com.diffplug.spotless.FormatterProperties;
2424
import com.diffplug.spotless.FormatterStep;
2525

26-
/** Wraps up [BasicFormatterImpl](https://docs.jboss.org/hibernate/orm/4.1/javadocs/org/hibernate/engine/jdbc/internal/BasicFormatterImpl.html) as a FormatterStep. */
26+
/** SQL formatter step which wraps up DBeaver's SqlTokenizedFormatter implementation. */
2727
public class DBeaverSQLFormatterStep {
2828

29-
static final String NAME = "dbeaverSql";
29+
private static final String NAME = "dbeaverSql";
3030

3131
// prevent direct instantiation
3232
private DBeaverSQLFormatterStep() {}
@@ -40,17 +40,16 @@ public static FormatterStep create(Iterable<File> files) {
4040
static final class State implements Serializable {
4141
private static final long serialVersionUID = 1L;
4242

43-
/** The signature of the settings file. */
44-
final FileSignature settings;
43+
final FileSignature settingsSignature;
4544

4645
State(final Iterable<File> settingsFiles) throws Exception {
47-
this.settings = FileSignature.signAsList(settingsFiles);
46+
this.settingsSignature = FileSignature.signAsList(settingsFiles);
4847
}
4948

5049
FormatterFunc createFormat() throws Exception {
51-
FormatterProperties preferences = FormatterProperties.from(settings.files());
52-
DBeaverSQLFormatter DBeaverSqlFormatter = new DBeaverSQLFormatter(preferences.getProperties());
53-
return DBeaverSqlFormatter::format;
50+
FormatterProperties preferences = FormatterProperties.from(settingsSignature.files());
51+
DBeaverSQLFormatter dbeaverSqlFormatter = new DBeaverSQLFormatter(preferences.getProperties());
52+
return dbeaverSqlFormatter::format;
5453
}
5554
}
5655
}

lib/src/main/java/com/diffplug/spotless/sql/dbeaver/DBPKeywordType.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@
2020
* DBeaver - Universal Database Manager
2121
* Copyright (C) 2010-2017 Serge Rider ([email protected])
2222
*
23-
* Database keyword type
24-
*/
25-
public enum DBPKeywordType {
23+
* Based on DBPKeywordType from https://github.com/serge-rider/dbeaver,
24+
* which itself is licensed under the Apache 2.0 license.
25+
*/
26+
enum DBPKeywordType {
2627
KEYWORD, FUNCTION, TYPE, OTHER
2728
}

lib/src/main/java/com/diffplug/spotless/sql/dbeaver/SQLFormatterConfiguration.java renamed to lib/src/main/java/com/diffplug/spotless/sql/dbeaver/DBeaverSQLFormatterConfiguration.java

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,34 +17,45 @@
1717

1818
import java.util.Properties;
1919

20+
import com.diffplug.spotless.annotations.Internal;
21+
2022
/**
21-
* SQLFormatterConfiguration
23+
* **Warning:** Use this class at your own risk. It is an implementation detail and is not
24+
* guaranteed to exist in future versions.
25+
*
26+
* Forked from
27+
* DBeaver - Universal Database Manager
28+
* Copyright (C) 2010-2017 Serge Rider ([email protected])
29+
*
30+
* Based on SQLFormatterConfiguration from https://github.com/serge-rider/dbeaver,
31+
* which itself is licensed under the Apache 2.0 license.
2232
*/
23-
public class SQLFormatterConfiguration {
33+
@Internal
34+
public class DBeaverSQLFormatterConfiguration {
2435

2536
/**
2637
* UPPER, LOWER or ORIGINAL
2738
*/
28-
public static final String SQL_FORMATTER_KEYWORD_CASE = "sql.formatter.keyword.case";
39+
private static final String SQL_FORMATTER_KEYWORD_CASE = "sql.formatter.keyword.case";
2940

3041
/**
3142
* ';' by default
3243
*/
33-
public static final String SQL_FORMATTER_STATEMENT_DELIMITER = "sql.formatter.statement.delimiter";
44+
private static final String SQL_FORMATTER_STATEMENT_DELIMITER = "sql.formatter.statement.delimiter";
3445
/**
3546
* space or tag
3647
*/
37-
public static final String SQL_FORMATTER_INDENT_TYPE = "sql.formatter.indent.type";
48+
private static final String SQL_FORMATTER_INDENT_TYPE = "sql.formatter.indent.type";
3849
/**
3950
* 4 by default
4051
*/
41-
public static final String SQL_FORMATTER_INDENT_SIZE = "sql.formatter.indent.size";
52+
private static final String SQL_FORMATTER_INDENT_SIZE = "sql.formatter.indent.size";
4253

4354
private String statementDelimiters;
4455
private KeywordCase keywordCase;
4556
private String indentString;
4657

47-
public SQLFormatterConfiguration(Properties properties) {
58+
public DBeaverSQLFormatterConfiguration(Properties properties) {
4859
this.keywordCase = KeywordCase.valueOf(properties.getProperty(SQL_FORMATTER_KEYWORD_CASE, "UPPER"));
4960
this.statementDelimiters = properties.getProperty(SQL_FORMATTER_STATEMENT_DELIMITER, SQLDialect.INSTANCE
5061
.getScriptDelimiter());

lib/src/main/java/com/diffplug/spotless/sql/dbeaver/FormatterToken.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,27 @@
1515
*/
1616
package com.diffplug.spotless.sql.dbeaver;
1717

18+
/*
19+
* Forked from
20+
* DBeaver - Universal Database Manager
21+
* Copyright (C) 2010-2017 Serge Rider ([email protected])
22+
*
23+
* Based on FormatterToken from https://github.com/serge-rider/dbeaver,
24+
* which itself is licensed under the Apache 2.0 license.
25+
*/
1826
class FormatterToken {
1927

2028
private TokenType fType;
2129
private String fString;
2230
private int fPos = -1;
2331

24-
public FormatterToken(final TokenType argType, final String argString, final int argPos) {
32+
FormatterToken(final TokenType argType, final String argString, final int argPos) {
2533
fType = argType;
2634
fString = argString;
2735
fPos = argPos;
2836
}
2937

30-
public FormatterToken(final TokenType argType, final String argString) {
38+
FormatterToken(final TokenType argType, final String argString) {
3139
this(argType, argString, -1);
3240
}
3341

lib/src/main/java/com/diffplug/spotless/sql/dbeaver/KeywordCase.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
/**
2121
* @author Baptiste Mesta.
2222
*/
23-
public enum KeywordCase {
23+
enum KeywordCase {
2424
UPPER {
2525
public String transform(String value) {
2626
return value.toUpperCase(Locale.ENGLISH);

lib/src/main/java/com/diffplug/spotless/sql/dbeaver/Pair.java

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,30 +16,35 @@
1616
package com.diffplug.spotless.sql.dbeaver;
1717

1818
/**
19-
* Pair
19+
* Forked from
20+
* DBeaver - Universal Database Manager
21+
* Copyright (C) 2010-2017 Serge Rider ([email protected])
22+
*
23+
* Based on Pair from https://github.com/serge-rider/dbeaver,
24+
* which itself is licensed under the Apache 2.0 license.
2025
*/
21-
public class Pair<T1, T2> {
26+
class Pair<T1, T2> {
2227
private T1 first;
2328
private T2 second;
2429

25-
public Pair(T1 first, T2 second) {
30+
Pair(T1 first, T2 second) {
2631
this.first = first;
2732
this.second = second;
2833
}
2934

30-
public T1 getFirst() {
35+
T1 getFirst() {
3136
return first;
3237
}
3338

34-
public void setFirst(T1 first) {
39+
void setFirst(T1 first) {
3540
this.first = first;
3641
}
3742

38-
public T2 getSecond() {
43+
T2 getSecond() {
3944
return second;
4045
}
4146

42-
public void setSecond(T2 second) {
47+
void setSecond(T2 second) {
4348
this.second = second;
4449
}
4550

lib/src/main/java/com/diffplug/spotless/sql/dbeaver/SQLConstants.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
* DBeaver - Universal Database Manager
2121
* Copyright (C) 2010-2017 Serge Rider ([email protected])
2222
*
23-
* SQL editor constants
23+
* Based on SQLConstants from https://github.com/serge-rider/dbeaver,
24+
* which itself is licensed under the Apache 2.0 license.
2425
*/
2526
class SQLConstants {
2627

lib/src/main/java/com/diffplug/spotless/sql/dbeaver/SQLDialect.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,21 @@
1515
*/
1616
package com.diffplug.spotless.sql.dbeaver;
1717

18-
import java.util.*;
18+
import java.util.Collection;
19+
import java.util.Collections;
20+
import java.util.HashSet;
21+
import java.util.Locale;
22+
import java.util.Set;
23+
import java.util.TreeMap;
24+
import java.util.TreeSet;
1925

2026
/**
21-
* Basic SQL Dialect
27+
* Forked from
28+
* DBeaver - Universal Database Manager
29+
* Copyright (C) 2010-2017 Serge Rider ([email protected])
30+
*
31+
* Based on SQLDialect from https://github.com/serge-rider/dbeaver,
32+
* which itself is licensed under the Apache 2.0 license.
2233
*/
2334
class SQLDialect {
2435

0 commit comments

Comments
 (0)