public int compareClasses(BugCollection lhsCollection, BugCollection rhsCollection, ClassAnnotation lhsClass, ClassAnnotation rhsClass) { if (lhsClass == null || rhsClass == null) { return compareNullElements(lhsClass, rhsClass); } else { return compareClassesByName(lhsCollection, rhsCollection, lhsClass.getClassName(), rhsClass.getClassName()); } }
@Override protected String formatPackageMember(String key, ClassAnnotation primaryClass) { if ("".equals(key) || "hash".equals(key)) { return className + "." + fieldName; } else if ("givenClass".equals(key)) { String primaryClassName = primaryClass.getClassName(); if (className.equals(primaryClassName)) { return getNameInClass(primaryClass); } else { return shorten(primaryClass.getPackageName(), className) + "." + fieldName; } } else if ("name".equals(key)) { return fieldName; } else if ("fullField".equals(key)) { SignatureConverter converter = new SignatureConverter(fieldSig); StringBuilder result = new StringBuilder(); if (isStatic) { result.append("static "); } result.append(converter.parseNext()); result.append(' '); result.append(className); result.append('.'); result.append(fieldName); return result.toString(); } else { throw new IllegalArgumentException("unknown key " + key); } }
@Override public boolean match(BugInstance bugInstance) { ClassAnnotation primaryClassAnnotation = bugInstance.getPrimaryClass(); if(primaryClassAnnotation == null){ return false; } String bugFileName = primaryClassAnnotation.getSourceFileName(); if(bugFileName == null || bugFileName.isEmpty()){ return false; } boolean result = fileName.match(bugFileName); if (DEBUG) { System.out.println("Matching " + bugFileName + " with " + fileName + ", result = " + result); } return result; }
static ClassAnnotation obfuscate(ClassAnnotation m) { ClassAnnotation result = new ClassAnnotation(hashClass(m.getClassName())); result.setDescription(m.getDescription()); return result; }
@Override protected String formatPackageMember(String key, ClassAnnotation primaryClass) { if ("".equals(key) || "hash".equals(key)) { return className; } else if ("givenClass".equals(key)) { return shorten(primaryClass.getPackageName(), className); } else if ("excludingPackage".equals(key)) { return shorten(getPackageName(), className); } else if ("simpleClass".equals(key) || "simpleName".equals(key)) { return ClassName.extractSimpleName(className); } else { throw new IllegalArgumentException("unknown key " + key); } }
String className = classBugFoundIn.getClassName(); String sourceFile = classBugFoundIn.getSourceFileName(); boolean fixed = sourceFile != null && analyzedSourceFiles.contains(sourceFile) || newCollection.getProjectStats().getClassStats(className) != null; String className = classBugFoundIn.getClassName(); if (origCollection.getProjectStats().getClassStats(className) != null) { newBug.setIntroducedByChangeOfExistingClass(true);
@Override public void writeXML(XMLOutput xmlOutput, boolean addMessages, boolean isPrimary) throws IOException { XMLAttributeList attributeList = new XMLAttributeList().addAttribute("classname", getClassName()); if (isPrimary) { attributeList.addAttribute("primary", "true"); } String role = getDescription(); if (!DEFAULT_ROLE.equals(role)) { attributeList.addAttribute("role", role); } xmlOutput.openTag(ELEMENT_NAME, attributeList); getSourceLines().writeXML(xmlOutput, addMessages, false); if (addMessages) { xmlOutput.openTag(BugAnnotation.MESSAGE_TAG); xmlOutput.writeText(this.toString()); xmlOutput.closeTag(BugAnnotation.MESSAGE_TAG); } xmlOutput.closeTag(ELEMENT_NAME); } }
private String getNameInClass(ClassAnnotation primaryClass) { if (primaryClass == null) { return className + "." + fieldName; } String givenPackageName = primaryClass.getPackageName(); String thisPackageName = this.getPackageName(); if (thisPackageName.equals(givenPackageName)) { if (thisPackageName.length() == 0) { return fieldName; } else { return className.substring(thisPackageName.length() + 1) + "." + fieldName; } } return className + "." + fieldName; }
if (a instanceof SourceLineAnnotation) { SourceLineAnnotation s = (SourceLineAnnotation) a; if (s.getClassName().equals(primaryClass.getClassName()) && s.getStartLine() > 0) { firstLine = Math.min(firstLine, s.getStartLine()); lastLine = Math.max(lastLine, s.getEndLine()); SourceLineAnnotation primarySource = primaryClass.getSourceLines(); if (primarySource.isSourceFileKnown() && firstLine >= 1 && firstLine <= lastLine && lastLine - firstLine < 50) { BufferedReader in = null;
public ClassAnnotation getTopLevelClass() { int firstDollar = className.indexOf('$'); if (firstDollar <= 0) { return this; } return new ClassAnnotation(className.substring(0, firstDollar)); }
/** * Add a class annotation. If this is the first class annotation added, it * becomes the primary class annotation. * * @param classDescriptor * the class to add * @return this object */ @Nonnull public BugInstance addClass(ClassDescriptor classDescriptor) { add(ClassAnnotation.fromClassDescriptor(classDescriptor)); return this; }
@Override public boolean match(BugInstance bugInstance) { if (!super.match(bugInstance)) { return false; } ClassAnnotation primaryClassAnnotation = bugInstance.getPrimaryClass(); if (DEBUG) { System.out.println("Compare " + primaryClassAnnotation + " with " + clazz); } return clazz.contains(primaryClassAnnotation); } }
ClassDescriptor classDesc = clazz.getClassDescriptor(); if(field != null && classDesc.equals(field.getClassDescriptor())) { continue;
@Override protected ActionResult doAccept(BugInstance issue, Ignore action) { final MethodAnnotation method = issue.getPrimaryMethod(); final String className = issue.getPrimaryClass().getClassName(); final String methodName = method == null ? null : method.getMethodName(); final Language language = Language.byFilename(issue.getPrimaryClass().getSourceFileName()); return action.accept(new NamedLocation(issue.getType(), language, className, methodName, true)); }
static ClassAnnotation obfuscate(ClassAnnotation m) { ClassAnnotation result = new ClassAnnotation(hashClass(m.getClassName())); result.setDescription(m.getDescription()); return result; }
@Override public void writeXML(XMLOutput xmlOutput, boolean addMessages, boolean isPrimary) throws IOException { XMLAttributeList attributeList = new XMLAttributeList().addAttribute("classname", getClassName()); if (isPrimary) { attributeList.addAttribute("primary", "true"); } String role = getDescription(); if (!DEFAULT_ROLE.equals(role)) { attributeList.addAttribute("role", role); } xmlOutput.openTag(ELEMENT_NAME, attributeList); getSourceLines().writeXML(xmlOutput, addMessages, false); if (addMessages) { xmlOutput.openTag(BugAnnotation.MESSAGE_TAG); xmlOutput.writeText(this.toString()); xmlOutput.closeTag(BugAnnotation.MESSAGE_TAG); } xmlOutput.closeTag(ELEMENT_NAME); } }
public void countBug(BugInstance b) { String packageName = b.getPrimaryClass().getPackageName(); countPackageMember(packageName); }
/** * Factory method to create a ClassAnnotation from a ClassDescriptor. * * @param classDescriptor * the ClassDescriptor * @return the ClassAnnotation */ public static ClassAnnotation fromClassDescriptor(ClassDescriptor classDescriptor) { return new ClassAnnotation(classDescriptor.toDottedClassName()); }
@Override protected String formatPackageMember(String key, ClassAnnotation primaryClass) { if ("".equals(key) || "hash".equals(key)) { return className; } else if ("givenClass".equals(key)) { return shorten(primaryClass.getPackageName(), className); } else if ("excludingPackage".equals(key)) { return shorten(getPackageName(), className); } else if ("simpleClass".equals(key) || "simpleName".equals(key)) { return ClassName.extractSimpleName(className); } else { throw new IllegalArgumentException("unknown key " + key); } }
annotation.add(ClassAnnotation.fromClassDescriptor(getClassDescriptor())); annotation.add(MethodAnnotation.fromVisitedMethod(this)); annotation.add(SourceLineAnnotation.fromVisitedInstruction(this));