Skip to content

Commit 426310a

Browse files
author
Vincent Potucek
committed
new step to expand java wildcard imports diffplug#2744 diffplug#2594
1 parent ee6c5b9 commit 426310a

File tree

2 files changed

+8
-9
lines changed

2 files changed

+8
-9
lines changed

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@
4747
import com.diffplug.common.collect.Table;
4848
import com.diffplug.spotless.FileSignature;
4949

50+
import static com.diffplug.spotless.FileSignature.pathNativeToUnix;
51+
import static org.eclipse.jgit.treewalk.TreeWalk.forPath;
52+
5053
/**
5154
* How to use:
5255
* - For best performance, you should have one instance of GitRatchet, shared by all projects.
@@ -57,9 +60,7 @@
5760
public abstract class GitRatchet<Project> implements AutoCloseable {
5861

5962
public boolean isClean(Project project, ObjectId treeSha, File file) throws IOException {
60-
Repository repo = repositoryFor(project);
61-
String relativePath = FileSignature.pathNativeToUnix(repo.getWorkTree().toPath().relativize(file.toPath()).toString());
62-
return isClean(project, treeSha, relativePath);
63+
return isClean(project, treeSha, pathNativeToUnix(repositoryFor(project).getWorkTree().toPath().relativize(file.toPath()).toString()));
6364
}
6465

6566
private final Map<Repository, DirCache> dirCaches = new HashMap<>();
@@ -210,8 +211,7 @@ public synchronized ObjectId subtreeShaOf(Project project, ObjectId rootTreeSha)
210211
if (repo.getWorkTree().equals(directory)) {
211212
subtreeSha = rootTreeSha;
212213
} else {
213-
String subpath = FileSignature.pathNativeToUnix(repo.getWorkTree().toPath().relativize(directory.toPath()).toString());
214-
TreeWalk treeWalk = TreeWalk.forPath(repo, subpath, rootTreeSha);
214+
TreeWalk treeWalk = forPath(repo, pathNativeToUnix(repo.getWorkTree().toPath().relativize(directory.toPath()).toString()), rootTreeSha);
215215
subtreeSha = treeWalk == null ? ObjectId.zeroId() : treeWalk.getObjectId(0);
216216
}
217217
subtreeShaCache.put(project, subtreeSha.copy());

lib/src/main/java/com/diffplug/spotless/java/ExpandWildcardImportsStep.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,9 @@ public State(Collection<File> typeSolverClasspath, JarState jarState) {
7272

7373
FormatterFunc toFormatter() {
7474
try {
75-
Class<?> formatterFunc = jarState.getClassLoader()
76-
.loadClass("com.diffplug.spotless.glue.javaparser.ExpandWildcardsFormatterFunc");
77-
Constructor<?> constructor = formatterFunc.getConstructor(Collection.class);
78-
return (FormatterFunc) constructor.newInstance(typeSolverClasspath);
75+
return (FormatterFunc) jarState.getClassLoader()
76+
.loadClass("com.diffplug.spotless.glue.javaparser.ExpandWildcardsFormatterFunc")
77+
.getConstructor(Collection.class).newInstance(typeSolverClasspath);
7978
} catch (ClassNotFoundException | NoSuchMethodException | InvocationTargetException
8079
| InstantiationException | IllegalAccessException | NoClassDefFoundError cause) {
8180
throw new IllegalStateException(INCOMPATIBLE_ERROR_MESSAGE, cause);

0 commit comments

Comments
 (0)