-
Notifications
You must be signed in to change notification settings - Fork 38
JDT Gotchas
Writing code transformations with Eclipse Java Development Tools is full of gotchas.
Here are the things to double check:
-
Assignment
: always check the operator type (getOpertor()
method) -
IfStatement
: always check whether the else statement is null (getElseStatement()
method) -
InfixExpression
: always check whether there are extendedOperands (extendedOperands()
method)-
JDT sometimes represent chained infix expressions (additions, boolean conditions, etc) using the same operator into a single
InfixExpression
node and stores the additional operands into theextendedOperands
attribute.
-
-
MethodDeclaration
: always check the body is not null (getBody()
method) -
IBinding
: always verify resolved bindings are not null-
Despite calling
ASTParser.setResolveBindings(true);
, using one of theASTNode.resolve*()
methods can return null at any time, so be prepared to handle nulls.
-
-
JDT does not check the validity of programmer built ASTs
-
For example, adding an
InfixExpression
inside a NOTPrefixExpresion
MUST be enclosed in aParenthezisedExpression
by the programmer, otherwise the resulting code will not be what was expected.-
For example, adding
a && b
to a not expression will result in!a && b
instead of the expected!(a && b)
.
-
-