Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Xtend2 - try/catch resulting in invalid xblockexpression
Xtend2 - try/catch resulting in invalid xblockexpression [message #670863] Mon, 16 May 2011 00:43 Go to next message
Edwin Park is currently offline Edwin ParkFriend
Messages: 124
Registered: July 2009
Senior Member
Hi,

I found the following issue in the latest Xtend2 (2.0.0.v201105141032). If I have an xtend function with multiple statements in a try block, it will generate an invalid _xblockexpression:

Xtend class:
package xtend.tutorial

import java.io.*

class Test {

	def containsExpression(File f) {
		try {
			val reader = new BufferedReader(new FileReader(f))
			
			var line = reader.readLine()
			while (line != null) {
				if (line.contains("function"))
					return true;
				line = reader.readLine()
			}
			
			reader.close()
		} catch (IOException ex) {
			ex.printStackTrace
		}

		return false
	}
	
}


Generated Test.java file:
package xtend.tutorial;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import org.eclipse.xtext.xbase.lib.ObjectExtensions;

@SuppressWarnings("all")
public class Test {
  
  public boolean containsExpression(final File f) {
    {
      try {
        void _xblockexpression = null;
        {
          FileReader _fileReader = new FileReader(f);
          BufferedReader _bufferedReader = new BufferedReader(_fileReader);
          final BufferedReader reader = _bufferedReader;
          String _readLine = reader.readLine();
          String line = _readLine;
          boolean _operator_notEquals = ObjectExtensions.operator_notEquals(line, null);
          Boolean _xwhileexpression = _operator_notEquals;
          while (_xwhileexpression) {
            {
              boolean _contains = line.contains("function");
              if (_contains) {
                return true;
              }
              String _readLine_1 = reader.readLine();
              line = _readLine_1;
            }
            boolean _operator_notEquals_1 = ObjectExtensions.operator_notEquals(line, null);
            _xwhileexpression = _operator_notEquals_1;
          }
          reader.close();
          _xblockexpression = (null);
        }
      } catch (IOException ex) { 
        ex.printStackTrace();
      }
      return false;
    }
  }
}


Note that the _xblockexpression is generated with a type of void.

Regards,
Edwin
Re: Xtend2 - try/catch resulting in invalid xblockexpression [message #670912 is a reply to message #670863] Mon, 16 May 2011 07:31 Go to previous message
Sebastian Zarnekow is currently offline Sebastian ZarnekowFriend
Messages: 3118
Registered: July 2009
Senior Member
Hi Edwin,

you may want to follow this ticket:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=345371

Regards,
Sebastian
--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com


Am 16.05.11 02:43, schrieb Edwin Park:
> Hi,
>
> I found the following issue in the latest Xtend2
> (2.0.0.v201105141032). If I have an xtend function with
> multiple statements in a try block, it will generate an
> invalid _xblockexpression:
>
> Xtend class:
>
> package xtend.tutorial
>
> import java.io.*
>
> class Test {
>
> def containsExpression(File f) {
> try {
> val reader = new BufferedReader(new FileReader(f))
>
> var line = reader.readLine()
> while (line != null) {
> if (line.contains("function"))
> return true;
> line = reader.readLine()
> }
>
> reader.close()
> } catch (IOException ex) {
> ex.printStackTrace
> }
>
> return false
> }
>
> }
>
>
> Generated Test.java file:
>
> package xtend.tutorial;
>
> import java.io.BufferedReader;
> import java.io.File;
> import java.io.FileReader;
> import java.io.IOException;
> import org.eclipse.xtext.xbase.lib.ObjectExtensions;
>
> @SuppressWarnings("all")
> public class Test {
>
> public boolean containsExpression(final File f) {
> {
> try {
> void _xblockexpression = null;
> {
> FileReader _fileReader = new FileReader(f);
> BufferedReader _bufferedReader = new
> BufferedReader(_fileReader);
> final BufferedReader reader = _bufferedReader;
> String _readLine = reader.readLine();
> String line = _readLine;
> boolean _operator_notEquals =
> ObjectExtensions.operator_notEquals(line, null);
> Boolean _xwhileexpression = _operator_notEquals;
> while (_xwhileexpression) {
> {
> boolean _contains =
> line.contains("function");
> if (_contains) {
> return true;
> }
> String _readLine_1 = reader.readLine();
> line = _readLine_1;
> }
> boolean _operator_notEquals_1 =
> ObjectExtensions.operator_notEquals(line, null);
> _xwhileexpression = _operator_notEquals_1;
> }
> reader.close();
> _xblockexpression = (null);
> }
> } catch (IOException ex) { ex.printStackTrace();
> }
> return false;
> }
> }
> }
>
>
> Note that the _xblockexpression is generated with a type of
> void.
>
> Regards,
> Edwin
>
Previous Topic:Intermittent IReferenceFinder injection
Next Topic:Cross-linking to alternative representations (not always having the 'name' attribute)?
Goto Forum:
  


Current Time: Thu Apr 25 00:44:44 GMT 2024

Powered by FUDForum. Page generated in 0.02832 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top