use of org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.annotation.GrAnnotationArrayInitializer in project intellij-community by JetBrains.
the class CustomAnnotationChecker method checkAnnotationValueByType.
public static void checkAnnotationValueByType(@NotNull AnnotationHolder holder, @NotNull GrAnnotationMemberValue value, @Nullable PsiType ltype, boolean skipArrays) {
final GlobalSearchScope resolveScope = value.getResolveScope();
final PsiManager manager = value.getManager();
if (value instanceof GrExpression) {
final PsiType rtype;
if (value instanceof GrClosableBlock) {
rtype = PsiType.getJavaLangClass(manager, resolveScope);
} else {
rtype = ((GrExpression) value).getType();
}
if (rtype != null && !checkAnnoTypeAssignable(ltype, rtype, value, skipArrays)) {
holder.createErrorAnnotation(value, GroovyBundle.message("cannot.assign", rtype.getPresentableText(), ltype.getPresentableText()));
}
} else if (value instanceof GrAnnotation) {
final PsiElement resolved = ((GrAnnotation) value).getClassReference().resolve();
if (resolved instanceof PsiClass) {
final PsiClassType rtype = JavaPsiFacade.getElementFactory(value.getProject()).createType((PsiClass) resolved, PsiSubstitutor.EMPTY);
if (!checkAnnoTypeAssignable(ltype, rtype, value, skipArrays)) {
holder.createErrorAnnotation(value, GroovyBundle.message("cannot.assign", rtype.getPresentableText(), ltype.getPresentableText()));
}
}
} else if (value instanceof GrAnnotationArrayInitializer) {
if (ltype instanceof PsiArrayType) {
final PsiType componentType = ((PsiArrayType) ltype).getComponentType();
final GrAnnotationMemberValue[] initializers = ((GrAnnotationArrayInitializer) value).getInitializers();
for (GrAnnotationMemberValue initializer : initializers) {
checkAnnotationValueByType(holder, initializer, componentType, false);
}
} else {
final PsiType rtype = TypesUtil.getTupleByAnnotationArrayInitializer((GrAnnotationArrayInitializer) value);
if (!checkAnnoTypeAssignable(ltype, rtype, value, skipArrays)) {
holder.createErrorAnnotation(value, GroovyBundle.message("cannot.assign", rtype.getPresentableText(), ltype.getPresentableText()));
}
}
}
}
use of org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.annotation.GrAnnotationArrayInitializer in project intellij-community by JetBrains.
the class GroovySuppressableInspectionTool method getInspectionIdsSuppressedInAnnotation.
@NotNull
private static Collection<String> getInspectionIdsSuppressedInAnnotation(final GrModifierList modifierList) {
if (modifierList == null) {
return Collections.emptyList();
}
PsiAnnotation annotation = modifierList.findAnnotation(BatchSuppressManager.SUPPRESS_INSPECTIONS_ANNOTATION_NAME);
if (annotation == null) {
return Collections.emptyList();
}
final GrAnnotationMemberValue attributeValue = (GrAnnotationMemberValue) annotation.findAttributeValue(null);
Collection<String> result = new ArrayList<>();
if (attributeValue instanceof GrAnnotationArrayInitializer) {
for (GrAnnotationMemberValue annotationMemberValue : ((GrAnnotationArrayInitializer) attributeValue).getInitializers()) {
final String id = getInspectionIdSuppressedInAnnotationAttribute(annotationMemberValue);
if (id != null) {
result.add(id);
}
}
} else {
final String id = getInspectionIdSuppressedInAnnotationAttribute(attributeValue);
if (id != null) {
result.add(id);
}
}
return result;
}
use of org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.annotation.GrAnnotationArrayInitializer in project intellij-community by JetBrains.
the class GroovyLanguageInjectionSupport method getTopLevelInjectionTarget.
@NotNull
public static PsiElement getTopLevelInjectionTarget(@NotNull final PsiElement host) {
PsiElement target = host;
PsiElement parent = target.getParent();
for (; parent != null; target = parent, parent = target.getParent()) {
if (parent instanceof GrBinaryExpression)
continue;
if (parent instanceof GrString)
continue;
if (parent instanceof GrParenthesizedExpression)
continue;
if (parent instanceof GrConditionalExpression && ((GrConditionalExpression) parent).getCondition() != target)
continue;
if (parent instanceof GrAnnotationArrayInitializer)
continue;
if (parent instanceof GrListOrMap) {
parent = parent.getParent();
continue;
}
break;
}
return target;
}
use of org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.annotation.GrAnnotationArrayInitializer in project intellij-community by JetBrains.
the class SuppressForMemberFix method addSuppressAnnotation.
private static void addSuppressAnnotation(final Project project, final GrModifierList modifierList, final String id) throws IncorrectOperationException {
PsiAnnotation annotation = modifierList.findAnnotation(BatchSuppressManager.SUPPRESS_INSPECTIONS_ANNOTATION_NAME);
final GrExpression toAdd = GroovyPsiElementFactory.getInstance(project).createExpressionFromText("\"" + id + "\"");
if (annotation != null) {
final PsiAnnotationMemberValue value = annotation.findDeclaredAttributeValue(null);
if (value instanceof GrAnnotationArrayInitializer) {
value.add(toAdd);
} else if (value != null) {
GrAnnotation anno = GroovyPsiElementFactory.getInstance(project).createAnnotationFromText("@A([])");
final GrAnnotationArrayInitializer list = (GrAnnotationArrayInitializer) anno.findDeclaredAttributeValue(null);
list.add(value);
list.add(toAdd);
annotation.setDeclaredAttributeValue(null, list);
}
} else {
modifierList.addAnnotation(BatchSuppressManager.SUPPRESS_INSPECTIONS_ANNOTATION_NAME).setDeclaredAttributeValue(null, toAdd);
}
}
use of org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.annotation.GrAnnotationArrayInitializer in project intellij-community by JetBrains.
the class MixinMemberContributor method processDynamicElements.
@Override
public void processDynamicElements(@NotNull final PsiType qualifierType, @NotNull PsiScopeProcessor processor, @NotNull final PsiElement place, @NotNull ResolveState state) {
if (isInAnnotation(place))
return;
final PsiClass aClass = PsiUtil.resolveClassInClassTypeOnly(qualifierType);
if (aClass == null)
return;
final PsiModifierList modifierList = aClass.getModifierList();
if (modifierList == null)
return;
List<PsiClass> mixins = new ArrayList<>();
for (PsiAnnotation annotation : getAllMixins(modifierList)) {
final PsiAnnotationMemberValue value = annotation.findAttributeValue("value");
if (value instanceof GrAnnotationArrayInitializer) {
final GrAnnotationMemberValue[] initializers = ((GrAnnotationArrayInitializer) value).getInitializers();
for (GrAnnotationMemberValue initializer : initializers) {
addMixin(initializer, mixins);
}
} else if (value instanceof GrExpression) {
addMixin((GrExpression) value, mixins);
}
}
final MixinProcessor delegate = new MixinProcessor(processor, qualifierType, place);
for (PsiClass mixin : mixins) {
if (!mixin.processDeclarations(delegate, state, null, place)) {
return;
}
}
}
Aggregations