Blame contrib/asm/src/org/objectweb/asm/commons/SimpleRemapper.java

Packit 5e46da
/***
Packit 5e46da
 * ASM: a very small and fast Java bytecode manipulation framework
Packit 5e46da
 * Copyright (c) 2000-2011 INRIA, France Telecom
Packit 5e46da
 * All rights reserved.
Packit 5e46da
 *
Packit 5e46da
 * Redistribution and use in source and binary forms, with or without
Packit 5e46da
 * modification, are permitted provided that the following conditions
Packit 5e46da
 * are met:
Packit 5e46da
 * 1. Redistributions of source code must retain the above copyright
Packit 5e46da
 *    notice, this list of conditions and the following disclaimer.
Packit 5e46da
 * 2. Redistributions in binary form must reproduce the above copyright
Packit 5e46da
 *    notice, this list of conditions and the following disclaimer in the
Packit 5e46da
 *    documentation and/or other materials provided with the distribution.
Packit 5e46da
 * 3. Neither the name of the copyright holders nor the names of its
Packit 5e46da
 *    contributors may be used to endorse or promote products derived from
Packit 5e46da
 *    this software without specific prior written permission.
Packit 5e46da
 *
Packit 5e46da
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
Packit 5e46da
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
Packit 5e46da
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
Packit 5e46da
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
Packit 5e46da
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
Packit 5e46da
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
Packit 5e46da
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
Packit 5e46da
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
Packit 5e46da
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
Packit 5e46da
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
Packit 5e46da
 * THE POSSIBILITY OF SUCH DAMAGE.
Packit 5e46da
 */
Packit 5e46da
Packit 5e46da
package org.objectweb.asm.commons;
Packit 5e46da
Packit 5e46da
import java.util.Collections;
Packit 5e46da
import java.util.Map;
Packit 5e46da
Packit 5e46da
/**
Packit 5e46da
 * A {@link Remapper} using a {@link Map} to define its mapping.
Packit 5e46da
 *
Packit 5e46da
 * @author Eugene Kuleshov
Packit 5e46da
 */
Packit 5e46da
public class SimpleRemapper extends Remapper {
Packit 5e46da
Packit 5e46da
    private final Map<String, String> mapping;
Packit 5e46da
Packit 5e46da
    public SimpleRemapper(Map<String, String> mapping) {
Packit 5e46da
        this.mapping = mapping;
Packit 5e46da
    }
Packit 5e46da
Packit 5e46da
    public SimpleRemapper(String oldName, String newName) {
Packit 5e46da
        this.mapping = Collections.singletonMap(oldName, newName);
Packit 5e46da
    }
Packit 5e46da
Packit 5e46da
    @Override
Packit 5e46da
    public String mapMethodName(String owner, String name, String desc) {
Packit 5e46da
        String s = map(owner + '.' + name + desc);
Packit 5e46da
        return s == null ? name : s;
Packit 5e46da
    }
Packit 5e46da
Packit 5e46da
    @Override
Packit 5e46da
    public String mapInvokeDynamicMethodName(String name, String desc) {
Packit 5e46da
        String s = map('.' + name + desc);
Packit 5e46da
        return s == null ? name : s;
Packit 5e46da
    }
Packit 5e46da
Packit 5e46da
    @Override
Packit 5e46da
    public String mapFieldName(String owner, String name, String desc) {
Packit 5e46da
        String s = map(owner + '.' + name);
Packit 5e46da
        return s == null ? name : s;
Packit 5e46da
    }
Packit 5e46da
Packit 5e46da
    @Override
Packit 5e46da
    public String map(String key) {
Packit 5e46da
        return mapping.get(key);
Packit 5e46da
    }
Packit 5e46da
}