/* * Copyright (C) 2022 The Android Open Source Project * * 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.android.libraries.pcc.chronicle.api.optics /** * A manifest of all known optics which is capable of composing bespoke, nested optics for a given * [OpticalAccessPath]. */ interface OpticsManifest { /** * Composes a [Traversal] for a given [accessPath]. * * If one can't be composed (either the access path is invalid, or the manifest doesn't contain * sufficient optics to compose a satisfactory result - an exception will be thrown). * * TODO(b/204939436): Consider making an API like this (or something nicer) - possibly as * extension funs. * ``` * optics[AppOps::class]["appOps"]["lastAccessTimeMs"] * optics[AppOps::class]["appOps.lastAccessTimeMs"] * ``` */ fun composeTraversal( accessPath: OpticalAccessPath, sourceEntityType: Class, targetEntityType: Class, sourceFieldType: Class, targetFieldType: Class, ): Traversal } /** * Assemble a polymorphic [Traversal] for a given [accessPath]. * * If one can't be assembled (either the access path is invalid, or the manifest doesn't contain * sufficient optics to compose a satisfactory result - an exception will be thrown). */ inline fun OpticsManifest.composePoly( accessPath: OpticalAccessPath ): Traversal { return composeTraversal(accessPath, S::class.java, T::class.java, A::class.java, B::class.java) } /** * Assemble a monomorphic [Traversal] for a given [accessPath]. * * If one can't be assembled (either the access path is invalid, or the manifest doesn't contain * sufficient optics to compose a satisfactory result - an exception will be thrown). */ inline fun OpticsManifest.composeMono( accessPath: OpticalAccessPath ): Traversal { return composeTraversal(accessPath, S::class.java, S::class.java, A::class.java, A::class.java) }