openrewrite / rewrite-python

OpenRewrite recipes for Python.
Apache License 2.0
12 stars 5 forks source link

Add `PythonCoreApplicationEnvironment` that extends the `CoreApplicationEnvironment` #56

Open traceyyoshima opened 1 year ago

traceyyoshima commented 1 year ago

The CoreApplicationEnvironment construction registers various required application services and provides access to the instances of each service for additional configurations.

Important fields in the CoreApplicationEnvironment:

In the extended CoreApplicationEnvironment register the appropriate file types and parser definitions:

        registerFileType(PythonFileType.INSTANCE, "py");
        registerParserDefinition(PythonLanguage.INSTANCE, new PythonParserDefinition());

        // TODO: add pyi support.
//        registerFileType(PyiFileType.INSTANCE, "pyi");
//        registerParserDefinition(PyiLanguageDialect.getInstance(), new PyiParserDefinition());

The CoreApplicationEnvironment is used to create the CoreProjectEnvironment. The CoreProjectEnvironment will automatically register various services for the project.

An instance of the CoreProjectEnvironment allows the project and application environment to be configured before parsing. Each service necessary for type attribution to resolve must be registered through the application environment, project, or extensions.