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;
}
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");
}
}
};
}
Aggregations