<commentsxsi:type="java:LineComment"originalCompilationUnit="//@compilationUnits.0"content="// oops, this probably was supposed to be boolean equals"enclosedByParent="true"/>
<commentsxsi:type="java:LineComment"originalCompilationUnit="//@compilationUnits.0"content="// oops, this probably was supposed to be equals(Object)"enclosedByParent="true"/>
<commentsxsi:type="java:LineComment"originalCompilationUnit="//@compilationUnits.0"content="// oops, this probably was supposed to be boolean equals"enclosedByParent="true"/>
<commentsxsi:type="java:LineComment"originalCompilationUnit="//@compilationUnits.0"content="// oops, this probably was supposed to be equals(Object)"enclosedByParent="true"/>
<commentsxsi:type="java:LineComment"originalCompilationUnit="//@compilationUnits.0"content="// oops, this probably was supposed to be equals(Object)"enclosedByParent="true"/>
<commentsxsi:type="java:LineComment"originalCompilationUnit="//@compilationUnits.0"content="// oops, this probably was supposed to be equals(Object)"enclosedByParent="true"/>
<commentsxsi:type="java:LineComment"originalCompilationUnit="//@compilationUnits.0"content="// oops, this probably was supposed to be equals(Object)"enclosedByParent="true"/>
<commentsxsi:type="java:LineComment"originalCompilationUnit="//@compilationUnits.0"content="// oops, this probably was supposed to be equals(Object)"enclosedByParent="true"/>
shortDescription <- 'The method name and parameter number are suspiciously close to equals(Object), which can denote an intention to override the equals(Object) method.'
),
measurement: smm!DirectMeasurement (
error <- 'The class ' + method.originalCompilationUnit.name + ' has a suspicious \'equals\' method name : ' + method.toString()
)
do {
noc;
}
}
-- A Measure instance if the class violates the rule 'AvoidUsingShortType'
--Detects the declaration of methods whose name and parameters looks like the equals(Object) method, which denote an intention to override the equals(Object) method.
--A method that looks like equals(Object) is named 'equals', or 'equal' wich is a common typo, and the parameters and return type can be wrong typed.
method.name = 'equals' or method.name = 'equal' and --'equal' method name can be a typo
(
(
method.parameters.size() = 1 and --there is only one parameter and the type of this parameter is wrong, or the return type of the method is wrong, or both.
not(method.parameters.first().type.type.name = 'Object') or
not(method.returnType.type.name = 'boolean')
)
or
(
method.parameters.size() = 2 and --there are two parameters, and everything is well typed
method.parameters->forAll(param | param.type.type.name = 'Object') and
method.returnType.type.name = 'boolean'
)
)
or
(
method.name = 'equal' and --the method is well typed but there is a typo
method.parameters.size() = 1 and
method.parameters.first().type.type.name = 'Object' and
method.returnType.type.name = 'boolean'
);
--Allows to have the signature of a method as a String.