blob: b554cd7cd174aab1324b63064fa5b569f82511ce [file] [log] [blame]
// Copyright (c) 2025, 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.partial.predicate;
import static java.nio.charset.StandardCharsets.UTF_8;
import com.android.tools.r8.errors.Unimplemented;
import com.android.tools.r8.graph.DexProgramClass;
import com.android.tools.r8.graph.DexString;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
public class R8PartialPredicateCollection implements Iterable<R8PartialPredicate> {
private final List<R8PartialPredicate> predicates = new ArrayList<>();
public void add(R8PartialPredicate predicate) {
predicates.add(predicate);
}
public boolean isEmpty() {
return predicates.isEmpty();
}
@Override
public Iterator<R8PartialPredicate> iterator() {
return predicates.iterator();
}
public int size() {
return predicates.size();
}
public boolean test(DexProgramClass clazz) {
return test(clazz.getType().getDescriptor());
}
public boolean test(DexString descriptor) {
for (R8PartialPredicate predicate : predicates) {
if (predicate.test(descriptor)) {
return true;
}
}
return false;
}
public byte[] getDumpFileContent() {
assert !isEmpty();
StringBuilder builder = new StringBuilder();
builder.append(predicates.iterator().next().serializeToString());
for (int i = 1; i < predicates.size(); i++) {
builder.append('\n').append(predicates.get(i).serializeToString());
}
return builder.toString().getBytes(UTF_8);
}
public String serializeToString() {
throw new Unimplemented();
}
}