use of org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GrLightAnnotation in project intellij-community by JetBrains.
the class GrAnnotationCollector method collectAnnotations.
/**
*
* @param list resulting collection of aliased annotations
* @param alias alias annotation
* @param annotationCollector @AnnotationCollector annotation used in alias declaration
* @return set of used arguments of alias annotation
*/
@NotNull
public static Set<String> collectAnnotations(@NotNull List<GrAnnotation> list, @NotNull GrAnnotation alias, @NotNull PsiAnnotation annotationCollector) {
final PsiModifierList modifierList = (PsiModifierList) annotationCollector.getParent();
Map<String, Map<String, PsiNameValuePair>> annotations = ContainerUtil.newLinkedHashMap();
collectAliasedAnnotationsFromAnnotationCollectorValueAttribute(annotationCollector, annotations);
collectAliasedAnnotationsFromAnnotationCollectorAnnotations(modifierList, annotations);
final PsiManager manager = alias.getManager();
final GrAnnotationNameValuePair[] attributes = alias.getParameterList().getAttributes();
Set<String> allUsedAttrs = ContainerUtil.newLinkedHashSet();
for (Map.Entry<String, Map<String, PsiNameValuePair>> entry : annotations.entrySet()) {
final String qname = entry.getKey();
final PsiClass resolved = JavaPsiFacade.getInstance(alias.getProject()).findClass(qname, alias.getResolveScope());
if (resolved == null)
continue;
final GrLightAnnotation annotation = new GrLightAnnotation(manager, alias.getLanguage(), qname, modifierList);
Set<String> usedAttrs = ContainerUtil.newLinkedHashSet();
for (GrAnnotationNameValuePair attr : attributes) {
final String name = attr.getName() != null ? attr.getName() : "value";
if (resolved.findMethodsByName(name, false).length > 0) {
annotation.addAttribute(attr);
allUsedAttrs.add(name);
usedAttrs.add(name);
}
}
final Map<String, PsiNameValuePair> defaults = entry.getValue();
for (Map.Entry<String, PsiNameValuePair> defa : defaults.entrySet()) {
if (!usedAttrs.contains(defa.getKey())) {
annotation.addAttribute(defa.getValue());
}
}
list.add(annotation);
}
return allUsedAttrs;
}
Aggregations