package de.espend.idea.php.annotation.annotator;

import com.intellij.lang.annotation.AnnotationHolder;
import com.intellij.lang.annotation.Annotator;
import com.intellij.psi.PsiElement;
import com.jetbrains.php.lang.documentation.phpdoc.psi.tags.PhpDocTag;
import com.jetbrains.php.lang.psi.elements.PhpClass;
import de.espend.idea.php.annotation.extension.PhpAnnotationDocTagAnnotator;
import de.espend.idea.php.annotation.extension.parameter.PhpAnnotationDocTagAnnotatorParameter;
import de.espend.idea.php.annotation.util.AnnotationUtil;
import org.jetbrains.annotations.NotNull;

public class AnnotationDocTagAnnotator implements Annotator {

    @Override
    public void annotate(@NotNull PsiElement psiElement, @NotNull AnnotationHolder holder) {

        if(!(psiElement instanceof PhpDocTag)) {
            return;
        }

        String name = ((PhpDocTag) psiElement).getName();
        if(AnnotationUtil.NON_ANNOTATION_TAGS.contains(name)) {
            return;
        }

        PhpClass phpClass = AnnotationUtil.getAnnotationReference(((PhpDocTag) psiElement));
        if(phpClass == null) {

            PhpAnnotationDocTagAnnotatorParameter parameter = new PhpAnnotationDocTagAnnotatorParameter((PhpDocTag) psiElement, holder);
            for(PhpAnnotationDocTagAnnotator annotator: AnnotationUtil.EP_DOC_TAG_ANNOTATOR.getExtensions()) {
                annotator.annotate(parameter);
            }

            return;
        }

        PhpAnnotationDocTagAnnotatorParameter parameter = new PhpAnnotationDocTagAnnotatorParameter(phpClass, (PhpDocTag) psiElement, holder);
        for(PhpAnnotationDocTagAnnotator annotator: AnnotationUtil.EP_DOC_TAG_ANNOTATOR.getExtensions()) {
            annotator.annotate(parameter);
        }


    }



}


@@ -195,66 +195,283 @@
 com.
-jetbrains.php.lang.documentation.phpdoc.psi.tags.PhpDocTag
+intellij.psi.util.PsiTreeUtil;%0Aimport com.jetbrains.php.lang.documentation.phpdoc.psi.PhpDocComment;%0Aimport com.jetbrains.php.lang.documentation.phpdoc.psi.tags.PhpDocTag;%0Aimport com.jetbrains.php.lang.parser.PhpElementTypes;%0Aimport com.jetbrains.php.lang.psi.elements.Method
 ;%0Aim
@@ -1104,16 +1104,16 @@
 Name();%0A
-
         
@@ -1191,32 +1191,492 @@
 urn;%0A        %7D%0A%0A
+        PhpDocComment phpDocComment = PsiTreeUtil.getParentOfType(psiElement, PhpDocComment.class);%0A        if(phpDocComment == null) %7B%0A            return;%0A        %7D%0A%0A        PsiElement nextPsiElement = phpDocComment.getNextPsiSibling();%0A        if(nextPsiElement == null %7C%7C !(nextPsiElement instanceof Method %7C%7C nextPsiElement instanceof PhpClass %7C%7C nextPsiElement.getNode().getElementType() == PhpElementTypes.CLASS_FIELDS)) %7B%0A            return;%0A        %7D%0A%0A
         PhpClass

add whitelist for annotation PhpDoc on next siblings #24