当前位置: 首页>>代码示例>>Java>>正文


Java NullableNotNullManager.isNullable方法代码示例

本文整理汇总了Java中com.intellij.codeInsight.NullableNotNullManager.isNullable方法的典型用法代码示例。如果您正苦于以下问题:Java NullableNotNullManager.isNullable方法的具体用法?Java NullableNotNullManager.isNullable怎么用?Java NullableNotNullManager.isNullable使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.intellij.codeInsight.NullableNotNullManager的用法示例。


在下文中一共展示了NullableNotNullManager.isNullable方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: isAnnotatedNullable

import com.intellij.codeInsight.NullableNotNullManager; //导入方法依赖的package包/类
public static boolean isAnnotatedNullable(PsiElement element) {
    PsiExpression expression;
    if (element instanceof PsiExpression) {
        expression = (PsiExpression) element;
    } else {
        expression = PsiTreeUtil.getParentOfType(element, PsiExpression.class, true);
        if (expression == null) {
            return false;
        }
    }
    expression = ParenthesesUtils.stripParentheses(expression);
    if (!(expression instanceof PsiReferenceExpression)) {
        return false;
    }
    final PsiReferenceExpression referenceExpression = (PsiReferenceExpression) expression;
    final PsiElement target = referenceExpression.resolve();
    if (!(target instanceof PsiModifierListOwner)) {
        return false;
    }
    final PsiModifierListOwner modifierListOwner = (PsiModifierListOwner) target;
    return NullableNotNullManager.isNullable(modifierListOwner);
}
 
开发者ID:cesards,项目名称:HakunaMatataIntelliJPlugin,代码行数:23,代码来源:AndroidPostfixUtil.java

示例2: isReferenceToNullableVariable

import com.intellij.codeInsight.NullableNotNullManager; //导入方法依赖的package包/类
private boolean isReferenceToNullableVariable(
  PsiExpression lhs) {
  if (!(lhs instanceof PsiReferenceExpression)) {
    return false;
  }
  final PsiReferenceExpression referenceExpression =
    (PsiReferenceExpression)lhs;
  final PsiElement element = referenceExpression.resolve();
  if (!(element instanceof PsiVariable)) {
    return false;
  }
  final PsiVariable variable = (PsiVariable)element;
  if (ignoreAssignmentsToFields && variable instanceof PsiField) {
    return true;
  }
  return NullableNotNullManager.isNullable(variable);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:18,代码来源:AssignmentToNullInspection.java

示例3: createInitialStates

import com.intellij.codeInsight.NullableNotNullManager; //导入方法依赖的package包/类
@Override
protected Collection<DfaMemoryState> createInitialStates(@NotNull PsiElement psiBlock, InstructionVisitor visitor) {
  final Collection<DfaMemoryState> initialStates = super.createInitialStates(psiBlock, visitor);

  myIsInMethod = psiBlock.getParent() instanceof PsiMethod;
  if (myIsInMethod) {
    PsiMethod method = (PsiMethod)psiBlock.getParent();
    PsiType returnType = method.getReturnType();
    myInNullableMethod = NullableNotNullManager.isNullable(method) ||
                         returnType != null && returnType.equalsToText(CommonClassNames.JAVA_LANG_VOID);
    myInNotNullMethod = NullableNotNullManager.isNotNull(method);
  }

  myNPEInstructions.clear();
  myCCEInstructions.clear();
  myNullableArguments.clear();
  myNullableArgumentsPassedToNonAnnotatedParam.clear();
  myNullableAssignments.clear();
  myNullableReturns.clear();
  myUnboxedNullables.clear();

  return initialStates;
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:24,代码来源:StandardDataFlowRunner.java

示例4: isNullableNotInferred

import com.intellij.codeInsight.NullableNotNullManager; //导入方法依赖的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

示例5: isAnnotated

import com.intellij.codeInsight.NullableNotNullManager; //导入方法依赖的package包/类
private static boolean isAnnotated(PsiExpression expression, boolean nullable)
{
	expression = ParenthesesUtils.stripParentheses(expression);
	if(!(expression instanceof PsiReferenceExpression))
	{
		return false;
	}
	final PsiReferenceExpression referenceExpression = (PsiReferenceExpression) expression;
	final PsiElement target = referenceExpression.resolve();
	if(!(target instanceof PsiModifierListOwner))
	{
		return false;
	}
	final PsiModifierListOwner modifierListOwner = (PsiModifierListOwner) target;
	return nullable ? NullableNotNullManager.isNullable(modifierListOwner) : NullableNotNullManager.isNotNull(modifierListOwner);
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:17,代码来源:ExpressionUtils.java

示例6: getElementNullability

import com.intellij.codeInsight.NullableNotNullManager; //导入方法依赖的package包/类
@NotNull
public static Nullness getElementNullability(@Nullable PsiType resultType, @Nullable PsiModifierListOwner owner) {
  if (owner == null) {
    return Nullness.UNKNOWN;
  }

  if (owner instanceof PsiEnumConstant) {
    return Nullness.NOT_NULL;
  }

  if (resultType != null) {
    NullableNotNullManager nnn = NullableNotNullManager.getInstance(owner.getProject());
    for (PsiAnnotation annotation : resultType.getAnnotations()) {
      if (!annotation.isValid()) {
        PsiUtilCore.ensureValid(owner);
        PsiUtil.ensureValidType(resultType, owner + " of " + owner.getClass());
        PsiUtilCore.ensureValid(annotation); //should fail
      }
      String qualifiedName = annotation.getQualifiedName();
      if (nnn.getNullables().contains(qualifiedName)) {
        return Nullness.NULLABLE;
      }
      if (nnn.getNotNulls().contains(qualifiedName)) {
        return Nullness.NOT_NULL;
      }
    }
  }

  if (NullableNotNullManager.isNullable(owner)) {
    return Nullness.NULLABLE;
  }
  if (NullableNotNullManager.isNotNull(owner)) {
    return Nullness.NOT_NULL;
  }

  return Nullness.UNKNOWN;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:38,代码来源:DfaPsiUtil.java

示例7: isNullableNotInferred

import com.intellij.codeInsight.NullableNotNullManager; //导入方法依赖的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;

  PsiAnnotation anno = manager.getNullableAnnotation(owner, checkBases);
  return !(anno != null && AnnotationUtil.isInferredAnnotation(anno));
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:9,代码来源:NullableStuffInspectionBase.java

示例8: isNullable

import com.intellij.codeInsight.NullableNotNullManager; //导入方法依赖的package包/类
private boolean isNullable(PsiModifierListOwner owner) {
  if (NullableNotNullManager.isNullable(owner)) {
    return true;
  }
  final SmartPsiElementPointer<PsiModifierListOwner> pointer = myPointerManager.createSmartPsiElementPointer(owner);
  return myNullableSet.contains(pointer);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:8,代码来源:NullityInferrer.java

示例9: createField

import com.intellij.codeInsight.NullableNotNullManager; //导入方法依赖的package包/类
private PsiField createField(PsiParameter parameter, PsiMethod constructor, boolean isFinal) {
  final String parameterName = parameter.getName();
  PsiType type = parameter.getType();
  if (type instanceof PsiEllipsisType) type = ((PsiEllipsisType)type).toArrayType();
  try {
    final JavaCodeStyleManager styleManager = JavaCodeStyleManager.getInstance(getMethod().getProject());
    final String fieldName = styleManager.suggestVariableName(VariableKind.FIELD, styleManager.variableNameToPropertyName(parameterName, VariableKind.PARAMETER), null, type).names[0];
    PsiField field = myElementFactory.createField(fieldName, type);

    final PsiModifierList modifierList = field.getModifierList();
    LOG.assertTrue(modifierList != null);
    final NullableNotNullManager manager = NullableNotNullManager.getInstance(myProject);
    if (manager.isNullable(parameter, false)) {
      modifierList.addAfter(myElementFactory.createAnnotationFromText("@" + manager.getDefaultNullable(), field), null);
    }
    modifierList.setModifierProperty(PsiModifier.FINAL, isFinal);

    final PsiCodeBlock methodBody = constructor.getBody();

    LOG.assertTrue(methodBody != null);

    @NonNls final  String stmtText;
    if (Comparing.strEqual(parameterName, fieldName)) {
      stmtText = "this." + fieldName + " = " + parameterName + ";";
    } else {
      stmtText = fieldName + " = " + parameterName + ";";
    }
    PsiStatement assignmentStmt = myElementFactory.createStatementFromText(stmtText, methodBody);
    assignmentStmt = (PsiStatement)CodeStyleManager.getInstance(constructor.getProject()).reformat(assignmentStmt);
    methodBody.add(assignmentStmt);

    field = (PsiField)myInnerClass.add(field);
    return field;
  }
  catch (IncorrectOperationException e) {
    LOG.error(e);
  }
  return null;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:40,代码来源:ExtractMethodObjectProcessor.java

示例10: isAnnotated

import com.intellij.codeInsight.NullableNotNullManager; //导入方法依赖的package包/类
private static boolean isAnnotated(PsiExpression expression, boolean nullable) {
  expression = ParenthesesUtils.stripParentheses(expression);
  if (!(expression instanceof PsiReferenceExpression)) {
    return false;
  }
  final PsiReferenceExpression referenceExpression = (PsiReferenceExpression)expression;
  final PsiElement target = referenceExpression.resolve();
  if (!(target instanceof PsiModifierListOwner)) {
    return false;
  }
  final PsiModifierListOwner modifierListOwner = (PsiModifierListOwner)target;
  return nullable ?
         NullableNotNullManager.isNullable(modifierListOwner):
         NullableNotNullManager.isNotNull(modifierListOwner);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:16,代码来源:ExpressionUtils.java

示例11: getElementNullability

import com.intellij.codeInsight.NullableNotNullManager; //导入方法依赖的package包/类
@NotNull
public static Nullness getElementNullability(@Nullable PsiType resultType, @Nullable PsiModifierListOwner owner) {
  if (owner == null) {
    return Nullness.UNKNOWN;
  }

  if (NullableNotNullManager.isNullable(owner)) {
    return Nullness.NULLABLE;
  }
  if (NullableNotNullManager.isNotNull(owner)) {
    return Nullness.NOT_NULL;
  }

  if (resultType != null) {
    NullableNotNullManager nnn = NullableNotNullManager.getInstance(owner.getProject());
    for (PsiAnnotation annotation : resultType.getAnnotations()) {
      String qualifiedName = annotation.getQualifiedName();
      if (nnn.getNullables().contains(qualifiedName)) {
        return Nullness.NULLABLE;
      }
      if (nnn.getNotNulls().contains(qualifiedName)) {
        return Nullness.NOT_NULL;
      }
    }
  }

  return Nullness.UNKNOWN;
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:29,代码来源:DfaPsiUtil.java

示例12: isNullableInitialized

import com.intellij.codeInsight.NullableNotNullManager; //导入方法依赖的package包/类
public static boolean isNullableInitialized(PsiVariable var, boolean nullable) {
  if (!isFinalField(var)) {
    return false;
  }

  List<PsiExpression> initializers = findAllConstructorInitializers((PsiField)var);
  if (initializers.isEmpty()) {
    return false;
  }

  for (PsiExpression expression : initializers) {
    if (!(expression instanceof PsiReferenceExpression)) {
      return false;
    }
    PsiElement target = ((PsiReferenceExpression)expression).resolve();
    if (!(target instanceof PsiParameter)) {
      return false;
    }
    if (nullable && NullableNotNullManager.isNullable((PsiParameter)target)) {
      return true;
    }
    if (!nullable && !NullableNotNullManager.isNotNull((PsiParameter)target)) {
      return false;
    }
  }
  return !nullable;
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:28,代码来源:DfaPsiUtil.java

示例13: checkMethodParameters

import com.intellij.codeInsight.NullableNotNullManager; //导入方法依赖的package包/类
@NotNull
static PsiParameter[] checkMethodParameters(PsiMethod method)
{
	if(method.getBody() == null)
	{
		return PsiParameter.EMPTY_ARRAY;
	}

	final Collection<PsiParameter> nullableParameters = new SmartList<>();
	final PsiParameter[] parameters = method.getParameterList().getParameters();
	for(int index = 0; index < parameters.length; index++)
	{
		PsiParameter parameter = parameters[index];
		if(!(parameter.getType() instanceof PsiPrimitiveType) && !NullableNotNullManager.isNotNull(parameter) && !NullableNotNullManager.isNullable(parameter) && JavaNullMethodArgumentUtil
				.hasNullArgument(method, index))
		{
			nullableParameters.add(parameter);
		}
	}
	if(nullableParameters.isEmpty())
	{
		return PsiParameter.EMPTY_ARRAY;
	}

	final NullParameterConstraintChecker checker = new NullParameterConstraintChecker(nullableParameters);
	checker.analyzeMethod(method.getBody(), new StandardInstructionVisitor());

	return checker.myPossiblyViolatedParameters.stream().filter(checker.myUsedParameters::contains).toArray(PsiParameter[]::new);
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:30,代码来源:NullParameterConstraintChecker.java

示例14: isNullable

import com.intellij.codeInsight.NullableNotNullManager; //导入方法依赖的package包/类
private boolean isNullable(PsiModifierListOwner owner)
{
	if(NullableNotNullManager.isNullable(owner))
	{
		return true;
	}
	final SmartPsiElementPointer<PsiModifierListOwner> pointer = myPointerManager.createSmartPsiElementPointer(owner);
	return myNullableSet.contains(pointer);
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:10,代码来源:NullityInferrer.java

示例15: hasAnnotation

import com.intellij.codeInsight.NullableNotNullManager; //导入方法依赖的package包/类
private boolean hasAnnotation(PsiModifierListOwner psiModifierListOwner) {
    return NullableNotNullManager.isNullable(psiModifierListOwner)
            || NullableNotNullManager.isNotNull(psiModifierListOwner);
}
 
开发者ID:stylismo,项目名称:nullability-annotations-inspection,代码行数:5,代码来源:NullabilityAnnotationsInspection.java


注:本文中的com.intellij.codeInsight.NullableNotNullManager.isNullable方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。