GrovyDoc API
[fedora-idea.git] / plugins / groovy / src / org / jetbrains / plugins / groovy / lang / groovydoc / psi / impl / GrDocCommentImpl.java
blob8199967bdd505ce77188fdac492aaeec2c11d82a
1 /*
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.
17 package org.jetbrains.plugins.groovy.lang.groovydoc.psi.impl;
19 import com.intellij.lang.ASTNode;
20 import com.intellij.psi.PsiElement;
21 import com.intellij.psi.impl.source.tree.LazyParseablePsiElement;
22 import com.intellij.psi.tree.IElementType;
23 import com.intellij.psi.util.PsiTreeUtil;
24 import org.jetbrains.annotations.NonNls;
25 import org.jetbrains.annotations.NotNull;
26 import org.jetbrains.annotations.Nullable;
27 import org.jetbrains.plugins.groovy.lang.groovydoc.parser.GroovyDocElementTypes;
28 import org.jetbrains.plugins.groovy.lang.groovydoc.psi.api.GrDocComment;
29 import org.jetbrains.plugins.groovy.lang.groovydoc.psi.api.GrDocCommentOwner;
30 import org.jetbrains.plugins.groovy.lang.groovydoc.psi.api.GrDocTag;
31 import org.jetbrains.plugins.groovy.lang.psi.GroovyElementVisitor;
32 import org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement;
34 import java.util.ArrayList;
36 /**
37 * @author ilyas
39 public class GrDocCommentImpl extends LazyParseablePsiElement implements GroovyDocElementTypes, GrDocComment {
40 public GrDocCommentImpl(CharSequence text) {
41 super(GROOVY_DOC_COMMENT, text);
44 public String toString() {
45 return "GrDocComment";
48 public IElementType getTokenType() {
49 return getElementType();
52 public void accept(GroovyElementVisitor visitor) {
53 visitor.visitElement(this);
56 public void acceptChildren(GroovyElementVisitor visitor) {
57 PsiElement child = getFirstChild();
58 while (child != null) {
59 if (child instanceof GroovyPsiElement) {
60 ((GroovyPsiElement)child).accept(visitor);
63 child = child.getNextSibling();
67 public GrDocCommentOwner getOwner() {
68 return GrDocCommentUtil.findDocOwner(this);
71 @NotNull
72 public GrDocTag[] getTags() {
73 final GrDocTag[] tags = PsiTreeUtil.getChildrenOfType(this, GrDocTag.class);
74 return tags == null ? GrDocTag.EMPTY_ARRAY : tags;
77 @Nullable
78 public GrDocTag findTagByName(@NonNls String name) {
79 if (!getText().contains(name)) return null;
80 for (PsiElement e = getFirstChild(); e != null; e = e.getNextSibling()) {
81 if (e instanceof GrDocTag && ((GrDocTag)e).getName().equals(name)) {
82 return (GrDocTag)e;
85 return null;
88 @NotNull
89 public GrDocTag[] findTagsByName(@NonNls String name) {
90 if (!getText().contains(name)) return GrDocTag.EMPTY_ARRAY;
91 ArrayList<GrDocTag> list = new ArrayList<GrDocTag>();
92 for (PsiElement e = getFirstChild(); e != null; e = e.getNextSibling()) {
93 if (e instanceof GrDocTag && ((GrDocTag)e).getName().equals(name)) {
94 list.add((GrDocTag)e);
97 return list.toArray(new GrDocTag[list.size()]);
100 public PsiElement[] getDescriptionElements() {
101 ArrayList<PsiElement> array = new ArrayList<PsiElement>();
102 for (PsiElement child = getFirstChild(); child != null; child = child.getNextSibling()) {
103 final ASTNode node = child.getNode();
104 if (node == null) continue;
105 final IElementType i = node.getElementType();
106 if (i == GDOC_TAG) break;
107 if (i != mGDOC_COMMENT_START && i != mGDOC_COMMENT_END && i != mGDOC_ASTERISKS) {
108 array.add(child);
111 return array.toArray(new PsiElement[array.size()]);