Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 342359 - [Xtend] evaluation of complex boolean expressions in generated Java code
Summary: [Xtend] evaluation of complex boolean expressions in generated Java code
Status: CLOSED DUPLICATE of bug 342424
Alias: None
Product: TMF
Classification: Modeling
Component: Xtext (show other bugs)
Version: 2.0.0   Edit
Hardware: All All
: P3 major (vote)
Target Milestone: M7   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-04-09 21:12 EDT by Maxim Frolov CLA
Modified: 2011-04-11 08:26 EDT (History)
3 users (show)

See Also:
sebastian.zarnekow: indigo+


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Maxim Frolov CLA 2011-04-09 21:12:32 EDT
Both in Java and many other programming languages the boolean expressions are evaluated 'lazily'. If, for example, in expression '(a && b)', a is false, then b is not evaluated. This lets write less code in many cases. Compare for example: 
if (file != null) {
   if (file.exist)
      return true;
}
with
return (file != null && file.exist)


In Xtend2 all parts of complex boolean expressions are evaluated. 

The following Xtend function:
boolean fileExists (File file) {
 file != null && file.exists
}

generates the following Java code:
public boolean fileExists(final File file) {
    final File typeConverted_file = (File)file;
    boolean _operator_notEquals = ObjectExtensions.operator_notEquals(typeConverted_file, null);
    boolean _exists = file.exists();
    boolean _operator_and = BooleanExtensions.operator_and(_operator_notEquals, _exists);
    return _operator_and;
  }

At runtime a NPE is thrown if the input argument file is null.
Comment 1 Sven Efftinge CLA 2011-04-11 08:26:00 EDT

*** This bug has been marked as a duplicate of bug 342424 ***