Search in sources :

Example 1 with RecordComponentBinding

use of org.eclipse.jdt.internal.compiler.lookup.RecordComponentBinding in project bazel-jdt-java-toolchain by salesforce.

the class ASTNode method resolveDeprecatedAnnotations.

/**
 * Figures if @Deprecated annotation is specified, do not resolve entire annotations.
 */
public static void resolveDeprecatedAnnotations(BlockScope scope, Annotation[] annotations, Binding recipient) {
    if (recipient != null) {
        int kind = recipient.kind();
        if (annotations != null) {
            int length;
            if ((length = annotations.length) >= 0) {
                switch(kind) {
                    case Binding.PACKAGE:
                        PackageBinding packageBinding = (PackageBinding) recipient;
                        if ((packageBinding.tagBits & TagBits.DeprecatedAnnotationResolved) != 0)
                            return;
                        break;
                    case Binding.TYPE:
                    case Binding.GENERIC_TYPE:
                        ReferenceBinding type = (ReferenceBinding) recipient;
                        if ((type.tagBits & TagBits.DeprecatedAnnotationResolved) != 0)
                            return;
                        break;
                    case Binding.METHOD:
                        MethodBinding method = (MethodBinding) recipient;
                        if ((method.tagBits & TagBits.DeprecatedAnnotationResolved) != 0)
                            return;
                        break;
                    case Binding.FIELD:
                        FieldBinding field = (FieldBinding) recipient;
                        if ((field.tagBits & TagBits.DeprecatedAnnotationResolved) != 0)
                            return;
                        break;
                    case Binding.LOCAL:
                        LocalVariableBinding local = (LocalVariableBinding) recipient;
                        if ((local.tagBits & TagBits.DeprecatedAnnotationResolved) != 0)
                            return;
                        break;
                    case Binding.RECORD_COMPONENT:
                        RecordComponentBinding recordComponentBinding = (RecordComponentBinding) recipient;
                        if ((recordComponentBinding.tagBits & TagBits.DeprecatedAnnotationResolved) != 0)
                            return;
                        break;
                    default:
                        return;
                }
                for (int i = 0; i < length; i++) {
                    TypeReference annotationTypeRef = annotations[i].type;
                    // only resolve type name if 'Deprecated' last token
                    if (!CharOperation.equals(TypeConstants.JAVA_LANG_DEPRECATED[2], annotationTypeRef.getLastToken()))
                        continue;
                    TypeBinding annotationType = annotations[i].type.resolveType(scope);
                    if (annotationType != null && annotationType.isValidBinding() && annotationType.id == TypeIds.T_JavaLangDeprecated) {
                        long deprecationTagBits = TagBits.AnnotationDeprecated | TagBits.DeprecatedAnnotationResolved;
                        if (scope.compilerOptions().complianceLevel >= ClassFileConstants.JDK9) {
                            for (MemberValuePair memberValuePair : annotations[i].memberValuePairs()) {
                                if (CharOperation.equals(memberValuePair.name, TypeConstants.FOR_REMOVAL)) {
                                    if (memberValuePair.value instanceof TrueLiteral)
                                        deprecationTagBits |= TagBits.AnnotationTerminallyDeprecated;
                                    break;
                                }
                            }
                        }
                        switch(kind) {
                            case Binding.PACKAGE:
                                PackageBinding packageBinding = (PackageBinding) recipient;
                                packageBinding.tagBits |= deprecationTagBits;
                                return;
                            case Binding.TYPE:
                            case Binding.GENERIC_TYPE:
                            case Binding.TYPE_PARAMETER:
                                ReferenceBinding type = (ReferenceBinding) recipient;
                                type.tagBits |= deprecationTagBits;
                                return;
                            case Binding.METHOD:
                                MethodBinding method = (MethodBinding) recipient;
                                method.tagBits |= deprecationTagBits;
                                return;
                            case Binding.FIELD:
                                FieldBinding field = (FieldBinding) recipient;
                                field.tagBits |= deprecationTagBits;
                                return;
                            case Binding.LOCAL:
                                LocalVariableBinding local = (LocalVariableBinding) recipient;
                                local.tagBits |= deprecationTagBits;
                                return;
                            case Binding.RECORD_COMPONENT:
                                RecordComponentBinding recordComponentBinding = (RecordComponentBinding) recipient;
                                recordComponentBinding.tagBits |= deprecationTagBits;
                                return;
                            default:
                                return;
                        }
                    }
                }
            }
        }
        switch(kind) {
            case Binding.PACKAGE:
                PackageBinding packageBinding = (PackageBinding) recipient;
                packageBinding.tagBits |= TagBits.DeprecatedAnnotationResolved;
                return;
            case Binding.TYPE:
            case Binding.GENERIC_TYPE:
            case Binding.TYPE_PARAMETER:
                ReferenceBinding type = (ReferenceBinding) recipient;
                type.tagBits |= TagBits.DeprecatedAnnotationResolved;
                return;
            case Binding.METHOD:
                MethodBinding method = (MethodBinding) recipient;
                method.tagBits |= TagBits.DeprecatedAnnotationResolved;
                return;
            case Binding.FIELD:
                FieldBinding field = (FieldBinding) recipient;
                field.tagBits |= TagBits.DeprecatedAnnotationResolved;
                return;
            case Binding.LOCAL:
                LocalVariableBinding local = (LocalVariableBinding) recipient;
                local.tagBits |= TagBits.DeprecatedAnnotationResolved;
                return;
            case Binding.RECORD_COMPONENT:
                RecordComponentBinding recordComponentBinding = (RecordComponentBinding) recipient;
                recordComponentBinding.tagBits |= TagBits.DeprecatedAnnotationResolved;
                return;
            default:
                return;
        }
    }
}
Also used : SourceTypeBinding(org.eclipse.jdt.internal.compiler.lookup.SourceTypeBinding) TypeBinding(org.eclipse.jdt.internal.compiler.lookup.TypeBinding) FieldBinding(org.eclipse.jdt.internal.compiler.lookup.FieldBinding) PackageBinding(org.eclipse.jdt.internal.compiler.lookup.PackageBinding) ProblemMethodBinding(org.eclipse.jdt.internal.compiler.lookup.ProblemMethodBinding) MethodBinding(org.eclipse.jdt.internal.compiler.lookup.MethodBinding) ParameterizedMethodBinding(org.eclipse.jdt.internal.compiler.lookup.ParameterizedMethodBinding) ParameterizedGenericMethodBinding(org.eclipse.jdt.internal.compiler.lookup.ParameterizedGenericMethodBinding) ReferenceBinding(org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding) RecordComponentBinding(org.eclipse.jdt.internal.compiler.lookup.RecordComponentBinding) LocalVariableBinding(org.eclipse.jdt.internal.compiler.lookup.LocalVariableBinding)

Example 2 with RecordComponentBinding

use of org.eclipse.jdt.internal.compiler.lookup.RecordComponentBinding in project bazel-jdt-java-toolchain by salesforce.

the class ASTNode method resolveAnnotations.

/**
 * Resolve annotations, and check duplicates, answers combined tagBits
 * for recognized standard annotations. Return null if nothing new is
 * resolved.
 */
public static AnnotationBinding[] resolveAnnotations(BlockScope scope, Annotation[] sourceAnnotations, Binding recipient, boolean copySE8AnnotationsToType) {
    AnnotationBinding[] annotations = null;
    int length = sourceAnnotations == null ? 0 : sourceAnnotations.length;
    if (recipient != null) {
        switch(recipient.kind()) {
            case Binding.PACKAGE:
                PackageBinding packageBinding = (PackageBinding) recipient;
                if ((packageBinding.tagBits & TagBits.AnnotationResolved) != 0)
                    return annotations;
                packageBinding.tagBits |= (TagBits.AnnotationResolved | TagBits.DeprecatedAnnotationResolved);
                break;
            case Binding.TYPE:
            case Binding.GENERIC_TYPE:
                ReferenceBinding type = (ReferenceBinding) recipient;
                if ((type.tagBits & TagBits.AnnotationResolved) != 0)
                    return annotations;
                type.tagBits |= (TagBits.AnnotationResolved | TagBits.DeprecatedAnnotationResolved);
                if (length > 0) {
                    annotations = new AnnotationBinding[length];
                    type.setAnnotations(annotations, false);
                }
                break;
            case Binding.METHOD:
                MethodBinding method = (MethodBinding) recipient;
                if ((method.tagBits & TagBits.AnnotationResolved) != 0)
                    return annotations;
                method.tagBits |= (TagBits.AnnotationResolved | TagBits.DeprecatedAnnotationResolved);
                if (length > 0) {
                    annotations = new AnnotationBinding[length];
                    method.setAnnotations(annotations, false);
                }
                break;
            case Binding.FIELD:
                FieldBinding field = (FieldBinding) recipient;
                if ((field.tagBits & TagBits.AnnotationResolved) != 0)
                    return annotations;
                field.tagBits |= (TagBits.AnnotationResolved | TagBits.DeprecatedAnnotationResolved);
                if (length > 0) {
                    annotations = new AnnotationBinding[length];
                    field.setAnnotations(annotations, false);
                }
                break;
            case Binding.RECORD_COMPONENT:
                RecordComponentBinding rcb = (RecordComponentBinding) recipient;
                if ((rcb.tagBits & TagBits.AnnotationResolved) != 0)
                    return annotations;
                rcb.tagBits |= (TagBits.AnnotationResolved | TagBits.DeprecatedAnnotationResolved);
                if (length > 0) {
                    annotations = new AnnotationBinding[length];
                    rcb.setAnnotations(annotations, false);
                }
                break;
            case Binding.LOCAL:
                LocalVariableBinding local = (LocalVariableBinding) recipient;
                if ((local.tagBits & TagBits.AnnotationResolved) != 0)
                    return annotations;
                local.tagBits |= (TagBits.AnnotationResolved | TagBits.DeprecatedAnnotationResolved);
                if (length > 0) {
                    annotations = new AnnotationBinding[length];
                    local.setAnnotations(annotations, scope, false);
                }
                break;
            case Binding.TYPE_PARAMETER:
            case Binding.TYPE_USE:
                // deliberately don't set the annotation resolved tagbits, it is not material and also we are working with a dummy static object.
                annotations = new AnnotationBinding[length];
                break;
            case Binding.MODULE:
                ModuleBinding module = (ModuleBinding) recipient;
                if ((module.tagBits & TagBits.AnnotationResolved) != 0)
                    return annotations;
                module.tagBits |= (TagBits.AnnotationResolved | TagBits.DeprecatedAnnotationResolved);
                if (length > 0) {
                    annotations = new AnnotationBinding[length];
                    module.setAnnotations(annotations, scope, false);
                }
                break;
            default:
                return annotations;
        }
    }
    if (sourceAnnotations == null)
        return annotations;
    for (int i = 0; i < length; i++) {
        Annotation annotation = sourceAnnotations[i];
        final Binding annotationRecipient = annotation.recipient;
        if (annotationRecipient != null && recipient != null) {
            // only local and field can share annotations and their types.
            switch(recipient.kind()) {
                case Binding.TYPE_USE:
                    if (annotations != null) {
                        // need to fill the instances array
                        for (int j = 0; j < length; j++) {
                            annotations[j] = sourceAnnotations[j].getCompilerAnnotation();
                        }
                    }
                    break;
                case Binding.FIELD:
                    FieldBinding field = (FieldBinding) recipient;
                    field.tagBits = ((FieldBinding) annotationRecipient).tagBits;
                    if (annotations != null) {
                        // need to fill the instances array
                        for (int j = 0; j < length; j++) {
                            Annotation annot = sourceAnnotations[j];
                            annotations[j] = annot.getCompilerAnnotation();
                        }
                    }
                    break;
                case Binding.RECORD_COMPONENT:
                    RecordComponentBinding recordComponentBinding = (RecordComponentBinding) recipient;
                    recordComponentBinding.tagBits = ((RecordComponentBinding) annotationRecipient).tagBits;
                    if (annotations != null) {
                        // need to fill the instances array
                        for (int j = 0; j < length; j++) {
                            Annotation annot = sourceAnnotations[j];
                            annotations[j] = annot.getCompilerAnnotation();
                        }
                    }
                    break;
                case Binding.LOCAL:
                    LocalVariableBinding local = (LocalVariableBinding) recipient;
                    // Note for JDK>=14, this could be LVB or RCB, hence typecasting to VB
                    long otherLocalTagBits = ((VariableBinding) annotationRecipient).tagBits;
                    // Make sure we retain the TagBits.IsArgument bit
                    local.tagBits = otherLocalTagBits | (local.tagBits & TagBits.IsArgument);
                    if ((otherLocalTagBits & TagBits.AnnotationSuppressWarnings) == 0) {
                        // need to fill the instances array
                        if (annotations != null) {
                            for (int j = 0; j < length; j++) {
                                Annotation annot = sourceAnnotations[j];
                                annotations[j] = annot.getCompilerAnnotation();
                            }
                        }
                    } else if (annotations != null) {
                        // One of the annotations at least is a SuppressWarnings annotation
                        LocalDeclaration localDeclaration = local.declaration;
                        int declarationSourceEnd = localDeclaration.declarationSourceEnd;
                        int declarationSourceStart = localDeclaration.declarationSourceStart;
                        for (int j = 0; j < length; j++) {
                            Annotation annot = sourceAnnotations[j];
                            /*
								 * Annotations are shared between two locals, but we still need to record
								 * the suppress annotation range for the second local
								 */
                            AnnotationBinding annotationBinding = annot.getCompilerAnnotation();
                            annotations[j] = annotationBinding;
                            if (annotationBinding != null) {
                                final ReferenceBinding annotationType = annotationBinding.getAnnotationType();
                                if (annotationType != null && annotationType.id == TypeIds.T_JavaLangSuppressWarnings) {
                                    annot.recordSuppressWarnings(scope, declarationSourceStart, declarationSourceEnd, scope.compilerOptions().suppressWarnings);
                                }
                            }
                        }
                    }
                    // copy the se8 annotations.
                    if (annotationRecipient instanceof RecordComponentBinding && copySE8AnnotationsToType)
                        copySE8AnnotationsToType(scope, recipient, sourceAnnotations, false);
                    break;
            }
            return annotations;
        } else {
            annotation.recipient = recipient;
            annotation.resolveType(scope);
            // null if receiver is a package binding
            if (annotations != null) {
                annotations[i] = annotation.getCompilerAnnotation();
            }
        }
    }
    /* See if the recipient is meta-annotated with @Repeatable and if so validate constraints. We can't do this during resolution of @Repeatable itself as @Target and
		   @Retention etc could come later
		*/
    if (recipient != null && recipient.isTaggedRepeatable()) {
        for (int i = 0; i < length; i++) {
            Annotation annotation = sourceAnnotations[i];
            ReferenceBinding annotationType = annotations[i] != null ? annotations[i].getAnnotationType() : null;
            if (annotationType != null && annotationType.id == TypeIds.T_JavaLangAnnotationRepeatable)
                annotation.checkRepeatableMetaAnnotation(scope);
        }
    }
    // check duplicate annotations
    if (annotations != null && length > 1) {
        // only copy after 1st duplicate is detected
        AnnotationBinding[] distinctAnnotations = annotations;
        Map implicitContainerAnnotations = null;
        for (int i = 0; i < length; i++) {
            AnnotationBinding annotation = distinctAnnotations[i];
            if (annotation == null)
                continue;
            ReferenceBinding annotationType = annotation.getAnnotationType();
            boolean foundDuplicate = false;
            ContainerAnnotation container = null;
            for (int j = i + 1; j < length; j++) {
                AnnotationBinding otherAnnotation = distinctAnnotations[j];
                if (otherAnnotation == null)
                    continue;
                if (TypeBinding.equalsEquals(otherAnnotation.getAnnotationType(), annotationType)) {
                    if (distinctAnnotations == annotations) {
                        System.arraycopy(distinctAnnotations, 0, distinctAnnotations = new AnnotationBinding[length], 0, length);
                    }
                    // report/process it only once
                    distinctAnnotations[j] = null;
                    if (annotationType.isRepeatableAnnotationType()) {
                        Annotation persistibleAnnotation = sourceAnnotations[i].getPersistibleAnnotation();
                        if (persistibleAnnotation instanceof ContainerAnnotation)
                            container = (ContainerAnnotation) persistibleAnnotation;
                        if (container == null) {
                            // first encounter with a duplicate.
                            ReferenceBinding containerAnnotationType = annotationType.containerAnnotationType();
                            container = new ContainerAnnotation(sourceAnnotations[i], containerAnnotationType, scope);
                            if (implicitContainerAnnotations == null)
                                implicitContainerAnnotations = new HashMap(3);
                            implicitContainerAnnotations.put(containerAnnotationType, sourceAnnotations[i]);
                            Annotation.checkForInstancesOfRepeatableWithRepeatingContainerAnnotation(scope, annotationType, sourceAnnotations);
                        }
                        container.addContainee(sourceAnnotations[j]);
                    } else {
                        foundDuplicate = true;
                        scope.problemReporter().duplicateAnnotation(sourceAnnotations[j], scope.compilerOptions().sourceLevel);
                    }
                }
            }
            if (container != null) {
                container.resolveType(scope);
            }
            if (foundDuplicate) {
                scope.problemReporter().duplicateAnnotation(sourceAnnotations[i], scope.compilerOptions().sourceLevel);
            }
        }
        // Check for presence of repeating annotation together with the containing annotation
        if (implicitContainerAnnotations != null) {
            for (int i = 0; i < length; i++) {
                if (distinctAnnotations[i] == null)
                    continue;
                Annotation annotation = sourceAnnotations[i];
                ReferenceBinding annotationType = distinctAnnotations[i].getAnnotationType();
                if (implicitContainerAnnotations.containsKey(annotationType)) {
                    scope.problemReporter().repeatedAnnotationWithContainer((Annotation) implicitContainerAnnotations.get(annotationType), annotation);
                }
            }
        }
    }
    if (copySE8AnnotationsToType)
        copySE8AnnotationsToType(scope, recipient, sourceAnnotations, false);
    return annotations;
}
Also used : SourceTypeBinding(org.eclipse.jdt.internal.compiler.lookup.SourceTypeBinding) LocalVariableBinding(org.eclipse.jdt.internal.compiler.lookup.LocalVariableBinding) WildcardBinding(org.eclipse.jdt.internal.compiler.lookup.WildcardBinding) FieldBinding(org.eclipse.jdt.internal.compiler.lookup.FieldBinding) ModuleBinding(org.eclipse.jdt.internal.compiler.lookup.ModuleBinding) Binding(org.eclipse.jdt.internal.compiler.lookup.Binding) TypeBinding(org.eclipse.jdt.internal.compiler.lookup.TypeBinding) TypeVariableBinding(org.eclipse.jdt.internal.compiler.lookup.TypeVariableBinding) ProblemMethodBinding(org.eclipse.jdt.internal.compiler.lookup.ProblemMethodBinding) MethodBinding(org.eclipse.jdt.internal.compiler.lookup.MethodBinding) VariableBinding(org.eclipse.jdt.internal.compiler.lookup.VariableBinding) ParameterizedMethodBinding(org.eclipse.jdt.internal.compiler.lookup.ParameterizedMethodBinding) ReferenceBinding(org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding) ArrayBinding(org.eclipse.jdt.internal.compiler.lookup.ArrayBinding) PackageBinding(org.eclipse.jdt.internal.compiler.lookup.PackageBinding) AnnotationBinding(org.eclipse.jdt.internal.compiler.lookup.AnnotationBinding) ParameterizedGenericMethodBinding(org.eclipse.jdt.internal.compiler.lookup.ParameterizedGenericMethodBinding) RecordComponentBinding(org.eclipse.jdt.internal.compiler.lookup.RecordComponentBinding) HashMap(java.util.HashMap) PackageBinding(org.eclipse.jdt.internal.compiler.lookup.PackageBinding) ModuleBinding(org.eclipse.jdt.internal.compiler.lookup.ModuleBinding) ReferenceBinding(org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding) LocalVariableBinding(org.eclipse.jdt.internal.compiler.lookup.LocalVariableBinding) AnnotationBinding(org.eclipse.jdt.internal.compiler.lookup.AnnotationBinding) FieldBinding(org.eclipse.jdt.internal.compiler.lookup.FieldBinding) ProblemMethodBinding(org.eclipse.jdt.internal.compiler.lookup.ProblemMethodBinding) MethodBinding(org.eclipse.jdt.internal.compiler.lookup.MethodBinding) ParameterizedMethodBinding(org.eclipse.jdt.internal.compiler.lookup.ParameterizedMethodBinding) ParameterizedGenericMethodBinding(org.eclipse.jdt.internal.compiler.lookup.ParameterizedGenericMethodBinding) RecordComponentBinding(org.eclipse.jdt.internal.compiler.lookup.RecordComponentBinding) LocalVariableBinding(org.eclipse.jdt.internal.compiler.lookup.LocalVariableBinding) TypeVariableBinding(org.eclipse.jdt.internal.compiler.lookup.TypeVariableBinding) VariableBinding(org.eclipse.jdt.internal.compiler.lookup.VariableBinding) HashMap(java.util.HashMap) Map(java.util.Map)

Example 3 with RecordComponentBinding

use of org.eclipse.jdt.internal.compiler.lookup.RecordComponentBinding in project bazel-jdt-java-toolchain by salesforce.

the class ASTNode method copySE8AnnotationsToType.

// When SE8 annotations feature in SE7 locations, they get attributed to the declared entity. Copy/move these to the type of the declared entity (field, local, argument etc.)
public static void copySE8AnnotationsToType(BlockScope scope, Binding recipient, Annotation[] annotations, boolean annotatingEnumerator) {
    if (annotations == null || annotations.length == 0 || recipient == null)
        return;
    long recipientTargetMask = 0;
    switch(recipient.kind()) {
        case Binding.LOCAL:
            recipientTargetMask = recipient.isParameter() ? TagBits.AnnotationForParameter : TagBits.AnnotationForLocalVariable;
            break;
        case Binding.FIELD:
            recipientTargetMask = TagBits.AnnotationForField;
            break;
        case Binding.METHOD:
            MethodBinding method = (MethodBinding) recipient;
            recipientTargetMask = method.isConstructor() ? TagBits.AnnotationForConstructor : TagBits.AnnotationForMethod;
            break;
        case Binding.RECORD_COMPONENT:
            recipientTargetMask = TagBits.AnnotationForRecordComponent;
            break;
        default:
            return;
    }
    AnnotationBinding[] se8Annotations = null;
    int se8count = 0;
    long se8nullBits = 0;
    // just any involved annotation so we have a location for error reporting
    Annotation se8NullAnnotation = null;
    int firstSE8 = -1;
    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 (annotatingEnumerator) {
                if ((metaTagBits & recipientTargetMask) == 0) {
                    scope.problemReporter().misplacedTypeAnnotations(annotations[i], annotations[i]);
                }
                continue;
            }
            if (firstSE8 == -1)
                firstSE8 = 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.hasNullBit(TypeIds.BitNonNullAnnotation)) {
                se8nullBits |= TagBits.AnnotationNonNull;
                se8NullAnnotation = annotations[i];
            } else if (annotationType.hasNullBit(TypeIds.BitNullableAnnotation)) {
                se8nullBits |= TagBits.AnnotationNullable;
                se8NullAnnotation = annotations[i];
            }
        }
    }
    if (se8Annotations != null) {
        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);
                    if (scope.environment().usesNullTypeAnnotations()) {
                        local.tagBits &= ~(se8nullBits);
                    }
                }
                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);
                    if (scope.environment().usesNullTypeAnnotations()) {
                        field.tagBits &= ~(se8nullBits);
                    }
                }
                break;
            case Binding.RECORD_COMPONENT:
                RecordComponentBinding recordComponentBinding = (RecordComponentBinding) recipient;
                RecordComponent recordComponent = recordComponentBinding.sourceRecordComponent();
                if (Annotation.isTypeUseCompatible(recordComponent.type, scope)) {
                    // discard hybrid annotations on name qualified types.
                    recordComponent.bits |= HasTypeAnnotations;
                    recordComponent.type.bits |= HasTypeAnnotations;
                    recordComponentBinding.type = mergeAnnotationsIntoType(scope, se8Annotations, se8nullBits, se8NullAnnotation, recordComponent.type, recordComponentBinding.type);
                    if (scope.environment().usesNullTypeAnnotations()) {
                        // TODO Bug 562478
                        recordComponentBinding.tagBits &= ~(se8nullBits);
                    }
                }
                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);
                        if (scope.environment().usesNullTypeAnnotations()) {
                            method.tagBits &= ~(se8nullBits);
                        }
                    }
                } else {
                    method.setTypeAnnotations(se8Annotations);
                }
                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);
            recipient.setAnnotations(recipientAnnotations, scope, false);
        }
    }
}
Also used : ReferenceBinding(org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding) LocalVariableBinding(org.eclipse.jdt.internal.compiler.lookup.LocalVariableBinding) AnnotationBinding(org.eclipse.jdt.internal.compiler.lookup.AnnotationBinding) FieldBinding(org.eclipse.jdt.internal.compiler.lookup.FieldBinding) ProblemMethodBinding(org.eclipse.jdt.internal.compiler.lookup.ProblemMethodBinding) MethodBinding(org.eclipse.jdt.internal.compiler.lookup.MethodBinding) ParameterizedMethodBinding(org.eclipse.jdt.internal.compiler.lookup.ParameterizedMethodBinding) ParameterizedGenericMethodBinding(org.eclipse.jdt.internal.compiler.lookup.ParameterizedGenericMethodBinding) RecordComponentBinding(org.eclipse.jdt.internal.compiler.lookup.RecordComponentBinding) SourceTypeBinding(org.eclipse.jdt.internal.compiler.lookup.SourceTypeBinding)

Example 4 with RecordComponentBinding

use of org.eclipse.jdt.internal.compiler.lookup.RecordComponentBinding in project bazel-jdt-java-toolchain by salesforce.

the class ClassFile method generateRecordAttributes.

private int generateRecordAttributes() {
    SourceTypeBinding record = this.referenceBinding;
    if (record == null || !record.isRecord())
        return 0;
    int localContentsOffset = this.contentsOffset;
    RecordComponentBinding[] recordComponents = this.referenceBinding.components();
    if (recordComponents == null)
        return 0;
    // could be an empty record also, account for zero components as well.
    int numberOfRecordComponents = recordComponents.length;
    int exSize = 8 + 2 * numberOfRecordComponents;
    if (exSize + localContentsOffset >= this.contents.length) {
        resizeContents(exSize);
    }
    /*
		 * Record_attribute {
    	 *  u2 attribute_name_index;
    	 *	u4 attribute_length;
    	 *	u2 components_count;
    	 *	component_info components[components_count];
		 *	}*/
    int attributeNameIndex = this.constantPool.literalIndex(AttributeNamesConstants.RecordClass);
    this.contents[localContentsOffset++] = (byte) (attributeNameIndex >> 8);
    this.contents[localContentsOffset++] = (byte) attributeNameIndex;
    int attrLengthOffset = localContentsOffset;
    localContentsOffset += 4;
    int base = localContentsOffset;
    this.contents[localContentsOffset++] = (byte) (numberOfRecordComponents >> 8);
    this.contents[localContentsOffset++] = (byte) numberOfRecordComponents;
    this.contentsOffset = localContentsOffset;
    for (int i = 0; i < numberOfRecordComponents; i++) {
        addComponentInfo(recordComponents[i]);
    }
    int attrLength = this.contentsOffset - base;
    this.contents[attrLengthOffset++] = (byte) (attrLength >> 24);
    this.contents[attrLengthOffset++] = (byte) (attrLength >> 16);
    this.contents[attrLengthOffset++] = (byte) (attrLength >> 8);
    this.contents[attrLengthOffset++] = (byte) attrLength;
    return 1;
}
Also used : RecordComponentBinding(org.eclipse.jdt.internal.compiler.lookup.RecordComponentBinding) SourceTypeBinding(org.eclipse.jdt.internal.compiler.lookup.SourceTypeBinding)

Example 5 with RecordComponentBinding

use of org.eclipse.jdt.internal.compiler.lookup.RecordComponentBinding in project bazel-jdt-java-toolchain by salesforce.

the class ClassFile method propagateRecordComponentArguments.

private void propagateRecordComponentArguments(AbstractMethodDeclaration methodDeclaration) {
    if ((methodDeclaration.bits & (ASTNode.IsCanonicalConstructor | ASTNode.IsImplicit)) == 0)
        return;
    ReferenceBinding declaringClass = methodDeclaration.binding.declaringClass;
    if (declaringClass instanceof SourceTypeBinding) {
        assert declaringClass.isRecord();
        RecordComponentBinding[] rcbs = ((SourceTypeBinding) declaringClass).components();
        Argument[] arguments = methodDeclaration.arguments;
        for (int i = 0, length = rcbs.length; i < length; i++) {
            RecordComponentBinding rcb = rcbs[i];
            RecordComponent recordComponent = rcb.sourceRecordComponent();
            if ((recordComponent.bits & ASTNode.HasTypeAnnotations) != 0) {
                methodDeclaration.bits |= ASTNode.HasTypeAnnotations;
                arguments[i].bits |= ASTNode.HasTypeAnnotations;
            }
            long rcMask = TagBits.AnnotationForParameter | TagBits.AnnotationForTypeUse;
            arguments[i].annotations = ASTNode.getRelevantAnnotations(recordComponent.annotations, rcMask, null);
        }
    }
}
Also used : Argument(org.eclipse.jdt.internal.compiler.ast.Argument) ReferenceBinding(org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding) ProblemReferenceBinding(org.eclipse.jdt.internal.compiler.lookup.ProblemReferenceBinding) RecordComponentBinding(org.eclipse.jdt.internal.compiler.lookup.RecordComponentBinding) SourceTypeBinding(org.eclipse.jdt.internal.compiler.lookup.SourceTypeBinding) RecordComponent(org.eclipse.jdt.internal.compiler.ast.RecordComponent)

Aggregations

RecordComponentBinding (org.eclipse.jdt.internal.compiler.lookup.RecordComponentBinding)8 SourceTypeBinding (org.eclipse.jdt.internal.compiler.lookup.SourceTypeBinding)8 ReferenceBinding (org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding)5 FieldBinding (org.eclipse.jdt.internal.compiler.lookup.FieldBinding)4 LocalVariableBinding (org.eclipse.jdt.internal.compiler.lookup.LocalVariableBinding)4 MethodBinding (org.eclipse.jdt.internal.compiler.lookup.MethodBinding)4 RecordComponent (org.eclipse.jdt.internal.compiler.ast.RecordComponent)3 ParameterizedGenericMethodBinding (org.eclipse.jdt.internal.compiler.lookup.ParameterizedGenericMethodBinding)3 ParameterizedMethodBinding (org.eclipse.jdt.internal.compiler.lookup.ParameterizedMethodBinding)3 ProblemMethodBinding (org.eclipse.jdt.internal.compiler.lookup.ProblemMethodBinding)3 TypeBinding (org.eclipse.jdt.internal.compiler.lookup.TypeBinding)3 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Annotation (org.eclipse.jdt.internal.compiler.ast.Annotation)2 Argument (org.eclipse.jdt.internal.compiler.ast.Argument)2 AnnotationBinding (org.eclipse.jdt.internal.compiler.lookup.AnnotationBinding)2 ArrayBinding (org.eclipse.jdt.internal.compiler.lookup.ArrayBinding)2 Binding (org.eclipse.jdt.internal.compiler.lookup.Binding)2 ModuleBinding (org.eclipse.jdt.internal.compiler.lookup.ModuleBinding)2 PackageBinding (org.eclipse.jdt.internal.compiler.lookup.PackageBinding)2