Package fr.adrienbrault.idea.symfony2plugin.routing.inspection

Source Code of fr.adrienbrault.idea.symfony2plugin.routing.inspection.DuplicateLocalRouteInspection

package fr.adrienbrault.idea.symfony2plugin.routing.inspection;

import com.intellij.codeInspection.LocalInspectionTool;
import com.intellij.codeInspection.ProblemsHolder;
import com.intellij.psi.PsiElementVisitor;
import com.intellij.psi.PsiFile;
import com.intellij.psi.util.PsiTreeUtil;
import fr.adrienbrault.idea.symfony2plugin.Symfony2ProjectComponent;
import fr.adrienbrault.idea.symfony2plugin.util.yaml.YamlHelper;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.yaml.psi.YAMLDocument;

public class DuplicateLocalRouteInspection extends LocalInspectionTool {

    @NotNull
    @Override
    public PsiElementVisitor buildVisitor(final @NotNull ProblemsHolder holder, boolean isOnTheFly) {

        PsiFile psiFile = holder.getFile();
        if(!Symfony2ProjectComponent.isEnabled(psiFile.getProject())) {
            return super.buildVisitor(holder, isOnTheFly);
        }

        // @TODO: detection of routing files in right way
        // routing.yml
        // comment.routing.yml
        // routing/foo.yml
        if(YamlHelper.isRoutingFile(psiFile)) {
            YAMLDocument document = PsiTreeUtil.findChildOfType(psiFile, YAMLDocument.class);
            if(document != null) {
                YamlHelper.attachDuplicateKeyInspection(document, holder);
            }
        }

        return super.buildVisitor(holder, isOnTheFly);
    }

}
TOP

Related Classes of fr.adrienbrault.idea.symfony2plugin.routing.inspection.DuplicateLocalRouteInspection

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.