public boolean accepts(@NotNull final T t, final ProcessingContext context) { return AnnotationUtil.findAnnotation(t, qualifiedNames) != null; } });
private PsiAnnotation findPlainNullabilityAnnotation(@NotNull PsiModifierListOwner owner, boolean checkBases) { Set<String> qNames = ContainerUtil.newHashSet(getNullables()); qNames.addAll(getNotNulls()); return checkBases && owner instanceof PsiMethod ? AnnotationUtil.findAnnotationInHierarchy(owner, qNames) : AnnotationUtil.findAnnotation(owner, qNames); }
@Nullable public static PsiAnnotation findAnnotation(@Nullable PsiModifierListOwner listOwner, @NotNull Set<String> annotationNames) { return findAnnotation(listOwner, (Collection<String>)annotationNames); }
@Nullable public static PsiAnnotation findAnnotation(@Nullable PsiModifierListOwner listOwner, @NotNull String... annotationNames) { return findAnnotation(listOwner, false, annotationNames); }
@Nullable public static PsiAnnotation findAnnotation(@Nullable PsiModifierListOwner listOwner, @NotNull Collection<String> annotationNames) { return findAnnotation(listOwner, annotationNames, false); }
@Nullable public static PsiAnnotation findAnnotation(@Nullable PsiModifierListOwner listOwner, final boolean skipExternal, @NotNull String... annotationNames) { if (annotationNames.length == 0) return null; Set<String> set = annotationNames.length == 1 ? Collections.singleton(annotationNames[0]) : new HashSet<String>(Arrays.asList(annotationNames)); return findAnnotation(listOwner, set, skipExternal); }
@Nullable public static PsiAnnotation findAnnotationInHierarchy(@NotNull final PsiModifierListOwner listOwner, @NotNull Set<String> annotationNames) { PsiAnnotation directAnnotation = findAnnotation(listOwner, annotationNames); if (directAnnotation != null) return directAnnotation; ConcurrentFactoryMap<Set<String>, PsiAnnotation> map = CachedValuesManager.getCachedValue( listOwner, new CachedValueProvider<ConcurrentFactoryMap<Set<String>, PsiAnnotation>>() { @Nullable @Override public Result<ConcurrentFactoryMap<Set<String>, PsiAnnotation>> compute() { ConcurrentFactoryMap<Set<String>, PsiAnnotation> value = new ConcurrentFactoryMap<Set<String>, PsiAnnotation>() { @Nullable @Override protected PsiAnnotation create(Set<String> annotationNames) { for (PsiModifierListOwner superOwner : getSuperAnnotationOwners(listOwner)) { PsiAnnotation annotation = findAnnotation(superOwner, annotationNames); if (annotation != null) { return annotation; } } return null; } }; return Result.create(value, PsiModificationTracker.MODIFICATION_COUNT); } }); return map.get(annotationNames); }
private static boolean isNullabilityDefault(@NotNull PsiAnnotation annotation, boolean nullable, PsiAnnotation.TargetType[] placeTargetTypes) { PsiJavaCodeReferenceElement element = annotation.getNameReferenceElement(); PsiElement declaration = element == null ? null : element.resolve(); if (!(declaration instanceof PsiClass)) return false; if (!AnnotationUtil.isAnnotated((PsiClass)declaration, nullable ? JAVAX_ANNOTATION_NULLABLE : JAVAX_ANNOTATION_NONNULL, false, true)) { return false; } PsiAnnotation tqDefault = AnnotationUtil.findAnnotation((PsiClass)declaration, true, "javax.annotation.meta.TypeQualifierDefault"); if (tqDefault == null) return false; Set<PsiAnnotation.TargetType> required = AnnotationTargetUtil.extractRequiredAnnotationTargets(tqDefault.findAttributeValue(null)); if (required == null) return false; return required.isEmpty() || ContainerUtil.intersects(required, Arrays.asList(placeTargetTypes)); }
PsiAnnotation mappings = findAnnotation( method, true, MapstructUtil.MAPPINGS_ANNOTATION_FQN ); Stream<PsiAnnotation> mappingsAnnotations; if ( mappings == null ) {
@NotNull Project project, @NotNull PsiMethod mappingMethod) { PsiAnnotation mappingsAnnotation = AnnotationUtil.findAnnotation( mappingMethod, MapstructUtil.MAPPINGS_ANNOTATION_FQN PsiAnnotation oldMappingAnnotation = AnnotationUtil.findAnnotation( mappingMethod, MapstructUtil.MAPPING_ANNOTATION_FQN
/** * Checks if MapStruct jdk8 is within the provided module. The MapStruct JDK 8 module is present when the * {@link Mapping} annotation is annotated with {@link java.lang.annotation.Repeatable} * * @param module that needs to be checked * * @return {@code true} if MapStruct jdk8 is present within the {@code module}, {@code false} otherwise */ static boolean isMapStructJdk8Present(@NotNull Module module) { return CachedValuesManager.getManager( module.getProject() ).getCachedValue( module, () -> { PsiClass mappingAnnotation = JavaPsiFacade.getInstance( module.getProject() ) .findClass( MAPPING_ANNOTATION_FQN, module.getModuleRuntimeScope( false ) ); boolean mapstructJdk8Present = findAnnotation( mappingAnnotation, true, CommonClassNames.JAVA_LANG_ANNOTATION_REPEATABLE ) != null; return CachedValueProvider.Result.createSingleDependency( mapstructJdk8Present, ProjectRootManager.getInstance( module.getProject() ) ); } ); }