Skip to content
This repository was archived by the owner on Mar 8, 2020. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions ANNOTATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
| /self::\*\[@InternalType='CompilationUnit'\]//\*\[@InternalType='DoStatement'\] | DoWhile |
| /self::\*\[@InternalType='CompilationUnit'\]//\*\[@InternalType='DoStatement'\]/\*\[@internalRole\]\[@internalRole='expression'\] | DoWhileCondition |
| /self::\*\[@InternalType='CompilationUnit'\]//\*\[@InternalType='DoStatement'\]/\*\[@internalRole\]\[@internalRole='body'\] | DoWhileBody |
| /self::\*\[@InternalType='CompilationUnit'\]//\*\[@InternalType='InfixExpression'\] | BinaryExpression |
| /self::\*\[@InternalType='CompilationUnit'\]//\*\[@InternalType='InfixExpression'\]/self::\*\[@operator\]\[@operator='\+'\] | OpAdd |
| /self::\*\[@InternalType='CompilationUnit'\]//\*\[@InternalType='InfixExpression'\]/self::\*\[@operator\]\[@operator='\-'\] | OpSubstract |
| /self::\*\[@InternalType='CompilationUnit'\]//\*\[@InternalType='InfixExpression'\]/self::\*\[@operator\]\[@operator='\*'\] | OpMultiply |
Expand All @@ -65,6 +66,8 @@
| /self::\*\[@InternalType='CompilationUnit'\]//\*\[@InternalType='InfixExpression'\]/self::\*\[@operator\]\[@operator='&&'\] | OpBooleanAnd |
| /self::\*\[@InternalType='CompilationUnit'\]//\*\[@InternalType='InfixExpression'\]/self::\*\[@operator\]\[@operator='\|\|'\] | OpBooleanOr |
| /self::\*\[@InternalType='CompilationUnit'\]//\*\[@InternalType='InfixExpression'\]/self::\*\[@operator\]\[@operator='^'\] | OpBooleanXor |
| /self::\*\[@InternalType='CompilationUnit'\]//\*\[@InternalType='InfixExpression'\]/\*\[@internalRole\]\[@internalRole='leftOperand'\] | BinaryExpressionLeft |
| /self::\*\[@InternalType='CompilationUnit'\]//\*\[@InternalType='InfixExpression'\]/\*\[@internalRole\]\[@internalRole='rightOperand'\] | BinaryExpressionRight |
| /self::\*\[@InternalType='CompilationUnit'\]//\*\[@InternalType='PostfixExpression'\]/self::\*\[@operator\]\[@operator='\+\+'\] | OpPostIncrement |
| /self::\*\[@InternalType='CompilationUnit'\]//\*\[@InternalType='PostfixExpression'\]/self::\*\[@operator\]\[@operator='\-\-'\] | OpPostDecrement |
| /self::\*\[@InternalType='CompilationUnit'\]//\*\[@InternalType='PrefixExpression'\]/self::\*\[@operator\]\[@operator='\+\+'\] | OpPreIncrement |
Expand Down
5 changes: 4 additions & 1 deletion driver/normalizer/annotation.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ var AnnotationRules = On(Any).Self(
On(jdt.PropertyBody).Roles(DoWhileBody),
),

On(jdt.InfixExpression).Self(
On(jdt.InfixExpression).Roles(BinaryExpression, BinaryExpressionOp).Self(
On(HasProperty("operator", "+")).Roles(OpAdd),
On(HasProperty("operator", "-")).Roles(OpSubstract),
On(HasProperty("operator", "*")).Roles(OpMultiply),
Expand All @@ -123,6 +123,9 @@ var AnnotationRules = On(Any).Self(
On(HasProperty("operator", "&&")).Roles(OpBooleanAnd),
On(HasProperty("operator", "||")).Roles(OpBooleanOr),
On(HasProperty("operator", "^")).Roles(OpBooleanXor),
).Children(
On(jdt.PropertyLeftOperand).Roles(BinaryExpressionLeft),
On(jdt.PropertyRightOperand).Roles(BinaryExpressionRight),
),

On(jdt.PostfixExpression).Self(
Expand Down
86 changes: 86 additions & 0 deletions tests/binary_expression.native
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
{
"status": "ok",
"errors": [],
"ast": {
"CompilationUnit": {
"internalClass": "CompilationUnit",
"types": [
{
"bodyDeclarations": [
{
"body": {
"internalClass": "Block",
"statements": [
{
"fragments": [
{
"initializer": {
"internalClass": "InfixExpression",
"leftOperand": {
"internalClass": "NumberLiteral",
"line": 3,
"startPosition": 41,
"token": "3"
},
"line": 3,
"operator": "+",
"rightOperand": {
"internalClass": "NumberLiteral",
"line": 3,
"startPosition": 45,
"token": "4"
},
"startPosition": 41
},
"internalClass": "VariableDeclarationFragment",
"name": {
"identifier": "a",
"internalClass": "SimpleName",
"line": 3,
"startPosition": 37
}
}
],
"internalClass": "VariableDeclarationStatement",
"type": {
"internalClass": "PrimitiveType",
"line": 3,
"primitiveTypeCode": "int",
"startPosition": 33
}
}
]
},
"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
}
]
}
}
}
5 changes: 5 additions & 0 deletions tests/binary_expression.source
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class Code {
void code() {
int a = 3 + 4;
}
}
155 changes: 155 additions & 0 deletions tests/binary_expression.uast
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
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 "int"
. . . . . . . . . . . StartPosition: {
. . . . . . . . . . . . Offset: 33
. . . . . . . . . . . . Line: 3
. . . . . . . . . . . . Col: 0
. . . . . . . . . . . }
. . . . . . . . . . . Properties: {
. . . . . . . . . . . . internalRole: type
. . . . . . . . . . . }
. . . . . . . . . . }
. . . . . . . . . . 1: VariableDeclarationFragment {
. . . . . . . . . . . Properties: {
. . . . . . . . . . . . internalRole: fragments
. . . . . . . . . . . }
. . . . . . . . . . . Children: {
. . . . . . . . . . . . 0: SimpleName {
. . . . . . . . . . . . . Roles: SimpleIdentifier
. . . . . . . . . . . . . TOKEN "a"
. . . . . . . . . . . . . StartPosition: {
. . . . . . . . . . . . . . Offset: 37
. . . . . . . . . . . . . . Line: 3
. . . . . . . . . . . . . . Col: 0
. . . . . . . . . . . . . }
. . . . . . . . . . . . . Properties: {
. . . . . . . . . . . . . . internalRole: name
. . . . . . . . . . . . . }
. . . . . . . . . . . . }
. . . . . . . . . . . . 1: InfixExpression {
. . . . . . . . . . . . . Roles: BinaryExpression,BinaryExpressionOp,OpAdd
. . . . . . . . . . . . . StartPosition: {
. . . . . . . . . . . . . . Offset: 41
. . . . . . . . . . . . . . Line: 3
. . . . . . . . . . . . . . Col: 0
. . . . . . . . . . . . . }
. . . . . . . . . . . . . Properties: {
. . . . . . . . . . . . . . internalRole: initializer
. . . . . . . . . . . . . . operator: +
. . . . . . . . . . . . . }
. . . . . . . . . . . . . Children: {
. . . . . . . . . . . . . . 0: NumberLiteral {
. . . . . . . . . . . . . . . Roles: NumberLiteral,BinaryExpressionLeft
. . . . . . . . . . . . . . . StartPosition: {
. . . . . . . . . . . . . . . . Offset: 41
. . . . . . . . . . . . . . . . Line: 3
. . . . . . . . . . . . . . . . Col: 0
. . . . . . . . . . . . . . . }
. . . . . . . . . . . . . . . Properties: {
. . . . . . . . . . . . . . . . internalRole: leftOperand
. . . . . . . . . . . . . . . . token: 3
. . . . . . . . . . . . . . . }
. . . . . . . . . . . . . . }
. . . . . . . . . . . . . . 1: NumberLiteral {
. . . . . . . . . . . . . . . Roles: NumberLiteral,BinaryExpressionRight
. . . . . . . . . . . . . . . StartPosition: {
. . . . . . . . . . . . . . . . Offset: 45
. . . . . . . . . . . . . . . . Line: 3
. . . . . . . . . . . . . . . . Col: 0
. . . . . . . . . . . . . . . }
. . . . . . . . . . . . . . . Properties: {
. . . . . . . . . . . . . . . . internalRole: rightOperand
. . . . . . . . . . . . . . . . token: 4
. . . . . . . . . . . . . . . }
. . . . . . . . . . . . . . }
. . . . . . . . . . . . . }
. . . . . . . . . . . . }
. . . . . . . . . . . }
. . . . . . . . . . }
. . . . . . . . . }
. . . . . . . . }
. . . . . . . }
. . . . . . }
. . . . . }
. . . . }
. . . }
. . }
. }
}

12 changes: 6 additions & 6 deletions tests/boolean_operators.uast
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ CompilationUnit {
. . . . . . . . . . . . . }
. . . . . . . . . . . . }
. . . . . . . . . . . . 1: InfixExpression {
. . . . . . . . . . . . . Roles: OpBooleanAnd
. . . . . . . . . . . . . Roles: BinaryExpression,BinaryExpressionOp,OpBooleanAnd
. . . . . . . . . . . . . StartPosition: {
. . . . . . . . . . . . . . Offset: 45
. . . . . . . . . . . . . . Line: 3
Expand All @@ -115,7 +115,7 @@ CompilationUnit {
. . . . . . . . . . . . . }
. . . . . . . . . . . . . Children: {
. . . . . . . . . . . . . . 0: BooleanLiteral {
. . . . . . . . . . . . . . . Roles: BooleanLiteral
. . . . . . . . . . . . . . . Roles: BooleanLiteral,BinaryExpressionLeft
. . . . . . . . . . . . . . . StartPosition: {
. . . . . . . . . . . . . . . . Offset: 45
. . . . . . . . . . . . . . . . Line: 3
Expand All @@ -127,7 +127,7 @@ CompilationUnit {
. . . . . . . . . . . . . . . }
. . . . . . . . . . . . . . }
. . . . . . . . . . . . . . 1: BooleanLiteral {
. . . . . . . . . . . . . . . Roles: BooleanLiteral
. . . . . . . . . . . . . . . Roles: BooleanLiteral,BinaryExpressionRight
. . . . . . . . . . . . . . . StartPosition: {
. . . . . . . . . . . . . . . . Offset: 53
. . . . . . . . . . . . . . . . Line: 3
Expand Down Expand Up @@ -175,7 +175,7 @@ CompilationUnit {
. . . . . . . . . . . . . }
. . . . . . . . . . . . }
. . . . . . . . . . . . 1: InfixExpression {
. . . . . . . . . . . . . Roles: OpBooleanOr,AssignmentValue
. . . . . . . . . . . . . Roles: BinaryExpression,BinaryExpressionOp,OpBooleanOr,AssignmentValue
. . . . . . . . . . . . . StartPosition: {
. . . . . . . . . . . . . . Offset: 68
. . . . . . . . . . . . . . Line: 4
Expand All @@ -187,7 +187,7 @@ CompilationUnit {
. . . . . . . . . . . . . }
. . . . . . . . . . . . . Children: {
. . . . . . . . . . . . . . 0: SimpleName {
. . . . . . . . . . . . . . . Roles: SimpleIdentifier
. . . . . . . . . . . . . . . Roles: SimpleIdentifier,BinaryExpressionLeft
. . . . . . . . . . . . . . . TOKEN "i"
. . . . . . . . . . . . . . . StartPosition: {
. . . . . . . . . . . . . . . . Offset: 68
Expand All @@ -199,7 +199,7 @@ CompilationUnit {
. . . . . . . . . . . . . . . }
. . . . . . . . . . . . . . }
. . . . . . . . . . . . . . 1: BooleanLiteral {
. . . . . . . . . . . . . . . Roles: BooleanLiteral
. . . . . . . . . . . . . . . Roles: BooleanLiteral,BinaryExpressionRight
. . . . . . . . . . . . . . . StartPosition: {
. . . . . . . . . . . . . . . . Offset: 73
. . . . . . . . . . . . . . . . Line: 4
Expand Down
6 changes: 3 additions & 3 deletions tests/do_while.uast
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ CompilationUnit {
. . . . . . . . . . . }
. . . . . . . . . . }
. . . . . . . . . . 1: InfixExpression {
. . . . . . . . . . . Roles: DoWhileCondition
. . . . . . . . . . . Roles: DoWhileCondition,BinaryExpression,BinaryExpressionOp
. . . . . . . . . . . StartPosition: {
. . . . . . . . . . . . Offset: 120
. . . . . . . . . . . . Line: 7
Expand All @@ -251,7 +251,7 @@ CompilationUnit {
. . . . . . . . . . . }
. . . . . . . . . . . Children: {
. . . . . . . . . . . . 0: SimpleName {
. . . . . . . . . . . . . Roles: SimpleIdentifier
. . . . . . . . . . . . . Roles: SimpleIdentifier,BinaryExpressionLeft
. . . . . . . . . . . . . TOKEN "i"
. . . . . . . . . . . . . StartPosition: {
. . . . . . . . . . . . . . Offset: 120
Expand All @@ -263,7 +263,7 @@ CompilationUnit {
. . . . . . . . . . . . . }
. . . . . . . . . . . . }
. . . . . . . . . . . . 1: NumberLiteral {
. . . . . . . . . . . . . Roles: NumberLiteral
. . . . . . . . . . . . . Roles: NumberLiteral,BinaryExpressionRight
. . . . . . . . . . . . . StartPosition: {
. . . . . . . . . . . . . . Offset: 124
. . . . . . . . . . . . . . Line: 7
Expand Down
6 changes: 3 additions & 3 deletions tests/for.uast
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ CompilationUnit {
. . . . . . . . . . . }
. . . . . . . . . . }
. . . . . . . . . . 1: InfixExpression {
. . . . . . . . . . . Roles: ForExpression
. . . . . . . . . . . Roles: ForExpression,BinaryExpression,BinaryExpressionOp
. . . . . . . . . . . StartPosition: {
. . . . . . . . . . . . Offset: 49
. . . . . . . . . . . . Line: 3
Expand All @@ -138,7 +138,7 @@ CompilationUnit {
. . . . . . . . . . . }
. . . . . . . . . . . Children: {
. . . . . . . . . . . . 0: SimpleName {
. . . . . . . . . . . . . Roles: SimpleIdentifier
. . . . . . . . . . . . . Roles: SimpleIdentifier,BinaryExpressionLeft
. . . . . . . . . . . . . TOKEN "i"
. . . . . . . . . . . . . StartPosition: {
. . . . . . . . . . . . . . Offset: 49
Expand All @@ -150,7 +150,7 @@ CompilationUnit {
. . . . . . . . . . . . . }
. . . . . . . . . . . . }
. . . . . . . . . . . . 1: NumberLiteral {
. . . . . . . . . . . . . Roles: NumberLiteral
. . . . . . . . . . . . . Roles: NumberLiteral,BinaryExpressionRight
. . . . . . . . . . . . . StartPosition: {
. . . . . . . . . . . . . . Offset: 53
. . . . . . . . . . . . . . Line: 3
Expand Down
Loading