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;
}
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();
}
}
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);
}
}
}
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;
}
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;
}
Aggregations