-
Notifications
You must be signed in to change notification settings - Fork 763
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Register Fir checkers to compiler processor
Summary: $title Fir compiler uses the FirExtensionRegistrar for all Fir extensions, which helps simplify the installation site in the compiler processor Reviewed By: fbcbl Differential Revision: D65447524 fbshipit-source-id: 4d777831f1f4b7a375b4e8b511140449b90ef019
- Loading branch information
1 parent
cb4d0bc
commit 3c1e024
Showing
3 changed files
with
92 additions
and
0 deletions.
There are no files selected for viewing
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
55 changes: 55 additions & 0 deletions
55
...mpiler-plugin/compiler/src/main/kotlin/com/facebook/litho/k2/LithoFirCheckersExtension.kt
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,55 @@ | ||
/* | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* 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.facebook.litho.k2 | ||
|
||
import com.facebook.litho.common.LithoNames | ||
import com.facebook.litho.k2.diagnostics.LithoFirHookUsageChecker | ||
import org.jetbrains.kotlin.fir.FirSession | ||
import org.jetbrains.kotlin.fir.analysis.checkers.expression.ExpressionCheckers | ||
import org.jetbrains.kotlin.fir.analysis.extensions.FirAdditionalCheckersExtension | ||
import org.jetbrains.kotlin.fir.extensions.FirDeclarationPredicateRegistrar | ||
import org.jetbrains.kotlin.fir.extensions.predicate.DeclarationPredicate | ||
|
||
/** | ||
* Responsible for supplying additional checkers that will be called when the compiler analyses | ||
* code. It can also report additional errors or warnings that can be visualized by the IDE. | ||
* | ||
* There are different kinds of checkers available, and can be as fine-grained as possible. | ||
* | ||
* @see [FirAdditionalCheckersExtension] | ||
* @see [LithoFirHookUsageChecker] | ||
*/ | ||
class LithoFirCheckersExtension(session: FirSession) : FirAdditionalCheckersExtension(session) { | ||
|
||
override val expressionCheckers: ExpressionCheckers = | ||
object : ExpressionCheckers() { | ||
override val functionCallCheckers = setOf(LithoFirHookUsageChecker()) | ||
} | ||
|
||
override fun FirDeclarationPredicateRegistrar.registerPredicates() { | ||
register(predicate) | ||
} | ||
|
||
/** | ||
* Defined a set of predicates that will be used to filter the declarations that should trigger | ||
* the checkers defined in this extension. | ||
*/ | ||
private val predicate = | ||
DeclarationPredicate.create { | ||
metaAnnotated(LithoNames.Unconditional.asSingleFqName(), includeItself = false) | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
...piler-plugin/compiler/src/main/kotlin/com/facebook/litho/k2/LithoFirExtensionRegistrar.kt
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,34 @@ | ||
/* | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* 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.facebook.litho.k2 | ||
|
||
import org.jetbrains.kotlin.fir.extensions.FirExtensionRegistrar | ||
|
||
/** | ||
* Responsible for registering all FIR specific extensions for Litho to the compiler. | ||
* | ||
* It exposes a shorthand API that makes it easy to register extensions correctly. The API | ||
* implicitly passes an [FirSession] object to the extension constructor, and also provides | ||
* mechanisms to pass explicit dependencies as necessary. | ||
* | ||
* @see [LithoFirCheckersExtension] | ||
*/ | ||
class LithoFirExtensionRegistrar : FirExtensionRegistrar() { | ||
override fun ExtensionRegistrarContext.configurePlugin() { | ||
+::LithoFirCheckersExtension | ||
} | ||
} |