use of org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.annotation.GrAnnotation in project intellij-community by JetBrains.
the class GrAnnotationNameValuePairImpl method getDetachedValue.
@Override
@Nullable
public PsiAnnotationMemberValue getDetachedValue() {
GrNameValuePairStub stub = getStub();
if (stub != null) {
String text = stub.getValue();
PsiAnnotationMemberValue result = SoftReference.dereference(myDetachedValue);
if (result == null) {
GrAnnotation annotation = GroovyPsiElementFactory.getInstance(getProject()).createAnnotationFromText("@F(" + text + ")", this);
((LightVirtualFile) annotation.getContainingFile().getViewProvider().getVirtualFile()).setWritable(false);
PsiAnnotationMemberValue value = annotation.findAttributeValue(null);
myDetachedValue = new SoftReference<>(result = value);
}
return result;
}
return getValue();
}
use of org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.annotation.GrAnnotation in project intellij-community by JetBrains.
the class GrAnnotationCollector method getResolvedAnnotations.
@NotNull
public static GrAnnotation[] getResolvedAnnotations(@NotNull GrModifierList modifierList) {
final GrAnnotation[] rawAnnotations = modifierList.getRawAnnotations();
if (!hasAliases(rawAnnotations))
return rawAnnotations;
List<GrAnnotation> result = ContainerUtil.newArrayList();
for (GrAnnotation annotation : rawAnnotations) {
final PsiAnnotation annotationCollector = findAnnotationCollector(annotation);
if (annotationCollector != null) {
collectAnnotations(result, annotation, annotationCollector);
} else {
result.add(annotation);
}
}
return result.toArray(new GrAnnotation[result.size()]);
}
use of org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.annotation.GrAnnotation in project intellij-community by JetBrains.
the class GrAnnotationCollector method collectAliasedAnnotationsFromAnnotationCollectorAnnotations.
private static void collectAliasedAnnotationsFromAnnotationCollectorAnnotations(@NotNull PsiModifierList modifierList, @NotNull Map<String, Map<String, PsiNameValuePair>> annotations) {
PsiElement parent = modifierList.getParent();
if (parent instanceof PsiClass && GroovyCommonClassNames.GROOVY_TRANSFORM_COMPILE_DYNAMIC.equals(((PsiClass) parent).getQualifiedName())) {
Map<String, PsiNameValuePair> params = ContainerUtil.newLinkedHashMap();
annotations.put(GroovyCommonClassNames.GROOVY_TRANSFORM_COMPILE_STATIC, params);
GrAnnotation annotation = GroovyPsiElementFactory.getInstance(modifierList.getProject()).createAnnotationFromText("@CompileStatic(TypeCheckingMode.SKIP)");
params.put("value", annotation.getParameterList().getAttributes()[0]);
return;
}
PsiAnnotation[] rawAnnotations = modifierList instanceof GrModifierList ? ((GrModifierList) modifierList).getRawAnnotations() : modifierList.getAnnotations();
for (PsiAnnotation annotation : rawAnnotations) {
final String qname = annotation.getQualifiedName();
if (qname == null || qname.equals(GroovyCommonClassNames.GROOVY_TRANSFORM_ANNOTATION_COLLECTOR))
continue;
final PsiNameValuePair[] attributes = annotation.getParameterList().getAttributes();
for (PsiNameValuePair pair : attributes) {
Map<String, PsiNameValuePair> map = annotations.get(qname);
if (map == null) {
map = ContainerUtil.newLinkedHashMap();
annotations.put(qname, map);
}
map.put(pair.getName() != null ? pair.getName() : "value", pair);
}
if (attributes.length == 0 && !annotations.containsKey(qname)) {
annotations.put(qname, ContainerUtil.<String, PsiNameValuePair>newLinkedHashMap());
}
}
}
use of org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.annotation.GrAnnotation in project intellij-community by JetBrains.
the class AnnotationAttributeCompletionResultProcessor method process.
public void process(@NotNull Consumer<LookupElement> consumer, @NotNull PrefixMatcher matcher) {
GrCodeReferenceElement ref = myAnnotation.getClassReference();
PsiElement resolved = ref.resolve();
if (resolved instanceof PsiClass) {
final PsiAnnotation annotationCollector = GrAnnotationCollector.findAnnotationCollector((PsiClass) resolved);
if (annotationCollector != null) {
final ArrayList<GrAnnotation> annotations = ContainerUtil.newArrayList();
GrAnnotationCollector.collectAnnotations(annotations, myAnnotation, annotationCollector);
Set<String> usedNames = ContainerUtil.newHashSet();
for (GrAnnotation annotation : annotations) {
final PsiElement resolvedAliased = annotation.getClassReference().resolve();
if (resolvedAliased instanceof PsiClass && ((PsiClass) resolvedAliased).isAnnotationType()) {
for (PsiMethod method : ((PsiClass) resolvedAliased).getMethods()) {
if (usedNames.add(method.getName())) {
for (LookupElement element : GroovyCompletionUtil.createLookupElements(new GroovyResolveResultImpl(method, true), false, matcher, null)) {
consumer.consume(element);
}
}
}
}
}
} else if (((PsiClass) resolved).isAnnotationType()) {
for (PsiMethod method : ((PsiClass) resolved).getMethods()) {
for (LookupElement element : GroovyCompletionUtil.createLookupElements(new GroovyResolveResultImpl(method, true), false, matcher, null)) {
consumer.consume(element);
}
}
}
}
}
use of org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.annotation.GrAnnotation in project intellij-community by JetBrains.
the class ModifierListGenerator method writeModifiers.
public static boolean writeModifiers(StringBuilder builder, PsiModifierList modifierList, String[] modifiers, boolean writeAnnotations) {
boolean wasAddedModifiers = false;
if (writeAnnotations && modifierList instanceof GrModifierList) {
GrAnnotation[] annotations = ((GrModifierList) modifierList).getAnnotations();
AnnotationGenerator annotationGenerator = new AnnotationGenerator(builder, new ExpressionContext(modifierList.getProject(), GroovyFile.EMPTY_ARRAY));
wasAddedModifiers = annotations.length > 0;
for (GrAnnotation annotation : annotations) {
annotation.accept(annotationGenerator);
builder.append(' ');
}
}
for (String modifierType : modifiers) {
if (modifierList.hasModifierProperty(modifierType)) {
builder.append(modifierType);
builder.append(' ');
wasAddedModifiers = true;
}
}
return wasAddedModifiers;
}
Aggregations