int se8count = 0;
long se8nullBits = 0;
Annotation se8NullAnnotation = null;
int firstSE8 = -1, lastSE8 = 0;
for (int i = 0, length = annotations.length; i < length; i++) {
AnnotationBinding annotation = annotations[i].getCompilerAnnotation();
if (annotation == null) continue;
final ReferenceBinding annotationType = annotation.getAnnotationType();
long metaTagBits = annotationType.getAnnotationTagBits();
if ((metaTagBits & TagBits.AnnotationForTypeUse) != 0) {
if (firstSE8 == -1) firstSE8 = i;
lastSE8 = i;
if (se8Annotations == null) {
se8Annotations = new AnnotationBinding[] { annotation };
se8count = 1;
} else {
System.arraycopy(se8Annotations, 0, se8Annotations = new AnnotationBinding[se8count + 1], 0, se8count);
se8Annotations[se8count++] = annotation;
}
if (annotationType.id == TypeIds.T_ConfiguredAnnotationNonNull) {
se8nullBits = TagBits.AnnotationNonNull;
se8NullAnnotation = annotations[i];
} else if (annotationType.id == TypeIds.T_ConfiguredAnnotationNullable) {
se8nullBits = TagBits.AnnotationNullable;
se8NullAnnotation = annotations[i];
}
}
}
if (se8Annotations != null) {
if (!isLegalLocation) {
scope.problemReporter().misplacedTypeAnnotations(annotations[firstSE8], annotations[lastSE8]);
return;
}
switch (recipient.kind()) {
case Binding.LOCAL:
LocalVariableBinding local = (LocalVariableBinding) recipient;
TypeReference typeRef = local.declaration.type;
if (Annotation.isTypeUseCompatible(typeRef, scope)) { // discard hybrid annotations on name qualified types.
local.declaration.bits |= HasTypeAnnotations;
typeRef.bits |= HasTypeAnnotations;
local.type = mergeAnnotationsIntoType(scope, se8Annotations, se8nullBits, se8NullAnnotation, typeRef, local.type);
}
break;
case Binding.FIELD:
FieldBinding field = (FieldBinding) recipient;
SourceTypeBinding sourceType = (SourceTypeBinding) field.declaringClass;
FieldDeclaration fieldDeclaration = sourceType.scope.referenceContext.declarationOf(field);
if (Annotation.isTypeUseCompatible(fieldDeclaration.type, scope)) { // discard hybrid annotations on name qualified types.
fieldDeclaration.bits |= HasTypeAnnotations;
fieldDeclaration.type.bits |= HasTypeAnnotations;
field.type = mergeAnnotationsIntoType(scope, se8Annotations, se8nullBits, se8NullAnnotation, fieldDeclaration.type, field.type);
}
break;
case Binding.METHOD:
MethodBinding method = (MethodBinding) recipient;
if (!method.isConstructor()) {
sourceType = (SourceTypeBinding) method.declaringClass;
MethodDeclaration methodDecl = (MethodDeclaration) sourceType.scope.referenceContext.declarationOf(method);
if (Annotation.isTypeUseCompatible(methodDecl.returnType, scope)) {
methodDecl.bits |= HasTypeAnnotations;
methodDecl.returnType.bits |= HasTypeAnnotations;
method.returnType = mergeAnnotationsIntoType(scope, se8Annotations, se8nullBits, se8NullAnnotation, methodDecl.returnType, method.returnType);
}
}
break;
}
AnnotationBinding [] recipientAnnotations = recipient.getAnnotations();
int length = recipientAnnotations == null ? 0 : recipientAnnotations.length;
int newLength = 0;
for (int i = 0; i < length; i++) {
final AnnotationBinding recipientAnnotation = recipientAnnotations[i];
if (recipientAnnotation == null)
continue;
long annotationTargetMask = recipientAnnotation.getAnnotationType().getAnnotationTagBits() & TagBits.AnnotationTargetMASK;
if (annotationTargetMask == 0 || (annotationTargetMask & recipientTargetMask) != 0)
recipientAnnotations[newLength++] = recipientAnnotation;
}
if (newLength != length) {
System.arraycopy(recipientAnnotations, 0, recipientAnnotations = new AnnotationBinding[newLength], 0, newLength);