openrewrite / rewrite-docs Goto Github PK
View Code? Open in Web Editor NEWStores the markdown documents used to generate docs.openrewrite.org
Home Page: https://docs.openrewrite.org
License: Apache License 2.0
Stores the markdown documents used to generate docs.openrewrite.org
Home Page: https://docs.openrewrite.org
License: Apache License 2.0
I've tried to follow this example https://docs.openrewrite.org/java/refactoring-java-source-code/changefieldtype#yaml-definition
But I get following error:
Failed to execute goal org.openrewrite.maven:rewrite-maven-plugin:2.1.1:fix (default-cli) on project rewrite-example: Execution default-cli of goal org.openrewrite.maven:rewrite-maven-plugin:2.1.1:fix failed: Problem parsing rewrite configuration from: file:/Users/guseyn/java-projects/rewrite-example/recipes/rewrite2.yml
[ERROR] visitor was '{org.openrewrite.java.ChangeFieldType=null, type=java.util.logging.Logger, targetType=org.slf4j.Logger}' but it must be constructable
Good afternoon,
Is there any recipe or set of recipes to be able to change the groupId and artifactId of existing dependencies in the POM to a new groupId and artifactId?
As far as I have been able to see in the documentation, you can only change the version or scope of a dependency, it would be interesting if there was an option to also change the groupId and artifactId.
To be consistent with the code (e.g.: JavaRefactorVisitor), we should describe visitors that alter the things they visit as "refactoring" rather than "transforming".
This includes headings and sections like Transforming Java Code as well as individual visitor descriptions, e.g.: AddAnnotation being described as a "transforming" visitor.
I've tried to follow this example: https://docs.openrewrite.org/java/refactoring-java-source-code/deletemethodargument
But I get error:
Failed to execute goal org.openrewrite.maven:rewrite-maven-plugin:2.1.1:fix (default-cli) on project rewrite-example: Execution default-cli of goal org.openrewrite.maven:rewrite-maven-plugin:2.1.1:fix failed: Problem parsing rewrite configuration from: file:/Users/guseyn/java-projects/rewrite-example/recipes/rewrite4.yml
[ERROR] visitor was '{org.openrewrite.java.DeleteMethodArgument=null, method=ch.qos.logback.classic.Logger debug(org.slf4j.Marker,..), index=0}' but it must be constructable
The following Checkstyle docs need some work:
SpansMultipleLines
- This file has very little that is done because it is non-standard in many ways. I know we're talking about moving this to another location in the docs, but something needs to be done to either hide it until we do that or make it look presentable.
EmptyStatement
- This file doesn't have a complete explanation for the example portion.
CovariantEquals
- This file doesn't have anything in the example explanation. It is the only file without something trying to explain the example.
JavaRefactorVisitor
has visitMethod()
and visitMethodInvocation()
, seems like return super.visitMethodDecl(method);
made sense in previous versions of API but not now.
I think visitMethod
should be instead in docs.
Consider if can be recovered from 6.x docs
Specifications/descriptions of recipes that contain options can be enhances by providing an example of how to configure this recipe in yaml.
In this example https://docs.openrewrite.org/java/refactoring-java-source-code/reordermethodarguments#java-definition there is a typo:
ReorderMethodArguments rma = new InsertMethodArgument();
It should be fixed to:
ReorderMethodArguments rma = new ReorderMethodArguments();
It fails because some line break issues:
org.opentest4j.AssertionFailedError:
expected: "package com.yourorg;
class A {
public String hello() {
return "Hello from com.yourorg.A!";
}
}"
but was: "package com.yourorg;
class A {
public String hello() {
return "Hello from com.yourorg.A!";
}
}"
The test was executed on a Windows system.
http://docs.openrewrite.org|docs.openrewrite.org is missing the recipe reference section. I must have messed it up last time I revved it. Note to self to fix it
https://moderneinc.slack.com/archives/C01VADFPJQZ/p1657893025714799
Perhaps add links to external docs? Add this to all options that use pointcut expressions like change method.
I try to reproduce this example: https://docs.openrewrite.org/v1beta/refactor#defining-programmatically
I've created new sample project for that: https://github.com/Guseyn/rewrite-java-definitions
I just don't understand how to create properly Iterable<SourceFile> sources
and Iterable<RefactorVisitor<?>> visitors
, so I can get Collection<Change> changeSet
.
That's how I get sources
:
Iterable<SourceFile> sources = SourceFiles.fromDirectory("src/sample-project");
public class SourceFiles {
public static List<SourceFile> fromDirectory(String sourceDirectory) throws IOException {
JavaParser javaParser = JavaParser.fromJavaVersion().build();
List<Path> javaSources = new ArrayList<>(listJavaSources(sourceDirectory));
return new ArrayList<>(javaParser.parse(javaSources, Paths.get(sourceDirectory)));
}
private static List<Path> listJavaSources(String sourceDirectory) throws IOException {
File sourceDirectoryFile = new File(sourceDirectory);
if (!sourceDirectoryFile.exists()) {
return emptyList();
}
Path sourceRoot = sourceDirectoryFile.toPath();
return Files.walk(sourceRoot)
.filter(f -> !Files.isDirectory(f) && f.toFile().getName().endsWith(".java"))
.collect(toList());
}
}
And that works, when I use debugger I actually see parsed java structures:
This is how I define visitors
:
Iterable<RefactorVisitor<?>> visitors = new ArrayList<>(){{
add(new ImportSet());
}};
public class ImportSet extends JavaRefactorVisitor {
public J visitClassDecl(J.ClassDecl clazz) {
maybeAddImport("java.util.Set");
return super.visitClassDecl(clazz);
}
}
But when I want to get changes:
Refactor refactor = new Refactor().visit(visitors);
Collection<Change> changes = refactor.fix(sources);
for (Change change : changes) {
Path file = Paths.get("src/sample-project/after").resolve(change.getOriginal().getSourcePath());
try (BufferedWriter sourceFileWriter = Files.newBufferedWriter(file)) {
sourceFileWriter.write(change.getFixed().print());
}
}
size of changes is zero. I think I do something wrong.
It'd be great to see whole example of using java definitions in the code.
I've tried copying the code blocks from https://docs.openrewrite.org/tutorials/writing-a-java-refactoring-recipe by using the copy button on the top right corner as well as by manually selecting the text in the code block and trying to copy it with CTRL+C as well as with the browser context menu. Nothing works. With Chrome it works on Windows - Linux I didn't check.
https://app.gitbook.com/@openrewrite/s/openrewrite/rewrite-7/concepts-and-explanations
Freeform explanation of core concepts of Rewrite for people who either want to learn about rewrite to make use of existing recipes or create new ones.
Add documentation for how to use the rewrite
namespaced properties added via: openrewrite/rewrite-maven-plugin#226
Note. openrewrite/rewrite-maven-plugin#314 how to run only a specific recipe
The list of recipe descriptions is very long now and it's hard to understand which groups of recipes we have now.
This is a pre-requisite for documenting specific guides for using dependency management recipes, SpringBoot migration, etc. These guides would point to their group of recipes rather than having to list them individually (and potentially drift when additional recipes are added to their group).
Audience: New to rewrite
Goal: Learn by doing
Outcomes:
Follow up tutorials and guides will assume this base level of knowledge of rewrite, project configuration etc.
Also some material here
https://app.gitbook.com/@openrewrite/s/openrewrite/rewrite-7/reference-1/maven/rewrite-maven-plugin
https://app.gitbook.com/@openrewrite/s/openrewrite/getting-started/rewrite-gradle-plugin
So people can add and exclude recipes from pre-built bundles.
Point to https://docs.openrewrite.org/tutorials/authoring-declarative-yaml-recipes and https://docs.openrewrite.org/reference/yaml-format-reference to help users activate the recipe they will produce.
For example, ability to get this recipe list in the Spring Boot 2.x migration as yaml
If we want to have transformation like in "after" section of this example https://docs.openrewrite.org/java/refactoring-java-source-code/autoformat#example, we need a bit different Java Definition:
public class ComplexMethodTransformation extends JavaRefactorVisitor {
public J visitMethod(J.MethodDecl method) {
// do some things to modify the method declaration
// or body in some significant way and don't worry about formatting...
// this will fix the indentation of the method declaration to be consistent with its surroundings
andThen(new AutoFormat(method));
return super.visitMethod(method);
}
public J visitMultiVariable(J.VariableDecls variable) {
// do some things to modify the variable declaration
// this will fix the indentation of the variable declaration to be consistent with its surroundings
andThen(new AutoFormat(variable));
return super.visitMultiVariable(variable);
}
}
The example before and after code provided in Checkstyle docs was pulled directly from the corresponding test files. This means many of them are rather complicated and cover many obscure situations that aren't helpful to include in the documentation. These code snippets should be simplified to the bare minimum to make it as easy and obvious as possible to see what changes were made.
It could also be helpful to rename some of the classes and functions, especially in the more complicated examples, in order to make the explanations of those examples more human readable. Take the following code snippet from Checkstyle/HiddenField:
public class A extends B {
int n;
int n1;
class C {
public void foo(int n) {
int n1 = 2;
}
}
static class D {
public void foo(int n) {
}
}
}
If instead we used something like the following example it would be much easier to explain what's going on.
public class Dog extends Animal {
String name;
class Breed {
String breed;
public void setBreed(String name) {
this.breed = name;
}
}
static class ThingsDogsDo {
public boolean canGetToy(String name) {
}
}
}
This section may not be necessary depending what will go into Getting Started Guides.
https://app.gitbook.com/@openrewrite/s/openrewrite/rewrite-7/getting-started
Our Rewrite Maven Plugin describes the basic usage and concepts related to using our Maven plugin. We need a similar guide for the Gradle plugin.
In documentation, it mentioned that we can add argument -DactiveRecipe=<receipe_name> to activate the receipt. The argument should be in plural. i.e. -DactiveRecipes=<receipe_name>
I was on this page and the link method-patterns gives me a 404 as it links to README.md instead of method-patterns.md
In this example https://docs.openrewrite.org/java/refactoring-java-source-code/changemethodname I get exception: NoSuchMethodError
. I use proper packages in definition, but it does not work anyway.
Only when I use following "before and after" it works fine:
// before
package org.openrewrite.before;
public class E {
void foo() {
}
}
//after
package org.openrewrite.after;
public class E {
void bar() {
}
}
with changed definition
ChangeMethodName cmn = new ChangeMethodName();
cmn.setMethod("org.openrewrite.before.E foo()");
cmn.setName("bar");
RefactorProcessor.run(cmn, "E.java");
As far as I understand it's java parser error.
Converted from note, added for issue-tracking
I would like to see a comprehensive example for Change method target to static because I think I have a use case for it but the documentation doesn't tell me enough on how to do it.
I have the following code:
MyCustomLogger logger = new MyCustomLogger(MyClass.class);
That I want to convert to proper SLF4J loggers so it would be:
Logger logger = LoggerFactory.getLogger(MyClass.class);
which I think this Recipe would cover but not sure.
Many of our documents have a "YAML Definition" heading which shows a yaml snippet that only declares the visitor without including it in a recipe. This is a source of confusion for people trying to adopt openrewrite.
Example of what these sections should look like: https://github.com/openrewrite/rewrite-docs/blob/master/java/checkstyle/covariantequals.md#yaml-definition
Describe the setup necessary for writing a new recipe as well as how to package and distribute it to recipe consumers.
When I do smth like this:
RemoveImport rmi = new RemoveImport();
rmi.setType("org.slf4j.MarkerFactory");
Collection<Change> changes = new Refactor().visit(rmi).fix(cus);
it works, but when I do:
AddImport adi = new AddImport();
adi.setType("org.slf4j.MarkerFactory");
Collection<Change> changes = new Refactor().visit(adi).fix(cus);
it does get any changes
Gradle equivalent of #21
Listing of all the recipes that are available in different modules. Autogenerated from code. Rewrite describe command output formatted as markdown on disk.
This isn't a priority, I don't have time to fix it just right yet, I'm just logging it because I spotted it and it may be in other places. Feel free to close whenever.
The UseStaticImport
6.x reference docs has broken indentation on the parameter value https://github.com/openrewrite/rewrite-docs/blob/926f06a694cab31b2566d0f7c92c572cfaf5d4a5/reference/java/refactoring-java-source-code/usestaticimport.md#yaml-definition
specifically, this:
type: specs.openrewrite.org/v1beta/visitor
name: com.yourorg.UseStaticJUnitAsserts
visitors:
- org.openrewrite.java.UseStaticImport:
method: 'org.junit.jupiter.api.Assertions assert*(..)'
should be this:
type: specs.openrewrite.org/v1beta/visitor
name: com.yourorg.UseStaticJUnitAsserts
visitors:
- org.openrewrite.java.UseStaticImport:
method: 'org.junit.jupiter.api.Assertions assert*(..)' # <-- note the indentation
And, also minor, but for future reference, in 7.x, method
changes to methodPattern
https://github.com/openrewrite/rewrite/blob/d7a15d40a20088f7a98fcc603d61216c677b621a/rewrite-java/src/main/java/org/openrewrite/java/UseStaticImport.java#L38
Again, not a big deal, I'm just pointing it out for visibility. Feel free to close whenever
Invites to join slack workspaces expire after 30 days with no option to make them valid for longer.
I did a bit of searching, and found four places where we have expired links to join our community slack:
https://github.com/openrewrite/rewrite/blob/master/README.md
https://github.com/openrewrite/rewrite-java-8/blob/master/README.md
https://github.com/openrewrite/rewrite-docs/blob/master/reference/java/semantic-search-for-java/semanticallyequal.md
https://github.com/openrewrite/rewrite-docs/blob/master/tutorials/authoring-java-refactoring-visitors.md
As long as we are posting a public link to join our community slack we need to update it once every 30 days
Per issue openrewrite/rewrite-maven-plugin#331 the next release of rewrite-maven-plugin will support runNoFork and dryRunNoFork.
Please update the documentation for "executions" from "dryRun" to "dryRunNoFork".
https://github.com/openrewrite/rewrite-docs/blob/master/reference/rewrite-maven-plugin.md
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.