Search in sources :

Example 1 with HbCloseBlockMustache

use of com.dmarcotte.handlebars.psi.HbCloseBlockMustache in project idea-handlebars by dmarcotte.

the class HbBlockMismatchAnnotator method annotate.

@Override
public void annotate(@NotNull PsiElement element, @NotNull AnnotationHolder holder) {
    if (element instanceof HbOpenBlockMustache) {
        HbOpenBlockMustache openBlockMustache = (HbOpenBlockMustache) element;
        HbMustacheName openBlockMustacheName = openBlockMustache.getBlockMustacheName();
        HbCloseBlockMustache closeBlockMustache = openBlockMustache.getPairedElement();
        if (closeBlockMustache != null) {
            HbMustacheName closeBlockMustacheName = closeBlockMustache.getBlockMustacheName();
            if (openBlockMustacheName == null || closeBlockMustacheName == null) {
                return;
            }
            String openBlockName = openBlockMustacheName.getName();
            String closeBlockName = closeBlockMustacheName.getName();
            if (!openBlockName.equals(closeBlockName)) {
                Annotation openBlockAnnotation = holder.createErrorAnnotation(openBlockMustacheName, HbBundle.message("hb.block.mismatch.inspection.open.block", openBlockName, closeBlockName));
                openBlockAnnotation.registerFix(new HbBlockMismatchFix(closeBlockName, openBlockName, true));
                openBlockAnnotation.registerFix(new HbBlockMismatchFix(openBlockName, closeBlockName, false));
                Annotation closeBlockAnnotation = holder.createErrorAnnotation(closeBlockMustacheName, HbBundle.message("hb.block.mismatch.inspection.close.block", openBlockName, closeBlockName));
                closeBlockAnnotation.registerFix(new HbBlockMismatchFix(openBlockName, closeBlockName, false));
                closeBlockAnnotation.registerFix(new HbBlockMismatchFix(closeBlockName, openBlockName, true));
            }
        } else {
            holder.createErrorAnnotation(openBlockMustacheName, HbBundle.message("hb.block.mismatch.inspection.missing.end.block", openBlockMustache.getName()));
        }
    }
    if (element instanceof HbCloseBlockMustache) {
        HbCloseBlockMustache closeBlockMustache = (HbCloseBlockMustache) element;
        PsiElement openBlockElement = closeBlockMustache.getPairedElement();
        if (openBlockElement == null) {
            HbMustacheName closeBlockMustacheName = closeBlockMustache.getBlockMustacheName();
            if (closeBlockMustacheName == null) {
                return;
            }
            holder.createErrorAnnotation(closeBlockMustacheName, HbBundle.message("hb.block.mismatch.inspection.missing.start.block", closeBlockMustache.getName()));
        }
    }
}
Also used : HbOpenBlockMustache(com.dmarcotte.handlebars.psi.HbOpenBlockMustache) HbMustacheName(com.dmarcotte.handlebars.psi.HbMustacheName) HbCloseBlockMustache(com.dmarcotte.handlebars.psi.HbCloseBlockMustache) Annotation(com.intellij.lang.annotation.Annotation) PsiElement(com.intellij.psi.PsiElement)

Example 2 with HbCloseBlockMustache

use of com.dmarcotte.handlebars.psi.HbCloseBlockMustache in project intellij-plugins by JetBrains.

the class HbBlockMismatchAnnotator method annotate.

@Override
public void annotate(@NotNull PsiElement element, @NotNull AnnotationHolder holder) {
    if (element instanceof HbOpenBlockMustache) {
        HbOpenBlockMustache openBlockMustache = (HbOpenBlockMustache) element;
        HbMustacheName openBlockMustacheName = openBlockMustache.getBlockMustacheName();
        HbCloseBlockMustache closeBlockMustache = openBlockMustache.getPairedElement();
        if (closeBlockMustache != null) {
            HbMustacheName closeBlockMustacheName = closeBlockMustache.getBlockMustacheName();
            if (openBlockMustacheName == null || closeBlockMustacheName == null) {
                return;
            }
            String openBlockName = openBlockMustacheName.getName();
            String closeBlockName = closeBlockMustacheName.getName();
            if (!openBlockName.equals(closeBlockName)) {
                Annotation openBlockAnnotation = holder.createErrorAnnotation(openBlockMustacheName, HbBundle.message("hb.block.mismatch.inspection.open.block", openBlockName, closeBlockName));
                openBlockAnnotation.registerFix(new HbBlockMismatchFix(closeBlockName, openBlockName, true));
                openBlockAnnotation.registerFix(new HbBlockMismatchFix(openBlockName, closeBlockName, false));
                Annotation closeBlockAnnotation = holder.createErrorAnnotation(closeBlockMustacheName, HbBundle.message("hb.block.mismatch.inspection.close.block", openBlockName, closeBlockName));
                closeBlockAnnotation.registerFix(new HbBlockMismatchFix(openBlockName, closeBlockName, false));
                closeBlockAnnotation.registerFix(new HbBlockMismatchFix(closeBlockName, openBlockName, true));
            }
        } else {
            if (openBlockMustacheName == null) {
                return;
            }
            holder.createErrorAnnotation(openBlockMustacheName, HbBundle.message("hb.block.mismatch.inspection.missing.end.block", openBlockMustache.getName()));
        }
    }
    if (element instanceof HbCloseBlockMustache) {
        HbCloseBlockMustache closeBlockMustache = (HbCloseBlockMustache) element;
        PsiElement openBlockElement = closeBlockMustache.getPairedElement();
        if (openBlockElement == null) {
            HbMustacheName closeBlockMustacheName = closeBlockMustache.getBlockMustacheName();
            if (closeBlockMustacheName == null) {
                return;
            }
            holder.createErrorAnnotation(closeBlockMustacheName, HbBundle.message("hb.block.mismatch.inspection.missing.start.block", closeBlockMustache.getName()));
        }
    }
}
Also used : HbOpenBlockMustache(com.dmarcotte.handlebars.psi.HbOpenBlockMustache) HbMustacheName(com.dmarcotte.handlebars.psi.HbMustacheName) HbCloseBlockMustache(com.dmarcotte.handlebars.psi.HbCloseBlockMustache) Annotation(com.intellij.lang.annotation.Annotation) PsiElement(com.intellij.psi.PsiElement)

Aggregations

HbCloseBlockMustache (com.dmarcotte.handlebars.psi.HbCloseBlockMustache)2 HbMustacheName (com.dmarcotte.handlebars.psi.HbMustacheName)2 HbOpenBlockMustache (com.dmarcotte.handlebars.psi.HbOpenBlockMustache)2 Annotation (com.intellij.lang.annotation.Annotation)2 PsiElement (com.intellij.psi.PsiElement)2