every Home interface must have findByPrimaryKey method

This commit is contained in:
Rick Giles 2003-06-30 20:40:13 +00:00
parent 7a2c495da7
commit 1bca9cc443
6 changed files with 67 additions and 19 deletions

View File

@ -92,4 +92,49 @@ public class AbstractInterfaceCheck
}
}
}
/**
* Checks that every method of an AST has a throws clause for a given
* Exception.
* @param aAST the AST to check.
* @param aException the name of the Exception class.
*/
protected void checkThrows(DetailAST aAST, String aException)
{
final DetailAST objBlock = aAST.findFirstToken(TokenTypes.OBJBLOCK);
if (objBlock != null) {
DetailAST child = (DetailAST) objBlock.getFirstChild();
while (child != null) {
if (child.getType() == TokenTypes.METHOD_DEF) {
if (!Utils.hasThrows(child, aException)) {
final DetailAST nameAST =
child.findFirstToken(TokenTypes.IDENT);
final String name = nameAST.getText();
log(nameAST.getLineNo(), nameAST.getColumnNo(),
"missingthrows.bean",
new Object[] {name, aException});
}
}
child = (DetailAST) child.getNextSibling();
}
}
}
/**
* Checks that an AST contains the definition of a findByPrimaryKey
* method.
* @param aAST the AST to check.
*/
protected void checkFindByPrimaryKey(DetailAST aAST)
{
if (!Utils.hasPublicMethod(aAST, "findByPrimaryKey", false, 1))
{
final DetailAST nameAST = aAST.findFirstToken(TokenTypes.IDENT);
log(
aAST.getLineNo(),
nameAST.getColumnNo(),
"missingmethod.bean",
new Object[] {"Home interface", "findByPrimaryKey"});
}
}
}

View File

@ -47,23 +47,9 @@ public class HomeInterfaceCheck
super.checkMethods(aAST);
// every method must throw java.rmi.RemoteException
final DetailAST objBlock = aAST.findFirstToken(TokenTypes.OBJBLOCK);
if (objBlock != null) {
DetailAST child = (DetailAST) objBlock.getFirstChild();
while (child != null) {
if (child.getType() == TokenTypes.METHOD_DEF) {
if (!Utils.hasThrows(child, "java.rmi.RemoteException")) {
final DetailAST nameAST =
child.findFirstToken(TokenTypes.IDENT);
final String name = nameAST.getText();
log(nameAST.getLineNo(), nameAST.getColumnNo(),
"missingthrows.bean",
new Object[] {name, "java.rmi.RemoteException"});
}
}
child = (DetailAST) child.getNextSibling();
}
}
checkThrows(aAST, "java.rmi.RemoteException");
// a home interface must have a findByPrimaryKey method
checkFindByPrimaryKey(aAST);
}
}

View File

@ -46,6 +46,9 @@ public class LocalHomeInterfaceCheck
{
super.checkMethods(aAST);
// a home interface must have a findByPrimaryKey method
checkFindByPrimaryKey(aAST);
// every method must not throw java.rmi.RemoteException
final DetailAST objBlock = aAST.findFirstToken(TokenTypes.OBJBLOCK);
if (objBlock != null) {

View File

@ -26,7 +26,7 @@ import com.puppycrawl.tools.checkstyle.api.DetailAST;
* @version 30-Jun-2003
*/
public class RemoteInterfaceCheck
extends HomeInterfaceCheck
extends AbstractInterfaceCheck
{
/**
* @see com.puppycrawl.tools.checkstyle.api.Check
@ -37,4 +37,16 @@ public class RemoteInterfaceCheck
checkMethods(aAST);
}
}
/**
*
* @see com.puppycrawl.tools.checkstyle.checks.j2ee.AbstractInterfaceCheck
*/
protected void checkMethods(DetailAST aAST)
{
super.checkMethods(aAST);
// every method must throw java.rmi.RemoteException
checkThrows(aAST, "java.rmi.RemoteException");
}
}

View File

@ -10,6 +10,7 @@ public class HomeInterfaceCheckTest extends BaseCheckTestCase
final DefaultConfiguration checkConfig =
createCheckConfig(HomeInterfaceCheck.class);
final String[] expected = {
"14:18: Home interface has no findByPrimaryKey method.",
"20:19: Method createSomething does not throw java.rmi.RemoteException.",
"20:19: Method createSomething does not throw javax.ejb.CreateException.",
"20:19: Method createSomething is not public.",

View File

@ -10,6 +10,7 @@ public class LocalHomeInterfaceCheckTest extends BaseCheckTestCase
final DefaultConfiguration checkConfig =
createCheckConfig(LocalHomeInterfaceCheck.class);
final String[] expected = {
"12:18: Home interface has no findByPrimaryKey method.",
"18:19: Method createSomething does not throw javax.ejb.CreateException.",
"18:19: Method createSomething is not public.",
"18:19: Void createSomething method.",