/*
 * fb-contrib - Auxiliary detectors for Java programs
 * Copyright (C) 2005-2016 Dave Brosius
 * 
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 * 
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */
package com.mebigfatguy.fbcontrib.collect;

import org.apache.bcel.Constants;

import com.mebigfatguy.fbcontrib.utils.ToString;

public class MethodInfo {

    public static final int PUBLIC_USE = 1;
    public static final int PRIVATE_USE = 2;
    public static final int PROTECTED_USE = 4;
    public static final int PACKAGE_USE = 8;

    private short numMethodBytes;
    private byte numMethodCalls;
    private byte immutabilityOrdinal;
    private byte declaredAccess;
    private byte isCalledType;

    public int getNumBytes() {
        return 0x0000FFFF & numMethodBytes;
    }

    public void setNumBytes(int numBytes) {
        numMethodBytes = (short) numBytes;
    }

    public int getNumMethodCalls() {
        return 0x000000FF & numMethodCalls;
    }

    public void setNumMethodCalls(int numCalls) {
        if (numCalls > 255) {
            numCalls = 255;
        }
        numMethodCalls = (byte) numCalls;
    }

    public void setDeclaredAccess(int access) {
        declaredAccess = (byte) access;
    }

    public int getDeclaredAccess() {
        return declaredAccess;
    }

    public void addCallingAccess(int access) {
        if ((access & Constants.ACC_PUBLIC) != 0) {
            isCalledType |= PUBLIC_USE;
        } else if ((access & Constants.ACC_PROTECTED) != 0) {
            isCalledType |= PROTECTED_USE;
        } else if ((access & Constants.ACC_PRIVATE) != 0) {
            isCalledType |= PRIVATE_USE;
        } else {
            isCalledType |= PACKAGE_USE;
        }
    }

    public boolean wasCalled() {
        return (isCalledType & (PUBLIC_USE | PROTECTED_USE | PACKAGE_USE | PRIVATE_USE)) != 0;
    }

    public boolean wasCalledPublicly() {
        return (isCalledType & PUBLIC_USE) != 0;
    }

    public boolean wasCalledProtectedly() {
        return (isCalledType & PROTECTED_USE) != 0;
    }

    public boolean wasCalledPackagely() {
        return (isCalledType & PACKAGE_USE) != 0;
    }

    public boolean wasCalledPrivately() {
        return (isCalledType & PRIVATE_USE) != 0;
    }

    public ImmutabilityType getImmutabilityType() {
        return ImmutabilityType.values()[immutabilityOrdinal];
    }

    public void setImmutabilityType(ImmutabilityType imType) {
        immutabilityOrdinal = (byte) imType.ordinal();
    }

    @Override
    public String toString() {
        return ToString.build(this);
    }
}
@@ -92,17 +92,16 @@
 osius%0A *
- 
 %0A * This
@@ -352,25 +352,24 @@
  version.%0A *
- 
 %0A * This lib
@@ -612,17 +612,16 @@
 ails.%0A *
- 
 %0A * You 
@@ -3138,24 +3138,594 @@
 l();%0A    %7D%0A%0A
+    @Override%0A    public boolean equals(Object o) %7B%0A        if (!(o instanceof MethodInfo)) %7B%0A            return false;%0A        %7D%0A%0A        MethodInfo mi = (MethodInfo) o;%0A%0A        return (numMethodBytes == mi.numMethodBytes) && (numMethodCalls == mi.numMethodCalls) && (immutabilityOrdinal == mi.immutabilityOrdinal)%0A                && (declaredAccess == mi.declaredAccess) && (isCalledType == mi.isCalledType);%0A    %7D%0A%0A    @Override%0A    public int hashCode() %7B%0A        return numMethodBytes %5E numMethodCalls %5E immutabilityOrdinal %5E declaredAccess %5E isCalledType;%0A    %7D%0A%0A
     @Overrid

add hashCode/equals