本文整理匯總了Java中com.intellij.codeInspection.dataFlow.Nullness.NULLABLE屬性的典型用法代碼示例。如果您正苦於以下問題:Java Nullness.NULLABLE屬性的具體用法?Java Nullness.NULLABLE怎麽用?Java Nullness.NULLABLE使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類com.intellij.codeInspection.dataFlow.Nullness
的用法示例。
在下文中一共展示了Nullness.NULLABLE屬性的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: isNullableNotInferred
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));
}
示例3: 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;
}
示例4: 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;
}
示例5: initNullness
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;
}
示例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: 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;
}
示例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: isNullable
public boolean isNullable() {
return myNullness == Nullness.NULLABLE;
}
示例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: createReturnTypePanel
@Nullable
private JPanel createReturnTypePanel() {
if (TypeConversionUtil.isPrimitiveWrapper(myReturnType) && myNullness == Nullness.NULLABLE) {
return null;
}
final TypeSelectorManagerImpl manager = new TypeSelectorManagerImpl(myProject, myReturnType, findOccurrences(), areTypesDirected()) {
@Override
public PsiType[] getTypesForAll(boolean direct) {
final PsiType[] types = super.getTypesForAll(direct);
return !isVoidReturn() ? types : ArrayUtil.prepend(PsiType.VOID, types);
}
};
mySelector = manager.getTypeSelector();
final JComponent component = mySelector.getComponent();
if (component instanceof JComboBox) {
if (isVoidReturn()) {
mySelector.selectType(PsiType.VOID);
}
final JPanel returnTypePanel = new JPanel(new BorderLayout(2, 0));
final JLabel label = new JLabel(RefactoringBundle.message("changeSignature.return.type.prompt"));
returnTypePanel.add(label, BorderLayout.NORTH);
returnTypePanel.add(component, BorderLayout.SOUTH);
DialogUtil.registerMnemonic(label, component);
((JComboBox)component).addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (myGenerateAnnotations != null) {
final PsiType selectedType = mySelector.getSelectedType();
final boolean enabled = PsiUtil.resolveClassInType(selectedType) != null;
if (!enabled) {
myGenerateAnnotations.setSelected(false);
}
myGenerateAnnotations.setEnabled(enabled);
}
updateSignature();
}
});
return returnTypePanel;
}
return null;
}
示例13: isNullable
public boolean isNullable()
{
return myNullness == Nullness.NULLABLE;
}
示例14: createReturnTypePanel
@Nullable
private JPanel createReturnTypePanel()
{
if(TypeConversionUtil.isPrimitiveWrapper(myReturnType) && myNullness == Nullness.NULLABLE)
{
return null;
}
final TypeSelectorManagerImpl manager = new TypeSelectorManagerImpl(myProject, myReturnType, findOccurrences(), areTypesDirected())
{
@Override
public PsiType[] getTypesForAll(boolean direct)
{
final PsiType[] types = super.getTypesForAll(direct);
return !isVoidReturn() ? types : ArrayUtil.prepend(PsiType.VOID, types);
}
};
mySelector = manager.getTypeSelector();
final JComponent component = mySelector.getComponent();
if(component instanceof JComboBox)
{
if(isVoidReturn())
{
mySelector.selectType(PsiType.VOID);
}
final JPanel returnTypePanel = new JPanel(new BorderLayout(2, 0));
final JLabel label = new JLabel(RefactoringBundle.message("changeSignature.return.type.prompt"));
returnTypePanel.add(label, BorderLayout.NORTH);
returnTypePanel.add(component, BorderLayout.SOUTH);
DialogUtil.registerMnemonic(label, component);
((JComboBox) component).addActionListener(new ActionListener()
{
@Override
public void actionPerformed(ActionEvent e)
{
if(myGenerateAnnotations != null)
{
final PsiType selectedType = mySelector.getSelectedType();
final boolean enabled = PsiUtil.resolveClassInType(selectedType) != null;
if(!enabled)
{
myGenerateAnnotations.setSelected(false);
}
myGenerateAnnotations.setEnabled(enabled);
}
updateSignature();
}
});
return returnTypePanel;
}
return null;
}