blob: 0c2eea47a4fcb398c1e31e914ef1f868103063f8 [file] [log] [blame]
// 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.utils.structural;
import com.android.tools.r8.utils.structural.StructuralItem.CompareToAccept;
import com.android.tools.r8.utils.structural.StructuralItem.HashingAccept;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.function.ToIntFunction;
public abstract class StructuralSpecification<T, V extends StructuralSpecification<T, V>> {
/**
* Basic specification for visiting an item.
*
* <p>This specified the getter for the item as well as all of the methods that are required for
* visiting. Those coincide with the requirements of Specified.
*
* <p>It is preferable to use withStructuralItem.
*/
@Deprecated
public abstract <S> V withCustomItem(
Function<T, S> getter, CompareToAccept<S> compare, HashingAccept<S> hasher);
/**
* Specification for a "specified" item.
*
* <p>Using this the visiting methods are could based on the implementation of the Specified
* interface.
*/
public <S extends StructuralItem<S>> V withItem(Function<T, S> getter) {
return withCustomItem(getter, S::acceptCompareTo, S::acceptHashing);
}
/**
* Helper to declare an assert on the item.
*
* <p>Only run if running with -ea. Must be run on any item being visited (ie, both in the case of
* comparisons and equality).
*/
public abstract V withAssert(Predicate<T> predicate);
// Primitive Java types. These will need overriding to avoid boxing.
public abstract V withBool(Predicate<T> getter);
public abstract V withInt(ToIntFunction<T> getter);
}