-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(Represented by AttributeDeclaration in the RedHat AST) CC #46.
- Loading branch information
1 parent
21ee921
commit 410ab4e
Showing
11 changed files
with
132 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
"""An attribute definition, using a specifier. | ||
Examples: | ||
shared actual String string => "``name`` from ``countryOfOrigin`` of age ``age``"; | ||
shared actual Null definition = null;""" | ||
shared class AttributeDefinition(name, type, definition, annotations = Annotations()) | ||
extends AnyAttribute() { | ||
|
||
shared actual MemberName name; | ||
"The type of the attribute. | ||
This can be: | ||
- a proper [[Type]], | ||
- a [[’`value`’ modifier|ValueModifier]] to indicate type inference, or | ||
- a [[’`dynamic`’ modifier|DynamicModifier]] to indicate the absence of a type." | ||
shared actual Type|ValueModifier|DynamicModifier type; | ||
"The definition of the attribute." | ||
shared actual AnySpecifier definition; | ||
shared actual Annotations annotations; | ||
|
||
shared actual [Annotations, Type|ValueModifier|DynamicModifier, LIdentifier, AnySpecifier] children = [annotations, type, name, definition]; | ||
|
||
shared actual Result transform<out Result>(Transformer<Result> transformer) | ||
=> transformer.transformAttributeDefinition(this); | ||
|
||
shared actual Boolean equals(Object that) { | ||
if (is AttributeDefinition that) { | ||
return name == that.name && type == that.type && definition == that.definition && annotations == that.annotations; | ||
} else { | ||
return false; | ||
} | ||
} | ||
|
||
shared actual Integer hash | ||
=> 31 * (name.hash + 31 * (type.hash + 31 * (definition.hash + 31 * annotations.hash))); | ||
|
||
shared AttributeDefinition copy(MemberName name = this.name, Type|ValueModifier|DynamicModifier type = this.type, AnySpecifier definition = this.definition, Annotations annotations = this.annotations) { | ||
value ret = AttributeDefinition(name, type, definition, annotations); | ||
copyExtraInfoTo(ret); | ||
return ret; | ||
} | ||
} |
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
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,46 @@ | ||
import ceylon.ast.core { | ||
AttributeDefinition, | ||
Type, | ||
ValueModifier, | ||
DynamicModifier | ||
} | ||
import com.redhat.ceylon.compiler.typechecker.tree { | ||
Tree { | ||
JAttributeDeclaration=AttributeDeclaration, | ||
JDynamicModifier=DynamicModifier, | ||
JSpecifierExpression=SpecifierExpression, | ||
JStaticType=StaticType, | ||
JValueModifier=ValueModifier | ||
} | ||
} | ||
|
||
"Converts a RedHat AST [[AttributeDeclaration|JAttributeDeclaration]] to a `ceylon.ast` [[AttributeDefinition]]." | ||
shared AttributeDefinition attributeDefinitionToCeylon(JAttributeDeclaration attributeDefinition) { | ||
"Must be defined" | ||
// The other case type of SpecifierOrInitializerExpression, InitializerExpression, is obsolete | ||
assert (is JSpecifierExpression definition = attributeDefinition.specifierOrInitializerExpression); | ||
assert (is JStaticType|JValueModifier|JDynamicModifier jType = attributeDefinition.type); | ||
Type|ValueModifier|DynamicModifier type; | ||
switch (jType) | ||
case (is JStaticType) { type = typeToCeylon(jType); } | ||
case (is JValueModifier) { type = valueModifierToCeylon(jType); } | ||
case (is JDynamicModifier) { type = dynamicModifierToCeylon(jType); } | ||
return AttributeDefinition { | ||
annotations = annotationsToCeylon(attributeDefinition.annotationList); | ||
type = type; | ||
name = lIdentifierToCeylon(attributeDefinition.identifier); | ||
definition = anySpecifierToCeylon(definition); | ||
}; | ||
} | ||
|
||
"Compiles the given [[code]] for an Attribute Definition | ||
into an [[AttributeDefinition]] using the Ceylon compiler | ||
(more specifically, the rule for a `declaration`)." | ||
shared AttributeDefinition? compileAttributeDefinition(String code) { | ||
if (is JAttributeDeclaration jDeclaration = createParser(code).declaration(), | ||
jDeclaration.specifierOrInitializerExpression exists) { | ||
return attributeDefinitionToCeylon(jDeclaration); | ||
} else { | ||
return null; | ||
} | ||
} |
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