Search in sources :

Example 11 with PhpFile

use of com.jetbrains.php.lang.psi.PhpFile in project yii2support by nvlad.

the class ValidationCompletionProvider method getClassIfInRulesMethod.

@Nullable
private PhpClass getClassIfInRulesMethod(PsiElement position) {
    PsiElement elem = position.getParent();
    Method currentMethod = null;
    PhpClass phpClass = null;
    while (true) {
        if (elem instanceof Method)
            currentMethod = (Method) elem;
        else if (elem instanceof PhpClass) {
            phpClass = (PhpClass) elem;
            break;
        } else if (elem instanceof PhpFile)
            break;
        else if (elem == null) {
            break;
        }
        elem = elem.getParent();
    }
    if (currentMethod != null && phpClass != null) {
        if (ClassUtils.isClassInherit(phpClass, "\\yii\\base\\Model", PhpIndex.getInstance(position.getProject())) && currentMethod.getName().equals("rules")) {
            return phpClass;
        } else
            return null;
    } else {
        return null;
    }
}
Also used : PhpFile(com.jetbrains.php.lang.psi.PhpFile) PsiElement(com.intellij.psi.PsiElement) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

PhpFile (com.jetbrains.php.lang.psi.PhpFile)11 PsiElement (com.intellij.psi.PsiElement)9 NotNull (org.jetbrains.annotations.NotNull)9 BasePhpElementVisitor (com.kalessil.phpStorm.phpInspectionsEA.openApi.BasePhpElementVisitor)8 ProblemsHolder (com.intellij.codeInspection.ProblemsHolder)5 PsiElementVisitor (com.intellij.psi.PsiElementVisitor)5 BasePhpInspection (com.kalessil.phpStorm.phpInspectionsEA.openApi.BasePhpInspection)5 MessagesPresentationUtil (com.kalessil.phpStorm.phpInspectionsEA.utils.MessagesPresentationUtil)5 Project (com.intellij.openapi.project.Project)4 com.jetbrains.php.lang.psi.elements (com.jetbrains.php.lang.psi.elements)4 PsiTreeUtil (com.intellij.psi.util.PsiTreeUtil)3 HashSet (java.util.HashSet)3 LocalQuickFix (com.intellij.codeInspection.LocalQuickFix)2 ProblemDescriptor (com.intellij.codeInspection.ProblemDescriptor)2 PsiFile (com.intellij.psi.PsiFile)2 PhpIndex (com.jetbrains.php.PhpIndex)2 PhpDocComment (com.jetbrains.php.lang.documentation.phpdoc.psi.PhpDocComment)2 PhpTokenTypes (com.jetbrains.php.lang.lexer.PhpTokenTypes)2 PhpPsiElementFactory (com.jetbrains.php.lang.psi.PhpPsiElementFactory)2 OptionsComponent (com.kalessil.phpStorm.phpInspectionsEA.options.OptionsComponent)2