"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "src/java/edu/umd/cs/findbugs/visitclass/PreorderVisitor.java" between
findbugs-3.0.0-source.zip and findbugs-3.0.1-source.zip

About: FindBugs uses static analysis to look for bugs in Java code. Source.

PreorderVisitor.java  (findbugs-3.0.0-source):PreorderVisitor.java  (findbugs-3.0.1-source)
skipping to change at line 23 skipping to change at line 23
* Lesser General Public License for more details. * Lesser General Public License for more details.
* *
* You should have received a copy of the GNU Lesser General Public * You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software * License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/ */
package edu.umd.cs.findbugs.visitclass; package edu.umd.cs.findbugs.visitclass;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection;
import java.util.HashSet; import java.util.HashSet;
import java.util.Set; import java.util.Set;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import org.apache.bcel.classfile.AnnotationDefault; import org.apache.bcel.classfile.AnnotationDefault;
import org.apache.bcel.classfile.AnnotationEntry; import org.apache.bcel.classfile.AnnotationEntry;
import org.apache.bcel.classfile.Annotations; import org.apache.bcel.classfile.Annotations;
import org.apache.bcel.classfile.Attribute; import org.apache.bcel.classfile.Attribute;
import org.apache.bcel.classfile.Code; import org.apache.bcel.classfile.Code;
import org.apache.bcel.classfile.CodeException; import org.apache.bcel.classfile.CodeException;
import org.apache.bcel.classfile.Constant; import org.apache.bcel.classfile.Constant;
import org.apache.bcel.classfile.ConstantCP;
import org.apache.bcel.classfile.ConstantClass; import org.apache.bcel.classfile.ConstantClass;
import org.apache.bcel.classfile.ConstantInterfaceMethodref;
import org.apache.bcel.classfile.ConstantMethodref;
import org.apache.bcel.classfile.ConstantNameAndType;
import org.apache.bcel.classfile.ConstantPool; import org.apache.bcel.classfile.ConstantPool;
import org.apache.bcel.classfile.ConstantUtf8; import org.apache.bcel.classfile.ConstantUtf8;
import org.apache.bcel.classfile.EnclosingMethod; import org.apache.bcel.classfile.EnclosingMethod;
import org.apache.bcel.classfile.Field; import org.apache.bcel.classfile.Field;
import org.apache.bcel.classfile.InnerClass; import org.apache.bcel.classfile.InnerClass;
import org.apache.bcel.classfile.InnerClasses; import org.apache.bcel.classfile.InnerClasses;
import org.apache.bcel.classfile.JavaClass; import org.apache.bcel.classfile.JavaClass;
import org.apache.bcel.classfile.LineNumber; import org.apache.bcel.classfile.LineNumber;
import org.apache.bcel.classfile.LineNumberTable; import org.apache.bcel.classfile.LineNumberTable;
import org.apache.bcel.classfile.LocalVariable; import org.apache.bcel.classfile.LocalVariable;
skipping to change at line 61 skipping to change at line 66
import edu.umd.cs.findbugs.FindBugs; import edu.umd.cs.findbugs.FindBugs;
import edu.umd.cs.findbugs.ba.AnalysisContext; import edu.umd.cs.findbugs.ba.AnalysisContext;
import edu.umd.cs.findbugs.ba.ClassContext; import edu.umd.cs.findbugs.ba.ClassContext;
import edu.umd.cs.findbugs.ba.XClass; import edu.umd.cs.findbugs.ba.XClass;
import edu.umd.cs.findbugs.ba.XField; import edu.umd.cs.findbugs.ba.XField;
import edu.umd.cs.findbugs.ba.XMethod; import edu.umd.cs.findbugs.ba.XMethod;
import edu.umd.cs.findbugs.classfile.CheckedAnalysisException; import edu.umd.cs.findbugs.classfile.CheckedAnalysisException;
import edu.umd.cs.findbugs.classfile.ClassDescriptor; import edu.umd.cs.findbugs.classfile.ClassDescriptor;
import edu.umd.cs.findbugs.classfile.DescriptorFactory; import edu.umd.cs.findbugs.classfile.DescriptorFactory;
import edu.umd.cs.findbugs.classfile.FieldDescriptor; import edu.umd.cs.findbugs.classfile.FieldDescriptor;
import edu.umd.cs.findbugs.classfile.FieldOrMethodDescriptor;
import edu.umd.cs.findbugs.classfile.Global; import edu.umd.cs.findbugs.classfile.Global;
import edu.umd.cs.findbugs.classfile.IAnalysisCache; import edu.umd.cs.findbugs.classfile.IAnalysisCache;
import edu.umd.cs.findbugs.classfile.MethodDescriptor; import edu.umd.cs.findbugs.classfile.MethodDescriptor;
import edu.umd.cs.findbugs.classfile.analysis.ClassInfo; import edu.umd.cs.findbugs.classfile.analysis.ClassInfo;
import edu.umd.cs.findbugs.classfile.analysis.FieldInfo; import edu.umd.cs.findbugs.classfile.analysis.FieldInfo;
import edu.umd.cs.findbugs.classfile.analysis.MethodInfo; import edu.umd.cs.findbugs.classfile.analysis.MethodInfo;
import edu.umd.cs.findbugs.internalAnnotations.DottedClassName; import edu.umd.cs.findbugs.internalAnnotations.DottedClassName;
import edu.umd.cs.findbugs.internalAnnotations.SlashedClassName; import edu.umd.cs.findbugs.internalAnnotations.SlashedClassName;
/** /**
skipping to change at line 317 skipping to change at line 323
} }
} }
public boolean amVisitingMainMethod() { public boolean amVisitingMainMethod() {
if (!visitingMethod) { if (!visitingMethod) {
throw new IllegalStateException("Not visiting a method"); throw new IllegalStateException("Not visiting a method");
} }
if (!method.isStatic()) { if (!method.isStatic()) {
return false; return false;
} }
if (!getMethodName().equals("main")) { if (!"main".equals(getMethodName())) {
return false; return false;
} }
if (!getMethodSig().equals("([Ljava/lang/String;)V")) { if (!"([Ljava/lang/String;)V".equals(getMethodSig())) {
return false; return false;
} }
return true; return true;
} }
// Extra classes (i.e. leaves in this context) // Extra classes (i.e. leaves in this context)
@Override @Override
public void visitInnerClasses(InnerClasses obj) { public void visitInnerClasses(InnerClasses obj) {
super.visitInnerClasses(obj); super.visitInnerClasses(obj);
skipping to change at line 530 skipping to change at line 536
public JavaClass getThisClass() { public JavaClass getThisClass() {
return thisClass; return thisClass;
} }
/** If currently visiting a method, get the method's fully qualified name */ /** If currently visiting a method, get the method's fully qualified name */
public String getFullyQualifiedMethodName() { public String getFullyQualifiedMethodName() {
if (!visitingMethod) { if (!visitingMethod) {
throw new IllegalStateException("getFullyQualifiedMethodName called while not visiting method"); throw new IllegalStateException("getFullyQualifiedMethodName called while not visiting method");
} }
if (fullyQualifiedMethodName == null) { if (fullyQualifiedMethodName == null) {
getDottedSuperclassName();
getMethodName(); getMethodName();
getDottedMethodSig(); getDottedMethodSig();
StringBuilder ref = new StringBuilder(5 + dottedClassName.length() + methodName.length() + dottedMethodSig.length()); StringBuilder ref = new StringBuilder(5 + dottedClassName.length() + methodName.length() + dottedMethodSig.length());
ref.append(dottedClassName).append(".").append(methodName).append(" : ").append(dottedMethodSig); ref.append(dottedClassName).append(".").append(methodName).append(" : ").append(dottedMethodSig);
fullyQualifiedMethodName = ref.toString(); fullyQualifiedMethodName = ref.toString();
} }
return fullyQualifiedMethodName; return fullyQualifiedMethodName;
} }
skipping to change at line 621 skipping to change at line 626
if (!inArray) { if (!inArray) {
count++; count++;
} }
inArray = false; inArray = false;
break; break;
} }
} }
} }
/**
* Returns true if given constant pool probably has a reference to any of su
pplied methods
* Useful to exclude from analysis uninteresting classes
* @param cp constant pool
* @param methods methods collection
* @return true if method is found
*/
public static boolean hasInterestingMethod(ConstantPool cp, Collection<Metho
dDescriptor> methods) {
for(Constant c : cp.getConstantPool()) {
if(c instanceof ConstantMethodref || c instanceof ConstantInterfaceM
ethodref) {
ConstantCP desc = (ConstantCP)c;
ConstantNameAndType nameAndType = (ConstantNameAndType) cp.getCo
nstant(desc.getNameAndTypeIndex());
String className = cp.getConstantString(desc.getClassIndex(), CO
NSTANT_Class);
String name = ((ConstantUtf8)cp.getConstant(nameAndType.getNameI
ndex())).getBytes();
String signature = ((ConstantUtf8)cp.getConstant(nameAndType.get
SignatureIndex())).getBytes();
// We don't know whether method is static thus cannot use equals
int hash = FieldOrMethodDescriptor.getNameSigHashCode(name, sign
ature);
for(MethodDescriptor method : methods) {
if (method.getNameSigHashCode() == hash
&& (method.getSlashedClassName().isEmpty() || method
.getSlashedClassName().equals(className))
&& method.getName().equals(name) && method.getSignat
ure().equals(signature)) {
return true;
}
}
}
}
return false;
}
public static boolean hasInterestingClass(ConstantPool cp, Collection<String
> classes) {
for(Constant c : cp.getConstantPool()) {
if(c instanceof ConstantClass) {
String className = ((ConstantUtf8)cp.getConstant(((ConstantClass
)c).getNameIndex())).getBytes();
if(classes.contains(className)) {
return true;
}
}
}
return false;
}
public int getNumberMethodArguments() { public int getNumberMethodArguments() {
return getNumberArguments(getMethodSig()); return getNumberArguments(getMethodSig());
} }
/** /**
* If currently visiting a method, get the method's slash-formatted * If currently visiting a method, get the method's slash-formatted
* signature * signature
*/ */
public String getMethodSig() { public String getMethodSig() {
if (!visitingMethod) { if (!visitingMethod) {
 End of changes. 8 change blocks. 
3 lines changed or deleted 61 lines changed or added

Home  |  About  |  All  |  Newest  |  Fossies Dox  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTPS