use of org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.literals.GrLiteral in project intellij-community by JetBrains.
the class GrLiteralImpl method updateText.
@Override
public GrLiteralImpl updateText(@NotNull final String text) {
final GrExpression newExpr = GroovyPsiElementFactory.getInstance(getProject()).createExpressionFromText(text);
LOG.assertTrue(newExpr instanceof GrLiteral, text);
LOG.assertTrue(newExpr.getFirstChild() != null, text);
final ASTNode valueNode = getNode().getFirstChildNode();
getNode().replaceChild(valueNode, newExpr.getFirstChild().getNode());
return this;
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.literals.GrLiteral in project intellij-community by JetBrains.
the class DefaultCallExpressionTypeCalculator method getClosureMethodsReturnType.
@Nullable
private static PsiType getClosureMethodsReturnType(GrMethodCall callExpression, GrReferenceExpression refExpr, PsiMethod resolved) {
PsiClass clazz = resolved.getContainingClass();
if (clazz == null || !GroovyCommonClassNames.GROOVY_LANG_CLOSURE.equals(clazz.getQualifiedName()))
return null;
if (!CLOSURE_METHODS.contains(resolved.getName()))
return null;
GrExpression qualifier = refExpr.getQualifierExpression();
if (qualifier == null)
return null;
PsiType qType = qualifier.getType();
if (!(qType instanceof GrClosureType))
return null;
if ("call".equals(resolved.getName())) {
return GrClosureSignatureUtil.getReturnType(((GrClosureType) qType).getSignature(), callExpression);
} else if ("curry".equals(resolved.getName()) || "trampoline".equals(resolved.getName())) {
return ((GrClosureType) qType).curry(PsiUtil.getArgumentTypes(refExpr, false), 0, callExpression);
} else if ("memoize".equals(resolved.getName())) {
return qType;
} else if ("rcurry".equals(resolved.getName())) {
return ((GrClosureType) qType).curry(PsiUtil.getArgumentTypes(refExpr, false), -1, callExpression);
} else if ("ncurry".equals(resolved.getName())) {
final GrArgumentList argList = callExpression.getArgumentList();
final GrExpression[] arguments = argList.getExpressionArguments();
if (arguments.length > 0) {
final GrExpression first = arguments[0];
if (first instanceof GrLiteral) {
final Object value = ((GrLiteral) first).getValue();
if (value instanceof Integer) {
final PsiType[] argTypes = PsiUtil.getArgumentTypes(refExpr, false);
if (argTypes != null) {
return ((GrClosureType) qType).curry(ArrayUtil.remove(argTypes, 0), (Integer) value, callExpression);
}
}
}
}
return qType;
}
return null;
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.literals.GrLiteral in project intellij-community by JetBrains.
the class GrCharConverter method checkSingleSymbolLiteral.
public static boolean checkSingleSymbolLiteral(GroovyPsiElement context) {
final GrLiteral literal = getLiteral(context);
final Object value = literal == null ? null : literal.getValue();
return value != null && value.toString().length() == 1;
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.literals.GrLiteral in project intellij-community by JetBrains.
the class GrClassConverter method isConvertibleEx.
@Nullable
@Override
public ConversionResult isConvertibleEx(@NotNull PsiType targetType, @NotNull PsiType actualType, @NotNull GroovyPsiElement context, @NotNull ApplicableTo currentPosition) {
if (!(targetType instanceof PsiClassType) || !((PsiClassType) targetType).rawType().equalsToText(CommonClassNames.JAVA_LANG_CLASS)) {
return null;
}
if (actualType == PsiType.NULL)
return ConversionResult.OK;
final GrLiteral literal = getLiteral(context);
final Object value = literal == null ? null : literal.getValue();
final String fqn = value == null ? null : value.toString();
final PsiClass psiClass = fqn == null ? null : JavaPsiFacade.getInstance(context.getProject()).findClass(fqn, context.getResolveScope());
return psiClass == null ? ConversionResult.WARNING : ConversionResult.OK;
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.literals.GrLiteral in project intellij-community by JetBrains.
the class StringPartInfo method findLiteral.
@Nullable
private static GrLiteral findLiteral(@NotNull PsiElement psi) {
PsiElement parent = psi.getParent();
if (isStringLiteral(parent)) {
return (GrLiteral) parent;
}
if (parent == null)
return null;
PsiElement gParent = parent.getParent();
if (isStringLiteral(gParent)) {
return (GrLiteral) gParent;
}
if (psi instanceof GrString) {
return (GrLiteral) psi;
}
return null;
}
Aggregations