diff --git a/driver/normalizer/annotation.go b/driver/normalizer/annotation.go index 2658e13..cfd1c9a 100644 --- a/driver/normalizer/annotation.go +++ b/driver/normalizer/annotation.go @@ -68,12 +68,21 @@ var AnnotationRules = On(Any).Self( On(jdt.IfStatement).Roles(If, Statement).Children( On(jdt.PropertyExpression).Roles(IfCondition), On(jdt.PropertyThenStatement).Roles(IfBody), - On(jdt.PropertyElseExpression).Roles(IfElse), + On(jdt.PropertyElseStatement).Roles(IfElse), ), On(jdt.SwitchStatement).Roles(Switch, Statement).Children( //TODO: On(jdt.PropertyExpression).Roles(SwitchExpression), - On(jdt.SwitchCase).Roles(SwitchCase), + On(jdt.SwitchCase).Self( + On(HasChild(Any)).Roles(SwitchCase).Children( + On(jdt.PropertyExpression).Roles(SwitchCaseCondition), + ), + On(Not(HasChild(Any))).Roles(SwitchDefault), + ), + // FIXME: Switch case bodies are not enclosed in a block, thus it may + // contain an arbitrary number of statements (of any kind). So this + // is just an initial approach. + On(jdt.ExpressionStatement).Roles(SwitchCaseBody), ), // Loops @@ -149,16 +158,25 @@ var AnnotationRules = On(Any).Self( ), ), + On(jdt.TryStatement).Roles(Try, Statement).Children( + // TODO: TryWithResourcesStatement + On(jdt.PropertyBody).Roles(TryBody), + On(jdt.PropertyCatchClauses).Roles(TryCatch), + On(jdt.PropertyFinally).Roles(TryFinally), + ), + + On(jdt.ThrowStatement).Roles(Throw, Statement), + On(jdt.AssertStatement).Roles(Assert, Statement), // Others On(jdt.Block).Roles(BlockScope, Block), On(jdt.ExpressionStatement).Roles(Statement), On(jdt.ReturnStatement).Roles(Return, Statement), + On(jdt.BreakStatement).Roles(Break, Statement), On(jdt.ThisExpression).Roles(This, Expression), //TODO: synchronized - //TODO: try-with-resources On(jdt.Javadoc).Roles(Documentation, Comment), ), ) diff --git a/tests/boolean_operators.native b/tests/boolean_operators.native new file mode 100644 index 0000000..fb5fa2c --- /dev/null +++ b/tests/boolean_operators.native @@ -0,0 +1,146 @@ +{ + "status": "ok", + "errors": [], + "ast": { + "CompilationUnit": { + "internalClass": "CompilationUnit", + "types": [ + { + "bodyDeclarations": [ + { + "body": { + "internalClass": "Block", + "statements": [ + { + "fragments": [ + { + "initializer": { + "internalClass": "InfixExpression", + "leftOperand": { + "booleanValue": "true", + "internalClass": "BooleanLiteral", + "line": 3, + "startPosition": 45 + }, + "line": 3, + "operator": "&&", + "rightOperand": { + "booleanValue": "false", + "internalClass": "BooleanLiteral", + "line": 3, + "startPosition": 53 + }, + "startPosition": 45 + }, + "internalClass": "VariableDeclarationFragment", + "name": { + "identifier": "i", + "internalClass": "SimpleName", + "line": 3, + "startPosition": 41 + } + } + ], + "internalClass": "VariableDeclarationStatement", + "type": { + "internalClass": "PrimitiveType", + "line": 3, + "primitiveTypeCode": "boolean", + "startPosition": 33 + } + }, + { + "expression": { + "internalClass": "Assignment", + "leftHandSide": { + "identifier": "i", + "internalClass": "SimpleName", + "line": 4, + "startPosition": 64 + }, + "line": 4, + "operator": "=", + "rightHandSide": { + "internalClass": "InfixExpression", + "leftOperand": { + "identifier": "i", + "internalClass": "SimpleName", + "line": 4, + "startPosition": 68 + }, + "line": 4, + "operator": "||", + "rightOperand": { + "booleanValue": "false", + "internalClass": "BooleanLiteral", + "line": 4, + "startPosition": 73 + }, + "startPosition": 68 + }, + "startPosition": 64 + }, + "internalClass": "ExpressionStatement" + }, + { + "expression": { + "internalClass": "Assignment", + "leftHandSide": { + "identifier": "i", + "internalClass": "SimpleName", + "line": 5, + "startPosition": 84 + }, + "line": 5, + "operator": "=", + "rightHandSide": { + "internalClass": "PrefixExpression", + "line": 5, + "operand": { + "identifier": "i", + "internalClass": "SimpleName", + "line": 5, + "startPosition": 89 + }, + "operator": "!", + "startPosition": 88 + }, + "startPosition": 84 + }, + "internalClass": "ExpressionStatement" + } + ] + }, + "constructor": "false", + "internalClass": "MethodDeclaration", + "line": 2, + "name": { + "identifier": "code", + "internalClass": "SimpleName", + "line": 2, + "startPosition": 20 + }, + "returnType2": { + "internalClass": "PrimitiveType", + "line": 2, + "primitiveTypeCode": "void", + "startPosition": 15 + }, + "startPosition": 15 + } + ], + "interface": "false", + "internalClass": "TypeDeclaration", + "line": 1, + "name": { + "identifier": "Code", + "internalClass": "SimpleName", + "line": 1, + "startPosition": 6 + }, + "startPosition": 0 + } + ] + } + } +} diff --git a/tests/boolean_operators.source b/tests/boolean_operators.source new file mode 100644 index 0000000..c9a77fd --- /dev/null +++ b/tests/boolean_operators.source @@ -0,0 +1,7 @@ +class Code { + void code() { + boolean i = true && false; + i = i || false; + i = !i; + } +} diff --git a/tests/boolean_operators.uast b/tests/boolean_operators.uast new file mode 100644 index 0000000..cbc72f4 --- /dev/null +++ b/tests/boolean_operators.uast @@ -0,0 +1,287 @@ +Status: ok +Errors: +UAST: +CompilationUnit { +. Roles: File +. Children: { +. . 0: TypeDeclaration { +. . . Roles: VisibleFromPackage,TypeDeclaration +. . . StartPosition: { +. . . . Offset: 0 +. . . . Line: 1 +. . . . Col: 0 +. . . } +. . . Properties: { +. . . . interface: false +. . . . internalRole: types +. . . } +. . . Children: { +. . . . 0: SimpleName { +. . . . . Roles: SimpleIdentifier +. . . . . TOKEN "Code" +. . . . . StartPosition: { +. . . . . . Offset: 6 +. . . . . . Line: 1 +. . . . . . Col: 0 +. . . . . } +. . . . . Properties: { +. . . . . . internalRole: name +. . . . . } +. . . . } +. . . . 1: MethodDeclaration { +. . . . . Roles: VisibleFromPackage,FunctionDeclaration +. . . . . StartPosition: { +. . . . . . Offset: 15 +. . . . . . Line: 2 +. . . . . . Col: 0 +. . . . . } +. . . . . Properties: { +. . . . . . constructor: false +. . . . . . internalRole: bodyDeclarations +. . . . . } +. . . . . Children: { +. . . . . . 0: PrimitiveType { +. . . . . . . TOKEN "void" +. . . . . . . StartPosition: { +. . . . . . . . Offset: 15 +. . . . . . . . Line: 2 +. . . . . . . . Col: 0 +. . . . . . . } +. . . . . . . Properties: { +. . . . . . . . internalRole: returnType2 +. . . . . . . } +. . . . . . } +. . . . . . 1: SimpleName { +. . . . . . . Roles: SimpleIdentifier,FunctionDeclarationName +. . . . . . . TOKEN "code" +. . . . . . . StartPosition: { +. . . . . . . . Offset: 20 +. . . . . . . . Line: 2 +. . . . . . . . Col: 0 +. . . . . . . } +. . . . . . . Properties: { +. . . . . . . . internalRole: name +. . . . . . . } +. . . . . . } +. . . . . . 2: Block { +. . . . . . . Roles: FunctionDeclarationBody,BlockScope,Block +. . . . . . . Properties: { +. . . . . . . . internalRole: body +. . . . . . . } +. . . . . . . Children: { +. . . . . . . . 0: VariableDeclarationStatement { +. . . . . . . . . Properties: { +. . . . . . . . . . internalRole: statements +. . . . . . . . . } +. . . . . . . . . Children: { +. . . . . . . . . . 0: PrimitiveType { +. . . . . . . . . . . TOKEN "boolean" +. . . . . . . . . . . StartPosition: { +. . . . . . . . . . . . Offset: 33 +. . . . . . . . . . . . Line: 3 +. . . . . . . . . . . . Col: 0 +. . . . . . . . . . . } +. . . . . . . . . . . Properties: { +. . . . . . . . . . . . internalRole: type +. . . . . . . . . . . } +. . . . . . . . . . } +. . . . . . . . . . 1: VariableDeclarationFragment { +. . . . . . . . . . . Properties: { +. . . . . . . . . . . . internalRole: fragments +. . . . . . . . . . . } +. . . . . . . . . . . Children: { +. . . . . . . . . . . . 0: SimpleName { +. . . . . . . . . . . . . Roles: SimpleIdentifier +. . . . . . . . . . . . . TOKEN "i" +. . . . . . . . . . . . . StartPosition: { +. . . . . . . . . . . . . . Offset: 41 +. . . . . . . . . . . . . . Line: 3 +. . . . . . . . . . . . . . Col: 0 +. . . . . . . . . . . . . } +. . . . . . . . . . . . . Properties: { +. . . . . . . . . . . . . . internalRole: name +. . . . . . . . . . . . . } +. . . . . . . . . . . . } +. . . . . . . . . . . . 1: InfixExpression { +. . . . . . . . . . . . . Roles: OpBooleanAnd +. . . . . . . . . . . . . StartPosition: { +. . . . . . . . . . . . . . Offset: 45 +. . . . . . . . . . . . . . Line: 3 +. . . . . . . . . . . . . . Col: 0 +. . . . . . . . . . . . . } +. . . . . . . . . . . . . Properties: { +. . . . . . . . . . . . . . internalRole: initializer +. . . . . . . . . . . . . . operator: && +. . . . . . . . . . . . . } +. . . . . . . . . . . . . Children: { +. . . . . . . . . . . . . . 0: BooleanLiteral { +. . . . . . . . . . . . . . . Roles: BooleanLiteral +. . . . . . . . . . . . . . . StartPosition: { +. . . . . . . . . . . . . . . . Offset: 45 +. . . . . . . . . . . . . . . . Line: 3 +. . . . . . . . . . . . . . . . Col: 0 +. . . . . . . . . . . . . . . } +. . . . . . . . . . . . . . . Properties: { +. . . . . . . . . . . . . . . . booleanValue: true +. . . . . . . . . . . . . . . . internalRole: leftOperand +. . . . . . . . . . . . . . . } +. . . . . . . . . . . . . . } +. . . . . . . . . . . . . . 1: BooleanLiteral { +. . . . . . . . . . . . . . . Roles: BooleanLiteral +. . . . . . . . . . . . . . . StartPosition: { +. . . . . . . . . . . . . . . . Offset: 53 +. . . . . . . . . . . . . . . . Line: 3 +. . . . . . . . . . . . . . . . Col: 0 +. . . . . . . . . . . . . . . } +. . . . . . . . . . . . . . . Properties: { +. . . . . . . . . . . . . . . . booleanValue: false +. . . . . . . . . . . . . . . . internalRole: rightOperand +. . . . . . . . . . . . . . . } +. . . . . . . . . . . . . . } +. . . . . . . . . . . . . } +. . . . . . . . . . . . } +. . . . . . . . . . . } +. . . . . . . . . . } +. . . . . . . . . } +. . . . . . . . } +. . . . . . . . 1: ExpressionStatement { +. . . . . . . . . Roles: Statement +. . . . . . . . . Properties: { +. . . . . . . . . . internalRole: statements +. . . . . . . . . } +. . . . . . . . . Children: { +. . . . . . . . . . 0: Assignment { +. . . . . . . . . . . Roles: Assignment +. . . . . . . . . . . StartPosition: { +. . . . . . . . . . . . Offset: 64 +. . . . . . . . . . . . Line: 4 +. . . . . . . . . . . . Col: 0 +. . . . . . . . . . . } +. . . . . . . . . . . Properties: { +. . . . . . . . . . . . internalRole: expression +. . . . . . . . . . . . operator: = +. . . . . . . . . . . } +. . . . . . . . . . . Children: { +. . . . . . . . . . . . 0: SimpleName { +. . . . . . . . . . . . . Roles: SimpleIdentifier,AssignmentVariable +. . . . . . . . . . . . . TOKEN "i" +. . . . . . . . . . . . . StartPosition: { +. . . . . . . . . . . . . . Offset: 64 +. . . . . . . . . . . . . . Line: 4 +. . . . . . . . . . . . . . Col: 0 +. . . . . . . . . . . . . } +. . . . . . . . . . . . . Properties: { +. . . . . . . . . . . . . . internalRole: leftHandSide +. . . . . . . . . . . . . } +. . . . . . . . . . . . } +. . . . . . . . . . . . 1: InfixExpression { +. . . . . . . . . . . . . Roles: OpBooleanOr,AssignmentValue +. . . . . . . . . . . . . StartPosition: { +. . . . . . . . . . . . . . Offset: 68 +. . . . . . . . . . . . . . Line: 4 +. . . . . . . . . . . . . . Col: 0 +. . . . . . . . . . . . . } +. . . . . . . . . . . . . Properties: { +. . . . . . . . . . . . . . internalRole: rightHandSide +. . . . . . . . . . . . . . operator: || +. . . . . . . . . . . . . } +. . . . . . . . . . . . . Children: { +. . . . . . . . . . . . . . 0: SimpleName { +. . . . . . . . . . . . . . . Roles: SimpleIdentifier +. . . . . . . . . . . . . . . TOKEN "i" +. . . . . . . . . . . . . . . StartPosition: { +. . . . . . . . . . . . . . . . Offset: 68 +. . . . . . . . . . . . . . . . Line: 4 +. . . . . . . . . . . . . . . . Col: 0 +. . . . . . . . . . . . . . . } +. . . . . . . . . . . . . . . Properties: { +. . . . . . . . . . . . . . . . internalRole: leftOperand +. . . . . . . . . . . . . . . } +. . . . . . . . . . . . . . } +. . . . . . . . . . . . . . 1: BooleanLiteral { +. . . . . . . . . . . . . . . Roles: BooleanLiteral +. . . . . . . . . . . . . . . StartPosition: { +. . . . . . . . . . . . . . . . Offset: 73 +. . . . . . . . . . . . . . . . Line: 4 +. . . . . . . . . . . . . . . . Col: 0 +. . . . . . . . . . . . . . . } +. . . . . . . . . . . . . . . Properties: { +. . . . . . . . . . . . . . . . booleanValue: false +. . . . . . . . . . . . . . . . internalRole: rightOperand +. . . . . . . . . . . . . . . } +. . . . . . . . . . . . . . } +. . . . . . . . . . . . . } +. . . . . . . . . . . . } +. . . . . . . . . . . } +. . . . . . . . . . } +. . . . . . . . . } +. . . . . . . . } +. . . . . . . . 2: ExpressionStatement { +. . . . . . . . . Roles: Statement +. . . . . . . . . Properties: { +. . . . . . . . . . internalRole: statements +. . . . . . . . . } +. . . . . . . . . Children: { +. . . . . . . . . . 0: Assignment { +. . . . . . . . . . . Roles: Assignment +. . . . . . . . . . . StartPosition: { +. . . . . . . . . . . . Offset: 84 +. . . . . . . . . . . . Line: 5 +. . . . . . . . . . . . Col: 0 +. . . . . . . . . . . } +. . . . . . . . . . . Properties: { +. . . . . . . . . . . . internalRole: expression +. . . . . . . . . . . . operator: = +. . . . . . . . . . . } +. . . . . . . . . . . Children: { +. . . . . . . . . . . . 0: SimpleName { +. . . . . . . . . . . . . Roles: SimpleIdentifier,AssignmentVariable +. . . . . . . . . . . . . TOKEN "i" +. . . . . . . . . . . . . StartPosition: { +. . . . . . . . . . . . . . Offset: 84 +. . . . . . . . . . . . . . Line: 5 +. . . . . . . . . . . . . . Col: 0 +. . . . . . . . . . . . . } +. . . . . . . . . . . . . Properties: { +. . . . . . . . . . . . . . internalRole: leftHandSide +. . . . . . . . . . . . . } +. . . . . . . . . . . . } +. . . . . . . . . . . . 1: PrefixExpression { +. . . . . . . . . . . . . Roles: OpBooleanNot,AssignmentValue +. . . . . . . . . . . . . StartPosition: { +. . . . . . . . . . . . . . Offset: 88 +. . . . . . . . . . . . . . Line: 5 +. . . . . . . . . . . . . . Col: 0 +. . . . . . . . . . . . . } +. . . . . . . . . . . . . Properties: { +. . . . . . . . . . . . . . internalRole: rightHandSide +. . . . . . . . . . . . . . operator: ! +. . . . . . . . . . . . . } +. . . . . . . . . . . . . Children: { +. . . . . . . . . . . . . . 0: SimpleName { +. . . . . . . . . . . . . . . Roles: SimpleIdentifier +. . . . . . . . . . . . . . . TOKEN "i" +. . . . . . . . . . . . . . . StartPosition: { +. . . . . . . . . . . . . . . . Offset: 89 +. . . . . . . . . . . . . . . . Line: 5 +. . . . . . . . . . . . . . . . Col: 0 +. . . . . . . . . . . . . . . } +. . . . . . . . . . . . . . . Properties: { +. . . . . . . . . . . . . . . . internalRole: operand +. . . . . . . . . . . . . . . } +. . . . . . . . . . . . . . } +. . . . . . . . . . . . . } +. . . . . . . . . . . . } +. . . . . . . . . . . } +. . . . . . . . . . } +. . . . . . . . . } +. . . . . . . . } +. . . . . . . } +. . . . . . } +. . . . . } +. . . . } +. . . } +. . } +. } +} + diff --git a/tests/break.native b/tests/break.native new file mode 100644 index 0000000..8fb1ead --- /dev/null +++ b/tests/break.native @@ -0,0 +1,51 @@ +{ + "status": "ok", + "errors": [], + "ast": { + "CompilationUnit": { + "internalClass": "CompilationUnit", + "types": [ + { + "bodyDeclarations": [ + { + "body": { + "internalClass": "Block", + "statements": [ + { + "internalClass": "BreakStatement" + } + ] + }, + "constructor": "false", + "internalClass": "MethodDeclaration", + "line": 2, + "name": { + "identifier": "code", + "internalClass": "SimpleName", + "line": 2, + "startPosition": 20 + }, + "returnType2": { + "internalClass": "PrimitiveType", + "line": 2, + "primitiveTypeCode": "void", + "startPosition": 15 + }, + "startPosition": 15 + } + ], + "interface": "false", + "internalClass": "TypeDeclaration", + "line": 1, + "name": { + "identifier": "Code", + "internalClass": "SimpleName", + "line": 1, + "startPosition": 6 + }, + "startPosition": 0 + } + ] + } + } +} diff --git a/tests/break.source b/tests/break.source new file mode 100644 index 0000000..5482195 --- /dev/null +++ b/tests/break.source @@ -0,0 +1,3 @@ +class Code { + void code() { break; } +} \ No newline at end of file diff --git a/tests/break.uast b/tests/break.uast new file mode 100644 index 0000000..4783cd4 --- /dev/null +++ b/tests/break.uast @@ -0,0 +1,86 @@ +Status: ok +Errors: +UAST: +CompilationUnit { +. Roles: File +. Children: { +. . 0: TypeDeclaration { +. . . Roles: VisibleFromPackage,TypeDeclaration +. . . StartPosition: { +. . . . Offset: 0 +. . . . Line: 1 +. . . . Col: 0 +. . . } +. . . Properties: { +. . . . interface: false +. . . . internalRole: types +. . . } +. . . Children: { +. . . . 0: SimpleName { +. . . . . Roles: SimpleIdentifier +. . . . . TOKEN "Code" +. . . . . StartPosition: { +. . . . . . Offset: 6 +. . . . . . Line: 1 +. . . . . . Col: 0 +. . . . . } +. . . . . Properties: { +. . . . . . internalRole: name +. . . . . } +. . . . } +. . . . 1: MethodDeclaration { +. . . . . Roles: VisibleFromPackage,FunctionDeclaration +. . . . . StartPosition: { +. . . . . . Offset: 15 +. . . . . . Line: 2 +. . . . . . Col: 0 +. . . . . } +. . . . . Properties: { +. . . . . . constructor: false +. . . . . . internalRole: bodyDeclarations +. . . . . } +. . . . . Children: { +. . . . . . 0: PrimitiveType { +. . . . . . . TOKEN "void" +. . . . . . . StartPosition: { +. . . . . . . . Offset: 15 +. . . . . . . . Line: 2 +. . . . . . . . Col: 0 +. . . . . . . } +. . . . . . . Properties: { +. . . . . . . . internalRole: returnType2 +. . . . . . . } +. . . . . . } +. . . . . . 1: SimpleName { +. . . . . . . Roles: SimpleIdentifier,FunctionDeclarationName +. . . . . . . TOKEN "code" +. . . . . . . StartPosition: { +. . . . . . . . Offset: 20 +. . . . . . . . Line: 2 +. . . . . . . . Col: 0 +. . . . . . . } +. . . . . . . Properties: { +. . . . . . . . internalRole: name +. . . . . . . } +. . . . . . } +. . . . . . 2: Block { +. . . . . . . Roles: FunctionDeclarationBody,BlockScope,Block +. . . . . . . Properties: { +. . . . . . . . internalRole: body +. . . . . . . } +. . . . . . . Children: { +. . . . . . . . 0: BreakStatement { +. . . . . . . . . Roles: Break,Statement +. . . . . . . . . Properties: { +. . . . . . . . . . internalRole: statements +. . . . . . . . . } +. . . . . . . . } +. . . . . . . } +. . . . . . } +. . . . . } +. . . . } +. . . } +. . } +. } +} + diff --git a/tests/if.native b/tests/if.native new file mode 100644 index 0000000..b5d84f6 --- /dev/null +++ b/tests/if.native @@ -0,0 +1,97 @@ +{ + "status": "ok", + "errors": [], + "ast": { + "CompilationUnit": { + "internalClass": "CompilationUnit", + "types": [ + { + "bodyDeclarations": [ + { + "body": { + "internalClass": "Block", + "statements": [ + { + "expression": { + "booleanValue": "true", + "internalClass": "BooleanLiteral", + "line": 3, + "startPosition": 37 + }, + "internalClass": "IfStatement", + "thenStatement": { + "internalClass": "Block", + "statements": [ + { + "expression": { + "arguments": [ + { + "booleanValue": "true", + "internalClass": "BooleanLiteral", + "line": 4, + "startPosition": 70 + } + ], + "expression": { + "internalClass": "QualifiedName", + "name": { + "identifier": "out", + "internalClass": "SimpleName", + "line": 4, + "startPosition": 58 + }, + "qualifier": { + "identifier": "System", + "internalClass": "SimpleName", + "line": 4, + "startPosition": 51 + } + }, + "internalClass": "MethodInvocation", + "name": { + "identifier": "println", + "internalClass": "SimpleName", + "line": 4, + "startPosition": 62 + } + }, + "internalClass": "ExpressionStatement" + } + ] + } + } + ] + }, + "constructor": "false", + "internalClass": "MethodDeclaration", + "line": 2, + "name": { + "identifier": "code", + "internalClass": "SimpleName", + "line": 2, + "startPosition": 20 + }, + "returnType2": { + "internalClass": "PrimitiveType", + "line": 2, + "primitiveTypeCode": "void", + "startPosition": 15 + }, + "startPosition": 15 + } + ], + "interface": "false", + "internalClass": "TypeDeclaration", + "line": 1, + "name": { + "identifier": "Code", + "internalClass": "SimpleName", + "line": 1, + "startPosition": 6 + }, + "startPosition": 0 + } + ] + } + } +} diff --git a/tests/if.source b/tests/if.source new file mode 100644 index 0000000..0bbf753 --- /dev/null +++ b/tests/if.source @@ -0,0 +1,7 @@ +class Code { + void code() { + if (true) { + System.out.println(true); + } + } +} diff --git a/tests/if.uast b/tests/if.uast new file mode 100644 index 0000000..5157373 --- /dev/null +++ b/tests/if.uast @@ -0,0 +1,181 @@ +Status: ok +Errors: +UAST: +CompilationUnit { +. Roles: File +. Children: { +. . 0: TypeDeclaration { +. . . Roles: VisibleFromPackage,TypeDeclaration +. . . StartPosition: { +. . . . Offset: 0 +. . . . Line: 1 +. . . . Col: 0 +. . . } +. . . Properties: { +. . . . interface: false +. . . . internalRole: types +. . . } +. . . Children: { +. . . . 0: SimpleName { +. . . . . Roles: SimpleIdentifier +. . . . . TOKEN "Code" +. . . . . StartPosition: { +. . . . . . Offset: 6 +. . . . . . Line: 1 +. . . . . . Col: 0 +. . . . . } +. . . . . Properties: { +. . . . . . internalRole: name +. . . . . } +. . . . } +. . . . 1: MethodDeclaration { +. . . . . Roles: VisibleFromPackage,FunctionDeclaration +. . . . . StartPosition: { +. . . . . . Offset: 15 +. . . . . . Line: 2 +. . . . . . Col: 0 +. . . . . } +. . . . . Properties: { +. . . . . . constructor: false +. . . . . . internalRole: bodyDeclarations +. . . . . } +. . . . . Children: { +. . . . . . 0: PrimitiveType { +. . . . . . . TOKEN "void" +. . . . . . . StartPosition: { +. . . . . . . . Offset: 15 +. . . . . . . . Line: 2 +. . . . . . . . Col: 0 +. . . . . . . } +. . . . . . . Properties: { +. . . . . . . . internalRole: returnType2 +. . . . . . . } +. . . . . . } +. . . . . . 1: SimpleName { +. . . . . . . Roles: SimpleIdentifier,FunctionDeclarationName +. . . . . . . TOKEN "code" +. . . . . . . StartPosition: { +. . . . . . . . Offset: 20 +. . . . . . . . Line: 2 +. . . . . . . . Col: 0 +. . . . . . . } +. . . . . . . Properties: { +. . . . . . . . internalRole: name +. . . . . . . } +. . . . . . } +. . . . . . 2: Block { +. . . . . . . Roles: FunctionDeclarationBody,BlockScope,Block +. . . . . . . Properties: { +. . . . . . . . internalRole: body +. . . . . . . } +. . . . . . . Children: { +. . . . . . . . 0: IfStatement { +. . . . . . . . . Roles: If,Statement +. . . . . . . . . TOKEN "if" +. . . . . . . . . Properties: { +. . . . . . . . . . internalRole: statements +. . . . . . . . . } +. . . . . . . . . Children: { +. . . . . . . . . . 0: BooleanLiteral { +. . . . . . . . . . . Roles: BooleanLiteral,IfCondition +. . . . . . . . . . . StartPosition: { +. . . . . . . . . . . . Offset: 37 +. . . . . . . . . . . . Line: 3 +. . . . . . . . . . . . Col: 0 +. . . . . . . . . . . } +. . . . . . . . . . . Properties: { +. . . . . . . . . . . . booleanValue: true +. . . . . . . . . . . . internalRole: expression +. . . . . . . . . . . } +. . . . . . . . . . } +. . . . . . . . . . 1: Block { +. . . . . . . . . . . Roles: IfBody,BlockScope,Block +. . . . . . . . . . . Properties: { +. . . . . . . . . . . . internalRole: thenStatement +. . . . . . . . . . . } +. . . . . . . . . . . Children: { +. . . . . . . . . . . . 0: ExpressionStatement { +. . . . . . . . . . . . . Roles: Statement +. . . . . . . . . . . . . Properties: { +. . . . . . . . . . . . . . internalRole: statements +. . . . . . . . . . . . . } +. . . . . . . . . . . . . Children: { +. . . . . . . . . . . . . . 0: MethodInvocation { +. . . . . . . . . . . . . . . Roles: Call +. . . . . . . . . . . . . . . Properties: { +. . . . . . . . . . . . . . . . internalRole: expression +. . . . . . . . . . . . . . . } +. . . . . . . . . . . . . . . Children: { +. . . . . . . . . . . . . . . . 0: QualifiedName { +. . . . . . . . . . . . . . . . . Roles: QualifiedIdentifier,CallReceiver +. . . . . . . . . . . . . . . . . Properties: { +. . . . . . . . . . . . . . . . . . internalRole: expression +. . . . . . . . . . . . . . . . . } +. . . . . . . . . . . . . . . . . Children: { +. . . . . . . . . . . . . . . . . . 0: SimpleName { +. . . . . . . . . . . . . . . . . . . Roles: SimpleIdentifier +. . . . . . . . . . . . . . . . . . . TOKEN "System" +. . . . . . . . . . . . . . . . . . . StartPosition: { +. . . . . . . . . . . . . . . . . . . . Offset: 51 +. . . . . . . . . . . . . . . . . . . . Line: 4 +. . . . . . . . . . . . . . . . . . . . Col: 0 +. . . . . . . . . . . . . . . . . . . } +. . . . . . . . . . . . . . . . . . . Properties: { +. . . . . . . . . . . . . . . . . . . . internalRole: qualifier +. . . . . . . . . . . . . . . . . . . } +. . . . . . . . . . . . . . . . . . } +. . . . . . . . . . . . . . . . . . 1: SimpleName { +. . . . . . . . . . . . . . . . . . . Roles: SimpleIdentifier +. . . . . . . . . . . . . . . . . . . TOKEN "out" +. . . . . . . . . . . . . . . . . . . StartPosition: { +. . . . . . . . . . . . . . . . . . . . Offset: 58 +. . . . . . . . . . . . . . . . . . . . Line: 4 +. . . . . . . . . . . . . . . . . . . . Col: 0 +. . . . . . . . . . . . . . . . . . . } +. . . . . . . . . . . . . . . . . . . Properties: { +. . . . . . . . . . . . . . . . . . . . internalRole: name +. . . . . . . . . . . . . . . . . . . } +. . . . . . . . . . . . . . . . . . } +. . . . . . . . . . . . . . . . . } +. . . . . . . . . . . . . . . . } +. . . . . . . . . . . . . . . . 1: SimpleName { +. . . . . . . . . . . . . . . . . Roles: SimpleIdentifier,CallCallee +. . . . . . . . . . . . . . . . . TOKEN "println" +. . . . . . . . . . . . . . . . . StartPosition: { +. . . . . . . . . . . . . . . . . . Offset: 62 +. . . . . . . . . . . . . . . . . . Line: 4 +. . . . . . . . . . . . . . . . . . Col: 0 +. . . . . . . . . . . . . . . . . } +. . . . . . . . . . . . . . . . . Properties: { +. . . . . . . . . . . . . . . . . . internalRole: name +. . . . . . . . . . . . . . . . . } +. . . . . . . . . . . . . . . . } +. . . . . . . . . . . . . . . . 2: BooleanLiteral { +. . . . . . . . . . . . . . . . . Roles: BooleanLiteral,CallPositionalArgument +. . . . . . . . . . . . . . . . . StartPosition: { +. . . . . . . . . . . . . . . . . . Offset: 70 +. . . . . . . . . . . . . . . . . . Line: 4 +. . . . . . . . . . . . . . . . . . Col: 0 +. . . . . . . . . . . . . . . . . } +. . . . . . . . . . . . . . . . . Properties: { +. . . . . . . . . . . . . . . . . . booleanValue: true +. . . . . . . . . . . . . . . . . . internalRole: arguments +. . . . . . . . . . . . . . . . . } +. . . . . . . . . . . . . . . . } +. . . . . . . . . . . . . . . } +. . . . . . . . . . . . . . } +. . . . . . . . . . . . . } +. . . . . . . . . . . . } +. . . . . . . . . . . } +. . . . . . . . . . } +. . . . . . . . . } +. . . . . . . . } +. . . . . . . } +. . . . . . } +. . . . . } +. . . . } +. . . } +. . } +. } +} + diff --git a/tests/ifelse.native b/tests/ifelse.native index f8aa05e..2c9ddef 100644 --- a/tests/ifelse.native +++ b/tests/ifelse.native @@ -22,7 +22,7 @@ "booleanValue": "false", "internalClass": "BooleanLiteral", "line": 6, - "startPosition": 125 + "startPosition": 115 } ], "expression": { @@ -31,13 +31,13 @@ "identifier": "out", "internalClass": "SimpleName", "line": 6, - "startPosition": 113 + "startPosition": 103 }, "qualifier": { "identifier": "System", "internalClass": "SimpleName", "line": 6, - "startPosition": 106 + "startPosition": 96 } }, "internalClass": "MethodInvocation", @@ -45,7 +45,7 @@ "identifier": "println", "internalClass": "SimpleName", "line": 6, - "startPosition": 117 + "startPosition": 107 } }, "internalClass": "ExpressionStatement" @@ -69,7 +69,7 @@ "booleanValue": "true", "internalClass": "BooleanLiteral", "line": 4, - "startPosition": 76 + "startPosition": 70 } ], "expression": { @@ -78,13 +78,13 @@ "identifier": "out", "internalClass": "SimpleName", "line": 4, - "startPosition": 64 + "startPosition": 58 }, "qualifier": { "identifier": "System", "internalClass": "SimpleName", "line": 4, - "startPosition": 57 + "startPosition": 51 } }, "internalClass": "MethodInvocation", @@ -92,7 +92,7 @@ "identifier": "println", "internalClass": "SimpleName", "line": 4, - "startPosition": 68 + "startPosition": 62 } }, "internalClass": "ExpressionStatement" @@ -109,15 +109,15 @@ "identifier": "code", "internalClass": "SimpleName", "line": 2, - "startPosition": 19 + "startPosition": 20 }, "returnType2": { "internalClass": "PrimitiveType", "line": 2, "primitiveTypeCode": "void", - "startPosition": 14 + "startPosition": 15 }, - "startPosition": 14 + "startPosition": 15 } ], "interface": "false", diff --git a/tests/ifelse.source b/tests/ifelse.source index f179b84..f427644 100644 --- a/tests/ifelse.source +++ b/tests/ifelse.source @@ -1,9 +1,9 @@ class Code { - void code() { - if (true) { - System.out.println(true); - } else { - System.out.println(false); - } - } + void code() { + if (true) { + System.out.println(true); + } else { + System.out.println(false); + } + } } diff --git a/tests/ifelse.uast b/tests/ifelse.uast index 4542a2a..89192e5 100644 --- a/tests/ifelse.uast +++ b/tests/ifelse.uast @@ -31,7 +31,7 @@ CompilationUnit { . . . . 1: MethodDeclaration { . . . . . Roles: VisibleFromPackage,FunctionDeclaration . . . . . StartPosition: { -. . . . . . Offset: 14 +. . . . . . Offset: 15 . . . . . . Line: 2 . . . . . . Col: 0 . . . . . } @@ -43,7 +43,7 @@ CompilationUnit { . . . . . . 0: PrimitiveType { . . . . . . . TOKEN "void" . . . . . . . StartPosition: { -. . . . . . . . Offset: 14 +. . . . . . . . Offset: 15 . . . . . . . . Line: 2 . . . . . . . . Col: 0 . . . . . . . } @@ -55,7 +55,7 @@ CompilationUnit { . . . . . . . Roles: SimpleIdentifier,FunctionDeclarationName . . . . . . . TOKEN "code" . . . . . . . StartPosition: { -. . . . . . . . Offset: 19 +. . . . . . . . Offset: 20 . . . . . . . . Line: 2 . . . . . . . . Col: 0 . . . . . . . } @@ -116,7 +116,7 @@ CompilationUnit { . . . . . . . . . . . . . . . . . . . Roles: SimpleIdentifier . . . . . . . . . . . . . . . . . . . TOKEN "System" . . . . . . . . . . . . . . . . . . . StartPosition: { -. . . . . . . . . . . . . . . . . . . . Offset: 57 +. . . . . . . . . . . . . . . . . . . . Offset: 51 . . . . . . . . . . . . . . . . . . . . Line: 4 . . . . . . . . . . . . . . . . . . . . Col: 0 . . . . . . . . . . . . . . . . . . . } @@ -128,7 +128,7 @@ CompilationUnit { . . . . . . . . . . . . . . . . . . . Roles: SimpleIdentifier . . . . . . . . . . . . . . . . . . . TOKEN "out" . . . . . . . . . . . . . . . . . . . StartPosition: { -. . . . . . . . . . . . . . . . . . . . Offset: 64 +. . . . . . . . . . . . . . . . . . . . Offset: 58 . . . . . . . . . . . . . . . . . . . . Line: 4 . . . . . . . . . . . . . . . . . . . . Col: 0 . . . . . . . . . . . . . . . . . . . } @@ -142,7 +142,7 @@ CompilationUnit { . . . . . . . . . . . . . . . . . Roles: SimpleIdentifier,CallCallee . . . . . . . . . . . . . . . . . TOKEN "println" . . . . . . . . . . . . . . . . . StartPosition: { -. . . . . . . . . . . . . . . . . . Offset: 68 +. . . . . . . . . . . . . . . . . . Offset: 62 . . . . . . . . . . . . . . . . . . Line: 4 . . . . . . . . . . . . . . . . . . Col: 0 . . . . . . . . . . . . . . . . . } @@ -153,7 +153,7 @@ CompilationUnit { . . . . . . . . . . . . . . . . 2: BooleanLiteral { . . . . . . . . . . . . . . . . . Roles: BooleanLiteral,CallPositionalArgument . . . . . . . . . . . . . . . . . StartPosition: { -. . . . . . . . . . . . . . . . . . Offset: 76 +. . . . . . . . . . . . . . . . . . Offset: 70 . . . . . . . . . . . . . . . . . . Line: 4 . . . . . . . . . . . . . . . . . . Col: 0 . . . . . . . . . . . . . . . . . } @@ -169,7 +169,7 @@ CompilationUnit { . . . . . . . . . . . } . . . . . . . . . . } . . . . . . . . . . 2: Block { -. . . . . . . . . . . Roles: BlockScope,Block +. . . . . . . . . . . Roles: IfElse,BlockScope,Block . . . . . . . . . . . Properties: { . . . . . . . . . . . . internalRole: elseStatement . . . . . . . . . . . } @@ -196,7 +196,7 @@ CompilationUnit { . . . . . . . . . . . . . . . . . . . Roles: SimpleIdentifier . . . . . . . . . . . . . . . . . . . TOKEN "System" . . . . . . . . . . . . . . . . . . . StartPosition: { -. . . . . . . . . . . . . . . . . . . . Offset: 106 +. . . . . . . . . . . . . . . . . . . . Offset: 96 . . . . . . . . . . . . . . . . . . . . Line: 6 . . . . . . . . . . . . . . . . . . . . Col: 0 . . . . . . . . . . . . . . . . . . . } @@ -208,7 +208,7 @@ CompilationUnit { . . . . . . . . . . . . . . . . . . . Roles: SimpleIdentifier . . . . . . . . . . . . . . . . . . . TOKEN "out" . . . . . . . . . . . . . . . . . . . StartPosition: { -. . . . . . . . . . . . . . . . . . . . Offset: 113 +. . . . . . . . . . . . . . . . . . . . Offset: 103 . . . . . . . . . . . . . . . . . . . . Line: 6 . . . . . . . . . . . . . . . . . . . . Col: 0 . . . . . . . . . . . . . . . . . . . } @@ -222,7 +222,7 @@ CompilationUnit { . . . . . . . . . . . . . . . . . Roles: SimpleIdentifier,CallCallee . . . . . . . . . . . . . . . . . TOKEN "println" . . . . . . . . . . . . . . . . . StartPosition: { -. . . . . . . . . . . . . . . . . . Offset: 117 +. . . . . . . . . . . . . . . . . . Offset: 107 . . . . . . . . . . . . . . . . . . Line: 6 . . . . . . . . . . . . . . . . . . Col: 0 . . . . . . . . . . . . . . . . . } @@ -233,7 +233,7 @@ CompilationUnit { . . . . . . . . . . . . . . . . 2: BooleanLiteral { . . . . . . . . . . . . . . . . . Roles: BooleanLiteral,CallPositionalArgument . . . . . . . . . . . . . . . . . StartPosition: { -. . . . . . . . . . . . . . . . . . Offset: 125 +. . . . . . . . . . . . . . . . . . Offset: 115 . . . . . . . . . . . . . . . . . . Line: 6 . . . . . . . . . . . . . . . . . . Col: 0 . . . . . . . . . . . . . . . . . } diff --git a/tests/return.native b/tests/return.native new file mode 100644 index 0000000..2894f93 --- /dev/null +++ b/tests/return.native @@ -0,0 +1,51 @@ +{ + "status": "ok", + "errors": [], + "ast": { + "CompilationUnit": { + "internalClass": "CompilationUnit", + "types": [ + { + "bodyDeclarations": [ + { + "body": { + "internalClass": "Block", + "statements": [ + { + "internalClass": "ReturnStatement" + } + ] + }, + "constructor": "false", + "internalClass": "MethodDeclaration", + "line": 2, + "name": { + "identifier": "code", + "internalClass": "SimpleName", + "line": 2, + "startPosition": 20 + }, + "returnType2": { + "internalClass": "PrimitiveType", + "line": 2, + "primitiveTypeCode": "void", + "startPosition": 15 + }, + "startPosition": 15 + } + ], + "interface": "false", + "internalClass": "TypeDeclaration", + "line": 1, + "name": { + "identifier": "Code", + "internalClass": "SimpleName", + "line": 1, + "startPosition": 6 + }, + "startPosition": 0 + } + ] + } + } +} diff --git a/tests/return.source b/tests/return.source new file mode 100644 index 0000000..fe4e623 --- /dev/null +++ b/tests/return.source @@ -0,0 +1,3 @@ +class Code { + void code() { return; } +} diff --git a/tests/return.uast b/tests/return.uast new file mode 100644 index 0000000..c1c503d --- /dev/null +++ b/tests/return.uast @@ -0,0 +1,86 @@ +Status: ok +Errors: +UAST: +CompilationUnit { +. Roles: File +. Children: { +. . 0: TypeDeclaration { +. . . Roles: VisibleFromPackage,TypeDeclaration +. . . StartPosition: { +. . . . Offset: 0 +. . . . Line: 1 +. . . . Col: 0 +. . . } +. . . Properties: { +. . . . interface: false +. . . . internalRole: types +. . . } +. . . Children: { +. . . . 0: SimpleName { +. . . . . Roles: SimpleIdentifier +. . . . . TOKEN "Code" +. . . . . StartPosition: { +. . . . . . Offset: 6 +. . . . . . Line: 1 +. . . . . . Col: 0 +. . . . . } +. . . . . Properties: { +. . . . . . internalRole: name +. . . . . } +. . . . } +. . . . 1: MethodDeclaration { +. . . . . Roles: VisibleFromPackage,FunctionDeclaration +. . . . . StartPosition: { +. . . . . . Offset: 15 +. . . . . . Line: 2 +. . . . . . Col: 0 +. . . . . } +. . . . . Properties: { +. . . . . . constructor: false +. . . . . . internalRole: bodyDeclarations +. . . . . } +. . . . . Children: { +. . . . . . 0: PrimitiveType { +. . . . . . . TOKEN "void" +. . . . . . . StartPosition: { +. . . . . . . . Offset: 15 +. . . . . . . . Line: 2 +. . . . . . . . Col: 0 +. . . . . . . } +. . . . . . . Properties: { +. . . . . . . . internalRole: returnType2 +. . . . . . . } +. . . . . . } +. . . . . . 1: SimpleName { +. . . . . . . Roles: SimpleIdentifier,FunctionDeclarationName +. . . . . . . TOKEN "code" +. . . . . . . StartPosition: { +. . . . . . . . Offset: 20 +. . . . . . . . Line: 2 +. . . . . . . . Col: 0 +. . . . . . . } +. . . . . . . Properties: { +. . . . . . . . internalRole: name +. . . . . . . } +. . . . . . } +. . . . . . 2: Block { +. . . . . . . Roles: FunctionDeclarationBody,BlockScope,Block +. . . . . . . Properties: { +. . . . . . . . internalRole: body +. . . . . . . } +. . . . . . . Children: { +. . . . . . . . 0: ReturnStatement { +. . . . . . . . . Roles: Return,Statement +. . . . . . . . . Properties: { +. . . . . . . . . . internalRole: statements +. . . . . . . . . } +. . . . . . . . } +. . . . . . . } +. . . . . . } +. . . . . } +. . . . } +. . . } +. . } +. } +} + diff --git a/tests/switch.uast b/tests/switch.uast index 5e70589..21f8e5f 100644 --- a/tests/switch.uast +++ b/tests/switch.uast @@ -94,7 +94,7 @@ CompilationUnit { . . . . . . . . . . . } . . . . . . . . . . . Children: { . . . . . . . . . . . . 0: NumberLiteral { -. . . . . . . . . . . . . Roles: NumberLiteral +. . . . . . . . . . . . . Roles: NumberLiteral,SwitchCaseCondition . . . . . . . . . . . . . StartPosition: { . . . . . . . . . . . . . . Offset: 69 . . . . . . . . . . . . . . Line: 4 @@ -108,7 +108,7 @@ CompilationUnit { . . . . . . . . . . . } . . . . . . . . . . } . . . . . . . . . . 2: ExpressionStatement { -. . . . . . . . . . . Roles: Statement +. . . . . . . . . . . Roles: SwitchCaseBody,Statement . . . . . . . . . . . Properties: { . . . . . . . . . . . . internalRole: statements . . . . . . . . . . . } @@ -186,7 +186,7 @@ CompilationUnit { . . . . . . . . . . . } . . . . . . . . . . . Children: { . . . . . . . . . . . . 0: NumberLiteral { -. . . . . . . . . . . . . Roles: NumberLiteral +. . . . . . . . . . . . . Roles: NumberLiteral,SwitchCaseCondition . . . . . . . . . . . . . StartPosition: { . . . . . . . . . . . . . . Offset: 121 . . . . . . . . . . . . . . Line: 5 @@ -200,7 +200,7 @@ CompilationUnit { . . . . . . . . . . . } . . . . . . . . . . } . . . . . . . . . . 4: ExpressionStatement { -. . . . . . . . . . . Roles: Statement +. . . . . . . . . . . Roles: SwitchCaseBody,Statement . . . . . . . . . . . Properties: { . . . . . . . . . . . . internalRole: statements . . . . . . . . . . . } @@ -278,7 +278,7 @@ CompilationUnit { . . . . . . . . . . . } . . . . . . . . . . . Children: { . . . . . . . . . . . . 0: NumberLiteral { -. . . . . . . . . . . . . Roles: NumberLiteral +. . . . . . . . . . . . . Roles: NumberLiteral,SwitchCaseCondition . . . . . . . . . . . . . StartPosition: { . . . . . . . . . . . . . . Offset: 173 . . . . . . . . . . . . . . Line: 6 @@ -292,7 +292,7 @@ CompilationUnit { . . . . . . . . . . . } . . . . . . . . . . } . . . . . . . . . . 6: ExpressionStatement { -. . . . . . . . . . . Roles: Statement +. . . . . . . . . . . Roles: SwitchCaseBody,Statement . . . . . . . . . . . Properties: { . . . . . . . . . . . . internalRole: statements . . . . . . . . . . . } @@ -364,7 +364,7 @@ CompilationUnit { . . . . . . . . . . . } . . . . . . . . . . } . . . . . . . . . . 7: ExpressionStatement { -. . . . . . . . . . . Roles: Statement +. . . . . . . . . . . Roles: SwitchCaseBody,Statement . . . . . . . . . . . Properties: { . . . . . . . . . . . . internalRole: statements . . . . . . . . . . . } @@ -436,27 +436,31 @@ CompilationUnit { . . . . . . . . . . . } . . . . . . . . . . } . . . . . . . . . . 8: BreakStatement { +. . . . . . . . . . . Roles: Break,Statement . . . . . . . . . . . Properties: { . . . . . . . . . . . . internalRole: statements . . . . . . . . . . . } . . . . . . . . . . } . . . . . . . . . . 9: BreakStatement { +. . . . . . . . . . . Roles: Break,Statement . . . . . . . . . . . Properties: { . . . . . . . . . . . . internalRole: statements . . . . . . . . . . . } . . . . . . . . . . } . . . . . . . . . . 10: BreakStatement { +. . . . . . . . . . . Roles: Break,Statement . . . . . . . . . . . Properties: { . . . . . . . . . . . . internalRole: statements . . . . . . . . . . . } . . . . . . . . . . } . . . . . . . . . . 11: SwitchCase { -. . . . . . . . . . . Roles: SwitchCase +. . . . . . . . . . . Roles: SwitchDefault . . . . . . . . . . . Properties: { . . . . . . . . . . . . internalRole: statements . . . . . . . . . . . } . . . . . . . . . . } . . . . . . . . . . 12: BreakStatement { +. . . . . . . . . . . Roles: Break,Statement . . . . . . . . . . . Properties: { . . . . . . . . . . . . internalRole: statements . . . . . . . . . . . } diff --git a/tests/throw.native b/tests/throw.native new file mode 100644 index 0000000..e724e78 --- /dev/null +++ b/tests/throw.native @@ -0,0 +1,54 @@ +{ + "status": "ok", + "errors": [], + "ast": { + "CompilationUnit": { + "internalClass": "CompilationUnit", + "types": [ + { + "bodyDeclarations": [ + { + "body": { + "internalClass": "Block", + "statements": [ + { + "expression": { + "internalClass": "NullLiteral" + }, + "internalClass": "ThrowStatement" + } + ] + }, + "constructor": "false", + "internalClass": "MethodDeclaration", + "line": 2, + "name": { + "identifier": "code", + "internalClass": "SimpleName", + "line": 2, + "startPosition": 20 + }, + "returnType2": { + "internalClass": "PrimitiveType", + "line": 2, + "primitiveTypeCode": "void", + "startPosition": 15 + }, + "startPosition": 15 + } + ], + "interface": "false", + "internalClass": "TypeDeclaration", + "line": 1, + "name": { + "identifier": "Code", + "internalClass": "SimpleName", + "line": 1, + "startPosition": 6 + }, + "startPosition": 0 + } + ] + } + } +} diff --git a/tests/throw.source b/tests/throw.source new file mode 100644 index 0000000..9a78080 --- /dev/null +++ b/tests/throw.source @@ -0,0 +1,5 @@ +class Code { + void code() { + throw null; + } +} diff --git a/tests/throw.uast b/tests/throw.uast new file mode 100644 index 0000000..dbdadd9 --- /dev/null +++ b/tests/throw.uast @@ -0,0 +1,95 @@ +Status: ok +Errors: +UAST: +CompilationUnit { +. Roles: File +. Children: { +. . 0: TypeDeclaration { +. . . Roles: VisibleFromPackage,TypeDeclaration +. . . StartPosition: { +. . . . Offset: 0 +. . . . Line: 1 +. . . . Col: 0 +. . . } +. . . Properties: { +. . . . interface: false +. . . . internalRole: types +. . . } +. . . Children: { +. . . . 0: SimpleName { +. . . . . Roles: SimpleIdentifier +. . . . . TOKEN "Code" +. . . . . StartPosition: { +. . . . . . Offset: 6 +. . . . . . Line: 1 +. . . . . . Col: 0 +. . . . . } +. . . . . Properties: { +. . . . . . internalRole: name +. . . . . } +. . . . } +. . . . 1: MethodDeclaration { +. . . . . Roles: VisibleFromPackage,FunctionDeclaration +. . . . . StartPosition: { +. . . . . . Offset: 15 +. . . . . . Line: 2 +. . . . . . Col: 0 +. . . . . } +. . . . . Properties: { +. . . . . . constructor: false +. . . . . . internalRole: bodyDeclarations +. . . . . } +. . . . . Children: { +. . . . . . 0: PrimitiveType { +. . . . . . . TOKEN "void" +. . . . . . . StartPosition: { +. . . . . . . . Offset: 15 +. . . . . . . . Line: 2 +. . . . . . . . Col: 0 +. . . . . . . } +. . . . . . . Properties: { +. . . . . . . . internalRole: returnType2 +. . . . . . . } +. . . . . . } +. . . . . . 1: SimpleName { +. . . . . . . Roles: SimpleIdentifier,FunctionDeclarationName +. . . . . . . TOKEN "code" +. . . . . . . StartPosition: { +. . . . . . . . Offset: 20 +. . . . . . . . Line: 2 +. . . . . . . . Col: 0 +. . . . . . . } +. . . . . . . Properties: { +. . . . . . . . internalRole: name +. . . . . . . } +. . . . . . } +. . . . . . 2: Block { +. . . . . . . Roles: FunctionDeclarationBody,BlockScope,Block +. . . . . . . Properties: { +. . . . . . . . internalRole: body +. . . . . . . } +. . . . . . . Children: { +. . . . . . . . 0: ThrowStatement { +. . . . . . . . . Roles: Throw,Statement +. . . . . . . . . Properties: { +. . . . . . . . . . internalRole: statements +. . . . . . . . . } +. . . . . . . . . Children: { +. . . . . . . . . . 0: NullLiteral { +. . . . . . . . . . . Roles: NullLiteral +. . . . . . . . . . . TOKEN "null" +. . . . . . . . . . . Properties: { +. . . . . . . . . . . . internalRole: expression +. . . . . . . . . . . } +. . . . . . . . . . } +. . . . . . . . . } +. . . . . . . . } +. . . . . . . } +. . . . . . } +. . . . . } +. . . . } +. . . } +. . } +. } +} + diff --git a/tests/try_catch.native b/tests/try_catch.native new file mode 100644 index 0000000..e8e717d --- /dev/null +++ b/tests/try_catch.native @@ -0,0 +1,83 @@ +{ + "status": "ok", + "errors": [], + "ast": { + "CompilationUnit": { + "internalClass": "CompilationUnit", + "types": [ + { + "bodyDeclarations": [ + { + "body": { + "internalClass": "Block", + "statements": [ + { + "body": { + "internalClass": "Block" + }, + "catchClauses": [ + { + "body": { + "internalClass": "Block" + }, + "exception": { + "internalClass": "SingleVariableDeclaration", + "line": 3, + "name": { + "identifier": "e", + "internalClass": "SimpleName", + "line": 3, + "startPosition": 57 + }, + "startPosition": 47, + "type": { + "internalClass": "SimpleType", + "name": { + "identifier": "Exception", + "internalClass": "SimpleName", + "line": 3, + "startPosition": 47 + } + }, + "varargs": "false" + }, + "internalClass": "CatchClause" + } + ], + "internalClass": "TryStatement" + } + ] + }, + "constructor": "false", + "internalClass": "MethodDeclaration", + "line": 2, + "name": { + "identifier": "code", + "internalClass": "SimpleName", + "line": 2, + "startPosition": 20 + }, + "returnType2": { + "internalClass": "PrimitiveType", + "line": 2, + "primitiveTypeCode": "void", + "startPosition": 15 + }, + "startPosition": 15 + } + ], + "interface": "false", + "internalClass": "TypeDeclaration", + "line": 1, + "name": { + "identifier": "Code", + "internalClass": "SimpleName", + "line": 1, + "startPosition": 6 + }, + "startPosition": 0 + } + ] + } + } +} diff --git a/tests/try_catch.source b/tests/try_catch.source new file mode 100644 index 0000000..38f7571 --- /dev/null +++ b/tests/try_catch.source @@ -0,0 +1,5 @@ +class Code { + void code() { + try {} catch (Exception e) {} + } +} diff --git a/tests/try_catch.uast b/tests/try_catch.uast new file mode 100644 index 0000000..b720e49 --- /dev/null +++ b/tests/try_catch.uast @@ -0,0 +1,152 @@ +Status: ok +Errors: +UAST: +CompilationUnit { +. Roles: File +. Children: { +. . 0: TypeDeclaration { +. . . Roles: VisibleFromPackage,TypeDeclaration +. . . StartPosition: { +. . . . Offset: 0 +. . . . Line: 1 +. . . . Col: 0 +. . . } +. . . Properties: { +. . . . interface: false +. . . . internalRole: types +. . . } +. . . Children: { +. . . . 0: SimpleName { +. . . . . Roles: SimpleIdentifier +. . . . . TOKEN "Code" +. . . . . StartPosition: { +. . . . . . Offset: 6 +. . . . . . Line: 1 +. . . . . . Col: 0 +. . . . . } +. . . . . Properties: { +. . . . . . internalRole: name +. . . . . } +. . . . } +. . . . 1: MethodDeclaration { +. . . . . Roles: VisibleFromPackage,FunctionDeclaration +. . . . . StartPosition: { +. . . . . . Offset: 15 +. . . . . . Line: 2 +. . . . . . Col: 0 +. . . . . } +. . . . . Properties: { +. . . . . . constructor: false +. . . . . . internalRole: bodyDeclarations +. . . . . } +. . . . . Children: { +. . . . . . 0: PrimitiveType { +. . . . . . . TOKEN "void" +. . . . . . . StartPosition: { +. . . . . . . . Offset: 15 +. . . . . . . . Line: 2 +. . . . . . . . Col: 0 +. . . . . . . } +. . . . . . . Properties: { +. . . . . . . . internalRole: returnType2 +. . . . . . . } +. . . . . . } +. . . . . . 1: SimpleName { +. . . . . . . Roles: SimpleIdentifier,FunctionDeclarationName +. . . . . . . TOKEN "code" +. . . . . . . StartPosition: { +. . . . . . . . Offset: 20 +. . . . . . . . Line: 2 +. . . . . . . . Col: 0 +. . . . . . . } +. . . . . . . Properties: { +. . . . . . . . internalRole: name +. . . . . . . } +. . . . . . } +. . . . . . 2: Block { +. . . . . . . Roles: FunctionDeclarationBody,BlockScope,Block +. . . . . . . Properties: { +. . . . . . . . internalRole: body +. . . . . . . } +. . . . . . . Children: { +. . . . . . . . 0: TryStatement { +. . . . . . . . . Roles: Try,Statement +. . . . . . . . . Properties: { +. . . . . . . . . . internalRole: statements +. . . . . . . . . } +. . . . . . . . . Children: { +. . . . . . . . . . 0: CatchClause { +. . . . . . . . . . . Roles: TryCatch +. . . . . . . . . . . Properties: { +. . . . . . . . . . . . internalRole: catchClauses +. . . . . . . . . . . } +. . . . . . . . . . . Children: { +. . . . . . . . . . . . 0: SingleVariableDeclaration { +. . . . . . . . . . . . . StartPosition: { +. . . . . . . . . . . . . . Offset: 47 +. . . . . . . . . . . . . . Line: 3 +. . . . . . . . . . . . . . Col: 0 +. . . . . . . . . . . . . } +. . . . . . . . . . . . . Properties: { +. . . . . . . . . . . . . . internalRole: exception +. . . . . . . . . . . . . . varargs: false +. . . . . . . . . . . . . } +. . . . . . . . . . . . . Children: { +. . . . . . . . . . . . . . 0: SimpleType { +. . . . . . . . . . . . . . . Properties: { +. . . . . . . . . . . . . . . . internalRole: type +. . . . . . . . . . . . . . . } +. . . . . . . . . . . . . . . Children: { +. . . . . . . . . . . . . . . . 0: SimpleName { +. . . . . . . . . . . . . . . . . Roles: SimpleIdentifier +. . . . . . . . . . . . . . . . . TOKEN "Exception" +. . . . . . . . . . . . . . . . . StartPosition: { +. . . . . . . . . . . . . . . . . . Offset: 47 +. . . . . . . . . . . . . . . . . . Line: 3 +. . . . . . . . . . . . . . . . . . Col: 0 +. . . . . . . . . . . . . . . . . } +. . . . . . . . . . . . . . . . . Properties: { +. . . . . . . . . . . . . . . . . . internalRole: name +. . . . . . . . . . . . . . . . . } +. . . . . . . . . . . . . . . . } +. . . . . . . . . . . . . . . } +. . . . . . . . . . . . . . } +. . . . . . . . . . . . . . 1: SimpleName { +. . . . . . . . . . . . . . . Roles: SimpleIdentifier +. . . . . . . . . . . . . . . TOKEN "e" +. . . . . . . . . . . . . . . StartPosition: { +. . . . . . . . . . . . . . . . Offset: 57 +. . . . . . . . . . . . . . . . Line: 3 +. . . . . . . . . . . . . . . . Col: 0 +. . . . . . . . . . . . . . . } +. . . . . . . . . . . . . . . Properties: { +. . . . . . . . . . . . . . . . internalRole: name +. . . . . . . . . . . . . . . } +. . . . . . . . . . . . . . } +. . . . . . . . . . . . . } +. . . . . . . . . . . . } +. . . . . . . . . . . . 1: Block { +. . . . . . . . . . . . . Roles: BlockScope,Block +. . . . . . . . . . . . . Properties: { +. . . . . . . . . . . . . . internalRole: body +. . . . . . . . . . . . . } +. . . . . . . . . . . . } +. . . . . . . . . . . } +. . . . . . . . . . } +. . . . . . . . . . 1: Block { +. . . . . . . . . . . Roles: TryBody,BlockScope,Block +. . . . . . . . . . . Properties: { +. . . . . . . . . . . . internalRole: body +. . . . . . . . . . . } +. . . . . . . . . . } +. . . . . . . . . } +. . . . . . . . } +. . . . . . . } +. . . . . . } +. . . . . } +. . . . } +. . . } +. . } +. } +} + diff --git a/tests/try_finally.native b/tests/try_finally.native new file mode 100644 index 0000000..e91e14c --- /dev/null +++ b/tests/try_finally.native @@ -0,0 +1,57 @@ +{ + "status": "ok", + "errors": [], + "ast": { + "CompilationUnit": { + "internalClass": "CompilationUnit", + "types": [ + { + "bodyDeclarations": [ + { + "body": { + "internalClass": "Block", + "statements": [ + { + "body": { + "internalClass": "Block" + }, + "finally": { + "internalClass": "Block" + }, + "internalClass": "TryStatement" + } + ] + }, + "constructor": "false", + "internalClass": "MethodDeclaration", + "line": 2, + "name": { + "identifier": "code", + "internalClass": "SimpleName", + "line": 2, + "startPosition": 20 + }, + "returnType2": { + "internalClass": "PrimitiveType", + "line": 2, + "primitiveTypeCode": "void", + "startPosition": 15 + }, + "startPosition": 15 + } + ], + "interface": "false", + "internalClass": "TypeDeclaration", + "line": 1, + "name": { + "identifier": "Code", + "internalClass": "SimpleName", + "line": 1, + "startPosition": 6 + }, + "startPosition": 0 + } + ] + } + } +} diff --git a/tests/try_finally.source b/tests/try_finally.source new file mode 100644 index 0000000..7b98b2f --- /dev/null +++ b/tests/try_finally.source @@ -0,0 +1,5 @@ +class Code { + void code() { + try {} finally {} + } +} diff --git a/tests/try_finally.uast b/tests/try_finally.uast new file mode 100644 index 0000000..95c18f7 --- /dev/null +++ b/tests/try_finally.uast @@ -0,0 +1,100 @@ +Status: ok +Errors: +UAST: +CompilationUnit { +. Roles: File +. Children: { +. . 0: TypeDeclaration { +. . . Roles: VisibleFromPackage,TypeDeclaration +. . . StartPosition: { +. . . . Offset: 0 +. . . . Line: 1 +. . . . Col: 0 +. . . } +. . . Properties: { +. . . . interface: false +. . . . internalRole: types +. . . } +. . . Children: { +. . . . 0: SimpleName { +. . . . . Roles: SimpleIdentifier +. . . . . TOKEN "Code" +. . . . . StartPosition: { +. . . . . . Offset: 6 +. . . . . . Line: 1 +. . . . . . Col: 0 +. . . . . } +. . . . . Properties: { +. . . . . . internalRole: name +. . . . . } +. . . . } +. . . . 1: MethodDeclaration { +. . . . . Roles: VisibleFromPackage,FunctionDeclaration +. . . . . StartPosition: { +. . . . . . Offset: 15 +. . . . . . Line: 2 +. . . . . . Col: 0 +. . . . . } +. . . . . Properties: { +. . . . . . constructor: false +. . . . . . internalRole: bodyDeclarations +. . . . . } +. . . . . Children: { +. . . . . . 0: PrimitiveType { +. . . . . . . TOKEN "void" +. . . . . . . StartPosition: { +. . . . . . . . Offset: 15 +. . . . . . . . Line: 2 +. . . . . . . . Col: 0 +. . . . . . . } +. . . . . . . Properties: { +. . . . . . . . internalRole: returnType2 +. . . . . . . } +. . . . . . } +. . . . . . 1: SimpleName { +. . . . . . . Roles: SimpleIdentifier,FunctionDeclarationName +. . . . . . . TOKEN "code" +. . . . . . . StartPosition: { +. . . . . . . . Offset: 20 +. . . . . . . . Line: 2 +. . . . . . . . Col: 0 +. . . . . . . } +. . . . . . . Properties: { +. . . . . . . . internalRole: name +. . . . . . . } +. . . . . . } +. . . . . . 2: Block { +. . . . . . . Roles: FunctionDeclarationBody,BlockScope,Block +. . . . . . . Properties: { +. . . . . . . . internalRole: body +. . . . . . . } +. . . . . . . Children: { +. . . . . . . . 0: TryStatement { +. . . . . . . . . Roles: Try,Statement +. . . . . . . . . Properties: { +. . . . . . . . . . internalRole: statements +. . . . . . . . . } +. . . . . . . . . Children: { +. . . . . . . . . . 0: Block { +. . . . . . . . . . . Roles: TryBody,BlockScope,Block +. . . . . . . . . . . Properties: { +. . . . . . . . . . . . internalRole: body +. . . . . . . . . . . } +. . . . . . . . . . } +. . . . . . . . . . 1: Block { +. . . . . . . . . . . Roles: TryFinally,BlockScope,Block +. . . . . . . . . . . Properties: { +. . . . . . . . . . . . internalRole: finally +. . . . . . . . . . . } +. . . . . . . . . . } +. . . . . . . . . } +. . . . . . . . } +. . . . . . . } +. . . . . . } +. . . . . } +. . . . } +. . . } +. . } +. } +} +