Added ejbPostCreate, ejbHome, ejbSelect checks for entity beans.

Uniform error messages.
This commit is contained in:
Rick Giles 2003-06-30 23:38:36 +00:00
parent 24a774b1e8
commit 9f4164a450
21 changed files with 304 additions and 59 deletions

View File

@ -9,6 +9,9 @@
<module name="TreeWalker">
<module name="j2ee.EntityBean"/>
<module name="j2ee.EntityBeanEjbCreate"/>
<module name="j2ee.EntityBeanEjbHome"/>
<module name="j2ee.EntityBeanEjbPostCreate"/>
<module name="j2ee.EntityBeanEjbSelect"/>
<module name="j2ee.EntityBeanFindByPrimaryKey"/>
<module name="j2ee.EntityBeanFinder"/>
<module name="j2ee.HomeInterface"/>

View File

@ -38,13 +38,14 @@ public class EntityBeanEjbCreateCheck
public void visitToken(DetailAST aAST)
{
final DetailAST nameAST = aAST.findFirstToken(TokenTypes.IDENT);
if (nameAST.getText().equals("ejbCreate")
final String name = nameAST.getText();
if (name.startsWith("ejbCreate")
&& Utils.implementsEntityBean(aAST))
{
checkMethod(aAST);
if (Utils.isVoid(aAST)) {
log(nameAST.getLineNo(), nameAST.getColumnNo(),
"voidmethod.bean", "ejbCreate");
"voidmethod.bean", name);
}
}
}

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 a EntityBean ejbHome method satisfies these requirements:
* <ul>
* <li>The access control modifier must be <code>public</code>.</li>
* <li>The method modifier cannot be <code>final</code>
* or <code>static</code>.</li>
* </ul>
* @author Rick Giles
*/
public class EntityBeanEjbHomeCheck
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("ejbHome")
&& Utils.implementsEntityBean(aAST))
{
checkMethod(aAST);
if (Utils.hasThrows(aAST, "java.rmi.RemoteException")) {
log(nameAST.getLineNo(), nameAST.getColumnNo(),
"illegalthrows.bean",
new Object[] {name, "java.rmi.RemoteException"});
}
}
}
}

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 a EntityBean ejbPostCreate method satisfies these requirements:
* <ul>
* <li>The access control modifier must be <code>public</code>.</li>
* <li>The return type must be void.</li>
* <li>The method modifier cannot be <code>final</code>
* or <code>static</code>.</li>
* </ul>
* @author Rick Giles
*/
public class EntityBeanEjbPostCreateCheck
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("ejbPostCreate")
&& Utils.implementsEntityBean(aAST))
{
checkMethod(aAST);
if (!Utils.isVoid(aAST)) {
log(nameAST.getLineNo(), nameAST.getColumnNo(),
"nonvoidmethod.bean", name);
}
}
}
}

View File

@ -0,0 +1,57 @@
////////////////////////////////////////////////////////////////////////////////
// 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 a EntityBean ejbSelect method satisfies these requirements:
* <ul>
* <li>The access control modifier must be <code>public</code>.</li>
* <li>The method must be <code>abstract</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 EntityBeanEjbSelectCheck
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("ejbSelect")
&& Utils.implementsEntityBean(aAST))
{
checkMethod(aAST);
if (Utils.isVoid(aAST)) {
log(nameAST.getLineNo(), nameAST.getColumnNo(),
"voidmethod.bean", name);
}
if (!Utils.isAbstract(aAST)) {
log(nameAST.getLineNo(), nameAST.getColumnNo(),
"nonabstract.bean", "Method " + name);
}
}
}
}

View File

@ -1,9 +1,10 @@
hasfinalize.bean={0} defines the finalize method.
illegalmodifier.bean={0} has illegal modifier {1}.
hasfinalize.bean={0} must not define the finalize method.
illegalmodifier.bean={0} must not have modifier {1}.
illegalthrows.bean=Method {0} must not throw {1}.
missingmethod.bean={0} has no {1} method.
missingthrows.bean=Method {0} does not throw {1}.
nonpublicconstructor.bean={0} does not have a public constructor with no parameters.
nonpublic.bean={0} is not public.
nonvoidmethod.bean=Non-void {0} method.
voidmethod.bean=Void {0} method.
missingmethod.bean={0} must have method {1}.
missingthrows.bean=Method {0} must throw {1}.
nonabstract.bean={0} must be abstract.
nonpublicconstructor.bean={0} must have a public constructor with no parameters.
nonpublic.bean={0} must be public.
nonvoidmethod.bean=Method {0} must be void.
voidmethod.bean=Method {0} must be non-void.

View File

@ -96,6 +96,21 @@ final class FinalEntityBean
{
}
protected static final int ejbPostCreate(int i)
{
return 0;
}
protected static final int ejbHomeMethod(int i)
throws java.rmi.RemoteException
{
return 0;
}
protected static final void ejbSelectSomething(int i)
{
}
/**
* @see javax.ejb.EntityBean#setEntityContext(javax.ejb.EntityContext)
*/

View File

@ -18,6 +18,9 @@ public class AllTests {
//$JUnit-BEGIN$
suite.addTest(new TestSuite(EntityBeanCheckTest.class));
suite.addTest(new TestSuite(EntityBeanEjbCreateCheckTest.class));
suite.addTest(new TestSuite(EntityBeanEjbHomeCheckTest.class));
suite.addTest(new TestSuite(EntityBeanEjbPostCreateCheckTest.class));
suite.addTest(new TestSuite(EntityBeanEjbSelectCheckTest.class));
suite.addTest(new TestSuite(EntityBeanFindByPrimaryKeyCheckTest.class));
suite.addTest(new TestSuite(EntityBeanFinderCheckTest.class));
suite.addTest(new TestSuite(HomeInterfaceCheckTest.class));

View File

@ -10,9 +10,9 @@ public class EntityBeanCheckTest extends BaseCheckTestCase
final DefaultConfiguration checkConfig =
createCheckConfig(EntityBeanCheck.class);
final String[] expected = {
"13:14: Entity bean does not have a public constructor with no parameters.",
"83:13: Entity bean has illegal modifier final.",
"83:13: Entity bean is not public.",
"13:14: Entity bean must have a public constructor with no parameters.",
"83:13: Entity bean must be public.",
"83:13: Entity bean must not have modifier final.",
};
verify(checkConfig, getPath("InputEntityBean.java"), expected);
}

View File

@ -10,10 +10,10 @@ public class EntityBeanEjbCreateCheckTest extends BaseCheckTestCase
final DefaultConfiguration checkConfig =
createCheckConfig(EntityBeanEjbCreateCheck.class);
final String[] expected = {
"91:33: Method ejbCreate has illegal modifier final.",
"91:33: Method ejbCreate has illegal modifier static.",
"91:33: Method ejbCreate is not public.",
"91:33: Void ejbCreate method.",
"91:33: Method ejbCreate must be non-void.",
"91:33: Method ejbCreate must be public.",
"91:33: Method ejbCreate must not have modifier final.",
"91:33: Method ejbCreate must not have modifier static.",
};
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.EntityBeanEjbHomeCheck;
public class EntityBeanEjbHomeCheckTest extends BaseCheckTestCase
{
public void testDefault()
throws Exception
{
final DefaultConfiguration checkConfig =
createCheckConfig(EntityBeanEjbHomeCheck.class);
final String[] expected = {
"104:32: Method ejbHomeMethod must be public.",
"104:32: Method ejbHomeMethod must not have modifier final.",
"104:32: Method ejbHomeMethod must not have modifier static.",
"104:32: Method ejbHomeMethod must not throw java.rmi.RemoteException.",
};
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.EntityBeanEjbPostCreateCheck;
public class EntityBeanEjbPostCreateCheckTest extends BaseCheckTestCase
{
public void testDefault()
throws Exception
{
final DefaultConfiguration checkConfig =
createCheckConfig(EntityBeanEjbPostCreateCheck.class);
final String[] expected = {
"99:32: Method ejbPostCreate must be public.",
"99:32: Method ejbPostCreate must be void.",
"99:32: Method ejbPostCreate must not have modifier final.",
"99:32: Method ejbPostCreate must not have modifier static.",
};
verify(checkConfig, getPath("InputEntityBean.java"), expected);
}
}

View File

@ -0,0 +1,21 @@
import com.puppycrawl.tools.checkstyle.BaseCheckTestCase;
import com.puppycrawl.tools.checkstyle.DefaultConfiguration;
import com.puppycrawl.tools.checkstyle.checks.j2ee.EntityBeanEjbSelectCheck;
public class EntityBeanEjbSelectCheckTest extends BaseCheckTestCase
{
public void testDefault()
throws Exception
{
final DefaultConfiguration checkConfig =
createCheckConfig(EntityBeanEjbSelectCheck.class);
final String[] expected = {
"110:33: Method ejbSelectSomething must be abstract.",
"110:33: Method ejbSelectSomething must be non-void.",
"110:33: Method ejbSelectSomething must be public.",
"110:33: Method ejbSelectSomething must not have modifier final.",
"110:33: Method ejbSelectSomething must not have modifier static.",
};
verify(checkConfig, getPath("InputEntityBean.java"), expected);
}
}

View File

@ -11,8 +11,8 @@ public class EntityBeanFindByPrimaryKeyCheckTest
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.",
"13:14: Entity bean must have method ejbFindByPrimaryKey.",
"83:13: Entity bean must have method ejbFindByPrimaryKey.",
};
verify(checkConfig, getPath("InputEntityBean.java"), expected);
}

View File

@ -10,10 +10,10 @@ public class EntityBeanFinderCheckTest extends BaseCheckTestCase
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.",
"95:33: Method ejbFindSomething must be non-void.",
"95:33: Method ejbFindSomething must be public.",
"95:33: Method ejbFindSomething must not have modifier final.",
"95:33: Method ejbFindSomething must not have modifier static.",
};
verify(checkConfig, getPath("InputEntityBean.java"), expected);
}

View File

@ -10,15 +10,15 @@ 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.",
"20:19: Void createSomething method.",
"22:19: Method findSomething does not throw java.rmi.RemoteException.",
"22:19: Method findSomething does not throw javax.ejb.FinderException.",
"22:19: Method findSomething is not public.",
"22:19: Void findSomething method.",
"14:18: Home interface must have method findByPrimaryKey.",
"20:19: Method createSomething must be non-void.",
"20:19: Method createSomething must be public.",
"20:19: Method createSomething must throw java.rmi.RemoteException.",
"20:19: Method createSomething must throw javax.ejb.CreateException.",
"22:19: Method findSomething must be non-void.",
"22:19: Method findSomething must be public.",
"22:19: Method findSomething must throw java.rmi.RemoteException.",
"22:19: Method findSomething must throw javax.ejb.FinderException.",
};
verify(checkConfig, getPath("InputHomeInterface.java"), expected);
}

View File

@ -10,13 +10,13 @@ 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.",
"20:19: Method findSomething does not throw javax.ejb.FinderException.",
"20:19: Method findSomething is not public.",
"20:19: Void findSomething method.",
"12:18: Home interface must have method findByPrimaryKey.",
"18:19: Method createSomething must be non-void.",
"18:19: Method createSomething must be public.",
"18:19: Method createSomething must throw javax.ejb.CreateException.",
"20:19: Method findSomething must be non-void.",
"20:19: Method findSomething must be public.",
"20:19: Method findSomething must throw javax.ejb.FinderException.",
"25:17: Method method must not throw java.rmi.RemoteException.",
};
verify(checkConfig, getPath("InputLocalHomeInterface.java"), expected);

View File

@ -10,10 +10,10 @@ public class MessageBeanCheckTest extends BaseCheckTestCase
final DefaultConfiguration checkConfig =
createCheckConfig(MessageBeanCheck.class);
final String[] expected = {
"12:14: Message bean does not have a public constructor with no parameters.",
"12:14: Message bean has no ejbCreate method.",
"46:13: Message bean has illegal modifier final.",
"46:13: Message bean is not public.",
"12:14: Message bean must have a public constructor with no parameters.",
"12:14: Message bean must have method ejbCreate.",
"46:13: Message bean must be public.",
"46:13: Message bean must not have modifier final.",
};
verify(checkConfig, getPath("InputMessageBean.java"), expected);
}

View File

@ -10,14 +10,14 @@ public class RemoteInterfaceCheckTest extends BaseCheckTestCase
final DefaultConfiguration checkConfig =
createCheckConfig(RemoteInterfaceCheck.class);
final String[] expected = {
"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.",
"20:19: Void createSomething method.",
"22:19: Method findSomething does not throw java.rmi.RemoteException.",
"22:19: Method findSomething does not throw javax.ejb.FinderException.",
"22:19: Method findSomething is not public.",
"22:19: Void findSomething method.",
"20:19: Method createSomething must be non-void.",
"20:19: Method createSomething must be public.",
"20:19: Method createSomething must throw java.rmi.RemoteException.",
"20:19: Method createSomething must throw javax.ejb.CreateException.",
"22:19: Method findSomething must be non-void.",
"22:19: Method findSomething must be public.",
"22:19: Method findSomething must throw java.rmi.RemoteException.",
"22:19: Method findSomething must throw javax.ejb.FinderException.",
};
verify(checkConfig, getPath("InputRemoteInterface.java"), expected);
}

View File

@ -10,10 +10,10 @@ public class SessionBeanCheckTest extends BaseCheckTestCase
final DefaultConfiguration checkConfig =
createCheckConfig(SessionBeanCheck.class);
final String[] expected = {
"12:14: Session bean does not have a public constructor with no parameters.",
"12:14: Session bean has no ejbCreate method.",
"58:13: Session bean has illegal modifier final.",
"58:13: Session bean is not public.",
"12:14: Session bean must have a public constructor with no parameters.",
"12:14: Session bean must have method ejbCreate.",
"58:13: Session bean must be public.",
"58:13: Session bean must not have modifier final.",
};
verify(checkConfig, getPath("InputSessionBean.java"), expected);
}

View File

@ -10,10 +10,10 @@ public class SessionBeanEjbCreateCheckTest extends BaseCheckTestCase
final DefaultConfiguration checkConfig =
createCheckConfig(SessionBeanEjbCreateCheck.class);
final String[] expected = {
"69:32: Method ejbCreate has illegal modifier final.",
"69:32: Method ejbCreate has illegal modifier static.",
"69:32: Method ejbCreate is not public.",
"69:32: Non-void ejbCreate method.",
"69:32: Method ejbCreate must be public.",
"69:32: Method ejbCreate must be void.",
"69:32: Method ejbCreate must not have modifier final.",
"69:32: Method ejbCreate must not have modifier static.",
};
verify(checkConfig, getPath("InputSessionBean.java"), expected);
}