|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| CheckUtils | Line # 35 | 95.7% |
0.9574468
|
41.13 | 89 | 41 | 41 | 0.46 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ( 10 of 70) | |||
| Result | |||
|
0.38297874
|
com.puppycrawl.tools.checkstyle.checks.coding.MagicNumberCheckTest.testIgnoreNone
com.puppycrawl.tools.checkstyle.checks.coding.MagicNumberCheckTest.testIgnoreNone
|
1 PASS | |
|
0.38297874
|
com.puppycrawl.tools.checkstyle.checks.coding.MagicNumberCheckTest.testDefault
com.puppycrawl.tools.checkstyle.checks.coding.MagicNumberCheckTest.testDefault
|
1 PASS | |
|
0.38297874
|
com.puppycrawl.tools.checkstyle.checks.coding.MagicNumberCheckTest.testIgnoreSome
com.puppycrawl.tools.checkstyle.checks.coding.MagicNumberCheckTest.testIgnoreSome
|
1 PASS | |
|
0.35460994
|
com.puppycrawl.tools.checkstyle.checks.coding.MagicNumberCheckTest.testIgnoreNegativeOctalHex
com.puppycrawl.tools.checkstyle.checks.coding.MagicNumberCheckTest.testIgnoreNegativeOctalHex
|
1 PASS | |
|
0.35460994
|
com.puppycrawl.tools.checkstyle.checks.coding.MagicNumberCheckTest.testIntegersOnly
com.puppycrawl.tools.checkstyle.checks.coding.MagicNumberCheckTest.testIntegersOnly
|
1 PASS | |
|
0.28368795
|
com.puppycrawl.tools.checkstyle.checks.coding.ExplicitInitializationCheckTest.testDefault
com.puppycrawl.tools.checkstyle.checks.coding.ExplicitInitializationCheckTest.testDefault
|
1 PASS | |
|
0.120567374
|
com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocTypeCheckTest.testAllowMissingTypeParameters
com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocTypeCheckTest.testAllowMissingTypeParameters
|
1 PASS | |
|
0.120567374
|
com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocTypeCheckTest.testTypeParameters
com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocTypeCheckTest.testTypeParameters
|
1 PASS | |
|
0.120567374
|
com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocMethodCheckTest.testTypeParamsTags
com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocMethodCheckTest.testTypeParamsTags
|
1 PASS | |
|
0.11347517
|
com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocStyleCheckTest.testScopeProtected
com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocStyleCheckTest.testScopeProtected
|
1 PASS | |
| 60 tests 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; | |
| 20 | ||
| 21 | import com.puppycrawl.tools.checkstyle.api.DetailAST; | |
| 22 | import com.puppycrawl.tools.checkstyle.api.FullIdent; | |
| 23 | import com.puppycrawl.tools.checkstyle.api.TokenTypes; | |
| 24 | ||
| 25 | import java.util.List; | |
| 26 | import java.util.ArrayList; | |
| 27 | ||
| 28 | /** | |
| 29 | * Contains utility methods for the checks. | |
| 30 | * | |
| 31 | * @author Oliver Burn | |
| 32 | * @author <a href="mailto:simon@redhillconsulting.com.au">Simon Harris</a> | |
| 33 | * @author o_sukhodolsky | |
| 34 | */ | |
| 35 | public final class CheckUtils | |
| 36 | { | |
| 37 | /** prevent instances */ | |
| 38 | 0 |
private CheckUtils() |
| 39 | { | |
| 40 | 0 | throw new UnsupportedOperationException(); |
| 41 | } | |
| 42 | ||
| 43 | /** | |
| 44 | * Tests whether a method definition AST defines an equals covariant. | |
| 45 | * @param aAST the method definition AST to test. | |
| 46 | * Precondition: aAST is a TokenTypes.METHOD_DEF node. | |
| 47 | * @return true if aAST defines an equals covariant. | |
| 48 | */ | |
| 49 | 20 |
public static boolean isEqualsMethod(DetailAST aAST) |
| 50 | { | |
| 51 | 20 | if (aAST.getType() != TokenTypes.METHOD_DEF) { |
| 52 | // A node must be method def | |
| 53 | 0 | return false; |
| 54 | } | |
| 55 | ||
| 56 | // non-static, non-abstract? | |
| 57 | 20 | final DetailAST modifiers = aAST.findFirstToken(TokenTypes.MODIFIERS); |
| 58 | 20 | if (modifiers.branchContains(TokenTypes.LITERAL_STATIC) |
| 59 | || modifiers.branchContains(TokenTypes.ABSTRACT)) | |
| 60 | { | |
| 61 | 1 | return false; |
| 62 | } | |
| 63 | ||
| 64 | // named "equals"? | |
| 65 | 19 | final DetailAST nameNode = aAST.findFirstToken(TokenTypes.IDENT); |
| 66 | 19 | final String name = nameNode.getText(); |
| 67 | 19 | if (!"equals".equals(name)) { |
| 68 | 3 | return false; |
| 69 | } | |
| 70 | ||
| 71 | // one parameter? | |
| 72 | 16 | final DetailAST paramsNode = aAST.findFirstToken(TokenTypes.PARAMETERS); |
| 73 | 16 | return (paramsNode.getChildCount() == 1); |
| 74 | } | |
| 75 | ||
| 76 | /** | |
| 77 | * Returns whether a token represents an ELSE as part of an ELSE / IF set. | |
| 78 | * @param aAST the token to check | |
| 79 | * @return whether it is | |
| 80 | */ | |
| 81 | 68 |
public static boolean isElseIf(DetailAST aAST) |
| 82 | { | |
| 83 | 68 | final DetailAST parentAST = aAST.getParent(); |
| 84 | ||
| 85 | 68 | return (aAST.getType() == TokenTypes.LITERAL_IF) |
| 86 | && (isElse(parentAST) || isElseWithCurlyBraces(parentAST)); | |
| 87 | } | |
| 88 | ||
| 89 | /** | |
| 90 | * Returns whether a token represents an ELSE. | |
| 91 | * @param aAST the token to check | |
| 92 | * @return whether the token represents an ELSE | |
| 93 | */ | |
| 94 | 112 |
private static boolean isElse(DetailAST aAST) |
| 95 | { | |
| 96 | 112 | return aAST.getType() == TokenTypes.LITERAL_ELSE; |
| 97 | } | |
| 98 | ||
| 99 | /** | |
| 100 | * Returns whether a token represents an SLIST as part of an ELSE | |
| 101 | * statement. | |
| 102 | * @param aAST the token to check | |
| 103 | * @return whether the toke does represent an SLIST as part of an ELSE | |
| 104 | */ | |
| 105 | 68 |
private static boolean isElseWithCurlyBraces(DetailAST aAST) |
| 106 | { | |
| 107 | 68 | return (aAST.getType() == TokenTypes.SLIST) |
| 108 | && (aAST.getChildCount() == 2) | |
| 109 | && isElse(aAST.getParent()); | |
| 110 | } | |
| 111 | ||
| 112 | /** | |
| 113 | * Creates <code>FullIdent</code> for given type node. | |
| 114 | * @param aTypeAST a type node. | |
| 115 | * @return <code>FullIdent</code> for given type. | |
| 116 | */ | |
| 117 | 69 |
public static FullIdent createFullType(DetailAST aTypeAST) |
| 118 | { | |
| 119 | 69 | final DetailAST arrayDeclAST = |
| 120 | aTypeAST.findFirstToken(TokenTypes.ARRAY_DECLARATOR); | |
| 121 | ||
| 122 | 69 | return createFullTypeNoArrays(arrayDeclAST == null ? aTypeAST |
| 123 | : arrayDeclAST); | |
| 124 | } | |
| 125 | ||
| 126 | /** | |
| 127 | * @param aTypeAST a type node (no array) | |