本文整理匯總了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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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();
}
示例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;
}
示例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;
}
示例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));
}
示例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);
}
示例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;
}
示例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);
});
}
示例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;
}
示例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;
}
示例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);
}