package edu.neu.ccs.demeter.tools.weave; import java.io.*; import java.util.*; import java.util.zip.*; import java.lang.reflect.*; /* * Weaver */ public Weaver = Aspect ":" CodeFrags *EOF* . Aspect = Ident . CodeFrags ~ {CodeFrag} . CodeFrag = AdjustItem . AdjustItem : *lookahead* (@ "add:" ("public"|"final"|"abstract")* "class" @) AddClass | *lookahead* (@ "add:" ("public"|"final"|"abstract")* "interface" @) AddInterface | *lookahead* (@2@) AddAttribute | AugmentMethod | ImplementInterface | RenameMethod | PackageSpec | ImportStatement | VarAssignment . /* * Keywords */ FixVisibility = [Visword *s] . Visword : PubOpt | PrivOpt | ProtOpt . FixModifiers ~ AModifier {AModifier} *s . AModifier : StaticOpt | FinalOpt | SynchOpt | TransOpt | VolOpt | AbsOpt | NativeOpt . PubOpt = "public" . PrivOpt = "private" . ProtOpt = "protected" . StaticOpt = "static" . FinalOpt = "final" . SynchOpt = "synchronized" . TransOpt = "transient" . VolOpt = "volatile" . AbsOpt = "abstract" . NativeOpt = "native" . /* * AddClass */ AddClass = "add:" FixVisibility [ FixModifiers] "class" AddClassName ClassParentFeature ["package" Pack] "{" ClassParts "}" . AddClassName = Ident . ClassParentFeature = ["extends" ParentClass] ["implements" Interfaces] . ParentClass = DottedName . DottedName = DotList(Ident) . Interfaces = ComListOfDotList . ClassParts ~ {ClassPart} . ClassPart : TextClassPart | ParsableClassPart . TextClassPart = JavaCode . JavaCode = Text . ParsableClassPart : *lookahead*(@ _Visibility() [_Modifiers()] _DataType() _MemberName() ("="|";"|",") @) ClassField | *lookahead*(@ _Visibility() [_Modifiers()] _MemberType() _MethodName() ("(") @) ClassMethod . ClassField = Visibility [ Modifiers] DataType FieldNamesAndOptInits ";" . ClassMethod = Visibility [ Modifiers] MemberType MethodName "(" [ Arguments] ")" [ MethodThrows] MethodBody . Visibility : VarVisibility | FixVisibility . VarVisibility = "visibility:" VarRef . Modifiers : VarModifiers | FixModifiers . VarModifiers = "modifiers:" VarRef . MemberType : ConstructorType | DataType . ConstructorType = "constructor" . DataType : VarDataType | FixDataType . VarDataType = "return:" VarRef . FixDataType = DottedName [ SquareBracketses] . SquareBracketses ~ SquareBrackets {SquareBrackets} *s . SquareBrackets = "[" "]" . MemberName = Ident [ SquareBracketses] . FieldNamesAndOptInits ~ FieldNameOptInit {"," FieldNameOptInit} . FieldNameOptInit = MemberName [ InitFieldTrailer] . InitFieldTrailer = "=" JavaCode . Arguments ~ Argument {"," *s Argument} . Argument = FixDataType VarName . VarName = Ident [ SquareBracketses] . MethodThrows = "throws" SomeExceptions . SomeExceptions = ComListOfDotList . MethodBody : VarMethodBody | FixMethodBody | NoMethodBody . VarMethodBody = "body:" VarRef ";" . FixMethodBody = JavaCode . NoMethodBody = ";" . /* * AddInterface */ AddInterface = "add:" FixVisibility [ FixModifiers] "interface" InterfaceName InterfaceParentFeature ["package" Pack] "{" InterfaceParts "}" . InterfaceName = Ident . InterfaceParentFeature = ["extends" Interfaces] . InterfaceParts ~ {InterfacePart} . InterfacePart : TextInterfacePart | ParsableInterfacePart . TextInterfacePart = JavaCode . ParsableInterfacePart : *lookahead*(@ _Visibility() [_Modifiers()] _DataType() _MemberName() "=" @) InterfaceField | *lookahead*(@ _Visibility() [_Modifiers()] _DataType() _MethodName() "(" @) InterfaceMethod . InterfaceField = Visibility [ Modifiers] DataType FieldNamesAndInits ";" . FieldNamesAndInits ~ FieldNameInit {"," FieldNameInit} . FieldNameInit = MemberName InitFieldTrailer . InterfaceMethod = Visibility [ Modifiers] DataType MethodName "(" [ Arguments] ")" [ MethodThrows] ";" . /* * AddAttribute */ AddAttribute = "add:" "to:" ClassName "{" ClassParts "}" . ClassName = Ident . /* * AugmentMethod */ AugmentMethod = InsertPlace FullMethodName JavaCode . InsertPlace : InsertBefore | InsertAfter . InsertBefore = "before:" . InsertAfter = "after:" . FullMethodName = ClassName "." GenMethodName [ MethodArgTypes] . GenMethodName : MethodName | StarMethod . MethodName = Ident . StarMethod = "*" . MethodArgTypes = "(" [ArgumentTypes] ")" . ArgumentTypes ~ ArgumentType {"," *s ArgumentType} . ArgumentType = FixDataType . /* * ImplementInterface */ ImplementInterface = "implement:" DottedName "in:" ClassName ";" . /* * RenameMethod */ RenameMethod = "rename:" FullMethodName "to:" FullMethodProto ";" . FullMethodProto = Visibility [ Modifiers] [*lookahead* (@_MemberType() _MethodName() _FullMethodArgTypes()@) DataType] MethodName [ FullMethodArgTypes] . FullMethodArgTypes = "(" [Arguments] ")" . /* * Packages / Imports */ PackageSpec = "package" Pack ";" . Pack : FixPackage | VarPackage . FixPackage ~ Ident {"." Ident} . VarPackage = VarRef . ImportStatement = "import" ImportName ";" . ImportName ~ ImportIdent {"." ImportPart} . ImportPart : ImportIdent | ImportStar . ImportIdent = Ident . ImportStar = "*" . /* * Variables */ VarAssignment = Ident "=" Rvalue . Rvalue : RVisibility | RModifiers | RReturnType | RBody | RJavaCode | RPackage | RVar . RVisibility = "visibility:" FullMethodName ";" . RModifiers = "modifiers:" FullMethodName ";" . RReturnType = "return:" FullMethodName ";" . RBody = "body:" FullMethodName ";" . RJavaCode = JavaCode . RPackage = "package:" ClassName ";" . RVar = RVarExp ";" . RVarExp = VarRef ["+" RVarExp] . VarRef = "#" Ident *s . ComListOfDotList ~ DottedName {"," *s DottedName} . DotList(S) ~ S {"." S} . *noparse* Main = . AspectSorter = . OutputVisitor = . Err = . Var = . //PrettyJavaWriter = extends PrintWriter . FileCheck = . *parse*