1/* 2 * Copyright (C) 2010 Google Inc. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17package com.google.doclava; 18 19import com.google.clearsilver.jsilver.data.Data; 20 21import java.util.Arrays; 22 23public class TagInfo { 24 public static final TagInfo[] EMPTY_ARRAY = new TagInfo[0]; 25 26 public static TagInfo[] getArray(int size) { 27 return size == 0 ? EMPTY_ARRAY : new TagInfo[size]; 28 } 29 30 public static TagInfo[] append(TagInfo[] list, TagInfo item) { 31 if (item == null) { 32 return list; 33 } if (list == null) { 34 return new TagInfo[] { item }; 35 } else { 36 list = Arrays.copyOf(list, list.length + 1); 37 list[list.length - 1] = item; 38 return list; 39 } 40 } 41 42 private String mName; 43 private String mText; 44 private String mKind; 45 private SourcePositionInfo mPosition; 46 47 TagInfo(String n, String k, String t, SourcePositionInfo sp) { 48 mName = n; 49 mText = t; 50 mKind = k; 51 mPosition = sp; 52 } 53 54 String name() { 55 return mName; 56 } 57 58 String text() { 59 return mText; 60 } 61 62 String kind() { 63 return mKind; 64 } 65 66 SourcePositionInfo position() { 67 return mPosition; 68 } 69 70 void setKind(String kind) { 71 mKind = kind; 72 } 73 74 public void makeHDF(Data data, String base) { 75 data.setValue(base + ".name", name()); 76 77 if (name().equals("@value")) { 78 mText = mText.replace('#', '.'); 79 } 80 data.setValue(base + ".text", text()); 81 data.setValue(base + ".kind", kind()); 82 } 83 84 public static void makeHDF(Data data, String base, TagInfo[] tags) { 85 makeHDF(data, base, tags, null, 0, 0); 86 } 87 88 public static void makeHDF(Data data, String base, InheritedTags tags) { 89 makeHDF(data, base, tags.tags(), tags.inherited(), 0, 0); 90 } 91 92 private static int makeHDF(Data data, String base, TagInfo[] tags, InheritedTags inherited, 93 int j, int depth) { 94 int i; 95 int len = tags.length; 96 if (len == 0 && inherited != null) { 97 j = makeHDF(data, base, inherited.tags(), inherited.inherited(), j, depth + 1); 98 } else { 99 for (i = 0; i < len; i++, j++) { 100 TagInfo t = tags[i]; 101 if (inherited != null && t.name().equals("@inheritDoc")) { 102 j = makeHDF(data, base, inherited.tags(), inherited.inherited(), j, depth + 1); 103 } else { 104 if (t.name().equals("@inheritDoc")) { 105 Errors.error(Errors.BAD_INHERITDOC, t.mPosition, 106 "@inheritDoc on class/method that is not inherited"); 107 } 108 t.makeHDF(data, base + "." + j); 109 } 110 } 111 } 112 return j; 113 } 114} 115