Search in sources :

Example 1 with VariableImpl

use of com.jetbrains.php.lang.psi.elements.impl.VariableImpl in project yii2support by nvlad.

the class YiiTypeProvider method getArrayCreationByVariableRef.

@NotNull
private PhpPsiElement getArrayCreationByVariableRef(PhpPsiElement firstParam) {
    Collection<? extends PhpNamedElement> localResolvedVariables = ((VariableImpl) firstParam).resolveLocal();
    PhpNamedElement firstElem = localResolvedVariables.iterator().next();
    if (firstElem instanceof Variable) {
        Variable variableDecl = (Variable) firstElem;
        if (variableDecl.getParent() != null) {
            PsiElement array = variableDecl.getParent().getLastChild();
            if (array instanceof ArrayCreationExpression) {
                firstParam = (ArrayCreationExpression) array;
            }
        }
    }
    return firstParam;
}
Also used : VariableImpl(com.jetbrains.php.lang.psi.elements.impl.VariableImpl) PsiElement(com.intellij.psi.PsiElement) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with VariableImpl

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

the class PhpGlobalsTypeProvider method getType.

@Nullable
@Override
public PhpType getType(PsiElement psiElement) {
    // $GLOBALS['TYPO3_DB']
    if (!(psiElement instanceof ArrayAccessExpression)) {
        return null;
    }
    VariableImpl variable = PsiTreeUtil.getChildOfType(psiElement, VariableImpl.class);
    if (variable == null || !variable.getName().equals("GLOBALS")) {
        return null;
    }
    ArrayIndex arrayIndex = PsiTreeUtil.getChildOfType(psiElement, ArrayIndex.class);
    if (arrayIndex == null) {
        return null;
    }
    StringLiteralExpression arrayIndexName = PsiTreeUtil.getChildOfType(arrayIndex, StringLiteralExpressionImpl.class);
    if (arrayIndexName == null) {
        return null;
    }
    switch(arrayIndexName.getContents()) {
        case "TYPO3_DB":
            return new PhpType().add("#C\\TYPO3\\CMS\\Core\\Database\\DatabaseConnection");
        case "TSFE":
            return new PhpType().add("#C\\TYPO3\\CMS\\Frontend\\Controller\\TypoScriptFrontendController");
        case "BE_USER":
            return new PhpType().add("#C\\TYPO3\\CMS\\Core\\Authentication\\BackendUserAuthentication");
        case "LANG":
            return new PhpType().add("#C\\TYPO3\\CMS\\Lang\\LanguageService");
        default:
            return null;
    }
}
Also used : VariableImpl(com.jetbrains.php.lang.psi.elements.impl.VariableImpl) PhpType(com.jetbrains.php.lang.psi.resolve.types.PhpType) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

VariableImpl (com.jetbrains.php.lang.psi.elements.impl.VariableImpl)2 PsiElement (com.intellij.psi.PsiElement)1 PhpType (com.jetbrains.php.lang.psi.resolve.types.PhpType)1 NotNull (org.jetbrains.annotations.NotNull)1 Nullable (org.jetbrains.annotations.Nullable)1