use of com.intellij.psi.PsiType in project intellij-community by JetBrains.
the class ArgumentInstruction method inferMixinType.
@Override
@Nullable
public PsiType inferMixinType() {
PsiElement element = getElement();
assert element != null;
GrCall call = findCall(element);
GrExpression[] arguments = call.getExpressionArguments();
boolean hasNamed = PsiImplUtil.hasNamedArguments(call.getArgumentList());
int index = ArrayUtil.indexOf(arguments, element) + (hasNamed ? 1 : 0);
GroovyResolveResult[] variants = call.getCallVariants((GrReferenceExpression) element);
PsiType result = null;
for (GroovyResolveResult variant : variants) {
GrClosureSignature signature = GrClosureSignatureUtil.createSignature(variant);
if (signature == null)
continue;
if (GrClosureSignatureUtil.mapParametersToArguments(signature, call) != null && !haveNullParameters(call)) {
return null;
}
GrClosureParameter[] parameters = signature.getParameters();
if (index >= parameters.length)
continue;
result = TypesUtil.getLeastUpperBoundNullable(result, parameters[index].getType(), element.getManager());
}
return result;
}
use of com.intellij.psi.PsiType in project intellij-community by JetBrains.
the class TypeInferenceHelper method getInitializerTypeFor.
@Nullable
public static PsiType getInitializerTypeFor(PsiElement element) {
final PsiElement parent = skipParentheses(element.getParent(), true);
if (parent instanceof GrAssignmentExpression) {
if (element instanceof GrIndexProperty) {
final GrExpression rvalue = ((GrAssignmentExpression) parent).getRValue();
//don't try to infer assignment type in case of index property because of infinite recursion (example: a[2]+=4)
return rvalue != null ? rvalue.getType() : null;
}
return ((GrAssignmentExpression) parent).getType();
}
if (parent instanceof GrTupleExpression) {
GrTupleExpression list = (GrTupleExpression) parent;
if (list.getParent() instanceof GrAssignmentExpression) {
// multiple assignment
final GrExpression rValue = ((GrAssignmentExpression) list.getParent()).getRValue();
int idx = list.indexOf(element);
if (idx >= 0 && rValue != null) {
PsiType rType = rValue.getType();
if (rType instanceof GrTupleType) {
PsiType[] componentTypes = ((GrTupleType) rType).getComponentTypes();
if (idx < componentTypes.length)
return componentTypes[idx];
return null;
}
return PsiUtil.extractIterableTypeParameter(rType, false);
}
}
}
if (parent instanceof GrUnaryExpression && TokenSets.POSTFIX_UNARY_OP_SET.contains(((GrUnaryExpression) parent).getOperationTokenType())) {
return ((GrUnaryExpression) parent).getType();
}
return null;
}
use of com.intellij.psi.PsiType in project intellij-community by JetBrains.
the class TypeDfaState method getBindings.
Map<String, PsiType> getBindings(Instruction instruction) {
HashMap<String, PsiType> map = ContainerUtil.newHashMap();
for (Map.Entry<String, DFAType> entry : myVarTypes.entrySet()) {
DFAType value = entry.getValue();
map.put(entry.getKey(), value == null ? null : value.negate(instruction).getResultType());
}
return map;
}
use of com.intellij.psi.PsiType in project intellij-community by JetBrains.
the class GroovyNamesUtil method getMethodArgumentsNames.
public static String[] getMethodArgumentsNames(Project project, PsiType[] types) {
Set<String> uniqNames = new LinkedHashSet<>();
Set<String> nonUniqNames = new THashSet<>();
for (PsiType type : types) {
final SuggestedNameInfo nameInfo = JavaCodeStyleManager.getInstance(project).suggestVariableName(VariableKind.PARAMETER, null, null, type);
final String name = nameInfo.names[0];
if (uniqNames.contains(name)) {
int i = 2;
while (uniqNames.contains(name + i)) i++;
uniqNames.add(name + i);
nonUniqNames.add(name);
} else {
uniqNames.add(name);
}
}
final String[] result = new String[uniqNames.size()];
int i = 0;
for (String name : uniqNames) {
result[i] = nonUniqNames.contains(name) ? name + 1 : name;
i++;
}
return result;
}
use of com.intellij.psi.PsiType in project intellij-community by JetBrains.
the class GrNumericBinaryExpressionTypeCalculator method fun.
@Nullable
@Override
public PsiType fun(GrOperatorExpression e) {
final GroovyResolveResult resolveResult = PsiImplUtil.extractUniqueResult(e.multiResolve(false));
if (resolveResult.isApplicable() && !PsiUtil.isDGMMethod(resolveResult.getElement())) {
return ResolveUtil.extractReturnTypeFromCandidate(resolveResult, e, new PsiType[] { e.getRightType() });
}
PsiType lType = e.getLeftType();
PsiType rType = e.getRightType();
if (TypesUtil.isNumericType(lType) && TypesUtil.isNumericType(rType)) {
return inferNumericType(lType, rType, e);
}
return ResolveUtil.extractReturnTypeFromCandidate(resolveResult, e, new PsiType[] { rType });
}
Aggregations