Coverage Report - com.jeantessier.classreader.impl.Method_info
 
Classes in this File Line Coverage Branch Coverage Complexity
Method_info
88%
45/51
72%
36/50
2.188
 
 1  
 /*
 2  
  *  Copyright (c) 2001-2009, Jean Tessier
 3  
  *  All rights reserved.
 4  
  *  
 5  
  *  Redistribution and use in source and binary forms, with or without
 6  
  *  modification, are permitted provided that the following conditions
 7  
  *  are met:
 8  
  *  
 9  
  *      * Redistributions of source code must retain the above copyright
 10  
  *        notice, this list of conditions and the following disclaimer.
 11  
  *  
 12  
  *      * Redistributions in binary form must reproduce the above copyright
 13  
  *        notice, this list of conditions and the following disclaimer in the
 14  
  *        documentation and/or other materials provided with the distribution.
 15  
  *  
 16  
  *      * Neither the name of Jean Tessier nor the names of his contributors
 17  
  *        may be used to endorse or promote products derived from this software
 18  
  *        without specific prior written permission.
 19  
  *  
 20  
  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 21  
  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 22  
  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 23  
  *  A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR
 24  
  *  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 25  
  *  EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 26  
  *  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 27  
  *  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
 28  
  *  LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 29  
  *  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 30  
  *  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 31  
  */
 32  
 
 33  
 package com.jeantessier.classreader.impl;
 34  
 
 35  
 import java.io.*;
 36  
 import java.util.*;
 37  
 
 38  
 import com.jeantessier.classreader.*;
 39  
 
 40  
 public class Method_info extends Feature_info implements com.jeantessier.classreader.Method_info {
 41  
     private static final int ACC_SYNCHRONIZED = 0x0020;
 42  
     private static final int ACC_BRIDGE = 0x0040;
 43  
     private static final int ACC_VARARGS = 0x0080;
 44  
     private static final int ACC_NATIVE = 0x0100;
 45  
     private static final int ACC_ABSTRACT = 0x0400;
 46  
     private static final int ACC_STRICT = 0x0800;
 47  
 
 48  
     public Method_info(Classfile classfile, DataInput in) throws IOException {
 49  2722
         super(classfile, in);
 50  2722
     }
 51  
 
 52  
     public String getFeatureType() {
 53  13460
         return "method";
 54  
     }
 55  
 
 56  
     public boolean isSynchronized() {
 57  6556
         return (getAccessFlag() & ACC_SYNCHRONIZED) != 0;
 58  
     }
 59  
 
 60  
     public boolean isBridge() {
 61  37
         return (getAccessFlag() & ACC_BRIDGE) != 0;
 62  
     }
 63  
 
 64  
     public boolean isVarargs() {
 65  39
         return (getAccessFlag() & ACC_VARARGS) != 0;
 66  
     }
 67  
 
 68  
     public boolean isNative() {
 69  6556
         return (getAccessFlag() & ACC_NATIVE) != 0;
 70  
     }
 71  
 
 72  
     public boolean isAbstract() {
 73  6768
         return (getAccessFlag() & ACC_ABSTRACT) != 0;
 74  
     }
 75  
 
 76  
     public boolean isStrict() {
 77  62
         return (getAccessFlag() & ACC_STRICT) != 0;
 78  
     }
 79  
 
 80  
     public boolean isConstructor() {
 81  38903
         return getName().equals("<init>");
 82  
     }
 83  
 
 84  
     public boolean isStaticInitializer() {
 85  19495
         return getName().equals("<clinit>");
 86  
     }
 87  
 
 88  
     public Collection<Class_info> getExceptions() {
 89  6518
         Collection<Class_info> result = Collections.emptyList();
 90  
 
 91  6518
         for (Attribute_info attribute : getAttributes()) {
 92  6164
             if (attribute instanceof Exceptions_attribute) {
 93  12
                 result = ((Exceptions_attribute) attribute).getExceptions();
 94  
             }
 95  
         }
 96  
 
 97  6518
         return result;
 98  
     }
 99  
 
 100  
     public String getSignature() {
 101  31768
         StringBuffer result = new StringBuffer();
 102  
 
 103  31768
         if (isConstructor()) {
 104  16050
             result.append(getClassfile().getSimpleName());
 105  16050
             result.append(DescriptorHelper.getSignature(getDescriptor()));
 106  15718
         } else if (isStaticInitializer()) {
 107  4
             result.append("static {}");
 108  
         } else {
 109  15714
             result.append(getName());
 110  15714
             result.append(DescriptorHelper.getSignature(getDescriptor()));
 111  
         }
 112  
 
 113  31768
         return result.toString();
 114  
     }
 115  
 
 116  
     public String getReturnType() {
 117  7816
         return DescriptorHelper.getReturnType(getDescriptor());
 118  
     }
 119  
 
 120  
     public String getDeclaration() {
 121  6117
         StringBuffer result = new StringBuffer();
 122  
 
 123  6117
         if (isPublic()) result.append("public ");
 124  6117
         if (isProtected()) result.append("protected ");
 125  6117
         if (isPrivate()) result.append("private ");
 126  6117
         if (isStatic() && !isStaticInitializer()) result.append("static ");
 127  6117
         if (isFinal()) result.append("final ");
 128  6117
         if (isSynchronized()) result.append("synchronized ");
 129  6117
         if (isNative()) result.append("native ");
 130  6117
         if (isAbstract()) result.append("abstract ");
 131  
 
 132  6117
         if (!isConstructor() && !isStaticInitializer()) {
 133  3775
             result.append((getReturnType() != null) ? getReturnType() : "void").append(" ");
 134  
         }
 135  
 
 136  6117
         result.append(getSignature());
 137  
 
 138  6117
         if (getExceptions().size() != 0) {
 139  0
             result.append(" throws ");
 140  0
             Iterator i = getExceptions().iterator();
 141  0
             while (i.hasNext()) {
 142  0
                 result.append(i.next());
 143  0
                 if (i.hasNext()) {
 144  0
                     result.append(", ");
 145  
                 }
 146  
             }
 147  
         }
 148  
 
 149  6117
         return result.toString();
 150  
     }
 151  
 
 152  
     public com.jeantessier.classreader.Code_attribute getCode() {
 153  2111
         CodeFinder finder = new CodeFinder();
 154  2111
         accept(finder);
 155  2111
         return finder.getCode();
 156  
     }
 157  
 
 158  
     public void accept(Visitor visitor) {
 159  2657
         visitor.visitMethod_info(this);
 160  2657
     }
 161  
 }