-
Notifications
You must be signed in to change notification settings - Fork 1
Add all the supporting infrastructure for removeUnused mode
#203
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
Changes from all commits
c3f0868
f05e3f4
0817d59
3548966
48091ca
429d12a
6e4fc4b
fbc545c
30effe7
9de5225
1f1ff19
a4bb47c
e835876
5e003a3
78001a9
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 |
|---|---|---|
|
|
@@ -20,6 +20,7 @@ | |
| import com.palantir.gradle.suppressibleerrorprone.modes.common.CommonOptions; | ||
| import com.palantir.gradle.suppressibleerrorprone.modes.common.Mode; | ||
| import com.palantir.gradle.suppressibleerrorprone.modes.common.PatchChecksOption; | ||
| import java.util.Map; | ||
| import java.util.Set; | ||
| import java.util.stream.Collectors; | ||
|
|
||
|
|
@@ -31,6 +32,11 @@ public CommonOptions configureAndReturnCommonOptions(ModeOptionContext context) | |
| public PatchChecksOption patchChecks() { | ||
| return PatchChecksOption.someChecks(() -> checksToApplySuggestedPatchesFor(context)); | ||
| } | ||
|
|
||
| @Override | ||
| public Map<String, String> extraErrorProneCheckOptions() { | ||
| return Map.of(SUPPRESSIBLE_ERROR_PRONE_MODE, "Apply"); | ||
| } | ||
|
Comment on lines
+36
to
+39
Contributor
Author
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. To maintain parity with RemoveUnusedMode. Also, potentially a way to move mode interference logic into VisitorStateModifications in the future (see #180) |
||
| }; | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| /* | ||
| * (c) Copyright 2025 Palantir Technologies Inc. All rights reserved. | ||
| * | ||
| * 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.palantir.gradle.suppressibleerrorprone.modes.modes; | ||
|
|
||
| import com.palantir.gradle.suppressibleerrorprone.modes.common.CommonOptions; | ||
| import com.palantir.gradle.suppressibleerrorprone.modes.common.Mode; | ||
| import com.palantir.gradle.suppressibleerrorprone.modes.common.ModifyCheckApiOption; | ||
| import com.palantir.gradle.suppressibleerrorprone.modes.common.ModifyCheckApiOption.ModifiedFile; | ||
| import com.palantir.gradle.suppressibleerrorprone.modes.common.PatchChecksOption; | ||
| import java.util.Map; | ||
|
|
||
| public final class RemoveUnusedMode implements Mode { | ||
| private static final String ALL_CHECKS = ""; | ||
|
|
||
| @Override | ||
| public ModifyCheckApiOption modifyCheckApi() { | ||
| return ModifyCheckApiOption.mustModify( | ||
| ModifiedFile.BUG_CHECKER_INFO, ModifiedFile.SUPPRESSIBLE_TREE_PATH_SCANNER, ModifiedFile.VISITOR_STATE); | ||
| } | ||
|
|
||
| @Override | ||
| public CommonOptions configureAndReturnCommonOptions(ModeOptionContext context) { | ||
| return new CommonOptions() { | ||
| @Override | ||
| public PatchChecksOption patchChecks() { | ||
| return PatchChecksOption.allChecks(); | ||
| } | ||
|
|
||
| @Override | ||
| public Map<String, String> extraErrorProneCheckOptions() { | ||
| return Map.of(SUPPRESSIBLE_ERROR_PRONE_MODE, "RemoveUnused"); | ||
| } | ||
|
Comment on lines
+43
to
+46
Contributor
Author
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 will be used in VisitorStateModifications to branch to the removeUnused procedure. |
||
|
|
||
| @Override | ||
| public boolean ignoreSuppressionAnnotations() { | ||
| return true; | ||
| } | ||
| }; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,6 +21,7 @@ | |
| import com.palantir.gradle.suppressibleerrorprone.modes.common.ModifyCheckApiOption; | ||
| import com.palantir.gradle.suppressibleerrorprone.modes.common.ModifyCheckApiOption.ModifiedFile; | ||
| import com.palantir.gradle.suppressibleerrorprone.modes.common.PatchChecksOption; | ||
| import java.util.Map; | ||
|
|
||
| public final class SuppressMode implements Mode { | ||
| @Override | ||
|
|
@@ -35,6 +36,11 @@ public CommonOptions configureAndReturnCommonOptions(ModeOptionContext context) | |
| public PatchChecksOption patchChecks() { | ||
| return PatchChecksOption.allChecks(); | ||
| } | ||
|
|
||
| @Override | ||
| public Map<String, String> extraErrorProneCheckOptions() { | ||
| return Map.of(SUPPRESSIBLE_ERROR_PRONE_MODE, "Suppress"); | ||
| } | ||
|
Comment on lines
+40
to
+43
Contributor
Author
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. To maintain parity with RemoveUnusedMode. Also, potentially a way to move mode interference logic into VisitorStateModifications in the future (see #180) |
||
| }; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| /* | ||
| * (c) Copyright 2025 Palantir Technologies Inc. All rights reserved. | ||
| * | ||
| * 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.palantir.suppressibleerrorprone; | ||
|
|
||
| import com.google.common.base.Suppliers; | ||
| import com.google.errorprone.BugCheckerInfo; | ||
| import com.google.errorprone.bugpatterns.BugChecker; | ||
| import com.google.errorprone.scanner.BuiltInCheckerSuppliers; | ||
| import java.util.ServiceLoader; | ||
| import java.util.Set; | ||
| import java.util.function.Supplier; | ||
| import java.util.stream.Collectors; | ||
| import java.util.stream.Stream; | ||
| import one.util.streamex.StreamEx; | ||
|
|
||
| public final class AllErrorprones { | ||
| private static Supplier<Set<String>> cachedAllBugcheckerNames = Suppliers.memoize(() -> { | ||
| Stream<BugChecker> pluginChecks = | ||
| ServiceLoader.load(BugChecker.class).stream().map(ServiceLoader.Provider::get); | ||
| Stream<String> pluginCheckNames = | ||
| StreamEx.of(pluginChecks).flatMap(bugchecker -> bugchecker.allNames().stream()); | ||
|
|
||
| Stream<BugCheckerInfo> builtInChecks = BuiltInCheckerSuppliers.allChecks().getAllChecks().values().stream(); | ||
| Stream<String> builtInCheckNames = | ||
| StreamEx.of(builtInChecks).flatMap(bugchecker -> bugchecker.allNames().stream()); | ||
|
|
||
| return Stream.concat(pluginCheckNames, builtInCheckNames).collect(Collectors.toSet()); | ||
| }); | ||
|
|
||
| public static Set<String> allBugcheckerNames() { | ||
| return cachedAllBugcheckerNames.get(); | ||
| } | ||
|
|
||
| private AllErrorprones() {} | ||
| } |
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.
We have to specify how we collect duplicate keys here, or else we get an error