|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| EntityBeanMethodChecker | Line # 32 | 93.8% |
0.9375
|
16.06 | 41 | 16 | 16 | 0.39 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ( 10 of 11) | |||
| Result | |||
|
0.828125
|
com.puppycrawl.tools.checkstyle.checks.j2ee.EntityBeanCheckTest.testCreate
com.puppycrawl.tools.checkstyle.checks.j2ee.EntityBeanCheckTest.testCreate
|
1 PASS | |
|
0.421875
|
com.puppycrawl.tools.checkstyle.checks.j2ee.EntityBeanCheckTest.testPostCreate
com.puppycrawl.tools.checkstyle.checks.j2ee.EntityBeanCheckTest.testPostCreate
|
1 PASS | |
|
0.375
|
com.puppycrawl.tools.checkstyle.checks.j2ee.EntityBeanCheckTest.testHome
com.puppycrawl.tools.checkstyle.checks.j2ee.EntityBeanCheckTest.testHome
|
1 PASS | |
|
0.296875
|
com.puppycrawl.tools.checkstyle.checks.j2ee.EntityBeanCheckTest.testAbstractBeanBean
com.puppycrawl.tools.checkstyle.checks.j2ee.EntityBeanCheckTest.testAbstractBeanBean
|
1 PASS | |
|
0.296875
|
com.puppycrawl.tools.checkstyle.checks.j2ee.EntityBeanCheckTest.testBeanBean
com.puppycrawl.tools.checkstyle.checks.j2ee.EntityBeanCheckTest.testBeanBean
|
1 PASS | |
|
0.296875
|
com.puppycrawl.tools.checkstyle.checks.j2ee.EntityBeanCheckTest.testContainerBean
com.puppycrawl.tools.checkstyle.checks.j2ee.EntityBeanCheckTest.testContainerBean
|
1 PASS | |
|
0.296875
|
com.puppycrawl.tools.checkstyle.checks.j2ee.EntityBeanCheckTest.testDefaultBean
com.puppycrawl.tools.checkstyle.checks.j2ee.EntityBeanCheckTest.testDefaultBean
|
1 PASS | |
|
0.296875
|
com.puppycrawl.tools.checkstyle.checks.j2ee.EntityBeanCheckTest.testAbstractBean
com.puppycrawl.tools.checkstyle.checks.j2ee.EntityBeanCheckTest.testAbstractBean
|
1 PASS | |
|
0.296875
|
com.puppycrawl.tools.checkstyle.checks.j2ee.EntityBeanCheckTest.testMissingConstructor
com.puppycrawl.tools.checkstyle.checks.j2ee.EntityBeanCheckTest.testMissingConstructor
|
1 PASS | |
|
0.296875
|
com.puppycrawl.tools.checkstyle.checks.j2ee.EntityBeanCheckTest.testMixedBean
com.puppycrawl.tools.checkstyle.checks.j2ee.EntityBeanCheckTest.testMixedBean
|
1 PASS | |
| 1 test are not displayed. This report was configured to show the top 10 tests that covered this file. | |||
| 1 | //////////////////////////////////////////////////////////////////////////////// | |
| 2 | // checkstyle: Checks Java source code for adherence to a set of rules. | |
| 3 | // Copyright (C) 2001-2005 Oliver Burn | |
| 4 | // | |
| 5 | // This library is free software; you can redistribute it and/or | |
| 6 | // modify it under the terms of the GNU Lesser General Public | |
| 7 | // License as published by the Free Software Foundation; either | |
| 8 | // version 2.1 of the License, or (at your option) any later version. | |
| 9 | // | |
| 10 | // This library is distributed in the hope that it will be useful, | |
| 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| 13 | // Lesser General Public License for more details. | |
| 14 | // | |
| 15 | // You should have received a copy of the GNU Lesser General Public | |
| 16 | // License along with this library; if not, write to the Free Software | |
| 17 | // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
| 18 | //////////////////////////////////////////////////////////////////////////////// | |
| 19 | package com.puppycrawl.tools.checkstyle.checks.j2ee; | |
| 20 | ||
| 21 | import java.util.HashSet; | |
| 22 | import java.util.Iterator; | |
| 23 | import java.util.Set; | |
| 24 | ||
| 25 | import com.puppycrawl.tools.checkstyle.api.DetailAST; | |
| 26 | import com.puppycrawl.tools.checkstyle.api.TokenTypes; | |
| 27 | ||
| 28 | /** | |
| 29 | * Root class for entity bean method checks. | |
| 30 | * @author Rick Giles | |
| 31 | */ | |
| 32 | public class EntityBeanMethodChecker | |
| 33 | extends BeanMethodChecker | |
| 34 | { | |
| 35 | /** set of ejbCreate methods for matching with ejbPostCreate methods */ | |
| 36 | private final Set mEjbCreates = new HashSet(); | |
| 37 | ||
| 38 | /** set of ejbPostCreate methods for matching with ejbCreate methods */ | |
| 39 | private final Set mEjbPostCreates = new HashSet(); | |
| 40 | ||
| 41 | /** | |
| 42 | * Constructs a EntityBeanMethodChecker for a bean check. | |
| 43 | * @param aCheck the bean check. | |
| 44 | */ | |
| 45 | 24 |
public EntityBeanMethodChecker(EntityBeanCheck aCheck) |
| 46 | { | |
| 47 | 24 | super(aCheck); |
| 48 | } | |
| 49 | ||
| 50 | /** | |
| 51 | * {@inheritDoc} | |
| 52 | */ | |
| 53 | 15 |
public void checkMethods(DetailAST aAST) |
| 54 | { | |
| 55 | 15 | mEjbCreates.clear(); |
| 56 | 15 | mEjbPostCreates.clear(); |
| 57 | ||
| 58 | 15 | super.checkMethods(aAST); |
| 59 | ||
| 60 | 15 | checkCreateMatch(); |
| 61 | } | |
| 62 | ||
| 63 | /** | |
| 64 | * Checks that every ejbCreate method has a matching ejbPostCreate method. | |
| 65 | */ | |
| 66 | 15 |
protected void checkCreateMatch() |
| 67 | { | |
| 68 | 15 | final Iterator it = mEjbCreates.iterator(); |
| 69 | 17 | while (it.hasNext()) { |
| 70 | 2 | final DetailAST createMethod = (DetailAST) it.next(); |
| 71 | 2 | final DetailAST nameAST = |
| 72 | createMethod.findFirstToken(TokenTypes.IDENT); | |
| 73 | 2 | final String name = nameAST.getText(); |
| 74 | 2 | final String method = name.substring("ejbCreate".length()); |
| 75 | ||
| 76 | // search for matching ejbPostCreate; | |
| 77 | 2 | boolean match = false; |
| 78 | 2 | final Iterator itPostCreate = mEjbPostCreates.iterator(); |
| 79 | 4 | while (!match && itPostCreate.hasNext()) { |
| 80 | 2 | final DetailAST postCreateMethod = |
| 81 | (DetailAST) itPostCreate.next(); | |
| 82 | 2 | final DetailAST postCreateNameAST = |
| 83 | postCreateMethod.findFirstToken(TokenTypes.IDENT); | |
| 84 | 2 | final String postCreateName = postCreateNameAST.getText(); |
| 85 | 2 | if (!postCreateName.equals("ejbPostCreate" + method)) { |
| 86 | 0 | continue; |
| 87 | } | |
| 88 | 2 | match = |
| 89 | Utils.sameParameters(createMethod, postCreateMethod); | |
| 90 | } | |
| 91 | 2 | if (!match) { |
| 92 | 2 | final String suffix = name.substring("ejbCreate".length()); |
| 93 | 2 | final String postCreateName = "ejbPostCreate" + suffix; |
| 94 | 2 | logName(createMethod, "unmatchedejbcreate.bean", |
| 95 | new Object[] {postCreateName}); | |
| 96 | } | |
| 97 | } | |
| 98 | } | |
| 99 | ||
| 100 | /** | |
| 101 | * {@inheritDoc} | |
| 102 | */ | |
| 103 | 108 |
public void checkMethod(DetailAST aMethodAST) |
| 104 | { | |
| 105 | 108 | super.checkMethod(aMethodAST); |
| 106 | ||
| 107 | 108 | final DetailAST nameAST = aMethodAST.findFirstToken(TokenTypes.IDENT); |
| 108 | 108 | final String name = nameAST.getText(); |
| 109 | ||
| 110 | 108 | if (name.startsWith("ejbHome")) { |
| 111 | 2 | checkHomeMethod(aMethodAST); |
| 112 | } | |
| 113 | 106 | else if (name.startsWith("ejbPostCreate")) { |
| 114 | 4 | checkPostCreateMethod(aMethodAST); |
| 115 | } | |
| 116 | } | |
| 117 | ||
| 118 | /** | |
| 119 | * {@inheritDoc} | |
| 120 | */ | |
| 121 | 2 |
protected void checkCreateMethod(DetailAST aMethodAST) |
| 122 | { | |
| 123 | 2 | super.checkCreateMethod(aMethodAST); |
| 124 | ||
| 125 | 2 | mEjbCreates.add(aMethodAST); |
| 126 | ||
| 127 | // The return type must be the entity beans primary key type | |
| 128 | 2 | if (Utils.isVoid(aMethodAST)) { |
| 129 | 2 | logName(aMethodAST, "voidmethod.bean", new Object[] {}); |
| 130 | } | |
| 131 | } | |
| 132 | ||
| 133 | ||
| 134 | /** | |
| 135 | * Checks whether an ejbHome<METHOD>(...) method of an | |
| 136 | * entity bean satisfies requirements. | |
| 137 | * @param aMethodAST the AST for the method definition. | |
| 138 | */ | |
| 139 | 2 |
protected void checkHomeMethod(DetailAST aMethodAST) |
| 140 | { | |
| 141 | // the method may be final | |
| 142 | 2 | checkMethod(aMethodAST, true); |
| 143 | ||
| 144 | // The throws clause for a home method of an entity bean must not throw | |
| 145 | // the java.rmi.RemoteException. | |
| 146 | 2 | checkNotThrows(aMethodAST, "java.rmi.RemoteException"); |
| 147 | } | |
| 148 | ||
| 149 | /** | |
| 150 | * Checks whether an ejbPostCreate<METHOD>(...) method of an | |
| 151 | * entity bean satisfies requirements. | |
| 152 | * @param aMethodAST the AST for the method definition. | |
| 153 | ||