blob: 29442ff67d6449bd6aaaa0538da194f73e65a844 [file] [log] [blame]
// Copyright (c) 2022, 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.keepanno.ast;
import java.util.Collections;
import java.util.List;
public abstract class KeepMethodParametersPattern {
public static KeepMethodParametersPattern any() {
return Any.getInstance();
}
public static KeepMethodParametersPattern none() {
return Some.EMPTY_INSTANCE;
}
private KeepMethodParametersPattern() {}
public boolean isAny() {
return false;
}
public boolean isList() {
return asList() != null;
}
public List<KeepTypePattern> asList() {
return null;
}
private static class Some extends KeepMethodParametersPattern {
private static final Some EMPTY_INSTANCE = new Some(Collections.emptyList());
private final List<KeepTypePattern> parameterPatterns;
private Some(List<KeepTypePattern> parameterPatterns) {
assert parameterPatterns != null;
this.parameterPatterns = parameterPatterns;
}
@Override
public List<KeepTypePattern> asList() {
return parameterPatterns;
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
Some that = (Some) o;
return parameterPatterns.equals(that.parameterPatterns);
}
@Override
public int hashCode() {
return parameterPatterns.hashCode();
}
}
private static class Any extends KeepMethodParametersPattern {
private static final Any INSTANCE = new Any();
public static Any getInstance() {
return INSTANCE;
}
@Override
public boolean isAny() {
return true;
}
@Override
public boolean equals(Object obj) {
return this == obj;
}
@Override
public int hashCode() {
return System.identityHashCode(this);
}
@Override
public String toString() {
return "(...)";
}
}
}