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


Java Nullness類代碼示例

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


Nullness類屬於com.intellij.codeInspection.dataFlow包,在下文中一共展示了Nullness類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: createTypeValue

import com.intellij.codeInspection.dataFlow.Nullness; //導入依賴的package包/類
@NotNull
public DfaTypeValue createTypeValue(@NotNull DfaPsiType type, @NotNull Nullness nullness) {
  ArrayList<DfaTypeValue> conditions = myCache.get(type);
  if (conditions == null) {
    conditions = new ArrayList<DfaTypeValue>();
    myCache.put(type, conditions);
  } else {
    for (DfaTypeValue aType : conditions) {
      if (aType.myNullness == nullness) return aType;
    }
  }

  DfaTypeValue result = new DfaTypeValue(type, nullness, myFactory);
  conditions.add(result);
  return result;
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:17,代碼來源:DfaTypeValue.java

示例2: calcInherentNullability

import com.intellij.codeInspection.dataFlow.Nullness; //導入依賴的package包/類
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,代碼行數:25,代碼來源:DfaVariableValue.java

示例3: createTypeValue

import com.intellij.codeInspection.dataFlow.Nullness; //導入依賴的package包/類
@NotNull
DfaTypeValue createTypeValue(@NotNull DfaPsiType type, @NotNull Nullness nullness)
{
	ArrayList<DfaTypeValue> conditions = myCache.get(type);
	if(conditions == null)
	{
		conditions = new ArrayList<>();
		myCache.put(type, conditions);
	}
	else
	{
		for(DfaTypeValue aType : conditions)
		{
			if(aType.myNullness == nullness)
			{
				return aType;
			}
		}
	}

	DfaTypeValue result = new DfaTypeValue(type, nullness, myFactory);
	conditions.add(result);
	return result;
}
 
開發者ID:consulo,項目名稱:consulo-java,代碼行數:25,代碼來源:DfaTypeValue.java

示例4: calcArgRequiredNullability

import com.intellij.codeInspection.dataFlow.Nullness; //導入依賴的package包/類
private Nullness[] calcArgRequiredNullability(PsiSubstitutor substitutor, PsiParameter[] parameters)
{
	if(myArgCount == 0)
	{
		return EMPTY_NULLNESS_ARRAY;
	}

	int checkedCount = Math.min(myArgCount, parameters.length) - (myVarArgCall ? 1 : 0);

	Nullness[] nullness = new Nullness[myArgCount];
	for(int i = 0; i < checkedCount; i++)
	{
		nullness[i] = DfaPsiUtil.getElementNullability(substitutor.substitute(parameters[i].getType()), parameters[i]);
	}

	if(myVarArgCall)
	{
		PsiType lastParamType = substitutor.substitute(parameters[parameters.length - 1].getType());
		if(isEllipsisWithNotNullElements(lastParamType))
		{
			Arrays.fill(nullness, parameters.length - 1, myArgCount, Nullness.NOT_NULL);
		}
	}
	return nullness;
}
 
開發者ID:consulo,項目名稱:consulo-java,代碼行數:26,代碼來源:MethodCallInstruction.java

示例5: pushOptionalValue

import com.intellij.codeInspection.dataFlow.Nullness; //導入依賴的package包/類
private static boolean pushOptionalValue(CFGBuilder builder, PsiExpression expression, PsiExpression dereferenceContext, NullabilityProblem problem)
{
	PsiType optionalElementType = getOptionalElementType(expression);
	if(optionalElementType == null)
	{
		return false;
	}
	if(expression instanceof PsiMethodCallExpression)
	{
		PsiMethodCallExpression qualifierCall = (PsiMethodCallExpression) expression;
		if(OPTIONAL_EMPTY.test(qualifierCall))
		{
			builder.pushNull();
			return true;
		}
		if(pushIntermediateOperationValue(builder, qualifierCall))
		{
			builder.assignTo(builder.createTempVariable(optionalElementType));
			return true;
		}
	}
	DfaOptionalValue presentOptional = builder.getFactory().getOptionalFactory().getOptional(true);
	builder.pushExpression(expression).checkNotNull(dereferenceContext, problem).push(presentOptional).ifCondition(JavaTokenType.INSTANCEOF_KEYWORD).push(builder.getFactory().createTypeValue
			(optionalElementType, Nullness.NOT_NULL)).elseBranch().pushNull().endIf().assignTo(builder.createTempVariable(optionalElementType));
	return true;
}
 
開發者ID:consulo,項目名稱:consulo-java,代碼行數:27,代碼來源:OptionalChainInliner.java

示例6: invokeAndUnwrapOptional

import com.intellij.codeInspection.dataFlow.Nullness; //導入依賴的package包/類
private static void invokeAndUnwrapOptional(CFGBuilder builder, int argCount, PsiExpression function)
{
	PsiLambdaExpression lambda = ObjectUtils.tryCast(PsiUtil.skipParenthesizedExprDown(function), PsiLambdaExpression.class);
	if(lambda != null)
	{
		PsiParameter[] parameters = lambda.getParameterList().getParameters();
		PsiExpression lambdaBody = LambdaUtil.extractSingleExpressionFromBody(lambda.getBody());
		if(parameters.length == argCount && lambdaBody != null)
		{
			StreamEx.ofReversed(parameters).forEach(p -> builder.assignTo(p).pop());
			if(pushOptionalValue(builder, lambdaBody, lambdaBody, NullabilityProblem.nullableFunctionReturn))
			{
				return;
			}
			// Restore stack for common invokeFunction
			StreamEx.of(parameters).forEach(p -> builder.push(builder.getFactory().getVarFactory().createVariableValue(p, false)));
		}
	}
	builder.evaluateFunction(function).invokeFunction(argCount, function, Nullness.NOT_NULL).pop().pushUnknown();
}
 
開發者ID:consulo,項目名稱:consulo-java,代碼行數:21,代碼來源:OptionalChainInliner.java

示例7: tryInlineCall

import com.intellij.codeInspection.dataFlow.Nullness; //導入依賴的package包/類
@Override
public boolean tryInlineCall(@NotNull CFGBuilder builder, @NotNull PsiMethodCallExpression call)
{
	FactoryInfo factoryInfo = STATIC_FACTORIES.mapFirst(call);
	if(factoryInfo == null)
	{
		return false;
	}
	PsiExpression[] args = call.getArgumentList().getExpressions();
	for(PsiExpression arg : args)
	{
		builder.pushExpression(arg).pop();
	}
	PsiVariable variable = builder.createTempVariable(call.getType());
	DfaValueFactory factory = builder.getFactory();
	DfaVariableValue variableValue = factory.getVarFactory().createVariableValue(variable, false);
	builder.pushVariable(variable) // tmpVar = <Value of collection type>
			.push(factory.createTypeValue(call.getType(), Nullness.NOT_NULL)).assign() // leave tmpVar on stack: it's result of method call
			.push(factoryInfo.mySizeField.createValue(factory, variableValue)) // tmpVar.size = <size>
			.push(factory.getConstFactory().createFromValue(factoryInfo.mySize, PsiType.INT, null)).assign().pop();
	return true;
}
 
開發者ID:consulo,項目名稱:consulo-java,代碼行數:23,代碼來源:CollectionFactoryInliner.java

示例8: isNotNullNotInferred

import com.intellij.codeInspection.dataFlow.Nullness; //導入依賴的package包/類
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;
}
 
開發者ID:consulo,項目名稱:consulo-java,代碼行數:25,代碼來源:NullableStuffInspectionBase.java

示例9: isNullableNotInferred

import com.intellij.codeInspection.dataFlow.Nullness; //導入依賴的package包/類
public static boolean isNullableNotInferred(@NotNull PsiModifierListOwner owner, boolean checkBases)
{
	Project project = owner.getProject();
	NullableNotNullManager manager = NullableNotNullManager.getInstance(project);
	if(!manager.isNullable(owner, checkBases))
	{
		return false;
	}
	if(DfaPsiUtil.getTypeNullability(getMemberType(owner)) == Nullness.NULLABLE)
	{
		return true;
	}

	PsiAnnotation anno = manager.getNullableAnnotation(owner, checkBases);
	return !(anno != null && AnnotationUtil.isInferredAnnotation(anno));
}
 
開發者ID:consulo,項目名稱:consulo-java,代碼行數:17,代碼來源:NullableStuffInspectionBase.java

示例10: getModifiedExpression

import com.intellij.codeInspection.dataFlow.Nullness; //導入依賴的package包/類
@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);
}
 
開發者ID:consulo,項目名稱:consulo-java,代碼行數:23,代碼來源:WrapObjectWithOptionalOfNullableFix.java

示例11: getInferredNullityAnnotation

import com.intellij.codeInspection.dataFlow.Nullness; //導入依賴的package包/類
@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;
}
 
開發者ID:consulo,項目名稱:consulo-java,代碼行數:26,代碼來源:InferredAnnotationsManagerImpl.java

示例12: getAllNullabilityNickNames

import com.intellij.codeInspection.dataFlow.Nullness; //導入依賴的package包/類
private List<PsiClass> getAllNullabilityNickNames()
{
	if(!getNotNulls().contains(JAVAX_ANNOTATION_NONNULL))
	{
		return Collections.emptyList();
	}
	return CachedValuesManager.getManager(myProject).getCachedValue(myProject, () ->
	{
		List<PsiClass> result = new ArrayList<>();
		GlobalSearchScope scope = GlobalSearchScope.allScope(myProject);
		for(PsiClass tqNick : JavaPsiFacade.getInstance(myProject).findClasses(TYPE_QUALIFIER_NICKNAME, scope))
		{
			result.addAll(ContainerUtil.findAll(MetaAnnotationUtil.getChildren(tqNick, scope), candidate ->
			{
				String qname = candidate.getQualifiedName();
				if(qname == null || qname.startsWith("javax.annotation."))
				{
					return false;
				}
				return getNickNamedNullability(candidate) != Nullness.UNKNOWN;
			}));
		}
		return CachedValueProvider.Result.create(result, PsiModificationTracker.MODIFICATION_COUNT);
	});
}
 
開發者ID:consulo,項目名稱:consulo-java,代碼行數:26,代碼來源:NullableNotNullManagerImpl.java

示例13: extractNullityFromWhenValue

import com.intellij.codeInspection.dataFlow.Nullness; //導入依賴的package包/類
@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,代碼行數:19,代碼來源:NullableNotNullManagerImpl.java

示例14: initNullness

import com.intellij.codeInspection.dataFlow.Nullness; //導入依賴的package包/類
private Nullness initNullness()
{
	if(!PsiUtil.isLanguageLevel5OrHigher(myElements[0]) || PsiUtil.resolveClassInType(myReturnType) == null)
	{
		return null;
	}
	final NullableNotNullManager manager = NullableNotNullManager.getInstance(myProject);
	final PsiClass nullableAnnotationClass = JavaPsiFacade.getInstance(myProject).findClass(manager.getDefaultNullable(), myElements[0].getResolveScope());
	if(nullableAnnotationClass != null)
	{
		final PsiElement elementInCopy = myTargetClass.getContainingFile().copy().findElementAt(myTargetClass.getTextOffset());
		final PsiClass classCopy = PsiTreeUtil.getParentOfType(elementInCopy, PsiClass.class);
		if(classCopy == null)
		{
			return null;
		}
		final PsiMethod emptyMethod = (PsiMethod) classCopy.addAfter(generateEmptyMethod("name"), classCopy.getLBrace());
		prepareMethodBody(emptyMethod, false);
		if(myNotNullConditionalCheck || myNullConditionalCheck)
		{
			return Nullness.NULLABLE;
		}
		return DfaUtil.inferMethodNullity(emptyMethod);
	}
	return null;
}
 
開發者ID:consulo,項目名稱:consulo-java,代碼行數:27,代碼來源:ExtractMethodProcessor.java

示例15: createLiteralValue

import com.intellij.codeInspection.dataFlow.Nullness; //導入依賴的package包/類
@Nullable
public DfaValue createLiteralValue(PsiLiteralExpression literal) {
  if (literal.getValue() instanceof String) {
    return createTypeValue(literal.getType(), Nullness.NOT_NULL); // Non-null string literal.
  }
  return getConstFactory().create(literal);
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:8,代碼來源:DfaValueFactory.java


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