Search code examples
javaeclipseeclipse-pluginternary-operatoreclipse-jdt

Eclipse plugin: How to find/parse ternary operator?


I already have several visitors implemented, e.g. for Assignments, ForStatements etc. But as it seems there is no convenient way to find ternary operators ( ? : ) in my Java projects?

So is there any other way to find ternary expressions in my project?


Solution

  • I assume you are using AST, since you are refering to "visitors". In that case you can use a vistor like this:

    new ASTVisitor() {
        @Override
        public boolean visit(ConditionalExpression node) {
            ...
            return false;
        }
    }
    

    A good tool to use inside of eclipse is the ASTView, which will show you the AST of any selected code in an opened editor. You can install the ASTView from this update site: http://www.eclipse.org/jdt/ui/update-site