blob: f6a446ba571f969fc45032cfdfc6063bf5766466 [file]
// Copyright (c) 2026, 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.keepradius;
import com.android.tools.r8.graph.DexField;
import com.android.tools.r8.graph.DexMethod;
import com.android.tools.r8.graph.DexType;
import com.android.tools.r8.shaking.ProguardKeepRuleBase;
import com.android.tools.r8.utils.internal.ListUtils;
import com.google.common.collect.Sets;
import java.util.Collection;
import java.util.Set;
public class RootSetKeepRadiusForRule {
private final ProguardKeepRuleBase rule;
private final Set<DexType> matchedClasses = Sets.newIdentityHashSet();
private final Set<DexField> matchedFields = Sets.newIdentityHashSet();
private final Set<DexMethod> matchedMethods = Sets.newIdentityHashSet();
RootSetKeepRadiusForRule(ProguardKeepRuleBase rule) {
this.rule = rule;
}
void addMatchedClass(DexType type) {
matchedClasses.add(type);
}
void addMatchedField(DexField field) {
matchedFields.add(field);
}
void addMatchedMethod(DexMethod method) {
matchedMethods.add(method);
}
Set<DexType> getMatchedClasses() {
return matchedClasses;
}
Collection<DexType> getMatchedClassesWithDeterministicOrder() {
return ListUtils.sort(matchedClasses, DexType::compareTo);
}
Set<DexField> getMatchedFields() {
return matchedFields;
}
Collection<DexField> getMatchedFieldsWithDeterministicOrder() {
return ListUtils.sort(matchedFields, DexField::compareTo);
}
Set<DexMethod> getMatchedMethods() {
return matchedMethods;
}
Collection<DexMethod> getMatchedMethodsWithDeterministicOrder() {
return ListUtils.sort(matchedMethods, DexMethod::compareTo);
}
public int getNumberOfItems() {
return matchedClasses.size() + matchedFields.size() + matchedMethods.size();
}
public ProguardKeepRuleBase getRule() {
return rule;
}
public String getSource() {
return rule.getSource();
}
public boolean isEmpty() {
return matchedClasses.isEmpty() && matchedFields.isEmpty() && matchedMethods.isEmpty();
}
public boolean isNoObfuscationSet() {
return !rule.getModifiers().allowsObfuscation;
}
public boolean isNoOptimizationSet() {
return !rule.getModifiers().allowsOptimization;
}
public boolean isNoShrinkingSet() {
return !rule.getModifiers().allowsShrinking;
}
}