Search in sources :

Example 1 with RecordComponent

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

the class SourceTypeBinding method resolveTypeFor.

public RecordComponentBinding resolveTypeFor(RecordComponentBinding component) {
    if (!isPrototype())
        return this.prototype.resolveTypeFor(component);
    if ((component.modifiers & ExtraCompilerModifiers.AccUnresolved) == 0)
        return component;
    component.getAnnotationTagBits();
    if (// TODO: Watch out the spec changes
    (component.getAnnotationTagBits() & TagBits.AnnotationDeprecated) != 0)
        // expected to be available soon.
        component.modifiers |= ClassFileConstants.AccDeprecated;
    if (isViewedAsDeprecated() && !component.isDeprecated()) {
        component.modifiers |= ExtraCompilerModifiers.AccDeprecatedImplicitly;
        component.tagBits |= this.tagBits & TagBits.AnnotationTerminallyDeprecated;
    }
    if (hasRestrictedAccess())
        component.modifiers |= ExtraCompilerModifiers.AccRestrictedAccess;
    RecordComponent[] componentDecls = this.scope.referenceContext.recordComponents;
    int length = componentDecls == null ? 0 : componentDecls.length;
    for (int f = 0; f < length; f++) {
        if (componentDecls[f].binding != component)
            continue;
        // component cannot be static, hence no static initializer scope
        MethodScope initializationScope = this.scope.referenceContext.initializerScope;
        RecordComponent componentDecl = componentDecls[f];
        TypeBinding componentType = componentDecl.type.resolveType(initializationScope, true);
        component.type = componentType;
        component.modifiers &= ~ExtraCompilerModifiers.AccUnresolved;
        if (componentType == null) {
            componentDecl.binding = null;
            return null;
        }
        if (componentType == TypeBinding.VOID) {
            this.scope.problemReporter().recordComponentCannotBeVoid(componentDecl);
            componentDecl.binding = null;
            return null;
        }
        if (componentType.isArrayType() && ((ArrayBinding) componentType).leafComponentType == TypeBinding.VOID) {
            this.scope.problemReporter().variableTypeCannotBeVoidArray(componentDecl);
            componentDecl.binding = null;
            return null;
        }
        if ((componentType.tagBits & TagBits.HasMissingType) != 0) {
            component.tagBits |= TagBits.HasMissingType;
        }
        TypeBinding leafType = componentType.leafComponentType();
        if (leafType instanceof ReferenceBinding && (((ReferenceBinding) leafType).modifiers & ExtraCompilerModifiers.AccGenericSignature) != 0) {
            component.modifiers |= ExtraCompilerModifiers.AccGenericSignature;
        }
        Annotation[] annotations = componentDecl.annotations;
        ASTNode.copyRecordComponentAnnotations(initializationScope, component, annotations);
        long sourceLevel = this.scope.compilerOptions().sourceLevel;
        if (sourceLevel >= ClassFileConstants.JDK1_8) {
            if (annotations != null && annotations.length != 0) {
                // piggybacking on an existing method to move type_use annotations to type in record component
                ASTNode.copySE8AnnotationsToType(initializationScope, component, annotations, false);
            }
            Annotation.isTypeUseCompatible(componentDecl.type, this.scope, annotations);
        }
        if (// fieldDecl.type is null for enum constants
        initializationScope.shouldCheckAPILeaks(this, component.isPublic()) && componentDecl.type != null)
            initializationScope.detectAPILeaks(componentDecl.type, componentType);
        if (this.externalAnnotationProvider != null) {
            ExternalAnnotationSuperimposer.annotateComponentBinding(component, this.externalAnnotationProvider, this.environment);
        }
        return component;
    }
    // should never reach this point
    return null;
}
Also used : Annotation(org.eclipse.jdt.internal.compiler.ast.Annotation) RecordComponent(org.eclipse.jdt.internal.compiler.ast.RecordComponent)

Example 2 with RecordComponent

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

the class ClassScope method buildComponents.

void buildComponents() {
    SourceTypeBinding sourceType = this.referenceContext.binding;
    if (!sourceType.isRecord())
        return;
    if (sourceType.areComponentsInitialized())
        return;
    if (this.referenceContext.recordComponents == null) {
        sourceType.setComponents(Binding.NO_COMPONENTS);
        return;
    }
    // count the number of fields vs. initializers
    RecordComponent[] recComps = this.referenceContext.recordComponents;
    int size = recComps.length;
    int count = size;
    // iterate the field declarations to create the bindings, lose all duplicates
    RecordComponentBinding[] componentBindings = new RecordComponentBinding[count];
    HashtableOfObject knownComponentNames = new HashtableOfObject(count);
    count = 0;
    for (int i = 0; i < size; i++) {
        RecordComponent recComp = recComps[i];
        RecordComponentBinding compBinding = new RecordComponentBinding(sourceType, recComp, null, recComp.modifiers | ExtraCompilerModifiers.AccUnresolved);
        compBinding.id = count;
        checkAndSetModifiersForComponents(compBinding, recComp);
        if (knownComponentNames.containsKey(recComp.name)) {
            RecordComponentBinding previousBinding = (RecordComponentBinding) knownComponentNames.get(recComp.name);
            if (previousBinding != null) {
                for (int f = 0; f < i; f++) {
                    RecordComponent previousComponent = recComps[f];
                    if (previousComponent.binding == previousBinding) {
                        // flag the duplicate component name error here.
                        problemReporter().recordDuplicateComponent(previousComponent);
                        break;
                    }
                }
            }
            // ensure that the duplicate field is found & removed
            knownComponentNames.put(recComp.name, null);
            problemReporter().recordDuplicateComponent(recComp);
            recComp.binding = null;
        } else {
            knownComponentNames.put(recComp.name, compBinding);
            // remember that we have seen a component with this name
            componentBindings[count++] = compBinding;
        }
    }
    // remove duplicate components
    if (count != componentBindings.length)
        System.arraycopy(componentBindings, 0, componentBindings = new RecordComponentBinding[count], 0, count);
    sourceType.setComponents(componentBindings);
    if (size > 0) {
        sourceType.isVarArgs = recComps[size - 1].isVarArgs();
    }
}
Also used : HashtableOfObject(org.eclipse.jdt.internal.compiler.util.HashtableOfObject) RecordComponent(org.eclipse.jdt.internal.compiler.ast.RecordComponent)

Example 3 with RecordComponent

use of org.eclipse.jdt.internal.compiler.ast.RecordComponent 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)

Example 4 with RecordComponent

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

the class ClassFile method addComponentAttributes.

private int addComponentAttributes(RecordComponentBinding recordComponentBinding, int componetAttributeOffset) {
    // See JVMS 14 Table 4.7-C - Record Preview for allowed attributes
    int attributesNumber = 0;
    // add signature attribute
    char[] genericSignature = recordComponentBinding.genericSignature();
    if (genericSignature != null) {
        attributesNumber += generateSignatureAttribute(genericSignature);
    }
    RecordComponent recordComponent = recordComponentBinding.sourceRecordComponent();
    if (recordComponent != null) {
        Annotation[] annotations = recordComponent.annotations;
        if (annotations != null) {
            attributesNumber += generateRuntimeAnnotations(annotations, TagBits.AnnotationForRecordComponent);
        }
        if ((this.produceAttributes & ClassFileConstants.ATTR_TYPE_ANNOTATION) != 0) {
            List<AnnotationContext> allTypeAnnotationContexts = new ArrayList<>();
            if (annotations != null && (recordComponent.bits & ASTNode.HasTypeAnnotations) != 0) {
                recordComponent.getAllAnnotationContexts(AnnotationTargetTypeConstants.FIELD, allTypeAnnotationContexts);
            }
            TypeReference recordComponentType = recordComponent.type;
            if (recordComponentType != null && ((recordComponentType.bits & ASTNode.HasTypeAnnotations) != 0)) {
                recordComponentType.getAllAnnotationContexts(AnnotationTargetTypeConstants.RECORD_COMPONENT, allTypeAnnotationContexts);
            }
            int size = allTypeAnnotationContexts.size();
            attributesNumber = completeRuntimeTypeAnnotations(attributesNumber, null, (node) -> size > 0, () -> allTypeAnnotationContexts);
        }
    }
    if ((recordComponentBinding.tagBits & TagBits.HasMissingType) != 0) {
        this.missingTypes = recordComponentBinding.type.collectMissingTypes(this.missingTypes);
    }
    return attributesNumber;
}
Also used : TypeAnnotationCodeStream(org.eclipse.jdt.internal.compiler.codegen.TypeAnnotationCodeStream) Arrays(java.util.Arrays) QualifiedNameReference(org.eclipse.jdt.internal.compiler.ast.QualifiedNameReference) OpensStatement(org.eclipse.jdt.internal.compiler.ast.OpensStatement) ClassLiteralAccess(org.eclipse.jdt.internal.compiler.ast.ClassLiteralAccess) Receiver(org.eclipse.jdt.internal.compiler.ast.Receiver) LocalVariableBinding(org.eclipse.jdt.internal.compiler.lookup.LocalVariableBinding) ProblemSeverities(org.eclipse.jdt.internal.compiler.problem.ProblemSeverities) FieldBinding(org.eclipse.jdt.internal.compiler.lookup.FieldBinding) ModuleBinding(org.eclipse.jdt.internal.compiler.lookup.ModuleBinding) AnnotationMethodDeclaration(org.eclipse.jdt.internal.compiler.ast.AnnotationMethodDeclaration) MethodScope(org.eclipse.jdt.internal.compiler.lookup.MethodScope) PolymorphicMethodBinding(org.eclipse.jdt.internal.compiler.lookup.PolymorphicMethodBinding) MemberValuePair(org.eclipse.jdt.internal.compiler.ast.MemberValuePair) ShouldNotImplement(org.eclipse.jdt.internal.compiler.problem.ShouldNotImplement) Expression(org.eclipse.jdt.internal.compiler.ast.Expression) TagBits(org.eclipse.jdt.internal.compiler.lookup.TagBits) Map(java.util.Map) TypeBinding(org.eclipse.jdt.internal.compiler.lookup.TypeBinding) VerificationTypeInfo(org.eclipse.jdt.internal.compiler.codegen.VerificationTypeInfo) FieldDeclaration(org.eclipse.jdt.internal.compiler.ast.FieldDeclaration) Messages(org.eclipse.jdt.internal.compiler.util.Messages) MethodBinding(org.eclipse.jdt.internal.compiler.lookup.MethodBinding) Argument(org.eclipse.jdt.internal.compiler.ast.Argument) Predicate(java.util.function.Predicate) ProblemReasons(org.eclipse.jdt.internal.compiler.lookup.ProblemReasons) CategorizedProblem(org.eclipse.jdt.core.compiler.CategorizedProblem) SyntheticMethodBinding(org.eclipse.jdt.internal.compiler.lookup.SyntheticMethodBinding) Set(java.util.Set) RecordComponent(org.eclipse.jdt.internal.compiler.ast.RecordComponent) TypeReference(org.eclipse.jdt.internal.compiler.ast.TypeReference) Collectors(java.util.stream.Collectors) CaseStatement(org.eclipse.jdt.internal.compiler.ast.CaseStatement) SingleMemberAnnotation(org.eclipse.jdt.internal.compiler.ast.SingleMemberAnnotation) NormalAnnotation(org.eclipse.jdt.internal.compiler.ast.NormalAnnotation) TypeParameter(org.eclipse.jdt.internal.compiler.ast.TypeParameter) ArrayBinding(org.eclipse.jdt.internal.compiler.lookup.ArrayBinding) List(java.util.List) Constant(org.eclipse.jdt.internal.compiler.impl.Constant) TypeIds(org.eclipse.jdt.internal.compiler.lookup.TypeIds) Util(org.eclipse.jdt.internal.compiler.util.Util) SingleNameReference(org.eclipse.jdt.internal.compiler.ast.SingleNameReference) Annotation(org.eclipse.jdt.internal.compiler.ast.Annotation) IProblem(org.eclipse.jdt.core.compiler.IProblem) TypeDeclaration(org.eclipse.jdt.internal.compiler.ast.TypeDeclaration) CompilerOptions(org.eclipse.jdt.internal.compiler.impl.CompilerOptions) AnnotationContext(org.eclipse.jdt.internal.compiler.codegen.AnnotationContext) CompilationUnitDeclaration(org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration) ClassFileConstants(org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants) AnnotationTargetTypeConstants(org.eclipse.jdt.internal.compiler.codegen.AnnotationTargetTypeConstants) StringLiteral(org.eclipse.jdt.internal.compiler.ast.StringLiteral) SourceTypeBinding(org.eclipse.jdt.internal.compiler.lookup.SourceTypeBinding) LambdaExpression(org.eclipse.jdt.internal.compiler.ast.LambdaExpression) HashMap(java.util.HashMap) ASTNode(org.eclipse.jdt.internal.compiler.ast.ASTNode) RequiresStatement(org.eclipse.jdt.internal.compiler.ast.RequiresStatement) Opcodes(org.eclipse.jdt.internal.compiler.codegen.Opcodes) AbortType(org.eclipse.jdt.internal.compiler.problem.AbortType) SyntheticArgumentBinding(org.eclipse.jdt.internal.compiler.lookup.SyntheticArgumentBinding) Supplier(java.util.function.Supplier) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) StackMapFrame(org.eclipse.jdt.internal.compiler.codegen.StackMapFrame) Binding(org.eclipse.jdt.internal.compiler.lookup.Binding) ExceptionLabel(org.eclipse.jdt.internal.compiler.codegen.ExceptionLabel) FunctionalExpression(org.eclipse.jdt.internal.compiler.ast.FunctionalExpression) ReferenceExpression(org.eclipse.jdt.internal.compiler.ast.ReferenceExpression) AttributeNamesConstants(org.eclipse.jdt.internal.compiler.codegen.AttributeNamesConstants) MethodDeclaration(org.eclipse.jdt.internal.compiler.ast.MethodDeclaration) SwitchStatement(org.eclipse.jdt.internal.compiler.ast.SwitchStatement) ExceptionMarker(org.eclipse.jdt.internal.compiler.codegen.StackMapFrameCodeStream.ExceptionMarker) LookupEnvironment(org.eclipse.jdt.internal.compiler.lookup.LookupEnvironment) TypeVariableBinding(org.eclipse.jdt.internal.compiler.lookup.TypeVariableBinding) Scope(org.eclipse.jdt.internal.compiler.lookup.Scope) Iterator(java.util.Iterator) ArrayInitializer(org.eclipse.jdt.internal.compiler.ast.ArrayInitializer) ReferenceBinding(org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding) ModuleDeclaration(org.eclipse.jdt.internal.compiler.ast.ModuleDeclaration) CodeStream(org.eclipse.jdt.internal.compiler.codegen.CodeStream) LocalTypeBinding(org.eclipse.jdt.internal.compiler.lookup.LocalTypeBinding) ProblemReferenceBinding(org.eclipse.jdt.internal.compiler.lookup.ProblemReferenceBinding) LocalDeclaration(org.eclipse.jdt.internal.compiler.ast.LocalDeclaration) CharOperation(org.eclipse.jdt.core.compiler.CharOperation) StackMapFrameCodeStream(org.eclipse.jdt.internal.compiler.codegen.StackMapFrameCodeStream) ExportsStatement(org.eclipse.jdt.internal.compiler.ast.ExportsStatement) TypeConstants(org.eclipse.jdt.internal.compiler.lookup.TypeConstants) AbortMethod(org.eclipse.jdt.internal.compiler.problem.AbortMethod) StringConstant(org.eclipse.jdt.internal.compiler.impl.StringConstant) AbstractMethodDeclaration(org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration) Comparator(java.util.Comparator) Collections(java.util.Collections) ConstantPool(org.eclipse.jdt.internal.compiler.codegen.ConstantPool) RecordComponentBinding(org.eclipse.jdt.internal.compiler.lookup.RecordComponentBinding) ArrayList(java.util.ArrayList) TypeReference(org.eclipse.jdt.internal.compiler.ast.TypeReference) AnnotationContext(org.eclipse.jdt.internal.compiler.codegen.AnnotationContext) SingleMemberAnnotation(org.eclipse.jdt.internal.compiler.ast.SingleMemberAnnotation) NormalAnnotation(org.eclipse.jdt.internal.compiler.ast.NormalAnnotation) Annotation(org.eclipse.jdt.internal.compiler.ast.Annotation) RecordComponent(org.eclipse.jdt.internal.compiler.ast.RecordComponent)

Example 5 with RecordComponent

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

the class RecordComponentBinding method getAnnotationTagBits.

@Override
public long getAnnotationTagBits() {
    RecordComponentBinding originalRecordComponentBinding = original();
    if ((originalRecordComponentBinding.tagBits & TagBits.AnnotationResolved) == 0 && originalRecordComponentBinding.declaringRecord instanceof SourceTypeBinding) {
        ClassScope scope = ((SourceTypeBinding) originalRecordComponentBinding.declaringRecord).scope;
        if (scope == null) {
            // should not be true - but safety net
            this.tagBits |= (TagBits.AnnotationResolved | TagBits.DeprecatedAnnotationResolved);
            return 0;
        }
        TypeDeclaration typeDecl = scope.referenceContext;
        RecordComponent recordComponent = typeDecl.declarationOf(originalRecordComponentBinding);
        if (recordComponent != null) {
            ASTNode.resolveAnnotations(typeDecl.initializerScope, recordComponent.annotations, originalRecordComponentBinding);
        }
    }
    return originalRecordComponentBinding.tagBits;
}
Also used : TypeDeclaration(org.eclipse.jdt.internal.compiler.ast.TypeDeclaration) RecordComponent(org.eclipse.jdt.internal.compiler.ast.RecordComponent)

Aggregations

RecordComponent (org.eclipse.jdt.internal.compiler.ast.RecordComponent)8 RecordComponentBinding (org.eclipse.jdt.internal.compiler.lookup.RecordComponentBinding)5 SourceTypeBinding (org.eclipse.jdt.internal.compiler.lookup.SourceTypeBinding)5 Annotation (org.eclipse.jdt.internal.compiler.ast.Annotation)4 Argument (org.eclipse.jdt.internal.compiler.ast.Argument)4 ArrayList (java.util.ArrayList)3 Arrays (java.util.Arrays)3 Collections (java.util.Collections)3 Comparator (java.util.Comparator)3 HashMap (java.util.HashMap)3 HashSet (java.util.HashSet)3 Iterator (java.util.Iterator)3 List (java.util.List)3 Map (java.util.Map)3 Set (java.util.Set)3 Predicate (java.util.function.Predicate)3 Supplier (java.util.function.Supplier)3 Collectors (java.util.stream.Collectors)3 CategorizedProblem (org.eclipse.jdt.core.compiler.CategorizedProblem)3 CharOperation (org.eclipse.jdt.core.compiler.CharOperation)3