Skip to content

Commit

Permalink
fixup! Introduce semantics-aware Java import ordering. (fixes diffplu…
Browse files Browse the repository at this point in the history
  • Loading branch information
Frettman committed May 22, 2023
1 parent 10610f8 commit ff38088
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2016-2021 DiffPlug
* Copyright 2016-2023 DiffPlug
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2016-2021 DiffPlug
* Copyright 2016-2023 DiffPlug
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,10 +291,10 @@ public int compare(String string1, String string2) {
* Ordering uses semantics of the import string by splitting it into package,
* class name(s) and static member (for static imports) and then comparing by
* each of those three substrings in sequence.
*
*
* When comparing static imports, the last segment in the dot-separated string
* is considered to be the member (field, method, type) name.
*
*
* The first segment starting with an upper case letter is considered to be the
* (first) class name. Since this comparator has no actual type information,
* this auto-detection will fail for upper case package names and lower case
Expand Down Expand Up @@ -359,7 +359,7 @@ private String[] splitFqcnAndMember(String importString) {
member = null;
}

return new String[] { fqcn, member };
return new String[]{fqcn, member};
}

/**
Expand Down Expand Up @@ -406,7 +406,7 @@ private String[] splitPackageAndClasses(String fqcn) {
classNames = fqcn.substring(i + 1);
}

return new String[] { packageNames, classNames };
return new String[]{packageNames, classNames};
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,13 +127,13 @@ public ImportOrderConfig treatAsPackage(Collection<String> treatAsPackage) {
public ImportOrderConfig treatAsClass(String... treatAsClass) {
return treatAsClass(Arrays.asList(treatAsClass));
}

public ImportOrderConfig treatAsClass(Collection<String> treatAsClass) {
this.treatAsClass = new HashSet<>(treatAsClass);
replaceStep(createStep());
return this;
}

private FormatterStep createStep() {
ImportOrderStep importOrderStep = ImportOrderStep.forJava();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2016-2021 DiffPlug
* Copyright 2016-2023 DiffPlug
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@
*/
package com.diffplug.spotless.java;

import java.util.Set;

import org.junit.jupiter.api.Test;

import com.diffplug.spotless.FormatterStep;
import com.diffplug.spotless.ResourceHarness;
import com.diffplug.spotless.SerializableEqualityTester;
import com.diffplug.spotless.StepHarness;
import java.util.Set;

class ImportOrderStepTest extends ResourceHarness {
@Test
Expand Down

0 comments on commit ff38088

Please sign in to comment.