blob: ca3a7322e183a5ec7a861b15d264288115e4988b [file] [log] [blame]
// Copyright (c) 2018, 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.experimental.graphinfo;
import com.android.tools.r8.errors.Unreachable;
public class GraphEdgeInfo {
// TODO(b/120959039): Simplify these. Most of the information is present in the source node.
public enum EdgeKind {
// Prioritized list of edge types.
KeepRule,
CompatibilityRule,
InstantiatedIn,
InvokedViaSuper,
TargetedBySuper,
InvokedFrom,
InvokedFromLambdaCreatedIn,
AnnotatedOn,
ReferencedFrom,
ReflectiveUseFrom,
ReachableFromLiveType,
ReferencedInAnnotation,
IsLibraryMethod,
MethodHandleUseFrom
}
private final EdgeKind kind;
public GraphEdgeInfo(EdgeKind kind) {
this.kind = kind;
}
public EdgeKind edgeKind() {
return kind;
}
public String getInfoPrefix() {
switch (edgeKind()) {
case KeepRule:
case CompatibilityRule:
return "referenced in keep rule";
case InstantiatedIn:
return "instantiated in";
case InvokedViaSuper:
return "invoked via super from";
case TargetedBySuper:
return "targeted by super from";
case InvokedFrom:
return "invoked from";
case InvokedFromLambdaCreatedIn:
return "invoked from lambda created in";
case AnnotatedOn:
return "annotated on";
case ReferencedFrom:
return "referenced from";
case ReflectiveUseFrom:
return "reflected from";
case ReachableFromLiveType:
return "reachable from";
case ReferencedInAnnotation:
return "referenced in annotation";
case IsLibraryMethod:
return "defined in library";
case MethodHandleUseFrom:
return "referenced by method handle";
default:
throw new Unreachable("Unexpected edge kind: " + edgeKind());
}
}
@Override
public String toString() {
return "{edge-type:" + kind.toString() + "}";
}
@Override
public boolean equals(Object o) {
return this == o || (o instanceof GraphEdgeInfo && ((GraphEdgeInfo) o).kind == kind);
}
@Override
public int hashCode() {
return kind.hashCode();
}
}