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


Java Nullness.NULLABLE屬性代碼示例

本文整理匯總了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;
}
 
開發者ID:lshain-android-source,項目名稱:tools-idea,代碼行數:24,代碼來源:DfaVariableValue.java

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

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

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

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

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

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

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

示例9: isNullable

public boolean isNullable() {
  return myNullness == Nullness.NULLABLE;
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:3,代碼來源:DfaTypeValue.java

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

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

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

示例13: isNullable

public boolean isNullable()
{
	return myNullness == Nullness.NULLABLE;
}
 
開發者ID:consulo,項目名稱:consulo-java,代碼行數:4,代碼來源:DfaTypeValue.java

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


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