Remove remaining deprecated flag usage
Bug: b/341991457
Change-Id: I461e7d40ab44bac51be3ac8ab2484546ba942c97
diff --git a/src/main/java/com/android/tools/r8/kotlin/KotlinContractInfo.java b/src/main/java/com/android/tools/r8/kotlin/KotlinContractInfo.java
index 1306045..4fb6774 100644
--- a/src/main/java/com/android/tools/r8/kotlin/KotlinContractInfo.java
+++ b/src/main/java/com/android/tools/r8/kotlin/KotlinContractInfo.java
@@ -4,7 +4,6 @@
package com.android.tools.r8.kotlin;
-import static com.android.tools.r8.kotlin.KotlinMetadataUtils.consume;
import static com.android.tools.r8.kotlin.KotlinMetadataUtils.rewriteList;
import static com.android.tools.r8.utils.FunctionUtils.forEachApply;
@@ -54,7 +53,8 @@
if (this == NO_EFFECT) {
return false;
}
- KmContract kmContract = consume(new KmContract(), consumer);
+ KmContract kmContract = new KmContract();
+ consumer.accept(kmContract);
return rewriteList(appView, effects, kmContract.getEffects(), KotlinEffectInfo::rewrite);
}
}
diff --git a/src/main/java/com/android/tools/r8/kotlin/KotlinEffectInfo.java b/src/main/java/com/android/tools/r8/kotlin/KotlinEffectInfo.java
index 0a973a1..6fc3950 100644
--- a/src/main/java/com/android/tools/r8/kotlin/KotlinEffectInfo.java
+++ b/src/main/java/com/android/tools/r8/kotlin/KotlinEffectInfo.java
@@ -4,7 +4,6 @@
package com.android.tools.r8.kotlin;
-import static com.android.tools.r8.kotlin.KotlinMetadataUtils.consume;
import static com.android.tools.r8.kotlin.KotlinMetadataUtils.rewriteList;
import static com.android.tools.r8.utils.FunctionUtils.forEachApply;
@@ -52,7 +51,8 @@
}
boolean rewrite(Consumer<KmEffect> consumer, AppView<?> appView) {
- KmEffect kmEffect = consume(new KmEffect(type, invocationKind), consumer);
+ KmEffect kmEffect = new KmEffect(type, invocationKind);
+ consumer.accept(kmEffect);
boolean rewritten = conclusion.rewrite(kmEffect::setConclusion, appView);
rewritten |=
rewriteList(
diff --git a/src/main/java/com/android/tools/r8/kotlin/KotlinFlagUtils.java b/src/main/java/com/android/tools/r8/kotlin/KotlinFlagUtils.java
index 301ac65..d541b5d 100644
--- a/src/main/java/com/android/tools/r8/kotlin/KotlinFlagUtils.java
+++ b/src/main/java/com/android/tools/r8/kotlin/KotlinFlagUtils.java
@@ -4,6 +4,8 @@
package com.android.tools.r8.kotlin;
+import java.util.HashMap;
+import java.util.Map;
import kotlin.metadata.Attributes;
import kotlin.metadata.KmClass;
import kotlin.metadata.KmConstructor;
@@ -11,10 +13,65 @@
import kotlin.metadata.KmFunction;
import kotlin.metadata.KmProperty;
import kotlin.metadata.KmPropertyAccessorAttributes;
+import kotlin.metadata.KmType;
+import kotlin.metadata.KmTypeAlias;
+import kotlin.metadata.KmTypeParameter;
+import kotlin.metadata.KmValueParameter;
import kotlin.metadata.jvm.JvmAttributes;
public class KotlinFlagUtils {
+ private static final String ANNOTATIONS_KEY = "hasAnnotations";
+ private static final String VISIBILITY_KEY = "visibility";
+ private static final String MODALITY_KEY = "modality";
+ private static final String KIND_KEY = "kind";
+ private static final String INNER_KEY = "inner";
+ private static final String DATA_KEY = "data";
+ private static final String VALUE_KEY = "value";
+ private static final String FUN_INTERFACE_KEY = "funInterface";
+ private static final String ENUM_ENTRIES_KEY = "enumEntries";
+ private static final String VAR_KEY = "var";
+ private static final String CONST_KEY = "const";
+ private static final String LATE_INIT_KEY = "lateInit";
+ private static final String CONSTANT_KEY = "hasConstant";
+ private static final String EXTERNAL_KEY = "external";
+ private static final String DELEGATED_KEY = "delegated";
+ private static final String EXPECT_KEY = "expect";
+ private static final String NOT_DEFAULT_KEY = "notDefault";
+ private static final String INLINE_KEY = "inline";
+ private static final String SECONDARY_KEY = "secondary";
+ private static final String NON_STABLE_PARAMETER_NAMES_KEY = "nonStableParameterNames";
+ private static final String NEGATED_KEY = "negated";
+ private static final String NULL_CHECK_PREDICATE_KEY = "nullCheckPredicate";
+ private static final String OPERATOR_KEY = "operator";
+ private static final String INFIX_KEY = "infix";
+ private static final String TAIL_REC_KEY = "tailRec";
+ private static final String SUSPEND_KEY = "suspend";
+ private static final String NULLABLE_KEY = "nullable";
+ private static final String DEFINITELY_NON_NULL_KEY = "definitelyNonNull";
+ private static final String DECLARES_DEFAULT_VALUE_KEY = "declaresDefaultValue";
+ private static final String CROSS_INLINE_KEY = "crossInline";
+ private static final String NO_INLINE_KEY = "noInline";
+ private static final String REIFIED_KEY = "reified_key";
+
+ public static Map<String, Object> extractFlags(KmProperty src) {
+ Map<String, Object> map = new HashMap<>();
+ map.put(ANNOTATIONS_KEY, Attributes.getHasAnnotations(src));
+ map.put(VISIBILITY_KEY, Attributes.getVisibility(src));
+ map.put(MODALITY_KEY, Attributes.getModality(src));
+ map.put(KIND_KEY, Attributes.getKind(src));
+ map.put(VAR_KEY, Attributes.isVar(src));
+ map.put(CONST_KEY, Attributes.isConst(src));
+ map.put(LATE_INIT_KEY, Attributes.isLateinit(src));
+ map.put(CONSTANT_KEY, Attributes.getHasConstant(src));
+ map.put(EXTERNAL_KEY, Attributes.isExternal(src));
+ map.put(DELEGATED_KEY, Attributes.isDelegated(src));
+ map.put(EXPECT_KEY, Attributes.isExpect(src));
+
+ map.put("movedFromInterfaceCompanion", JvmAttributes.isMovedFromInterfaceCompanion(src));
+ return map;
+ }
+
static void copyAllFlags(KmProperty src, KmProperty dest) {
Attributes.setHasAnnotations(dest, Attributes.getHasAnnotations(src));
Attributes.setVisibility(dest, Attributes.getVisibility(src));
@@ -32,6 +89,31 @@
dest, JvmAttributes.isMovedFromInterfaceCompanion(src));
}
+ public static Map<String, Object> extractFlags(KmType src) {
+ Map<String, Object> map = new HashMap<>();
+ map.put(NULLABLE_KEY, Attributes.isNullable(src));
+ map.put(SUSPEND_KEY, Attributes.isSuspend(src));
+ map.put(DEFINITELY_NON_NULL_KEY, Attributes.isDefinitelyNonNull(src));
+ return map;
+ }
+
+ static void copyAllFlags(KmType src, KmType dest) {
+ Attributes.setNullable(dest, Attributes.isNullable(src));
+ Attributes.setSuspend(dest, Attributes.isSuspend(src));
+ Attributes.setDefinitelyNonNull(dest, Attributes.isDefinitelyNonNull(src));
+ }
+
+ public static Map<String, Object> extractFlags(KmPropertyAccessorAttributes src) {
+ Map<String, Object> map = new HashMap<>();
+ map.put(ANNOTATIONS_KEY, Attributes.getHasAnnotations(src));
+ map.put(VISIBILITY_KEY, Attributes.getVisibility(src));
+ map.put(MODALITY_KEY, Attributes.getModality(src));
+ map.put(NOT_DEFAULT_KEY, Attributes.isNotDefault(src));
+ map.put(EXTERNAL_KEY, Attributes.isExternal(src));
+ map.put(INLINE_KEY, Attributes.isInline(src));
+ return map;
+ }
+
static void copyAllFlags(KmPropertyAccessorAttributes src, KmPropertyAccessorAttributes dest) {
Attributes.setHasAnnotations(dest, Attributes.getHasAnnotations(src));
Attributes.setVisibility(dest, Attributes.getVisibility(src));
@@ -41,6 +123,25 @@
Attributes.setInline(dest, Attributes.isInline(src));
}
+ public static Map<String, Object> extractFlags(KmClass src) {
+ Map<String, Object> map = new HashMap<>();
+ map.put(ANNOTATIONS_KEY, Attributes.getHasAnnotations(src));
+ map.put(VISIBILITY_KEY, Attributes.getVisibility(src));
+ map.put(MODALITY_KEY, Attributes.getModality(src));
+ map.put(KIND_KEY, Attributes.getKind(src));
+ map.put(INNER_KEY, Attributes.isInner(src));
+ map.put(DATA_KEY, Attributes.isData(src));
+ map.put(EXTERNAL_KEY, Attributes.isExternal(src));
+ map.put(EXPECT_KEY, Attributes.isExpect(src));
+ map.put(VALUE_KEY, Attributes.isValue(src));
+ map.put(FUN_INTERFACE_KEY, Attributes.isFunInterface(src));
+ map.put(ENUM_ENTRIES_KEY, Attributes.getHasEnumEntries(src));
+
+ map.put("compiledInCompatibilityMode", JvmAttributes.isCompiledInCompatibilityMode(src));
+ map.put("hasMethodBodiesInInterface", JvmAttributes.getHasMethodBodiesInInterface(src));
+ return map;
+ }
+
static void copyAllFlags(KmClass src, KmClass dest) {
Attributes.setHasAnnotations(dest, Attributes.getHasAnnotations(src));
Attributes.setVisibility(dest, Attributes.getVisibility(src));
@@ -60,6 +161,15 @@
dest, JvmAttributes.getHasMethodBodiesInInterface(src));
}
+ public static Map<String, Object> extractFlags(KmConstructor src) {
+ Map<String, Object> map = new HashMap<>();
+ map.put(ANNOTATIONS_KEY, Attributes.getHasAnnotations(src));
+ map.put(VISIBILITY_KEY, Attributes.getVisibility(src));
+ map.put(SECONDARY_KEY, Attributes.isSecondary(src));
+ map.put(NON_STABLE_PARAMETER_NAMES_KEY, Attributes.getHasNonStableParameterNames(src));
+ return map;
+ }
+
static void copyAllFlags(KmConstructor src, KmConstructor dest) {
Attributes.setHasAnnotations(dest, Attributes.getHasAnnotations(src));
Attributes.setVisibility(dest, Attributes.getVisibility(src));
@@ -67,6 +177,23 @@
Attributes.setHasNonStableParameterNames(dest, Attributes.getHasNonStableParameterNames(src));
}
+ public static Map<String, Object> extractFlags(KmFunction src) {
+ Map<String, Object> map = new HashMap<>();
+ map.put(ANNOTATIONS_KEY, Attributes.getHasAnnotations(src));
+ map.put(KIND_KEY, Attributes.getKind(src));
+ map.put(MODALITY_KEY, Attributes.getModality(src));
+ map.put(OPERATOR_KEY, Attributes.isOperator(src));
+ map.put(INFIX_KEY, Attributes.isInfix(src));
+ map.put(INLINE_KEY, Attributes.isInline(src));
+ map.put(TAIL_REC_KEY, Attributes.isTailrec(src));
+ map.put(EXTERNAL_KEY, Attributes.isExternal(src));
+ map.put(SUSPEND_KEY, Attributes.isSuspend(src));
+ map.put(EXPECT_KEY, Attributes.isExpect(src));
+ map.put(VISIBILITY_KEY, Attributes.getVisibility(src));
+ map.put(NON_STABLE_PARAMETER_NAMES_KEY, Attributes.getHasNonStableParameterNames(src));
+ return map;
+ }
+
static void copyAllFlags(KmFunction src, KmFunction dest) {
Attributes.setHasAnnotations(dest, Attributes.getHasAnnotations(src));
Attributes.setKind(dest, Attributes.getKind(src));
@@ -82,8 +209,53 @@
Attributes.setHasNonStableParameterNames(dest, Attributes.getHasNonStableParameterNames(src));
}
+ public static Map<String, Object> extractFlags(KmEffectExpression src) {
+ Map<String, Object> map = new HashMap<>();
+ map.put(NEGATED_KEY, Attributes.isNegated(src));
+ map.put(NULL_CHECK_PREDICATE_KEY, Attributes.isNullCheckPredicate(src));
+ return map;
+ }
+
static void copyAllFlags(KmEffectExpression src, KmEffectExpression dest) {
Attributes.setNegated(dest, Attributes.isNegated(src));
Attributes.setNullCheckPredicate(dest, Attributes.isNullCheckPredicate(src));
}
+
+ public static Map<String, Object> extractFlags(KmTypeAlias src) {
+ Map<String, Object> map = new HashMap<>();
+ map.put(ANNOTATIONS_KEY, Attributes.getHasAnnotations(src));
+ map.put(VISIBILITY_KEY, Attributes.getVisibility(src));
+ return map;
+ }
+
+ static void copyAllFlags(KmTypeAlias src, KmTypeAlias dest) {
+ Attributes.setHasAnnotations(dest, Attributes.getHasAnnotations(src));
+ Attributes.setVisibility(dest, Attributes.getVisibility(src));
+ }
+
+ public static Map<String, Object> extractFlags(KmValueParameter src) {
+ Map<String, Object> map = new HashMap<>();
+ map.put(ANNOTATIONS_KEY, Attributes.getHasAnnotations(src));
+ map.put(DECLARES_DEFAULT_VALUE_KEY, Attributes.getDeclaresDefaultValue(src));
+ map.put(CROSS_INLINE_KEY, Attributes.isCrossinline(src));
+ map.put(NO_INLINE_KEY, Attributes.isNoinline(src));
+ return map;
+ }
+
+ static void copyAllFlags(KmValueParameter src, KmValueParameter dest) {
+ Attributes.setHasAnnotations(dest, Attributes.getHasAnnotations(src));
+ Attributes.setDeclaresDefaultValue(dest, Attributes.getDeclaresDefaultValue(src));
+ Attributes.setCrossinline(dest, Attributes.isCrossinline(src));
+ Attributes.setNoinline(dest, Attributes.isNoinline(src));
+ }
+
+ public static Map<String, Object> extractFlags(KmTypeParameter src) {
+ Map<String, Object> map = new HashMap<>();
+ map.put(REIFIED_KEY, Attributes.isReified(src));
+ return map;
+ }
+
+ static void copyAllFlags(KmTypeParameter src, KmTypeParameter dest) {
+ Attributes.setReified(dest, Attributes.isReified(src));
+ }
}
diff --git a/src/main/java/com/android/tools/r8/kotlin/KotlinLambdaInfo.java b/src/main/java/com/android/tools/r8/kotlin/KotlinLambdaInfo.java
index 77673c0..d9ecef0 100644
--- a/src/main/java/com/android/tools/r8/kotlin/KotlinLambdaInfo.java
+++ b/src/main/java/com/android/tools/r8/kotlin/KotlinLambdaInfo.java
@@ -4,7 +4,6 @@
package com.android.tools.r8.kotlin;
-import static com.android.tools.r8.kotlin.KotlinMetadataUtils.consume;
import static com.android.tools.r8.kotlin.KotlinMetadataUtils.toJvmMethodSignature;
import com.android.tools.r8.graph.AppView;
@@ -51,7 +50,8 @@
}
boolean rewrite(Consumer<KmLambda> consumer, DexClass clazz, AppView<?> appView) {
- KmLambda kmLambda = consume(new KmLambda(), consumer);
+ KmLambda kmLambda = new KmLambda();
+ consumer.accept(kmLambda);
if (!hasBacking) {
return function.rewrite(kmLambda::setFunction, null, appView);
}
diff --git a/src/main/java/com/android/tools/r8/kotlin/KotlinMetadataWriter.java b/src/main/java/com/android/tools/r8/kotlin/KotlinMetadataWriter.java
index 24c5af9..9509c98 100644
--- a/src/main/java/com/android/tools/r8/kotlin/KotlinMetadataWriter.java
+++ b/src/main/java/com/android/tools/r8/kotlin/KotlinMetadataWriter.java
@@ -286,9 +286,23 @@
(nextNextIndent, kmProperty) -> appendKmProperty(nextNextIndent, sb, kmProperty)));
}
+ public static void appendFlags(
+ String indent, String keyword, StringBuilder sb, Map<String, Object> flags) {
+ sb.append(indent).append(keyword).append(": [").append(LINE_SEPARATOR);
+ flags.forEach(
+ (name, value) ->
+ sb.append(indent)
+ .append(INDENT)
+ .append(name)
+ .append(": ")
+ .append(value)
+ .append(",")
+ .append(LINE_SEPARATOR));
+ sb.append(indent).append("]");
+ }
+
public static void appendKmClass(String indent, StringBuilder sb, KmClass kmClass) {
- appendKeyValue(indent, "flags", sb, kmClass.getFlags() + "");
- appendKeyValue(indent, "jvmFlags", sb, JvmExtensionsKt.getJvmFlags(kmClass) + "");
+ appendFlags(indent, "flags", sb, KotlinFlagUtils.extractFlags(kmClass));
appendKeyValue(indent, "name", sb, kmClass.getName());
appendKeyValue(
indent,
@@ -387,7 +401,7 @@
"KmConstructor",
sb,
newIndent -> {
- appendKeyValue(newIndent, "flags", sb, constructor.getFlags() + "");
+ appendFlags(indent, "flags", sb, KotlinFlagUtils.extractFlags(constructor));
appendKeyValue(
newIndent,
"valueParameters",
@@ -406,7 +420,7 @@
"KmFunction",
sb,
newIndent -> {
- appendKeyValue(newIndent, "flags", sb, function.getFlags() + "");
+ appendFlags(indent, "flags", sb, KotlinFlagUtils.extractFlags(function));
appendKeyValue(newIndent, "name", sb, function.getName());
appendKeyValue(
newIndent,
@@ -466,7 +480,7 @@
"KmProperty",
sb,
newIndent -> {
- appendKeyValue(newIndent, "flags", sb, kmProperty.getFlags() + "");
+ appendFlags(indent, "flags", sb, KotlinFlagUtils.extractFlags(kmProperty));
appendKeyValue(newIndent, "name", sb, kmProperty.getName());
appendKeyValue(
newIndent,
@@ -483,8 +497,12 @@
"typeParameters",
sb,
nextIndent -> appendTypeParameters(nextIndent, sb, kmProperty.getTypeParameters()));
- appendKeyValue(newIndent, "getterFlags", sb, kmProperty.getGetterFlags() + "");
- appendKeyValue(newIndent, "setterFlags", sb, kmProperty.getSetterFlags() + "");
+ appendFlags(
+ indent, "getterFlags", sb, KotlinFlagUtils.extractFlags(kmProperty.getGetter()));
+ if (kmProperty.getSetter() != null) {
+ appendFlags(
+ indent, "setterFlags", sb, KotlinFlagUtils.extractFlags(kmProperty.getSetter()));
+ }
appendKeyValue(
newIndent,
"setterParameter",
@@ -502,7 +520,6 @@
sb,
kmProperty.getContextReceiverTypes(),
(nextIndent, kmType) -> appendKmType(nextIndent, sb, kmType)));
- appendKeyValue(newIndent, "jvmFlags", sb, JvmExtensionsKt.getJvmFlags(kmProperty) + "");
JvmFieldSignature fieldSignature = JvmExtensionsKt.getFieldSignature(kmProperty);
appendKeyValue(newIndent, "fieldSignature", sb, Objects.toString(fieldSignature));
JvmMethodSignature getterSignature = JvmExtensionsKt.getGetterSignature(kmProperty);
@@ -536,7 +553,7 @@
"KmType",
sb,
newIndent -> {
- appendKeyValue(newIndent, "flags", sb, kmType.getFlags() + "");
+ appendFlags(newIndent, "flags", sb, KotlinFlagUtils.extractFlags(kmType));
appendKeyValue(newIndent, "classifier", sb, kmType.classifier.toString());
appendKeyValue(
newIndent,
@@ -641,7 +658,7 @@
"KmValueParameter",
sb,
newIndent -> {
- appendKeyValue(newIndent, "flags", sb, valueParameter.getFlags() + "");
+ appendFlags(newIndent, "flags", sb, KotlinFlagUtils.extractFlags(valueParameter));
appendKeyValue(newIndent, "name", sb, valueParameter.getName());
appendKeyValue(
newIndent,
@@ -674,7 +691,7 @@
sb,
newIndent -> {
appendKeyValue(newIndent, "id", sb, typeParameter.getId() + "");
- appendKeyValue(newIndent, "flags", sb, typeParameter.getFlags() + "");
+ appendFlags(newIndent, "flags", sb, KotlinFlagUtils.extractFlags(typeParameter));
appendKeyValue(newIndent, "name", sb, typeParameter.getName());
appendKeyValue(newIndent, "variance", sb, typeParameter.getVariance().name());
appendKeyValue(
@@ -695,7 +712,7 @@
nextIndent ->
appendKmList(
nextIndent,
- "KmAnnotion",
+ "KmAnnotation",
sb,
JvmExtensionsKt.getAnnotations(typeParameter),
(nextNextIndent, kmAnnotation) ->
@@ -726,7 +743,7 @@
"expandedType",
sb,
nextIndent -> appendKmType(nextIndent, sb, kmTypeAlias.expandedType));
- appendKeyValue(newIndent, "flags", sb, kmTypeAlias.getFlags() + "");
+ appendFlags(newIndent, "flags", sb, KotlinFlagUtils.extractFlags(kmTypeAlias));
appendKeyValue(newIndent, "name", sb, kmTypeAlias.getName());
appendKeyValue(
newIndent,
@@ -895,7 +912,7 @@
"KmEffectExpression",
sb,
newIndent -> {
- appendKeyValue(newIndent, "flags", sb, expression.getFlags() + "");
+ appendFlags(indent, "flags", sb, KotlinFlagUtils.extractFlags(expression));
appendKeyValue(
newIndent,
"foo",
diff --git a/src/main/java/com/android/tools/r8/kotlin/KotlinTypeAliasInfo.java b/src/main/java/com/android/tools/r8/kotlin/KotlinTypeAliasInfo.java
index 038f838..9371fa1 100644
--- a/src/main/java/com/android/tools/r8/kotlin/KotlinTypeAliasInfo.java
+++ b/src/main/java/com/android/tools/r8/kotlin/KotlinTypeAliasInfo.java
@@ -4,7 +4,6 @@
package com.android.tools.r8.kotlin;
-import static com.android.tools.r8.kotlin.KotlinMetadataUtils.consume;
import static com.android.tools.r8.kotlin.KotlinMetadataUtils.rewriteList;
import static com.android.tools.r8.utils.FunctionUtils.forEachApply;
@@ -20,59 +19,56 @@
// Holds information about KmTypeAlias
public class KotlinTypeAliasInfo implements EnqueuerMetadataTraceable {
- private final int flags;
- private final String name;
+ private final KmTypeAlias kmTypeAlias;
private final KotlinTypeInfo underlyingType;
private final KotlinTypeInfo expandedType;
private final List<KotlinTypeParameterInfo> typeParameters;
private final List<KotlinAnnotationInfo> annotations;
- private final KotlinVersionRequirementInfo versionRequirements;
private KotlinTypeAliasInfo(
- int flags,
- String name,
+ KmTypeAlias kmTypeAlias,
KotlinTypeInfo underlyingType,
KotlinTypeInfo expandedType,
List<KotlinTypeParameterInfo> typeParameters,
- List<KotlinAnnotationInfo> annotations,
- KotlinVersionRequirementInfo versionRequirements) {
- this.flags = flags;
- this.name = name;
+ List<KotlinAnnotationInfo> annotations) {
+ this.kmTypeAlias = kmTypeAlias;
assert underlyingType != null;
assert expandedType != null;
this.underlyingType = underlyingType;
this.expandedType = expandedType;
this.typeParameters = typeParameters;
this.annotations = annotations;
- this.versionRequirements = versionRequirements;
}
public static KotlinTypeAliasInfo create(
KmTypeAlias alias, DexItemFactory factory, Reporter reporter) {
return new KotlinTypeAliasInfo(
- alias.getFlags(),
- alias.getName(),
+ alias,
KotlinTypeInfo.create(alias.underlyingType, factory, reporter),
KotlinTypeInfo.create(alias.expandedType, factory, reporter),
KotlinTypeParameterInfo.create(alias.getTypeParameters(), factory, reporter),
- KotlinAnnotationInfo.create(alias.getAnnotations(), factory),
- KotlinVersionRequirementInfo.create(alias.getVersionRequirements()));
+ KotlinAnnotationInfo.create(alias.getAnnotations(), factory));
}
boolean rewrite(Consumer<KmTypeAlias> consumer, AppView<?> appView) {
- KmTypeAlias kmTypeAlias = consume(new KmTypeAlias(flags, name), consumer);
- boolean rewritten = underlyingType.rewrite(kmTypeAlias::setUnderlyingType, appView);
- rewritten |= expandedType.rewrite(kmTypeAlias::setExpandedType, appView);
+ KmTypeAlias rewrittenKmTypeAlias = new KmTypeAlias(kmTypeAlias.getName());
+ consumer.accept(rewrittenKmTypeAlias);
+ KotlinFlagUtils.copyAllFlags(kmTypeAlias, rewrittenKmTypeAlias);
+ boolean rewritten = underlyingType.rewrite(rewrittenKmTypeAlias::setUnderlyingType, appView);
+ rewritten |= expandedType.rewrite(rewrittenKmTypeAlias::setExpandedType, appView);
rewritten |=
rewriteList(
appView,
typeParameters,
- kmTypeAlias.getTypeParameters(),
+ rewrittenKmTypeAlias.getTypeParameters(),
KotlinTypeParameterInfo::rewrite);
rewritten |=
rewriteList(
- appView, annotations, kmTypeAlias.getAnnotations(), KotlinAnnotationInfo::rewrite);
- rewritten |= versionRequirements.rewrite(kmTypeAlias.getVersionRequirements()::addAll);
+ appView,
+ annotations,
+ rewrittenKmTypeAlias.getAnnotations(),
+ KotlinAnnotationInfo::rewrite);
+ rewrittenKmTypeAlias.getVersionRequirements().addAll(kmTypeAlias.getVersionRequirements());
return rewritten;
}
diff --git a/src/main/java/com/android/tools/r8/kotlin/KotlinTypeInfo.java b/src/main/java/com/android/tools/r8/kotlin/KotlinTypeInfo.java
index a0090b0..25dc018 100644
--- a/src/main/java/com/android/tools/r8/kotlin/KotlinTypeInfo.java
+++ b/src/main/java/com/android/tools/r8/kotlin/KotlinTypeInfo.java
@@ -4,7 +4,6 @@
package com.android.tools.r8.kotlin;
-import static com.android.tools.r8.kotlin.KotlinMetadataUtils.consume;
import static com.android.tools.r8.kotlin.KotlinMetadataUtils.rewriteIfNotNull;
import static com.android.tools.r8.kotlin.KotlinMetadataUtils.rewriteList;
import static com.android.tools.r8.utils.FunctionUtils.forEachApply;
@@ -28,7 +27,7 @@
private static final List<KotlinTypeProjectionInfo> EMPTY_ARGUMENTS = ImmutableList.of();
- private final int flags;
+ private final KmType kmType;
private final KotlinClassifierInfo classifier;
private final KotlinTypeInfo abbreviatedType;
private final KotlinTypeInfo outerType;
@@ -38,7 +37,7 @@
private final boolean isRaw;
KotlinTypeInfo(
- int flags,
+ KmType kmType,
KotlinClassifierInfo classifier,
KotlinTypeInfo abbreviatedType,
KotlinTypeInfo outerType,
@@ -46,7 +45,7 @@
List<KotlinAnnotationInfo> annotations,
KotlinFlexibleTypeUpperBoundInfo flexibleTypeUpperBound,
boolean isRaw) {
- this.flags = flags;
+ this.kmType = kmType;
this.classifier = classifier;
this.abbreviatedType = abbreviatedType;
this.outerType = outerType;
@@ -61,7 +60,7 @@
return null;
}
return new KotlinTypeInfo(
- kmType.getFlags(),
+ kmType,
KotlinClassifierInfo.create(kmType.classifier, factory, reporter),
KotlinTypeInfo.create(kmType.getAbbreviatedType(), factory, reporter),
KotlinTypeInfo.create(kmType.getOuterType(), factory, reporter),
@@ -85,17 +84,21 @@
}
boolean rewrite(Consumer<KmType> consumer, AppView<?> appView) {
- // TODO(b/154348683): Check for correct flags
- KmType kmType = consume(new KmType(flags), consumer);
- boolean rewritten = classifier.rewrite(kmType, appView);
+ KmType rewrittenKmType = new KmType();
+ consumer.accept(rewrittenKmType);
+ KotlinFlagUtils.copyAllFlags(kmType, rewrittenKmType);
+ boolean rewritten = classifier.rewrite(rewrittenKmType, appView);
rewritten |=
rewriteIfNotNull(
- appView, abbreviatedType, kmType::setAbbreviatedType, KotlinTypeInfo::rewrite);
+ appView, abbreviatedType, rewrittenKmType::setAbbreviatedType, KotlinTypeInfo::rewrite);
rewritten |=
- rewriteIfNotNull(appView, outerType, kmType::setOuterType, KotlinTypeInfo::rewrite);
+ rewriteIfNotNull(
+ appView, outerType, rewrittenKmType::setOuterType, KotlinTypeInfo::rewrite);
rewritten |=
- rewriteList(appView, arguments, kmType.getArguments(), KotlinTypeProjectionInfo::rewrite);
- rewritten |= flexibleTypeUpperBound.rewrite(kmType::setFlexibleTypeUpperBound, appView);
+ rewriteList(
+ appView, arguments, rewrittenKmType.getArguments(), KotlinTypeProjectionInfo::rewrite);
+ rewritten |=
+ flexibleTypeUpperBound.rewrite(rewrittenKmType::setFlexibleTypeUpperBound, appView);
if (annotations.isEmpty() && !isRaw) {
return rewritten;
}
@@ -103,9 +106,9 @@
rewriteList(
appView,
annotations,
- JvmExtensionsKt.getAnnotations(kmType),
+ JvmExtensionsKt.getAnnotations(rewrittenKmType),
KotlinAnnotationInfo::rewrite);
- JvmExtensionsKt.setRaw(kmType, isRaw);
+ JvmExtensionsKt.setRaw(rewrittenKmType, isRaw);
return rewritten;
}
diff --git a/src/main/java/com/android/tools/r8/kotlin/KotlinTypeParameterInfo.java b/src/main/java/com/android/tools/r8/kotlin/KotlinTypeParameterInfo.java
index ba2aaa9..4ba90b6 100644
--- a/src/main/java/com/android/tools/r8/kotlin/KotlinTypeParameterInfo.java
+++ b/src/main/java/com/android/tools/r8/kotlin/KotlinTypeParameterInfo.java
@@ -4,7 +4,6 @@
package com.android.tools.r8.kotlin;
-import static com.android.tools.r8.kotlin.KotlinMetadataUtils.consume;
import static com.android.tools.r8.kotlin.KotlinMetadataUtils.rewriteList;
import static com.android.tools.r8.utils.FunctionUtils.forEachApply;
@@ -18,7 +17,6 @@
import java.util.function.Consumer;
import kotlin.metadata.KmType;
import kotlin.metadata.KmTypeParameter;
-import kotlin.metadata.KmVariance;
import kotlin.metadata.jvm.JvmExtensionsKt;
// Provides access to Kotlin information about a type-parameter.
@@ -27,24 +25,15 @@
private static final List<KotlinTypeParameterInfo> EMPTY_TYPE_PARAMETERS = ImmutableList.of();
private static final List<KotlinTypeInfo> EMPTY_UPPER_BOUNDS = ImmutableList.of();
- private final int flags;
- private final int id;
- private final String name;
- private final KmVariance variance;
+ private final KmTypeParameter kmTypeParameter;
private final List<KotlinTypeInfo> originalUpperBounds;
private final List<KotlinAnnotationInfo> annotations;
private KotlinTypeParameterInfo(
- int flags,
- int id,
- String name,
- KmVariance variance,
+ KmTypeParameter kmTypeParameter,
List<KotlinTypeInfo> originalUpperBounds,
List<KotlinAnnotationInfo> annotations) {
- this.flags = flags;
- this.id = id;
- this.name = name;
- this.variance = variance;
+ this.kmTypeParameter = kmTypeParameter;
this.originalUpperBounds = originalUpperBounds;
this.annotations = annotations;
}
@@ -52,10 +41,7 @@
private static KotlinTypeParameterInfo create(
KmTypeParameter kmTypeParameter, DexItemFactory factory, Reporter reporter) {
return new KotlinTypeParameterInfo(
- kmTypeParameter.getFlags(),
- kmTypeParameter.getId(),
- kmTypeParameter.getName(),
- kmTypeParameter.getVariance(),
+ kmTypeParameter,
getUpperBounds(kmTypeParameter.getUpperBounds(), factory, reporter),
KotlinAnnotationInfo.create(JvmExtensionsKt.getAnnotations(kmTypeParameter), factory));
}
@@ -85,19 +71,22 @@
}
boolean rewrite(Consumer<KmTypeParameter> consumer, AppView<?> appView) {
- KmTypeParameter kmTypeParameter =
- consume(new KmTypeParameter(flags, name, id, variance), consumer);
+ KmTypeParameter rewrittenTypeParameter =
+ new KmTypeParameter(
+ kmTypeParameter.getName(), kmTypeParameter.getId(), kmTypeParameter.getVariance());
+ consumer.accept(rewrittenTypeParameter);
+ KotlinFlagUtils.copyAllFlags(kmTypeParameter, rewrittenTypeParameter);
boolean rewritten =
rewriteList(
appView,
originalUpperBounds,
- kmTypeParameter.getUpperBounds(),
+ rewrittenTypeParameter.getUpperBounds(),
KotlinTypeInfo::rewrite);
rewritten |=
rewriteList(
appView,
annotations,
- JvmExtensionsKt.getAnnotations(kmTypeParameter),
+ JvmExtensionsKt.getAnnotations(rewrittenTypeParameter),
KotlinAnnotationInfo::rewrite);
return rewritten;
}
diff --git a/src/main/java/com/android/tools/r8/kotlin/KotlinValueParameterInfo.java b/src/main/java/com/android/tools/r8/kotlin/KotlinValueParameterInfo.java
index a96b249..5f54ce1 100644
--- a/src/main/java/com/android/tools/r8/kotlin/KotlinValueParameterInfo.java
+++ b/src/main/java/com/android/tools/r8/kotlin/KotlinValueParameterInfo.java
@@ -4,7 +4,6 @@
package com.android.tools.r8.kotlin;
-import static com.android.tools.r8.kotlin.KotlinMetadataUtils.consume;
import static com.android.tools.r8.kotlin.KotlinMetadataUtils.rewriteIfNotNull;
import com.android.tools.r8.graph.AppView;
@@ -65,10 +64,9 @@
}
boolean rewrite(Consumer<KmValueParameter> consumer, AppView<?> appView) {
- KmValueParameter rewrittenKmValueParameter =
- consume(
- new KmValueParameter(kmValueParameter.getFlags(), kmValueParameter.getName()),
- consumer);
+ KmValueParameter rewrittenKmValueParameter = new KmValueParameter(kmValueParameter.getName());
+ consumer.accept(rewrittenKmValueParameter);
+ KotlinFlagUtils.copyAllFlags(kmValueParameter, rewrittenKmValueParameter);
boolean rewritten = type.rewrite(rewrittenKmValueParameter::setType, appView);
rewritten |=
rewriteIfNotNull(
diff --git a/src/main/java/com/android/tools/r8/kotlin/KotlinVersionRequirementInfo.java b/src/main/java/com/android/tools/r8/kotlin/KotlinVersionRequirementInfo.java
deleted file mode 100644
index 7242cf5..0000000
--- a/src/main/java/com/android/tools/r8/kotlin/KotlinVersionRequirementInfo.java
+++ /dev/null
@@ -1,37 +0,0 @@
-// Copyright (c) 2020, the R8 project authors. Please see the AUTHORS file
-// for details. All rights reserved. Use of this source code is governed by a
-// BSD-style license that can be found in the LICENSE file.
-
-package com.android.tools.r8.kotlin;
-
-import com.google.common.collect.ImmutableList;
-import java.util.List;
-import java.util.function.Consumer;
-import kotlin.metadata.KmVersionRequirement;
-
-class KotlinVersionRequirementInfo {
-
- private static final KotlinVersionRequirementInfo NO_VERSION_REQUIREMENTS =
- new KotlinVersionRequirementInfo(ImmutableList.of());
-
- private final List<KmVersionRequirement> versionRequirements;
-
- private KotlinVersionRequirementInfo(List<KmVersionRequirement> versionRequirements) {
- this.versionRequirements = versionRequirements;
- }
-
- static KotlinVersionRequirementInfo create(List<KmVersionRequirement> kmVersionRequirements) {
- if (kmVersionRequirements.isEmpty()) {
- return NO_VERSION_REQUIREMENTS;
- }
- return new KotlinVersionRequirementInfo(ImmutableList.copyOf(kmVersionRequirements));
- }
-
- boolean rewrite(Consumer<List<KmVersionRequirement>> consumer) {
- if (this == NO_VERSION_REQUIREMENTS) {
- return false;
- }
- consumer.accept(versionRequirements);
- return false;
- }
-}