-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4df0ee6
commit 7e5449f
Showing
17 changed files
with
473 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
89 changes: 89 additions & 0 deletions
89
pkgs/swift2objc/lib/src/parser/parsers/declaration_parsers/parse_property_declaration.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
import '../../../ast/_core/interfaces/declaration.dart'; | ||
import '../../../ast/_core/shared/referred_type.dart'; | ||
import '../../../ast/declarations/compounds/class_declaration.dart'; | ||
import '../../_core/json.dart'; | ||
import '../../_core/parsed_symbolgraph.dart'; | ||
import '../../_core/utils.dart'; | ||
import '../parse_declarations.dart'; | ||
|
||
ClassPropertyDeclaration parsePropertyDeclaration( | ||
Json propertySymbolJson, | ||
ParsedSymbolgraph symbolgraph, | ||
) { | ||
return ClassPropertyDeclaration( | ||
id: parseSymbolId(propertySymbolJson), | ||
name: parseSymbolName(propertySymbolJson), | ||
type: _parsePropertyType(propertySymbolJson, symbolgraph), | ||
hasObjCAnnotation: symbolHasObjcAnnotation(propertySymbolJson), | ||
hasSetter: _propertyHasSetter(propertySymbolJson), | ||
); | ||
} | ||
|
||
ReferredType _parsePropertyType( | ||
Json propertySymbolJson, | ||
ParsedSymbolgraph symbolgraph, | ||
) { | ||
final subHeadings = propertySymbolJson['names']['subHeading']; | ||
|
||
final typeSymbolJson = | ||
subHeadings.firstJsonWhereKey('kind', 'typeIdentifier'); | ||
final typeSymbolId = typeSymbolJson['preciseIdentifier'].get<String>(); | ||
final typeSymbol = symbolgraph.symbols[typeSymbolId]; | ||
|
||
if (typeSymbol == null) { | ||
throw Exception( | ||
'The property at path "${propertySymbolJson.path}" has a return type ' | ||
'that does not exist among parsed symbols.', | ||
); | ||
} | ||
|
||
final typeDeclaration = parseDeclaration( | ||
typeSymbol, | ||
symbolgraph, | ||
); | ||
|
||
return typeDeclaration.asDeclaredType; | ||
} | ||
|
||
bool _propertyHasSetter(Json propertySymbolJson) { | ||
final fragmentsJson = propertySymbolJson['declarationFragments']; | ||
|
||
final declarationKeywordJson = fragmentsJson.firstWhere( | ||
(json) { | ||
if (json['kind'].get<String>() != 'keyword') return false; | ||
|
||
final keyword = json['spelling'].get<String>(); | ||
if (keyword != 'var' && keyword != 'let') return false; | ||
|
||
return true; | ||
}, | ||
orElse: () => throw ArgumentError( | ||
'Invalid property declaration fragments at path: ${fragmentsJson.path}. ' | ||
'Expected to find "var" or "let" as a keyword, found none', | ||
), | ||
); | ||
|
||
final declarationKeyword = declarationKeywordJson['spelling'].get<String>(); | ||
|
||
if (declarationKeyword == 'var') { | ||
final hasExplicitSetter = fragmentsJson.any( | ||
(json) => json['spelling'].get<String>() == 'set', | ||
); | ||
|
||
final hasExplicitGetter = fragmentsJson.any( | ||
(json) => json['spelling'].get<String>() == 'get', | ||
); | ||
|
||
if (hasExplicitGetter) { | ||
if (hasExplicitSetter) { | ||
return true; | ||
} else { | ||
return false; | ||
} | ||
} | ||
|
||
return true; | ||
} | ||
|
||
return false; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import '../../ast/_core/interfaces/declaration.dart'; | ||
import '../../ast/_core/shared/referred_type.dart'; | ||
import '../../ast/declarations/compounds/class_declaration.dart'; | ||
import '../transform.dart'; | ||
import 'unique_namer.dart'; | ||
|
||
(String value, ReferredType type) maybeWrapValue( | ||
ReferredType type, | ||
String valueIdentifier, | ||
UniqueNamer globalNamer, | ||
TransformationMap transformationMap, | ||
) { | ||
if (type is GenericType) { | ||
throw UnimplementedError('Generic types are not implemented yet'); | ||
} | ||
|
||
type as DeclaredType; | ||
|
||
if (type.isObjCRepresentable) { | ||
return (valueIdentifier, type); | ||
} | ||
|
||
final transformedTypeDeclaration = transformDeclaration( | ||
type.declaration, | ||
globalNamer, | ||
transformationMap, | ||
); | ||
|
||
return ( | ||
'${transformedTypeDeclaration.name}($valueIdentifier)', | ||
transformedTypeDeclaration.asDeclaredType | ||
); | ||
} | ||
|
||
(String value, ReferredType type) maybeUnwrapValue( | ||
ReferredType type, | ||
String valueIdentifier, | ||
) { | ||
if (type is GenericType) { | ||
throw UnimplementedError('Generic types are not implemented yet'); | ||
} | ||
|
||
final declaration = (type as DeclaredType).declaration; | ||
|
||
if (declaration is ClassDeclaration && declaration.wrappedInstance != null) { | ||
final wrappedInstance = declaration.wrappedInstance; | ||
return ('$valueIdentifier.${wrappedInstance!.name}', wrappedInstance.type); | ||
} else { | ||
return (valueIdentifier, type); | ||
} | ||
} |
Oops, something went wrong.