-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adds per codemod Includes/Excludes #438
Changes from 6 commits
8aed515
33f495a
c5b9924
6b66393
0df51f2
f2c89e4
ab03c27
df5de2b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
import com.github.javaparser.ast.CompilationUnit; | ||
import io.codemodder.codetf.UnfixedFinding; | ||
import io.codemodder.javaparser.JavaParserChanger; | ||
import java.nio.file.Path; | ||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
|
@@ -29,6 +30,17 @@ protected CompositeJavaParserChanger(final JavaParserChanger... changers) { | |
this.changers = Arrays.asList(Objects.requireNonNull(changers)); | ||
} | ||
|
||
@Override | ||
public IncludesExcludesPattern getIncludesExcludesPattern() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This doesn't seem right, but not sure I have another proposal right now. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ideally this would be an intersection of all the patterns. But I'm not sure we can calculate this with just the patterns themselves. |
||
// The first changer will dictate which files this composition accepts | ||
return changers.get(0).getIncludesExcludesPattern(); | ||
} | ||
|
||
@Override | ||
public boolean supports(final Path file) { | ||
return changers.stream().anyMatch(c -> c.supports(file)); | ||
} | ||
|
||
@Override | ||
public CodemodFileScanningResult visit( | ||
final CodemodInvocationContext context, final CompilationUnit cu) { | ||
|
@@ -44,9 +56,4 @@ public CodemodFileScanningResult visit( | |
|
||
return CodemodFileScanningResult.from(changes, unfixedFindings); | ||
} | ||
|
||
@Override | ||
public boolean shouldRun() { | ||
return changers.stream().anyMatch(CodeChanger::shouldRun); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package io.codemodder; | ||
|
||
import java.nio.file.Path; | ||
import java.util.*; | ||
|
||
/** Holds includes and excludes patterns for files */ | ||
public interface IncludesExcludesPattern { | ||
|
||
/** | ||
* Returns an IncludesExcludes file matcher that matches files following the patterns specified | ||
* patterns. The patterns must follow the java's {@link java.nio.file.PathMatcher} specification | ||
* and are treated as relative paths with regard to the repository root. | ||
*/ | ||
IncludesExcludes getRootedMatcher(final Path root); | ||
|
||
class Default implements IncludesExcludesPattern { | ||
|
||
private final Set<String> pathIncludes; | ||
private final Set<String> pathExcludes; | ||
|
||
public Default(final Set<String> pathIncludes, final Set<String> pathExcludes) { | ||
andrecsilva marked this conversation as resolved.
Show resolved
Hide resolved
|
||
this.pathIncludes = pathIncludes; | ||
this.pathExcludes = pathExcludes; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "Includes: " + pathIncludes + "\nExcludes: " + pathExcludes; | ||
} | ||
|
||
@Override | ||
public IncludesExcludes getRootedMatcher(final Path root) { | ||
return IncludesExcludes.withSettings( | ||
root.toFile(), pathIncludes.stream().toList(), pathExcludes.stream().toList()); | ||
} | ||
} | ||
|
||
/** An includes/excludes pattern that matches java files. */ | ||
final class JavaMatcherSingleton { | ||
private static IncludesExcludesPattern singleton; | ||
|
||
private JavaMatcherSingleton() {} | ||
|
||
public static IncludesExcludesPattern getInstance() { | ||
andrecsilva marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if (singleton == null) { | ||
singleton = | ||
new IncludesExcludesPattern.Default( | ||
Set.of("**.[jJ][aA][vV][Aa]"), Collections.emptySet()); | ||
} | ||
return singleton; | ||
} | ||
} | ||
|
||
/** An includes/excludes pattern that matches any files. */ | ||
final class AnySingleton { | ||
private static IncludesExcludesPattern singleton; | ||
|
||
private AnySingleton() {} | ||
|
||
public static IncludesExcludesPattern getInstance() { | ||
if (singleton == null) { | ||
singleton = new IncludesExcludesPattern.Default(Set.of("**"), Collections.emptySet()); | ||
} | ||
return singleton; | ||
} | ||
} | ||
|
||
/** Returns an includes/excludes pattern that matches any java files. */ | ||
static IncludesExcludesPattern getJavaMatcher() { | ||
return JavaMatcherSingleton.getInstance(); | ||
} | ||
|
||
/** Returns an includes/excludes pattern that matches any files. */ | ||
static IncludesExcludesPattern getAnyMatcher() { | ||
return AnySingleton.getInstance(); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we expose the actual values so both the tests and the CLI use the same values?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CLI doesn't use these default includes anymore.
Do you still want these to be the default values for find-and-fix codemods? Right now every javaparser based one will only have
**.java
as its pattern.