本文整理匯總了Java中com.intellij.codeInspection.dataFlow.Nullness.NOT_NULL屬性的典型用法代碼示例。如果您正苦於以下問題:Java Nullness.NOT_NULL屬性的具體用法?Java Nullness.NOT_NULL怎麽用?Java Nullness.NOT_NULL使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類com.intellij.codeInspection.dataFlow.Nullness
的用法示例。
在下文中一共展示了Nullness.NOT_NULL屬性的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: calcInherentNullability
private Nullness calcInherentNullability() {
PsiMethod accessMethod = myAccessMethod;
Nullness nullability = DfaPsiUtil.getElementNullability(getVariableType(), accessMethod);
if (nullability != Nullness.UNKNOWN) {
return nullability;
}
PsiVariable var = getPsiVariable();
nullability = DfaPsiUtil.getElementNullability(getVariableType(), var);
if (nullability != Nullness.UNKNOWN) {
return nullability;
}
if (var != null) {
if (DfaPsiUtil.isNullableInitialized(var, true)) {
return Nullness.NULLABLE;
}
if (DfaPsiUtil.isNullableInitialized(var, false)) {
return Nullness.NOT_NULL;
}
}
return Nullness.UNKNOWN;
}
示例2: isNotNullNotInferred
private static boolean isNotNullNotInferred(@NotNull PsiModifierListOwner owner, boolean checkBases, boolean skipExternal)
{
Project project = owner.getProject();
NullableNotNullManager manager = NullableNotNullManager.getInstance(project);
if(!manager.isNotNull(owner, checkBases))
{
return false;
}
if(DfaPsiUtil.getTypeNullability(getMemberType(owner)) == Nullness.NOT_NULL)
{
return true;
}
PsiAnnotation anno = manager.getNotNullAnnotation(owner, checkBases);
if(anno == null || AnnotationUtil.isInferredAnnotation(anno))
{
return false;
}
if(skipExternal && AnnotationUtil.isExternalAnnotation(anno))
{
return false;
}
return true;
}
示例3: getModifiedExpression
@NotNull
private static PsiExpression getModifiedExpression(PsiExpression expression)
{
final Project project = expression.getProject();
PsiModifierListOwner toCheckNullability = null;
if(expression instanceof PsiMethodCallExpression)
{
toCheckNullability = ((PsiMethodCallExpression) expression).resolveMethod();
}
else if(expression instanceof PsiReferenceExpression)
{
final PsiElement resolved = ((PsiReferenceExpression) expression).resolve();
if(resolved instanceof PsiModifierListOwner)
{
toCheckNullability = (PsiModifierListOwner) resolved;
}
}
final Nullness nullability = toCheckNullability == null ? Nullness.NOT_NULL : DfaPsiUtil.getElementNullability(expression.getType(), toCheckNullability);
String methodName = nullability == Nullness.NOT_NULL ? "of" : "ofNullable";
final String newExpressionText = CommonClassNames.JAVA_UTIL_OPTIONAL + "." + methodName + "(" + expression.getText() + ")";
return JavaPsiFacade.getElementFactory(project).createExpressionFromText(newExpressionText, expression);
}
示例4: getInferredNullityAnnotation
@Nullable
private PsiAnnotation getInferredNullityAnnotation(PsiMethodImpl method)
{
NullableNotNullManager manager = NullableNotNullManager.getInstance(myProject);
if(AnnotationUtil.findAnnotation(method, manager.getNotNulls(), true) != null || AnnotationUtil.findAnnotation(method, manager.getNullables(), true) != null)
{
return null;
}
if(NullableNotNullManager.findNullabilityDefaultInHierarchy(method, true) != null || NullableNotNullManager.findNullabilityDefaultInHierarchy(method, false) != null)
{
return null;
}
Nullness nullness = NullityInference.inferNullity(method);
if(nullness == Nullness.NOT_NULL)
{
return ProjectBytecodeAnalysis.getInstance(myProject).getNotNullAnnotation();
}
if(nullness == Nullness.NULLABLE)
{
return ProjectBytecodeAnalysis.getInstance(myProject).getNullableAnnotation();
}
return null;
}
示例5: extractNullityFromWhenValue
@NotNull
private static Nullness extractNullityFromWhenValue(PsiAnnotation nonNull)
{
PsiAnnotationMemberValue when = nonNull.findAttributeValue("when");
if(when instanceof PsiReferenceExpression)
{
String refName = ((PsiReferenceExpression) when).getReferenceName();
if("ALWAYS".equals(refName))
{
return Nullness.NOT_NULL;
}
if("MAYBE".equals(refName) || "NEVER".equals(refName))
{
return Nullness.NULLABLE;
}
}
return Nullness.UNKNOWN;
}
示例6: getFieldInitializerNullness
private static Nullness getFieldInitializerNullness(@NotNull PsiExpression expression) {
if (expression.textMatches(PsiKeyword.NULL)) return Nullness.NULLABLE;
if (expression instanceof PsiNewExpression || expression instanceof PsiLiteralExpression || expression instanceof PsiPolyadicExpression) return Nullness.NOT_NULL;
if (expression instanceof PsiReferenceExpression) {
PsiElement target = ((PsiReferenceExpression)expression).resolve();
return DfaPsiUtil.getElementNullability(null, (PsiModifierListOwner)target);
}
if (expression instanceof PsiMethodCallExpression) {
PsiMethod method = ((PsiMethodCallExpression)expression).resolveMethod();
return method != null ? DfaPsiUtil.getElementNullability(null, method) : Nullness.UNKNOWN;
}
return Nullness.UNKNOWN;
}
示例7: MethodCallInstruction
public MethodCallInstruction(@NotNull PsiMethodReferenceExpression reference, @NotNull List<? extends MethodContract> contracts)
{
myContext = reference;
myMethodType = MethodType.METHOD_REFERENCE_CALL;
JavaResolveResult resolveResult = reference.advancedResolve(false);
myTargetMethod = ObjectUtils.tryCast(resolveResult.getElement(), PsiMethod.class);
myContracts = Collections.unmodifiableList(contracts);
myArgCount = myTargetMethod == null ? 0 : myTargetMethod.getParameterList().getParametersCount();
if(myTargetMethod == null)
{
myType = null;
myReturnNullability = Nullness.UNKNOWN;
}
else
{
if(myTargetMethod.isConstructor())
{
PsiClass containingClass = myTargetMethod.getContainingClass();
myType = containingClass == null ? null : JavaPsiFacade.getElementFactory(myTargetMethod.getProject()).createType(containingClass, resolveResult.getSubstitutor());
myReturnNullability = Nullness.NOT_NULL;
}
else
{
myType = resolveResult.getSubstitutor().substitute(myTargetMethod.getReturnType());
myReturnNullability = DfaPsiUtil.getElementNullability(myType, myTargetMethod);
}
}
myVarArgCall = false; // vararg method reference calls are not supported now
myPrecalculatedReturnValue = null;
myArgRequiredNullability = myTargetMethod == null ? EMPTY_NULLNESS_ARRAY : calcArgRequiredNullability(resolveResult.getSubstitutor(), myTargetMethod.getParameterList().getParameters());
myShouldFlushFields = !isPureCall();
}
示例8: checkLoopParameterNullability
private static void checkLoopParameterNullability(ProblemsHolder holder, @Nullable PsiAnnotation notNull, @Nullable PsiAnnotation nullable, Nullness expectedNullability)
{
if(notNull != null && expectedNullability == Nullness.NULLABLE)
{
holder.registerProblem(notNull, "Parameter can be null", new RemoveAnnotationQuickFix(notNull, null));
}
else if(nullable != null && expectedNullability == Nullness.NOT_NULL)
{
holder.registerProblem(nullable, "Parameter is always not-null", new RemoveAnnotationQuickFix(nullable, null));
}
}
示例9: isNotNull
public boolean isNotNull() {
return myNullness == Nullness.NOT_NULL;
}
示例10: calcInherentNullability
private Nullness calcInherentNullability() {
PsiModifierListOwner var = getPsiVariable();
Nullness nullability = DfaPsiUtil.getElementNullability(getVariableType(), var);
if (nullability != Nullness.UNKNOWN) {
return nullability;
}
Nullness defaultNullability = myFactory.isUnknownMembersAreNullable() && MEMBER_OR_METHOD_PARAMETER.accepts(var) ? Nullness.NULLABLE : Nullness.UNKNOWN;
if (var instanceof PsiParameter && var.getParent() instanceof PsiForeachStatement) {
PsiExpression iteratedValue = ((PsiForeachStatement)var.getParent()).getIteratedValue();
if (iteratedValue != null) {
PsiType itemType = JavaGenericsUtil.getCollectionItemType(iteratedValue);
if (itemType != null) {
return DfaPsiUtil.getElementNullability(itemType, var);
}
}
}
if (var instanceof PsiField && DfaPsiUtil.isFinalField((PsiVariable)var) && myFactory.isHonorFieldInitializers()) {
List<PsiExpression> initializers = DfaPsiUtil.findAllConstructorInitializers((PsiField)var);
if (initializers.isEmpty()) {
return defaultNullability;
}
boolean hasUnknowns = false;
for (PsiExpression expression : initializers) {
Nullness nullness = getFieldInitializerNullness(expression);
if (nullness == Nullness.NULLABLE) {
return Nullness.NULLABLE;
}
if (nullness == Nullness.UNKNOWN) {
hasUnknowns = true;
}
}
if (hasUnknowns) {
if (DfaPsiUtil.isInitializedNotNull((PsiField)var)) {
return Nullness.NOT_NULL;
}
return defaultNullability;
}
return Nullness.NOT_NULL;
}
return defaultNullability;
}
示例11: checkNullness
@NotNull
private static Nullness checkNullness(final PsiElement element) {
// null
PsiElement value = element;
if (value instanceof PsiExpression) {
value = PsiUtil.deparenthesizeExpression((PsiExpression)value);
}
if (value instanceof PsiLiteralExpression) {
return ((PsiLiteralExpression)value).getValue() == null ? Nullness.NULLABLE : Nullness.NOT_NULL;
}
// not null
if (value instanceof PsiNewExpression) return Nullness.NOT_NULL;
if (value instanceof PsiThisExpression) return Nullness.NOT_NULL;
if (value instanceof PsiMethodCallExpression) {
PsiMethod method = ((PsiMethodCallExpression)value).resolveMethod();
if (method != null && NullableNotNullManager.isNotNull(method)) return Nullness.NOT_NULL;
if (method != null && NullableNotNullManager.isNullable(method)) return Nullness.NULLABLE;
}
if (value instanceof PsiPolyadicExpression && ((PsiPolyadicExpression)value).getOperationTokenType() == JavaTokenType.PLUS) {
return Nullness.NOT_NULL; // "xxx" + var
}
// unfortunately have to resolve here, since there can be no subnodes
PsiElement context = value;
if (value instanceof PsiReference) {
PsiElement resolved = ((PsiReference)value).resolve();
if (resolved instanceof PsiCompiledElement) {
resolved = resolved.getNavigationElement();
}
value = resolved;
}
if (value instanceof PsiParameter && ((PsiParameter)value).getDeclarationScope() instanceof PsiCatchSection) {
// exception thrown is always not null
return Nullness.NOT_NULL;
}
if (value instanceof PsiLocalVariable || value instanceof PsiParameter) {
Nullness result = DfaUtil.checkNullness((PsiVariable)value, context);
if (result != Nullness.UNKNOWN) {
return result;
}
}
if (value instanceof PsiModifierListOwner) {
if (NullableNotNullManager.isNotNull((PsiModifierListOwner)value)) return Nullness.NOT_NULL;
if (NullableNotNullManager.isNullable((PsiModifierListOwner)value)) return Nullness.NULLABLE;
}
if (value instanceof PsiEnumConstant) return Nullness.NOT_NULL;
return Nullness.UNKNOWN;
}
示例12: createTypeValueWithNullability
public DfaValue createTypeValueWithNullability(@Nullable PsiType type, Nullness nullability) {
return nullability == Nullness.NOT_NULL ? getNotNullFactory().create(type) : getTypeFactory().create(type, nullability == Nullness.NULLABLE);
}
示例13: isNotNull
public boolean isNotNull()
{
return myNullness == Nullness.NOT_NULL;
}
示例14: isEllipsisWithNotNullElements
private static boolean isEllipsisWithNotNullElements(PsiType lastParamType)
{
return lastParamType instanceof PsiEllipsisType && DfaPsiUtil.getElementNullability(((PsiEllipsisType) lastParamType).getComponentType(), null) == Nullness.NOT_NULL;
}