EntityBean finder checks.

This commit is contained in:
Rick Giles 2003-06-30 13:26:14 +00:00
parent 304ca8487a
commit cc857f0940
7 changed files with 147 additions and 0 deletions

View File

@ -9,6 +9,8 @@
<module name="TreeWalker">
<module name="j2ee.EntityBean"/>
<module name="j2ee.EntityBeanEjbCreate"/>
<module name="j2ee.EntityBeanFindByPrimaryKey"/>
<module name="j2ee.EntityBeanFinder"/>
<module name="j2ee.MessageBean"/>
<module name="j2ee.SessionBean"/>
<module name="j2ee.SessionBeanEjbCreate"/>

View File

@ -0,0 +1,48 @@
////////////////////////////////////////////////////////////////////////////////
// checkstyle: Checks Java source code for adherence to a set of rules.
// Copyright (C) 2001-2003 Oliver Burn
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
////////////////////////////////////////////////////////////////////////////////
package com.puppycrawl.tools.checkstyle.checks.j2ee;
import com.puppycrawl.tools.checkstyle.api.DetailAST;
import com.puppycrawl.tools.checkstyle.api.TokenTypes;
/**
* Checks that an EntityBean defines method ejbFindByPrimaryKey.
* @author Rick Giles
*/
public class EntityBeanFindByPrimaryKeyCheck
extends AbstractBeanCheck
{
/**
* @see com.puppycrawl.tools.checkstyle.api.Check
*/
public void visitToken(DetailAST aAST)
{
if (Utils.hasImplements(aAST, "javax.ejb.EntityBean")
&& !Utils.isAbstract(aAST)
&& !Utils.hasPublicMethod(aAST, "ejbFindByPrimaryKey", false, 1))
{
final DetailAST nameAST = aAST.findFirstToken(TokenTypes.IDENT);
log(
aAST.getLineNo(),
nameAST.getColumnNo(),
"missingmethod.bean",
new Object[] {"Entity bean", "ejbFindByPrimaryKey"});
}
}
}

View File

@ -0,0 +1,52 @@
////////////////////////////////////////////////////////////////////////////////
// checkstyle: Checks Java source code for adherence to a set of rules.
// Copyright (C) 2001-2003 Oliver Burn
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
////////////////////////////////////////////////////////////////////////////////
package com.puppycrawl.tools.checkstyle.checks.j2ee;
import com.puppycrawl.tools.checkstyle.api.DetailAST;
import com.puppycrawl.tools.checkstyle.api.TokenTypes;
/**
* Checks that an EntityBean ejbFind method satisfies these requirements:
* <ul>
* <li>The access control modifier must be <code>public</code>.</li>
* <li>The return type must not be void.</li>
* <li>The method modifier cannot be <code>final</code>
* or <code>static</code>.</li>
* </ul>
* @author Rick Giles
*/
public class EntityBeanFinderCheck
extends AbstractMethodCheck
{
/** @see com.puppycrawl.tools.checkstyle.api.Check */
public void visitToken(DetailAST aAST)
{
final DetailAST nameAST = aAST.findFirstToken(TokenTypes.IDENT);
final String name = nameAST.getText();
if (name.startsWith("ejbFind")
&& Utils.implementsEntityBean(aAST))
{
checkMethod(aAST);
if (Utils.isVoid(aAST)) {
log(nameAST.getLineNo(), nameAST.getColumnNo(),
"voidmethod.bean", name);
}
}
}
}

View File

@ -91,6 +91,10 @@ final class FinalEntityBean
protected static final void ejbCreate(int i)
{
}
protected static final void ejbFindSomething()
{
}
/**
* @see javax.ejb.EntityBean#setEntityContext(javax.ejb.EntityContext)

View File

@ -18,6 +18,8 @@ public class AllTests {
//$JUnit-BEGIN$
suite.addTest(new TestSuite(EntityBeanCheckTest.class));
suite.addTest(new TestSuite(EntityBeanEjbCreateCheckTest.class));
suite.addTest(new TestSuite(EntityBeanFindByPrimaryKeyCheckTest.class));
suite.addTest(new TestSuite(EntityBeanFinderCheckTest.class));
suite.addTest(new TestSuite(MessageBeanCheckTest.class));
suite.addTest(new TestSuite(SessionBeanCheckTest.class));
suite.addTest(new TestSuite(SessionBeanEjbCreateCheckTest.class));

View File

@ -0,0 +1,19 @@
import com.puppycrawl.tools.checkstyle.BaseCheckTestCase;
import com.puppycrawl.tools.checkstyle.DefaultConfiguration;
import com.puppycrawl.tools.checkstyle.checks.j2ee.EntityBeanFindByPrimaryKeyCheck;
public class EntityBeanFindByPrimaryKeyCheckTest
extends BaseCheckTestCase
{
public void testDefault()
throws Exception
{
final DefaultConfiguration checkConfig =
createCheckConfig(EntityBeanFindByPrimaryKeyCheck.class);
final String[] expected = {
"13:14: Entity bean has no ejbFindByPrimaryKey method.",
"83:13: Entity bean has no ejbFindByPrimaryKey method.",
};
verify(checkConfig, getPath("InputEntityBean.java"), expected);
}
}

View File

@ -0,0 +1,20 @@
import com.puppycrawl.tools.checkstyle.BaseCheckTestCase;
import com.puppycrawl.tools.checkstyle.DefaultConfiguration;
import com.puppycrawl.tools.checkstyle.checks.j2ee.EntityBeanFinderCheck;
public class EntityBeanFinderCheckTest extends BaseCheckTestCase
{
public void testDefault()
throws Exception
{
final DefaultConfiguration checkConfig =
createCheckConfig(EntityBeanFinderCheck.class);
final String[] expected = {
"95:33: Method ejbFindSomething has illegal modifier final.",
"95:33: Method ejbFindSomething has illegal modifier static.",
"95:33: Method ejbFindSomething is not public.",
"95:33: Void ejbFindSomething method.",
};
verify(checkConfig, getPath("InputEntityBean.java"), expected);
}
}