-
Notifications
You must be signed in to change notification settings - Fork 458
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into dependabot/gradle/com.diffplug.spotless-6.0.0
- Loading branch information
Showing
14 changed files
with
264 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
lib/src/main/java/com/diffplug/spotless/FilterByContentPatternFormatterStep.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/* | ||
* Copyright 2016-2021 DiffPlug | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.diffplug.spotless; | ||
|
||
import java.io.File; | ||
import java.util.Objects; | ||
import java.util.regex.Matcher; | ||
import java.util.regex.Pattern; | ||
|
||
import javax.annotation.Nullable; | ||
|
||
final class FilterByContentPatternFormatterStep implements FormatterStep { | ||
private final FormatterStep delegateStep; | ||
final Pattern contentPattern; | ||
|
||
FilterByContentPatternFormatterStep(FormatterStep delegateStep, String contentPattern) { | ||
this.delegateStep = Objects.requireNonNull(delegateStep); | ||
this.contentPattern = Pattern.compile(Objects.requireNonNull(contentPattern)); | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return delegateStep.getName(); | ||
} | ||
|
||
@Override | ||
public @Nullable String format(String raw, File file) throws Exception { | ||
Objects.requireNonNull(raw, "raw"); | ||
Objects.requireNonNull(file, "file"); | ||
|
||
Matcher matcher = contentPattern.matcher(raw); | ||
|
||
if (matcher.find()) { | ||
return delegateStep.format(raw, file); | ||
} else { | ||
return raw; | ||
} | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) { | ||
return true; | ||
} | ||
if (o == null || getClass() != o.getClass()) { | ||
return false; | ||
} | ||
FilterByContentPatternFormatterStep that = (FilterByContentPatternFormatterStep) o; | ||
return Objects.equals(delegateStep, that.delegateStep) && | ||
Objects.equals(contentPattern.pattern(), that.contentPattern.pattern()); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(delegateStep, contentPattern.pattern()); | ||
} | ||
|
||
private static final long serialVersionUID = 1L; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.