/** * Adds the specified annotation to this container. * * @param annotation the annotation to add */ public final void addAnnotation(final FileAnnotation annotation) { if (!annotations.contains(annotation)) { expandRelativePaths(annotation); annotations.add(annotation); Integer count = annotationCountByPriority.get(annotation.getPriority()); annotationCountByPriority.put(annotation.getPriority(), count + 1); } }
/** * Adds the specified annotation to this container. * * @param annotation the annotation to add * @return the number of added annotations */ @WithBridgeMethods(value = void.class) // JENKINS-25405 public final int addAnnotation(final FileAnnotation annotation) { expandRelativePaths(annotation); if (annotations.add(annotation)) { Integer count = annotationCountByPriority.get(annotation.getPriority()); annotationCountByPriority.put(annotation.getPriority(), count + 1); return 1; } return 0; }
private void mergeResults(final BuildResult current, final Map<String, Integer[]> annotationCountByUser) { Collection<FileAnnotation> annotations = current.getAnnotations(); for (FileAnnotation annotation : annotations) { String author = annotation.getAuthor(); if (StringUtils.isNotBlank(author) && !"-".equals(author)) { if (annotationCountByUser.get(author) == null) { annotationCountByUser.put(author, new Integer[]{0, 0, 0}); } Integer[] priorities = annotationCountByUser.get(author); int index = annotation.getPriority().ordinal(); priorities[index]++; } } }
/** * Creates a project that contains a single annotation. * * @return the created project */ private ParserResult createProjectWithWarning() { ParserResult project = new ParserResult(); FileAnnotation annotation = mock(FileAnnotation.class); when(annotation.getPriority()).thenReturn(Priority.HIGH); when(annotation.getFileName()).thenReturn(FILENAME); when(annotation.getModuleName()).thenReturn("Module"); when(annotation.getPackageName()).thenReturn("Package"); project.addAnnotation(annotation); return project; }
/** * Creates a project that contains a single annotation. * * @return the created project */ private ParserResult createProjectWithWarning() { ParserResult project = new ParserResult(); FileAnnotation annotation = mock(FileAnnotation.class); when(annotation.getPriority()).thenReturn(Priority.HIGH); when(annotation.getFileName()).thenReturn(FILENAME); when(annotation.getModuleName()).thenReturn("Module"); when(annotation.getPackageName()).thenReturn("Package"); project.addAnnotation(annotation); return project; }
Priority prio = annotation.getPriority(); if (prio == Priority.LOW && !showLow) { continue;
@Override protected Collection<FileAnnotation> postProcessWarnings(final List<FileAnnotation> warnings) { List<FileAnnotation> condensed = Lists.newArrayList(); int line = -1; for (FileAnnotation warning : warnings) { if (warning.getPrimaryLineNumber() == line + 1 && !condensed.isEmpty()) { FileAnnotation previous = condensed.get(condensed.size() - 1); if (previous.getPriority() == warning.getPriority()) { condensed.remove(condensed.size() - 1); condensed.add(new Warning(previous, warning.getMessage(), warning.getPrimaryLineNumber())); } } else { condensed.add(warning); } line = warning.getPrimaryLineNumber(); } List<FileAnnotation> noBlank = Lists.newArrayList(); for (FileAnnotation warning : condensed) { if (StringUtils.isNotBlank(warning.getMessage())) { noBlank.add(warning); } } return noBlank; } }
if (warning.getPrimaryLineNumber() == line + 1 && !condensed.isEmpty()) { FileAnnotation previous = condensed.getLast(); if (previous.getPriority() == warning.getPriority()) { condensed.removeLast(); if (previous.getMessage().length() + warning.getMessage().length() >= MAX_MESSAGE_LENGTH) {
/** * Updates the annotation drill-down mappings (priority, packages, files) with the specified annotation. * * @param annotation the new annotation */ private void updateMappings(final FileAnnotation annotation) { annotationsByPriority.get(annotation.getPriority()).add(annotation); if (StringUtils.isNotBlank(annotation.getCategory())) { addCategory(annotation); } if (StringUtils.isNotBlank(annotation.getType())) { addType(annotation); } if (hierarchy == Hierarchy.PROJECT) { addModule(annotation); } if (hierarchy == Hierarchy.PROJECT || hierarchy == Hierarchy.MODULE) { addPackage(annotation); } if (hierarchy == Hierarchy.PROJECT || hierarchy == Hierarchy.MODULE || hierarchy == Hierarchy.PACKAGE) { addFile(annotation); } }
/** * Updates the annotation drill-down mappings (priority, packages, files) with the specified annotation. * * @param annotation the new annotation */ @SuppressWarnings("SF_SWITCH_FALLTHROUGH") @java.lang.SuppressWarnings("fallthrough") private void updateMappings(final FileAnnotation annotation) { annotationsByPriority.get(annotation.getPriority()).add(annotation); if (StringUtils.isNotBlank(annotation.getCategory())) { addCategory(annotation); } if (StringUtils.isNotBlank(annotation.getType())) { addType(annotation); } if (hierarchy == Hierarchy.PROJECT) { addModule(annotation); } if (hierarchy == Hierarchy.PROJECT || hierarchy == Hierarchy.MODULE) { addPackage(annotation); } if (hierarchy == Hierarchy.PROJECT || hierarchy == Hierarchy.MODULE || hierarchy == Hierarchy.PACKAGE) { addFile(annotation); } if (hierarchy == Hierarchy.PROJECT || hierarchy == Hierarchy.MODULE || hierarchy == Hierarchy.PACKAGE || hierarchy == Hierarchy.FILE) { addAuthorName(annotation); } }
public Warning(final FileAnnotation copy, final int currentLine) { super(copy.getPriority(), copy.getMessage(), copy.getPrimaryLineNumber(), currentLine, copy.getCategory(), copy.getType()); setFileName(copy.getFileName()); setOrigin(ORIGIN); }
/** * Creates a new instance of {@link Warning}. This warning is a copy of the * specified warning with the additional message text (at the specified * line). * * @param copy * the warning to copy * @param additionalMessage * the additional message text * @param currentLine * the current line */ public Warning(final FileAnnotation copy, final String additionalMessage, final int currentLine) { super(copy.getPriority(), copy.getMessage() + "\n" + additionalMessage, copy.getPrimaryLineNumber(), currentLine, copy.getCategory(), copy.getType()); setFileName(copy.getFileName()); setOrigin(ORIGIN); }
/** * Creates a new instance of {@link Warning}. This warning is a copy of the * specified warning with the additional message text (at the specified * line). * * @param copy * the warning to copy * @param additionalMessage * the additional message text * @param currentLine * the current line */ public Warning(final FileAnnotation copy, final String additionalMessage, final int currentLine) { super(copy.getPriority(), copy.getMessage() + "\n" + additionalMessage, copy.getPrimaryLineNumber(), currentLine, copy.getCategory(), copy.getType()); setFileName(copy.getFileName()); setOrigin(ORIGIN); }
/** * Copy constructor: Creates a new instance of {@link AbstractAnnotation}. * * @param copy * the annotation to copy the values from */ @SuppressFBWarnings("ST") public AbstractAnnotation(final FileAnnotation copy) { key = currentKey++; message = TreeString.of(copy.getMessage()); priority = copy.getPriority(); primaryLineNumber = copy.getPrimaryLineNumber(); lineRanges = new LineRangeList(copy.getLineRanges()); contextHashCode = copy.getContextHashCode(); fileName = TreeString.of(copy.getFileName()); category = copy.getCategory(); type = copy.getType(); moduleName = TreeString.of(copy.getModuleName()); packageName = TreeString.of(copy.getPackageName()); authorName = copy.getAuthorName(); authorEmail = copy.getAuthorEmail(); commitId = copy.getCommitId(); overridePackageCategoryName = TreeString.of(copy.getOverridePackageCategoryName()); }