-
Notifications
You must be signed in to change notification settings - Fork 0
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
fa1015c
commit bfa5f80
Showing
14 changed files
with
230 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
use strum_macros::{EnumString, Display, AsRefStr}; | ||
use crate::{AnyNode, DebugRange, NamedSyntaxNode, SyntaxNode}; | ||
use crate::tokens::{AnnotationIdentifierNode, IdentifierNode}; | ||
|
||
|
||
mod tags { | ||
pub struct Annotation; | ||
} | ||
|
||
#[derive(Debug, Clone, Copy, PartialEq, Eq, EnumString, Display, AsRefStr)] | ||
pub enum AnnotationKind { | ||
#[strum(serialize="@addMethod")] | ||
AddMethod, | ||
#[strum(serialize="@addField")] | ||
AddField, | ||
#[strum(serialize="@replaceMethod")] | ||
ReplaceMethod, | ||
#[strum(serialize="@wrapMethod")] | ||
WrapMethod | ||
} | ||
|
||
pub const WRAPPED_METHOD_NAME: &'static str = "wrappedMethod"; | ||
|
||
|
||
pub type AnnotationNode<'script> = SyntaxNode<'script, tags::Annotation>; | ||
|
||
impl NamedSyntaxNode for AnnotationNode<'_> { | ||
const NODE_KIND: &'static str = "annotation"; | ||
} | ||
|
||
impl<'script> AnnotationNode<'script> { | ||
pub fn name(&self) -> AnnotationIdentifierNode<'script> { | ||
self.field_child("name").unwrap().into() | ||
} | ||
|
||
pub fn arg(&self) -> Option<IdentifierNode<'script>> { | ||
self.field_child("arg").map(|n| n.into()) | ||
} | ||
} | ||
|
||
impl std::fmt::Debug for AnnotationNode<'_> { | ||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
f.debug_struct(&format!("Annotation {}", self.range().debug())) | ||
.field("name", &self.name()) | ||
.field("arg", &self.arg()) | ||
.finish() | ||
} | ||
} | ||
|
||
impl<'script> TryFrom<AnyNode<'script>> for AnnotationNode<'script> { | ||
type Error = (); | ||
|
||
fn try_from(value: AnyNode<'script>) -> Result<Self, Self::Error> { | ||
if value.tree_node.kind() == Self::NODE_KIND { | ||
Ok(value.into()) | ||
} else { | ||
Err(()) | ||
} | ||
} | ||
} |
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
Oops, something went wrong.