Search in sources :

Example 1 with ClassConstantReference

use of com.jetbrains.php.lang.psi.elements.ClassConstantReference in project phpinspectionsea by kalessil.

the class InstanceOfTraitStrategy method apply.

public static boolean apply(@NotNull BinaryExpression expression, @NotNull ProblemsHolder holder) {
    /* general structure expectations */
    if (expression.getOperationType() != PhpTokenTypes.kwINSTANCEOF) {
        return false;
    }
    final PsiElement right = expression.getRightOperand();
    if (!(right instanceof ClassReference) && !(right instanceof ClassConstantReference)) {
        return false;
    }
    /* $this, self, static are referencing to host classes, skip the case */
    if (lateBindingSymbols.contains(right.getText())) {
        return false;
    }
    /* getting class from invariant constructs  */
    PsiElement resolved = null;
    if (right instanceof ClassReference) {
        resolved = OpenapiResolveUtil.resolveReference((ClassReference) right);
    }
    if (right instanceof ClassConstantReference) {
        final ClassConstantReference ref = (ClassConstantReference) right;
        final PsiElement classReference = ref.getClassReference();
        final String constantName = ref.getName();
        if (null != constantName && constantName.equals("class") && classReference instanceof ClassReference) {
            resolved = OpenapiResolveUtil.resolveReference((ClassReference) classReference);
        }
    }
    /* analysis itself */
    if (resolved instanceof PhpClass && ((PhpClass) resolved).isTrait()) {
        holder.registerProblem(expression, MessagesPresentationUtil.prefixWithEa(message));
        return true;
    }
    return false;
}
Also used : PhpClass(com.jetbrains.php.lang.psi.elements.PhpClass) ClassReference(com.jetbrains.php.lang.psi.elements.ClassReference) PsiElement(com.intellij.psi.PsiElement) ClassConstantReference(com.jetbrains.php.lang.psi.elements.ClassConstantReference)

Example 2 with ClassConstantReference

use of com.jetbrains.php.lang.psi.elements.ClassConstantReference in project idea-php-typo3-plugin by cedricziel.

the class ClassConstantMatcherInspection method buildVisitor.

@NotNull
@Override
public PsiElementVisitor buildVisitor(@NotNull ProblemsHolder problemsHolder, boolean b) {
    return new PhpElementVisitor() {

        @Override
        public void visitPhpElement(PhpPsiElement element) {
            if (!PlatformPatterns.psiElement(PhpElementTypes.CLASS_CONSTANT_REFERENCE).accepts(element)) {
                return;
            }
            Set<String> constants = getDeprecatedClassConstants(element);
            ClassConstantReference classConstantReference = (ClassConstantReference) element;
            if (constants.contains(classConstantReference.getText())) {
                problemsHolder.registerProblem(element, "Deprecated class constant");
            }
        }
    };
}
Also used : PhpElementVisitor(com.jetbrains.php.lang.psi.visitors.PhpElementVisitor) PhpPsiElement(com.jetbrains.php.lang.psi.elements.PhpPsiElement) ClassConstantReference(com.jetbrains.php.lang.psi.elements.ClassConstantReference) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

ClassConstantReference (com.jetbrains.php.lang.psi.elements.ClassConstantReference)2 PsiElement (com.intellij.psi.PsiElement)1 ClassReference (com.jetbrains.php.lang.psi.elements.ClassReference)1 PhpClass (com.jetbrains.php.lang.psi.elements.PhpClass)1 PhpPsiElement (com.jetbrains.php.lang.psi.elements.PhpPsiElement)1 PhpElementVisitor (com.jetbrains.php.lang.psi.visitors.PhpElementVisitor)1 NotNull (org.jetbrains.annotations.NotNull)1