JavaParser Source Viewer

Home|JavaParser/com/github/javaparser/javadoc/description/JavadocInlineTag.java
1/*
2 * Copyright (C) 2007-2010 JĂșlio Vilmar Gesser.
3 * Copyright (C) 2011, 2013-2020 The JavaParser Team.
4 *
5 * This file is part of JavaParser.
6 *
7 * JavaParser can be used either under the terms of
8 * a) the GNU Lesser General Public License as published by
9 *     the Free Software Foundation, either version 3 of the License, or
10 *     (at your option) any later version.
11 * b) the terms of the Apache License
12 *
13 * You should have received a copy of both licenses in LICENCE.LGPL and
14 * LICENCE.APACHE. Please refer to those files for details.
15 *
16 * JavaParser is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19 * GNU Lesser General Public License for more details.
20 */
21
22package com.github.javaparser.javadoc.description;
23
24import static com.github.javaparser.utils.Utils.nextWord;
25import static com.github.javaparser.utils.Utils.screamingToCamelCase;
26
27/**
28 * An inline tag contained in a Javadoc description.
29 * <p>
30 * For example <code>{@link String}</code>
31 */
32public class JavadocInlineTag implements JavadocDescriptionElement {
33
34    public static JavadocDescriptionElement fromText(String text) {
35        if (!text.startsWith("{@")) {
36            throw new IllegalArgumentException(String.format("Expected to start with '{@'. Text '%s'"text));
37        }
38        if (!text.endsWith("}")) {
39            throw new IllegalArgumentException(String.format("Expected to end with '}'. Text '%s'"text));
40        }
41        text = text.substring(2text.length() - 1);
42        String tagName = nextWord(text);
43        Type type = Type.fromName(tagName);
44        String content = text.substring(tagName.length());
45        return new JavadocInlineTag(tagNametypecontent);
46    }
47
48    /**
49     * The type of tag: it could either correspond to a known tag (code, docRoot, etc.) or represent
50     * an unknown tag.
51     */
52    public enum Type {
53        CODE,
54        DOC_ROOT,
55        INHERIT_DOC,
56        LINK,
57        LINKPLAIN,
58        LITERAL,
59        VALUE,
60        SYSTEM_PROPERTY,
61        UNKNOWN;
62
63        Type() {
64            this.keyword = screamingToCamelCase(name());
65        }
66
67        private String keyword;
68
69        static JavadocInlineTag.Type fromName(String tagName) {
70            for (JavadocInlineTag.Type t : JavadocInlineTag.Type.values()) {
71                if (t.keyword.equals(tagName)) {
72                    return t;
73                }
74            }
75            return UNKNOWN;
76        }
77
78    }
79
80    private String tagName;
81    private Type type;
82    private String content;
83
84    public JavadocInlineTag(String tagNameType typeString content) {
85        this.tagName = tagName;
86        this.type = type;
87        this.content = content;
88    }
89
90    public Type getType() {
91        return type;
92    }
93
94    public String getContent() {
95        return content;
96    }
97
98    public String getName() {
99        return tagName;
100    }
101
102    @Override
103    public String toText() {
104        return "{@" + tagName + this.content +"}";
105    }
106
107    @Override
108    public boolean equals(Object o) {
109        if (this == o) return true;
110        if (o == null || getClass() != o.getClass()) return false;
111
112        JavadocInlineTag that = (JavadocInlineTago;
113
114        if (tagName != null ? !tagName.equals(that.tagName) : that.tagName != null) return false;
115        if (type != that.type) return false;
116        return content != null ? content.equals(that.content) : that.content == null;
117    }
118
119    @Override
120    public int hashCode() {
121        int result = tagName != null ? tagName.hashCode() : 0;
122        result = 31 * result + (type != null ? type.hashCode() : 0);
123        result = 31 * result + (content != null ? content.hashCode() : 0);
124        return result;
125    }
126
127    @Override
128    public String toString() {
129        return "JavadocInlineTag{" +
130                "tagName='" + tagName + '\'' +
131                ", type=" + type +
132                ", content='" + content + '\'' +
133                '}';
134    }
135}
136
MembersX
JavadocInlineTag:fromText:Block:tagName
JavadocInlineTag:hashCode
JavadocInlineTag:equals
JavadocInlineTag:Type:VALUE
JavadocInlineTag:equals:Block:that
JavadocInlineTag:type
JavadocInlineTag:Type:keyword
JavadocInlineTag:getContent
JavadocInlineTag:Type:fromName
JavadocInlineTag:toString
JavadocInlineTag:Type:Type
JavadocInlineTag:Type:SYSTEM_PROPERTY
JavadocInlineTag:JavadocInlineTag
JavadocInlineTag:hashCode:Block:result
JavadocInlineTag:Type:UNKNOWN
JavadocInlineTag:fromText
JavadocInlineTag:fromText:Block:type
JavadocInlineTag:getName
JavadocInlineTag:toText
JavadocInlineTag:Type:LITERAL
JavadocInlineTag:Type:CODE
JavadocInlineTag:Type:LINKPLAIN
JavadocInlineTag:Type:INHERIT_DOC
JavadocInlineTag:fromText:Block:content
JavadocInlineTag:Type:LINK
JavadocInlineTag:tagName
JavadocInlineTag:getType
JavadocInlineTag:Type:DOC_ROOT
JavadocInlineTag:content
Members
X