| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| JavadocTag |
|
| 1.4285714285714286;1.429 |
| 1 | //////////////////////////////////////////////////////////////////////////////// | |
| 2 | // checkstyle: Checks Java source code for adherence to a set of rules. | |
| 3 | // Copyright (C) 2001-2014 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.javadoc; | |
| 20 | ||
| 21 | import com.puppycrawl.tools.checkstyle.api.JavadocTagInfo; | |
| 22 | ||
| 23 | /** | |
| 24 | * Represents a Javadoc tag. Provides methods to query what type of tag it is. | |
| 25 | * @author Oliver Burn | |
| 26 | */ | |
| 27 | public class JavadocTag | |
| 28 | { | |
| 29 | /** the line number of the tag **/ | |
| 30 | private final int mLineNo; | |
| 31 | /** the column number of the tag **/ | |
| 32 | private int mColumnNo; | |
| 33 | /** an optional first argument. For example the parameter name. **/ | |
| 34 | private final String mArg1; | |
| 35 | /** the JavadocTagInfo representing this tag **/ | |
| 36 | private final JavadocTagInfo mTagInfo; | |
| 37 | ||
| 38 | /** | |
| 39 | * Constructs the object. | |
| 40 | * @param aLine the line number of the tag | |
| 41 | * @param aColumn the column number of the tag | |
| 42 | * @param aTag the tag string | |
| 43 | * @param aArg1 the tag argument | |
| 44 | **/ | |
| 45 | public JavadocTag(int aLine, int aColumn, String aTag, String aArg1) | |
| 46 | 309 | { |
| 47 | 309 | mLineNo = aLine; |
| 48 | 309 | mColumnNo = aColumn; |
| 49 | 309 | mArg1 = aArg1; |
| 50 | 309 | mTagInfo = JavadocTagInfo.fromName(aTag); |
| 51 | 309 | } |
| 52 | ||
| 53 | /** | |
| 54 | * Constructs the object. | |
| 55 | * @param aLine the line number of the tag | |
| 56 | * @param aColumn the column number of the tag | |
| 57 | * @param aTag the tag string | |
| 58 | **/ | |
| 59 | public JavadocTag(int aLine, int aColumn, String aTag) | |
| 60 | { | |
| 61 | 66 | this(aLine, aColumn, aTag, null); |
| 62 | 66 | } |
| 63 | ||
| 64 | /** @return the tag string **/ | |
| 65 | public String getTagName() | |
| 66 | { | |
| 67 | 83 | return mTagInfo.getName(); |
| 68 | } | |
| 69 | ||
| 70 | /** @return the first argument. null if not set. **/ | |
| 71 | public String getArg1() | |
| 72 | { | |
| 73 | 367 | return mArg1; |
| 74 | } | |
| 75 | ||
| 76 | /** @return the line number **/ | |
| 77 | public int getLineNo() | |
| 78 | { | |
| 79 | 121 | return mLineNo; |
| 80 | } | |
| 81 | ||
| 82 | /** @return the column number */ | |
| 83 | public int getColumnNo() | |
| 84 | { | |
| 85 | 115 | return mColumnNo; |
| 86 | } | |
| 87 | ||
| 88 | @Override | |
| 89 | public String toString() | |
| 90 | { | |
| 91 | 0 | return "{Tag = '" + getTagName() + "', lineNo = " + getLineNo() |
| 92 | + ", columnNo=" + mColumnNo + ", Arg1 = '" + getArg1() + "'}"; | |
| 93 | } | |
| 94 | ||
| 95 | /** @return whether the tag is an 'author' tag **/ | |
| 96 | public boolean isAuthorTag() | |
| 97 | { | |
| 98 | 0 | return JavadocTagInfo.AUTHOR.equals(mTagInfo); |
| 99 | } | |
| 100 | ||
| 101 | /** @return whether the tag is an 'return' tag **/ | |
| 102 | public boolean isReturnTag() | |
| 103 | { | |
| 104 | 31 | return JavadocTagInfo.RETURN.equals(mTagInfo); |
| 105 | } | |
| 106 | ||
| 107 | /** @return whether the tag is an 'param' tag **/ | |
| 108 | public boolean isParamTag() | |
| 109 | { | |
| 110 | 281 | return JavadocTagInfo.PARAM.equals(mTagInfo); |
| 111 | } | |
| 112 | ||
| 113 | /** @return whether the tag is an 'throws' or 'exception' tag **/ | |
| 114 | public boolean isThrowsTag() | |
| 115 | { | |
| 116 | 128 | return (JavadocTagInfo.THROWS.equals(mTagInfo) |
| 117 | || JavadocTagInfo.EXCEPTION.equals(mTagInfo)); | |
| 118 | } | |
| 119 | ||
| 120 | /** @return whether the tag is a 'see' or 'inheritDoc' tag **/ | |
| 121 | public boolean isSeeOrInheritDocTag() | |
| 122 | { | |
| 123 | 27 | return (JavadocTagInfo.SEE.equals(mTagInfo) || isInheritDocTag()); |
| 124 | } | |
| 125 | ||
| 126 | /** @return whether the tag is a 'inheritDoc' tag **/ | |
| 127 | public boolean isInheritDocTag() | |
| 128 | { | |
| 129 | 257 | return JavadocTagInfo.INHERIT_DOC.equals(mTagInfo); |
| 130 | } | |
| 131 | ||
| 132 | /** @return whether the tag can contain references to imported classes **/ | |
| 133 | public boolean canReferenceImports() | |
| 134 | { | |
| 135 | 10 | return (JavadocTagInfo.SEE.equals(mTagInfo) |
| 136 | || JavadocTagInfo.LINK.equals(mTagInfo) | |
| 137 | || JavadocTagInfo.LINKPLAIN.equals(mTagInfo) | |
| 138 | || JavadocTagInfo.THROWS.equals(mTagInfo) | |
| 139 | || JavadocTagInfo.EXCEPTION.equals(mTagInfo)); | |
| 140 | } | |
| 141 | } | |
| 142 |