use of com.intellij.psi.PsiAnnotation in project component-runtime by Talend.
the class SuggestionServiceImpl method getFamilyFromPackageInfo.
private String getFamilyFromPackageInfo(final PsiPackage psiPackage, final Module module) {
return of(FilenameIndex.getFilesByName(psiPackage.getProject(), "package-info.java", GlobalSearchScope.moduleScope(module))).map(psiFile -> {
if (!PsiJavaFile.class.cast(psiFile).getPackageName().equals(psiPackage.getQualifiedName())) {
return null;
}
final String[] family = { null };
PsiJavaFile.class.cast(psiFile).accept(new JavaRecursiveElementWalkingVisitor() {
@Override
public void visitAnnotation(final PsiAnnotation annotation) {
super.visitAnnotation(annotation);
if (!COMPONENTS.equals(annotation.getQualifiedName())) {
return;
}
final PsiAnnotationMemberValue familyAttribute = annotation.findAttributeValue("family");
if (familyAttribute == null) {
return;
}
family[0] = removeQuotes(familyAttribute.getText());
}
});
return family[0];
}).filter(Objects::nonNull).findFirst().orElseGet(() -> {
final PsiPackage parent = psiPackage.getParentPackage();
if (parent == null) {
return null;
}
return getFamilyFromPackageInfo(parent, module);
});
}
Aggregations