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);
}
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;
}
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$)";
}
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);
}
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);
}
Aggregations