}
BugCode bugCode = pattern.getBugCode();
return bugCode.getCWEid();
}
public void writeXML(XMLOutput xmlOutput, BugCollection bugCollection, boolean addMessages) throws IOException {
XMLAttributeList attributeList = new XMLAttributeList().addAttribute("type", type).addAttribute("priority",
String.valueOf(priority));
// Always add the rank attribute.
attributeList.addAttribute("rank", Integer.toString(getBugRank()));
BugPattern pattern = getBugPattern();
// The bug abbreviation and pattern category are
// emitted into the XML for informational purposes only.
// (The information is redundant, but might be useful
// for processing tools that want to make sense of
// bug instances without looking at the plugin descriptor.)
attributeList.addAttribute("abbrev", pattern.getAbbrev());
attributeList.addAttribute("category", pattern.getCategory());
if (addMessages) {
// Add a uid attribute, if we have a unique id.
attributeList.addAttribute("instanceHash", getInstanceHash());
attributeList.addAttribute("instanceOccurrenceNum", Integer.toString(getInstanceOccurrenceNum()));
attributeList.addAttribute("instanceOccurrenceMax", Integer.toString(getInstanceOccurrenceMax()));
int cweid = getCWEid();
if (cweid != 0) {
attributeList.addAttribute("cweid", Integer.toString(cweid));
}
} else if (oldInstanceHash != null && !isInstanceHashConsistent()) {
attributeList.addAttribute("oldInstanceHash", oldInstanceHash);
}
if (firstVersion > 0) {
attributeList.addAttribute("first", Long.toString(firstVersion));
}
if (lastVersion >= 0) {
attributeList.addAttribute("last", Long.toString(lastVersion));
}
if (introducedByChangeOfExistingClass) {
attributeList.addAttribute("introducedByChange", "true");
}
if (removedByChangeOfPersistingClass) {
attributeList.addAttribute("removedByChange", "true");
}
if (bugCollection != null) {
Cloud cloud = bugCollection.getCloudLazily();
if (cloud != null && cloud.communicationInitiated()) {
long firstSeen = cloud.getFirstSeen(this);
attributeList.addAttribute("firstSeen", firstSeenXMLFormat().format(firstSeen));
int reviews = cloud.getNumberReviewers(this);
UserDesignation consensus = cloud.getConsensusDesignation(this);
if (!cloud.isInCloud(this)) {
attributeList.addAttribute("isInCloud", "false");
}
if (reviews > 0) {
attributeList.addAttribute("reviews", Integer.toString(reviews));
if (consensus != UserDesignation.UNCLASSIFIED) {
attributeList.addAttribute("consensus", consensus.toString());
}
}
if (addMessages) {
int ageInDays = ageInDays(bugCollection, firstSeen);
attributeList.addAttribute("ageInDays", Integer.toString(ageInDays));
if (reviews > 0 && consensus != UserDesignation.UNCLASSIFIED) {
if (consensus.score() < 0) {
attributeList.addAttribute("notAProblem", "true");
}
if (consensus.score() > 0) {
attributeList.addAttribute("shouldFix", "true");
}
}
}
} else if (hasXmlProps()) {
XmlProps props = getXmlProps();
if (props.firstSeen != null) {
attributeList.addOptionalAttribute("firstSeen", firstSeenXMLFormat().format(props.firstSeen));
}
if (props.reviewCount > 0) {
if (props.consensus != null) {
attributeList.addOptionalAttribute("consensus", props.consensus);
}
attributeList.addAttribute("reviews", Integer.toString(props.reviewCount));
}
if (!props.isInCloud()) {
attributeList.addAttribute("isInCloud", "false");
}
if (addMessages) {
UserDesignation consesus = UserDesignation.valueOf(props.consensus);
if (consesus.shouldFix()) {
attributeList.addAttribute("shouldFix", "true");
} else if (consesus.notAProblem()) {
attributeList.addAttribute("notAProblem", "true");
}
if (props.firstSeen != null) {
int ageInDays = ageInDays(bugCollection, props.firstSeen.getTime());
attributeList.addAttribute("ageInDays", Integer.toString(ageInDays));
}
}
}
}