Search in sources :

Example 11 with PhpPsiElement

use of com.jetbrains.php.lang.psi.elements.PhpPsiElement 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 12 with PhpPsiElement

use of com.jetbrains.php.lang.psi.elements.PhpPsiElement 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)

Example 13 with PhpPsiElement

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

the class OpenapiPsiSearchUtil method findResolutionOperator.

/*
        finds '::' or '->' node in a method reference and returns it;
        we are aware of getReferenceType method, but we need operator itself for QF-ing
    */
@Nullable
public static PsiElement findResolutionOperator(@Nullable MemberReference reference) {
    if (reference != null) {
        final PhpPsiElement start = reference.getFirstPsiChild();
        if (start != null) {
            final PsiElement end = reference instanceof FieldReference ? reference.getLastChild() : start.getNextPsiSibling();
            if (end != null) {
                PsiElement current = start.getNextSibling();
                while (current != null && current != end) {
                    final IElementType nodeType = current.getNode().getElementType();
                    if (nodeType == PhpTokenTypes.ARROW || nodeType == PhpTokenTypes.SCOPE_RESOLUTION) {
                        return current;
                    }
                    current = current.getNextSibling();
                }
            }
        }
    }
    return null;
}
Also used : IElementType(com.intellij.psi.tree.IElementType) FieldReference(com.jetbrains.php.lang.psi.elements.FieldReference) PhpPsiElement(com.jetbrains.php.lang.psi.elements.PhpPsiElement) PsiElement(com.intellij.psi.PsiElement) PhpPsiElement(com.jetbrains.php.lang.psi.elements.PhpPsiElement) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

PhpPsiElement (com.jetbrains.php.lang.psi.elements.PhpPsiElement)13 NotNull (org.jetbrains.annotations.NotNull)10 PhpElementVisitor (com.jetbrains.php.lang.psi.visitors.PhpElementVisitor)9 PsiElement (com.intellij.psi.PsiElement)8 StringLiteralExpression (com.jetbrains.php.lang.psi.elements.StringLiteralExpression)5 GroupNames (com.intellij.codeInsight.daemon.GroupNames)3 ProblemsHolder (com.intellij.codeInspection.ProblemsHolder)3 PlatformPatterns (com.intellij.patterns.PlatformPatterns)3 PsiElementVisitor (com.intellij.psi.PsiElementVisitor)3 PsiFile (com.intellij.psi.PsiFile)3 FilenameIndex (com.intellij.psi.search.FilenameIndex)3 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)3 PsiTreeUtil (com.intellij.psi.util.PsiTreeUtil)3 PhpInspection (com.jetbrains.php.lang.inspections.PhpInspection)3 PhpElementTypes (com.jetbrains.php.lang.parser.PhpElementTypes)3 Collections (java.util.Collections)3 HashSet (java.util.HashSet)3 Set (java.util.Set)3 Collectors (java.util.stream.Collectors)3 Nls (org.jetbrains.annotations.Nls)3