| /* |
| * Copyright (C) 2015 The Android Open Source Project |
| * |
| * Licensed under the Apache License, Version 2.0 (the "License"); |
| * you may not use this file except in compliance with the License. |
| * You may obtain a copy of the License at |
| * |
| * http://www.apache.org/licenses/LICENSE-2.0 |
| * |
| * Unless required by applicable law or agreed to in writing, software |
| * distributed under the License is distributed on an "AS IS" BASIS, |
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| * See the License for the specific language governing permissions and |
| * limitations under the License. |
| */ |
| |
| package com.android.jack.shrob.shrink; |
| |
| import com.android.jack.ir.ast.JDefinedClassOrInterface; |
| import com.android.jack.ir.ast.JMethod; |
| import com.android.jack.ir.ast.JNode; |
| import com.android.jack.ir.ast.JSession; |
| import com.android.jack.transformations.TypeRemover; |
| import com.android.sched.item.Description; |
| import com.android.sched.item.Synchronized; |
| import com.android.sched.schedulable.Constraint; |
| import com.android.sched.schedulable.ExclusiveAccess; |
| import com.android.sched.schedulable.RunnableSchedulable; |
| import com.android.sched.util.log.TracerFactory; |
| |
| import javax.annotation.Nonnull; |
| |
| /** |
| * A {@link RunnableSchedulable} removing all types not marked with the {@link KeepMarker}. |
| */ |
| @Description("Removes all types not marked with the KeepMarker") |
| @Synchronized |
| @Constraint(need = KeepMarker.class) |
| // This schedulable removes some types and updates the hierarchy |
| @ExclusiveAccess(JSession.class) |
| public class TypeShrinker extends TypeRemover { |
| |
| @Nonnull |
| private final com.android.sched.util.log.Tracer tracer = TracerFactory.getTracer(); |
| |
| @Override |
| protected boolean mustBeRemoved(@Nonnull JDefinedClassOrInterface type) { |
| // Type from classpath can not be remove |
| return !isTypeFromClasspath(type) && !((JNode) type).containsMarker(KeepMarker.class); |
| } |
| |
| @Override |
| public void run(@Nonnull JDefinedClassOrInterface type) { |
| super.run(type); |
| tracer.getStatistic(ShrinkStatistic.TYPES_REMOVED).add(mustBeRemoved(type)); |
| } |
| |
| @Override |
| protected boolean isPlannedForRemoval(@Nonnull JMethod method) { |
| return method.getEnclosingType().isToEmit() |
| && !((JNode) method).containsMarker(KeepMarker.class); |
| } |
| } |