001//////////////////////////////////////////////////////////////////////////////// 002// checkstyle: Checks Java source code for adherence to a set of rules. 003// Copyright (C) 2001-2020 the original author or authors. 004// 005// This library is free software; you can redistribute it and/or 006// modify it under the terms of the GNU Lesser General Public 007// License as published by the Free Software Foundation; either 008// version 2.1 of the License, or (at your option) any later version. 009// 010// This library is distributed in the hope that it will be useful, 011// but WITHOUT ANY WARRANTY; without even the implied warranty of 012// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 013// Lesser General Public License for more details. 014// 015// You should have received a copy of the GNU Lesser General Public 016// License along with this library; if not, write to the Free Software 017// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 018//////////////////////////////////////////////////////////////////////////////// 019 020package com.puppycrawl.tools.checkstyle.checks.javadoc; 021 022import java.util.Arrays; 023import java.util.Objects; 024 025import com.puppycrawl.tools.checkstyle.api.DetailNode; 026import com.puppycrawl.tools.checkstyle.utils.JavadocUtil; 027 028/** 029 * Implementation of DetailNode interface that is mutable. 030 * 031 * 032 */ 033public class JavadocNodeImpl implements DetailNode { 034 035 /** 036 * Empty array of {@link DetailNode} type. 037 */ 038 public static final JavadocNodeImpl[] EMPTY_DETAIL_NODE_ARRAY = new JavadocNodeImpl[0]; 039 040 /** 041 * Node index among parent's children. 042 */ 043 private int index; 044 045 /** 046 * Node type. 047 */ 048 private int type; 049 050 /** 051 * Node's text content. 052 */ 053 private String text; 054 055 /** 056 * Line number. 057 */ 058 private int lineNumber; 059 060 /** 061 * Column number. 062 */ 063 private int columnNumber; 064 065 /** 066 * Array of child nodes. 067 */ 068 private DetailNode[] children; 069 070 /** 071 * Parent node. 072 */ 073 private DetailNode parent; 074 075 @Override 076 public int getType() { 077 return type; 078 } 079 080 @Override 081 public String getText() { 082 return text; 083 } 084 085 @Override 086 public int getLineNumber() { 087 return lineNumber; 088 } 089 090 @Override 091 public int getColumnNumber() { 092 return columnNumber; 093 } 094 095 @Override 096 public DetailNode[] getChildren() { 097 DetailNode[] nodeChildren = EMPTY_DETAIL_NODE_ARRAY; 098 if (children != null) { 099 nodeChildren = Arrays.copyOf(children, children.length); 100 } 101 return nodeChildren; 102 } 103 104 @Override 105 public DetailNode getParent() { 106 return parent; 107 } 108 109 @Override 110 public int getIndex() { 111 return index; 112 } 113 114 /** 115 * Sets node's type. 116 * 117 * @param type Node's type. 118 */ 119 public void setType(int type) { 120 this.type = type; 121 } 122 123 /** 124 * Sets node's text content. 125 * 126 * @param text Node's text content. 127 */ 128 public void setText(String text) { 129 this.text = text; 130 } 131 132 /** 133 * Sets line number. 134 * 135 * @param lineNumber Line number. 136 */ 137 public void setLineNumber(int lineNumber) { 138 this.lineNumber = lineNumber; 139 } 140 141 /** 142 * Sets column number. 143 * 144 * @param columnNumber Column number. 145 */ 146 public void setColumnNumber(int columnNumber) { 147 this.columnNumber = columnNumber; 148 } 149 150 /** 151 * Sets array of child nodes. 152 * 153 * @param children Array of child nodes. 154 */ 155 public void setChildren(DetailNode... children) { 156 this.children = Arrays.copyOf(children, children.length); 157 } 158 159 /** 160 * Sets parent node. 161 * 162 * @param parent Parent node. 163 */ 164 public void setParent(DetailNode parent) { 165 this.parent = parent; 166 } 167 168 /** 169 * Sets node's index among parent's children. 170 * 171 * @param index Node's index among parent's children. 172 */ 173 public void setIndex(int index) { 174 this.index = index; 175 } 176 177 @Override 178 public String toString() { 179 return "JavadocNodeImpl[" 180 + "index=" + index 181 + ", type=" + JavadocUtil.getTokenName(type) 182 + ", text='" + text + '\'' 183 + ", lineNumber=" + lineNumber 184 + ", columnNumber=" + columnNumber 185 + ", children=" + Objects.hashCode(children) 186 + ", parent=" + parent + ']'; 187 } 188 189}