| // Copyright (c) 2017, 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.shaking; | |
| import com.android.tools.r8.origin.Origin; | |
| import com.android.tools.r8.position.Position; | |
| import com.android.tools.r8.utils.internal.exceptions.Unreachable; | |
| import java.util.List; | |
| public class InlineRule extends ProguardConfigurationRule { | |
| public enum InlineRuleType { | |
| ALWAYS, | |
| NEVER, | |
| NEVER_CLASS_INLINE, | |
| NEVER_SINGLE_CALLER | |
| } | |
| @SuppressWarnings("NonCanonicalType") | |
| public static class Builder extends ProguardConfigurationRule.Builder<InlineRule, Builder> { | |
| private Builder() { | |
| super(); | |
| } | |
| InlineRuleType type; | |
| @Override | |
| public Builder self() { | |
| return this; | |
| } | |
| public Builder setType(InlineRuleType type) { | |
| this.type = type; | |
| return this; | |
| } | |
| @Override | |
| public InlineRule build() { | |
| return new InlineRule( | |
| origin, | |
| getPosition(), | |
| source, | |
| buildClassAnnotations(), | |
| classAccessFlags, | |
| negatedClassAccessFlags, | |
| classTypeNegated, | |
| classType, | |
| classNames, | |
| buildInheritanceAnnotations(), | |
| inheritanceClassName, | |
| inheritanceIsExtends, | |
| memberRules, | |
| type); | |
| } | |
| } | |
| private final InlineRuleType type; | |
| protected InlineRule( | |
| Origin origin, | |
| Position position, | |
| String source, | |
| List<ProguardTypeMatcher> classAnnotations, | |
| ProguardAccessFlags classAccessFlags, | |
| ProguardAccessFlags negatedClassAccessFlags, | |
| boolean classTypeNegated, | |
| ProguardClassType classType, | |
| ProguardClassNameList classNames, | |
| List<ProguardTypeMatcher> inheritanceAnnotations, | |
| ProguardTypeMatcher inheritanceClassName, | |
| boolean inheritanceIsExtends, | |
| List<ProguardMemberRule> memberRules, | |
| InlineRuleType type) { | |
| super( | |
| origin, | |
| position, | |
| source, | |
| classAnnotations, | |
| classAccessFlags, | |
| negatedClassAccessFlags, | |
| classTypeNegated, | |
| classType, | |
| classNames, | |
| inheritanceAnnotations, | |
| inheritanceClassName, | |
| inheritanceIsExtends, | |
| memberRules); | |
| this.type = type; | |
| } | |
| public static Builder builder() { | |
| return new Builder(); | |
| } | |
| public InlineRuleType getType() { | |
| return type; | |
| } | |
| @Override | |
| String typeString() { | |
| switch (type) { | |
| case ALWAYS: | |
| return "alwaysinline"; | |
| case NEVER: | |
| return "neverinline"; | |
| case NEVER_CLASS_INLINE: | |
| return "neverclassinlinemethod"; | |
| case NEVER_SINGLE_CALLER: | |
| return "neversinglecaller"; | |
| } | |
| throw new Unreachable("Unknown inline type " + type); | |
| } | |
| } |