Skip to content

Commit 893f425

Browse files
committed
Apply spotless and document origin
1 parent 51f4988 commit 893f425

File tree

8 files changed

+261
-221
lines changed

8 files changed

+261
-221
lines changed

lib-extra/src/jdt/java/com/diffplug/spotless/extra/glue/jdt/DefaultJavaElementComparator.java

+178-160
Large diffs are not rendered by default.

lib-extra/src/jdt/java/com/diffplug/spotless/extra/glue/jdt/EclipseJdtFormatterStepImpl.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2023 DiffPlug
2+
* Copyright 2016-2024 DiffPlug
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -38,10 +38,10 @@ public class EclipseJdtFormatterStepImpl {
3838

3939
public EclipseJdtFormatterStepImpl(Properties formatterSettings, Map<String, String> sortProperties) {
4040
Map<String, String> options = formatterSettings.entrySet().stream().collect(Collectors.toMap(
41-
e -> String.valueOf(e.getKey()),
42-
e -> String.valueOf(e.getValue()),
43-
(prev, next) -> next,
44-
HashMap::new));
41+
e -> String.valueOf(e.getKey()),
42+
e -> String.valueOf(e.getValue()),
43+
(prev, next) -> next,
44+
HashMap::new));
4545
this.codeFormatter = new DefaultCodeFormatter(options);
4646
this.sortProperties = EclipseJdtSortMembers.SortProperties.from(sortProperties);
4747
}

lib-extra/src/jdt/java/com/diffplug/spotless/extra/glue/jdt/EclipseJdtSortMembers.java

+33-28
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
/*
2+
* Copyright 2024 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+
*/
116
package com.diffplug.spotless.extra.glue.jdt;
217

318
import java.util.Comparator;
@@ -58,10 +73,10 @@ static String sortMember(String code, SortProperties properties) {
5873
try {
5974
CompilationUnit compilationUnit = compilationUnit(code);
6075
DefaultJavaElementComparator comparator = DefaultJavaElementComparator.of(
61-
properties.doNotSortFields,
62-
properties.membersOrder,
63-
properties.sortByVisibility,
64-
properties.visibilityOrder);
76+
properties.doNotSortFields,
77+
properties.membersOrder,
78+
properties.sortByVisibility,
79+
properties.visibilityOrder);
6580
new Sorter(AST.getJLSLatest(), compilationUnit, null, comparator).sort();
6681
String content = compilationUnit.getBuffer().getContents();
6782
if (content != null) {
@@ -81,17 +96,13 @@ private static class Buffer implements IBuffer {
8196
this.contents = contents;
8297
}
8398

84-
public void addBufferChangedListener(IBufferChangedListener listener) {
85-
}
99+
public void addBufferChangedListener(IBufferChangedListener listener) {}
86100

87-
public void append(char[] text) {
88-
}
101+
public void append(char[] text) {}
89102

90-
public void append(String text) {
91-
}
103+
public void append(String text) {}
92104

93-
public void close() {
94-
}
105+
public void close() {}
95106

96107
public char getChar(int position) {
97108
return '\u0000';
@@ -133,20 +144,15 @@ public boolean isReadOnly() {
133144
return true;
134145
}
135146

136-
public void removeBufferChangedListener(IBufferChangedListener listener) {
137-
}
147+
public void removeBufferChangedListener(IBufferChangedListener listener) {}
138148

139-
public void replace(int position, int length, char[] text) {
140-
}
149+
public void replace(int position, int length, char[] text) {}
141150

142-
public void replace(int position, int length, String text) {
143-
}
151+
public void replace(int position, int length, String text) {}
144152

145-
public void save(IProgressMonitor progress, boolean force) {
146-
}
153+
public void save(IProgressMonitor progress, boolean force) {}
147154

148-
public void setContents(char[] contents) {
149-
}
155+
public void setContents(char[] contents) {}
150156

151157
public void setContents(String contents) {
152158
this.contents = contents;
@@ -172,12 +178,11 @@ static class SortProperties {
172178
final String visibilityOrder;
173179

174180
SortProperties(
175-
boolean enabled,
176-
String membersOrder,
177-
boolean doNotSortFields,
178-
boolean sortByVisibility,
179-
String visibilityOrder
180-
) {
181+
boolean enabled,
182+
String membersOrder,
183+
boolean doNotSortFields,
184+
boolean sortByVisibility,
185+
String visibilityOrder) {
181186
this.enabled = enabled;
182187
this.membersOrder = membersOrder;
183188
this.doNotSortFields = doNotSortFields;

lib-extra/src/jdt/java/com/diffplug/spotless/extra/glue/jdt/JdtFlags.java

+23-5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
/*
2+
* Copyright 2024 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+
*/
116
package com.diffplug.spotless.extra.glue.jdt;
217

318
import org.eclipse.core.runtime.Assert;
@@ -10,14 +25,17 @@
1025
import org.eclipse.jdt.core.dom.Modifier;
1126
import org.eclipse.jdt.core.dom.TypeDeclaration;
1227

28+
/**
29+
* This class is derived and adapted code from the Eclipse JDT project (Derivative Works according to EPL 2.0 license).
30+
*/
1331
class JdtFlags {
1432

15-
static final int VISIBILITY_CODE_INVALID= -1;
33+
static final int VISIBILITY_CODE_INVALID = -1;
1634

1735
static boolean isStatic(BodyDeclaration bodyDeclaration) {
1836
if (isNestedInterfaceOrAnnotation(bodyDeclaration))
1937
return true;
20-
int nodeType= bodyDeclaration.getNodeType();
38+
int nodeType = bodyDeclaration.getNodeType();
2139
if (nodeType != ASTNode.METHOD_DECLARATION
2240
&& nodeType != ASTNode.ANNOTATION_TYPE_MEMBER_DECLARATION
2341
&& isInterfaceOrAnnotationMember(bodyDeclaration))
@@ -30,7 +48,7 @@ && isInterfaceOrAnnotationMember(bodyDeclaration))
3048
}
3149

3250
private static boolean isPackageVisible(BodyDeclaration bodyDeclaration) {
33-
return (! isPrivate(bodyDeclaration) && ! isProtected(bodyDeclaration) && ! isPublic(bodyDeclaration));
51+
return (!isPrivate(bodyDeclaration) && !isProtected(bodyDeclaration) && !isPublic(bodyDeclaration));
3452
}
3553

3654
private static boolean isPrivate(BodyDeclaration bodyDeclaration) {
@@ -52,8 +70,8 @@ private static boolean isInterfaceOrAnnotationMember(BodyDeclaration bodyDeclara
5270
}
5371

5472
private static boolean isInterfaceOrAnnotation(ASTNode node) {
55-
boolean isInterface= (node instanceof TypeDeclaration) && ((TypeDeclaration) node).isInterface();
56-
boolean isAnnotation= node instanceof AnnotationTypeDeclaration;
73+
boolean isInterface = (node instanceof TypeDeclaration) && ((TypeDeclaration) node).isInterface();
74+
boolean isAnnotation = node instanceof AnnotationTypeDeclaration;
5775
return isInterface || isAnnotation;
5876
}
5977

lib-extra/src/main/java/com/diffplug/spotless/extra/EquoBasedStepBuilder.java

+9-9
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,11 @@ public abstract class EquoBasedStepBuilder {
5959

6060
/** Initialize valid default configuration, taking latest version */
6161
public EquoBasedStepBuilder(
62-
String formatterName,
63-
Provisioner mavenProvisioner,
64-
@Nullable String defaultVersion,
65-
SerializedFunction<State, FormatterFunc> stateToFormatter,
66-
ImmutableMap.Builder<String, String> stepProperties) {
62+
String formatterName,
63+
Provisioner mavenProvisioner,
64+
@Nullable String defaultVersion,
65+
SerializedFunction<State, FormatterFunc> stateToFormatter,
66+
ImmutableMap.Builder<String, String> stepProperties) {
6767

6868
this.formatterName = formatterName;
6969
this.mavenProvisioner = mavenProvisioner;
@@ -169,10 +169,10 @@ static class EquoStep implements Serializable {
169169
private final ImmutableMap<String, String> stepProperties;
170170

171171
EquoStep(
172-
String semanticVersion,
173-
FileSignature.Promised settingsPromise,
174-
JarState.Promised jarPromise,
175-
ImmutableMap<String, String> stepProperties) {
172+
String semanticVersion,
173+
FileSignature.Promised settingsPromise,
174+
JarState.Promised jarPromise,
175+
ImmutableMap<String, String> stepProperties) {
176176

177177
this.semanticVersion = semanticVersion;
178178
this.settingsPromise = settingsPromise;

lib-extra/src/main/java/com/diffplug/spotless/extra/java/EclipseJdtFormatterStep.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,11 @@ public static class Builder extends EquoBasedStepBuilder {
5757
private final ImmutableMap.Builder<String, String> stepProperties;
5858

5959
Builder(
60-
String formatterName,
61-
Provisioner mavenProvisioner,
62-
String defaultVersion,
63-
SerializedFunction<State, FormatterFunc> stateToFormatter,
64-
ImmutableMap.Builder<String, String> stepProperties) {
60+
String formatterName,
61+
Provisioner mavenProvisioner,
62+
String defaultVersion,
63+
SerializedFunction<State, FormatterFunc> stateToFormatter,
64+
ImmutableMap.Builder<String, String> stepProperties) {
6565
super(formatterName, mavenProvisioner, defaultVersion, stateToFormatter, stepProperties);
6666
this.stepProperties = stepProperties;
6767
}

lib-extra/src/test/java/com/diffplug/spotless/extra/java/EclipseJdtFormatterStepSpecialCaseTest.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2023 DiffPlug
2+
* Copyright 2016-2024 DiffPlug
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -33,7 +33,7 @@ public void issue_1638() {
3333
EquoBasedStepBuilder builder = EclipseJdtFormatterStep.createBuilder(TestProvisioner.mavenCentral());
3434
builder.setPreferences(List.of(file));
3535
StepHarness.forStep(builder.build())
36-
.testResource("java/eclipse/AbstractType.test", "java/eclipse/AbstractType.clean");
36+
.testResource("java/eclipse/AbstractType.test", "java/eclipse/AbstractType.clean");
3737
}
3838

3939
@Test
@@ -42,7 +42,7 @@ public void sort_members_no_fields() {
4242
EclipseJdtFormatterStep.Builder builder = EclipseJdtFormatterStep.createBuilder(TestProvisioner.mavenCentral());
4343
builder.setMembersOrdering("SF,SI,SM,F,I,C,M,T", true);
4444
StepHarness.forStep(builder.build())
45-
.testResource("java/eclipse/SortExample.test", "java/eclipse/SortExample.sortMembersNoFields.clean");
45+
.testResource("java/eclipse/SortExample.test", "java/eclipse/SortExample.sortMembersNoFields.clean");
4646
}
4747

4848
@Test
@@ -51,7 +51,7 @@ public void sort_members() {
5151
EclipseJdtFormatterStep.Builder builder = EclipseJdtFormatterStep.createBuilder(TestProvisioner.mavenCentral());
5252
builder.setMembersOrdering("SF,SI,SM,F,I,C,M,T", false);
5353
StepHarness.forStep(builder.build())
54-
.testResource("java/eclipse/SortExample.test", "java/eclipse/SortExample.sortMembers.clean");
54+
.testResource("java/eclipse/SortExample.test", "java/eclipse/SortExample.sortMembers.clean");
5555
}
5656

5757
@Test
@@ -61,6 +61,6 @@ public void sort_members_and_by_visibility() {
6161
builder.setMembersOrdering("SF,SI,SM,F,I,C,M,T", false);
6262
builder.setVisibilityOrdering("B,R,D,V");
6363
StepHarness.forStep(builder.build())
64-
.testResource("java/eclipse/SortExample.test", "java/eclipse/SortExample.sortMembersByVisibility.clean");
64+
.testResource("java/eclipse/SortExample.test", "java/eclipse/SortExample.sortMembersByVisibility.clean");
6565
}
6666
}

plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java

+3-4
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
import org.gradle.api.tasks.SourceSet;
3434

3535
import com.diffplug.spotless.FormatterStep;
36-
import com.diffplug.spotless.extra.EquoBasedStepBuilder;
3736
import com.diffplug.spotless.extra.java.EclipseJdtFormatterStep;
3837
import com.diffplug.spotless.generic.LicenseHeaderStep;
3938
import com.diffplug.spotless.java.CleanthatJavaStep;
@@ -314,9 +313,9 @@ public EclipseConfig sortMembers(String memberCategoryOrder, boolean doNotSortFi
314313
}
315314

316315
public EclipseConfig sortMembers(
317-
String memberCategoryOrder,
318-
boolean doNotSortFields,
319-
String visibilityOrder) {
316+
String memberCategoryOrder,
317+
boolean doNotSortFields,
318+
String visibilityOrder) {
320319
requireElementsNonNull(memberCategoryOrder);
321320
requireElementsNonNull(visibilityOrder);
322321
builder.setMembersOrdering(memberCategoryOrder, doNotSortFields);

0 commit comments

Comments
 (0)