org.sonar.api.rules
Class Violation

java.lang.Object
  extended by org.sonar.api.rules.Violation

public class Violation
extends Object

A class that represents a violation. A violation happens when a resource does not respect a defined rule.


Constructor Summary
Violation(Rule rule)
          Deprecated. since 2.3. Use the factory method create()
Violation(Rule rule, Resource resource)
          Deprecated. since 2.3. Use the factory method create()
 
Method Summary
static Violation create(ActiveRule activeRule, Resource resource)
           
static Violation create(Rule rule, Resource resource)
           
 boolean equals(Object obj)
           
 Double getCost()
           
 Date getCreatedAt()
           
 Integer getLineId()
           
 String getMessage()
           
 RulePriority getPriority()
          Deprecated. since 2.5 use getSeverity() instead. See http://jira.codehaus.org/browse/SONAR-1829
 Resource getResource()
           
 Rule getRule()
           
 RulePriority getSeverity()
           
 int hashCode()
           
 Violation setCost(Double d)
          The cost to fix a violation can't be precisely computed without this information.
 Violation setCreatedAt(Date createdAt)
          For internal use only
 Violation setLineId(Integer lineId)
          Sets the violation line.
 Violation setMessage(String message)
          Sets the violation message
 Violation setPriority(RulePriority priority)
          Deprecated. since 2.5 use setSeverity(RulePriority) instead. See http://jira.codehaus.org/browse/SONAR-1829
 Violation setResource(Resource resource)
          Sets the resource the violation applies to
 Violation setRule(Rule rule)
          Sets the rule violated
 Violation setSeverity(RulePriority severity)
          For internal use only.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Violation

@Deprecated
public Violation(Rule rule)
Deprecated. since 2.3. Use the factory method create()

Creates of a violation from a rule. Will need to define the resource later on


Violation

@Deprecated
public Violation(Rule rule,
                            Resource resource)
Deprecated. since 2.3. Use the factory method create()

Creates a fully qualified violation

Parameters:
rule - the rule that has been violated
resource - the resource the violation should be attached to
Method Detail

getResource

public Resource getResource()

setResource

public Violation setResource(Resource resource)
Sets the resource the violation applies to

Returns:
the current object

getRule

public Rule getRule()

setRule

public Violation setRule(Rule rule)
Sets the rule violated

Returns:
the current object

getMessage

public String getMessage()

setMessage

public Violation setMessage(String message)
Sets the violation message

Returns:
the current object

getLineId

public Integer getLineId()
See Also:
setLineId(Integer)

setLineId

public Violation setLineId(Integer lineId)
Sets the violation line. Note that numbering starts from 1.

Returns:
the current object

getSeverity

public RulePriority getSeverity()
Since:
2.5

setSeverity

public Violation setSeverity(RulePriority severity)
For internal use only.

Since:
2.5

getPriority

@Deprecated
public RulePriority getPriority()
Deprecated. since 2.5 use getSeverity() instead. See http://jira.codehaus.org/browse/SONAR-1829


setPriority

@Deprecated
public Violation setPriority(RulePriority priority)
Deprecated. since 2.5 use setSeverity(RulePriority) instead. See http://jira.codehaus.org/browse/SONAR-1829

For internal use only


getCost

public Double getCost()
Since:
2.4
See Also:
setCost(Double)

setCost

public Violation setCost(Double d)
The cost to fix a violation can't be precisely computed without this information. Let's take the following example : a rule forbids to have methods whose complexity is greater than 10. Without this field "cost", the same violation is created with a method whose complexity is 15 and a method whose complexity is 100. If the cost to fix one point of complexity is 0.05h, then 15mn is necessary to fix the method whose complexity is 15, and 3h5mn is required to fix the method whose complexity is 100.

Since:
2.4

getCreatedAt

public Date getCreatedAt()
Since:
2.5

setCreatedAt

public Violation setCreatedAt(Date createdAt)
For internal use only

Since:
2.5

equals

public boolean equals(Object obj)
Overrides:
equals in class Object

hashCode

public int hashCode()
Overrides:
hashCode in class Object

toString

public String toString()
Overrides:
toString in class Object

create

public static Violation create(ActiveRule activeRule,
                               Resource resource)

create

public static Violation create(Rule rule,
                               Resource resource)


Copyright © 2009-2011 SonarSource. All Rights Reserved.