Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/realm_generator/lib/src/class_element_ex.dart
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ extension ClassElementEx on ClassElement {
return null;
}

final modelName = this.name;
final modelName = this.displayName;

// ensure a valid prefix and suffix is used.
final prefix = session.prefix;
Expand Down
6 changes: 3 additions & 3 deletions packages/realm_generator/lib/src/dart_type_ex.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ import 'session.dart';
import 'type_checkers.dart';

extension DartTypeEx on DartType {
bool isExactly<T>() => TypeChecker.fromRuntime(T).isExactlyType(this);
bool isA<T>() => TypeChecker.fromRuntime(T).isAssignableFromType(this);
bool isExactly<T>() => TypeChecker.typeNamed(T).isExactlyType(this);
bool isA<T>() => TypeChecker.typeNamed(T).isAssignableFromType(this);

bool get isRealmValue => const TypeChecker.fromRuntime(RealmValue).isAssignableFromType(this);
bool get isRealmValue => const TypeChecker.typeNamed(RealmValue).isAssignableFromType(this);
bool get isRealmCollection => realmCollectionType != RealmCollectionType.none;
bool get isRealmSet => realmCollectionType == RealmCollectionType.set;

Expand Down
4 changes: 2 additions & 2 deletions packages/realm_generator/lib/src/element.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ import 'session.dart';
import 'type_checkers.dart';
import 'utils.dart';

ElementDeclarationResult? getDeclarationFromElement(Element element) {
return session.resolvedLibrary.getElementDeclaration(element);
FragmentDeclarationResult? getDeclarationFromElement(Element element) {
return session.resolvedLibrary.getFragmentDeclaration(element.firstFragment);
}

extension on FileSpan {
Expand Down
2 changes: 1 addition & 1 deletion packages/realm_generator/lib/src/error.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class RealmInvalidGenerationSourceError extends InvalidGenerationSourceError {
color = color ?? session.color,
super(element: element) {
if (element is FieldElement || element is ConstructorElement) {
final classElement = element.enclosingElement3!;
final classElement = element.enclosingElement!;
this.secondarySpans.addAll({
classElement.span!: "in realm model for '${session.mapping.entries.where((e) => e.value == classElement).singleOrNull?.key}'",
});
Expand Down
16 changes: 8 additions & 8 deletions packages/realm_generator/lib/src/field_element_ex.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import 'type_checkers.dart';
extension FieldElementEx on FieldElement {
static const realmSetUnsupportedRealmTypes = [RealmPropertyType.linkingObjects];

ClassElement get enclosingClassElement => enclosingElement3 as ClassElement;
ClassElement get enclosingClassElement => enclosingElement as ClassElement;

FieldDeclaration get declarationAstNode => getDeclarationFromElement(this)!.node.parent!.parent as FieldDeclaration;

Expand All @@ -38,7 +38,7 @@ extension FieldElementEx on FieldElement {

TypeAnnotation? get typeAnnotation => declarationAstNode.fields.type;

Expression? get initializerExpression => declarationAstNode.fields.variables.singleWhere((v) => v.name.toString() == name).initializer;
Expression? get initializerExpression => declarationAstNode.fields.variables.singleWhere((v) => v.name.toString() == displayName).initializer;

FileSpan? typeSpan(SourceFile file) => ExpandedContextSpan(
ExpandedContextSpan(
Expand Down Expand Up @@ -163,7 +163,7 @@ extension FieldElementEx on FieldElement {
String? linkOriginProperty;

// Validate field type
final modelSpan = enclosingElement3.span!;
final modelSpan = enclosingElement.span!;
final file = modelSpan.file;
final realmType = type.realmType;
if (realmType == null) {
Expand All @@ -185,7 +185,7 @@ extension FieldElementEx on FieldElement {
primarySpan: typeSpan(file),
primaryLabel: '$modelTypeName is not a realm model type',
secondarySpans: {
modelSpan: "in realm model '${enclosingElement3.displayName}'",
modelSpan: "in realm model '${enclosingElement.displayName}'",
// may go both above and below, or stem from another file
if (notARealmTypeSpan != null) notARealmTypeSpan: ''
},
Expand Down Expand Up @@ -281,7 +281,7 @@ extension FieldElementEx on FieldElement {

final sourceFieldName = backlink.value.getField('fieldName')?.toSymbolValue();
final sourceType = (type as ParameterizedType).typeArguments.first;
final sourceField = (sourceType.element as ClassElement?)?.fields.where((f) => f.name == sourceFieldName).singleOrNull;
final sourceField = (sourceType.element as ClassElement?)?.fields.where((f) => f.displayName == sourceFieldName).singleOrNull;

if (sourceField == null) {
throw RealmInvalidGenerationSourceError(
Expand All @@ -293,7 +293,7 @@ extension FieldElementEx on FieldElement {
);
}

final thisType = (enclosingElement3 as ClassElement).thisType;
final thisType = (enclosingElement as ClassElement).thisType;
final linkType = thisType.asNullable;
final listOf = session.typeProvider.listType(thisType);
if (sourceField.type != linkType && sourceField.type != listOf) {
Expand All @@ -307,7 +307,7 @@ extension FieldElementEx on FieldElement {
}

// everything is kosher, just need to account for @MapTo!
linkOriginProperty = sourceField.remappedRealmName ?? sourceField.name;
linkOriginProperty = sourceField.remappedRealmName ?? sourceField.displayName;
}

// Validate object references
Expand Down Expand Up @@ -398,7 +398,7 @@ extension FieldElementEx on FieldElement {
ParenthesizedExpression i => _isValidFieldInitializer(i.expression),
PrefixExpression e => _isValidFieldInitializer(e.operand),
BinaryExpression b => _isValidFieldInitializer(b.leftOperand) && _isValidFieldInitializer(b.rightOperand),
Identifier i => (i.staticElement as PropertyAccessorElement?)?.variable2?.isConst ?? false,
Identifier i => (i.element as PropertyAccessorElement?)?.variable.isConst ?? false,
_ => false,
};
}
Expand Down
2 changes: 1 addition & 1 deletion packages/realm_generator/lib/src/realm_field_info.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class RealmFieldInfo {
bool get isDartCoreSet => type.isDartCoreSet;
bool get isDartCoreMap => type.isDartCoreMap;

String get name => fieldElement.name;
String get name => fieldElement.displayName;
String get realmName => mapTo ?? name;

String get basicMappedTypeName => type.basicMappedName;
Expand Down
12 changes: 6 additions & 6 deletions packages/realm_generator/lib/src/type_checkers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
import 'package:realm_common/realm_common.dart';
import 'package:source_gen/source_gen.dart';

const ignoredChecker = TypeChecker.fromRuntime(Ignored);
const ignoredChecker = TypeChecker.typeNamed(Ignored);

const indexedChecker = TypeChecker.fromRuntime(Indexed);
const indexedChecker = TypeChecker.typeNamed(Indexed);

const mapToChecker = TypeChecker.fromRuntime(MapTo);
const mapToChecker = TypeChecker.typeNamed(MapTo);

const primaryKeyChecker = TypeChecker.fromRuntime(PrimaryKey);
const primaryKeyChecker = TypeChecker.typeNamed(PrimaryKey);

const backlinkChecker = TypeChecker.fromRuntime(Backlink);
const backlinkChecker = TypeChecker.typeNamed(Backlink);

const realmAnnotationChecker = TypeChecker.any([
ignoredChecker,
Expand All @@ -21,4 +21,4 @@ const realmAnnotationChecker = TypeChecker.any([
primaryKeyChecker,
]);

const realmModelChecker = TypeChecker.fromRuntime(RealmModel);
const realmModelChecker = TypeChecker.typeNamed(RealmModel);
19 changes: 9 additions & 10 deletions packages/realm_generator/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,24 @@ repository: https://github.com/realm/realm-dart
issue_tracker: https://github.com/realm/realm-dart/issues

environment:
sdk: ^3.6.0
sdk: ^3.7.0

dependencies:
analyzer: ^7.3.0
build_resolvers: ^2.4.3
build: '2.4.2'
dart_style: ^3.0.1
analyzer: ^8.0.0
build: 4.0.2
dart_style: ^3.1.1
realm_common: ^20.2.0
source_gen: ^2.0.0
source_gen: ^4.0.0
source_span: ^1.8.0
collection: ^1.19.0

dev_dependencies:
build_runner: ^2.4.14
build_test: ^2.2.2
lints: ^5.1.1
build_runner: ^2.6.0
build_test: ^3.0.0
lints: ^6.0.0
logging: ^1.2.0
meta: ^1.15.0
path: ^1.9.0
term_glyph: ^1.2.0
test: ^1.25.9
test: ^1.26.3
pub_semver: ^2.2.0
5 changes: 2 additions & 3 deletions packages/realm_generator/test/common.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import 'package:analyzer/dart/analysis/results.dart';
import 'package:analyzer/diagnostic/diagnostic.dart';
import 'package:analyzer/error/error.dart';
import 'package:build_test/build_test.dart';
import 'package:test/test.dart';

Expand All @@ -16,7 +15,7 @@ $src
}, (r) => r.findLibraryByName('main'));

final errorResult = await main!.session.getErrors('/realm/test/integration/main.dart') as ErrorsResult;
final criticalErrors = errorResult.errors.where((element) => element.severity == Severity.error).toList();
final criticalErrors = errorResult.diagnostics.where((element) => element.severity == Severity.error).toList();

if (criticalErrors.isNotEmpty) {
throw CompileError(criticalErrors);
Expand All @@ -25,7 +24,7 @@ $src

class CompileError extends Error {
CompileError(this.errors);
final List<AnalysisError> errors;
final List<Diagnostic> errors;

@override
String toString() {
Expand Down