001: /***
002: * Retrotranslator: a Java bytecode transformer that translates Java classes
003: * compiled with JDK 5.0 into classes that can be run on JVM 1.4.
004: *
005: * Copyright (c) 2005 - 2008 Taras Puchko
006: * All rights reserved.
007: *
008: * Redistribution and use in source and binary forms, with or without
009: * modification, are permitted provided that the following conditions
010: * are met:
011: * 1. Redistributions of source code must retain the above copyright
012: * notice, this list of conditions and the following disclaimer.
013: * 2. Redistributions in binary form must reproduce the above copyright
014: * notice, this list of conditions and the following disclaimer in the
015: * documentation and/or other materials provided with the distribution.
016: * 3. Neither the name of the copyright holders nor the names of its
017: * contributors may be used to endorse or promote products derived from
018: * this software without specific prior written permission.
019: *
020: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
021: * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
022: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
023: * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
024: * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
025: * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
026: * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
027: * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
028: * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
029: * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
030: * THE POSSIBILITY OF SUCH DAMAGE.
031: */package net.sf.retrotranslator.transformer;
032:
033: import java.util.*;
034: import net.sf.retrotranslator.runtime.asm.Type;
035:
036: /**
037: * @author Taras Puchko
038: */
039: class ClassReplacement {
040:
041: private String uniqueTypeName;
042: private String referenceTypeName;
043: private MemberReplacement checkCastReplacement;
044: private MemberReplacement instanceOfReplacement;
045: private final Map<MemberKey, MemberReplacement> fieldReplacements = createMap();
046: private final Map<String, ConstructorReplacement> constructorReplacements = createMap();
047: private final Map<String, MemberReplacement> converterReplacements = createMap();
048: private final Map<MemberKey, MemberReplacement> methodReplacements = createMap();
049: private final Map<String, MemberReplacement> instantiationReplacements = createMap();
050:
051: public ClassReplacement() {
052: }
053:
054: public String getUniqueTypeName() {
055: return uniqueTypeName;
056: }
057:
058: public void setUniqueTypeName(String uniqueTypeName) {
059: this .uniqueTypeName = uniqueTypeName;
060: }
061:
062: public String getReferenceTypeName() {
063: return referenceTypeName;
064: }
065:
066: public void setReferenceTypeName(String referenceTypeName) {
067: this .referenceTypeName = referenceTypeName;
068: }
069:
070: public MemberReplacement getCheckCastReplacement() {
071: return checkCastReplacement;
072: }
073:
074: public void setCheckCastReplacement(
075: MemberReplacement checkCastReplacement) {
076: this .checkCastReplacement = checkCastReplacement;
077: }
078:
079: public MemberReplacement getInstanceOfReplacement() {
080: return instanceOfReplacement;
081: }
082:
083: public void setInstanceOfReplacement(
084: MemberReplacement instanceOfReplacement) {
085: this .instanceOfReplacement = instanceOfReplacement;
086: }
087:
088: public Map<MemberKey, MemberReplacement> getFieldReplacements() {
089: return fieldReplacements;
090: }
091:
092: public Map<String, ConstructorReplacement> getConstructorReplacements() {
093: return constructorReplacements;
094: }
095:
096: public Map<String, MemberReplacement> getConverterReplacements() {
097: return converterReplacements;
098: }
099:
100: public Map<MemberKey, MemberReplacement> getMethodReplacements() {
101: return methodReplacements;
102: }
103:
104: public Map<String, MemberReplacement> getInstantiationReplacements() {
105: return instantiationReplacements;
106: }
107:
108: public boolean isEmpty(String className) {
109: return uniqueTypeName.equals(className)
110: && referenceTypeName.equals(className)
111: && checkCastReplacement == null
112: && instanceOfReplacement == null
113: && fieldReplacements.isEmpty()
114: && constructorReplacements.isEmpty()
115: && converterReplacements.isEmpty()
116: && methodReplacements.isEmpty()
117: && instantiationReplacements.isEmpty();
118: }
119:
120: private static <K, V> Map<K, V> createMap() {
121: return Collections.synchronizedMap(new LinkedHashMap<K, V>());
122: }
123:
124: static String getConstructorDesc(MemberReplacement converter) {
125: return Type.getMethodDescriptor(Type.VOID_TYPE,
126: new Type[] { Type.getReturnType(converter.getDesc()) });
127: }
128: }
|