use of com.intellij.psi.PsiPrimitiveType in project intellij-community by JetBrains.
the class NullParameterConstraintChecker method checkMethodParameters.
@NotNull
static PsiParameter[] checkMethodParameters(PsiMethod method) {
if (method.getBody() == null)
return PsiParameter.EMPTY_ARRAY;
final Collection<PsiParameter> nullableParameters = new SmartList<>();
final PsiParameter[] parameters = method.getParameterList().getParameters();
for (int index = 0; index < parameters.length; index++) {
PsiParameter parameter = parameters[index];
if (!(parameter.getType() instanceof PsiPrimitiveType) && !NullableNotNullManager.isNotNull(parameter) && !NullableNotNullManager.isNullable(parameter) && JavaNullMethodArgumentUtil.hasNullArgument(method, index)) {
nullableParameters.add(parameter);
}
}
if (nullableParameters.isEmpty())
return PsiParameter.EMPTY_ARRAY;
final NullParameterConstraintChecker checker = new NullParameterConstraintChecker(nullableParameters);
checker.analyzeMethod(method.getBody(), new StandardInstructionVisitor());
return checker.myPossiblyViolatedParameters.stream().filter(checker.myUsedParameters::contains).toArray(PsiParameter[]::new);
}
use of com.intellij.psi.PsiPrimitiveType in project intellij-community by JetBrains.
the class ContractInference method postProcessContracts.
@NotNull
private static List<MethodContract> postProcessContracts(@NotNull PsiMethodImpl method, MethodData data, List<PreContract> rawContracts) {
List<MethodContract> contracts = ContainerUtil.concat(rawContracts, c -> c.toContracts(method, data.methodBody(method)));
if (contracts.isEmpty())
return Collections.emptyList();
final PsiType returnType = method.getReturnType();
if (returnType != null && !(returnType instanceof PsiPrimitiveType)) {
contracts = boxReturnValues(contracts);
}
List<MethodContract> compatible = ContainerUtil.filter(contracts, contract -> isContractCompatibleWithMethod(method, returnType, contract));
if (compatible.size() > MAX_CONTRACT_COUNT) {
LOG.debug("Too many contracts for " + PsiUtil.getMemberQualifiedName(method) + ", shrinking the list");
return compatible.subList(0, MAX_CONTRACT_COUNT);
}
return compatible;
}
use of com.intellij.psi.PsiPrimitiveType in project intellij-community by JetBrains.
the class PsiTypeCanonicalLookupElement method renderElement.
@Override
public void renderElement(LookupElementPresentation presentation) {
final PsiClass psiClass = getPsiClass();
if (psiClass != null) {
presentation.setIcon(presentation.isReal() ? psiClass.getIcon(Iconable.ICON_FLAG_VISIBILITY) : EMPTY_ICON);
presentation.setTailText(" (" + PsiFormatUtil.getPackageDisplayName(psiClass) + ")", true);
}
final PsiType type = getPsiType();
presentation.setItemText(type.getPresentableText());
presentation.setItemTextBold(type instanceof PsiPrimitiveType);
}
use of com.intellij.psi.PsiPrimitiveType in project intellij-community by JetBrains.
the class GrReplacePrimitiveTypeWithWrapperFix method doFix.
@Override
protected void doFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) throws IncorrectOperationException {
final PsiElement element = descriptor.getPsiElement();
assert element instanceof GrTypeElement : element;
GrTypeElement typeElement = (GrTypeElement) element;
final PsiType type = typeElement.getType();
if (!(type instanceof PsiPrimitiveType))
return;
final PsiClassType boxed = ((PsiPrimitiveType) type).getBoxedType(typeElement);
if (boxed == null)
return;
final GrTypeElement newTypeElement = GroovyPsiElementFactory.getInstance(project).createTypeElement(boxed);
final PsiElement replaced = typeElement.replace(newTypeElement);
JavaCodeStyleManager.getInstance(project).shortenClassReferences(replaced);
}
use of com.intellij.psi.PsiPrimitiveType in project intellij-community by JetBrains.
the class GrCharConverter method isConvertibleEx.
@Nullable
@Override
public ConversionResult isConvertibleEx(@NotNull PsiType lType, @NotNull PsiType rType, @NotNull GroovyPsiElement context, @NotNull ApplicableTo currentPosition) {
if (!PsiType.CHAR.equals(TypesUtil.unboxPrimitiveTypeWrapper(lType)))
return null;
if (PsiType.CHAR.equals(TypesUtil.unboxPrimitiveTypeWrapper(rType)))
return ConversionResult.OK;
// can assign numeric types to char
if (TypesUtil.isNumericType(rType)) {
if (rType instanceof PsiPrimitiveType || TypesUtil.unboxPrimitiveTypeWrapper(rType) instanceof PsiPrimitiveType) {
return PsiType.CHAR.equals(lType) ? ConversionResult.OK : ConversionResult.ERROR;
} else {
// BigDecimal && BigInteger
return ConversionResult.ERROR;
}
}
{
// special case 'c = []' will throw RuntimeError
final GrExpression rValue;
if (context instanceof GrAssignmentExpression) {
final GrAssignmentExpression assignmentExpression = (GrAssignmentExpression) context;
rValue = assignmentExpression.getRValue();
} else if (context instanceof GrVariable) {
final GrVariable assignmentExpression = (GrVariable) context;
rValue = assignmentExpression.getInitializerGroovy();
} else {
rValue = null;
}
if (rValue instanceof GrListOrMap && ((GrListOrMap) rValue).isEmpty()) {
return ConversionResult.WARNING;
}
}
if (PsiType.BOOLEAN.equals(TypesUtil.unboxPrimitiveTypeWrapper(rType))) {
switch(currentPosition) {
case ASSIGNMENT:
case RETURN_VALUE:
return ConversionResult.WARNING;
default:
return null;
}
}
// one-symbol string-to-char conversion doesn't work with return value
if (currentPosition == ApplicableTo.RETURN_VALUE) {
return null;
}
// can cast and assign one-symbol strings to char
if (!TypesUtil.isClassType(rType, CommonClassNames.JAVA_LANG_STRING))
return null;
return checkSingleSymbolLiteral(context) ? ConversionResult.OK : ConversionResult.ERROR;
}
Aggregations