Package edu.hm.hafner.analysis
Class IssueBuilder
- java.lang.Object
-
- edu.hm.hafner.analysis.IssueBuilder
-
- All Implemented Interfaces:
AutoCloseable
public class IssueBuilder extends Object implements AutoCloseable
Creates newissuesusing the builder pattern. All properties that have not been set in the builder will be set to their default value.Example:
Issue issue = new IssueBuilder() .setFileName("affected.file") .setLineStart(0) .setCategory("JavaDoc") .setMessage("Missing JavaDoc") .setSeverity(Severity.WARNING_LOW);- Author:
- Ullrich Hafner
-
-
Constructor Summary
Constructors Constructor Description IssueBuilder()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Issuebuild()Creates a newIssuebased on the specified properties.IssuebuildAndClean()Creates a newIssuebased on the specified properties.Optional<Issue>buildOptional()Creates a newIssuebased on the specified properties.voidclose()Reduce the memory print of internal string instances.IssueBuildercopy(Issue copy)Initializes this builder with an exact copy of all properties of the specified issue.IssueBuilderguessSeverity(String severityString)Guesses a severity for the issues: converts a String severity to one of the predefined severities.IssueBuildersetAdditionalProperties(Serializable additionalProperties)Sets additional properties from the statical analysis tool.IssueBuildersetCategory(String category)Sets the category of this issue (depends on the available categories of the static analysis tool).IssueBuildersetColumnEnd(int columnEnd)Sets the the last column of this issue (columns start at 1).IssueBuildersetColumnEnd(String columnEnd)Sets the the last column of this issue (columns start at 1).IssueBuildersetColumnStart(int columnStart)Sets the first column of this issue (columns start at 1, 0 indicates the whole line).IssueBuildersetColumnStart(String columnStart)Sets the first column of this issue (columns start at 1, 0 indicates the whole line).IssueBuildersetDescription(String description)Sets an additional description for this issue.IssueBuildersetDirectory(String directory)Sets the current work directory.IssueBuildersetFileName(String fileName)Sets the name of the affected file.IssueBuildersetFingerprint(String fingerprint)Sets the fingerprint for this issue.IssueBuildersetId(UUID id)Sets the unique ID of the issue.IssueBuildersetLineEnd(int lineEnd)Sets the last line of this issue (lines start at 1).IssueBuildersetLineEnd(String lineEnd)Sets the last line of this issue (lines start at 1).IssueBuildersetLineRanges(LineRangeList lineRanges)Sets additional line ranges for this issue.IssueBuildersetLineStart(int lineStart)Sets the first line of this issue (lines start at 1; 0 indicates the whole file).IssueBuildersetLineStart(String lineStart)Sets the first line of this issue (lines start at 1; 0 indicates the whole file).IssueBuildersetMessage(String message)Sets the detailed message for this issue.IssueBuildersetModuleName(String moduleName)Sets the name of the module or project (or similar concept) that contains this issue.IssueBuildersetOrigin(String origin)Sets the ID of the tool that did report this issue.IssueBuildersetOriginName(String originName)Sets the name of the tool that did report this issue.IssueBuildersetPackageName(String packageName)Sets the name of the package or name space (or similar concept) that contains this issue.IssueBuildersetPathName(String pathName)Sets the path of the affected file.IssueBuildersetReference(String reference)Sets a reference to the execution of the static analysis tool (build ID, timestamp, etc.).IssueBuildersetSeverity(Severity severity)Sets the severity of this issue.IssueBuildersetType(String type)Sets the type of this issue (depends on the available types of the static analysis tool).
-
-
-
Method Detail
-
setId
public IssueBuilder setId(UUID id)
Sets the unique ID of the issue. If not set then an ID will be generated.- Parameters:
id- the ID- Returns:
- this
-
setAdditionalProperties
public IssueBuilder setAdditionalProperties(@CheckForNull Serializable additionalProperties)
Sets additional properties from the statical analysis tool. This object could be used to store tool specific information.- Parameters:
additionalProperties- the instance- Returns:
- this
-
setFingerprint
public IssueBuilder setFingerprint(@CheckForNull String fingerprint)
Sets the fingerprint for this issue. Used to decide if two issues are equal even if the equals method returnsfalsesince some of the properties differ due to code refactorings. The fingerprint is created by analyzing the content of the affected file.- Parameters:
fingerprint- the fingerprint to set- Returns:
- this
-
setFileName
public IssueBuilder setFileName(@CheckForNull String fileName)
Sets the name of the affected file. This file name is a path relative to the path of the affected files (seesetPathName(String)).- Parameters:
fileName- the file name- Returns:
- this
-
setDirectory
public IssueBuilder setDirectory(@CheckForNull String directory)
Sets the current work directory. This directory is used as prefix for all subsequent issue file names. If the path is set as well, then the final path of an issue is the concatenation ofpath,directory, andfileName. Note that this directory is not visible later on, the issue does only store the path in thepathandfileNameproperties. I.e., the created issue will get a new file name that is composed ofdirectoryandfileName.- Parameters:
directory- the directory that contains all affected files- Returns:
- this
-
setPathName
public IssueBuilder setPathName(@CheckForNull String pathName)
Sets the path of the affected file. Note that this path is not the parent folder of the affected file. This path is the folder that contains all of the affected files of aReport. The path of an affected file is stored in thepathandfileNameproperties so that issues can be tracked even if the root folder changes (due to different build environments).- Parameters:
pathName- the path that contains all affected files- Returns:
- this
-
setLineStart
public IssueBuilder setLineStart(int lineStart)
Sets the first line of this issue (lines start at 1; 0 indicates the whole file).- Parameters:
lineStart- the first line- Returns:
- this
-
setLineStart
public IssueBuilder setLineStart(@CheckForNull String lineStart)
Sets the first line of this issue (lines start at 1; 0 indicates the whole file).- Parameters:
lineStart- the first line- Returns:
- this
-
setLineEnd
public IssueBuilder setLineEnd(int lineEnd)
Sets the last line of this issue (lines start at 1).- Parameters:
lineEnd- the last line- Returns:
- this
-
setLineEnd
public IssueBuilder setLineEnd(@CheckForNull String lineEnd)
Sets the last line of this issue (lines start at 1).- Parameters:
lineEnd- the last line- Returns:
- this
-
setColumnStart
public IssueBuilder setColumnStart(int columnStart)
Sets the first column of this issue (columns start at 1, 0 indicates the whole line).- Parameters:
columnStart- the first column- Returns:
- this
-
setColumnStart
public IssueBuilder setColumnStart(@CheckForNull String columnStart)
Sets the first column of this issue (columns start at 1, 0 indicates the whole line).- Parameters:
columnStart- the first column- Returns:
- this
-
setColumnEnd
public IssueBuilder setColumnEnd(int columnEnd)
Sets the the last column of this issue (columns start at 1).- Parameters:
columnEnd- the last column- Returns:
- this
-
setColumnEnd
public IssueBuilder setColumnEnd(@CheckForNull String columnEnd)
Sets the the last column of this issue (columns start at 1).- Parameters:
columnEnd- the last column- Returns:
- this
-
setCategory
public IssueBuilder setCategory(@CheckForNull String category)
Sets the category of this issue (depends on the available categories of the static analysis tool). Examples for categories are "Deprecation", "Design", or "JavaDoc".- Parameters:
category- the category- Returns:
- this
-
setType
public IssueBuilder setType(@CheckForNull String type)
Sets the type of this issue (depends on the available types of the static analysis tool). The type typically is the associated rule of the static analysis tool that reported this issue.- Parameters:
type- the type- Returns:
- this
-
setPackageName
public IssueBuilder setPackageName(@CheckForNull String packageName)
Sets the name of the package or name space (or similar concept) that contains this issue.- Parameters:
packageName- the package or namespace name- Returns:
- this
-
setModuleName
public IssueBuilder setModuleName(@CheckForNull String moduleName)
Sets the name of the module or project (or similar concept) that contains this issue.- Parameters:
moduleName- the module name- Returns:
- this
-
setOrigin
public IssueBuilder setOrigin(@CheckForNull String origin)
Sets the ID of the tool that did report this issue.- Parameters:
origin- the ID of the originating tool- Returns:
- this
-
setOriginName
public IssueBuilder setOriginName(@CheckForNull String originName)
Sets the name of the tool that did report this issue.- Parameters:
originName- the ID of the originating tool- Returns:
- this
-
setReference
public IssueBuilder setReference(@CheckForNull String reference)
Sets a reference to the execution of the static analysis tool (build ID, timestamp, etc.).- Parameters:
reference- the reference- Returns:
- this
-
setSeverity
public IssueBuilder setSeverity(@CheckForNull Severity severity)
Sets the severity of this issue.- Parameters:
severity- the severity- Returns:
- this
-
guessSeverity
public IssueBuilder guessSeverity(@CheckForNull String severityString)
Guesses a severity for the issues: converts a String severity to one of the predefined severities. If the provided String does not match (even partly) then the default severity will be returned.- Parameters:
severityString- the severity given as a string representation- Returns:
- this
-
setMessage
public IssueBuilder setMessage(@CheckForNull String message)
Sets the detailed message for this issue.- Parameters:
message- the message- Returns:
- this
-
setDescription
public IssueBuilder setDescription(@CheckForNull String description)
Sets an additional description for this issue. Static analysis tools might provide some additional information about this issue. This description may contain valid HTML.- Parameters:
description- the description (as HTML content)- Returns:
- this
-
setLineRanges
public IssueBuilder setLineRanges(LineRangeList lineRanges)
Sets additional line ranges for this issue. Not that the primary range given bylineStartand* lineEndis not included.- Parameters:
lineRanges- the additional line ranges- Returns:
- this
-
copy
public IssueBuilder copy(Issue copy)
Initializes this builder with an exact copy of all properties of the specified issue.- Parameters:
copy- the issue to copy the properties from- Returns:
- the initialized builder
-
build
public Issue build()
Creates a newIssuebased on the specified properties. After building the issue, thisIssueBuildercreates a new ID, but all otherIssueproperties will remain unchanged.- Returns:
- the created issue
-
buildAndClean
public Issue buildAndClean()
Creates a newIssuebased on the specified properties. After building the issue, thisIssueBuilderwill be reset to its defaults.- Returns:
- the created issue
-
buildOptional
public Optional<Issue> buildOptional()
Creates a newIssuebased on the specified properties. The returned issue is wrapped in anOptional. After building the issue, thisIssueBuilderwill be reset to its defaults.- Returns:
- the created issue
- See Also:
buildAndClean()
-
close
public void close()
Reduce the memory print of internal string instances.- Specified by:
closein interfaceAutoCloseable
-
-