-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding Java 11 recipe -RemovedSecurityManagerMethods (#458)
* adding Java 11 recipe -RemovedSecurityManagerMethods * adding the .yml file * deleting test file * updating recipes to only work with void returns * updating description * removed extra ( & updated description * Apply formatter for consistency --------- Co-authored-by: anuram <[email protected]> Co-authored-by: Tim te Beek <[email protected]>
- Loading branch information
1 parent
e954a3e
commit 2e51b86
Showing
2 changed files
with
60 additions
and
0 deletions.
There are no files selected for viewing
59 changes: 59 additions & 0 deletions
59
src/main/java/org/openrewrite/java/migrate/RemovedSecurityManagerMethods.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,59 @@ | ||
/* | ||
* Copyright 2024 the original author or authors. | ||
* <p> | ||
* 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 | ||
* <p> | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* <p> | ||
* 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 org.openrewrite.java.migrate; | ||
|
||
import org.openrewrite.ExecutionContext; | ||
import org.openrewrite.Recipe; | ||
import org.openrewrite.TreeVisitor; | ||
import org.openrewrite.java.JavaTemplate; | ||
import org.openrewrite.java.JavaVisitor; | ||
import org.openrewrite.java.MethodMatcher; | ||
import org.openrewrite.java.tree.J; | ||
|
||
public class RemovedSecurityManagerMethods extends Recipe { | ||
@Override | ||
public String getDisplayName() { | ||
return "Replace deprecated methods in`SecurityManager`"; | ||
} | ||
|
||
@Override | ||
public String getDescription() { | ||
return "Replace `SecurityManager` methods `checkAwtEventQueueAccess()`, `checkSystemClipboardAccess()`," + | ||
" `checkMemberAccess()` and `checkTopLevelWindow()` deprecated in Java SE 11 by" + | ||
" `checkPermission(new java.security.AllPermission())`."; | ||
} | ||
|
||
@Override | ||
public TreeVisitor<?, ExecutionContext> getVisitor() { | ||
return new JavaVisitor<ExecutionContext>() { | ||
private final MethodMatcher METHOD_PATTERN_QUE = new MethodMatcher("java.lang.SecurityManager checkAwtEventQueueAccess()", false); | ||
private final MethodMatcher METHOD_PATTERN_CLIP = new MethodMatcher("java.lang.SecurityManager checkSystemClipboardAccess()", false); | ||
private final MethodMatcher METHOD_PATTERN_MEMBER = new MethodMatcher("java.lang.SecurityManager checkMemberAccess(..)", false); | ||
private final MethodMatcher METHOD_PATTERN_WINDOW = new MethodMatcher("java.lang.SecurityManager checkTopLevelWindow(..)", false); | ||
|
||
@Override | ||
public J visitMethodInvocation(J.MethodInvocation method, ExecutionContext ctx) { | ||
if (METHOD_PATTERN_QUE.matches(method) || METHOD_PATTERN_CLIP.matches(method) || METHOD_PATTERN_MEMBER.matches(method) || METHOD_PATTERN_WINDOW.matches(method)) { | ||
return JavaTemplate.builder("checkPermission(new java.security.AllPermission())") | ||
.imports("java.security.AllPermission") | ||
.build().apply(updateCursor(method), | ||
method.getCoordinates().replaceMethod()); | ||
} | ||
return method; | ||
} | ||
}; | ||
} | ||
} |
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