2 * Copyright 2000-2009 JetBrains s.r.o.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 package com
.intellij
.psi
.impl
.source
.tree
.java
;
18 import com
.intellij
.lang
.ASTNode
;
19 import com
.intellij
.openapi
.diagnostic
.Logger
;
20 import com
.intellij
.psi
.JavaElementVisitor
;
21 import com
.intellij
.psi
.PsiElement
;
22 import com
.intellij
.psi
.PsiElementVisitor
;
23 import com
.intellij
.psi
.impl
.PsiImplUtil
;
24 import com
.intellij
.psi
.impl
.source
.SourceTreeToPsiMap
;
25 import com
.intellij
.psi
.impl
.source
.Constants
;
26 import com
.intellij
.psi
.impl
.source
.PsiElementArrayConstructor
;
27 import com
.intellij
.psi
.impl
.source
.tree
.ChildRole
;
28 import com
.intellij
.psi
.impl
.source
.tree
.CompositePsiElement
;
29 import com
.intellij
.psi
.impl
.source
.tree
.JavaDocElementType
;
30 import com
.intellij
.psi
.javadoc
.PsiDocComment
;
31 import com
.intellij
.psi
.javadoc
.PsiDocTagValue
;
32 import com
.intellij
.psi
.javadoc
.PsiInlineDocTag
;
33 import com
.intellij
.psi
.tree
.IElementType
;
34 import com
.intellij
.psi
.tree
.TokenSet
;
35 import com
.intellij
.psi
.tree
.ChildRoleBase
;
36 import com
.intellij
.util
.IncorrectOperationException
;
37 import org
.jetbrains
.annotations
.NotNull
;
39 public class PsiInlineDocTagImpl
extends CompositePsiElement
implements PsiInlineDocTag
, Constants
{
40 private static final Logger LOG
= Logger
.getInstance("#com.intellij.psi.impl.source.tree.java.PsiInlineDocTagImpl");
42 private static final TokenSet VALUE_BIT_SET
= TokenSet
.create(new IElementType
[]{
45 DOC_METHOD_OR_FIELD_REF
,
51 public PsiInlineDocTagImpl() {
52 super(DOC_INLINE_TAG
);
55 public PsiDocComment
getContainingComment() {
56 ASTNode scope
= getTreeParent();
57 while (scope
.getElementType() != JavaDocElementType
.DOC_COMMENT
) {
58 scope
= scope
.getTreeParent();
60 return (PsiDocComment
)SourceTreeToPsiMap
.treeElementToPsi(scope
);
63 public PsiElement
getNameElement() {
64 return findChildByRoleAsPsiElement(ChildRole
.DOC_TAG_NAME
);
67 public PsiElement
[] getDataElements() {
68 return getChildrenAsPsiElements(VALUE_BIT_SET
, PsiElementArrayConstructor
.PSI_ELEMENT_ARRAY_CONSTRUCTOR
);
71 public PsiDocTagValue
getValueElement() {
72 return (PsiDocTagValue
)findChildByRoleAsPsiElement(ChildRole
.DOC_TAG_VALUE
);
75 public String
getName() {
76 final PsiElement nameElement
= getNameElement();
77 if (nameElement
== null) return "";
78 return nameElement
.getText().substring(1);
81 public int getChildRole(ASTNode child
) {
82 LOG
.assertTrue(child
.getTreeParent() == this);
83 IElementType i
= child
.getElementType();
84 if (i
== DOC_TAG_NAME
) {
85 return ChildRole
.DOC_TAG_NAME
;
87 else if (i
== JavaDocElementType
.DOC_COMMENT
|| i
== DOC_INLINE_TAG
) {
88 return ChildRole
.DOC_CONTENT
;
90 else if (i
== DOC_INLINE_TAG_START
) {
91 return ChildRole
.DOC_INLINE_TAG_START
;
93 else if (i
== DOC_INLINE_TAG_END
) {
94 return ChildRole
.DOC_INLINE_TAG_END
;
96 else if (i
== DOC_TAG_VALUE_TOKEN
) {
97 return ChildRole
.DOC_TAG_VALUE
;
99 else if (i
== DOC_METHOD_OR_FIELD_REF
) {
100 return ChildRole
.DOC_TAG_VALUE
;
103 return ChildRoleBase
.NONE
;
107 public void accept(@NotNull PsiElementVisitor visitor
) {
108 if (visitor
instanceof JavaElementVisitor
) {
109 ((JavaElementVisitor
)visitor
).visitInlineDocTag(this);
112 visitor
.visitElement(this);
116 public String
toString() {
117 PsiElement nameElement
= getNameElement();
118 return "PsiInlineDocTag:" + (nameElement
!= null ? nameElement
.getText() : null);
121 public PsiElement
setName(@NotNull String name
) throws IncorrectOperationException
{
122 PsiImplUtil
.setName(getNameElement(), name
);