本文整理汇总了Java中com.intellij.codeInsight.NullableNotNullManager类的典型用法代码示例。如果您正苦于以下问题:Java NullableNotNullManager类的具体用法?Java NullableNotNullManager怎么用?Java NullableNotNullManager使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
NullableNotNullManager类属于com.intellij.codeInsight包,在下文中一共展示了NullableNotNullManager类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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);
}
示例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;
}
示例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;
}
示例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);
}
示例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;
}
示例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);
}
示例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);
}
示例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);
}
});
}
示例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);
}
}
}
示例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;
}
示例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;
}
示例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);
}
});
}
示例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);
}
}
}
示例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();
}