001: /*
002: * Bytecode Analysis Framework
003: * Copyright (C) 2003,2004 University of Maryland
004: *
005: * This library is free software; you can redistribute it and/or
006: * modify it under the terms of the GNU Lesser General Public
007: * License as published by the Free Software Foundation; either
008: * version 2.1 of the License, or (at your option) any later version.
009: *
010: * This library is distributed in the hope that it will be useful,
011: * but WITHOUT ANY WARRANTY; without even the implied warranty of
012: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
013: * Lesser General Public License for more details.
014: *
015: * You should have received a copy of the GNU Lesser General Public
016: * License along with this library; if not, write to the Free Software
017: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
018: */
019:
020: package edu.umd.cs.findbugs.ba;
021:
022: public class ReturnPath {
023: /**
024: * Top value.
025: */
026: public static final int TOP = 0;
027: /**
028: * Method "returns" by exiting the process.
029: */
030: public static final int EXIT = 1;
031: /**
032: * Method returns by throwing an unhandled exception.
033: */
034: public static final int UE = 2;
035: /**
036: * Method returns either by exiting or throwing an unhandled exception.
037: */
038: public static final int EXIT_UE = 3;
039: /**
040: * Method may return normally.
041: */
042: public static final int RETURNS = 4;
043:
044: private int kind;
045:
046: public ReturnPath(int kind) {
047: this .kind = kind;
048: }
049:
050: public int getKind() {
051: return kind;
052: }
053:
054: public void setKind(int kind) {
055: this .kind = kind;
056: }
057:
058: public void copyFrom(ReturnPath other) {
059: this .kind = other.kind;
060: }
061:
062: public boolean sameAs(ReturnPath other) {
063: return this .kind == other.kind;
064: }
065:
066: private static final int[][] mergeMatrix = {
067: // TOP EXIT UE EXIT_UE RETURNS
068: { TOP, }, // TOP
069: { EXIT, EXIT, }, // EXIT
070: { UE, EXIT_UE, UE, }, // UE
071: { EXIT_UE, EXIT_UE, EXIT_UE, EXIT_UE, }, // EXIT_UE
072: { RETURNS, RETURNS, RETURNS, RETURNS, RETURNS }, // RETURNS
073: };
074:
075: public void mergeWith(ReturnPath other) {
076: int max = Math.max(this .kind, other.kind);
077: int min = Math.min(this .kind, other.kind);
078: this .kind = mergeMatrix[max][min];
079: }
080:
081: @Override
082: public String toString() {
083: switch (kind) {
084: case TOP:
085: return "[TOP]";
086: case EXIT:
087: return "[EXIT]";
088: case UE:
089: return "[UE]";
090: case EXIT_UE:
091: return "[EXIT_UE]";
092: case RETURNS:
093: return "[RETURNS]";
094: default:
095: throw new IllegalStateException();
096: }
097: }
098: }
099:
100: // vim:ts=4
|