diff --git a/CHANGELOG.md b/CHANGELOG.md index 4f7bbfbd17fda263e2456f1c4161a98553e71a9b..d7ac58555991f2be7fbc0efecf8d985b7a26d581 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,16 +1,7 @@ # Changelog -## [Unreleased] -### Added - -### Changed - -### Deprecated - -### Removed +## [0.3.1] -### Fixed -## [0.3.0] ### Added - Reference support for type names within aspect files. - Usages are now highlighted. @@ -24,7 +15,7 @@ - Attributes and inter-type declarations are shown sorted by aspect. - There are toggle buttons to show or hide attributes, inter-type declarations and rewrites. - Note that things outside aspects, equations and some other elements are not yet included. -- Support for IntelliJ IDEA 2022.2. +- Support for IntelliJ IDEA 2022.3. ### Changed diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000000000000000000000000000000000000..be3ef86d2c212bd4ca76617ea1bc2c4be0ad308d --- /dev/null +++ b/LICENSE @@ -0,0 +1,29 @@ +BSD 3-Clause License + +Copyright (c) 2022, TU Dresden, Software Technology Group +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +1. Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + +2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +3. Neither the name of the copyright holder nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/README.md b/README.md index 9136fd64c14dc1bab1d4bbfb3a26a61259a84f6c..6c61ab484cc8d055c760ff5766f6c84673c69089 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # JastAdd Language Support <!-- Plugin description --> -This plugin provides support for JastAdd and Relational RAGs +This plugin provides support for [JastAdd](https://jastadd.cs.lth.se/) and [Relational RAGs](http://relational-rags.eu) <!-- Plugin description end --> diff --git a/gradle.properties b/gradle.properties index b0659b6f0c4f8a45d38c92178e83fd80a7c3e2bf..16b68b231aa7308e231f803fb1a92b9ad033e7f9 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,16 +3,16 @@ pluginGroup = org.jastadd pluginName = JastAdd -pluginVersion = 0.3.0 +pluginVersion = 0.3.1 # See https://plugins.jetbrains.com/docs/intellij/build-number-ranges.html # for insight into build numbers and IntelliJ Platform versions. pluginSinceBuild = 211 -pluginUntilBuild = 222.* +pluginUntilBuild = 223.* # Plugin Verifier integration -> https://github.com/JetBrains/gradle-intellij-plugin#plugin-verifier-dsl # See https://jb.gg/intellij-platform-builds-list for available build versions. -pluginVerifierIdeVersions = 2021.1.1, 2021.1.2, 2021.1.3, 2021.2.3, 2021.3.1, 2022.1.4, 2022.2 +pluginVerifierIdeVersions = 2021.1.3, 2021.2.4, 2021.3.3, 2022.1.4, 2022.2.4, 2022.3.1 platformType = IC platformVersion = 2021.3.1 diff --git a/licenses/JastAdd-BSD b/licenses/JastAdd-BSD new file mode 100644 index 0000000000000000000000000000000000000000..d20c9c31898488284af0b0dc40d0c9917f5b6905 --- /dev/null +++ b/licenses/JastAdd-BSD @@ -0,0 +1,25 @@ +Copyright (c) 2005-2020, The JastAdd Team +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + * Neither the name of the Lund University nor the names of its contributors + may be used to endorse or promote products derived from this software + without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/src/main/grammar/Grammar.bnf b/src/main/grammar/Grammar.bnf index 34db53bc3d952affdf27c6c4d9846762c6a16e6e..e8245110ae8855fde17a7e20e64c96a9569a9d1f 100644 --- a/src/main/grammar/Grammar.bnf +++ b/src/main/grammar/Grammar.bnf @@ -1,3 +1,14 @@ +/** + * The rules in this file are based on the JavaCC specifications from the file + * Jrag.jjt which is part of the JastAdd source code and can be found at + * https://bitbucket.org/jastadd/jastadd2/src/1a3b0a9/src/javacc/jrag/Jrag.jjt + * That file itself is based on the Java1.1.jjt file from the VTransformer example + * from JavaCC by Sun Microsystems, Inc. Modifications have been made by the + * JastAdd team to add support for JastAdd features. The original author of + * this file, according to older releases of JavaCC, was Sriram Sankar. A date + * tag in the older releases shows the file was created on 3/5/97. + */ + { parserClass="org.jastadd.tooling.grammar.parser.GrammarParser" diff --git a/src/main/grammar/Jrag.jjt b/src/main/grammar/Jrag.jjt deleted file mode 100644 index 0fad94504848b91080e3d8e0fe3c94ce0468bb79..0000000000000000000000000000000000000000 --- a/src/main/grammar/Jrag.jjt +++ /dev/null @@ -1,2733 +0,0 @@ -/* Copyright (c) 2006, Sun Microsystems, Inc. - * 2006-2018, The JastAdd Team - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * * Neither the name of the Sun Microsystems, Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF - * THE POSSIBILITY OF SUCH DAMAGE. - */ - -/** - * This file is based on the Java1.1.jjt file from the VTransformer example - * from JavaCC by Sun Microsystems, Inc. Modifications have been made by the - * JastAdd team to add support for JastAdd features. The original author of - * this file, according to older releases of JavaCC, was Sriram Sankar. A date - * tag in the older releases shows the file was created on 3/5/97. - */ -options { - JAVA_UNICODE_ESCAPE = true; - - STATIC=false; - MULTI=true; - VISITOR=true; - NODE_USES_PARSER=true; - NODE_SCOPE_HOOK= true; - NODE_PACKAGE="org.jastadd.jrag.AST"; -} - -PARSER_BEGIN(JragParser) -package org.jastadd.jrag.AST; -import java.util.*; -import org.jastadd.jrag.*; - -import org.jastadd.ast.AST.Grammar; - -public class JragParser { - - /* Added attributes to the parser: */ - public String className = ""; // Name of class currently parsed. - public String enclosingAspect = ""; // The name of the aspect currently being parsed. - public String fileName; // Name of parsed file. - - private java.util.List<String> contextStack = new java.util.ArrayList<String>(); - - public boolean inTopLevelOrAspect() { - int size = contextStack.size(); - return size == 0 || (size == 1 && contextStack.get(0).equals("aspect")); - } - - public boolean shouldAddClassBodyDecl() { - int size = contextStack.size(); - return size == 1 && - (contextStack.get(0).equals("aspect") || - contextStack.get(0).equals("class") || - contextStack.get(0).equals("interface")); - } - - public void pushTopLevelOrAspect(String context) { - contextStack.add(context); - } - - public void popTopLevelOrAspect() { - contextStack.remove(contextStack.size()-1); - } - - public Grammar root; - public java.io.InputStream inputStream; - - /** Set name of parsed file. */ - public void setFileName(String name) { - fileName = name; - className = ""; - contextStack = new java.util.ArrayList<String>(); - } - - /* ------ Added methods for NODE_SCOPE_HOOKS ---------*/ - public void jjtreeOpenNodeScope(Node n) { - ((SimpleNode) n).firstToken = getToken(1); - } - - public void jjtreeCloseNodeScope(Node n) { - ((SimpleNode) n).lastToken = getToken(0); - } - /* ------End of methods for NODE_SCOPE_HOOK------------*/ - - /** Returns string consisting of all chars before a dot. */ - public String beforeDot(String s) { - int i = s.indexOf('.'); - if (i < 0) { - return s; - } else { - return s.substring(0, i); - } - } - - /** - * Returns string consisting of all chars between "get" and before a '('. - * Returns null if "get" is not a prefix; s if no "(" found. - */ - public String stripGet(String s) { - if (!s.startsWith("get")) { - return null; - } - s = s.substring(3, s.length()); - return s; - } - - /** Returns string consisting of all chars after a dot. */ - public String afterDot(String s) { - int i = s.indexOf('.'); - if (i < 0) { - return null; - } else { - return s.substring(i+1,s.length()); - } - } -} - -PARSER_END(JragParser) - -/* WHITE SPACE */ - -<DEFAULT,COLLECTION_DECL> -SPECIAL_TOKEN : -{ - " " -| "\t" -| "\n" -| "\r" -| "\f" -} - -/* COMMENTS */ - -<DEFAULT,COLLECTION_DECL> -MORE : -{ - "//" : IN_SINGLE_LINE_COMMENT -| - <"/**" ~["/"]> { input_stream.backup(1); } : IN_FORMAL_COMMENT -| - "/*" : IN_MULTI_LINE_COMMENT -} - - -<IN_SINGLE_LINE_COMMENT> -SPECIAL_TOKEN : -{ - <SINGLE_LINE_COMMENT: "\n" | "\r" | "\r\n" > : DEFAULT -} - -<IN_FORMAL_COMMENT> -SPECIAL_TOKEN : -{ - <FORMAL_COMMENT: "*/" > : DEFAULT -} - -<IN_MULTI_LINE_COMMENT> -SPECIAL_TOKEN : -{ - <MULTI_LINE_COMMENT: "*/" > : DEFAULT -} - -<IN_SINGLE_LINE_COMMENT,IN_FORMAL_COMMENT,IN_MULTI_LINE_COMMENT> -MORE : -{ - < ~[] > -} - -/* RESERVED WORDS AND LITERALS */ - -<DEFAULT,COLLECTION_DECL> -TOKEN : -{ - < ABSTRACT: "abstract" > -| < ASSERT: "assert" > -| < BOOLEAN: "boolean" > -| < BREAK: "break" > -| < BYTE: "byte" > -| < CASE: "case" > -| < CATCH: "catch" > -| < CHAR: "char" > -| < CLASS: "class" > -| < CONST: "const" > -| < CONTINUE: "continue" > -| < _DEFAULT: "default" > -| < DO: "do" > -| < DOUBLE: "double" > -| < ELSE: "else" > -| < ENUM: "enum" > -| < EXTENDS: "extends" > -| < FALSE: "false" > -| < FINAL: "final" > -| < FINALLY: "finally" > -| < FLOAT: "float" > -| < FOR: "for" > -| < GOTO: "goto" > -| < IF: "if" > -| < IMPLEMENTS: "implements" > -| < IMPORT: "import" > -| < INSTANCEOF: "instanceof" > -| < INT: "int" > -| < INTERFACE: "interface" > -| < LONG: "long" > -| < NATIVE: "native" > -| < NEW: "new" > -| < NULL: "null" > -| < PACKAGE: "package"> -| < PRIVATE: "private" > -| < PROTECTED: "protected" > -| < PUBLIC: "public" > -| < RETURN: "return" > -| < SHORT: "short" > -| < STATIC: "static" > -| < STRICTFP: "strictfp" > -| < SUPER: "super" > -| < SWITCH: "switch" > -| < SYNCHRONIZED: "synchronized" > -| < THIS: "this" > -| < THROW: "throw" > -| < THROWS: "throws" > -| < TRANSIENT: "transient" > -| < TRUE: "true" > -| < TRY: "try" > -| < VOID: "void" > -| < VOLATILE: "volatile" > -| < WHILE: "while" > - -// JastAdd keywords: -| < INH: "inh"> -| < SYN: "syn"> -| < LAZY: "lazy"> -| < REWRITE: "rewrite"> -| < TO: "to"> -| < WHEN: "when"> -| < ASPECT: "aspect"> -| < EQUATION: "eq"> -| < CIRCULAR: "circular"> -| < REFINE: "refine"> -| < CONTRIBUTES: "contributes"> -| < EACH: "each"> -| < NTA: "nta"> -| < CACHE: "cache"> -| < UNCACHE: "uncache"> -} - -TOKEN : -{ - < COLL: "coll"> : COLLECTION_DECL -} - -<COLLECTION_DECL> -TOKEN : -{ - < WITH: "with"> -| < ROOT: "root"> -} - -/* LITERALS */ - -<DEFAULT,COLLECTION_DECL> -TOKEN : -{ - < INTEGER_LITERAL: - <DECIMAL_LITERAL> (["l","L"])? - | <HEX_LITERAL> (["l","L"])? - | <OCTAL_LITERAL> (["l","L"])? - > -| - < #DECIMAL_LITERAL: ["1"-"9"] (["0"-"9"])* > -| - < #HEX_LITERAL: "0" ["x","X"] (["0"-"9","a"-"f","A"-"F"])+ > -| - < #OCTAL_LITERAL: "0" (["0"-"7"])* > -| - < FLOATING_POINT_LITERAL: - (["0"-"9"])+ "." (["0"-"9"])* (<EXPONENT>)? (["f","F","d","D"])? - | "." (["0"-"9"])+ (<EXPONENT>)? (["f","F","d","D"])? - | (["0"-"9"])+ <EXPONENT> (["f","F","d","D"])? - | (["0"-"9"])+ (<EXPONENT>)? ["f","F","d","D"] - > -| - < #EXPONENT: ["e","E"] (["+","-"])? (["0"-"9"])+ > -| - < CHARACTER_LITERAL: - "'" - ( (~["'","\\","\n","\r"]) - | ("\\" - ( ["n","t","b","r","f","\\","'","\""] - | ["0"-"7"] ( ["0"-"7"] )? - | ["0"-"3"] ["0"-"7"] ["0"-"7"] - ) - ) - ) - "'" - > -| - < STRING_LITERAL: - "\"" - ( (~["\"","\\","\n","\r"]) - | ("\\" - ( ["n","t","b","r","f","\\","'","\""] - | ["0"-"7"] ( ["0"-"7"] )? - | ["0"-"3"] ["0"-"7"] ["0"-"7"] - ) - ) - )* - "\"" - > -} - -/* IDENTIFIERS */ - -<DEFAULT,COLLECTION_DECL> -TOKEN : -{ - < IDENTIFIER: <LETTER> (<LETTER>|<DIGIT>)* > -| - < #LETTER: - [ - "\u0024", - "\u0041"-"\u005a", - "\u005f", - "\u0061"-"\u007a", - "\u00c0"-"\u00d6", - "\u00d8"-"\u00f6", - "\u00f8"-"\u00ff", - "\u0100"-"\u1fff", - "\u3040"-"\u318f", - "\u3300"-"\u337f", - "\u3400"-"\u3d2d", - "\u4e00"-"\u9fff", - "\uf900"-"\ufaff" - ] - > -| - < #DIGIT: - [ - "\u0030"-"\u0039", - "\u0660"-"\u0669", - "\u06f0"-"\u06f9", - "\u0966"-"\u096f", - "\u09e6"-"\u09ef", - "\u0a66"-"\u0a6f", - "\u0ae6"-"\u0aef", - "\u0b66"-"\u0b6f", - "\u0be7"-"\u0bef", - "\u0c66"-"\u0c6f", - "\u0ce6"-"\u0cef", - "\u0d66"-"\u0d6f", - "\u0e50"-"\u0e59", - "\u0ed0"-"\u0ed9", - "\u1040"-"\u1049" - ] - > -} - -/* SEPARATORS */ - -<DEFAULT,COLLECTION_DECL> -TOKEN : -{ - < LPAREN: "(" > -| < RPAREN: ")" > -| < LBRACE: "{" > -| < RBRACE: "}" > -| < LBRACKET: "[" > -| < RBRACKET: "]" > -| < SEMICOLON: ";" > -| < COMMA: "," > -| < DOT: "." > -| < AT: "@" > -} - -/* OPERATORS */ - -<DEFAULT,COLLECTION_DECL> -TOKEN : -{ - < ASSIGN: "=" > -| < LT: "<" > -| < BANG: "!" > -| < TILDE: "~" > -| < HOOK: "?" > -| < COLON: ":" > -| < EQ: "==" > -| < LE: "<=" > -| < GE: ">=" > -| < NE: "!=" > -| < SC_OR: "||" > -| < SC_AND: "&&" > -| < INCR: "++" > -| < DECR: "--" > -| < PLUS: "+" > -| < MINUS: "-" > -| < STAR: "*" > -| < SLASH: "/" > -| < BIT_AND: "&" > -| < BIT_OR: "|" > -| < XOR: "^" > -| < REM: "%" > -| < LSHIFT: "<<" > -| < PLUSASSIGN: "+=" > -| < MINUSASSIGN: "-=" > -| < STARASSIGN: "*=" > -| < SLASHASSIGN: "/=" > -| < ANDASSIGN: "&=" > -| < ORASSIGN: "|=" > -| < XORASSIGN: "^=" > -| < REMASSIGN: "%=" > -| < LSHIFTASSIGN: "<<=" > -| < RSIGNEDSHIFTASSIGN: ">>=" > -| < RUNSIGNEDSHIFTASSIGN: ">>>=" > -| < ELLIPSIS: "..." > -| < ARROW: "->" > -| < DOUBLECOLON: "::" > -} - -/* >'s need special attention due to generics syntax. */ -<DEFAULT,COLLECTION_DECL> -TOKEN : -{ - < RUNSIGNEDSHIFT: ">>>" > - { - matchedToken.kind = GT; - ((Token.GTToken)matchedToken).realKind = RUNSIGNEDSHIFT; - input_stream.backup(2); - } -| < RSIGNEDSHIFT: ">>" > - { - matchedToken.kind = GT; - ((Token.GTToken)matchedToken).realKind = RSIGNEDSHIFT; - input_stream.backup(1); - } -| < GT: ">" > -} - -/***************************************** - * THE JAVA LANGUAGE GRAMMAR STARTS HERE * - *****************************************/ - -/* - * Program structuring syntax follows. - */ - -ASTCompilationUnit CompilationUnit() : -{} -{ - ( ImportDeclaration() )* - ( TypeDeclaration() )* - <EOF> - { - return jjtThis; - } -} - -void ImportDeclaration() : -{} -{ - "import" [ "static" ] Name() [ "." "*" ] ";" -} - -String Modifiers() : -{ - StringBuilder buf = new StringBuilder(); - SimpleNode annotation; -} -{ - (LOOKAHEAD(2) - ( - "public" - { - if (buf.length() > 0) buf.append(" "); - buf.append(token.image); - } - | - "static" - { - if (buf.length() > 0) buf.append(" "); - buf.append(token.image); - } - | - "protected" - { - if (buf.length() > 0) buf.append(" "); - buf.append(token.image); - } - | - "private" - { - if (buf.length() > 0) buf.append(" "); - buf.append(token.image); - } - | - "final" - { - if (buf.length() > 0) buf.append(" "); - buf.append(token.image); - } - | - "abstract" - { - if (buf.length() > 0) buf.append(" "); - buf.append(token.image); - } - | - "synchronized" - { - if (buf.length() > 0) buf.append(" "); - buf.append(token.image); - } - | - "native" - { - if (buf.length() > 0) buf.append(" "); - buf.append(token.image); - } - | - "transient" - { - if (buf.length() > 0) buf.append(" "); - buf.append(token.image); - } - | - "volatile" - { - if (buf.length() > 0) buf.append(" "); - buf.append(token.image); - } - | - "strictfp" - { - if (buf.length() > 0) buf.append(" "); - buf.append(token.image); - } - | - annotation = Annotation() - { - if (buf.length() > 0) buf.append(" "); - buf.append(Unparser.unparse(annotation)); - } - ) - )* - { jjtree.popNode(); return buf.toString(); } -} - -void TypeDeclaration() : -{ - String modifiers; -} -{ - ";" -| - modifiers = Modifiers() - ( - ClassDeclaration(modifiers) - | - InterfaceDeclaration(modifiers) - | - UnmodifiedEnumDeclaration(modifiers) - | - AnnotationTypeDeclaration(modifiers) - | - AspectDeclaration(modifiers) - ) -} - -void AspectDeclaration(String modifiers) : -{ Token t; } -{ - "aspect" { pushTopLevelOrAspect("aspect"); } - t = <IDENTIFIER> { - enclosingAspect = t.image; - root.registerAspect(enclosingAspect, Unparser.unparseComment(jjtThis)); - } - AspectBody() - { popTopLevelOrAspect(); enclosingAspect = ""; } -} - -void AspectBody() : -{} -{ - "{" ( AspectBodyDeclaration() )* "}" -} - -void AspectBodyDeclaration() : -{} -{ - LOOKAHEAD(<REFINE> <IDENTIFIER> "eq" <IDENTIFIER> "." <IDENTIFIER> "(" [<INT> <IDENTIFIER>] ")" "." <IDENTIFIER>) - AspectRefineInhEquation() -| - LOOKAHEAD(<REFINE> <IDENTIFIER> "eq") - AspectRefineSynEquation() -| - LOOKAHEAD(AspectRefineMethodDeclarationLookahead()) - AspectRefineMethodDeclaration() -| - LOOKAHEAD(<REFINE>) - AspectRefineConstructorDeclaration() -| - LOOKAHEAD( Modifiers() "class" ) - AspectClassDeclaration() -| - LOOKAHEAD( Modifiers() "interface" ) - AspectInterfaceDeclaration() -| - LOOKAHEAD( Modifiers() "enum" ) - AspectEnumDeclaration() -| - LOOKAHEAD( ( Annotation() )* "syn" ) - AspectSynAttributeDeclaration() -| - LOOKAHEAD( ( Annotation() )* "inh" ) - AspectInhAttributeDeclaration() -| - LOOKAHEAD( "rewrite" ) - AspectRewrite() -| - LOOKAHEAD( ( Annotation() )* "eq" <IDENTIFIER> "." <IDENTIFIER> "(" [<INT> <IDENTIFIER>] ")" "." ) - AspectInhEquation() -| - LOOKAHEAD( ( Annotation() )* "eq" ) - AspectSynEquation() -| - LOOKAHEAD( <IDENTIFIER> "implements" ) - AspectAddInterface() -| - LOOKAHEAD( <IDENTIFIER> "extends" ) - AspectExtendInterface() -| - LOOKAHEAD( ( Annotation() )* "coll" ) - CollectionAttribute() -| - LOOKAHEAD( <IDENTIFIER> "contributes" ) - CollectionContribution() -| - LOOKAHEAD( AspectMethodDeclarationLookahead() ) - AspectMethodDeclaration() -| - LOOKAHEAD( Modifiers() <IDENTIFIER> "." <IDENTIFIER> "(" ) - AspectConstructorDeclaration() -| - LOOKAHEAD( AspectFieldDeclarationLookahead() ) - AspectFieldDeclaration() -| - LOOKAHEAD( ( "cache" | "uncache" ) ) - AspectCacheDeclaration() -} - -/** - * This production is used for aspects generated by JastAdd and includes an EOF - */ -void AspectBodyDeclarationsEOF() : -{} -{ - ( AspectBodyDeclaration() )* <EOF> -} - -void AspectClassDeclaration() : -{ - Token t; - Token first; - String outerClassName; - String name = ""; - SimpleNode nameList = null; - String modifiers; - SimpleNode node; - org.jastadd.ast.AST.TypeDecl typeDecl = null; - String typeParameters; -} -{ - modifiers = Modifiers() - first = "class" - t = <IDENTIFIER> { - pushTopLevelOrAspect("class"); - outerClassName = className; - className = t.image; - typeDecl = root.findClassDecl(className, Unparser.unparseComment(jjtThis), - fileName, first.beginLine, enclosingAspect); - typeDecl.modifiers = modifiers; - } - [ typeParameters = TypeParameters() { typeDecl.typeParameters = typeParameters; } ] - [ "extends" - node = ClassOrInterfaceType() { - name = Unparser.unparse(node); - if (!name.equals("") && typeDecl instanceof org.jastadd.ast.AST.ClassDecl) { - ((org.jastadd.ast.AST.ClassDecl)typeDecl).extendsName = name; - } - } - ] - [ "implements" nameList = TypeNameList() { root.addInterface(nameList, className, fileName); } ] - AspectClassBody() { className = outerClassName; popTopLevelOrAspect(); } -} - -void AspectClassBody() : -{ - SimpleNode n; -} -{ - "{" ( n = ClassBodyDeclaration() { root.addClassBodyDecl(n, className, fileName, enclosingAspect); } )* "}" -} - -void AspectInterfaceDeclaration() : -{ - Token t; - Token first; - String outerClassName; - SimpleNode nameList = null; - org.jastadd.ast.AST.TypeDecl typeDecl = null; - String typeParameters; - String modifiers; -} -{ - modifiers = Modifiers() - first = "interface" - t = <IDENTIFIER> { - pushTopLevelOrAspect("interface"); - outerClassName = className; - className = t.image; - typeDecl = root.findInterfaceDecl(className, Unparser.unparseComment(jjtThis), - fileName, first.beginLine, enclosingAspect); - typeDecl.modifiers = modifiers; - } - [ typeParameters = TypeParameters() { typeDecl.typeParameters = typeParameters; } ] - [ "extends" nameList = TypeNameList() { root.addInterface(nameList, className, fileName); } ] - "{" ( AspectInterfaceMemberDeclaration() )* "}" { className = outerClassName; popTopLevelOrAspect(); } -} - -void AspectInterfaceMemberDeclaration() : -{} -{ - LOOKAHEAD( Modifiers() "class" ) - AspectNestedClassDeclaration() -| - LOOKAHEAD( Modifiers() "interface" ) - AspectNestedInterfaceDeclaration() -| - LOOKAHEAD("syn") - AspectInterfaceSynAttributeDeclaration() -| - LOOKAHEAD("inh") - AspectInterfaceInhAttributeDeclaration() -| - LOOKAHEAD( AspectInterfaceMethodDeclarationLookahead() ) - AspectInterfaceMethodDeclaration() -| - AspectInterfaceFieldDeclaration() -} - -void AspectInterfaceSynAttributeDeclaration() : -{ String attrType; - Token attrName; - Token t; - Token first, last; - - String type; - Token name; - String targetName; - - org.jastadd.ast.AST.List list = new org.jastadd.ast.AST.List(); - - SimpleNode eq = null; - - boolean init = false; - boolean isLazy = false; - boolean isFinal = false; - SimpleNode bottomValue = null; - - ArrayList<String> annotations = new ArrayList<String>(); - SimpleNode annotation; -} -{ - ( annotation = Annotation() { annotations.add(Unparser.unparseSkipComment(annotation)); } )* - - "syn" { first = token; } ["lazy" {isLazy = true;}] ["final" {isFinal = true;}] - attrType = AspectType() attrName = AttributeName() - - "(" - [ - type = Type() name = <IDENTIFIER> { list.add(new org.jastadd.ast.AST.Parameter(type, name.image)); } - ( "," type = Type() name = <IDENTIFIER> { list.add(new org.jastadd.ast.AST.Parameter(type, name.image)); })* - ] - ")" - - [ - <CIRCULAR> <LBRACKET> bottomValue = Expression() <RBRACKET> - ] - - ";" { last = token; } - { - root.addSynDecl(attrName.image, attrType, className, - isLazy, fileName, first.beginLine, last.endLine, list, - bottomValue == null ? "" : Unparser.unparse(bottomValue), - isFinal, false, jjtThis, enclosingAspect, annotations); - - } -} - -void AspectInterfaceInhAttributeDeclaration() : -{ String attrType; - Token attrName; - Token t; - Token first, last; - - String type; - Token name; - String targetName; - org.jastadd.ast.AST.List list = new org.jastadd.ast.AST.List(); - SimpleNode bottomValue = null; - boolean isLazy = false; - boolean isFinal = false; - - ArrayList<String> annotations = new ArrayList<String>(); - SimpleNode annotation; -} -{ - ( annotation = Annotation() { annotations.add(Unparser.unparse(annotation)); } )* - - "inh" { first = token; } ["lazy" {isLazy = true;}] ["final" {isFinal = true;}] attrType = AspectType() - attrName = AttributeName() - - "(" - [ - type = Type() name = <IDENTIFIER> { list.add(new org.jastadd.ast.AST.Parameter(type, name.image)); } - ( "," type = Type() name = <IDENTIFIER> { list.add(new org.jastadd.ast.AST.Parameter(type, name.image)); })* - ] - - ")" - - [ - <CIRCULAR> <LBRACKET> bottomValue = Expression() <RBRACKET> - ] - - ";" - { - last = token; - root.addInhDecl(attrName.image, attrType, className, - isLazy, fileName, first.beginLine, - last.endLine, list, bottomValue == null ? "" : Unparser.unparse(bottomValue), - isFinal, false, jjtThis, enclosingAspect, annotations); - } -} - -void AspectInterfaceMethodDeclarationLookahead() : -{} -{ - ( "public" | "protected" | "private" | "static" | "abstract" | "final" | "native" | "synchronized" )* - AspectResultType() JavaIdentifier() "(" -} - -void AspectInterfaceMethodDeclaration() : -{ - Token t; -} -{ - ( "public" | "protected" | "private" | "static" | "abstract" | "final" | "native" | "synchronized" )* - AspectResultType() MethodDeclarator() [ "throws" NameList() ] - ";" { - root.addClassBodyDecl(jjtThis, className, fileName, enclosingAspect); - } -} - -void AspectInterfaceFieldDeclaration() : -{ - Token t; - String modifiers; -} -{ - modifiers = Modifiers() - AspectType() VariableDeclarator() ( "," VariableDeclarator() )* ";" - { - root.addClassBodyDecl(jjtThis, className, fileName, enclosingAspect); - } -} - -void AspectNestedInterfaceDeclaration() : -{ - String outerClassName = className; - className = "D$u$m$m$y"; - String modifiers; -} -{ - modifiers = Modifiers() - "interface" { pushTopLevelOrAspect("interface"); } <IDENTIFIER> - [ TypeParameters() ] - [ "extends" TypeNameList() ] - "{" ( InterfaceMemberDeclaration() )* "}" - { - className = outerClassName; - root.addClassBodyDecl(jjtThis, className, fileName, modifiers, enclosingAspect); - popTopLevelOrAspect(); - } -} - -void AspectNestedClassDeclaration() : -{ - String outerClassName = className; - className = "D$u$m$m$y"; - String modifiers; - String typeParameters; -} -{ - modifiers = Modifiers() - "class" { pushTopLevelOrAspect("class"); } <IDENTIFIER> - [ TypeParameters() ] - [ "extends" ClassOrInterfaceType() ] - [ "implements" TypeNameList() ] - ClassBody() - { - className = outerClassName; - root.addClassBodyDecl(jjtThis, className, fileName, modifiers, enclosingAspect); - popTopLevelOrAspect(); - } -} - -void AspectMethodDeclarationLookahead() : -{} -{ - Modifiers() - [ TypeParameters() ] - AspectResultType() <IDENTIFIER> "." JavaIdentifier() "(" -} - -void AspectMethodDeclaration() : -{Token t;} -{ - Modifiers() - [ TypeParameters() ] - AspectResultType() t = <IDENTIFIER> "." { className = t.image; } MethodDeclarator() [ "throws" NameList() ] - ( Block() | ";" ) { - root.addClassBodyDecl(jjtThis, className, fileName, enclosingAspect); - } -} - -void AspectRefineMethodDeclarationLookahead() : -{} -{ - <REFINE> [LOOKAHEAD(<IDENTIFIER>)<IDENTIFIER>] - Modifiers() - [ TypeParameters() ] - AspectResultType() <IDENTIFIER> "." JavaIdentifier() "(" -} - -void AspectRefineMethodDeclaration() : -{Token t; String aspectName = ""; String secondAspectName; } -{ - t = <REFINE> { t.image = ""; } [LOOKAHEAD(<IDENTIFIER>) t = <IDENTIFIER> { aspectName = t.image; t.image = ""; }] - Modifiers() - [ TypeParameters() ] - AspectResultType() t = <IDENTIFIER> "." { className = t.image; } MethodDeclarator() [ "throws" NameList() ] - ( Block() | ";" ) { - root.addRefinedClassBodyDecl(jjtThis, className, fileName, aspectName, enclosingAspect); - } -} -void AspectConstructorDeclaration() : -{Token t;} -{ - Modifiers() - t = <IDENTIFIER> "." { className = t.image; } <IDENTIFIER> FormalParameters() [ "throws" NameList() ] - "{" - [ LOOKAHEAD(ExplicitConstructorInvocation()) ExplicitConstructorInvocation() ] - ( BlockStatement() )* - "}" - { - root.addClassBodyDecl(jjtThis, className, fileName, enclosingAspect); - } -} - -void AspectRefineConstructorDeclaration() : -{Token t; String aspectName; String secondAspectName; } -{ - t = <REFINE> { t.image = ""; } t = <IDENTIFIER> { aspectName = t.image; t.image = ""; } [ "public" | "protected" | "private" ] - t = <IDENTIFIER> "." { className = t.image; } <IDENTIFIER> FormalParameters() [ "throws" NameList() ] - "{" - [ LOOKAHEAD(ExplicitConstructorInvocation()) ExplicitConstructorInvocation() ] - ( BlockStatement() )* - "}" - { - root.addRefinedClassBodyDecl(jjtThis, className, fileName, aspectName, enclosingAspect); - } -} - -void AspectFieldDeclarationLookahead() : -{} -{ - Modifiers() - AspectType() <IDENTIFIER> "." VariableDeclarator() -} - -void AspectFieldDeclaration() : -{Token t;} -{ - Modifiers() - AspectType() t = <IDENTIFIER> "." { className = t.image; } VariableDeclarator() ( "," VariableDeclarator() )* ";" { - root.addClassBodyDecl(jjtThis, className, fileName, enclosingAspect); - } -} - -void AspectSynAttributeDeclaration() : -{ String attrType; - Token attrName; - Token t; - Token first, last; - - String type; - Token name; - String targetName; - - org.jastadd.ast.AST.List list = new org.jastadd.ast.AST.List(); - - SimpleNode eq = null; - - boolean init = false; - boolean isLazy = false; - SimpleNode bottomValue = null; - boolean isFinal = false; - boolean isNTA = false; - - ArrayList<String> annotations = new ArrayList<String>(); - SimpleNode annotation; -} -{ - ( annotation = Annotation() { annotations.add(Unparser.unparseSkipComment(annotation)); } )* - - "syn" { first = token; } - - [<NTA> {isNTA = true; }] - - ["lazy" {isLazy = true;}] - - ["final" {isFinal = true; }] - - attrType = AspectType() - - t = <IDENTIFIER> "." { targetName = t.image; } - - attrName = AttributeName() - - "(" - [ - type = Type() name = <IDENTIFIER> { list.add(new org.jastadd.ast.AST.Parameter(type, name.image)); } - ( "," type = Type() name = <IDENTIFIER> { list.add(new org.jastadd.ast.AST.Parameter(type, name.image)); })* - ] - ")" - - [ - <CIRCULAR> <LBRACKET> bottomValue = Expression() <RBRACKET> - ] - - ( ("=" eq = Expression() ";" { last = token; init = true;} ) - | (eq = Block() { last = token; init = true;}) - | ";" { last = token; } ) - - { - root.addSynDecl(attrName.image, attrType, targetName, - isLazy, fileName, first.beginLine, - last.endLine, list, bottomValue == null ? "" : Unparser.unparse(bottomValue), - isFinal, isNTA, jjtThis, enclosingAspect, annotations); - - if (init) { - root.addSynEq(attrName.image, targetName, eq, fileName, first.beginLine, - last.endLine, (org.jastadd.ast.AST.List)list.fullCopy(), jjtThis, - enclosingAspect, annotations); - } - } -} - -void AspectInhAttributeDeclaration() : -{ String attrType; - Token attrName; - Token t; - Token first, last; - - String type; - Token name; - String targetName; - org.jastadd.ast.AST.List list = new org.jastadd.ast.AST.List(); - SimpleNode bottomValue = null; - boolean isLazy = false; - boolean isFinal = false; - boolean isNTA = false; - - ArrayList<String> annotations = new ArrayList<String>(); - SimpleNode annotation; -} -{ - ( annotation = Annotation() { annotations.add(Unparser.unparseSkipComment(annotation)); } )* - - "inh" { first = token; } [<NTA> {isNTA = true;}] ["lazy" {isLazy = true;}] ["final" {isFinal = true; }] attrType = AspectType() - t = <IDENTIFIER> "." { targetName = t.image; } - attrName = AttributeName() - - "(" - [ - type = Type() name = <IDENTIFIER> { list.add(new org.jastadd.ast.AST.Parameter(type, name.image)); } - ( "," type = Type() name = <IDENTIFIER> { list.add(new org.jastadd.ast.AST.Parameter(type, name.image)); })* - ] - - ")" - - [ - <CIRCULAR> <LBRACKET> bottomValue = Expression() <RBRACKET> - ] - - ";" - { - last = token; - root.addInhDecl(attrName.image, attrType, targetName, - isLazy, fileName, first.beginLine, - last.endLine, list, bottomValue == null ? "" : Unparser.unparse(bottomValue), - isFinal, isNTA, jjtThis, enclosingAspect, annotations); - } -} - - -void AspectRewrite() : -{ - Token t; - SimpleNode cond; - SimpleNode eq; - Token first, last; - - Token parent = null; - Token child = null; - String type; -} -{ - "rewrite" {cond = null; first = token;} t = <IDENTIFIER> { className = t.image; } - [<IDENTIFIER> parent = <IDENTIFIER> "." child = <IDENTIFIER> <LPAREN> <RPAREN>] - <LBRACE> - ( ["when" { first = token; } <LPAREN> cond = Expression() <RPAREN>] - "to" type = AspectType() ( (eq = Expression() ";" { last = token; }) | eq = Block() { last = token; } ) - { - if (parent != null && child != null) { - root.addRewriteList(className, cond, eq, type, fileName, first.beginLine, last.endLine, parent.image, child.image, enclosingAspect); - } else { - root.addRewrite(className, cond, eq, type, fileName, first.beginLine, last.endLine, enclosingAspect); - } - cond = null; - } - )+ - <RBRACE> -} - -void AspectSynEquation() : -{ - String t; - Token first, last; - SimpleNode eq; - String type; - Token name; - Token attrName; - Token targetName; - org.jastadd.ast.AST.List list = new org.jastadd.ast.AST.List(); - - ArrayList<String> annotations = new ArrayList<String>(); - SimpleNode annotation; -} -{ - ( annotation = Annotation() { annotations.add(Unparser.unparseSkipComment(annotation)); } )* - - "eq" { first = token; } - - targetName = <IDENTIFIER> "." - attrName = AttributeName() - - "(" - [ - type = Type() name = <IDENTIFIER> { list.add(new org.jastadd.ast.AST.Parameter(type, name.image)); } - ( "," type = Type() name = <IDENTIFIER> { list.add(new org.jastadd.ast.AST.Parameter(type, name.image)); })* - ] - - ")" - - ( ("=" eq = Expression() ";" { last = token; }) - | eq = Block() { last = token; } ) - - { - root.addSynEq(attrName.image, targetName.image, eq, fileName, - first.beginLine, last.endLine, list, jjtThis, enclosingAspect, - annotations); - } - -} -void AspectRefineSynEquation() : -{ - String t; - Token first, last; - SimpleNode eq; - String type; - Token name; - Token attrName; - Token targetName; - Token aspectName; - Token secondAspectName; - org.jastadd.ast.AST.List list = new org.jastadd.ast.AST.List(); -} -{ - <REFINE> aspectName = <IDENTIFIER> - "eq" { first = token; } - - targetName = <IDENTIFIER> "." - attrName = AttributeName() - - "(" - [ - type = Type() name = <IDENTIFIER> { list.add(new org.jastadd.ast.AST.Parameter(type, name.image)); } - ( "," type = Type() name = <IDENTIFIER> { list.add(new org.jastadd.ast.AST.Parameter(type, name.image)); })* - ] - - ")" - - ( ( ("=" eq = Expression() ";" { last = token; }) - | eq = Block() { last = token; } ) - { root.addRefinedSynEq(attrName.image, targetName.image, eq, fileName, first.beginLine, last.endLine, list, aspectName.image, jjtThis, enclosingAspect); } - ) -} - -void AspectInhEquation() : -{ - String t; - Token first, last; - SimpleNode eq; - Token name; - String type; - Token attrName; - Token targetName; - Token childName; - org.jastadd.ast.AST.List list = new org.jastadd.ast.AST.List(); - org.jastadd.ast.AST.Parameter p = null; - - ArrayList<String> annotations = new ArrayList<String>(); - SimpleNode annotation; -} -{ - ( annotation = Annotation() { annotations.add(Unparser.unparseSkipComment(annotation)); } )* - - "eq" { first = token; } - - targetName = <IDENTIFIER> "." - childName = <IDENTIFIER> "(" [ <INT> name = <IDENTIFIER> { p = new org.jastadd.ast.AST.Parameter("int", name.image); } ] ")" "." - attrName = AttributeName() - - "(" - [ - type = Type() name = <IDENTIFIER> { list.add(new org.jastadd.ast.AST.Parameter(type, name.image)); } - ( "," type = Type() name = <IDENTIFIER> { list.add(new org.jastadd.ast.AST.Parameter(type, name.image)); })* - ] - - ")" - - ( ("=" eq = Expression() ";" { last = token; }) - | eq = Block() { last = token; } ) - - { - root.addInhEq(childName.image, attrName.image, targetName.image, eq, - fileName, first.beginLine, last.endLine, list, p, jjtThis, - enclosingAspect, annotations); - } -} -void AspectRefineInhEquation() : -{ - String t; - Token first, last; - SimpleNode eq; - Token name; - String type; - Token attrName; - Token targetName; - Token childName; - org.jastadd.ast.AST.List list = new org.jastadd.ast.AST.List(); - org.jastadd.ast.AST.Parameter p = null; - Token aspectName; -} -{ - <REFINE> aspectName = <IDENTIFIER> "eq" { first = token; } - - targetName = <IDENTIFIER> "." - childName = <IDENTIFIER> "(" [ <INT> name = <IDENTIFIER> { p = new org.jastadd.ast.AST.Parameter("int", name.image); } ] ")" "." - attrName = AttributeName() - - "(" - [ - type = Type() name = <IDENTIFIER> { list.add(new org.jastadd.ast.AST.Parameter(type, name.image)); } - ( "," type = Type() name = <IDENTIFIER> { list.add(new org.jastadd.ast.AST.Parameter(type, name.image)); })* - ] - - ")" - - ( ("=" eq = Expression() ";" { last = token; }) - | eq = Block() { last = token; } ) - - { - root.addRefinedInhEq(childName.image, attrName.image, targetName.image, eq, fileName, first.beginLine, last.endLine, list, p, aspectName.image, jjtThis, enclosingAspect); - } -} - -void CollectionAttribute(): -{ - Token t; - Token first, last; - String attrType; - String targetName; - Token attrName; - String combOp = "add"; - String rootName = null; - SimpleNode startValue = null; - boolean isCircular = false; - - ArrayList<String> annotations = new ArrayList<String>(); - SimpleNode annotation; -} -{ - ( annotation = Annotation() { annotations.add(Unparser.unparseSkipComment(annotation)); } )* - "coll" { first = token; } - attrType = AspectType() t = <IDENTIFIER> "." { targetName = t.image; } attrName = AttributeName() "(" ")" - [ <CIRCULAR> { isCircular = true; } ] - [ <LBRACKET> startValue = Expression() <RBRACKET> ] - [ <WITH> t = <IDENTIFIER> { combOp = t.image; } ] - [ <ROOT> t = <IDENTIFIER> { rootName = t.image; } ] - ";" - { - last = token; - root.addCollDecl(attrName.image, attrType, targetName, fileName, - first.beginLine, last.endLine, - startValue == null ? "new " + attrType + "()" : Unparser.unparse(startValue), - combOp, - isCircular, annotations, jjtThis, rootName, enclosingAspect); - token_source.SwitchTo(DEFAULT); - } -} - -void CollectionContribution(): -{ - Token t; - Token first, last; - SimpleNode block; - SimpleNode value = null; - SimpleNode condition = null; - SimpleNode ntaExpression = null; - String targetName; - String targetAttributeName; - String attributeType; - String surveyBlock = null; - SimpleNode reference = null; - org.jastadd.ast.AST.List contributionList = new org.jastadd.ast.AST.List(); - boolean iterableValue = false; - boolean iterableTarget = false; - ArrayList<String> annotations = new ArrayList<String>(); - SimpleNode annotation; -} -{ - ( annotation = Annotation() { annotations.add(Unparser.unparseComment(annotation)); } )* - t = <IDENTIFIER> { first = token; attributeType = t.image; } - "contributes" - ( - LOOKAHEAD("nta") "nta" - ntaExpression = Expression() - "to" t = <IDENTIFIER> "." { targetName = t.image; } t = AttributeName() { targetAttributeName = t.image; } "(" ")" - | [ LOOKAHEAD("each") "each" { iterableValue = true; } ] - value = Expression() - [ "when" condition = Expression() ] - "to" t = <IDENTIFIER> "." { targetName = t.image; } t = AttributeName() { targetAttributeName = t.image; } "(" ")" - [ "for" [ LOOKAHEAD("each") "each" { iterableTarget = true; } ] reference = Expression() ] - | block = Block() { surveyBlock = Unparser.unparse(block); } - "to" t = <IDENTIFIER> "." { targetName = t.image; } t = AttributeName() { targetAttributeName = t.image; } "(" ")" - ) - ";" { last = token; } - { - if (surveyBlock != null) { - root.addCustomSurveyBlock(targetName, - targetAttributeName, - attributeType, - surveyBlock, - fileName, - first.beginLine, - last.endLine, - jjtThis, - enclosingAspect, - annotations); - } else if (ntaExpression != null) { - root.addCustomSurveyExpression(targetName, - targetAttributeName, - attributeType, - Unparser.unparse(ntaExpression), - fileName, - first.beginLine, - last.endLine, - jjtThis, - enclosingAspect, - annotations); - } else { - org.jastadd.ast.AST.CollEq equ = root.addCollEq(targetName, - targetAttributeName, - attributeType, - reference == null ? "" : Unparser.unparse(reference), - fileName, - first.beginLine, - last.endLine, - iterableValue, - iterableTarget, - jjtThis, - enclosingAspect, - annotations); - // TODO(joqvist): make the returned equ non-null. - if (equ != null) { - equ.setValue(Unparser.unparse(value)); - if (condition != null) { - equ.setCondition(Unparser.unparse(condition)); - } - } - } - } -} - -void AspectAddInterface() : -{ - Token first, last; - Token targetName; - SimpleNode nameList; -} -{ - targetName = <IDENTIFIER> { first = token; } - "implements" - nameList = TypeNameList() - ";" - { - last = token; - root.addInterface(nameList, targetName.image, fileName); - } - -} - -void AspectExtendInterface() : -{ - Token first, last; - Token targetName; - SimpleNode nameList; -} -{ - targetName = <IDENTIFIER> { first = token; } - "extends" - nameList = TypeNameList() - ";" - { - last = token; - root.extendInterface(nameList, targetName.image, fileName); - } - -} - - -/* - * Declaration syntax follows. - */ - -void ClassDeclaration(String modifiers) : -{ Token t; - Token first; - SimpleNode node; - String outerClassName; - StringBuffer name = new StringBuffer(); - org.jastadd.ast.AST.TypeDecl typeDecl = null; - SimpleNode nameList = null; - String typeParameters; -} -{ - first = "class" - t = <IDENTIFIER> { - pushTopLevelOrAspect("class"); - outerClassName = className; - className = t.image; - typeDecl = root.findClassDecl(className, Unparser.unparseComment(jjtThis), - fileName, first.beginLine, enclosingAspect); - typeDecl.modifiers = modifiers; - } - [ typeParameters = TypeParameters() { typeDecl.typeParameters = typeParameters; } ] - [ "extends" - node = ClassOrInterfaceType() { name.append(Unparser.unparse(node)); } - { if(!name.toString().equals("") && typeDecl instanceof org.jastadd.ast.AST.ClassDecl) - ((org.jastadd.ast.AST.ClassDecl)typeDecl).extendsName = name.toString(); - } - ] - [ "implements" nameList = TypeNameList() { root.addInterface(nameList, className, fileName);} ] - ClassBody() { className = outerClassName; popTopLevelOrAspect(); } -} - -SimpleNode TypeNameList(): -{} -{ - ( - ClassOrInterfaceType() - ( "," ClassOrInterfaceType() )* - ) - { return jjtThis; } -} - - -/* Added action to set classname and add class to allClasses */ -void UnmodifiedClassDeclaration(String modifiers) : -{ - Token t; - SimpleNode nameList; - String outerClassName; -} -{ - "class" t = <IDENTIFIER> { pushTopLevelOrAspect("class"); outerClassName = className; className = t.image; } - [ TypeParameters() ] - [ "extends" ClassOrInterfaceType() ] [ "implements" nameList = TypeNameList() ] - ClassBody() { className = outerClassName; popTopLevelOrAspect(); } - { if (shouldAddClassBodyDecl()) { - root.addClassBodyDecl(jjtThis, className, fileName, modifiers, enclosingAspect); - } - } -} - - -void AspectEnumDeclaration(): -{ - Token t; - Token first; - String outerClassName; - String modifiers; - SimpleNode node; - org.jastadd.ast.AST.EnumDecl typeDecl = null; -} -{ - modifiers = Modifiers() - first = "enum" - t = <IDENTIFIER> { - pushTopLevelOrAspect("enum"); - outerClassName = className; - className = t.image; - typeDecl = (org.jastadd.ast.AST.EnumDecl) root.findEnumDecl(className, Unparser.unparseComment(jjtThis), - fileName, first.beginLine, enclosingAspect); - typeDecl.modifiers = modifiers; - typeDecl.simpleNode = jjtThis; - } - [ "implements" TypeNameList() ] - EnumBody() { className = outerClassName; popTopLevelOrAspect(); } -} - -void UnmodifiedEnumDeclaration(String modifiers): -{} -{ - "enum" { pushTopLevelOrAspect("enum"); } JavaIdentifier() - [ "implements" TypeNameList() ] - EnumBody() - { popTopLevelOrAspect(); - if (shouldAddClassBodyDecl()) { - root.addClassBodyDecl(jjtThis, className, fileName, modifiers, enclosingAspect); - } - } -} - -void EnumBody(): -{ - SimpleNode n; -} -{ - "{" - EnumConstant() ( "," EnumConstant() )* - [ ";" ( ClassBodyDeclaration() )* ] - "}" -} - -void EnumConstant(): -{} -{ - JavaIdentifier() [ Arguments() ] [ ClassBody() ] -} - -String TypeParameters(): -{} -{ - ( - "<" TypeParameter() ( "," TypeParameter() )* ">" - ) - { return Unparser.unparse(jjtThis); } -} - -void TypeParameter(): -{} -{ - JavaIdentifier() [ TypeBound() ] -} - -void TypeBound(): -{} -{ - "extends" ClassOrInterfaceType() ( "&" ClassOrInterfaceType() )* -} - - - - -void ClassBody() : -{} -{ - "{" ( ClassBodyDeclaration() )* "}" -} - -/* Added one branch corresponding to attribute declarations - and two branches for syn and inh attribute equations */ -SimpleNode ClassBodyDeclaration() : -{ - String modifiers; -} -{ - ( - LOOKAHEAD(2) - Initializer() -| - modifiers = Modifiers() - ( - UnmodifiedClassDeclaration(modifiers) - | - UnmodifiedInterfaceDeclaration(modifiers) - | - AnnotationTypeDeclaration(modifiers) - | - UnmodifiedEnumDeclaration(modifiers) - | - LOOKAHEAD( [TypeParameters() ] JavaIdentifier() "(" ) - ConstructorDeclaration(modifiers) - | - LOOKAHEAD( AspectType() JavaIdentifier() ( "[" "]" )* ( "," | "=" | ";" ) ) - FieldDeclaration(modifiers) - | - MethodDeclaration(modifiers) - ) -| - ";" - ) - { - return jjtThis; - } -} - -void InterfaceDeclaration(String modifiers) : -{} -{ - UnmodifiedInterfaceDeclaration(modifiers) -} - -void UnmodifiedInterfaceDeclaration(String modifiers) : -{ - boolean isTopLevel; - Token t; - Token first; - String outerClassName; - SimpleNode nameList = null; - org.jastadd.ast.AST.TypeDecl typeDecl = null; - String typeParameters; -} -{ - first = "interface" - t = <IDENTIFIER> { - isTopLevel = inTopLevelOrAspect(); - pushTopLevelOrAspect("interface"); - outerClassName = className; - className = t.image; - if (isTopLevel) { - typeDecl = root.findInterfaceDecl(className, Unparser.unparseComment(jjtThis), - fileName, first.beginLine, enclosingAspect); - typeDecl.modifiers = modifiers; - } - } - [ typeParameters = TypeParameters() { if (isTopLevel) typeDecl.typeParameters = typeParameters; } ] - [ "extends" nameList = TypeNameList() { if (isTopLevel) root.addInterface(nameList, className, fileName); } ] - "{" ( InterfaceMemberDeclaration() )* "}" { className = outerClassName; popTopLevelOrAspect(); } - { if (shouldAddClassBodyDecl()) { - root.addClassBodyDecl(jjtThis, className, fileName, modifiers, enclosingAspect); - } - } -} - -void InterfaceMemberDeclaration() : -{ - String modifiers; -} -{ - modifiers = Modifiers() - ( - UnmodifiedClassDeclaration(modifiers) - | - UnmodifiedInterfaceDeclaration(modifiers) - | - LOOKAHEAD( AspectType() JavaIdentifier() ( "[" "]" )* ( "," | "=" | ";" ) ) - FieldDeclaration(modifiers) - | - MethodDeclaration(modifiers) - ) -| - ";" -} - -void FieldDeclaration(String modifiers) : -{} -{ - AspectType() VariableDeclarator() ( "," VariableDeclarator() )* ";" - { if (shouldAddClassBodyDecl()) { - root.addClassBodyDecl(jjtThis, className, fileName, modifiers, enclosingAspect); - } - } -} - -void VariableDeclarator() : -{} -{ - VariableDeclaratorId() [ "=" VariableInitializer() ] - -} - -void VariableDeclaratorId() : -{} -{ - JavaIdentifier() ( "[" "]" )* -} - -void VariableInitializer() : -{} -{ - ArrayInitializer() -| - Expression() -} - -void ArrayInitializer() : -{} -{ - "{" [ VariableInitializer() ( LOOKAHEAD(2) "," VariableInitializer() )* ] [ "," ] "}" -} - -void MethodDeclaration(String modifiers) : -{} -{ - [ TypeParameters() ] - AspectResultType() MethodDeclarator() [ "throws" NameList() ] - ( Block() | ";" ) - { if (shouldAddClassBodyDecl()) { - root.addMethodDecl(jjtThis, className, fileName, modifiers, enclosingAspect); - } - } -} - -void MethodDeclarator() : -{} -{ - JavaIdentifier() FormalParameters() ( "[" "]" )* -} - -void FormalParameters() : -{} -{ - "(" [ FormalParameter() ( "," FormalParameter() )* ] ")" -} - -void FormalParameter() : -{} -{ - [ "final" ] Type() ["..."] VariableDeclaratorId() -} - -void ConstructorDeclaration(String modifiers) : -{} -{ - [ TypeParameters() ] - JavaIdentifier() FormalParameters() [ "throws" NameList() ] - "{" - [ LOOKAHEAD(ExplicitConstructorInvocation()) ExplicitConstructorInvocation() ] - ( BlockStatement() )* - "}" - { if (shouldAddClassBodyDecl()) { - root.addClassBodyDecl(jjtThis, className, fileName, modifiers, enclosingAspect); - } - } -} - -void ExplicitConstructorInvocation() : -{} -{ - LOOKAHEAD("this" Arguments() ";") - "this" Arguments() ";" -| - [ LOOKAHEAD(2) PrimaryExpression() "." ] "super" Arguments() ";" -} - -void Initializer() : -{} -{ - [ "static" ] Block() -} - - -/* - * Type, name and expression syntax follows. - */ - -// Attribute type names can not start with JastAdd reserved words such as 'syn', 'eq', etc. -String AspectType(): -{} -{ - ( - LOOKAHEAD(2) AspectReferenceType() - | - LOOKAHEAD(2) PrimitiveType() ( LOOKAHEAD(2) "[" "]" )+ - | - PrimitiveType() - ) - { return Unparser.unparse(jjtThis); } -} - -void AspectResultType(): -{} -{ - "void" - | - AspectType() -} - -void AspectReferenceType(): -{} -{ - ( AspectClassOrInterfaceType() ) ( LOOKAHEAD(2) "[" "]" )* -} - -SimpleNode AspectClassOrInterfaceType(): -{} -{ - ( - <IDENTIFIER> [ LOOKAHEAD(2) TypeArguments() ] - ( LOOKAHEAD(2) "." JavaIdentifier() [ LOOKAHEAD(2) TypeArguments() ] )* - ) - { return jjtThis; } -} - -/*Changed to return string */ -String Type(): -{} -{ - ( - LOOKAHEAD(2) ReferenceType() - | - PrimitiveType() - ) - { return Unparser.unparse(jjtThis); } -} - -void ReferenceType(): -{} -{ - PrimitiveType() ( LOOKAHEAD(2) "[" "]" )+ - | - ( ClassOrInterfaceType() ) ( LOOKAHEAD(2) "[" "]" )* -} - -SimpleNode ClassOrInterfaceType(): -{} -{ - ( - JavaIdentifier() [ LOOKAHEAD(2) TypeArguments() ] - ( LOOKAHEAD(2) "." JavaIdentifier() [ LOOKAHEAD(2) TypeArguments() ] )* - ) - { return jjtThis; } -} - -void TypeArguments(): -{} -{ - "<" [ TypeArgument() ( "," TypeArgument() )* ] ">" -} - -void TypeArgument(): -{} -{ - ReferenceType() - | - "?" [ WildcardBounds() ] -} - -void WildcardBounds(): -{} -{ - "extends" ReferenceType() - | - "super" ReferenceType() -} - -void PrimitiveType(): -{} -{ - "boolean" -| - "char" -| - "byte" -| - "short" -| - "int" -| - "long" -| - "float" -| - "double" -} - -void ResultType(): -{} -{ - "void" -| - Type() -} - -/* Changed to return token */ -String Name() : -/* - * A lookahead of 2 is required below since "Name" can be followed - * by a ".*" when used in the context of an "ImportDeclaration". - */ -{} -{ - (JavaIdentifier() - ( LOOKAHEAD(2) "." JavaIdentifier() - )* - ) - { return Unparser.unparse(jjtThis); } -} - -SimpleNode NameList() : -{} -{ - (Name() - ( "," Name() - )* - ) - { - return jjtThis; - } -} - - -/* - * Expression syntax follows. - */ - -SimpleNode Expression() : -/* - * This expansion has been written this way instead of: - * Assignment() | ConditionalExpression() - * for performance reasons. - * However, it is a weakening of the grammar for it allows the LHS of - * assignments to be any conditional expression whereas it can only be - * a primary expression. Consider adding a semantic predicate to work - * around this. - */ -{} -{ -( - LOOKAHEAD(LambdaExpression()) - LambdaExpression() -| - ConditionalExpression() - [ - LOOKAHEAD(2) - AssignmentOperator() Expression() - ] -) - { - return jjtThis; - } -} - -void AssignmentOperator() : -{} -{ - "=" | "*=" | "/=" | "%=" | "+=" | "-=" | "<<=" | ">>=" | ">>>=" | "&=" | "^=" | "|=" -} - -void ConditionalExpression() : -{} -{ - ConditionalOrExpression() [ "?" Expression() ":" ConditionalExpression() ] -} - -void ConditionalOrExpression() : -{} -{ - ConditionalAndExpression() ( "||" ConditionalAndExpression() )* -} - -void ConditionalAndExpression() : -{} -{ - InclusiveOrExpression() ( "&&" InclusiveOrExpression() )* -} - -void InclusiveOrExpression() : -{} -{ - ExclusiveOrExpression() ( "|" ExclusiveOrExpression() )* -} - -void ExclusiveOrExpression() : -{} -{ - AndExpression() ( "^" AndExpression() )* -} - -void AndExpression() : -{} -{ - EqualityExpression() ( "&" EqualityExpression() )* -} - -void EqualityExpression() : -{} -{ - InstanceOfExpression() ( ( "==" | "!=" ) InstanceOfExpression() )* -} - -void InstanceOfExpression() : -{} -{ - RelationalExpression() [ "instanceof" Type() ] -} - -void RelationalExpression() : -{} -{ - ShiftExpression() ( ( "<" | ">" | "<=" | ">=" ) ShiftExpression() )* -} - -void ShiftExpression(): -{} -{ - AdditiveExpression() ( ( "<<" | RSIGNEDSHIFT() | RUNSIGNEDSHIFT() ) AdditiveExpression() )* -} - -void AdditiveExpression() : -{} -{ - MultiplicativeExpression() ( ( "+" | "-" ) MultiplicativeExpression() )* -} - -void MultiplicativeExpression() : -{} -{ - UnaryExpression() ( ( "*" | "/" | "%" ) UnaryExpression() )* -} - -void UnaryExpression() : -{} -{ - ( "+" | "-" ) UnaryExpression() -| - PreIncrementExpression() -| - PreDecrementExpression() -| - UnaryExpressionNotPlusMinus() -} - -void PreIncrementExpression() : -{} -{ - "++" PrimaryExpression() -} - -void PreDecrementExpression() : -{} -{ - "--" PrimaryExpression() -} - -void UnaryExpressionNotPlusMinus() : -{} -{ - ( "~" | "!" ) UnaryExpression() -| - LOOKAHEAD( CastLookahead() ) - CastExpression() -| - PostfixExpression() -} - -// This production is to determine lookahead only. The LOOKAHEAD specifications -// below are not used, but they are there just to indicate that we know about -// this. -void CastLookahead() : -{} -{ - LOOKAHEAD(2) - "(" PrimitiveType() -| - LOOKAHEAD("(" Type() "[") - "(" Type() "[" "]" -| - "(" Type() ")" ( "~" | "!" | "(" | JavaIdentifier() | "this" | "super" | "new" | Literal() ) -} - -void PostfixExpression() : -{} -{ - PrimaryExpression() [ "++" | "--" ] -} - -void CastExpression() : -{} -{ - LOOKAHEAD("(" PrimitiveType()) - "(" Type() ")" UnaryExpression() -| - "(" Type() ")" UnaryExpressionNotPlusMinus() -} - -void PrimaryExpression() : -{} -{ - PrimaryPrefix() ( LOOKAHEAD(2) PrimarySuffix() )* -} - -void MemberSelector(): -{} -{ - "." TypeArguments() JavaIdentifier() -} - -void PrimaryPrefix() : -{} -{ - Literal() -| - "this" -| - "super" "." JavaIdentifier() -| - "(" Expression() ")" -| - AllocationExpression() -| - LOOKAHEAD( ResultType() "." "class" ) - ResultType() "." "class" -| - Name() -} - -void PrimarySuffix() : -{} -{ - LOOKAHEAD(2) - "." "this" -| - LOOKAHEAD(2) - "." AllocationExpression() -| - LOOKAHEAD(3) - "." TypeArguments() JavaIdentifier() -| - "[" Expression() "]" -| - "." JavaIdentifier() -| - Arguments() -| - LOOKAHEAD(2) - "::" "new" -| - LOOKAHEAD(2) - "::" JavaIdentifier() -} - -void Literal() : -{} -{ - <INTEGER_LITERAL> -| - <FLOATING_POINT_LITERAL> -| - <CHARACTER_LITERAL> -| - <STRING_LITERAL> -| - BooleanLiteral() -| - NullLiteral() -} - -void BooleanLiteral() : -{} -{ - "true" -| - "false" -} - -void NullLiteral() : -{} -{ - "null" -} - -void Arguments() : -{} -{ - "(" [ ArgumentList() ] ")" -} - -void ArgumentList() : -{} -{ - Expression() ( "," Expression() )* -} - -void AllocationExpression() : -{ String outerClassName = className; - className = "D$u$m$m$y"; - pushTopLevelOrAspect("expr"); -} -{ - ( - LOOKAHEAD(2) - "new" PrimitiveType() ArrayDimsAndInits() -| - "new" ClassOrInterfaceType() [ TypeArguments() ] - - ( - ArrayDimsAndInits() - | - Arguments() - [ ClassBody() ] - ) - ) - { - className = outerClassName; - popTopLevelOrAspect(); - } -} - -/* - * The third LOOKAHEAD specification below is to parse to PrimarySuffix - * if there is an expression between the "[...]". - */ -void ArrayDimsAndInits() : -{} -{ - LOOKAHEAD(2) - ( LOOKAHEAD(2) "[" Expression() "]" )+ ( LOOKAHEAD(2) "[" "]" )* -| - ( "[" "]" )+ ArrayInitializer() -} - -/* - * Java 8 expression additions follow. - * - * New Java 8 expressions: lambdas, method/constructor reference, union types. - */ -void LambdaExpression() : -{} -{ - LambdaParameters() "->" ( Expression() | Block() ) -} - -void LambdaParameters() : -{} -{ - Name() -| - "(" [ LOOKAHEAD(2) TypedLambdaParameters() | UntypedLambdaParameters() ] ")" -} - -void TypedLambdaParameters() : -{} -{ - Type() Name() ( "," Type() Name() )* -} - -void UntypedLambdaParameters() : -{} -{ - Name() ( "," Name() )* -} - -/* - * Statement syntax follows. - */ - -void Statement() : -{} -{ - LOOKAHEAD(2) - LabeledStatement() -| - AssertStatement() -| - Block() -| - EmptyStatement() -| - StatementExpression() ";" -| - SwitchStatement() -| - IfStatement() -| - WhileStatement() -| - DoStatement() -| - ForStatement() -| - BreakStatement() -| - ContinueStatement() -| - ReturnStatement() -| - ThrowStatement() -| - SynchronizedStatement() -| - TryStatement() -} - -void AssertStatement(): -{} -{ - "assert" Expression() [ ":" Expression() ] ";" -} - -void LabeledStatement() : -{} -{ - JavaIdentifier() ":" Statement() -} - -SimpleNode Block() : -{} -{ - ( - "{" ( BlockStatement() )* "}" - ) - { - return jjtThis; - } -} - -void BlockStatement() : -{} -{ - LOOKAHEAD([ "final" ] Type() JavaIdentifier()) - LocalVariableDeclaration() ";" -| - Statement() -| - UnmodifiedClassDeclaration("") -} - -void LocalVariableDeclaration() : -{} -{ - [ "final" ] Type() VariableDeclarator() ( "," VariableDeclarator() )* -} - -void EmptyStatement() : -{} -{ - ";" -} - -void StatementExpression() : -/* - * The last expansion of this production accepts more than the legal - * Java expansions for StatementExpression. This expansion does not - * use PostfixExpression for performance reasons. - */ -{} -{ - PreIncrementExpression() -| - PreDecrementExpression() -| - PrimaryExpression() - [ - "++" - | - "--" - | - AssignmentOperator() Expression() - ] -} - -void SwitchStatement() : -{} -{ - "switch" "(" Expression() ")" "{" - ( SwitchLabel() ( BlockStatement() )* )* - "}" -} - -void SwitchLabel() : -{} -{ - "case" Expression() ":" -| - "default" ":" -} - -void IfStatement() : -/* - * The disambiguating algorithm of JavaCC automatically binds dangling - * else's to the innermost if statement. The LOOKAHEAD specification - * is to tell JavaCC that we know what we are doing. - */ -{} -{ - "if" "(" Expression() ")" Statement() [ LOOKAHEAD(1) "else" Statement() ] -} - -void WhileStatement() : -{} -{ - "while" "(" Expression() ")" Statement() -} - -void DoStatement() : -{} -{ - "do" Statement() "while" "(" Expression() ")" ";" -} - -void ForStatement() : -{} -{ - "for" "(" - - ( - LOOKAHEAD(Type() JavaIdentifier() ":") - Type() JavaIdentifier() ":" Expression() - | - [ ForInit() ] ";" [ Expression() ] ";" [ ForUpdate() ] - ) - - ")" Statement() -} - -void ForInit() : -{} -{ - LOOKAHEAD( [ "final" ] Type() JavaIdentifier() ) - LocalVariableDeclaration() -| - StatementExpressionList() -} - -void StatementExpressionList() : -{} -{ - StatementExpression() ( "," StatementExpression() )* -} - -void ForUpdate() : -{} -{ - StatementExpressionList() -} - -void BreakStatement() : -{} -{ - "break" [ JavaIdentifier() ] ";" -} - -void ContinueStatement() : -{} -{ - "continue" [ JavaIdentifier() ] ";" -} - -void ReturnStatement() : -{} -{ - "return" [ Expression() ] ";" -} - -void ThrowStatement() : -{} -{ - "throw" Expression() ";" -} - -void SynchronizedStatement() : -{} -{ - "synchronized" "(" Expression() ")" Block() -} - -void TryStatement() : -/* - * Semantic check required here to make sure that at least one - * finally/catch is present. - */ -{} -{ - "try" - // Java 7 extension (resource declarations): - [ "(" LocalVariableDeclaration() ( LOOKAHEAD(2) ";" LocalVariableDeclaration() )* [ ";" ] ")" ] - Block() - ( "catch" "(" ["final"] Type() ( "|" ["final"] Type() )* VariableDeclaratorId() ")" Block() )* - [ "finally" Block() ] -} - -/* We use productions to match >>>, >> and > so that we can keep the - * type declaration syntax with generics clean - */ - -void RUNSIGNEDSHIFT(): -{} -{ - ( LOOKAHEAD({ getToken(1).kind == GT && - ((Token.GTToken)getToken(1)).realKind == RUNSIGNEDSHIFT} ) - ">" ">" ">" - ) -} - -void RSIGNEDSHIFT(): -{} -{ - ( LOOKAHEAD({ getToken(1).kind == GT && - ((Token.GTToken)getToken(1)).realKind == RSIGNEDSHIFT} ) - ">" ">" - ) -} - -/* Annotation syntax follows. */ - -SimpleNode Annotation(): -{} -{ - ( - LOOKAHEAD( NormalAnnotation() ) - NormalAnnotation() - | - LOOKAHEAD( SingleMemberAnnotation() ) - SingleMemberAnnotation() - | - LOOKAHEAD( MarkerAnnotation() ) - MarkerAnnotation() - ) - { return jjtThis; } -} - -void NormalAnnotation(): -{} -{ - "@" Name() "(" [ MemberValuePairs() ] ")" -} - -void MarkerAnnotation(): -{} -{ - "@" Name() -} - -void SingleMemberAnnotation(): -{} -{ - "@" Name() "(" MemberValue() ")" -} - -void MemberValuePairs(): -{} -{ - MemberValuePair() ( "," MemberValuePair() )* -} - -void MemberValuePair(): -{} -{ - JavaIdentifier() "=" MemberValue() -} - -void MemberValue(): -{} -{ - Annotation() - | - MemberValueArrayInitializer() - | - ConditionalExpression() -} - -void MemberValueArrayInitializer(): -{} -{ - "{" MemberValue() ( LOOKAHEAD(2) "," MemberValue() )* [ "," ] "}" -} - - -/* Annotation Types. */ - -void AnnotationTypeDeclaration(String modifiers): -{} -{ - "@" "interface" { pushTopLevelOrAspect("annotation"); } JavaIdentifier() AnnotationTypeBody() { popTopLevelOrAspect(); } - { if (shouldAddClassBodyDecl()) { - root.addClassBodyDecl(jjtThis, className, fileName, modifiers, enclosingAspect); - } - } -} - -void AnnotationTypeBody(): -{} -{ - "{" ( AnnotationTypeMemberDeclaration() )* "}" -} - -void AnnotationTypeMemberDeclaration(): -{ - String modifiers; -} -{ - modifiers = Modifiers() - ( - LOOKAHEAD(AspectType() JavaIdentifier() "(") - AspectType() JavaIdentifier() "(" ")" [ DefaultValue() ] ";" - | - UnmodifiedClassDeclaration(modifiers) - | - UnmodifiedInterfaceDeclaration(modifiers) - | - UnmodifiedEnumDeclaration(modifiers) - | - AnnotationTypeDeclaration(modifiers) - | - FieldDeclaration(modifiers) - ) - | - ( ";" ) -} - -void DefaultValue(): -{} -{ - "default" MemberValue() -} - -// Adding (cache|uncached) keywords in front of each line in the cache configuration. -// This information is propagated to the grammar via setAttributeCacheMode(..) -void AspectCacheDeclaration(): -{ - Token t; - Token cacheConfig; - Token hostType; - Token attrName; - - int paramIndex = 1; - String paramType; - Token paramName; - org.jastadd.ast.AST.List paramList = new org.jastadd.ast.AST.List(); -} -{ - ( cacheConfig = "cache" | cacheConfig = "uncache" ) - hostType = <IDENTIFIER> "." - attrName = AttributeName() - "(" { paramList = new org.jastadd.ast.AST.List(); } - [ - paramType = Type() (<IDENTIFIER>)? - { paramList.add(new org.jastadd.ast.AST.Parameter(paramType, "p0")); } - ( - "," paramType = Type() (<IDENTIFIER>)? - { paramList.add(new org.jastadd.ast.AST.Parameter(paramType, "p" + (paramIndex++))); } - )* - ] - ")" - ";" - { - root.setAttributeCacheMode(cacheConfig.image, hostType.image, attrName.image, - paramList, fileName, cacheConfig.beginLine); - } -} - -// Valid Java identifiers include 'syn', 'eq', etc. (reserved JastAdd words are legal in pure Java) -void JavaIdentifier() : -{} -{ - <IDENTIFIER> -| <INH> -| <SYN> -| <LAZY> -| <REWRITE> -| <TO> -| <WHEN> -| <ASPECT> -| <EQUATION> -| <CIRCULAR> -| <REFINE> -| <COLL> -| <CONTRIBUTES> -| <EACH> -| <NTA> -| <CACHE> -| <UNCACHE> -} - -Token AttributeName() : -{Token t;} -{ - t = <IDENTIFIER> { return t; } -} -