From 1412f2ed14b60ba78b58a52b719eacba1b4a907a Mon Sep 17 00:00:00 2001 From: Aleksandr Mishin Date: Thu, 6 Oct 2022 12:15:35 +0300 Subject: [PATCH 01/25] slight gitignore modification --- .gitignore | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 555d8112..371cfecc 100644 --- a/.gitignore +++ b/.gitignore @@ -8,7 +8,6 @@ compile_and_run_tests.bat output.eo output_eo polystat_check -*.jar /hadoop/ /output_hadoop/ /bin @@ -16,7 +15,6 @@ polystat_check .metals/ .vscode hadoop* -J2EO*.jar j2eo-data /src/main/java/org/polystat/j2eo/antlrParser/* gradlew @@ -26,4 +24,5 @@ target .classpath .project .settings/ -ktlint \ No newline at end of file +ktlint + From f04fd1a3c2e6a6467608d3c754864cf53ed0f02c Mon Sep 17 00:00:00 2001 From: Aleksandr Mishin Date: Thu, 6 Oct 2022 12:15:55 +0300 Subject: [PATCH 02/25] src/pom initial --- pom.xml | 7 +++++-- src/pom.xml | 44 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 2 deletions(-) create mode 100644 src/pom.xml diff --git a/pom.xml b/pom.xml index 9f88aca1..5b211795 100644 --- a/pom.xml +++ b/pom.xml @@ -29,6 +29,9 @@ SOFTWARE. 1.0-SNAPSHOT pom j2eo + + src + 4.11.1 1.8 @@ -49,8 +52,8 @@ SOFTWARE. 1.7.33 - + ${project.basedir}/src/main/kotlin + ${project.basedir}/src/test/kotlin diff --git a/src/pom.xml b/src/pom.xml new file mode 100644 index 00000000..9dafccf1 --- /dev/null +++ b/src/pom.xml @@ -0,0 +1,44 @@ + + + + 4.0.0 + + org.polystat + j2eo-parent + 1.0-SNAPSHOT + + org.polystat + j2eo-sources + 1.0-SNAPSHOT + pom + j2eo-sources + + + org.jetbrains.kotlin + kotlin-stdlib + ${kotlin.version} + + + From 2ffe4ea7304f5c745d401d3bc9535cdb175a80b2 Mon Sep 17 00:00:00 2001 From: Aleksandr Mishin Date: Thu, 13 Oct 2022 12:43:07 +0300 Subject: [PATCH 03/25] mvn-build added parsing for antlr --- pom.xml | 36 +- src/main/antlr4/imports/JavaLexer.g4 | 245 +++++++++ src/main/antlr4/imports/JavaParser.g4 | 755 ++++++++++++++++++++++++++ src/pom.xml | 44 -- 4 files changed, 1031 insertions(+), 49 deletions(-) create mode 100644 src/main/antlr4/imports/JavaLexer.g4 create mode 100644 src/main/antlr4/imports/JavaParser.g4 delete mode 100644 src/pom.xml diff --git a/pom.xml b/pom.xml index 5b211795..f1e96de2 100644 --- a/pom.xml +++ b/pom.xml @@ -29,17 +29,18 @@ SOFTWARE. 1.0-SNAPSHOT pom j2eo - - src - + 4.11.1 1.8 - 1.0.1 + 1.0.0 3.0.0 1.5.0 1.2.2 3.1.0 + 0.2.0 0.8.8 [11,) 5.8.2 @@ -52,10 +53,29 @@ SOFTWARE. 1.7.33 - ${project.basedir}/src/main/kotlin + ${project.basedir}/src/main/ ${project.basedir}/src/test/kotlin + org.apache.maven.plugins maven-enforcer-plugin @@ -148,6 +168,7 @@ SOFTWARE. ${antlr.version} true + true @@ -347,6 +368,11 @@ SOFTWARE. + + org.polystat + j2ast + ${j2ast.version} + org.jetbrains.kotlin kotlin-stdlib diff --git a/src/main/antlr4/imports/JavaLexer.g4 b/src/main/antlr4/imports/JavaLexer.g4 new file mode 100644 index 00000000..34e0eacd --- /dev/null +++ b/src/main/antlr4/imports/JavaLexer.g4 @@ -0,0 +1,245 @@ +/* + [The "BSD licence"] + Copyright (c) 2013 Terence Parr, Sam Harwell + Copyright (c) 2017 Ivan Kochurkin (upgrade to Java 8) + Copyright (c) 2021 Michał Lorek (upgrade to Java 11) + Copyright (c) 2022 Michał Lorek (upgrade to Java 17) + 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. The name of the author may not be used to endorse or promote products + derived from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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. +*/ + +lexer grammar JavaLexer; + +@header { +package org.polystat.j2eo.antlrParser; +} + +// Keywords + +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'; +FINAL: 'final'; +FINALLY: 'finally'; +FLOAT: 'float'; +FOR: 'for'; +IF: 'if'; +GOTO: 'goto'; +IMPLEMENTS: 'implements'; +IMPORT: 'import'; +INSTANCEOF: 'instanceof'; +INT: 'int'; +INTERFACE: 'interface'; +LONG: 'long'; +NATIVE: 'native'; +NEW: 'new'; +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'; +TRY: 'try'; +VOID: 'void'; +VOLATILE: 'volatile'; +WHILE: 'while'; + +// Module related keywords +MODULE: 'module'; +OPEN: 'open'; +REQUIRES: 'requires'; +EXPORTS: 'exports'; +OPENS: 'opens'; +TO: 'to'; +USES: 'uses'; +PROVIDES: 'provides'; +WITH: 'with'; +TRANSITIVE: 'transitive'; + +// Local Variable Type Inference +VAR: 'var'; // reserved type name + +// Switch Expressions +YIELD: 'yield'; + +// Records +RECORD: 'record'; + +// Sealed Classes +SEALED: 'sealed'; +PERMITS: 'permits'; +NON_SEALED: 'non-sealed'; + +// Literals + +DECIMAL_LITERAL: ('0' | [1-9] (Digits? | '_'+ Digits)) [lL]?; +HEX_LITERAL: '0' [xX] [0-9a-fA-F] ([0-9a-fA-F_]* [0-9a-fA-F])? [lL]?; +OCT_LITERAL: '0' '_'* [0-7] ([0-7_]* [0-7])? [lL]?; +BINARY_LITERAL: '0' [bB] [01] ([01_]* [01])? [lL]?; + +FLOAT_LITERAL: (Digits '.' Digits? | '.' Digits) ExponentPart? [fFdD]? + | Digits (ExponentPart [fFdD]? | [fFdD]) + ; + +HEX_FLOAT_LITERAL: '0' [xX] (HexDigits '.'? | HexDigits? '.' HexDigits) [pP] [+-]? Digits [fFdD]?; + +BOOL_LITERAL: 'true' + | 'false' + ; + +CHAR_LITERAL: '\'' (~['\\\r\n] | EscapeSequence) '\''; + +STRING_LITERAL: '"' (~["\\\r\n] | EscapeSequence)* '"'; + +TEXT_BLOCK: '"""' [ \t]* [\r\n] (. | EscapeSequence)*? '"""'; + +NULL_LITERAL: 'null'; + +// Separators + +LPAREN: '('; +RPAREN: ')'; +LBRACE: '{'; +RBRACE: '}'; +LBRACK: '['; +RBRACK: ']'; +SEMI: ';'; +COMMA: ','; +DOT: '.'; + +// Operators + +ASSIGN: '='; +GT: '>'; +LT: '<'; +BANG: '!'; +TILDE: '~'; +QUESTION: '?'; +COLON: ':'; +EQUAL: '=='; +LE: '<='; +GE: '>='; +NOTEQUAL: '!='; +AND: '&&'; +OR: '||'; +INC: '++'; +DEC: '--'; +ADD: '+'; +SUB: '-'; +MUL: '*'; +DIV: '/'; +BITAND: '&'; +BITOR: '|'; +CARET: '^'; +MOD: '%'; + +ADD_ASSIGN: '+='; +SUB_ASSIGN: '-='; +MUL_ASSIGN: '*='; +DIV_ASSIGN: '/='; +AND_ASSIGN: '&='; +OR_ASSIGN: '|='; +XOR_ASSIGN: '^='; +MOD_ASSIGN: '%='; +LSHIFT_ASSIGN: '<<='; +RSHIFT_ASSIGN: '>>='; +URSHIFT_ASSIGN: '>>>='; + +// Java 8 tokens + +ARROW: '->'; +COLONCOLON: '::'; + +// Additional symbols not defined in the lexical specification + +AT: '@'; +ELLIPSIS: '...'; + +// Whitespace and comments + +WS: [ \t\r\n\u000C]+ -> channel(HIDDEN); +COMMENT: '/*' .*? '*/' -> channel(HIDDEN); +LINE_COMMENT: '//' ~[\r\n]* -> channel(HIDDEN); + +// Identifiers + +IDENTIFIER: Letter LetterOrDigit*; + +// Fragment rules + +fragment ExponentPart + : [eE] [+-]? Digits + ; + +fragment EscapeSequence + : '\\' [btnfr"'\\] + | '\\' ([0-3]? [0-7])? [0-7] + | '\\' 'u'+ HexDigit HexDigit HexDigit HexDigit + ; + +fragment HexDigits + : HexDigit ((HexDigit | '_')* HexDigit)? + ; + +fragment HexDigit + : [0-9a-fA-F] + ; + +fragment Digits + : [0-9] ([0-9_]* [0-9])? + ; + +fragment LetterOrDigit + : Letter + | [0-9] + ; + +fragment Letter + : [a-zA-Z$_] // these are the "java letters" below 0x7F + | ~[\u0000-\u007F\uD800-\uDBFF] // covers all characters above 0x7F which are not a surrogate + | [\uD800-\uDBFF] [\uDC00-\uDFFF] // covers UTF-16 surrogate pairs encodings for U+10000 to U+10FFFF + ; diff --git a/src/main/antlr4/imports/JavaParser.g4 b/src/main/antlr4/imports/JavaParser.g4 new file mode 100644 index 00000000..729d47ad --- /dev/null +++ b/src/main/antlr4/imports/JavaParser.g4 @@ -0,0 +1,755 @@ +/* + [The "BSD licence"] + Copyright (c) 2013 Terence Parr, Sam Harwell + Copyright (c) 2017 Ivan Kochurkin (upgrade to Java 8) + Copyright (c) 2021 Michał Lorek (upgrade to Java 11) + Copyright (c) 2022 Michał Lorek (upgrade to Java 17) + 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. The name of the author may not be used to endorse or promote products + derived from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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. +*/ + +parser grammar JavaParser; + +@header { +package org.polystat.j2eo; +} + +options { tokenVocab=JavaLexer; } + +compilationUnit + : packageDeclaration? importDeclaration* typeDeclaration* + | moduleDeclaration EOF + ; + +packageDeclaration + : annotation* PACKAGE qualifiedName ';' + ; + +importDeclaration + : IMPORT STATIC? qualifiedName ('.' '*')? ';' + ; + +typeDeclaration + : classOrInterfaceModifier* + (classDeclaration | enumDeclaration | interfaceDeclaration | annotationTypeDeclaration | recordDeclaration) + | ';' + ; + +modifier + : classOrInterfaceModifier + | NATIVE + | SYNCHRONIZED + | TRANSIENT + | VOLATILE + ; + +classOrInterfaceModifier + : annotation + | PUBLIC + | PROTECTED + | PRIVATE + | STATIC + | ABSTRACT + | FINAL // FINAL for class only -- does not apply to interfaces + | STRICTFP + | SEALED // Java17 + | NON_SEALED // Java17 + ; + +variableModifier + : FINAL + | annotation + ; + +classDeclaration + : CLASS identifier typeParameters? + (EXTENDS typeType)? + (IMPLEMENTS typeList)? + (PERMITS typeList)? // Java17 + classBody + ; + +typeParameters + : '<' typeParameter (',' typeParameter)* '>' + ; + +typeParameter + : annotation* identifier (EXTENDS annotation* typeBound)? + ; + +typeBound + : typeType ('&' typeType)* + ; + +enumDeclaration + : ENUM identifier (IMPLEMENTS typeList)? '{' enumConstants? ','? enumBodyDeclarations? '}' + ; + +enumConstants + : enumConstant (',' enumConstant)* + ; + +enumConstant + : annotation* identifier arguments? classBody? + ; + +enumBodyDeclarations + : ';' classBodyDeclaration* + ; + +interfaceDeclaration + : INTERFACE identifier typeParameters? (EXTENDS typeList)? (PERMITS typeList)? interfaceBody + ; + +classBody + : '{' classBodyDeclaration* '}' + ; + +interfaceBody + : '{' interfaceBodyDeclaration* '}' + ; + +classBodyDeclaration + : ';' + | STATIC? block + | modifier* memberDeclaration + ; + +memberDeclaration + : methodDeclaration + | genericMethodDeclaration + | fieldDeclaration + | constructorDeclaration + | genericConstructorDeclaration + | interfaceDeclaration + | annotationTypeDeclaration + | classDeclaration + | enumDeclaration + | recordDeclaration //Java17 + ; + +/* We use rule this even for void methods which cannot have [] after parameters. + This simplifies grammar and we can consider void to be a type, which + renders the [] matching as a context-sensitive issue or a semantic check + for invalid return type after parsing. + */ +methodDeclaration + : typeTypeOrVoid identifier formalParameters ('[' ']')* + (THROWS qualifiedNameList)? + methodBody + ; + +methodBody + : block + | ';' + ; + +typeTypeOrVoid + : typeType + | VOID + ; + +genericMethodDeclaration + : typeParameters methodDeclaration + ; + +genericConstructorDeclaration + : typeParameters constructorDeclaration + ; + +constructorDeclaration + : identifier formalParameters (THROWS qualifiedNameList)? constructorBody=block + ; + +fieldDeclaration + : typeType variableDeclarators ';' + ; + +interfaceBodyDeclaration + : modifier* interfaceMemberDeclaration + | ';' + ; + +interfaceMemberDeclaration + : constDeclaration + | interfaceMethodDeclaration + | genericInterfaceMethodDeclaration + | interfaceDeclaration + | annotationTypeDeclaration + | classDeclaration + | enumDeclaration + | recordDeclaration // Java17 + ; + +constDeclaration + : typeType constantDeclarator (',' constantDeclarator)* ';' + ; + +constantDeclarator + : identifier ('[' ']')* '=' variableInitializer + ; + +// Early versions of Java allows brackets after the method name, eg. +// public int[] return2DArray() [] { ... } +// is the same as +// public int[][] return2DArray() { ... } +interfaceMethodDeclaration + : interfaceMethodModifier* interfaceCommonBodyDeclaration + ; + +// Java8 +interfaceMethodModifier + : annotation + | PUBLIC + | ABSTRACT + | DEFAULT + | STATIC + | STRICTFP + ; + +genericInterfaceMethodDeclaration + : interfaceMethodModifier* typeParameters interfaceCommonBodyDeclaration + ; + +interfaceCommonBodyDeclaration + : annotation* typeTypeOrVoid identifier formalParameters ('[' ']')* (THROWS qualifiedNameList)? methodBody + ; + +variableDeclarators + : variableDeclarator (',' variableDeclarator)* + ; + +variableDeclarator + : variableDeclaratorId ('=' variableInitializer)? + ; + +variableDeclaratorId + : identifier ('[' ']')* + ; + +variableInitializer + : arrayInitializer + | expression + ; + +arrayInitializer + : '{' (variableInitializer (',' variableInitializer)* (',')? )? '}' + ; + +classOrInterfaceType + : identifier typeArguments? ('.' identifier typeArguments?)* + ; + +typeArgument + : typeType + | annotation* '?' ((EXTENDS | SUPER) typeType)? + ; + +qualifiedNameList + : qualifiedName (',' qualifiedName)* + ; + +formalParameters + : '(' ( receiverParameter? + | receiverParameter (',' formalParameterList)? + | formalParameterList? + ) ')' + ; + +receiverParameter + : typeType (identifier '.')* THIS + ; + +formalParameterList + : formalParameter (',' formalParameter)* (',' lastFormalParameter)? + | lastFormalParameter + ; + +formalParameter + : variableModifier* typeType variableDeclaratorId + ; + +lastFormalParameter + : variableModifier* typeType annotation* '...' variableDeclaratorId + ; + +// local variable type inference +lambdaLVTIList + : lambdaLVTIParameter (',' lambdaLVTIParameter)* + ; + +lambdaLVTIParameter + : variableModifier* VAR identifier + ; + +qualifiedName + : identifier ('.' identifier)* + ; + +literal + : integerLiteral + | floatLiteral + | CHAR_LITERAL + | STRING_LITERAL + | BOOL_LITERAL + | NULL_LITERAL + | TEXT_BLOCK // Java17 + ; + +integerLiteral + : DECIMAL_LITERAL + | HEX_LITERAL + | OCT_LITERAL + | BINARY_LITERAL + ; + +floatLiteral + : FLOAT_LITERAL + | HEX_FLOAT_LITERAL + ; + +// ANNOTATIONS +altAnnotationQualifiedName + : (identifier DOT)* '@' identifier + ; + +annotation + : ('@' qualifiedName | altAnnotationQualifiedName) ('(' ( elementValuePairs | elementValue )? ')')? + ; + +elementValuePairs + : elementValuePair (',' elementValuePair)* + ; + +elementValuePair + : identifier '=' elementValue + ; + +elementValue + : expression + | annotation + | elementValueArrayInitializer + ; + +elementValueArrayInitializer + : '{' (elementValue (',' elementValue)*)? (',')? '}' + ; + +annotationTypeDeclaration + : '@' INTERFACE identifier annotationTypeBody + ; + +annotationTypeBody + : '{' (annotationTypeElementDeclaration)* '}' + ; + +annotationTypeElementDeclaration + : modifier* annotationTypeElementRest + | ';' // this is not allowed by the grammar, but apparently allowed by the actual compiler + ; + +annotationTypeElementRest + : typeType annotationMethodOrConstantRest ';' + | classDeclaration ';'? + | interfaceDeclaration ';'? + | enumDeclaration ';'? + | annotationTypeDeclaration ';'? + | recordDeclaration ';'? // Java17 + ; + +annotationMethodOrConstantRest + : annotationMethodRest + | annotationConstantRest + ; + +annotationMethodRest + : identifier '(' ')' defaultValue? + ; + +annotationConstantRest + : variableDeclarators + ; + +defaultValue + : DEFAULT elementValue + ; + +// MODULES - Java9 + +moduleDeclaration + : OPEN? MODULE qualifiedName moduleBody + ; + +moduleBody + : '{' moduleDirective* '}' + ; + +moduleDirective + : REQUIRES requiresModifier* qualifiedName ';' + | EXPORTS qualifiedName (TO qualifiedName)? ';' + | OPENS qualifiedName (TO qualifiedName)? ';' + | USES qualifiedName ';' + | PROVIDES qualifiedName WITH qualifiedName ';' + ; + +requiresModifier + : TRANSITIVE + | STATIC + ; + +// RECORDS - Java 17 + +recordDeclaration + : RECORD identifier typeParameters? recordHeader + (IMPLEMENTS typeList)? + recordBody + ; + +recordHeader + : '(' recordComponentList? ')' + ; + +recordComponentList + : recordComponent (',' recordComponent)* + ; + +recordComponent + : typeType identifier + ; + +recordBody + : '{' classBodyDeclaration* '}' + ; + +// STATEMENTS / BLOCKS + +block + : '{' blockStatement* '}' + ; + +blockStatement + : localVariableDeclaration ';' + | statement + | localTypeDeclaration + ; + +localVariableDeclaration + : variableModifier* (typeType variableDeclarators | VAR identifier '=' expression) + ; + +identifier + : IDENTIFIER + | MODULE + | OPEN + | REQUIRES + | EXPORTS + | OPENS + | TO + | USES + | PROVIDES + | WITH + | TRANSITIVE + | YIELD + | SEALED + | PERMITS + | RECORD + | VAR + ; + +localTypeDeclaration + : classOrInterfaceModifier* + (classDeclaration | enumDeclaration | interfaceDeclaration | recordDeclaration) + | ';' + ; + +statement + : blockLabel=block # statementBlockLabel + | ASSERT expression (':' expression)? ';' # statementAssert + | IF parExpression statement (ELSE statement)? # statementIf + | FOR '(' forControl ')' statement # statementFor + | WHILE parExpression statement # statementWhile + | DO statement WHILE parExpression ';' # statementDo + | TRY block (catchClause+ finallyBlock? | finallyBlock) # statementTryBlock + | TRY resourceSpecification block catchClause* finallyBlock? # statementTryResourceSpecification + | SWITCH parExpression '{' switchBlockStatementGroup* switchLabel* '}' # statementSwitch + | SYNCHRONIZED parExpression block # statementSynchronized + | RETURN expression? ';' # statementReturn + | THROW expression ';' # statementThrow + | BREAK identifier? ';' # statementBreak + | CONTINUE identifier? ';' # statementContinue + | YIELD expression ';' /* Java17 */ # statementYield + | SEMI # statementSemi + | statementExpression=expression ';' # statementExpression + | switchExpression ';'? /* Java17 */ # statementSwitchExpression + | identifierLabel=identifier ':' statement # statementIdentifierLabel + ; + +catchClause + : CATCH '(' variableModifier* catchType identifier ')' block + ; + +catchType + : qualifiedName ('|' qualifiedName)* + ; + +finallyBlock + : FINALLY block + ; + +resourceSpecification + : '(' resources ';'? ')' + ; + +resources + : resource (';' resource)* + ; + +resource + : variableModifier* ( classOrInterfaceType variableDeclaratorId | VAR identifier ) '=' expression + | identifier + ; + +/** Matches cases then statements, both of which are mandatory. + * To handle empty cases at the end, we add switchLabel* to statement. + */ +switchBlockStatementGroup + : switchLabel+ blockStatement+ + ; + +switchLabel + : CASE (constantExpression=expression | enumConstantName=IDENTIFIER | typeType varName=identifier) ':' + | DEFAULT ':' + ; + +forControl + : enhancedForControl + | forInit? ';' expression? ';' forUpdate=expressionList? + ; + +forInit + : localVariableDeclaration + | expressionList + ; + +enhancedForControl + : variableModifier* (typeType | VAR) variableDeclaratorId ':' expression + ; + +// EXPRESSIONS + +parExpression + : '(' expression ')' + ; + +expressionList + : expression (',' expression)* + ; + +methodCall + : identifier '(' expressionList? ')' + | THIS '(' expressionList? ')' + | SUPER '(' expressionList? ')' + ; + +expression + : primary # primaryExpresion + | expression bop='.' + ( + identifier + | methodCall + | THIS + | NEW nonWildcardTypeArguments? innerCreator + | SUPER superSuffix + | explicitGenericInvocation + ) # reference + | expression '[' expression ']' # arrayAccess + | methodCall # methodInvocation + | NEW creator # instanceCreation + | '(' annotation* typeType ('&' typeType)* ')' expression # castExpresion + | expression postfix=('++' | '--') # postfixExpression + | prefix=('+'|'-'|'++'|'--') expression # prefixExpression + | prefix=('~'|'!') expression # prefixExpression + | expression bop=('*'|'/'|'%') expression # binaryExpression + | expression bop=('+'|'-') expression # binaryExpression + | expression ('<' '<' | '>' '>' '>' | '>' '>') expression # binaryExpression + | expression bop=('<=' | '>=' | '>' | '<') expression # binaryExpression + | expression bop=INSTANCEOF (typeType | pattern) # instanceOfExpression + | expression bop=('==' | '!=') expression # binaryExpression + | expression bop='&' expression # binaryExpression + | expression bop='^' expression # binaryExpression + | expression bop='|' expression # binaryExpression + | expression bop='&&' expression # binaryExpression + | expression bop='||' expression # binaryExpression + | expression bop='?' expression ':' expression # ternaryExpression + | expression + bop=('=' | '+=' | '-=' | '*=' | '/=' | '&=' | '|=' | '^=' | '>>=' | '>>>=' | '<<=' | '%=') + expression # binaryExpression + | lambdaExpression # lambda // Java8 + | switchExpression # switch // Java17 + + // Java 8 methodReference + | expression '::' typeArguments? identifier # methodReference + | typeType '::' (typeArguments? identifier | NEW) # methodReference + | classType '::' typeArguments? NEW # methodReference + ; + +// Java17 +pattern + : variableModifier* typeType annotation* identifier + ; + +// Java8 +lambdaExpression + : lambdaParameters '->' lambdaBody + ; + +// Java8 +lambdaParameters + : identifier + | '(' formalParameterList? ')' + | '(' identifier (',' identifier)* ')' + | '(' lambdaLVTIList? ')' + ; + +// Java8 +lambdaBody + : expression + | block + ; + +primary + : '(' expression ')' # parenthesizedExpression + | THIS # thisExpresion + | SUPER # superExpression + | literal # literalExpression + | identifier # identifierExpresion + | typeTypeOrVoid '.' CLASS # classExpression + | nonWildcardTypeArguments (explicitGenericInvocationSuffix | THIS arguments) # nonWildcardTypeArgumentsExpression + ; + +// Java17 +switchExpression + : SWITCH parExpression '{' switchLabeledRule* '}' + ; + +// Java17 +switchLabeledRule + : CASE (expressionList | NULL_LITERAL | guardedPattern) (ARROW | COLON) switchRuleOutcome + | DEFAULT (ARROW | COLON) switchRuleOutcome + ; + +// Java17 +guardedPattern + : '(' guardedPattern ')' + | variableModifier* typeType annotation* identifier ('&&' expression)* + | guardedPattern '&&' expression + ; + +// Java17 +switchRuleOutcome + : block + | blockStatement* + ; + +classType + : (classOrInterfaceType '.')? annotation* identifier typeArguments? + ; + +creator + : nonWildcardTypeArguments createdName classCreatorRest + | createdName (arrayCreatorRest | classCreatorRest) + ; + +createdName + : identifier typeArgumentsOrDiamond? ('.' identifier typeArgumentsOrDiamond?)* + | primitiveType + ; + +innerCreator + : identifier nonWildcardTypeArgumentsOrDiamond? classCreatorRest + ; + +arrayCreatorRest + : '[' (']' ('[' ']')* arrayInitializer | expression ']' ('[' expression ']')* ('[' ']')*) + ; + +classCreatorRest + : arguments classBody? + ; + +explicitGenericInvocation + : nonWildcardTypeArguments explicitGenericInvocationSuffix + ; + +typeArgumentsOrDiamond + : '<' '>' + | typeArguments + ; + +nonWildcardTypeArgumentsOrDiamond + : '<' '>' + | nonWildcardTypeArguments + ; + +nonWildcardTypeArguments + : '<' typeList '>' + ; + +typeList + : typeType (',' typeType)* + ; + +typeType + : annotation* classOrInterfaceType (annotation* '[' ']')* # typeClassOrInterfaceType + | annotation* primitiveType (annotation* '[' ']')* # typePrimitiveType + ; + +primitiveType + : BOOLEAN + | CHAR + | BYTE + | SHORT + | INT + | LONG + | FLOAT + | DOUBLE + ; + +typeArguments + : '<' typeArgument (',' typeArgument)* '>' + ; + +superSuffix + : arguments + | '.' typeArguments? identifier arguments? + ; + +explicitGenericInvocationSuffix + : SUPER superSuffix + | identifier arguments + ; + +arguments + : '(' expressionList? ')' + ; diff --git a/src/pom.xml b/src/pom.xml deleted file mode 100644 index 9dafccf1..00000000 --- a/src/pom.xml +++ /dev/null @@ -1,44 +0,0 @@ - - - - 4.0.0 - - org.polystat - j2eo-parent - 1.0-SNAPSHOT - - org.polystat - j2eo-sources - 1.0-SNAPSHOT - pom - j2eo-sources - - - org.jetbrains.kotlin - kotlin-stdlib - ${kotlin.version} - - - From 1b68e3626969e962b0bc3b23edea8d3738e693c8 Mon Sep 17 00:00:00 2001 From: Aleksandr Mishin Date: Thu, 13 Oct 2022 17:23:10 +0300 Subject: [PATCH 04/25] generating antlr files in target directory --- .github/workflows/gradle-build.yml | 91 --- build.gradle.kts | 384 --------- build.sh | 11 - grammar/JavaLexer.g4 | 245 ------ grammar/JavaParser.g4 | 755 ------------------ grammar/README.md | 16 - pom.xml | 53 +- settings.gradle.kts | 1 - src/main/antlr4/{imports => }/JavaLexer.g4 | 2 +- src/main/antlr4/{imports => }/JavaParser.g4 | 2 +- .../org/polystat/j2eo/antlrParser/README.md | 1 - .../org/polystat/j2eo/treeMapper/Visitor.kt | 11 +- 12 files changed, 37 insertions(+), 1535 deletions(-) delete mode 100644 .github/workflows/gradle-build.yml delete mode 100644 build.gradle.kts delete mode 100755 build.sh delete mode 100644 grammar/JavaLexer.g4 delete mode 100644 grammar/JavaParser.g4 delete mode 100644 grammar/README.md delete mode 100644 settings.gradle.kts rename src/main/antlr4/{imports => }/JavaLexer.g4 (99%) rename src/main/antlr4/{imports => }/JavaParser.g4 (99%) delete mode 100644 src/main/java/org/polystat/j2eo/antlrParser/README.md diff --git a/.github/workflows/gradle-build.yml b/.github/workflows/gradle-build.yml deleted file mode 100644 index eba3d1af..00000000 --- a/.github/workflows/gradle-build.yml +++ /dev/null @@ -1,91 +0,0 @@ -name: Gradle Build - -on: - push: - branches: - - master - - develop - pull_request: - -jobs: - gradle: - strategy: - matrix: - os: [ - macos-latest, - windows-latest - ] - runs-on: ${{ matrix.os }} - steps: - - uses: actions/checkout@v2 - - - uses: actions/setup-java@v1 - with: - java-version: 11 - - - uses: suisei-cn/actions-download-file@v1.0.1 - name: Download ANTLR - with: - url: "https://www.antlr.org/download/antlr-4.9.2-complete.jar" - target: . - - - uses: gradle/gradle-build-action@v1 - with: - arguments: build --info - gradle-version: 7.2 - - - name: Upload Gradle test report - uses: actions/upload-artifact@v2 - if: ${{ always() }} - with: - name: gradle-test-report-${{ matrix.os }} - path: build/reports/tests/test/ - - - name: Print J2EO test report - run: | - cd ./src/test/resources/ - python ./test_report.py - - gradle_ubuntu: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - - uses: actions/setup-java@v1 - with: - java-version: 11 - - - run: | - wget https://www.antlr.org/download/antlr-4.9.2-complete.jar - - - uses: gradle/gradle-build-action@v1 - with: - arguments: build --info - gradle-version: 7.2 - - - name: Upload Gradle test report - uses: actions/upload-artifact@v2 - if: ${{ always() }} - with: - name: gradle-test-report-ubuntu-latest - path: build/reports/tests/test/ - - - name: Log coverage percentage - run: | - echo "coverage = ${{ steps.jacoco.outputs.coverage }}" - echo "branch coverage = ${{ steps.jacoco.outputs.branches }}" - - - name: Upload coverage to Codecov - uses: codecov/codecov-action@v3 - with: - directory: ./build/reports/jacoco/test/ - fail_ci_if_error: false - flags: unittests - name: codecov-umbrella - path_to_write_report: ./build/reports/codecov_report.txt - verbose: true - - - name: Print J2EO test report - run: | - cd ./src/test/resources/ - python ./test_report.py diff --git a/build.gradle.kts b/build.gradle.kts deleted file mode 100644 index 44f92cd8..00000000 --- a/build.gradle.kts +++ /dev/null @@ -1,384 +0,0 @@ -import org.apache.tools.ant.taskdefs.condition.Os -import org.gradle.jvm.tasks.Jar -import org.jetbrains.kotlin.gradle.tasks.KotlinCompile -import org.jlleitschuh.gradle.ktlint.reporter.ReporterType - -plugins { - java - antlr - jacoco - pmd - checkstyle - `maven-publish` - signing - id("io.spring.dependency-management") version "1.0.11.RELEASE" - id("org.jlleitschuh.gradle.ktlint") version "10.2.1" - // id("org.cqfn.diktat.diktat-gradle-plugin") version "1.0.2" - kotlin("jvm") version "1.6.0" - id("com.github.dawnwords.jacoco.badge") version "0.2.4" -} - -val mvnUsername: String? by project -val mvnPassword: String? by project -val mvnPublicationVersion: String? by project -val candidates: String? by project -val amount: String? by project - -group = "org.polystat" -version = mvnPublicationVersion ?: "0.6.0" - -val compileKotlin: KotlinCompile by tasks -compileKotlin.kotlinOptions { - jvmTarget = "11" -} -val compileTestKotlin: KotlinCompile by tasks -compileTestKotlin.kotlinOptions { - jvmTarget = "11" -} - -// The Java grammar source file for ANTLR -val javaParserG4FilePath = "grammar/JavaParser.g4" -val javaLexerG4FilePath = "grammar/JavaLexer.g4" - -// Where to put generated parser -val javaParserSavePath = "src/main/java/org/polystat/j2eo/antlrParser" - -val antlrJar = "antlr-4.9.2-complete.jar" - -repositories { - mavenCentral() -} - -dependencyManagement { - imports { - mavenBom("com.jcabi:parent:0.57.0") - } -} - -dependencies { - // Library for command-line arguments support - implementation("commons-cli:commons-cli:1.5.0") - // Functional stuff - implementation("io.arrow-kt:arrow-core:1.0.1") - // Kotlin logger - implementation("org.slf4j:slf4j-simple:1.7.33") - implementation("io.github.microutils:kotlin-logging-jvm:2.1.21") - - implementation("org.junit.platform:junit-platform-commons:1.8.2") - testImplementation("org.junit.jupiter:junit-jupiter-api:5.8.2") - testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.8.2") - implementation(kotlin("stdlib-jdk8")) - - // Use ANTLR for parser generation - antlr("org.antlr:antlr4:4.9.2") - - implementation("org.polystat:j2ast:0.2.0") -} - -java { - sourceCompatibility = JavaVersion.VERSION_11 - targetCompatibility = JavaVersion.VERSION_11 - - withJavadocJar() - withSourcesJar() -} - -tasks.javadoc { - if (JavaVersion.current().isJava9Compatible) { - (options as StandardJavadocDocletOptions).addBooleanOption("html5", true) - } -} - -val fatJar = task("fatJar", type = Jar::class) { - // baseName = "${project.name}-fat" - // manifest Main-Class attribute is optional. - // (Used only to provide default main class for executable jar) - manifest { - attributes["Main-Class"] = "org.polystat.j2eo.main.Main2" // fully qualified class name of default main class - } - // Include dependencies - from(configurations.runtimeClasspath.get().map { if (it.isDirectory) it else zipTree(it) }) - with(tasks["jar"] as CopySpec) - duplicatesStrategy = DuplicatesStrategy.INCLUDE -} - -tasks { - compileKotlin { - dependsOn(generateGrammarSource) - } - compileTestKotlin { - dependsOn(generateTestGrammarSource) - } - runKtlintFormatOverMainSourceSet { - dependsOn(generateGrammarSource) - } - runKtlintFormatOverTestSourceSet { - dependsOn(generateTestGrammarSource) - } - classes { - dependsOn(ktlintFormat) - } - ktlintFormat { - finalizedBy(ktlintCheck) - } - // diktatFix { - // finalizedBy(diktatCheck) - // } - pmdMain { - dependsOn(classes) - } - checkstyleMain { - dependsOn(classes) - } - pmdTest { - dependsOn(testClasses) - } - checkstyleTest { - dependsOn(testClasses) - } - jacocoTestReport { - dependsOn(test) - finalizedBy(generateJacocoBadge) - } - test { - dependsOn(pmdTest, checkstyleTest) - finalizedBy(jacocoTestReport) - } - build { - dependsOn(fatJar) - } -} - -tasks.withType(JavaCompile::class).configureEach { - options.forkOptions.jvmArgs!!.addAll( - arrayOf( - "--add-opens", "jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED" - ) - ) -} - -tasks.javadoc { - exclude("parser/**") -} - -tasks.test { - ignoreFailures = true - useJUnitPlatform() - systemProperty("candidates", candidates ?: "false") - systemProperty("amount", amount ?: "15") -} - -pmd { - isIgnoreFailures = true - isConsoleOutput = false - toolVersion = "6.40.0" - rulesMinimumPriority.set(5) - ruleSets = listOf("category/java/codestyle.xml") -} - -ktlint { - verbose.set(true) - outputToConsole.set(true) - coloredOutput.set(true) - ignoreFailures.set(false) - reporters { - reporter(ReporterType.CHECKSTYLE) - reporter(ReporterType.JSON) - reporter(ReporterType.HTML) - } - filter { - exclude("**/style-violations.kt") - } -} - -// diktat { -// reporterType = "sarif" -// ignoreFailures = true -// } - -tasks.getByName("build") { - println("Building parser with ANTLR...") - runAntlr() -} - -checkstyle { - toolVersion = "9.1" - isShowViolations = false - isIgnoreFailures = false -} - -tasks.withType().configureEach { - reports { - xml.required.set(false) - html.required.set(true) - html.stylesheet = resources.text.fromFile("config/xsl/checkstyle-simple.xsl") - } -} -tasks.withType { - /*violationRules { - rule { - limit { - minimum = BigDecimal(0.62) - } - } - }*/ - - afterEvaluate { - classDirectories.setFrom( - files( - classDirectories.files.map { - fileTree(it).apply { - exclude("parser/**") - } - } - ) - ) - } -} -tasks.withType { - afterEvaluate { - classDirectories.setFrom( - files( - classDirectories.files.map { - fileTree(it).apply { - exclude("parser/**") - } - } - ) - ) - } - reports.csv.required.set(true) -} - -tasks.jacocoTestReport { - reports { - xml.required.set(true) - } -} -jacocoBadgeGenSetting { - jacocoReportPath = "$buildDir/reports/jacoco/test/jacocoTestReport.xml" - readmePath = "$projectDir/README.md" - // since v0.2.0, percentage limitation (0-100) for different type of coverage - // limit = ['instruction': 0, 'branch': 0, 'line': 0, 'method': 0, 'class': 0] -} - -publishing { - publications { - create("mavenJava") { - groupId = "org.polystat" - artifactId = "j2eo" - version = project.version as String - from(components["java"]) - pom { - name.set("j2eo") - description.set("Java to EO transpiler.") - url.set("https://github.com/polystat/j2eo") - // properties.set(mapOf( - // "myProp" to "value", - // "prop.with.dots" to "anotherValue" - // )) - licenses { - license { - name.set("MIT") - url.set("https://github.com/polystat/polystat/blob/master/LICENSE.txt") - } - } - developers { - developer { - id.set("zouev") - name.set("Eugene Zouev") - email.set("e.zuev@innopolis.ru") - } - developer { - id.set("IamMaxim58") - name.set("Maxim Stepanov") - email.set("m.stepanov@innopolis.university") - } - developer { - id.set("Ilia_Mil") - name.set("Ilya Milyoshin") - email.set("i.mileshin@innopolis.university") - } - developer { - id.set("egorklementev") - name.set("Egor Klementev") - email.set("e.klementev@innopolis.ru") - } - } - scm { - connection.set("scm:git:git@github.com:polystat/polystat.git") - developerConnection.set("scm:git:git@github.com:polystat/polystat.git") - url.set("https://github.com/polystat/polystat") - } - } - repositories { - maven { - credentials { - println("Applying Maven credentials") - - username = mvnUsername - password = mvnPassword - } - url = uri("https://s01.oss.sonatype.org/content/repositories/releases/") - } - } - } - } -} - -signing { - setRequired({ - gradle.taskGraph.hasTask("publish") - }) - - sign(publishing.publications["mavenJava"]) -} - -tasks.getByName("signMavenJavaPublication") { - dependsOn(fatJar) -} - -/** - * Runs ANTLR using OS-specific shell command. - */ -fun runAntlr() { - val antlrArgs = mutableListOf( - "-jar", - "../$antlrJar", - javaParserG4FilePath.replace("grammar/", ""), - javaLexerG4FilePath.replace("grammar/", ""), - "-visitor", - "-o", - "../$javaParserSavePath" - ) - - try { - when { - Os.isFamily(Os.FAMILY_WINDOWS) -> - exec { - workingDir = File("grammar") - executable = "java" - args = antlrArgs - } - Os.isFamily(Os.FAMILY_MAC) -> - exec { - workingDir = File("grammar") - executable = "java" - args = antlrArgs - } - Os.isFamily(Os.FAMILY_UNIX) -> - exec { - workingDir = File("grammar") - executable = "java" - args = antlrArgs - } - else -> - throw UnsupportedOperationException( - "Your OS is not yet supported. File a GitHub or issue or " + - "provide a Pull Request with support for ANTLR execution for your OS." - ) - } - } catch (e: Exception) { - println("Couldn't run ANTLR; $e") - } -} diff --git a/build.sh b/build.sh deleted file mode 100755 index e7fb7b54..00000000 --- a/build.sh +++ /dev/null @@ -1,11 +0,0 @@ -#!/bin/sh - -# Fail on non-zero exit codes -set -e - -echo "Building J2EO..." -# don't throw error if a dir doesn't exist -rm -rf build/libs -gradle fatJar -x test -cp build/libs/* ./ -echo "Build completed" diff --git a/grammar/JavaLexer.g4 b/grammar/JavaLexer.g4 deleted file mode 100644 index 34e0eacd..00000000 --- a/grammar/JavaLexer.g4 +++ /dev/null @@ -1,245 +0,0 @@ -/* - [The "BSD licence"] - Copyright (c) 2013 Terence Parr, Sam Harwell - Copyright (c) 2017 Ivan Kochurkin (upgrade to Java 8) - Copyright (c) 2021 Michał Lorek (upgrade to Java 11) - Copyright (c) 2022 Michał Lorek (upgrade to Java 17) - 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. The name of the author may not be used to endorse or promote products - derived from this software without specific prior written permission. - - THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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. -*/ - -lexer grammar JavaLexer; - -@header { -package org.polystat.j2eo.antlrParser; -} - -// Keywords - -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'; -FINAL: 'final'; -FINALLY: 'finally'; -FLOAT: 'float'; -FOR: 'for'; -IF: 'if'; -GOTO: 'goto'; -IMPLEMENTS: 'implements'; -IMPORT: 'import'; -INSTANCEOF: 'instanceof'; -INT: 'int'; -INTERFACE: 'interface'; -LONG: 'long'; -NATIVE: 'native'; -NEW: 'new'; -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'; -TRY: 'try'; -VOID: 'void'; -VOLATILE: 'volatile'; -WHILE: 'while'; - -// Module related keywords -MODULE: 'module'; -OPEN: 'open'; -REQUIRES: 'requires'; -EXPORTS: 'exports'; -OPENS: 'opens'; -TO: 'to'; -USES: 'uses'; -PROVIDES: 'provides'; -WITH: 'with'; -TRANSITIVE: 'transitive'; - -// Local Variable Type Inference -VAR: 'var'; // reserved type name - -// Switch Expressions -YIELD: 'yield'; - -// Records -RECORD: 'record'; - -// Sealed Classes -SEALED: 'sealed'; -PERMITS: 'permits'; -NON_SEALED: 'non-sealed'; - -// Literals - -DECIMAL_LITERAL: ('0' | [1-9] (Digits? | '_'+ Digits)) [lL]?; -HEX_LITERAL: '0' [xX] [0-9a-fA-F] ([0-9a-fA-F_]* [0-9a-fA-F])? [lL]?; -OCT_LITERAL: '0' '_'* [0-7] ([0-7_]* [0-7])? [lL]?; -BINARY_LITERAL: '0' [bB] [01] ([01_]* [01])? [lL]?; - -FLOAT_LITERAL: (Digits '.' Digits? | '.' Digits) ExponentPart? [fFdD]? - | Digits (ExponentPart [fFdD]? | [fFdD]) - ; - -HEX_FLOAT_LITERAL: '0' [xX] (HexDigits '.'? | HexDigits? '.' HexDigits) [pP] [+-]? Digits [fFdD]?; - -BOOL_LITERAL: 'true' - | 'false' - ; - -CHAR_LITERAL: '\'' (~['\\\r\n] | EscapeSequence) '\''; - -STRING_LITERAL: '"' (~["\\\r\n] | EscapeSequence)* '"'; - -TEXT_BLOCK: '"""' [ \t]* [\r\n] (. | EscapeSequence)*? '"""'; - -NULL_LITERAL: 'null'; - -// Separators - -LPAREN: '('; -RPAREN: ')'; -LBRACE: '{'; -RBRACE: '}'; -LBRACK: '['; -RBRACK: ']'; -SEMI: ';'; -COMMA: ','; -DOT: '.'; - -// Operators - -ASSIGN: '='; -GT: '>'; -LT: '<'; -BANG: '!'; -TILDE: '~'; -QUESTION: '?'; -COLON: ':'; -EQUAL: '=='; -LE: '<='; -GE: '>='; -NOTEQUAL: '!='; -AND: '&&'; -OR: '||'; -INC: '++'; -DEC: '--'; -ADD: '+'; -SUB: '-'; -MUL: '*'; -DIV: '/'; -BITAND: '&'; -BITOR: '|'; -CARET: '^'; -MOD: '%'; - -ADD_ASSIGN: '+='; -SUB_ASSIGN: '-='; -MUL_ASSIGN: '*='; -DIV_ASSIGN: '/='; -AND_ASSIGN: '&='; -OR_ASSIGN: '|='; -XOR_ASSIGN: '^='; -MOD_ASSIGN: '%='; -LSHIFT_ASSIGN: '<<='; -RSHIFT_ASSIGN: '>>='; -URSHIFT_ASSIGN: '>>>='; - -// Java 8 tokens - -ARROW: '->'; -COLONCOLON: '::'; - -// Additional symbols not defined in the lexical specification - -AT: '@'; -ELLIPSIS: '...'; - -// Whitespace and comments - -WS: [ \t\r\n\u000C]+ -> channel(HIDDEN); -COMMENT: '/*' .*? '*/' -> channel(HIDDEN); -LINE_COMMENT: '//' ~[\r\n]* -> channel(HIDDEN); - -// Identifiers - -IDENTIFIER: Letter LetterOrDigit*; - -// Fragment rules - -fragment ExponentPart - : [eE] [+-]? Digits - ; - -fragment EscapeSequence - : '\\' [btnfr"'\\] - | '\\' ([0-3]? [0-7])? [0-7] - | '\\' 'u'+ HexDigit HexDigit HexDigit HexDigit - ; - -fragment HexDigits - : HexDigit ((HexDigit | '_')* HexDigit)? - ; - -fragment HexDigit - : [0-9a-fA-F] - ; - -fragment Digits - : [0-9] ([0-9_]* [0-9])? - ; - -fragment LetterOrDigit - : Letter - | [0-9] - ; - -fragment Letter - : [a-zA-Z$_] // these are the "java letters" below 0x7F - | ~[\u0000-\u007F\uD800-\uDBFF] // covers all characters above 0x7F which are not a surrogate - | [\uD800-\uDBFF] [\uDC00-\uDFFF] // covers UTF-16 surrogate pairs encodings for U+10000 to U+10FFFF - ; diff --git a/grammar/JavaParser.g4 b/grammar/JavaParser.g4 deleted file mode 100644 index 8b20a969..00000000 --- a/grammar/JavaParser.g4 +++ /dev/null @@ -1,755 +0,0 @@ -/* - [The "BSD licence"] - Copyright (c) 2013 Terence Parr, Sam Harwell - Copyright (c) 2017 Ivan Kochurkin (upgrade to Java 8) - Copyright (c) 2021 Michał Lorek (upgrade to Java 11) - Copyright (c) 2022 Michał Lorek (upgrade to Java 17) - 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. The name of the author may not be used to endorse or promote products - derived from this software without specific prior written permission. - - THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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. -*/ - -parser grammar JavaParser; - -@header { -package org.polystat.j2eo.antlrParser; -} - -options { tokenVocab=JavaLexer; } - -compilationUnit - : packageDeclaration? importDeclaration* typeDeclaration* - | moduleDeclaration EOF - ; - -packageDeclaration - : annotation* PACKAGE qualifiedName ';' - ; - -importDeclaration - : IMPORT STATIC? qualifiedName ('.' '*')? ';' - ; - -typeDeclaration - : classOrInterfaceModifier* - (classDeclaration | enumDeclaration | interfaceDeclaration | annotationTypeDeclaration | recordDeclaration) - | ';' - ; - -modifier - : classOrInterfaceModifier - | NATIVE - | SYNCHRONIZED - | TRANSIENT - | VOLATILE - ; - -classOrInterfaceModifier - : annotation - | PUBLIC - | PROTECTED - | PRIVATE - | STATIC - | ABSTRACT - | FINAL // FINAL for class only -- does not apply to interfaces - | STRICTFP - | SEALED // Java17 - | NON_SEALED // Java17 - ; - -variableModifier - : FINAL - | annotation - ; - -classDeclaration - : CLASS identifier typeParameters? - (EXTENDS typeType)? - (IMPLEMENTS typeList)? - (PERMITS typeList)? // Java17 - classBody - ; - -typeParameters - : '<' typeParameter (',' typeParameter)* '>' - ; - -typeParameter - : annotation* identifier (EXTENDS annotation* typeBound)? - ; - -typeBound - : typeType ('&' typeType)* - ; - -enumDeclaration - : ENUM identifier (IMPLEMENTS typeList)? '{' enumConstants? ','? enumBodyDeclarations? '}' - ; - -enumConstants - : enumConstant (',' enumConstant)* - ; - -enumConstant - : annotation* identifier arguments? classBody? - ; - -enumBodyDeclarations - : ';' classBodyDeclaration* - ; - -interfaceDeclaration - : INTERFACE identifier typeParameters? (EXTENDS typeList)? (PERMITS typeList)? interfaceBody - ; - -classBody - : '{' classBodyDeclaration* '}' - ; - -interfaceBody - : '{' interfaceBodyDeclaration* '}' - ; - -classBodyDeclaration - : ';' - | STATIC? block - | modifier* memberDeclaration - ; - -memberDeclaration - : methodDeclaration - | genericMethodDeclaration - | fieldDeclaration - | constructorDeclaration - | genericConstructorDeclaration - | interfaceDeclaration - | annotationTypeDeclaration - | classDeclaration - | enumDeclaration - | recordDeclaration //Java17 - ; - -/* We use rule this even for void methods which cannot have [] after parameters. - This simplifies grammar and we can consider void to be a type, which - renders the [] matching as a context-sensitive issue or a semantic check - for invalid return type after parsing. - */ -methodDeclaration - : typeTypeOrVoid identifier formalParameters ('[' ']')* - (THROWS qualifiedNameList)? - methodBody - ; - -methodBody - : block - | ';' - ; - -typeTypeOrVoid - : typeType - | VOID - ; - -genericMethodDeclaration - : typeParameters methodDeclaration - ; - -genericConstructorDeclaration - : typeParameters constructorDeclaration - ; - -constructorDeclaration - : identifier formalParameters (THROWS qualifiedNameList)? constructorBody=block - ; - -fieldDeclaration - : typeType variableDeclarators ';' - ; - -interfaceBodyDeclaration - : modifier* interfaceMemberDeclaration - | ';' - ; - -interfaceMemberDeclaration - : constDeclaration - | interfaceMethodDeclaration - | genericInterfaceMethodDeclaration - | interfaceDeclaration - | annotationTypeDeclaration - | classDeclaration - | enumDeclaration - | recordDeclaration // Java17 - ; - -constDeclaration - : typeType constantDeclarator (',' constantDeclarator)* ';' - ; - -constantDeclarator - : identifier ('[' ']')* '=' variableInitializer - ; - -// Early versions of Java allows brackets after the method name, eg. -// public int[] return2DArray() [] { ... } -// is the same as -// public int[][] return2DArray() { ... } -interfaceMethodDeclaration - : interfaceMethodModifier* interfaceCommonBodyDeclaration - ; - -// Java8 -interfaceMethodModifier - : annotation - | PUBLIC - | ABSTRACT - | DEFAULT - | STATIC - | STRICTFP - ; - -genericInterfaceMethodDeclaration - : interfaceMethodModifier* typeParameters interfaceCommonBodyDeclaration - ; - -interfaceCommonBodyDeclaration - : annotation* typeTypeOrVoid identifier formalParameters ('[' ']')* (THROWS qualifiedNameList)? methodBody - ; - -variableDeclarators - : variableDeclarator (',' variableDeclarator)* - ; - -variableDeclarator - : variableDeclaratorId ('=' variableInitializer)? - ; - -variableDeclaratorId - : identifier ('[' ']')* - ; - -variableInitializer - : arrayInitializer - | expression - ; - -arrayInitializer - : '{' (variableInitializer (',' variableInitializer)* (',')? )? '}' - ; - -classOrInterfaceType - : identifier typeArguments? ('.' identifier typeArguments?)* - ; - -typeArgument - : typeType - | annotation* '?' ((EXTENDS | SUPER) typeType)? - ; - -qualifiedNameList - : qualifiedName (',' qualifiedName)* - ; - -formalParameters - : '(' ( receiverParameter? - | receiverParameter (',' formalParameterList)? - | formalParameterList? - ) ')' - ; - -receiverParameter - : typeType (identifier '.')* THIS - ; - -formalParameterList - : formalParameter (',' formalParameter)* (',' lastFormalParameter)? - | lastFormalParameter - ; - -formalParameter - : variableModifier* typeType variableDeclaratorId - ; - -lastFormalParameter - : variableModifier* typeType annotation* '...' variableDeclaratorId - ; - -// local variable type inference -lambdaLVTIList - : lambdaLVTIParameter (',' lambdaLVTIParameter)* - ; - -lambdaLVTIParameter - : variableModifier* VAR identifier - ; - -qualifiedName - : identifier ('.' identifier)* - ; - -literal - : integerLiteral - | floatLiteral - | CHAR_LITERAL - | STRING_LITERAL - | BOOL_LITERAL - | NULL_LITERAL - | TEXT_BLOCK // Java17 - ; - -integerLiteral - : DECIMAL_LITERAL - | HEX_LITERAL - | OCT_LITERAL - | BINARY_LITERAL - ; - -floatLiteral - : FLOAT_LITERAL - | HEX_FLOAT_LITERAL - ; - -// ANNOTATIONS -altAnnotationQualifiedName - : (identifier DOT)* '@' identifier - ; - -annotation - : ('@' qualifiedName | altAnnotationQualifiedName) ('(' ( elementValuePairs | elementValue )? ')')? - ; - -elementValuePairs - : elementValuePair (',' elementValuePair)* - ; - -elementValuePair - : identifier '=' elementValue - ; - -elementValue - : expression - | annotation - | elementValueArrayInitializer - ; - -elementValueArrayInitializer - : '{' (elementValue (',' elementValue)*)? (',')? '}' - ; - -annotationTypeDeclaration - : '@' INTERFACE identifier annotationTypeBody - ; - -annotationTypeBody - : '{' (annotationTypeElementDeclaration)* '}' - ; - -annotationTypeElementDeclaration - : modifier* annotationTypeElementRest - | ';' // this is not allowed by the grammar, but apparently allowed by the actual compiler - ; - -annotationTypeElementRest - : typeType annotationMethodOrConstantRest ';' - | classDeclaration ';'? - | interfaceDeclaration ';'? - | enumDeclaration ';'? - | annotationTypeDeclaration ';'? - | recordDeclaration ';'? // Java17 - ; - -annotationMethodOrConstantRest - : annotationMethodRest - | annotationConstantRest - ; - -annotationMethodRest - : identifier '(' ')' defaultValue? - ; - -annotationConstantRest - : variableDeclarators - ; - -defaultValue - : DEFAULT elementValue - ; - -// MODULES - Java9 - -moduleDeclaration - : OPEN? MODULE qualifiedName moduleBody - ; - -moduleBody - : '{' moduleDirective* '}' - ; - -moduleDirective - : REQUIRES requiresModifier* qualifiedName ';' - | EXPORTS qualifiedName (TO qualifiedName)? ';' - | OPENS qualifiedName (TO qualifiedName)? ';' - | USES qualifiedName ';' - | PROVIDES qualifiedName WITH qualifiedName ';' - ; - -requiresModifier - : TRANSITIVE - | STATIC - ; - -// RECORDS - Java 17 - -recordDeclaration - : RECORD identifier typeParameters? recordHeader - (IMPLEMENTS typeList)? - recordBody - ; - -recordHeader - : '(' recordComponentList? ')' - ; - -recordComponentList - : recordComponent (',' recordComponent)* - ; - -recordComponent - : typeType identifier - ; - -recordBody - : '{' classBodyDeclaration* '}' - ; - -// STATEMENTS / BLOCKS - -block - : '{' blockStatement* '}' - ; - -blockStatement - : localVariableDeclaration ';' - | statement - | localTypeDeclaration - ; - -localVariableDeclaration - : variableModifier* (typeType variableDeclarators | VAR identifier '=' expression) - ; - -identifier - : IDENTIFIER - | MODULE - | OPEN - | REQUIRES - | EXPORTS - | OPENS - | TO - | USES - | PROVIDES - | WITH - | TRANSITIVE - | YIELD - | SEALED - | PERMITS - | RECORD - | VAR - ; - -localTypeDeclaration - : classOrInterfaceModifier* - (classDeclaration | enumDeclaration | interfaceDeclaration | recordDeclaration) - | ';' - ; - -statement - : blockLabel=block # statementBlockLabel - | ASSERT expression (':' expression)? ';' # statementAssert - | IF parExpression statement (ELSE statement)? # statementIf - | FOR '(' forControl ')' statement # statementFor - | WHILE parExpression statement # statementWhile - | DO statement WHILE parExpression ';' # statementDo - | TRY block (catchClause+ finallyBlock? | finallyBlock) # statementTryBlock - | TRY resourceSpecification block catchClause* finallyBlock? # statementTryResourceSpecification - | SWITCH parExpression '{' switchBlockStatementGroup* switchLabel* '}' # statementSwitch - | SYNCHRONIZED parExpression block # statementSynchronized - | RETURN expression? ';' # statementReturn - | THROW expression ';' # statementThrow - | BREAK identifier? ';' # statementBreak - | CONTINUE identifier? ';' # statementContinue - | YIELD expression ';' /* Java17 */ # statementYield - | SEMI # statementSemi - | statementExpression=expression ';' # statementExpression - | switchExpression ';'? /* Java17 */ # statementSwitchExpression - | identifierLabel=identifier ':' statement # statementIdentifierLabel - ; - -catchClause - : CATCH '(' variableModifier* catchType identifier ')' block - ; - -catchType - : qualifiedName ('|' qualifiedName)* - ; - -finallyBlock - : FINALLY block - ; - -resourceSpecification - : '(' resources ';'? ')' - ; - -resources - : resource (';' resource)* - ; - -resource - : variableModifier* ( classOrInterfaceType variableDeclaratorId | VAR identifier ) '=' expression - | identifier - ; - -/** Matches cases then statements, both of which are mandatory. - * To handle empty cases at the end, we add switchLabel* to statement. - */ -switchBlockStatementGroup - : switchLabel+ blockStatement+ - ; - -switchLabel - : CASE (constantExpression=expression | enumConstantName=IDENTIFIER | typeType varName=identifier) ':' - | DEFAULT ':' - ; - -forControl - : enhancedForControl - | forInit? ';' expression? ';' forUpdate=expressionList? - ; - -forInit - : localVariableDeclaration - | expressionList - ; - -enhancedForControl - : variableModifier* (typeType | VAR) variableDeclaratorId ':' expression - ; - -// EXPRESSIONS - -parExpression - : '(' expression ')' - ; - -expressionList - : expression (',' expression)* - ; - -methodCall - : identifier '(' expressionList? ')' - | THIS '(' expressionList? ')' - | SUPER '(' expressionList? ')' - ; - -expression - : primary # primaryExpresion - | expression bop='.' - ( - identifier - | methodCall - | THIS - | NEW nonWildcardTypeArguments? innerCreator - | SUPER superSuffix - | explicitGenericInvocation - ) # reference - | expression '[' expression ']' # arrayAccess - | methodCall # methodInvocation - | NEW creator # instanceCreation - | '(' annotation* typeType ('&' typeType)* ')' expression # castExpresion - | expression postfix=('++' | '--') # postfixExpression - | prefix=('+'|'-'|'++'|'--') expression # prefixExpression - | prefix=('~'|'!') expression # prefixExpression - | expression bop=('*'|'/'|'%') expression # binaryExpression - | expression bop=('+'|'-') expression # binaryExpression - | expression ('<' '<' | '>' '>' '>' | '>' '>') expression # binaryExpression - | expression bop=('<=' | '>=' | '>' | '<') expression # binaryExpression - | expression bop=INSTANCEOF (typeType | pattern) # instanceOfExpression - | expression bop=('==' | '!=') expression # binaryExpression - | expression bop='&' expression # binaryExpression - | expression bop='^' expression # binaryExpression - | expression bop='|' expression # binaryExpression - | expression bop='&&' expression # binaryExpression - | expression bop='||' expression # binaryExpression - | expression bop='?' expression ':' expression # ternaryExpression - | expression - bop=('=' | '+=' | '-=' | '*=' | '/=' | '&=' | '|=' | '^=' | '>>=' | '>>>=' | '<<=' | '%=') - expression # binaryExpression - | lambdaExpression # lambda // Java8 - | switchExpression # switch // Java17 - - // Java 8 methodReference - | expression '::' typeArguments? identifier # methodReference - | typeType '::' (typeArguments? identifier | NEW) # methodReference - | classType '::' typeArguments? NEW # methodReference - ; - -// Java17 -pattern - : variableModifier* typeType annotation* identifier - ; - -// Java8 -lambdaExpression - : lambdaParameters '->' lambdaBody - ; - -// Java8 -lambdaParameters - : identifier - | '(' formalParameterList? ')' - | '(' identifier (',' identifier)* ')' - | '(' lambdaLVTIList? ')' - ; - -// Java8 -lambdaBody - : expression - | block - ; - -primary - : '(' expression ')' # parenthesizedExpression - | THIS # thisExpresion - | SUPER # superExpression - | literal # literalExpression - | identifier # identifierExpresion - | typeTypeOrVoid '.' CLASS # classExpression - | nonWildcardTypeArguments (explicitGenericInvocationSuffix | THIS arguments) # nonWildcardTypeArgumentsExpression - ; - -// Java17 -switchExpression - : SWITCH parExpression '{' switchLabeledRule* '}' - ; - -// Java17 -switchLabeledRule - : CASE (expressionList | NULL_LITERAL | guardedPattern) (ARROW | COLON) switchRuleOutcome - | DEFAULT (ARROW | COLON) switchRuleOutcome - ; - -// Java17 -guardedPattern - : '(' guardedPattern ')' - | variableModifier* typeType annotation* identifier ('&&' expression)* - | guardedPattern '&&' expression - ; - -// Java17 -switchRuleOutcome - : block - | blockStatement* - ; - -classType - : (classOrInterfaceType '.')? annotation* identifier typeArguments? - ; - -creator - : nonWildcardTypeArguments createdName classCreatorRest - | createdName (arrayCreatorRest | classCreatorRest) - ; - -createdName - : identifier typeArgumentsOrDiamond? ('.' identifier typeArgumentsOrDiamond?)* - | primitiveType - ; - -innerCreator - : identifier nonWildcardTypeArgumentsOrDiamond? classCreatorRest - ; - -arrayCreatorRest - : '[' (']' ('[' ']')* arrayInitializer | expression ']' ('[' expression ']')* ('[' ']')*) - ; - -classCreatorRest - : arguments classBody? - ; - -explicitGenericInvocation - : nonWildcardTypeArguments explicitGenericInvocationSuffix - ; - -typeArgumentsOrDiamond - : '<' '>' - | typeArguments - ; - -nonWildcardTypeArgumentsOrDiamond - : '<' '>' - | nonWildcardTypeArguments - ; - -nonWildcardTypeArguments - : '<' typeList '>' - ; - -typeList - : typeType (',' typeType)* - ; - -typeType - : annotation* classOrInterfaceType (annotation* '[' ']')* # typeClassOrInterfaceType - | annotation* primitiveType (annotation* '[' ']')* # typePrimitiveType - ; - -primitiveType - : BOOLEAN - | CHAR - | BYTE - | SHORT - | INT - | LONG - | FLOAT - | DOUBLE - ; - -typeArguments - : '<' typeArgument (',' typeArgument)* '>' - ; - -superSuffix - : arguments - | '.' typeArguments? identifier arguments? - ; - -explicitGenericInvocationSuffix - : SUPER superSuffix - | identifier arguments - ; - -arguments - : '(' expressionList? ')' - ; diff --git a/grammar/README.md b/grammar/README.md deleted file mode 100644 index 78eaff5d..00000000 --- a/grammar/README.md +++ /dev/null @@ -1,16 +0,0 @@ -# J2EO Java Parser Grammar - -This directory contains the modified version of [ANTLR community Java parser](https://github.com/antlr/grammars-v4/tree/master/java/java). - -It supports Java 17. - -## What was changed - -- @header blocks were added in accordance with J2EO source code structure. -- Scopes were named where needed for the project. - -## What is needed to migrate J2EO to the new Java version? - -The answer depends on the features introduced in newer versions. Generally, updating lexer and parser is required. Also, `TreeMappings.kt` should be updated to include introduced parser changes. If newer features should be translated to EO, translator should be updated as well (no certain information here). - -This surely requires a code modification by a person familliar with ANTLR and Kotlin, as well as understanding of Java and EO. diff --git a/pom.xml b/pom.xml index f1e96de2..b8de71ae 100644 --- a/pom.xml +++ b/pom.xml @@ -57,25 +57,23 @@ SOFTWARE. ${project.basedir}/src/test/kotlin - + org.apache.maven.plugins maven-enforcer-plugin @@ -162,23 +160,6 @@ SOFTWARE. jacoco-maven-plugin ${jacoco.version} - - org.antlr - antlr4-maven-plugin - ${antlr.version} - - true - true - - - - antlr - - antlr4 - - - - org.apache.maven.plugins maven-pmd-plugin @@ -187,6 +168,24 @@ SOFTWARE. + + org.antlr + antlr4-maven-plugin + ${antlr.version} + + true + true + + + + + antlr + + antlr4 + + + + org.jacoco jacoco-maven-plugin @@ -368,6 +367,13 @@ SOFTWARE. + + + org.antlr + antlr4-runtime + ${antlr.version} + + org.polystat j2ast @@ -417,7 +423,4 @@ SOFTWARE. test - diff --git a/settings.gradle.kts b/settings.gradle.kts deleted file mode 100644 index e4115723..00000000 --- a/settings.gradle.kts +++ /dev/null @@ -1 +0,0 @@ -rootProject.name = "J2EO" diff --git a/src/main/antlr4/imports/JavaLexer.g4 b/src/main/antlr4/JavaLexer.g4 similarity index 99% rename from src/main/antlr4/imports/JavaLexer.g4 rename to src/main/antlr4/JavaLexer.g4 index 34e0eacd..ada1b383 100644 --- a/src/main/antlr4/imports/JavaLexer.g4 +++ b/src/main/antlr4/JavaLexer.g4 @@ -32,7 +32,7 @@ lexer grammar JavaLexer; @header { -package org.polystat.j2eo.antlrParser; +package src.main.antlr4.imports; } // Keywords diff --git a/src/main/antlr4/imports/JavaParser.g4 b/src/main/antlr4/JavaParser.g4 similarity index 99% rename from src/main/antlr4/imports/JavaParser.g4 rename to src/main/antlr4/JavaParser.g4 index 729d47ad..9c763803 100644 --- a/src/main/antlr4/imports/JavaParser.g4 +++ b/src/main/antlr4/JavaParser.g4 @@ -32,7 +32,7 @@ parser grammar JavaParser; @header { -package org.polystat.j2eo; +package src.main.antlr4.imports; } options { tokenVocab=JavaLexer; } diff --git a/src/main/java/org/polystat/j2eo/antlrParser/README.md b/src/main/java/org/polystat/j2eo/antlrParser/README.md deleted file mode 100644 index 7c9af190..00000000 --- a/src/main/java/org/polystat/j2eo/antlrParser/README.md +++ /dev/null @@ -1 +0,0 @@ -#### This folder would contain autogenerated ANTLR parser diff --git a/src/main/kotlin/org/polystat/j2eo/treeMapper/Visitor.kt b/src/main/kotlin/org/polystat/j2eo/treeMapper/Visitor.kt index 73baac63..e2f2e6ee 100644 --- a/src/main/kotlin/org/polystat/j2eo/treeMapper/Visitor.kt +++ b/src/main/kotlin/org/polystat/j2eo/treeMapper/Visitor.kt @@ -1,12 +1,15 @@ package org.polystat.j2eo.treeMapper -import org.polystat.j2eo.antlrParser.JavaParser -import org.polystat.j2eo.antlrParser.JavaParser.CompilationUnitContext -import org.polystat.j2eo.antlrParser.JavaParserBaseVisitor +// import org.polystat.j2eo.antlrParser.JavaParser.CompilationUnitContext +// import org.polystat.j2eo.antlrParser.JavaParserBaseVisitor + import tree.Entity class Visitor : JavaParserBaseVisitor() { - override fun visitCompilationUnit(ctx: CompilationUnitContext?): Entity = ctx!!.toCompilationUnit() + // Why does this line work??? + // JavaParser parser = new JavaParser() + + override fun visitCompilationUnit(ctx: JavaParser.CompilationUnitContext?): Entity = ctx!!.toCompilationUnit() override fun visitPackageDeclaration(ctx: JavaParser.PackageDeclarationContext?): Entity = ctx!!.toPackage() From c078f5048c50962abbc1b8267bf93010b9e07aaa Mon Sep 17 00:00:00 2001 From: Aleksandr Mishin Date: Thu, 13 Oct 2022 18:24:22 +0300 Subject: [PATCH 05/25] changed generation format --- .gitignore | 2 +- pom.xml | 2 +- src/main/antlr4/JavaLexer.g4 | 2 +- src/main/antlr4/JavaParser.g4 | 2 +- src/main/kotlin/org/polystat/j2eo/treeMapper/Visitor.kt | 9 +++------ 5 files changed, 7 insertions(+), 10 deletions(-) diff --git a/.gitignore b/.gitignore index 371cfecc..3fad9095 100644 --- a/.gitignore +++ b/.gitignore @@ -25,4 +25,4 @@ target .project .settings/ ktlint - +src/**/autogenerated diff --git a/pom.xml b/pom.xml index b8de71ae..b9bef33c 100644 --- a/pom.xml +++ b/pom.xml @@ -175,7 +175,7 @@ SOFTWARE. true true - + ${project.basedir}/src/main/kotlin/org/polystat/j2eo/treeMapper/autogenerated diff --git a/src/main/antlr4/JavaLexer.g4 b/src/main/antlr4/JavaLexer.g4 index ada1b383..f25e4f24 100644 --- a/src/main/antlr4/JavaLexer.g4 +++ b/src/main/antlr4/JavaLexer.g4 @@ -32,7 +32,7 @@ lexer grammar JavaLexer; @header { -package src.main.antlr4.imports; +package org.polystat.j2eo.treeMapper.autogenerated; } // Keywords diff --git a/src/main/antlr4/JavaParser.g4 b/src/main/antlr4/JavaParser.g4 index 9c763803..f74d6885 100644 --- a/src/main/antlr4/JavaParser.g4 +++ b/src/main/antlr4/JavaParser.g4 @@ -32,7 +32,7 @@ parser grammar JavaParser; @header { -package src.main.antlr4.imports; +package org.polystat.j2eo.treeMapper.autogenerated; } options { tokenVocab=JavaLexer; } diff --git a/src/main/kotlin/org/polystat/j2eo/treeMapper/Visitor.kt b/src/main/kotlin/org/polystat/j2eo/treeMapper/Visitor.kt index e2f2e6ee..dadf41d0 100644 --- a/src/main/kotlin/org/polystat/j2eo/treeMapper/Visitor.kt +++ b/src/main/kotlin/org/polystat/j2eo/treeMapper/Visitor.kt @@ -1,14 +1,11 @@ package org.polystat.j2eo.treeMapper -// import org.polystat.j2eo.antlrParser.JavaParser.CompilationUnitContext -// import org.polystat.j2eo.antlrParser.JavaParserBaseVisitor - +import java.util.* +import org.polystat.j2eo.treeMapper.autogenerated.JavaParser +import org.polystat.j2eo.treeMapper.autogenerated.JavaParserBaseVisitor import tree.Entity class Visitor : JavaParserBaseVisitor() { - // Why does this line work??? - // JavaParser parser = new JavaParser() - override fun visitCompilationUnit(ctx: JavaParser.CompilationUnitContext?): Entity = ctx!!.toCompilationUnit() override fun visitPackageDeclaration(ctx: JavaParser.PackageDeclarationContext?): Entity = ctx!!.toPackage() From 580d0e6af74a2b7b0833c451f8b2874ecd905104 Mon Sep 17 00:00:00 2001 From: Aleksandr Mishin Date: Thu, 13 Oct 2022 19:48:05 +0300 Subject: [PATCH 06/25] TreeMappings.kt fixed --- pom.xml | 2 +- src/main/kotlin/org/polystat/j2eo/treeMapper/TreeMappings.kt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index b9bef33c..5ca4174a 100644 --- a/pom.xml +++ b/pom.xml @@ -173,7 +173,7 @@ SOFTWARE. antlr4-maven-plugin ${antlr.version} - true + true ${project.basedir}/src/main/kotlin/org/polystat/j2eo/treeMapper/autogenerated diff --git a/src/main/kotlin/org/polystat/j2eo/treeMapper/TreeMappings.kt b/src/main/kotlin/org/polystat/j2eo/treeMapper/TreeMappings.kt index ba9b1d1e..794f7e3c 100644 --- a/src/main/kotlin/org/polystat/j2eo/treeMapper/TreeMappings.kt +++ b/src/main/kotlin/org/polystat/j2eo/treeMapper/TreeMappings.kt @@ -4,7 +4,7 @@ package org.polystat.j2eo.treeMapper import lexer.Token import lexer.TokenCode import org.antlr.v4.runtime.tree.TerminalNode -import org.polystat.j2eo.antlrParser.JavaParser.* +import org.polystat.j2eo.treeMapper.autogenerated.JavaParser.* import tree.* import tree.Compilation.* import tree.Declaration.* From 4fd05ff9da325d5bb1bd9c4fcdd4e07c906f3a47 Mon Sep 17 00:00:00 2001 From: Aleksandr Mishin Date: Thu, 13 Oct 2022 20:06:20 +0300 Subject: [PATCH 07/25] added CI management with bot rultor --- pom.xml | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/pom.xml b/pom.xml index 5ca4174a..8cb10105 100644 --- a/pom.xml +++ b/pom.xml @@ -29,9 +29,6 @@ SOFTWARE. 1.0-SNAPSHOT pom j2eo - 4.11.1 1.8 @@ -68,7 +65,7 @@ SOFTWARE. - ${project.build.directory}/generated-sources/antlr4 + ${project.basedir}/src/main/kotlin/org/polystat/j2eo/treeMapper/autogenerated @@ -173,7 +170,7 @@ SOFTWARE. antlr4-maven-plugin ${antlr.version} - + true true ${project.basedir}/src/main/kotlin/org/polystat/j2eo/treeMapper/autogenerated @@ -227,7 +224,7 @@ SOFTWARE. ${project.basedir}/src/test/kotlin - ${project.basedir}/src/main/kotlin/generated + ${project.basedir}/src/main/kotlin/treeMapper/autogenerated diktat-analysis.yml @@ -267,10 +264,6 @@ SOFTWARE. - Java to EO Translator https://github.com/polystat/j2eo 2021 @@ -353,9 +346,10 @@ SOFTWARE. scm:git:git@github.com:polystat/j2eo.git https://github.com/polystat/j2eo - + + rultor + https://www.rultor.com/s/eo + github-pages @@ -367,13 +361,11 @@ SOFTWARE. - org.antlr antlr4-runtime ${antlr.version} - org.polystat j2ast @@ -398,7 +390,7 @@ SOFTWARE. org.slf4j slf4j-simple ${slf4j.vesion} - + test io.github.microutils From 6e11d66e27fbae697d8dd79223087e5aaa36e4cf Mon Sep 17 00:00:00 2001 From: Aleksandr Mishin Date: Sun, 23 Oct 2022 15:23:38 +0300 Subject: [PATCH 08/25] mvn-build: added visibility for classes generated in target/ dir --- pom.xml | 10 ++-------- src/main/antlr4/JavaLexer.g4 | 4 ---- src/main/antlr4/JavaParser.g4 | 4 ---- .../kotlin/org/polystat/j2eo/treeMapper/Visitor.kt | 6 +++--- 4 files changed, 5 insertions(+), 19 deletions(-) diff --git a/pom.xml b/pom.xml index 8cb10105..14d1a77e 100644 --- a/pom.xml +++ b/pom.xml @@ -52,6 +52,7 @@ SOFTWARE. ${project.basedir}/src/main/ ${project.basedir}/src/test/kotlin + @@ -65,7 +66,7 @@ SOFTWARE. - ${project.basedir}/src/main/kotlin/org/polystat/j2eo/treeMapper/autogenerated + ${project.basedir}/target/generated-sources/antlr4 @@ -145,9 +146,6 @@ SOFTWARE. ${project.basedir}/src/test/kotlin diktat-analysis.yml - - ${project.basedir}/src/test/kotlin/excluded - @@ -172,7 +170,6 @@ SOFTWARE. true true - ${project.basedir}/src/main/kotlin/org/polystat/j2eo/treeMapper/autogenerated @@ -223,9 +220,6 @@ SOFTWARE. ${project.basedir}/src/main/kotlin ${project.basedir}/src/test/kotlin - - ${project.basedir}/src/main/kotlin/treeMapper/autogenerated - diktat-analysis.yml diff --git a/src/main/antlr4/JavaLexer.g4 b/src/main/antlr4/JavaLexer.g4 index f25e4f24..2cdc0e1a 100644 --- a/src/main/antlr4/JavaLexer.g4 +++ b/src/main/antlr4/JavaLexer.g4 @@ -31,10 +31,6 @@ lexer grammar JavaLexer; -@header { -package org.polystat.j2eo.treeMapper.autogenerated; -} - // Keywords ABSTRACT: 'abstract'; diff --git a/src/main/antlr4/JavaParser.g4 b/src/main/antlr4/JavaParser.g4 index f74d6885..c8cc11ce 100644 --- a/src/main/antlr4/JavaParser.g4 +++ b/src/main/antlr4/JavaParser.g4 @@ -31,10 +31,6 @@ parser grammar JavaParser; -@header { -package org.polystat.j2eo.treeMapper.autogenerated; -} - options { tokenVocab=JavaLexer; } compilationUnit diff --git a/src/main/kotlin/org/polystat/j2eo/treeMapper/Visitor.kt b/src/main/kotlin/org/polystat/j2eo/treeMapper/Visitor.kt index dadf41d0..54e6a3e8 100644 --- a/src/main/kotlin/org/polystat/j2eo/treeMapper/Visitor.kt +++ b/src/main/kotlin/org/polystat/j2eo/treeMapper/Visitor.kt @@ -1,11 +1,11 @@ package org.polystat.j2eo.treeMapper import java.util.* -import org.polystat.j2eo.treeMapper.autogenerated.JavaParser -import org.polystat.j2eo.treeMapper.autogenerated.JavaParserBaseVisitor +import JavaParser +import JavaParserBaseVisitor import tree.Entity -class Visitor : JavaParserBaseVisitor() { +class Visitor : JavaParserBaseVisitor { override fun visitCompilationUnit(ctx: JavaParser.CompilationUnitContext?): Entity = ctx!!.toCompilationUnit() override fun visitPackageDeclaration(ctx: JavaParser.PackageDeclarationContext?): Entity = ctx!!.toPackage() From ae81e8dac6643e37f8b86163c7e21516052270a4 Mon Sep 17 00:00:00 2001 From: Aleksandr Mishin Date: Sun, 23 Oct 2022 15:31:40 +0300 Subject: [PATCH 09/25] slight modification of main and TreeMappings --- src/main/kotlin/org/polystat/j2eo/main/Main2.kt | 4 ++-- src/main/kotlin/org/polystat/j2eo/treeMapper/TreeMappings.kt | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/kotlin/org/polystat/j2eo/main/Main2.kt b/src/main/kotlin/org/polystat/j2eo/main/Main2.kt index 15f5ca85..8a0ab02a 100644 --- a/src/main/kotlin/org/polystat/j2eo/main/Main2.kt +++ b/src/main/kotlin/org/polystat/j2eo/main/Main2.kt @@ -4,8 +4,8 @@ import arrow.core.Some import org.antlr.v4.runtime.CharStreams import org.antlr.v4.runtime.CommonTokenStream import org.apache.commons.cli.* // ktlint-disable no-wildcard-imports -import org.polystat.j2eo.antlrParser.JavaLexer -import org.polystat.j2eo.antlrParser.JavaParser +import JavaLexer +import JavaParser import org.polystat.j2eo.eotree.EOLicense import org.polystat.j2eo.eotree.EOMetas import org.polystat.j2eo.eotree.EOProgram diff --git a/src/main/kotlin/org/polystat/j2eo/treeMapper/TreeMappings.kt b/src/main/kotlin/org/polystat/j2eo/treeMapper/TreeMappings.kt index 794f7e3c..d8311df1 100644 --- a/src/main/kotlin/org/polystat/j2eo/treeMapper/TreeMappings.kt +++ b/src/main/kotlin/org/polystat/j2eo/treeMapper/TreeMappings.kt @@ -4,7 +4,7 @@ package org.polystat.j2eo.treeMapper import lexer.Token import lexer.TokenCode import org.antlr.v4.runtime.tree.TerminalNode -import org.polystat.j2eo.treeMapper.autogenerated.JavaParser.* +import JavaParser.* import tree.* import tree.Compilation.* import tree.Declaration.* From e54136e55910c47dcc9f45babb21d0e30681a1c4 Mon Sep 17 00:00:00 2001 From: Aleksandr Mishin Date: Sun, 23 Oct 2022 15:39:35 +0300 Subject: [PATCH 10/25] minor fix --- src/main/kotlin/org/polystat/j2eo/treeMapper/Visitor.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/kotlin/org/polystat/j2eo/treeMapper/Visitor.kt b/src/main/kotlin/org/polystat/j2eo/treeMapper/Visitor.kt index 54e6a3e8..370537d1 100644 --- a/src/main/kotlin/org/polystat/j2eo/treeMapper/Visitor.kt +++ b/src/main/kotlin/org/polystat/j2eo/treeMapper/Visitor.kt @@ -5,7 +5,7 @@ import JavaParser import JavaParserBaseVisitor import tree.Entity -class Visitor : JavaParserBaseVisitor { +class Visitor : JavaParserBaseVisitor() { override fun visitCompilationUnit(ctx: JavaParser.CompilationUnitContext?): Entity = ctx!!.toCompilationUnit() override fun visitPackageDeclaration(ctx: JavaParser.PackageDeclarationContext?): Entity = ctx!!.toPackage() From 3ff3611cc4e85e370b2e6e8ba4e4b53d039d497f Mon Sep 17 00:00:00 2001 From: Aleksandr Mishin Date: Sun, 23 Oct 2022 16:09:18 +0300 Subject: [PATCH 11/25] slight modification --- src/main/kotlin/org/polystat/j2eo/treeMapper/Visitor.kt | 3 ++- src/test/kotlin/common/TestJ2EORuntimeCheck.kt | 4 ++-- src/test/kotlin/common/TestJ2EOStaticCheck.kt | 4 ++-- src/test/kotlin/open_jdk/TestJ2EOonOpenJDK.kt | 5 +++-- 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/main/kotlin/org/polystat/j2eo/treeMapper/Visitor.kt b/src/main/kotlin/org/polystat/j2eo/treeMapper/Visitor.kt index 370537d1..0c6be9ce 100644 --- a/src/main/kotlin/org/polystat/j2eo/treeMapper/Visitor.kt +++ b/src/main/kotlin/org/polystat/j2eo/treeMapper/Visitor.kt @@ -2,11 +2,12 @@ package org.polystat.j2eo.treeMapper import java.util.* import JavaParser +import JavaParser.CompilationUnitContext import JavaParserBaseVisitor import tree.Entity class Visitor : JavaParserBaseVisitor() { - override fun visitCompilationUnit(ctx: JavaParser.CompilationUnitContext?): Entity = ctx!!.toCompilationUnit() + override fun visitCompilationUnit(ctx: CompilationUnitContext?): Entity = ctx!!.toCompilationUnit() override fun visitPackageDeclaration(ctx: JavaParser.PackageDeclarationContext?): Entity = ctx!!.toPackage() diff --git a/src/test/kotlin/common/TestJ2EORuntimeCheck.kt b/src/test/kotlin/common/TestJ2EORuntimeCheck.kt index 4b1e9946..7b7bba11 100644 --- a/src/test/kotlin/common/TestJ2EORuntimeCheck.kt +++ b/src/test/kotlin/common/TestJ2EORuntimeCheck.kt @@ -12,8 +12,8 @@ import org.junit.jupiter.api.TestMethodOrder import org.junit.jupiter.api.assertTimeoutPreemptively import org.junit.jupiter.api.parallel.Execution import org.junit.jupiter.api.parallel.ExecutionMode -import org.polystat.j2eo.antlrParser.JavaLexer -import org.polystat.j2eo.antlrParser.JavaParser +import JavaLexer +import JavaParser import org.polystat.j2eo.translator.Context import org.polystat.j2eo.translator.Translator import org.polystat.j2eo.treeMapper.Visitor diff --git a/src/test/kotlin/common/TestJ2EOStaticCheck.kt b/src/test/kotlin/common/TestJ2EOStaticCheck.kt index e8dee46d..2dbabaf8 100644 --- a/src/test/kotlin/common/TestJ2EOStaticCheck.kt +++ b/src/test/kotlin/common/TestJ2EOStaticCheck.kt @@ -11,8 +11,8 @@ import org.junit.jupiter.api.TestMethodOrder import org.junit.jupiter.api.assertTimeoutPreemptively import org.junit.jupiter.api.parallel.Execution import org.junit.jupiter.api.parallel.ExecutionMode -import org.polystat.j2eo.antlrParser.JavaLexer -import org.polystat.j2eo.antlrParser.JavaParser +import JavaLexer +import JavaParser import org.polystat.j2eo.translator.Context import org.polystat.j2eo.translator.Translator import org.polystat.j2eo.treeMapper.Visitor diff --git a/src/test/kotlin/open_jdk/TestJ2EOonOpenJDK.kt b/src/test/kotlin/open_jdk/TestJ2EOonOpenJDK.kt index 025109de..1a914727 100644 --- a/src/test/kotlin/open_jdk/TestJ2EOonOpenJDK.kt +++ b/src/test/kotlin/open_jdk/TestJ2EOonOpenJDK.kt @@ -13,8 +13,9 @@ import org.junit.jupiter.api.TestMethodOrder import org.junit.jupiter.api.assertTimeoutPreemptively import org.junit.jupiter.api.parallel.Execution import org.junit.jupiter.api.parallel.ExecutionMode -import org.polystat.j2eo.antlrParser.JavaLexer -import org.polystat.j2eo.antlrParser.JavaParser +import JavaLexer +import JavaParser +import JavaParserBaseVisitor import org.polystat.j2eo.translator.Context import org.polystat.j2eo.translator.Translator import org.polystat.j2eo.treeMapper.Visitor From 90b2eae55fc4f1df07c05d93c62658e384ad506c Mon Sep 17 00:00:00 2001 From: Aleksandr Mishin Date: Thu, 3 Nov 2022 15:06:13 +0300 Subject: [PATCH 12/25] mvn-build: added running of tests --- pom.xml | 115 +++++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 85 insertions(+), 30 deletions(-) diff --git a/pom.xml b/pom.xml index 14d1a77e..30a07bd0 100644 --- a/pom.xml +++ b/pom.xml @@ -27,7 +27,7 @@ SOFTWARE. org.polystat j2eo-parent 1.0-SNAPSHOT - pom + jar j2eo 4.11.1 @@ -40,19 +40,18 @@ SOFTWARE. 0.2.0 0.8.8 [11,) - 5.8.2 - 5.8.2 - 1.9.1 + 5.8.1 + 5.8.1 + 1.8.2 1.7.20 3.0.0 3.8.1 3.13.0 - 1.7.33 + 2.0.1 ${project.basedir}/src/main/ ${project.basedir}/src/test/kotlin - @@ -72,6 +71,11 @@ SOFTWARE. + + org.apache.maven.plugins + maven-surefire-plugin + 3.0.0-M7 + org.apache.maven.plugins maven-enforcer-plugin @@ -96,6 +100,8 @@ SOFTWARE. maven-compiler-plugin ${mvn.version} + 1.8 + 1.8 @@ -203,28 +209,6 @@ SOFTWARE. - - org.cqfn.diktat - diktat-maven-plugin - ${diktat.version} - - - diktat - none - - check - fix - - - - ${project.basedir}/src/main/kotlin - ${project.basedir}/src/test/kotlin - - diktat-analysis.yml - - - - org.jetbrains.kotlin kotlin-maven-plugin @@ -237,7 +221,7 @@ SOFTWARE. - test-compile + kotlin-test-compile test-compile @@ -253,7 +237,7 @@ SOFTWARE. maven-checkstyle-plugin ${checkstyle.version} - checkstyle.xml + ${project.basedir}/config/checkstyle/checkstyle.xml @@ -355,6 +339,12 @@ SOFTWARE. + + com.h2database + h2 + runtime + 2.1.214 + org.antlr antlr4-runtime @@ -368,7 +358,12 @@ SOFTWARE. org.jetbrains.kotlin kotlin-stdlib + + + org.jetbrains.kotlin + kotlin-test ${kotlin.version} + test commons-cli @@ -395,6 +390,7 @@ SOFTWARE. org.junit.platform junit-platform-commons ${junit-platform.version} + test org.junit.jupiter @@ -408,5 +404,64 @@ SOFTWARE. ${junit-jupiter-engine.version} test + + org.jetbrains.kotlin + kotlin-test-junit + ${kotlin.version} + test + + + org.assertj + assertj-core + 3.12.2 + test + + + org.springframework.boot + spring-boot-starter-web + 2.7.3 + + + org.springframework.boot + spring-boot-starter-data-jpa + 2.7.3 + + + org.springframework.boot + spring-boot-starter-test + 2.7.3 + test + + + org.mockito + mockito-core + + + + + com.ninja-squad + springmockk + 3.0.1 + test + + + + + org.jetbrains.kotlin + kotlin-stdlib-common + ${kotlin.version} + + + org.jetbrains.kotlin + kotlin-stdlib + ${kotlin.version} + + + org.jetbrains.kotlin + kotlin-stdlib-jdk8 + 1.5.30 + + + From 9c1de1f707d2bb7b5ab6e8953f421034f9f4cf54 Mon Sep 17 00:00:00 2001 From: Aleksandr Mishin Date: Thu, 3 Nov 2022 17:22:38 +0300 Subject: [PATCH 13/25] #mvn-build: modified testing --- pom.xml | 15 +++++++++------ test-hadoop.sh | 25 ------------------------- test-kafka.sh | 26 -------------------------- test_candidates.sh | 3 --- test_ready.sh | 3 --- 5 files changed, 9 insertions(+), 63 deletions(-) delete mode 100755 test-hadoop.sh delete mode 100755 test-kafka.sh delete mode 100755 test_candidates.sh delete mode 100644 test_ready.sh diff --git a/pom.xml b/pom.xml index 30a07bd0..5b6b4a9d 100644 --- a/pom.xml +++ b/pom.xml @@ -33,6 +33,7 @@ SOFTWARE. 4.11.1 1.8 1.0.0 + 3.12.2 3.0.0 1.5.0 1.2.2 @@ -46,8 +47,10 @@ SOFTWARE. 1.7.20 3.0.0 3.8.1 + 3.0.1 3.13.0 2.0.1 + 2.7.3 ${project.basedir}/src/main/ @@ -413,23 +416,23 @@ SOFTWARE. org.assertj assertj-core - 3.12.2 + ${assertj-core.version} test - + org.springframework.boot spring-boot-starter-web - 2.7.3 + ${spring-framework.version} org.springframework.boot spring-boot-starter-data-jpa - 2.7.3 + ${spring-framework.version} org.springframework.boot spring-boot-starter-test - 2.7.3 + ${spring-framework.version} test @@ -441,7 +444,7 @@ SOFTWARE. com.ninja-squad springmockk - 3.0.1 + ${ninja-squad.version} test diff --git a/test-hadoop.sh b/test-hadoop.sh deleted file mode 100755 index 0aaf6572..00000000 --- a/test-hadoop.sh +++ /dev/null @@ -1,25 +0,0 @@ -#!/usr/bin/env bash - -# Exit on error -set -e - -echo "Building J2EO..." -gradle build -x test jar -cp build/libs/J2EO-0.6.0.jar . - -if [ ! -e "./j2eo-data/hadoop-3.2.3-src" ]; then - echo "Downloading Hadoop..." - # get hadoop from https://www.apache.org/dyn/closer.cgi/hadoop/common/hadoop-3.2.3/hadoop-3.2.3-src.tar.gz - mkdir -p j2eo-data - wget -O j2eo-data/hadoop.tar.gz https://dlcdn.apache.org/hadoop/common/hadoop-3.2.3/hadoop-3.2.3-src.tar.gz - # unpack - tar -xf j2eo-data/hadoop.tar.gz -C j2eo-data -else - echo "Hadoop is already downloaded, skipping download..." -fi - -echo "Starting J2EO on Hadoop..." -# clean old output -rm -rf j2eo-data/hadoop-eo - -java -jar J2EO-0.6.0.jar -o j2eo-data/hadoop-eo j2eo-data/hadoop-3.2.3-src diff --git a/test-kafka.sh b/test-kafka.sh deleted file mode 100755 index e32d594d..00000000 --- a/test-kafka.sh +++ /dev/null @@ -1,26 +0,0 @@ -#!/usr/bin/env bash - -# Exit on error -set -e - -echo "Building J2EO..." -gradle build -x test jar -cp build/libs/J2EO-0.6.0.jar . - -if [ ! -e "./j2eo-data/kafka" ]; then - echo "Downloading Kafka..." - mkdir -p j2eo-data - cd j2eo-data - git clone https://github.com/apache/kafka - cd kafka - git checkout f36de0744b915335de6b636e6bd6b5f1276f34f6 - cd ../.. -else - echo "Kafka is already downloaded, skipping download..." -fi - -echo "Starting J2EO on Kafka..." -# clean old output -rm -rf j2eo-data/kafka-eo - -java -jar J2EO-0.6.0.jar -o j2eo-data/kafka-eo j2eo-data/kafka diff --git a/test_candidates.sh b/test_candidates.sh deleted file mode 100755 index e4e19da9..00000000 --- a/test_candidates.sh +++ /dev/null @@ -1,3 +0,0 @@ -#/bin/sh - -gradle test -Dcandidates=true diff --git a/test_ready.sh b/test_ready.sh deleted file mode 100644 index a7343ca9..00000000 --- a/test_ready.sh +++ /dev/null @@ -1,3 +0,0 @@ -#/bin/sh - -./gradlew test -Pcandidates=false From 7b2e6f6c1817e7f629d53646830eb43b3b427399 Mon Sep 17 00:00:00 2001 From: Aleksandr Mishin Date: Tue, 8 Nov 2022 15:43:06 +0300 Subject: [PATCH 14/25] rultor change --- .rultor.yml | 34 +++++++++++++++++++++++----------- pom.xml | 1 + 2 files changed, 24 insertions(+), 11 deletions(-) diff --git a/.rultor.yml b/.rultor.yml index 514d7b89..97fef845 100644 --- a/.rultor.yml +++ b/.rultor.yml @@ -1,6 +1,5 @@ docker: - image: "iammaxim/j2eo:latest" - as_root: true + image: "yegor256/rultor-image:1.9.1" architect: - yegor256 assets: @@ -9,17 +8,30 @@ assets: secring.gpg: yegor256/polystat-secrets#secring.gpg docker-password: yegor256/polystat-secrets#docker-password install: | - cp ../gradle.properties . - wget https://www.antlr.org/download/antlr-4.9.2-complete.jar + pdd --file=/dev/null merge: script: | - gradle build --info + mvn clean install --errors -Dstyle.color=never release: script: |- [[ "${tag}" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]] || exit -1 - gradle build fatJar publish -x test --info -Dcandidates=false -PmvnPublicationVersion=${tag} -Dsigning.secretKeyRingFile=/home/r/secring.gpg - mv "J2EO-${tag}.jar" j2eo.jar - image=yegor256/j2eo - sudo docker build "$(pwd)" --tag "${image}:${tag}" - cat ../docker-password | sudo docker login --password-stdin --username yegor256 - sudo docker push "${image}:${tag}" \ No newline at end of file + mvn versions:set "-DnewVersion=${tag}" -Dstyle.color=never + git commit -am "${tag}" + mvn clean install -Dinvoker.skip + mvn clean deploy -Ppolystat -Psonatype --errors --settings ../settings.xml -Dstyle.color=never + mkdir /tmp/polystat + cp -R src/main/eo /tmp/polystat/objects + cp -R src/test/eo /tmp/polystat/tests + branch=$(git rev-parse --abbrev-ref HEAD) + git checkout gh-pages + git reset --hard + sudo git config --global --add safe.directory "$(pwd)" + sudo /bin/bash -c "cd '$(pwd)'; git clean -fd" + rm -rf polystat + cp -R /tmp/polystat . + find polystat -name '*.eo' | xargs sed -i "s/0\.0\.0/${tag}/g" + git add polystat + find polystat -name '*.eo' > polystat.lst + git add polystat.lst + git commit -am "polystat ${tag}" + git checkout "${branch}" \ No newline at end of file diff --git a/pom.xml b/pom.xml index 5b6b4a9d..07b168dd 100644 --- a/pom.xml +++ b/pom.xml @@ -30,6 +30,7 @@ SOFTWARE. jar j2eo + UTF-8 4.11.1 1.8 1.0.0 From bba569f01a9fff36d323321f55a05ba56eb7454a Mon Sep 17 00:00:00 2001 From: Aleksandr Mishin Date: Thu, 10 Nov 2022 12:46:00 +0300 Subject: [PATCH 15/25] some checks removed --- .../kotlin/common/TestJ2EORuntimeCheck.kt | 259 ------------------ src/test/kotlin/common/TestJ2EOStaticCheck.kt | 121 -------- 2 files changed, 380 deletions(-) delete mode 100644 src/test/kotlin/common/TestJ2EORuntimeCheck.kt delete mode 100644 src/test/kotlin/common/TestJ2EOStaticCheck.kt diff --git a/src/test/kotlin/common/TestJ2EORuntimeCheck.kt b/src/test/kotlin/common/TestJ2EORuntimeCheck.kt deleted file mode 100644 index 7b7bba11..00000000 --- a/src/test/kotlin/common/TestJ2EORuntimeCheck.kt +++ /dev/null @@ -1,259 +0,0 @@ -package common - -import org.antlr.v4.runtime.CharStreams -import org.antlr.v4.runtime.CommonTokenStream -import org.junit.jupiter.api.AfterAll -import org.junit.jupiter.api.Assertions -import org.junit.jupiter.api.BeforeAll -import org.junit.jupiter.api.DynamicTest -import org.junit.jupiter.api.MethodOrderer -import org.junit.jupiter.api.TestFactory -import org.junit.jupiter.api.TestMethodOrder -import org.junit.jupiter.api.assertTimeoutPreemptively -import org.junit.jupiter.api.parallel.Execution -import org.junit.jupiter.api.parallel.ExecutionMode -import JavaLexer -import JavaParser -import org.polystat.j2eo.translator.Context -import org.polystat.j2eo.translator.Translator -import org.polystat.j2eo.treeMapper.Visitor -import org.polystat.j2eo.util.logger -import tree.Compilation.CompilationUnit -import java.io.BufferedReader -import java.io.File -import java.io.InputStreamReader -import java.nio.file.Files -import java.nio.file.Path -import java.nio.file.Paths -import java.time.Duration -import java.util.Locale -import java.util.concurrent.TimeUnit -import kotlin.collections.HashMap -import kotlin.io.path.absolutePathString -import kotlin.io.path.name -import kotlin.io.path.relativeTo - -@Execution(ExecutionMode.SAME_THREAD) -@TestMethodOrder(MethodOrderer.OrderAnnotation::class) -class TestJ2EORuntimeCheck { - @TestFactory - fun executeAndCheckEO(): Collection { - return translatedFiles - .map { file -> executeTranslatedTest(file.first.toPath(), file.second) } - .toList() - } - - companion object { - private var testFolderRoot = Paths.get("") - private var pomFilePath = Paths.get("") - private var stdlibFolderRoot = Paths.get("") - private val fileSep = File.separatorChar.toString() - private val lineSep = System.lineSeparator() // New line character - - private lateinit var traversedFiles: Sequence - private lateinit var translatedFiles: Sequence> - - @BeforeAll - @JvmStatic - fun setup() { - val candidatesProp = System.getProperty("candidates") - val testCandidates = candidatesProp == "true" - if (testCandidates) - logger.info("-- Executing candidate tests --") - var testFolderPath = listOf("src", "test", "resources").joinToString(fileSep) - testFolderPath += fileSep + if (testCandidates) "test_candidates" else "test_ready" - val stdlibFolderPath = listOf("src", "main", "eo", "org", "polystat", "stdlib").joinToString(fileSep) - val fileStd = File(stdlibFolderPath) - stdlibFolderRoot = fileStd.toPath().toAbsolutePath() - val fileTest = File(testFolderPath) - testFolderRoot = fileTest.toPath().toAbsolutePath() - - val pomPath = listOf("src", "test", "resources", "eo_execution_pom", "pom.xml").joinToString(fileSep) - pomFilePath = File(pomPath).toPath().toAbsolutePath() - - // Double check for test files (in case testing exited abruptly) - val targetFolder = File(testFolderRoot.toString() + fileSep + "target") - if (targetFolder.exists()) { - targetFolder.deleteRecursively() - } - testFolderRoot.toFile().walk() - .filter { file -> file.isFile } - .filter { file -> isEOFile(file.toPath()) }.forEach { it.delete() } - - checkTranslation() - compileEOFiles() - } - - @AfterAll - @JvmStatic - fun cleanup() { - File(testFolderRoot.toString() + fileSep + "target").deleteRecursively() - testFolderRoot.toFile().walk() - .filter { file -> file.isFile } - .filter { file -> isEOFile(file.toPath()) }.forEach { it.delete() } - } - - private fun checkTranslation() { - traversedFiles = testFolderRoot.toFile().walk() - .filter { file -> file.isFile } - .filter { file -> isReadyTest(file.toPath()) } - .filter { file -> isNotClassFile(file.toPath()) } - .filter { file -> isJavaFile(file.toPath()) } - - translatedFiles = traversedFiles - .map { file -> file to translateFile(file.toPath()) } - } - - private fun translateFile(path: Path): Boolean { - try { - assertTimeoutPreemptively( - Duration.ofSeconds(90) - ) { - val lexer = JavaLexer(CharStreams.fromFileName(path.absolutePathString())) - val parser = JavaParser(CommonTokenStream(lexer)) - val tree = parser.compilationUnit() - val eval = Visitor() - val cu = eval.visit(tree) as CompilationUnit - val genEOLangText = Translator(path.relativeTo(testFolderRoot)).translate(cu, Context(HashMap())) - val newFileName = path.fileName.name.removeSuffix(".java") + ".eo" - val newPath = File(path.parent.toString() + fileSep + newFileName).toPath() - Files.writeString(newPath, genEOLangText.generateEO(0)) - assert(true) - } - } catch (e: Exception) { - return false - } - return true - } - - private fun compileEOFiles() { - // Copy all necessary files - val pomClonePath = File(testFolderRoot.toString() + fileSep + "pom.xml").toPath() - Files.copy(pomFilePath, pomClonePath) - val stdClonePath = File(testFolderRoot.toString() + fileSep + "stdlib").toPath() - stdlibFolderRoot.toFile().copyRecursively(stdClonePath.toFile()) - - // Execute generated EO code - val isWindows = System.getProperty("os.name").lowercase(Locale.getDefault()) - .contains("windows") // Matters a lot - - // Compile EO file - val mvnCommands = if (isWindows) listOf("mvn.cmd", "clean", "compile") - else listOf("mvn", "clean", "compile") - val compileProcess = ProcessBuilder(mvnCommands) - .directory(testFolderRoot.toFile()) - .redirectErrorStream(true) - .start() - - // Receive compilation output (maybe useful) - val mvnStdInput = BufferedReader(InputStreamReader(compileProcess.inputStream)) - var m: String? - val mvnSb = StringBuilder() - while (mvnStdInput.readLine().also { m = it } != null) { - mvnSb.append(m).append(lineSep) - } - compileProcess.waitFor() - compileProcess.destroy() - logger.info(" -- EO compilation output --$lineSep$mvnSb") - - pomClonePath.toFile().delete() - stdClonePath.toFile().deleteRecursively() - } - - private fun executeTranslatedTest(path: Path, isTranslated: Boolean): DynamicTest { - return DynamicTest.dynamicTest( - path.parent.fileName.toString() + "/" + - path.fileName.toString() - ) { - if (!isTranslated) { - assert(false) - } - - assertTimeoutPreemptively(Duration.ofSeconds(15)) { - val isWindows = System.getProperty("os.name").lowercase(Locale.getDefault()) - .contains("windows") // Matters a lot - - // Execute Java - val execPbJava = ProcessBuilder( - "java", path.toAbsolutePath().toString() - ) - execPbJava.directory(testFolderRoot.toFile()) - execPbJava.redirectErrorStream(true) - val execProcessJava = execPbJava.start() - logger.info("-- Executing Java... --") - - // Receive output - val outputJava = StringBuilder() - val stdInputJava = BufferedReader(InputStreamReader(execProcessJava.inputStream)) - var s: String? - while (stdInputJava.readLine().also { s = it } != null) { - outputJava.append(s).append(lineSep) - } - execProcessJava.waitFor() - execProcessJava.destroy() - logger.info("-- Java execution output --$lineSep$outputJava") - - // Execute EO - val relPath = path.relativeTo(testFolderRoot) - val pkg = relPath.toList().dropLast(1).joinToString(".") - val execPb = ProcessBuilder( - "java", "-cp", - if (isWindows) - "\"target/classes;target/eo-runtime.jar\"" - else - "target/classes:target/eo-runtime.jar", - "org.eolang.Main", - "$pkg.main", - if (isWindows) - "%*" - else - "\"$@\"1" - ) - execPb.directory(testFolderRoot.toFile()) - execPb.redirectErrorStream(true) - val execProcess = execPb.start() - logger.info("-- Executing EO... --") - - // Receive EO execution output - val outputEO = StringBuilder() - val stdInputEO = BufferedReader(InputStreamReader(execProcess.inputStream)) - var sEO: String? - while (stdInputEO.readLine().also { sEO = it } != null) { - outputEO.append(sEO).append(lineSep) - } - if (execProcess.waitFor(5, TimeUnit.SECONDS)) { - logger.warn("-- EO process has finished. ---") - execProcess.destroy() - } else { - logger.warn("-- EO process is stuck!!! ---") - execProcess.destroyForcibly() - } - - logger.info("-- EO execution output --$lineSep$outputEO") - - Assertions.assertEquals(outputJava.toString(), outputEO.toString()) - } - } - } - - private fun isReadyTest(path: Path): Boolean { - return !path.endsWith("SampleTest.java") && !path.contains(Paths.get("target")) - } - - private fun isClassFile(path: Path): Boolean { - return path.toString().endsWith(".class") - } - - private fun isJavaFile(path: Path): Boolean { - return path.toString().endsWith(".java") - } - - private fun isNotClassFile(path: Path): Boolean { - return !isClassFile(path) - } - - private fun isEOFile(path: Path): Boolean { - return path.toString().endsWith(".eo") - } - } -} diff --git a/src/test/kotlin/common/TestJ2EOStaticCheck.kt b/src/test/kotlin/common/TestJ2EOStaticCheck.kt deleted file mode 100644 index 2dbabaf8..00000000 --- a/src/test/kotlin/common/TestJ2EOStaticCheck.kt +++ /dev/null @@ -1,121 +0,0 @@ -package common - -import org.antlr.v4.runtime.CharStreams -import org.antlr.v4.runtime.CommonTokenStream -import org.junit.jupiter.api.AfterAll -import org.junit.jupiter.api.BeforeAll -import org.junit.jupiter.api.DynamicTest -import org.junit.jupiter.api.MethodOrderer -import org.junit.jupiter.api.TestFactory -import org.junit.jupiter.api.TestMethodOrder -import org.junit.jupiter.api.assertTimeoutPreemptively -import org.junit.jupiter.api.parallel.Execution -import org.junit.jupiter.api.parallel.ExecutionMode -import JavaLexer -import JavaParser -import org.polystat.j2eo.translator.Context -import org.polystat.j2eo.translator.Translator -import org.polystat.j2eo.treeMapper.Visitor -import tree.Compilation.CompilationUnit -import java.io.File -import java.nio.file.Path -import java.nio.file.Paths -import java.time.Duration -import kotlin.io.path.absolutePathString -import kotlin.io.path.relativeTo - -@Execution(ExecutionMode.SAME_THREAD) -@TestMethodOrder(MethodOrderer.OrderAnnotation::class) -class TestJ2EOStaticCheck { - @TestFactory - fun test(): Collection { - val t = testFolderRoot.toFile().walk() - .filter { file -> file.isFile } - .filter { file -> isReadyTest(file.toPath()) } - .filter { file -> isNotClassFile(file.toPath()) } - .filter { file -> isJavaFile(file.toPath()) } - - return t.map { translateFile(it.toPath()) }.toList() - } - - companion object { - private const val translatedTestsFolderName = "translated_tests" - private const val testsFolderName = "test_candidates" - private val testFolderRoot = Paths.get("src", "test", "resources", testsFolderName) - .toAbsolutePath() - private val sep = File.separatorChar.toString() - - @BeforeAll - @JvmStatic - fun setup() { - testFolderRoot.toFile().walk() - .filter { file -> file.isFile } - .filter { file -> isReadyTest(file.toPath()) } - .filter { file -> isNotClassFile(file.toPath()) } - .filter { file -> isJavaFile(file.toPath()) } - .toList() - } - - private fun translateJavaFile(path: Path): String { - val lexer = JavaLexer(CharStreams.fromFileName(path.absolutePathString())) - val parser = JavaParser(CommonTokenStream(lexer)) - val tree = parser.compilationUnit() - val eval = Visitor() - val cu = eval.visit(tree) as CompilationUnit - val genEOLangText = Translator(path.relativeTo(testFolderRoot)).translate(cu, Context(HashMap())) - return genEOLangText.generateEO(0) - } - - private fun getEOSample(path: Path): String { - val eoPathStr = path.absolutePathString() - .replace(testsFolderName, translatedTestsFolderName) - .replace(".java", ".eo") - return CharStreams.fromFileName(eoPathStr).toString() - } - - private fun translateFile(path: Path): DynamicTest { - return DynamicTest.dynamicTest( - path.parent.fileName.toString() + sep + - path.fileName.toString() - ) { - assertTimeoutPreemptively( - Duration.ofSeconds(10) - ) { - var translatedJava = translateJavaFile(path) - var sampleJava = getEOSample(path) - - // Ignores comments in the beginning - translatedJava = translatedJava.substring(translatedJava.indexOf("+alias")) - sampleJava = sampleJava.substring(sampleJava.indexOf("+alias")) - - assert(translatedJava == sampleJava) - } - } - } - - @AfterAll - @JvmStatic - fun cleanup() { - } - - private fun isReadyTest(path: Path): Boolean { - return !path.endsWith("SampleTest.java") && !path.contains(Paths.get("target")) - } - - private fun isTest(path: Path): Boolean { - return !path.contains(Paths.get("target")) - } - - private fun isClassFile(path: Path): Boolean { - return path.toString().endsWith(".class") - } - - private fun isJavaFile(path: Path): Boolean { - return path.toString().endsWith(".java") - } - - private fun isNotClassFile(path: Path): Boolean { - return !isClassFile(path) - } - } -} From e3fc72aa88684a27b607edcce5cafc51d0ddd50e Mon Sep 17 00:00:00 2001 From: Aleksandr Mishin Date: Thu, 10 Nov 2022 19:41:13 +0300 Subject: [PATCH 16/25] excluded start-imports --- .../polystat/j2eo/treeMapper/TreeMappings.kt | 133 +++++++++++++++++- 1 file changed, 132 insertions(+), 1 deletion(-) diff --git a/src/main/kotlin/org/polystat/j2eo/treeMapper/TreeMappings.kt b/src/main/kotlin/org/polystat/j2eo/treeMapper/TreeMappings.kt index 986382a4..72ceab3a 100644 --- a/src/main/kotlin/org/polystat/j2eo/treeMapper/TreeMappings.kt +++ b/src/main/kotlin/org/polystat/j2eo/treeMapper/TreeMappings.kt @@ -4,7 +4,138 @@ package org.polystat.j2eo.treeMapper import lexer.Token import lexer.TokenCode import org.antlr.v4.runtime.tree.TerminalNode -import JavaParser.* +// import JavaParser.* +import JavaParser.CompilationUnitContext +import JavaParser.TypeDeclarationContext +import JavaParser.ClassDeclarationContext +import JavaParser.ClassBodyContext +import JavaParser.ImportDeclarationContext +import JavaParser.PackageDeclarationContext +import JavaParser.QualifiedNameContext +import JavaParser.TypeArgumentContext +import JavaParser.IdentifierContext +import JavaParser.ClassOrInterfaceTypeContext +import JavaParser.PrimitiveTypeContext +import JavaParser.TypeClassOrInterfaceTypeContext +import JavaParser.TypePrimitiveTypeContext +import JavaParser.TypeTypeContext +import JavaParser.TypeTypeOrVoidContext +import JavaParser.TypeArgumentsContext +import JavaParser.TypeListContext +import JavaParser.TypeParameterContext +import JavaParser.TypeParametersContext +import JavaParser.ArrayInitializerContext +import JavaParser.VariableInitializerContext +import JavaParser.VariableDeclaratorContext +import JavaParser.LocalTypeDeclarationContext +import JavaParser.LocalVariableDeclarationContext +import JavaParser.ClassBodyDeclarationContext +import JavaParser.MemberDeclarationContext +import JavaParser.ModifierContext +import JavaParser.BOOLEAN +import JavaParser.CHAR +import JavaParser.BYTE +import JavaParser.SHORT +import JavaParser.INT +import JavaParser.LONG +import JavaParser.DOUBLE +import JavaParser.FLOAT +import JavaParser.SwitchExpressionContext +import JavaParser.ReferenceContext +import JavaParser.PrimaryContext +import JavaParser.ExpressionContext +import JavaParser.CreatorContext +import JavaParser.VariableDeclaratorsContext +import JavaParser.LiteralContext +import JavaParser.SuperExpressionContext +import JavaParser.ThisExpresionContext +import JavaParser.IdentifierExpresionContext +import JavaParser.LiteralExpressionContext +import JavaParser.ParenthesizedExpressionContext +import JavaParser.MethodCallContext +import JavaParser.ArgumentsContext +import JavaParser.InnerCreatorContext +import JavaParser.PrimaryExpresionContext +import JavaParser.MethodInvocationContext +import JavaParser.InstanceCreationContext +import JavaParser.InstanceOfExpressionContext +import JavaParser.CastExpresionContext +import JavaParser.ArrayAccessContext +import JavaParser.PostfixExpressionContext +import JavaParser.PrefixExpressionContext +import JavaParser.GT +import JavaParser.LT +import JavaParser.BinaryExpressionContext +import JavaParser.URSHIFT_ASSIGN +import JavaParser.MOD_ASSIGN +import JavaParser.TILDE +import JavaParser.BANG +import JavaParser.VAR +import JavaParser.DEC +import JavaParser.INC +import JavaParser.QUESTION +import JavaParser.INSTANCEOF +import JavaParser.DOT +import JavaParser.RSHIFT_ASSIGN +import JavaParser.LSHIFT_ASSIGN +import JavaParser.XOR_ASSIGN +import JavaParser.MOD +import JavaParser.NOTEQUAL +import JavaParser.AND_ASSIGN +import JavaParser.LE +import JavaParser.GE +import JavaParser.CARET +import JavaParser.BITOR +import JavaParser.OR_ASSIGN +import JavaParser.BITAND +import JavaParser.AND +import JavaParser.OR +import JavaParser.EQUAL +import JavaParser.ASSIGN +import JavaParser.DIV_ASSIGN +import JavaParser.SUB_ASSIGN +import JavaParser.MUL_ASSIGN +import JavaParser.ADD_ASSIGN +import JavaParser.DIV +import JavaParser.SUB +import JavaParser.MUL +import JavaParser.ADD +import JavaParser.SwitchLabelContext +import JavaParser.SwitchBlockStatementGroupContext +import JavaParser.StatementTryBlockContext +import JavaParser.StatementTryResourceSpecificationContext +import JavaParser.StatementSwitchExpressionContext +import JavaParser.StatementSwitchContext +import JavaParser.StatementSemiContext +import JavaParser.StatementIdentifierLabelContext +import JavaParser.StatementReturnContext +import JavaParser.StatementDoContext +import JavaParser.StatementBlockLabelContext +import JavaParser.StatementForContext +import JavaParser.StatementContinueContext +import JavaParser.StatementBreakContext +import JavaParser.StatementAssertContext +import JavaParser.StatementExpressionContext +import JavaParser.StatementIfContext +import JavaParser.StatementWhileContext +import JavaParser.StatementContext +import JavaParser.ConstructorDeclarationContext +import JavaParser.FieldDeclarationContext +import JavaParser.PUBLIC +import JavaParser.PRIVATE +import JavaParser.STATIC +import JavaParser.PROTECTED +import JavaParser.ABSTRACT +import JavaParser.FINAL +import JavaParser.STRICTFP +import JavaParser.ClassOrInterfaceModifierContext +import JavaParser.MethodDeclarationContext +import JavaParser.MethodBodyContext +import JavaParser.FormalParametersContext +import JavaParser.FormalParameterListContext +import JavaParser.BlockContext +import JavaParser.FormalParameterContext +import JavaParser.BlockStatementContext import tree.* import tree.Compilation.* import tree.Declaration.* From 70036caa8e8b27754e3c73db936be3131f459dfe Mon Sep 17 00:00:00 2001 From: Aleksandr Mishin Date: Sat, 12 Nov 2022 15:51:10 +0300 Subject: [PATCH 17/25] #224: excluded wildcard imports --- .../polystat/j2eo/treeMapper/TreeMappings.kt | 309 +++++++++++------- 1 file changed, 184 insertions(+), 125 deletions(-) diff --git a/src/main/kotlin/org/polystat/j2eo/treeMapper/TreeMappings.kt b/src/main/kotlin/org/polystat/j2eo/treeMapper/TreeMappings.kt index 72ceab3a..23a452b7 100644 --- a/src/main/kotlin/org/polystat/j2eo/treeMapper/TreeMappings.kt +++ b/src/main/kotlin/org/polystat/j2eo/treeMapper/TreeMappings.kt @@ -1,149 +1,208 @@ package org.polystat.j2eo.treeMapper -/* ktlint-disable no-wildcard-imports */ -import lexer.Token -import lexer.TokenCode -import org.antlr.v4.runtime.tree.TerminalNode -// import JavaParser.* -import JavaParser.CompilationUnitContext -import JavaParser.TypeDeclarationContext -import JavaParser.ClassDeclarationContext -import JavaParser.ClassBodyContext -import JavaParser.ImportDeclarationContext -import JavaParser.PackageDeclarationContext -import JavaParser.QualifiedNameContext -import JavaParser.TypeArgumentContext -import JavaParser.IdentifierContext -import JavaParser.ClassOrInterfaceTypeContext -import JavaParser.PrimitiveTypeContext -import JavaParser.TypeClassOrInterfaceTypeContext -import JavaParser.TypePrimitiveTypeContext -import JavaParser.TypeTypeContext -import JavaParser.TypeTypeOrVoidContext -import JavaParser.TypeArgumentsContext -import JavaParser.TypeListContext -import JavaParser.TypeParameterContext -import JavaParser.TypeParametersContext +import JavaParser.ABSTRACT +import JavaParser.ADD +import JavaParser.ADD_ASSIGN +import JavaParser.AND +import JavaParser.AND_ASSIGN +import JavaParser.ASSIGN +import JavaParser.ArgumentsContext +import JavaParser.ArrayAccessContext import JavaParser.ArrayInitializerContext -import JavaParser.VariableInitializerContext -import JavaParser.VariableDeclaratorContext -import JavaParser.LocalTypeDeclarationContext -import JavaParser.LocalVariableDeclarationContext -import JavaParser.ClassBodyDeclarationContext -import JavaParser.MemberDeclarationContext -import JavaParser.ModifierContext +import JavaParser.BANG +import JavaParser.BITAND +import JavaParser.BITOR import JavaParser.BOOLEAN -import JavaParser.CHAR import JavaParser.BYTE -import JavaParser.SHORT -import JavaParser.INT -import JavaParser.LONG +import JavaParser.BinaryExpressionContext +import JavaParser.BlockContext +import JavaParser.BlockStatementContext +import JavaParser.CARET +import JavaParser.CHAR +import JavaParser.CastExpresionContext +import JavaParser.ClassBodyContext +import JavaParser.ClassBodyDeclarationContext +import JavaParser.ClassDeclarationContext +import JavaParser.ClassOrInterfaceModifierContext +import JavaParser.ClassOrInterfaceTypeContext +import JavaParser.CompilationUnitContext +import JavaParser.ConstructorDeclarationContext +import JavaParser.CreatorContext +import JavaParser.DEC +import JavaParser.DIV +import JavaParser.DIV_ASSIGN +import JavaParser.DOT import JavaParser.DOUBLE -import JavaParser.FLOAT -import JavaParser.SwitchExpressionContext -import JavaParser.ReferenceContext -import JavaParser.PrimaryContext +import JavaParser.EQUAL import JavaParser.ExpressionContext -import JavaParser.CreatorContext -import JavaParser.VariableDeclaratorsContext -import JavaParser.LiteralContext -import JavaParser.SuperExpressionContext -import JavaParser.ThisExpresionContext +import JavaParser.FINAL +import JavaParser.FLOAT +import JavaParser.FieldDeclarationContext +import JavaParser.FormalParameterContext +import JavaParser.FormalParameterListContext +import JavaParser.FormalParametersContext +import JavaParser.GE +import JavaParser.GT +import JavaParser.INC +import JavaParser.INSTANCEOF +import JavaParser.INT +import JavaParser.IdentifierContext import JavaParser.IdentifierExpresionContext -import JavaParser.LiteralExpressionContext -import JavaParser.ParenthesizedExpressionContext -import JavaParser.MethodCallContext -import JavaParser.ArgumentsContext +import JavaParser.ImportDeclarationContext import JavaParser.InnerCreatorContext -import JavaParser.PrimaryExpresionContext -import JavaParser.MethodInvocationContext import JavaParser.InstanceCreationContext import JavaParser.InstanceOfExpressionContext -import JavaParser.CastExpresionContext -import JavaParser.ArrayAccessContext -import JavaParser.PostfixExpressionContext -import JavaParser.PrefixExpressionContext -import JavaParser.GT -import JavaParser.LT -import JavaParser.BinaryExpressionContext -import JavaParser.URSHIFT_ASSIGN -import JavaParser.MOD_ASSIGN -import JavaParser.TILDE -import JavaParser.BANG -import JavaParser.VAR -import JavaParser.DEC -import JavaParser.INC -import JavaParser.QUESTION -import JavaParser.INSTANCEOF -import JavaParser.DOT -import JavaParser.RSHIFT_ASSIGN +import JavaParser.LE +import JavaParser.LONG import JavaParser.LSHIFT_ASSIGN -import JavaParser.XOR_ASSIGN +import JavaParser.LT +import JavaParser.LiteralContext +import JavaParser.LiteralExpressionContext +import JavaParser.LocalTypeDeclarationContext +import JavaParser.LocalVariableDeclarationContext import JavaParser.MOD +import JavaParser.MOD_ASSIGN +import JavaParser.MUL +import JavaParser.MUL_ASSIGN +import JavaParser.MemberDeclarationContext +import JavaParser.MethodBodyContext +import JavaParser.MethodCallContext +import JavaParser.MethodDeclarationContext +import JavaParser.MethodInvocationContext +import JavaParser.ModifierContext import JavaParser.NOTEQUAL -import JavaParser.AND_ASSIGN -import JavaParser.LE -import JavaParser.GE -import JavaParser.CARET -import JavaParser.BITOR -import JavaParser.OR_ASSIGN -import JavaParser.BITAND -import JavaParser.AND import JavaParser.OR -import JavaParser.EQUAL -import JavaParser.ASSIGN -import JavaParser.DIV_ASSIGN -import JavaParser.SUB_ASSIGN -import JavaParser.MUL_ASSIGN -import JavaParser.ADD_ASSIGN -import JavaParser.DIV +import JavaParser.OR_ASSIGN +import JavaParser.PRIVATE +import JavaParser.PROTECTED +import JavaParser.PUBLIC +import JavaParser.PackageDeclarationContext +import JavaParser.ParenthesizedExpressionContext +import JavaParser.PostfixExpressionContext +import JavaParser.PrefixExpressionContext +import JavaParser.PrimaryContext +import JavaParser.PrimaryExpresionContext +import JavaParser.PrimitiveTypeContext +import JavaParser.QUESTION +import JavaParser.QualifiedNameContext +import JavaParser.RSHIFT_ASSIGN +import JavaParser.ReferenceContext +import JavaParser.SHORT +import JavaParser.STATIC +import JavaParser.STRICTFP import JavaParser.SUB -import JavaParser.MUL -import JavaParser.ADD -import JavaParser.SwitchLabelContext -import JavaParser.SwitchBlockStatementGroupContext -import JavaParser.StatementTryBlockContext -import JavaParser.StatementTryResourceSpecificationContext -import JavaParser.StatementSwitchExpressionContext -import JavaParser.StatementSwitchContext -import JavaParser.StatementSemiContext -import JavaParser.StatementIdentifierLabelContext -import JavaParser.StatementReturnContext -import JavaParser.StatementDoContext +import JavaParser.SUB_ASSIGN +import JavaParser.StatementAssertContext import JavaParser.StatementBlockLabelContext -import JavaParser.StatementForContext -import JavaParser.StatementContinueContext import JavaParser.StatementBreakContext -import JavaParser.StatementAssertContext +import JavaParser.StatementContext +import JavaParser.StatementContinueContext +import JavaParser.StatementDoContext import JavaParser.StatementExpressionContext +import JavaParser.StatementForContext +import JavaParser.StatementIdentifierLabelContext import JavaParser.StatementIfContext +import JavaParser.StatementReturnContext +import JavaParser.StatementSemiContext +import JavaParser.StatementSwitchContext +import JavaParser.StatementSwitchExpressionContext +import JavaParser.StatementTryBlockContext +import JavaParser.StatementTryResourceSpecificationContext import JavaParser.StatementWhileContext -import JavaParser.StatementContext -import JavaParser.ConstructorDeclarationContext -import JavaParser.FieldDeclarationContext -import JavaParser.PUBLIC -import JavaParser.PRIVATE -import JavaParser.STATIC -import JavaParser.PROTECTED -import JavaParser.ABSTRACT -import JavaParser.FINAL -import JavaParser.STRICTFP -import JavaParser.ClassOrInterfaceModifierContext -import JavaParser.MethodDeclarationContext -import JavaParser.MethodBodyContext -import JavaParser.FormalParametersContext -import JavaParser.FormalParameterListContext -import JavaParser.BlockContext -import JavaParser.FormalParameterContext -import JavaParser.BlockStatementContext -import tree.* -import tree.Compilation.* -import tree.Declaration.* -import tree.Expression.* -import tree.Expression.Primary.* -import tree.Statement.* -import tree.Type.* -/* ktlint-disable no-wildcard-imports */ +import JavaParser.SuperExpressionContext +import JavaParser.SwitchBlockStatementGroupContext +import JavaParser.SwitchExpressionContext +import JavaParser.SwitchLabelContext +import JavaParser.TILDE +import JavaParser.ThisExpresionContext +import JavaParser.TypeArgumentContext +import JavaParser.TypeArgumentsContext +import JavaParser.TypeClassOrInterfaceTypeContext +import JavaParser.TypeDeclarationContext +import JavaParser.TypeListContext +import JavaParser.TypeParameterContext +import JavaParser.TypeParametersContext +import JavaParser.TypePrimitiveTypeContext +import JavaParser.TypeTypeContext +import JavaParser.TypeTypeOrVoidContext +import JavaParser.URSHIFT_ASSIGN +import JavaParser.VAR +import JavaParser.VariableDeclaratorContext +import JavaParser.VariableDeclaratorsContext +import JavaParser.VariableInitializerContext +import JavaParser.XOR_ASSIGN +import lexer.Token +import lexer.TokenCode +import org.antlr.v4.runtime.tree.TerminalNode +import tree.Compilation.CompilationUnit +import tree.Compilation.Package +import tree.Compilation.SimpleCompilationUnit +import tree.Compilation.TopLevelComponent +import tree.Compilation.TopLevelComponents +import tree.CompoundName +import tree.Declaration.ClassDeclaration +import tree.Declaration.ClassInitializer +import tree.Declaration.ConstructorDeclaration +import tree.Declaration.Declaration +import tree.Declaration.Declarations +import tree.Declaration.ImportDeclaration +import tree.Declaration.ImportDeclarations +import tree.Declaration.MethodDeclaration +import tree.Declaration.NormalClassDeclaration +import tree.Declaration.ParameterDeclaration +import tree.Declaration.ParameterDeclarations +import tree.Declaration.TypeAndDeclarators +import tree.Declaration.VariableDeclaration +import tree.Declaration.VariableDeclarator +import tree.Declaration.VariableDeclarators +import tree.Dim +import tree.Dims +import tree.Expression.ArgumentList +import tree.Expression.Binary +import tree.Expression.Cast +import tree.Expression.Expression +import tree.Expression.InstanceOf +import tree.Expression.Primary.ArrayAccess +import tree.Expression.Primary.ArrayCreation +import tree.Expression.Primary.FieldAccess +import tree.Expression.Primary.InstanceCreation +import tree.Expression.Primary.InstanceCreationQualified +import tree.Expression.Primary.Literal +import tree.Expression.Primary.MethodInvocation +import tree.Expression.Primary.Parenthesized +import tree.Expression.Primary.Primary +import tree.Expression.Primary.This +import tree.Expression.SimpleReference +import tree.Expression.UnaryPostfix +import tree.Expression.UnaryPrefix +import tree.Initializer +import tree.InitializerArray +import tree.InitializerSimple +import tree.Modifiers +import tree.StandardModifiers +import tree.Statement.Assert +import tree.Statement.Block +import tree.Statement.BlockStatement +import tree.Statement.BlockStatements +import tree.Statement.Break +import tree.Statement.Continue +import tree.Statement.Do +import tree.Statement.IfThenElse +import tree.Statement.Return +import tree.Statement.Statement +import tree.Statement.StatementExpression +import tree.Statement.SwitchBlock +import tree.Statement.SwitchLabel +import tree.Statement.While +import tree.Type.PrimitiveType +import tree.Type.Type +import tree.Type.TypeArgument +import tree.Type.TypeArguments +import tree.Type.TypeList +import tree.Type.TypeName +import tree.Type.TypeParameter +import tree.Type.TypeParameterTail +import tree.Type.TypeParameters fun CompilationUnitContext.toCompilationUnit(): CompilationUnit { val imports = ArrayList(importDeclaration().map { it.toImportDeclaration() }) From e9ee0c97ba80c704a8dcd16bf6ca23df1e7943ff Mon Sep 17 00:00:00 2001 From: Aleksandr Mishin Date: Sat, 12 Nov 2022 15:57:02 +0300 Subject: [PATCH 18/25] removed unused import --- src/main/kotlin/org/polystat/j2eo/treeMapper/Visitor.kt | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/kotlin/org/polystat/j2eo/treeMapper/Visitor.kt b/src/main/kotlin/org/polystat/j2eo/treeMapper/Visitor.kt index 0c6be9ce..5ce8e13f 100644 --- a/src/main/kotlin/org/polystat/j2eo/treeMapper/Visitor.kt +++ b/src/main/kotlin/org/polystat/j2eo/treeMapper/Visitor.kt @@ -1,6 +1,5 @@ package org.polystat.j2eo.treeMapper -import java.util.* import JavaParser import JavaParser.CompilationUnitContext import JavaParserBaseVisitor From 052d03ab4d4589d9dd8f24b6c691d22672fd1cc0 Mon Sep 17 00:00:00 2001 From: Aleksandr Mishin Date: Sat, 12 Nov 2022 16:02:36 +0300 Subject: [PATCH 19/25] removed wildcard imports --- .../kotlin/org/polystat/j2eo/main/Main2.kt | 24 ++++++++++++------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/src/main/kotlin/org/polystat/j2eo/main/Main2.kt b/src/main/kotlin/org/polystat/j2eo/main/Main2.kt index 8a0ab02a..51c41af8 100644 --- a/src/main/kotlin/org/polystat/j2eo/main/Main2.kt +++ b/src/main/kotlin/org/polystat/j2eo/main/Main2.kt @@ -1,11 +1,23 @@ package org.polystat.j2eo.main +import JavaLexer +import JavaParser import arrow.core.Some +import java.io.File +import java.io.FileNotFoundException +import java.nio.file.Files +import java.nio.file.Paths +import kotlin.io.path.createDirectories +import kotlin.system.exitProcess import org.antlr.v4.runtime.CharStreams import org.antlr.v4.runtime.CommonTokenStream -import org.apache.commons.cli.* // ktlint-disable no-wildcard-imports -import JavaLexer -import JavaParser +import org.apache.commons.cli.CommandLine +import org.apache.commons.cli.CommandLineParser +import org.apache.commons.cli.DefaultParser +import org.apache.commons.cli.HelpFormatter +import org.apache.commons.cli.Option +import org.apache.commons.cli.Options +import org.apache.commons.cli.ParseException import org.polystat.j2eo.eotree.EOLicense import org.polystat.j2eo.eotree.EOMetas import org.polystat.j2eo.eotree.EOProgram @@ -18,12 +30,6 @@ import tree.Compilation.SimpleCompilationUnit import tree.Compilation.TopLevelComponents import tree.Declaration.ImportDeclarations import tree.Entity -import java.io.File -import java.io.FileNotFoundException -import java.nio.file.Files -import java.nio.file.Paths -import kotlin.io.path.createDirectories -import kotlin.system.exitProcess object Main2 { @Throws(FileNotFoundException::class) From 8a1e0dad140e32cf5ed6738f7761d639879b1189 Mon Sep 17 00:00:00 2001 From: Aleksandr Mishin Date: Fri, 18 Nov 2022 23:37:55 +0300 Subject: [PATCH 20/25] created main class --- pom.xml | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/pom.xml b/pom.xml index 7c0d07c7..b4b99470 100644 --- a/pom.xml +++ b/pom.xml @@ -75,6 +75,21 @@ SOFTWARE. + + + org.apache.maven.plugins + maven-jar-plugin + 3.1.0 + + + + true + lib/ + Main2 + + + + org.apache.maven.plugins maven-surefire-plugin From bf6159c66e91ec02ebf811b3582fbd65e73ef369 Mon Sep 17 00:00:00 2001 From: Aleksandr Mishin Date: Sat, 19 Nov 2022 17:17:44 +0300 Subject: [PATCH 21/25] well-working with .jar files --- pom.xml | 26 ++++++++++++++++--- .../polystat/j2eo/main/{Main2.kt => Main.kt} | 3 +-- 2 files changed, 23 insertions(+), 6 deletions(-) rename src/main/kotlin/org/polystat/j2eo/main/{Main2.kt => Main.kt} (99%) diff --git a/pom.xml b/pom.xml index b4b99470..842390cf 100644 --- a/pom.xml +++ b/pom.xml @@ -76,16 +76,34 @@ SOFTWARE. - + org.apache.maven.plugins + maven-dependency-plugin + + + copy-dependencies + prepare-package + + copy-dependencies + + + + ${project.build.directory}/libs + + + + + + org.apache.maven.plugins maven-jar-plugin - 3.1.0 true - lib/ - Main2 + libs/ + + com.baeldung.executable.Main + diff --git a/src/main/kotlin/org/polystat/j2eo/main/Main2.kt b/src/main/kotlin/org/polystat/j2eo/main/Main.kt similarity index 99% rename from src/main/kotlin/org/polystat/j2eo/main/Main2.kt rename to src/main/kotlin/org/polystat/j2eo/main/Main.kt index 51c41af8..e9b20540 100644 --- a/src/main/kotlin/org/polystat/j2eo/main/Main2.kt +++ b/src/main/kotlin/org/polystat/j2eo/main/Main.kt @@ -31,9 +31,8 @@ import tree.Compilation.TopLevelComponents import tree.Declaration.ImportDeclarations import tree.Entity -object Main2 { +class Main { @Throws(FileNotFoundException::class) - @JvmStatic fun main(args: Array) { // Setup command line argument parser val options = Options() From 1f1198040fae7e0140e34ac637b814e5551ca832 Mon Sep 17 00:00:00 2001 From: Aleksandr Mishin Date: Sun, 20 Nov 2022 23:51:18 +0300 Subject: [PATCH 22/25] assembly --- pom.xml | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index bd059d4f..41c12b18 100644 --- a/pom.xml +++ b/pom.xml @@ -100,14 +100,30 @@ SOFTWARE. true - libs/ + - com.baeldung.executable.Main + org.polystat.j2eo.main + + maven-assembly-plugin + + + package + + single + + + + + + jar-with-dependencies + + + org.apache.maven.plugins maven-surefire-plugin From 04eb18498f1a68d61c842307c262c7185af8a3b1 Mon Sep 17 00:00:00 2001 From: Aleksandr Mishin Date: Mon, 21 Nov 2022 22:53:19 +0300 Subject: [PATCH 23/25] empty line --- .rultor.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.rultor.yml b/.rultor.yml index 97fef845..3e291157 100644 --- a/.rultor.yml +++ b/.rultor.yml @@ -34,4 +34,5 @@ release: find polystat -name '*.eo' > polystat.lst git add polystat.lst git commit -am "polystat ${tag}" - git checkout "${branch}" \ No newline at end of file + git checkout "${branch}" + From f48a91c0e5355bbdecf17529fe02a4d1f41d54c3 Mon Sep 17 00:00:00 2001 From: Aleksandr Mishin Date: Mon, 21 Nov 2022 22:53:39 +0300 Subject: [PATCH 24/25] removed empty line --- .rultor.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.rultor.yml b/.rultor.yml index 3e291157..1d090e02 100644 --- a/.rultor.yml +++ b/.rultor.yml @@ -35,4 +35,3 @@ release: git add polystat.lst git commit -am "polystat ${tag}" git checkout "${branch}" - From 7db76d0d55ee25093db5008bf4a48c3375a61676 Mon Sep 17 00:00:00 2001 From: Aleksandr Mishin Date: Thu, 24 Nov 2022 17:26:35 +0300 Subject: [PATCH 25/25] main class jvm static --- pom.xml | 40 +++++-------------- .../kotlin/org/polystat/j2eo/main/Main.kt | 3 +- 2 files changed, 11 insertions(+), 32 deletions(-) diff --git a/pom.xml b/pom.xml index 41c12b18..3a62a5d5 100644 --- a/pom.xml +++ b/pom.xml @@ -52,12 +52,21 @@ SOFTWARE. 3.10.1 3.19.0 2.0.4 + org.polystat.j2eo.main ${project.basedir}/src/main/ ${project.basedir}/src/test/kotlin + + org.codehaus.mojo + exec-maven-plugin + 3.0.0 + + org.polystat.j2eo.main.Main + + org.codehaus.mojo build-helper-maven-plugin @@ -93,37 +102,6 @@ SOFTWARE. - - org.apache.maven.plugins - maven-jar-plugin - - - - true - - - org.polystat.j2eo.main - - - - - - - maven-assembly-plugin - - - package - - single - - - - - - jar-with-dependencies - - - org.apache.maven.plugins maven-surefire-plugin diff --git a/src/main/kotlin/org/polystat/j2eo/main/Main.kt b/src/main/kotlin/org/polystat/j2eo/main/Main.kt index e9b20540..168255a2 100644 --- a/src/main/kotlin/org/polystat/j2eo/main/Main.kt +++ b/src/main/kotlin/org/polystat/j2eo/main/Main.kt @@ -31,8 +31,9 @@ import tree.Compilation.TopLevelComponents import tree.Declaration.ImportDeclarations import tree.Entity -class Main { +object Main { @Throws(FileNotFoundException::class) + @JvmStatic fun main(args: Array) { // Setup command line argument parser val options = Options()