當前位置: 首頁>>代碼示例>>Java>>正文


Java Nullness.UNKNOWN屬性代碼示例

本文整理匯總了Java中com.intellij.codeInspection.dataFlow.Nullness.UNKNOWN屬性的典型用法代碼示例。如果您正苦於以下問題:Java Nullness.UNKNOWN屬性的具體用法?Java Nullness.UNKNOWN怎麽用?Java Nullness.UNKNOWN使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在com.intellij.codeInspection.dataFlow.Nullness的用法示例。


在下文中一共展示了Nullness.UNKNOWN屬性的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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;
}
 
開發者ID:lshain-android-source,項目名稱:tools-idea,代碼行數:24,代碼來源:DfaVariableValue.java

示例2: 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;
}
 
開發者ID:consulo,項目名稱:consulo-java,代碼行數:18,代碼來源:NullableNotNullManagerImpl.java

示例3: 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;
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:13,代碼來源:DfaVariableValue.java

示例4: suggestNullabilityForNonAnnotatedMember

@NotNull
public Nullness suggestNullabilityForNonAnnotatedMember(@NotNull PsiModifierListOwner member)
{
	if(myUnknownMembersAreNullable && MEMBER_OR_METHOD_PARAMETER.accepts(member) && AnnotationUtil.getSuperAnnotationOwners(member).isEmpty())
	{
		return Nullness.NULLABLE;
	}

	return Nullness.UNKNOWN;
}
 
開發者ID:consulo,項目名稱:consulo-java,代碼行數:10,代碼來源:DfaValueFactory.java

示例5: MethodCallInstruction

public MethodCallInstruction(@NotNull PsiExpression context, MethodType methodType, @Nullable PsiType resultType)
{
	myContext = context;
	myContracts = Collections.emptyList();
	myMethodType = methodType;
	myArgCount = 0;
	myType = resultType;
	myShouldFlushFields = false;
	myPrecalculatedReturnValue = null;
	myTargetMethod = null;
	myVarArgCall = false;
	myArgRequiredNullability = EMPTY_NULLNESS_ARRAY;
	myReturnNullability = Nullness.UNKNOWN;
}
 
開發者ID:consulo,項目名稱:consulo-java,代碼行數:14,代碼來源:MethodCallInstruction.java

示例6: getNickNamedNullability

private static Nullness getNickNamedNullability(@NotNull PsiClass psiClass)
{
	if(AnnotationUtil.findAnnotation(psiClass, TYPE_QUALIFIER_NICKNAME) == null)
	{
		return Nullness.UNKNOWN;
	}

	PsiAnnotation nonNull = AnnotationUtil.findAnnotation(psiClass, JAVAX_ANNOTATION_NONNULL);
	return nonNull != null ? extractNullityFromWhenValue(nonNull) : Nullness.UNKNOWN;
}
 
開發者ID:consulo,項目名稱:consulo-java,代碼行數:10,代碼來源:NullableNotNullManagerImpl.java

示例7: 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;
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:48,代碼來源:DfaVariableValue.java

示例8: 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;
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:52,代碼來源:SliceNullnessAnalyzer.java


注:本文中的com.intellij.codeInspection.dataFlow.Nullness.UNKNOWN屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。