001: /*
002: * Copyright (c) 2001-2007, Jean Tessier
003: * All rights reserved.
004: *
005: * Redistribution and use in source and binary forms, with or without
006: * modification, are permitted provided that the following conditions
007: * are met:
008: *
009: * * Redistributions of source code must retain the above copyright
010: * notice, this list of conditions and the following disclaimer.
011: *
012: * * Redistributions in binary form must reproduce the above copyright
013: * notice, this list of conditions and the following disclaimer in the
014: * documentation and/or other materials provided with the distribution.
015: *
016: * * Neither the name of Jean Tessier nor the names of his contributors
017: * may be used to endorse or promote products derived from this software
018: * without specific prior written permission.
019: *
020: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
021: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
022: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
023: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
024: * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
025: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
026: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
027: * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
028: * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
029: * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
030: * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
031: */
032:
033: package com.jeantessier.diff;
034:
035: import java.util.*;
036:
037: import org.apache.log4j.*;
038:
039: import com.jeantessier.classreader.*;
040: import com.jeantessier.text.*;
041:
042: /**
043: * TODO class comment
044: */
045: public class CodeDifferenceStrategy implements DifferenceStrategy {
046: public boolean isPackageDifferent(Map oldPackage, Map newPackage) {
047: return false;
048: }
049:
050: public boolean isClassDifferent(Classfile oldClass,
051: Classfile newClass) {
052: return false;
053: }
054:
055: public boolean isDeclarationModified(Classfile oldClass,
056: Classfile newClass) {
057: return false;
058: }
059:
060: public boolean isFieldDifferent(Field_info oldField,
061: Field_info newField) {
062: return false;
063: }
064:
065: public boolean isConstantValueDifferent(
066: ConstantValue_attribute oldValue,
067: ConstantValue_attribute newValue) {
068: boolean result;
069:
070: if (oldValue != null) {
071: result = !oldValue.equals(newValue);
072: } else {
073: result = oldValue != newValue;
074: }
075:
076: return result;
077: }
078:
079: public boolean isMethodDifferent(Method_info oldMethod,
080: Method_info newMethod) {
081: return false;
082: }
083:
084: public boolean isCodeDifferent(Code_attribute oldCode,
085: Code_attribute newCode) {
086: boolean result;
087:
088: if (oldCode != null && newCode != null) {
089: result = oldCode.getCode().length != newCode.getCode().length;
090:
091: Iterator oldIterator = oldCode.iterator();
092: Iterator newIterator = newCode.iterator();
093:
094: while (!result && oldIterator.hasNext()
095: && newIterator.hasNext()) {
096: Instruction oldInstruction = (Instruction) oldIterator
097: .next();
098: Instruction newInstruction = (Instruction) newIterator
099: .next();
100: result = !oldInstruction.equals(newInstruction);
101: }
102:
103: if (Logger.getLogger(getClass()).isDebugEnabled()) {
104: Logger.getLogger(getClass()).debug(
105: "Code compare for " + oldCode.getOwner());
106: Logger.getLogger(getClass()).debug(
107: "old code: " + Hex.toString(oldCode.getCode()));
108: Logger.getLogger(getClass()).debug(
109: "new code: " + Hex.toString(newCode.getCode()));
110: Logger.getLogger(getClass()).debug(
111: result ? "[different]" : "[same]");
112: }
113: } else {
114: result = oldCode != newCode;
115: }
116:
117: return result;
118: }
119: }
|