Git Product home page Git Product logo

rewrite-docs's People

Contributors

aegershman avatar fupgang avatar gadams00 avatar gitbook-bot avatar jkschneider avatar jonesbusy avatar jsoref avatar knutwannheden avatar kunli2 avatar kvandenhoute avatar lrkwz avatar mattnworb avatar mckratt avatar mike-solomon avatar namyalg avatar okundzich avatar pstreef avatar pway99 avatar sambsnyd avatar shanman190 avatar shaoranlaos avatar simonverhoeven avatar sjungling avatar sofiabrittoschwartz avatar sullis avatar tarilabs avatar timtebeek avatar tkvangorder avatar traceyyoshima avatar xshen053 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

rewrite-docs's Issues

ChangeFieldType example

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

update the groupId and artifactId of a dependency

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.

Delete argument example

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

Finishing Checkstyle Docs

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.

Error in AutoFormat docs (and maybe in more sections)

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.

Refactor: Defining Programmatically

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.

Docs: Group recipe descriptions into different types, ex java core, maven, xml, Junit5, Spring2, cleanup

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).

Docs: Getting Started Java and Maven

https://app.gitbook.com/@openrewrite/s/openrewrite/rewrite-7/getting-started/getting-started-java-and-maven

Audience: New to rewrite
Goal: Learn by doing
Outcomes:

  • Clone sample project or use their own
  • Configure everything they need: IDE, plugins, dependencies, https://github.com/openrewrite/rewrite point to prerequisites here
  • Get familiar with the rewrite core recipes, plugin commands, yaml syntax, activate recipes, execute, see diffs, etc.

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

Error in Java Definition of ComplexMethodTransformation

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);
    }
}

Simplify Code Examples for Checkstyle Docs

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) {
        }
    }
}

Change method name

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.

Comprehensive example for Change method target to static

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.

RemoveImport works, but AddImport does not

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

Minor note, UseStaticImports uses incorrect yaml indent; in 7.x has different parameter key

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

Need to keep links to join the community slack up to date

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.