Add Builder pattern check

Summary: Add the builder pattern check to the MissingStaticMethodInNonInstantiatableClass rule

Test Plan: run tests

Reviewers: jmsotuyo

Reviewed By: jmsotuyo

Maniphest Tasks: T1440

Differential Revision: http://ph.monits.com/D13295
This commit is contained in:
Damian Techeira
2015-10-30 10:55:48 -03:00
parent b0e657a3d8
commit 50554257ce
2 changed files with 47 additions and 0 deletions

View File

@ -843,6 +843,21 @@ A class that has private constructors and does not have any static methods or fi
]
) > 0]
) = 0
and
count(//ClassOrInterfaceDeclaration
[@Nested='true']
[@Static='true']
[@Public='true']
[.//MethodDeclaration
[@Public='true']
[.//ReturnStatement//AllocationExpression
[ClassOrInterfaceType
[@Image = //ClassOrInterfaceDeclaration/@Image]
]
[./Arguments//PrimaryPrefix/@ThisModifier='true']
]
]
) = 0
]
]]>
</value>

View File

@ -177,6 +177,38 @@ public class AccountSelectionSubForm extends Form implements WidgetEventListener
{
super( parent, null );
}
}
]]></code>
</test-code>
<test-code>
<description>Check Builder pattern</description>
<expected-problems>0</expected-problems>
<code><![CDATA[
public final class BacklogElementParameters {
private final Long backlogId;
private final String name;
private BacklogElementParameters(final BacklogElementParameters.Builder builder) {
this.backlogId = builder.backlogId;
this.name = builder.name;
}
public static class Builder {
public Builder backlogId(final Long backlogId) {
this.backlogId = backlogId;
return this;
}
public Builder name(final String name) {
this.name = name;
return this;
}
public BacklogElementParameters build() {
return new BacklogElementParameters(this);
}
}
}
]]></code>
</test-code>