• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java NullableNotNullManager类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: findAnnotations

import com.intellij.codeInsight.NullableNotNullManager; //导入依赖的package包/类
static List<String> findAnnotations(PsiModifierListOwner element, boolean nullable) {
    if (overridesSuper(element)) {
        return Collections.emptyList();
    }

    List<String> annotations = new ArrayList<>();
    Project project = element.getProject();
    PsiModifierList modifierList = element.getModifierList();
    List<String> nullabilityAnnotations = nullable
            ? NullableNotNullManager.getInstance(project).getNullables()
            : NullableNotNullManager.getInstance(project).getNotNulls();
    for (String notNullAnnotationFqn : nullabilityAnnotations) {
        PsiElementFactory factory = JavaPsiFacade.getElementFactory(project);
        PsiAnnotation annotation = factory.createAnnotationFromText("@" + notNullAnnotationFqn, null);
        PsiAnnotation.TargetType[] targetTypes = getTargetsForLocation(modifierList);
        if (isNullabilityAnnotationForTypeQualifierDefault(annotation, nullable, targetTypes)) {
            annotations.add(annotation.getQualifiedName());
        }
    }
    return annotations;
}
 
开发者ID:stylismo,项目名称:nullability-annotations-inspection,代码行数:22,代码来源:NullabilityAnnotationsWithTypeQualifierDefault.java


示例2: 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


示例3: withConstraint

import com.intellij.codeInsight.NullableNotNullManager; //导入依赖的package包/类
@Nullable
private ValueConstraint[] withConstraint(ValueConstraint[] constraints, int index, ValueConstraint constraint) {
  if (constraints[index] == constraint) return constraints;

  ValueConstraint negated = negateConstraint(constraint);
  if (negated != constraint && constraints[index] == negated) {
    return null;
  }

  if (constraint == NULL_VALUE && NullableNotNullManager.isNotNull(getParameter(index))) {
    return null;
  }

  ValueConstraint[] copy = constraints.clone();
  copy[index] = constraint;
  return copy;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:18,代码来源:ContractInference.java


示例4: checkNonStandardAnnotations

import com.intellij.codeInsight.NullableNotNullManager; //导入依赖的package包/类
private static boolean checkNonStandardAnnotations(PsiField field,
                                                   Annotated annotated,
                                                   NullableNotNullManager manager, String anno, @NotNull ProblemsHolder holder) {
  if (!AnnotationUtil.isAnnotatingApplicable(field, anno)) {
    final PsiAnnotation notNull = AnnotationUtil.findAnnotation(field, manager.getNotNulls());
    final PsiAnnotation nullable = AnnotationUtil.findAnnotation(field, manager.getNullables());
    final PsiAnnotation annotation;
    String message = "Not \'";
    if (annotated.isDeclaredNullable) {
      message += nullable.getQualifiedName();
      annotation = nullable;
    } else {
      message += notNull.getQualifiedName();
      annotation = notNull;
    }
    message += "\' but \'" + anno + "\' would be used for code generation.";
    final PsiJavaCodeReferenceElement annotationNameReferenceElement = annotation.getNameReferenceElement();
    holder.registerProblem(annotationNameReferenceElement != null && annotationNameReferenceElement.isPhysical() ? annotationNameReferenceElement : field.getNameIdentifier(),
                           message,
                           ProblemHighlightType.WEAK_WARNING,
                           new ChangeNullableDefaultsFix(notNull, nullable, manager));
    return false;
  }
  return true;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:26,代码来源:NullableStuffInspectionBase.java


示例5: checkNullableStuffForMethod

import com.intellij.codeInsight.NullableNotNullManager; //导入依赖的package包/类
private void checkNullableStuffForMethod(PsiMethod method, final ProblemsHolder holder) {
  Annotated annotated = check(method, holder, method.getReturnType());

  List<PsiMethod> superMethods = ContainerUtil.map(
    method.findSuperMethodSignaturesIncludingStatic(true), new Function<MethodSignatureBackedByPsiMethod, PsiMethod>() {
      @Override
      public PsiMethod fun(MethodSignatureBackedByPsiMethod signature) {
        return signature.getMethod();
      }
    });

  final NullableNotNullManager nullableManager = NullableNotNullManager.getInstance(holder.getProject());

  checkSupers(method, holder, annotated, superMethods, nullableManager);
  checkParameters(method, holder, superMethods, nullableManager);
  checkOverriders(method, holder, annotated, nullableManager);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:18,代码来源:NullableStuffInspectionBase.java


示例6: initNullness

import com.intellij.codeInsight.NullableNotNullManager; //导入依赖的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:jskierbi,项目名称:intellij-ce-playground,代码行数:21,代码来源:ExtractMethodProcessor.java


示例7: testOverrideCustomDefault

import com.intellij.codeInsight.NullableNotNullManager; //导入依赖的package包/类
public void testOverrideCustomDefault() {
  DataFlowInspectionTest.addJavaxNullabilityAnnotations(myFixture);
  myFixture.addClass("package custom;" +
                     "public @interface CheckForNull {}");

  final NullableNotNullManager nnnManager = NullableNotNullManager.getInstance(getProject());
  nnnManager.setNullables("custom.CheckForNull");
  Disposer.register(myTestRootDisposable, new Disposable() {
    @Override
    public void dispose() {
      nnnManager.setNullables();
    }
  });

  myFixture.addClass("package foo;" +
                     "import static java.lang.annotation.ElementType.*;" +
                     "@javax.annotation.meta.TypeQualifierDefault(METHOD) " +
                     "@javax.annotation.Nonnull " +
                     "public @interface ReturnValuesAreNonnullByDefault {}");

  myFixture.addFileToProject("foo/package-info.java", "@ReturnValuesAreNonnullByDefault package foo;");

  myFixture.configureFromExistingVirtualFile(myFixture.copyFileToProject(getTestName(false) + ".java", "foo/Classes.java"));
  myFixture.enableInspections(myInspection);
  myFixture.checkHighlighting(true, false, true);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:27,代码来源:NullableStuffInspectionTest.java


示例8: 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


示例9: buildFix

import com.intellij.codeInsight.NullableNotNullManager; //导入依赖的package包/类
@Override
@Nullable
protected InspectionGadgetsFix buildFix(Object... infos) {
  final PsiElement elt = (PsiElement)infos[0];
  if (!AnnotationUtil.isAnnotatingApplicable(elt)) {
    return null;
  }

  if (PsiTreeUtil.getParentOfType(elt, PsiMethod.class, PsiLambdaExpression.class) instanceof PsiLambdaExpression) {
    return null;
  }

  final NullableNotNullManager manager = NullableNotNullManager.getInstance(elt.getProject());
  return new DelegatingFix(new AnnotateMethodFix(
    manager.getDefaultNullable(),
    ArrayUtil.toStringArray(manager.getNotNulls())){
    @Override
    public int shouldAnnotateBaseMethod(PsiMethod method, PsiMethod superMethod, Project project) {
      return ReturnNullInspectionBase.this.shouldAnnotateBaseMethod(method, superMethod);
    }
  });
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:23,代码来源:ReturnNullInspectionBase.java


示例10: annotateWithNullableStuff

import com.intellij.codeInsight.NullableNotNullManager; //导入依赖的package包/类
private static void annotateWithNullableStuff(final PsiModifierListOwner field, final PsiModifierListOwner listOwner)
  throws IncorrectOperationException {
  final NullableNotNullManager manager = NullableNotNullManager.getInstance(field.getProject());
  final PsiAnnotation notNull = manager.copyNotNullAnnotation(field);
  if (notNull != null) {
    annotate(listOwner, notNull);
  }
  else {
    final PsiAnnotation nullable = manager.copyNullableAnnotation(field);
    if (nullable != null) {
      annotate(listOwner, nullable);
    }
  }

  final PsiModifierList modifierList = listOwner.getModifierList();
  if (modifierList.hasExplicitModifier(GrModifier.DEF)) {
    LOG.assertTrue(modifierList instanceof GrModifierList);
    if (modifierList.getAnnotations().length > 0 || ((GrModifierList)modifierList).getModifiers().length > 1) {
      ((GrModifierList)modifierList).setModifierProperty(GrModifier.DEF, false);
    }
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:23,代码来源:GroovyPropertyUtils.java


示例11: 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


示例12: 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);
  if (initialStates == null) {
    return null;
  }

  final PsiElement parent = psiBlock.getParent();
  if (parent instanceof PsiMethod) {
    PsiMethod method = (PsiMethod)parent;

    //todo move out from generic runner
    for (PsiParameter parameter : method.getParameterList().getParameters()) {
      if (NullableNotNullManager.isNotNull(parameter)) {
        final DfaVariableValue value = getFactory().getVarFactory().createVariableValue(parameter, false);
        for (final DfaMemoryState initialState : initialStates) {
          initialState.applyNotNull(value);
        }
      }
    }
  }
  return initialStates;
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:24,代码来源:AnnotationsAwareDataFlowRunner.java


示例13: buildFix

import com.intellij.codeInsight.NullableNotNullManager; //导入依赖的package包/类
@Override
@Nullable
protected InspectionGadgetsFix buildFix(Object... infos) {
  final PsiElement elt = (PsiElement)infos[0];
  if (!AnnotationUtil.isAnnotatingApplicable(elt)) {
    return null;
  }
  final NullableNotNullManager manager =
    NullableNotNullManager.getInstance(elt.getProject());
  return new DelegatingFix(new AnnotateMethodFix(
    manager.getDefaultNullable(),
    ArrayUtil.toStringArray(manager.getNotNulls())){
    @Override
    public int shouldAnnotateBaseMethod(PsiMethod method, PsiMethod superMethod, Project project) {
      return ReturnNullInspectionBase.this.shouldAnnotateBaseMethod(method, superMethod);
    }
  });
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:19,代码来源:ReturnNullInspectionBase.java


示例14: annotateWithNullableStuff

import com.intellij.codeInsight.NullableNotNullManager; //导入依赖的package包/类
private static void annotateWithNullableStuff(final PsiModifierListOwner field, final PsiModifierListOwner listOwner)
  throws IncorrectOperationException {
  final NullableNotNullManager manager = NullableNotNullManager.getInstance(field.getProject());
  final String notNull = manager.getNotNull(field);
  if (notNull != null) {
    annotate(listOwner, notNull);
  }
  else {
    final String nullable = manager.getNullable(field);
    if (nullable != null) {
      annotate(listOwner, nullable);
    }
  }

  final PsiModifierList modifierList = listOwner.getModifierList();
  if (modifierList.hasExplicitModifier(GrModifier.DEF)) {
    LOG.assertTrue(modifierList instanceof GrModifierList);
    if (modifierList.getAnnotations().length > 0 || ((GrModifierList)modifierList).getModifiers().length > 1) {
      ((GrModifierList)modifierList).setModifierProperty(GrModifier.DEF, false);
    }
  }
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:23,代码来源:GroovyPropertyUtils.java


示例15: toContracts

import com.intellij.codeInsight.NullableNotNullManager; //导入依赖的package包/类
@NotNull
@Override
public List<StandardMethodContract> toContracts(PsiMethod method, Supplier<PsiCodeBlock> body)
{
	PsiExpression expression = call.restoreExpression(body.get());
	if(!(expression instanceof PsiMethodCallExpression))
	{
		return Collections.emptyList();
	}
	PsiMethod target = ((PsiMethodCallExpression) expression).resolveMethod();
	if(target != null && NullableNotNullManager.isNotNull(target))
	{
		return ContractInferenceInterpreter.toContracts(ContainerUtil.map(states, it -> it.toArray(new MethodContract.ValueConstraint[it.size()])), MethodContract.ValueConstraint.NOT_NULL_VALUE);
	}
	return Collections.emptyList();
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:17,代码来源:MethodCallContract.java


示例16: getTypeOwnNullability

import com.intellij.codeInsight.NullableNotNullManager; //导入依赖的package包/类
@NotNull
private static Nullness getTypeOwnNullability(Ref<Nullness> result, PsiType eachType)
{
	for(PsiAnnotation annotation : eachType.getAnnotations())
	{
		String qualifiedName = annotation.getQualifiedName();
		NullableNotNullManager nnn = NullableNotNullManager.getInstance(annotation.getProject());
		if(nnn.getNullables().contains(qualifiedName))
		{
			return Nullness.NULLABLE;
		}
		if(nnn.getNotNulls().contains(qualifiedName))
		{
			return Nullness.NOT_NULL;
		}
	}
	return Nullness.UNKNOWN;
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:19,代码来源:DfaPsiUtil.java


示例17: isNotNullLocally

import com.intellij.codeInsight.NullableNotNullManager; //导入依赖的package包/类
private static boolean isNotNullLocally(@NotNull PsiModifierListOwner owner, boolean ignoreParameterNullabilityInference)
{
	NullableNotNullManager nnnm = NullableNotNullManager.getInstance(owner.getProject());
	PsiAnnotation notNullAnno = nnnm.getNotNullAnnotation(owner, true);
	if(notNullAnno == null || ignoreParameterNullabilityInference && owner instanceof PsiParameter && AnnotationUtil.isInferredAnnotation(notNullAnno))
	{
		return false;
	}

	if(!(owner instanceof PsiParameter))
	{
		return true; // notnull on a super method requires all inheritors to return notnull as well
	}

	// @NotNull on a super parameter doesn't prohibit calling the inheritors with null args, if they're ready for that.
	// so treat parameters as @NotNull only if they're annotated explicitly, or if they're in a scope of some nullity default annotation.
	return isOwnAnnotation(owner, notNullAnno) || nnnm.isContainerAnnotation(notNullAnno);
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:19,代码来源:DfaPsiUtil.java


示例18: getPresentableAnnoName

import com.intellij.codeInsight.NullableNotNullManager; //导入依赖的package包/类
@NotNull
private static String getPresentableAnnoName(@NotNull PsiModifierListOwner owner)
{
	NullableNotNullManager manager = NullableNotNullManager.getInstance(owner.getProject());
	Set<String> names = ContainerUtil.newHashSet(manager.getNullables());
	names.addAll(manager.getNotNulls());

	PsiAnnotation annotation = AnnotationUtil.findAnnotationInHierarchy(owner, names);
	if(annotation != null)
	{
		return getPresentableAnnoName(annotation);
	}

	String anno = manager.getNotNull(owner);
	return StringUtil.getShortName(anno != null ? anno : StringUtil.notNullize(manager.getNullable(owner), "???"));
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:17,代码来源:NullableStuffInspectionBase.java


示例19: checkNullLiteralArgumentOfNotNullParameterUsages

import com.intellij.codeInsight.NullableNotNullManager; //导入依赖的package包/类
private void checkNullLiteralArgumentOfNotNullParameterUsages(PsiMethod method,
		ProblemsHolder holder,
		NullableNotNullManager nullableManager,
		boolean isOnFly,
		int parameterIdx,
		PsiParameter parameter)
{
	if(REPORT_NULLS_PASSED_TO_NOT_NULL_PARAMETER && isOnFly && isNotNullNotInferred(parameter, false, false))
	{
		PsiAnnotation notNullAnnotation = nullableManager.getNotNullAnnotation(parameter, false);
		if(JavaNullMethodArgumentUtil.hasNullArgument(method, parameterIdx))
		{
			boolean physical = PsiTreeUtil.isAncestor(parameter, notNullAnnotation, true);
			holder.registerProblem(physical ? notNullAnnotation : parameter.getNameIdentifier(), JavaInspectionsBundle.message("inspection.nullable.problems.NotNull.parameter.receives.null" + "" +
					".literal", getPresentableAnnoName(parameter)), ProblemHighlightType.GENERIC_ERROR_OR_WARNING, createNavigateToNullParameterUsagesFix(parameter));
		}
	}
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:19,代码来源:NullableStuffInspectionBase.java


示例20: isNotNullNotInferred

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



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java FixedValue类代码示例发布时间:2022-05-22
下一篇:
Java WsSession类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap