Christoffer Quist Adamsen | 9684aa3 | 2021-01-21 16:32:29 +0100 | [diff] [blame] | 1 | // Copyright (c) 2020, the R8 project authors. Please see the AUTHORS file |
| 2 | // for details. All rights reserved. Use of this source code is governed by a |
| 3 | // BSD-style license that can be found in the LICENSE file. |
| 4 | package com.android.tools.r8.synthesis; |
| 5 | |
| 6 | import com.android.tools.r8.graph.DexClass; |
| 7 | import com.android.tools.r8.graph.DexClasspathClass; |
| 8 | import com.android.tools.r8.graph.DexType; |
Christoffer Quist Adamsen | 7e2a9d4 | 2023-03-28 13:05:04 +0200 | [diff] [blame] | 9 | import com.android.tools.r8.graph.lens.NonIdentityGraphLens; |
Christoffer Quist Adamsen | 9684aa3 | 2021-01-21 16:32:29 +0100 | [diff] [blame] | 10 | import com.android.tools.r8.synthesis.SyntheticNaming.SyntheticKind; |
| 11 | import java.util.function.Function; |
| 12 | |
| 13 | /** |
| 14 | * Reference to a synthetic class item. |
| 15 | * |
| 16 | * <p>This class is internal to the synthetic items collection, thus package-protected. |
| 17 | */ |
| 18 | class SyntheticClasspathClassReference |
| 19 | extends SyntheticClassReference< |
| 20 | SyntheticClasspathClassReference, SyntheticClasspathClassDefinition, DexClasspathClass> { |
| 21 | |
| 22 | SyntheticClasspathClassReference(SyntheticKind kind, SynthesizingContext context, DexType type) { |
| 23 | super(kind, context, type); |
| 24 | } |
| 25 | |
| 26 | @Override |
| 27 | SyntheticClasspathClassDefinition lookupDefinition(Function<DexType, DexClass> definitions) { |
| 28 | DexClass clazz = definitions.apply(type); |
| 29 | if (clazz == null) { |
| 30 | return null; |
| 31 | } |
| 32 | assert clazz.isClasspathClass(); |
| 33 | return new SyntheticClasspathClassDefinition(getKind(), getContext(), clazz.asClasspathClass()); |
| 34 | } |
| 35 | |
| 36 | @Override |
Christoffer Quist Adamsen | eb5af05 | 2021-02-19 08:27:05 +0100 | [diff] [blame] | 37 | SyntheticClasspathClassReference internalRewrite( |
| 38 | SynthesizingContext rewrittenContext, NonIdentityGraphLens lens) { |
Christoffer Quist Adamsen | 9684aa3 | 2021-01-21 16:32:29 +0100 | [diff] [blame] | 39 | assert type == lens.lookupType(type) |
| 40 | : "Unexpected classpath rewrite of type " + type.toSourceString(); |
Christoffer Quist Adamsen | eb5af05 | 2021-02-19 08:27:05 +0100 | [diff] [blame] | 41 | assert getContext() == rewrittenContext |
| 42 | : "Unexpected classpath rewrite of context type " + getContext(); |
Christoffer Quist Adamsen | 9684aa3 | 2021-01-21 16:32:29 +0100 | [diff] [blame] | 43 | return this; |
| 44 | } |
| 45 | } |