// Copyright 2018 The Bazel Authors. All rights reserved.
//
// 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.google.devtools.build.android.desugar;

import org.objectweb.asm.ClassVisitor;
import org.objectweb.asm.Handle;
import org.objectweb.asm.commons.ClassRemapper;
import org.objectweb.asm.commons.Remapper;

/**
 * A visitor that renames some type names and only when the owner is also renamed.
 */
class CorePackageRenamer extends ClassRemapper {

  public CorePackageRenamer(ClassVisitor cv, CoreLibrarySupport support) {
    super(cv, new CorePackageRemapper(support));
  }

  private static final class CorePackageRemapper extends Remapper {
    private final CoreLibrarySupport support;

    private CorePackageRemapper(CoreLibrarySupport support) {
      this.support = support;
    }

    public boolean isRenamed(String owner) {
      return support.isRenamedCoreLibrary(owner);
    }

    @Override
    public String map(String typeName) {
      return isRenamed(typeName) ? support.renameCoreLibrary(typeName) : typeName;
    }

    @Override
    public Object mapValue(Object value) {
      if (value instanceof Handle && !isRenamed(((Handle) value).getOwner())) {
        return value;
      }
      return super.mapValue(value);
    }
  }
}

@@ -703,41 +703,8 @@
 or;%0A
-import org.objectweb.asm.Handle;%0A
 impo
@@ -825,63 +825,64 @@
 mes 
-some type names and only when the owner is also renamed
+packages so configured using %7B@link CoreLibrarySupport%7D.
 .%0A *
@@ -1525,218 +1525,8 @@
    %7D
-%0A%0A    @Override%0A    public Object mapValue(Object value) %7B%0A      if (value instanceof Handle && !isRenamed(((Handle) value).getOwner())) %7B%0A        return value;%0A      %7D%0A      return super.mapValue(value);%0A    %7D
 %0A  %7D

Delete erroneous piece of desugar's renaming logic RELNOTES: None.