Search in sources :

Example 31 with PsiExpression

use of com.intellij.psi.PsiExpression in project intellij-community by JetBrains.

the class ComponentTypeOfMacro method calculateResult.

@Override
public Result calculateResult(@NotNull Expression[] params, final ExpressionContext context) {
    if (params.length != 1)
        return null;
    final Result result = params[0].calculateResult(context);
    if (result == null)
        return null;
    if (result instanceof PsiTypeResult) {
        PsiType type = ((PsiTypeResult) result).getType();
        if (type instanceof PsiArrayType) {
            return new PsiTypeResult(((PsiArrayType) type).getComponentType(), context.getProject());
        }
    }
    PsiExpression expr = MacroUtil.resultToPsiExpression(result, context);
    PsiType type = expr == null ? MacroUtil.resultToPsiType(result, context) : expr.getType();
    if (type instanceof PsiArrayType) {
        return new PsiTypeResult(((PsiArrayType) type).getComponentType(), context.getProject());
    }
    LookupElement[] elements = params[0].calculateLookupItems(context);
    if (elements != null) {
        for (LookupElement element : elements) {
            PsiTypeLookupItem typeLookupItem = element.as(PsiTypeLookupItem.CLASS_CONDITION_KEY);
            if (typeLookupItem != null) {
                PsiType psiType = typeLookupItem.getType();
                if (psiType instanceof PsiArrayType) {
                    return new PsiTypeResult(((PsiArrayType) psiType).getComponentType(), context.getProject());
                }
            }
        }
    }
    return new PsiElementResult(null);
}
Also used : PsiTypeLookupItem(com.intellij.codeInsight.lookup.PsiTypeLookupItem) PsiExpression(com.intellij.psi.PsiExpression) LookupElement(com.intellij.codeInsight.lookup.LookupElement) PsiArrayType(com.intellij.psi.PsiArrayType) PsiType(com.intellij.psi.PsiType)

Example 32 with PsiExpression

use of com.intellij.psi.PsiExpression in project intellij-community by JetBrains.

the class JavaPolyadicExpressionUnwrapper method isApplicableTo.

@Override
public boolean isApplicableTo(PsiElement e) {
    if (!(e.getParent() instanceof PsiPolyadicExpression)) {
        return false;
    }
    final PsiPolyadicExpression expression = (PsiPolyadicExpression) e.getParent();
    final PsiExpression operand = findOperand(e, expression);
    return operand != null;
}
Also used : PsiExpression(com.intellij.psi.PsiExpression) PsiPolyadicExpression(com.intellij.psi.PsiPolyadicExpression)

Example 33 with PsiExpression

use of com.intellij.psi.PsiExpression in project intellij-community by JetBrains.

the class OptionalPostfixTemplate method getTemplateString.

@Nullable
@Override
public String getTemplateString(@NotNull PsiElement element) {
    String className = "Optional";
    String methodName = "ofNullable";
    if (element instanceof PsiExpression) {
        PsiType type = ((PsiExpression) element).getType();
        if (type instanceof PsiPrimitiveType) {
            if (PsiType.INT.equals(type)) {
                className = "OptionalInt";
            } else if (PsiType.DOUBLE.equals(type)) {
                className = "OptionalDouble";
            } else if (PsiType.LONG.equals(type)) {
                className = "OptionalLong";
            }
            methodName = "of";
        }
    }
    return "java.util." + className + "." + methodName + "($expr$)";
}
Also used : PsiPrimitiveType(com.intellij.psi.PsiPrimitiveType) PsiExpression(com.intellij.psi.PsiExpression) PsiType(com.intellij.psi.PsiType) Nullable(org.jetbrains.annotations.Nullable)

Example 34 with PsiExpression

use of com.intellij.psi.PsiExpression in project intellij-community by JetBrains.

the class NotInSuperOrThisCallFilterBase method isOK.

public boolean isOK(PsiExpression occurrence) {
    PsiElement parent = occurrence.getParent();
    while (parent instanceof PsiExpression) {
        parent = parent.getParent();
    }
    if (!(parent instanceof PsiExpressionList))
        return true;
    parent = parent.getParent();
    if (!(parent instanceof PsiMethodCallExpression))
        return true;
    final String text = ((PsiMethodCallExpression) parent).getMethodExpression().getText();
    return !getKeywordText().equals(text);
}
Also used : PsiExpression(com.intellij.psi.PsiExpression) PsiExpressionList(com.intellij.psi.PsiExpressionList) PsiElement(com.intellij.psi.PsiElement) PsiMethodCallExpression(com.intellij.psi.PsiMethodCallExpression)

Example 35 with PsiExpression

use of com.intellij.psi.PsiExpression in project intellij-community by JetBrains.

the class ReturnWrappedValue method fixUsage.

@Override
public void fixUsage() throws IncorrectOperationException {
    PsiMethodCallExpression returnValue = (PsiMethodCallExpression) myStatement.getReturnValue();
    assert returnValue != null;
    PsiExpression qualifier = returnValue.getMethodExpression().getQualifierExpression();
    assert qualifier != null;
    MutationUtils.replaceExpression(qualifier.getText(), returnValue);
}
Also used : PsiExpression(com.intellij.psi.PsiExpression) PsiMethodCallExpression(com.intellij.psi.PsiMethodCallExpression)

Aggregations

PsiExpression (com.intellij.psi.PsiExpression)72 PsiElement (com.intellij.psi.PsiElement)28 PsiReferenceExpression (com.intellij.psi.PsiReferenceExpression)13 PsiMethodCallExpression (com.intellij.psi.PsiMethodCallExpression)11 Nullable (org.jetbrains.annotations.Nullable)9 PsiReference (com.intellij.psi.PsiReference)8 PsiType (com.intellij.psi.PsiType)8 NonNls (org.jetbrains.annotations.NonNls)8 PsiClass (com.intellij.psi.PsiClass)7 PsiAssignmentExpression (com.intellij.psi.PsiAssignmentExpression)6 PsiExpressionStatement (com.intellij.psi.PsiExpressionStatement)6 PsiLocalVariable (com.intellij.psi.PsiLocalVariable)6 PsiMethod (com.intellij.psi.PsiMethod)6 PsiNewExpression (com.intellij.psi.PsiNewExpression)6 PsiPolyadicExpression (com.intellij.psi.PsiPolyadicExpression)6 PsiStatement (com.intellij.psi.PsiStatement)6 Project (com.intellij.openapi.project.Project)5 PsiBinaryExpression (com.intellij.psi.PsiBinaryExpression)5 PsiDeclarationStatement (com.intellij.psi.PsiDeclarationStatement)5 PsiElementFactory (com.intellij.psi.PsiElementFactory)5