Search in sources :

Example 61 with PsiAnnotation

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);
    });
}
Also used : PsiPackage(com.intellij.psi.PsiPackage) PsiType(com.intellij.psi.PsiType) JavaPsiFacade(com.intellij.psi.JavaPsiFacade) FilenameIndex(com.intellij.psi.search.FilenameIndex) DISPLAY_NAME(org.talend.sdk.component.intellij.completion.properties.Suggestion.DISPLAY_NAME) CompletionParameters(com.intellij.codeInsight.completion.CompletionParameters) Collections.singletonList(java.util.Collections.singletonList) PsiClass(com.intellij.psi.PsiClass) PsiEnumConstant(com.intellij.psi.PsiEnumConstant) PsiClassReferenceType(com.intellij.psi.impl.source.PsiClassReferenceType) Project(com.intellij.openapi.project.Project) JavaRecursiveElementWalkingVisitor(com.intellij.psi.JavaRecursiveElementWalkingVisitor) ROOT(java.util.Locale.ROOT) Module(com.intellij.openapi.module.Module) PLACEHOLDER(org.talend.sdk.component.intellij.completion.properties.Suggestion.PLACEHOLDER) Suggestion(org.talend.sdk.component.intellij.completion.properties.Suggestion) LookupElement(com.intellij.codeInsight.lookup.LookupElement) Collections.emptyList(java.util.Collections.emptyList) Optional.ofNullable(java.util.Optional.ofNullable) Stream.of(java.util.stream.Stream.of) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) PsiJavaFile(com.intellij.psi.PsiJavaFile) Objects(java.util.Objects) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) Stream(java.util.stream.Stream) AnnotationUtil(com.intellij.codeInsight.AnnotationUtil) PsiAnnotation(com.intellij.psi.PsiAnnotation) JvmModifier(com.intellij.lang.jvm.JvmModifier) Collections(java.util.Collections) PsiAnnotationMemberValue(com.intellij.psi.PsiAnnotationMemberValue) Objects(java.util.Objects) PsiPackage(com.intellij.psi.PsiPackage) PsiAnnotation(com.intellij.psi.PsiAnnotation) JavaRecursiveElementWalkingVisitor(com.intellij.psi.JavaRecursiveElementWalkingVisitor) PsiAnnotationMemberValue(com.intellij.psi.PsiAnnotationMemberValue)

Aggregations

PsiAnnotation (com.intellij.psi.PsiAnnotation)61 PsiModifierList (com.intellij.psi.PsiModifierList)18 PsiAnnotationMemberValue (com.intellij.psi.PsiAnnotationMemberValue)14 PsiMethod (com.intellij.psi.PsiMethod)14 NotNull (org.jetbrains.annotations.NotNull)13 Project (com.intellij.openapi.project.Project)12 PsiClass (com.intellij.psi.PsiClass)11 PsiElement (com.intellij.psi.PsiElement)9 MockProblemDescriptor (com.intellij.testFramework.MockProblemDescriptor)6 ProblemDescriptor (com.intellij.codeInspection.ProblemDescriptor)5 PsiParameter (com.intellij.psi.PsiParameter)5 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)5 Nullable (org.jetbrains.annotations.Nullable)5 PsiParameterList (com.intellij.psi.PsiParameterList)4 TestSize (com.google.idea.blaze.base.dependencies.TestSize)3 PsiJavaCodeReferenceElement (com.intellij.psi.PsiJavaCodeReferenceElement)3 PsiNameValuePair (com.intellij.psi.PsiNameValuePair)3 HashMap (java.util.HashMap)3 LinkedHashMap (java.util.LinkedHashMap)3 Nullable (javax.annotation.Nullable)3