Search in sources :

Example 26 with PhpIndex

use of com.jetbrains.php.PhpIndex in project yii2support by nvlad.

the class ClassUtils method getPhpClassUniversal.

@Nullable
public static PhpClass getPhpClassUniversal(Project project, PhpPsiElement value) {
    if (value instanceof MethodReference && (value.getName().equals("className") || value.getName().equals("tableName"))) {
        MethodReference methodRef = (MethodReference) value;
        return getPhpClass(methodRef.getClassReference());
    }
    if (value instanceof ClassConstantReference || value instanceof ConstantReference) {
        return getPhpClass(value);
    }
    if (value instanceof StringLiteralExpression) {
        StringLiteralExpression str = (StringLiteralExpression) value;
        PhpIndex phpIndex = PhpIndex.getInstance(project);
        return getClass(phpIndex, str.getContents());
    }
    return null;
}
Also used : PhpIndex(com.jetbrains.php.PhpIndex) Nullable(org.jetbrains.annotations.Nullable)

Example 27 with PhpIndex

use of com.jetbrains.php.PhpIndex in project yii2support by nvlad.

the class ValidationCompletionProvider method getDefaultValidators.

private static HashMap<String, PhpPsiElement> getDefaultValidators(Project project) {
    HashMap<String, PhpPsiElement> validators = new LinkedHashMap<>();
    PhpIndex phpIndex = PhpIndex.getInstance(project);
    Collection<PhpClass> classesByFQN = phpIndex.getClassesByFQN("\\yii\\validators\\Validator");
    if (!classesByFQN.isEmpty()) {
        PhpClass validatorClass = classesByFQN.iterator().next();
        Field builtInValidatorsField = validatorClass.findOwnFieldByName("builtInValidators", false);
        // Default validators not found
        if (builtInValidatorsField == null)
            return null;
        ArrayCreationExpression fieldArray = (ArrayCreationExpression) builtInValidatorsField.getDefaultValue();
        Iterable<ArrayHashElement> hashElements = fieldArray.getHashElements();
        for (ArrayHashElement elem : hashElements) {
            if (elem.getValue() instanceof ArrayCreationExpression) {
                PhpClass phpClass = ObjectFactoryUtils.findClassByArray((ArrayCreationExpression) elem.getValue());
                validators.put(ClassUtils.removeQuotes(elem.getKey().getText()), phpClass);
            } else {
                PhpClass phpClass = phpIndex.getClassesByFQN(ClassUtils.removeQuotes(elem.getValue().getText())).iterator().next();
                String validatorName = ClassUtils.removeQuotes(elem.getKey().getText());
                validators.put(validatorName, phpClass);
            }
        }
    }
    return validators;
}
Also used : PhpIndex(com.jetbrains.php.PhpIndex)

Example 28 with PhpIndex

use of com.jetbrains.php.PhpIndex in project idea-php-typo3-plugin by cedricziel.

the class GeneralUtilityServiceTypeProvider method getBySignature.

@Override
public Collection<? extends PhpNamedElement> getBySignature(String expression, Set<String> visited, int depth, Project project) {
    Collection<PhpNamedElement> phpNamedElementCollections = new ArrayList<>();
    PhpIndex phpIndex = PhpIndex.getInstance(project);
    CoreServiceParser serviceParser = new CoreServiceParser();
    serviceParser.collect(project);
    List<TYPO3ServiceDefinition> resolvedServices = serviceParser.resolve(project, expression);
    if (resolvedServices == null || resolvedServices.isEmpty()) {
        return phpNamedElementCollections;
    }
    resolvedServices.forEach(serviceDefinition -> {
        Collection<PhpClass> classesByFQN = phpIndex.getClassesByFQN(serviceDefinition.getClassName());
        phpNamedElementCollections.addAll(classesByFQN);
    });
    return phpNamedElementCollections;
}
Also used : TYPO3ServiceDefinition(com.cedricziel.idea.typo3.domain.TYPO3ServiceDefinition) PhpNamedElement(com.jetbrains.php.lang.psi.elements.PhpNamedElement) PhpIndex(com.jetbrains.php.PhpIndex) PhpClass(com.jetbrains.php.lang.psi.elements.PhpClass) ArrayList(java.util.ArrayList) CoreServiceParser(com.cedricziel.idea.typo3.container.CoreServiceParser)

Example 29 with PhpIndex

use of com.jetbrains.php.PhpIndex in project idea-php-typo3-plugin by cedricziel.

the class PhpElementsUtil method allExtendedClasses.

public static List<PhpClass> allExtendedClasses(PhpClass phpClass) {
    List<PhpClass> classReferences = new ArrayList<>();
    PhpIndex index = PhpIndex.getInstance(phpClass.getProject());
    List<ClassReference> referenceElements = phpClass.getExtendsList().getReferenceElements();
    for (ClassReference reference : referenceElements) {
        Collection<PhpClass> classesByFQN = index.getClassesByFQN(reference.getFQN());
        for (PhpClass phpClass1 : classesByFQN) {
            classReferences.add(phpClass);
            classReferences.addAll(allExtendedClasses(phpClass1));
        }
    }
    return classReferences;
}
Also used : PhpIndex(com.jetbrains.php.PhpIndex)

Aggregations

PhpIndex (com.jetbrains.php.PhpIndex)29 PsiElement (com.intellij.psi.PsiElement)19 NotNull (org.jetbrains.annotations.NotNull)18 PhpType (com.jetbrains.php.lang.psi.resolve.types.PhpType)11 BasePhpElementVisitor (com.kalessil.phpStorm.phpInspectionsEA.openApi.BasePhpElementVisitor)11 HashSet (java.util.HashSet)11 ProblemsHolder (com.intellij.codeInspection.ProblemsHolder)9 Project (com.intellij.openapi.project.Project)9 PhpClass (com.jetbrains.php.lang.psi.elements.PhpClass)8 Nullable (org.jetbrains.annotations.Nullable)7 PsiElementVisitor (com.intellij.psi.PsiElementVisitor)6 com.jetbrains.php.lang.psi.elements (com.jetbrains.php.lang.psi.elements)6 BasePhpInspection (com.kalessil.phpStorm.phpInspectionsEA.openApi.BasePhpInspection)6 OpenapiResolveUtil (com.kalessil.phpStorm.phpInspectionsEA.utils.OpenapiResolveUtil)6 InterfacesExtractUtil (com.kalessil.phpStorm.phpInspectionsEA.utils.hierarhy.InterfacesExtractUtil)6 Set (java.util.Set)6 PsiTreeUtil (com.intellij.psi.util.PsiTreeUtil)5 PhpTokenTypes (com.jetbrains.php.lang.lexer.PhpTokenTypes)4 MessagesPresentationUtil (com.kalessil.phpStorm.phpInspectionsEA.utils.MessagesPresentationUtil)4 Types (com.kalessil.phpStorm.phpInspectionsEA.utils.Types)4