Skip to content
Jean-Noël Rouvignac edited this page Sep 20, 2015 · 1 revision

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 the extendedOperands 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 the ASTNode.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 NOT PrefixExpresion MUST be enclosed in a ParenthezisedExpression 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).