Search in sources :

Example 16 with PhpElementVisitor

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

the class FunctionCallMatcherInspection 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.FUNCTION_CALL).accepts(element)) {
                return;
            }
            Set<String> constants = getRemovedGlobalFuntions(element);
            FunctionReference constantReference = (FunctionReference) element;
            if (constants.contains(constantReference.getFQN())) {
                problemsHolder.registerProblem(element, "Global function removed with TYPO3 9, consider using an alternative");
            }
        }
    };
}
Also used : PhpElementVisitor(com.jetbrains.php.lang.psi.visitors.PhpElementVisitor) FunctionReference(com.jetbrains.php.lang.psi.elements.FunctionReference) PhpPsiElement(com.jetbrains.php.lang.psi.elements.PhpPsiElement) NotNull(org.jetbrains.annotations.NotNull)

Example 17 with PhpElementVisitor

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

the class MethodArgumentDroppedMatcherInspection 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.METHOD_REFERENCE).accepts(element)) {
                return;
            }
            MethodReference methodReference = (MethodReference) element;
            ParameterList parameterList = methodReference.getParameterList();
            PhpExpression classReference = methodReference.getClassReference();
            if (classReference != null) {
                PhpType inferredType = classReference.getInferredType();
                String compiledClassMethodKey = inferredType.toString() + "->" + methodReference.getName();
                if (ExtensionScannerUtil.classMethodHasDroppedArguments(element.getProject(), compiledClassMethodKey)) {
                    Integer maximumNumberOfArguments = ExtensionScannerUtil.getMaximumNumberOfArguments(element.getProject(), compiledClassMethodKey);
                    if (parameterList != null && maximumNumberOfArguments != -1 && parameterList.getParameters().length != maximumNumberOfArguments) {
                        problemsHolder.registerProblem(element, "Number of arguments changed with TYPO3 9, consider refactoring");
                    }
                }
            }
        }
    };
}
Also used : PhpElementVisitor(com.jetbrains.php.lang.psi.visitors.PhpElementVisitor) PhpExpression(com.jetbrains.php.lang.psi.elements.PhpExpression) ParameterList(com.jetbrains.php.lang.psi.elements.ParameterList) MethodReference(com.jetbrains.php.lang.psi.elements.MethodReference) PhpPsiElement(com.jetbrains.php.lang.psi.elements.PhpPsiElement) PhpType(com.jetbrains.php.lang.psi.resolve.types.PhpType) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

PhpElementVisitor (com.jetbrains.php.lang.psi.visitors.PhpElementVisitor)17 NotNull (org.jetbrains.annotations.NotNull)17 PsiElement (com.intellij.psi.PsiElement)9 PhpPsiElement (com.jetbrains.php.lang.psi.elements.PhpPsiElement)5 Project (com.intellij.openapi.project.Project)4 MethodReference (com.jetbrains.php.lang.psi.elements.MethodReference)4 PhpClass (com.jetbrains.php.lang.psi.elements.PhpClass)4 ViewResolve (com.nvlad.yii2support.views.entities.ViewResolve)4 PhpIndex (com.jetbrains.php.PhpIndex)3 ViewInfo (com.nvlad.yii2support.views.entities.ViewInfo)3 ClassReference (com.jetbrains.php.lang.psi.elements.ClassReference)2 FunctionReference (com.jetbrains.php.lang.psi.elements.FunctionReference)2 StringLiteralExpression (com.jetbrains.php.lang.psi.elements.StringLiteralExpression)2 PhpType (com.jetbrains.php.lang.psi.resolve.types.PhpType)2 HashSet (java.util.HashSet)2 LocalQuickFix (com.intellij.codeInspection.LocalQuickFix)1 ProblemHighlightType (com.intellij.codeInspection.ProblemHighlightType)1 ProblemsHolder (com.intellij.codeInspection.ProblemsHolder)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 PsiDirectory (com.intellij.psi.PsiDirectory)1