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
24 changes: 21 additions & 3 deletions driver/normalizer/annotation.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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),
),
)
146 changes: 146 additions & 0 deletions tests/boolean_operators.native
Original file line number Diff line number Diff line change
@@ -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
}
]
}
}
}
7 changes: 7 additions & 0 deletions tests/boolean_operators.source
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class Code {
void code() {
boolean i = true && false;
i = i || false;
i = !i;
}
}
Loading