/*
 * $Id$
 *
 * SARL is an general-purpose agent programming language.
 * More details on http://www.sarl.io
 *
 * Copyright (C) 2014-2026 SARL.io, the original authors and main authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package io.sarl.lang.tests.general.compilation.general.castoverriding;

import static io.sarl.tests.api.tools.TestEObjects.file;
import static io.sarl.tests.api.tools.TestUtils.multilineString;
import static io.sarl.tests.api.tools.TestValidator.validate;

import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.xtext.common.types.TypesPackage;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;

import io.sarl.lang.core.SARLVersion;
import io.sarl.lang.sarl.SarlPackage;
import io.sarl.lang.sarl.SarlScript;
import io.sarl.lang.tests.api.AbstractSarlTest;
import io.sarl.lang.tests.api.globalcompilation.GlobalCompilationSuite;
import io.sarl.lang.tests.api.globalcompilation.GlobalCompilationTestContribution;
import io.sarl.lang.tests.api.globalcompilation.ResourceSetGlobalCompilationContext;
import io.sarl.lang.validation.IssueCodes;
import io.sarl.tests.api.tools.TestValidator.Validator;


/**
 * @author $Author: sgalland$
 * @version $Name$ $Revision$ $Date$
 * @mavengroupid $GroupId$
 * @mavenartifactid $ArtifactId$
 * @since 0.9
 */
@GlobalCompilationSuite
@SuppressWarnings("all")
@DisplayName("Compilation: cast operator without inheritance")
@Tag("core")
@Tag("compileToJava")
public class A0NoIngerithanceTest extends AbstractSarlTest {

	private static final String NO_FUNCTION_SARL = multilineString(
			"class A0 {",
			"}",
			"class A1 {",
			"}",
			"class A2 {",
			"  def fct(x : A1) : A0 {",
			"    var y = fct(null)",
			"    return x as A0",
			"  }",
			"}"
			);

	@Test
	public void parseNoFunction() throws Exception {
		SarlScript mas = file(getParseHelper(), NO_FUNCTION_SARL);
		Validator val = validate(getValidationHelper(), getInjector(), mas);
		val
			.assertError(
				TypesPackage.eINSTANCE.getJvmParameterizedTypeReference(),
				org.eclipse.xtext.xbase.validation.IssueCodes.INVALID_CAST,
				"Cannot cast from A1 to A0")
			.assertNoWarnings(
					TypesPackage.eINSTANCE.getJvmParameterizedTypeReference(),
					org.eclipse.xtext.xbase.validation.IssueCodes.OBSOLETE_CAST)
			.assertNoWarnings(
					TypesPackage.eINSTANCE.getJvmParameterizedTypeReference(),
					IssueCodes.POTENTIAL_INEFFICIENT_VALUE_CONVERSION);
	}

	private static final String INTEGER_SARL = multilineString(
			"class A0 {",
			"}",
			"class A1 {",
			"}",
			"class A2 {",
			"  def fct(x : A1) : A0 {",
			"    var y = fct(null)",
			"    return 3 as A0",
			"  }",
			"}"
			);

	@Test
	public void parseInteger() throws Exception {
		SarlScript mas = file(getParseHelper(), INTEGER_SARL);
		Validator val = validate(getValidationHelper(), getInjector(), mas);
		val
			.assertError(
				TypesPackage.eINSTANCE.getJvmParameterizedTypeReference(),
				org.eclipse.xtext.xbase.validation.IssueCodes.INVALID_CAST,
				"Cannot cast from int or Integer to A0")
			.assertNoWarnings(
					TypesPackage.eINSTANCE.getJvmParameterizedTypeReference(),
					org.eclipse.xtext.xbase.validation.IssueCodes.OBSOLETE_CAST)
			.assertNoWarnings(
					TypesPackage.eINSTANCE.getJvmParameterizedTypeReference(),
					IssueCodes.POTENTIAL_INEFFICIENT_VALUE_CONVERSION);
	}

	private static final String BOOLEAN_SARL = multilineString(
			"class A0 {",
			"}",
			"class A1 {",
			"}",
			"class A2 {",
			"  def fct(x : A1) : A0 {",
			"    var y = fct(null)",
			"    return false as A0",
			"  }",
			"}"
			);

	@Test
	public void parseBoolean() throws Exception {
		SarlScript mas = file(getParseHelper(), BOOLEAN_SARL);
		Validator val = validate(getValidationHelper(), getInjector(), mas);
		val
			.assertError(
				TypesPackage.eINSTANCE.getJvmParameterizedTypeReference(),
				org.eclipse.xtext.xbase.validation.IssueCodes.INVALID_CAST,
				"Cannot cast from boolean or Boolean to A0")
			.assertNoWarnings(
					TypesPackage.eINSTANCE.getJvmParameterizedTypeReference(),
					org.eclipse.xtext.xbase.validation.IssueCodes.OBSOLETE_CAST)
			.assertNoWarnings(
					TypesPackage.eINSTANCE.getJvmParameterizedTypeReference(),
					IssueCodes.POTENTIAL_INEFFICIENT_VALUE_CONVERSION);
	}

	private static final String STRING_SARL = multilineString(
			"class A0 {",
			"}",
			"class A1 {",
			"}",
			"class A2 {",
			"  def fct(x : A1) : A0 {",
			"    var y = fct(null)",
			"    return \"hello\" as A0",
			"  }",
			"}"
			);

	@Test
	public void parseString() throws Exception {
		SarlScript mas = file(getParseHelper(), STRING_SARL);
		Validator val = validate(getValidationHelper(), getInjector(), mas);
		val
			.assertError(
				TypesPackage.eINSTANCE.getJvmParameterizedTypeReference(),
				org.eclipse.xtext.xbase.validation.IssueCodes.INVALID_CAST,
				"Cannot cast from String to A0")
			.assertNoWarnings(
					TypesPackage.eINSTANCE.getJvmParameterizedTypeReference(),
					org.eclipse.xtext.xbase.validation.IssueCodes.OBSOLETE_CAST)
			.assertNoWarnings(
					TypesPackage.eINSTANCE.getJvmParameterizedTypeReference(),
					IssueCodes.POTENTIAL_INEFFICIENT_VALUE_CONVERSION);
	}

	private static final String LOCAL_INTEGER_SARL = multilineString(
			"class A0 {",
			"}",
			"class A2 {",
			"  def fct : A0 {",
			"    var y = fct",
			"    return 3 as A0",
			"  }",
			"  def toA0(x : int) : A0 {",
			"    null",
			"  }",
			"}"
			);

	private static final String LOCAL_INTEGER_JAVA = multilineString(
			"import io.sarl.lang.core.annotation.SarlElementType;",
			"import io.sarl.lang.core.annotation.SarlSpecification;",
			"import io.sarl.lang.core.annotation.SyntheticMember;",
			"import org.eclipse.xtext.xbase.lib.Pure;",
			"import org.eclipse.xtext.xbase.lib.XbaseGenerated;",
			"",
			"@SarlSpecification(\"" + SARLVersion.SPECIFICATION_RELEASE_VERSION_STRING + "\")",
			"@SarlElementType(" + SarlPackage.SARL_CLASS + ")",
			"@XbaseGenerated",
			"@SuppressWarnings(\"all\")",
			"public class A2 {",
			"  @Pure",
			"  public A0 fct() {",
			"    A0 y = this.fct();",
			"    return this.toA0(3);",
			"  }",
			"  ",
			"  @Pure",
			"  public A0 toA0(final int x) {",
			"    return null;",
			"  }",
			"  ",
			"  @SyntheticMember",
			"  public A2() {",
			"    super();",
			"  }",
			"}",
			"");

	@Test
	public void parseLocalInteger() throws Exception {
		SarlScript mas = file(getParseHelper(), LOCAL_INTEGER_SARL);
		Validator val = validate(getValidationHelper(), getInjector(), mas);
		val
			.assertNoErrors(
				TypesPackage.eINSTANCE.getJvmParameterizedTypeReference(),
				org.eclipse.xtext.xbase.validation.IssueCodes.INVALID_CAST)
			.assertNoWarnings(
				TypesPackage.eINSTANCE.getJvmParameterizedTypeReference(),
				org.eclipse.xtext.xbase.validation.IssueCodes.OBSOLETE_CAST)
			.assertWarning(
				TypesPackage.eINSTANCE.getJvmParameterizedTypeReference(),
				IssueCodes.POTENTIAL_INEFFICIENT_VALUE_CONVERSION,
				"toA0");
	}

	@GlobalCompilationTestContribution
	public void compileLocalInteger(ResourceSetGlobalCompilationContext ctx) throws Exception {
		ctx.compileTo(LOCAL_INTEGER_SARL, LOCAL_INTEGER_JAVA);
	}

	private static final String LOCAL_BOOLEAN_SARL = multilineString(
			"class A0 {",
			"}",
			"class A1 {",
			"}",
			"class A2 {",
			"  def fct(x : A1) : A0 {",
			"    var y = fct(null)",
			"    return false as A0",
			"  }",
			"  def toA0(x : boolean) : A0 {",
			"    null",
			"  }",
			"}"
			);

	private static final String LOCAL_BOOLEAN_JAVA = multilineString(
			"import io.sarl.lang.core.annotation.SarlElementType;",
			"import io.sarl.lang.core.annotation.SarlSpecification;",
			"import io.sarl.lang.core.annotation.SyntheticMember;",
			"import org.eclipse.xtext.xbase.lib.Pure;",
			"import org.eclipse.xtext.xbase.lib.XbaseGenerated;",
			"",
			"@SarlSpecification(\"" + SARLVersion.SPECIFICATION_RELEASE_VERSION_STRING + "\")",
			"@SarlElementType(" + SarlPackage.SARL_CLASS + ")",
			"@XbaseGenerated",
			"@SuppressWarnings(\"all\")",
			"public class A2 {",
			"  @Pure",
			"  public A0 fct(final A1 x) {",
			"    A0 y = this.fct(null);",
			"    return this.toA0(false);",
			"  }",
			"  ",
			"  @Pure",
			"  public A0 toA0(final boolean x) {",
			"    return null;",
			"  }",
			"  ",
			"  @SyntheticMember",
			"  public A2() {",
			"    super();",
			"  }",
			"}",
			"");

	@Test
	public void parseLocalBoolean() throws Exception {
		SarlScript mas = file(getParseHelper(), LOCAL_BOOLEAN_SARL);
		Validator val = validate(getValidationHelper(), getInjector(), mas);
		val
			.assertNoErrors(
				TypesPackage.eINSTANCE.getJvmParameterizedTypeReference(),
				org.eclipse.xtext.xbase.validation.IssueCodes.INVALID_CAST)
			.assertNoWarnings(
				TypesPackage.eINSTANCE.getJvmParameterizedTypeReference(),
				org.eclipse.xtext.xbase.validation.IssueCodes.OBSOLETE_CAST)
			.assertWarning(
				TypesPackage.eINSTANCE.getJvmParameterizedTypeReference(),
				IssueCodes.POTENTIAL_INEFFICIENT_VALUE_CONVERSION,
				"toA0");
	}

	@GlobalCompilationTestContribution
	public void compileLocalBoolean(ResourceSetGlobalCompilationContext ctx) throws Exception {
		ctx.compileTo(LOCAL_BOOLEAN_SARL, LOCAL_BOOLEAN_JAVA);
	}

	private static final String LOCAL_STRING_SARL_01 = multilineString(
			"class A0 {",
			"}",
			"class A1 {",
			"}",
			"class A2 {",
			"  def fct(x : A1) : A0 {",
			"    var y = fct(null)",
			"    return \"hello\" as A0",
			"  }",
			"  def toA0(x : String) : A0 {",
			"    null",
			"  }",
			"}"
			);

	private static final String LOCAL_STRING_JAVA_01 = multilineString(
			"import io.sarl.lang.core.annotation.SarlElementType;",
			"import io.sarl.lang.core.annotation.SarlSpecification;",
			"import io.sarl.lang.core.annotation.SyntheticMember;",
			"import org.eclipse.xtext.xbase.lib.Pure;",
			"import org.eclipse.xtext.xbase.lib.XbaseGenerated;",
			"",
			"@SarlSpecification(\"" + SARLVersion.SPECIFICATION_RELEASE_VERSION_STRING + "\")",
			"@SarlElementType(" + SarlPackage.SARL_CLASS + ")",
			"@XbaseGenerated",
			"@SuppressWarnings(\"all\")",
			"public class A2 {",
			"  @Pure",
			"  public A0 fct(final A1 x) {",
			"    A0 y = this.fct(null);",
			"    return this.toA0(\"hello\");",
			"  }",
			"  ",
			"  @Pure",
			"  public A0 toA0(final String x) {",
			"    return null;",
			"  }",
			"  ",
			"  @SyntheticMember",
			"  public A2() {",
			"    super();",
			"  }",
			"}",
			"");

	@Test
	public void parseLocalString01() throws Exception {
		SarlScript mas = file(getParseHelper(), LOCAL_STRING_SARL_01);
		Validator val = validate(getValidationHelper(), getInjector(), mas);
		val
			.assertNoErrors(
				TypesPackage.eINSTANCE.getJvmParameterizedTypeReference(),
				org.eclipse.xtext.xbase.validation.IssueCodes.INVALID_CAST)
			.assertNoWarnings(
				TypesPackage.eINSTANCE.getJvmParameterizedTypeReference(),
				org.eclipse.xtext.xbase.validation.IssueCodes.OBSOLETE_CAST)
			.assertWarning(
				TypesPackage.eINSTANCE.getJvmParameterizedTypeReference(),
				IssueCodes.POTENTIAL_INEFFICIENT_VALUE_CONVERSION,
				"toA0");
	}

	@GlobalCompilationTestContribution
	public void compileLocalString01(ResourceSetGlobalCompilationContext ctx) throws Exception {
		ctx.compileTo(LOCAL_STRING_SARL_01, LOCAL_STRING_JAVA_01);
	}

	private static final String LOCAL_STRING_SARL_02 = multilineString(
			"class A0 {",
			"}",
			"class A2 {",
			"  def fct(x : String) : A0 {",
			"    var y = fct(null)",
			"    return x as A0",
			"  }",
			"  def toA0(x : String) : A0 {",
			"    null",
			"  }",
			"}"
			);

	private static final String LOCAL_STRING_JAVA_02 = multilineString(
			"import io.sarl.lang.core.annotation.SarlElementType;",
			"import io.sarl.lang.core.annotation.SarlSpecification;",
			"import io.sarl.lang.core.annotation.SyntheticMember;",
			"import org.eclipse.xtext.xbase.lib.Pure;",
			"import org.eclipse.xtext.xbase.lib.XbaseGenerated;",
			"",
			"@SarlSpecification(\"" + SARLVersion.SPECIFICATION_RELEASE_VERSION_STRING + "\")",
			"@SarlElementType(" + SarlPackage.SARL_CLASS + ")",
			"@XbaseGenerated",
			"@SuppressWarnings(\"all\")",
			"public class A2 {",
			"  @Pure",
			"  public A0 fct(final String x) {",
			"    A0 y = this.fct(null);",
			"    return (x == null ? null : this.toA0(x));",
			"  }",
			"  ",
			"  @Pure",
			"  public A0 toA0(final String x) {",
			"    return null;",
			"  }",
			"  ",
			"  @SyntheticMember",
			"  public A2() {",
			"    super();",
			"  }",
			"}",
			"");

	@Test
	public void parseLocalString02() throws Exception {
		SarlScript mas = file(getParseHelper(), LOCAL_STRING_SARL_02);
		Validator val = validate(getValidationHelper(), getInjector(), mas);
		val
			.assertNoErrors(
				TypesPackage.eINSTANCE.getJvmParameterizedTypeReference(),
				org.eclipse.xtext.xbase.validation.IssueCodes.INVALID_CAST)
			.assertNoWarnings(
				TypesPackage.eINSTANCE.getJvmParameterizedTypeReference(),
				org.eclipse.xtext.xbase.validation.IssueCodes.OBSOLETE_CAST)
			.assertWarning(
				TypesPackage.eINSTANCE.getJvmParameterizedTypeReference(),
				IssueCodes.POTENTIAL_INEFFICIENT_VALUE_CONVERSION,
				"toA0");
	}

	@GlobalCompilationTestContribution
	public void compileLocalString02(ResourceSetGlobalCompilationContext ctx) throws Exception {
		ctx.compileTo(LOCAL_STRING_SARL_02, LOCAL_STRING_JAVA_02);
	}

	private static final String LOCAL_IFTHEN_SARL = multilineString(
			"class A0 {",
			"}",
			"class A1 {",
			"}",
			"class A2 {",
			"  def fct(x : A1, y : A1) : A0 {",
			"    var z = fct(null, null)",
			"    return (if (x !== null) x else y) as A0",
			"  }",
			"  def toA0(x : A1) : A0 {",
			"    null",
			"  }",
			"}"
			);

	private static final String LOCAL_IFTHEN_JAVA = multilineString(
			"import io.sarl.lang.core.annotation.SarlElementType;",
			"import io.sarl.lang.core.annotation.SarlSpecification;",
			"import io.sarl.lang.core.annotation.SyntheticMember;",
			"import org.eclipse.xtext.xbase.lib.Pure;",
			"import org.eclipse.xtext.xbase.lib.XbaseGenerated;",
			"",
			"@SarlSpecification(\"" + SARLVersion.SPECIFICATION_RELEASE_VERSION_STRING + "\")",
			"@SarlElementType(" + SarlPackage.SARL_CLASS + ")",
			"@XbaseGenerated",
			"@SuppressWarnings(\"all\")",
			"public class A2 {",
			"  @Pure",
			"  public A0 fct(final A1 x, final A1 y) {",
			"    A0 z = this.fct(null, null);",
			"    A1 _xifexpression = null;",
			"    if ((x != null)) {",
			"      _xifexpression = x;",
			"    } else {",
			"      _xifexpression = y;",
			"    }",
			"    return (_xifexpression == null ? null : this.toA0(_xifexpression));",
			"  }",
			"  ",
			"  @Pure",
			"  public A0 toA0(final A1 x) {",
			"    return null;",
			"  }",
			"  ",
			"  @SyntheticMember",
			"  public A2() {",
			"    super();",
			"  }",
			"}",
			"");

	@Test
	public void parseLocalIfThen() throws Exception {
		SarlScript mas = file(getParseHelper(), LOCAL_IFTHEN_SARL);
		Validator val = validate(getValidationHelper(), getInjector(), mas);
		val
			.assertNoErrors(
				TypesPackage.eINSTANCE.getJvmParameterizedTypeReference(),
				org.eclipse.xtext.xbase.validation.IssueCodes.INVALID_CAST)
			.assertNoWarnings(
				TypesPackage.eINSTANCE.getJvmParameterizedTypeReference(),
				org.eclipse.xtext.xbase.validation.IssueCodes.OBSOLETE_CAST)
			.assertWarning(
				TypesPackage.eINSTANCE.getJvmParameterizedTypeReference(),
				IssueCodes.POTENTIAL_INEFFICIENT_VALUE_CONVERSION,
				"toA0");
	}

	@GlobalCompilationTestContribution
	public void compileLocalIfThen(ResourceSetGlobalCompilationContext ctx) throws Exception {
		ctx.compileTo(LOCAL_IFTHEN_SARL, LOCAL_IFTHEN_JAVA);
	}

	private static final String LOCAL_ARITH_SARL = multilineString(
			"class A0 {",
			"}",
			"class A2 {",
			"  def fct(x : double) : A0 {",
			"    var y = fct(0)",
			"    return (x + 3) as A0",
			"  }",
			"  def toA0(x : double) : A0 {",
			"    null",
			"  }",
			"}"
			);

	private static final String LOCAL_ARITH_JAVA = multilineString(
			"import io.sarl.lang.core.annotation.SarlElementType;",
			"import io.sarl.lang.core.annotation.SarlSpecification;",
			"import io.sarl.lang.core.annotation.SyntheticMember;",
			"import org.eclipse.xtext.xbase.lib.Pure;",
			"import org.eclipse.xtext.xbase.lib.XbaseGenerated;",
			"",
			"@SarlSpecification(\"" + SARLVersion.SPECIFICATION_RELEASE_VERSION_STRING + "\")",
			"@SarlElementType(" + SarlPackage.SARL_CLASS + ")",
			"@XbaseGenerated",
			"@SuppressWarnings(\"all\")",
			"public class A2 {",
			"  @Pure",
			"  public A0 fct(final double x) {",
			"    A0 y = this.fct(0);",
			"    return this.toA0((x + 3));",
			"  }",
			"  ",
			"  @Pure",
			"  public A0 toA0(final double x) {",
			"    return null;",
			"  }",
			"  ",
			"  @SyntheticMember",
			"  public A2() {",
			"    super();",
			"  }",
			"}",
			"");

	@Test
	public void parseLocalArith() throws Exception {
		SarlScript mas = file(getParseHelper(), LOCAL_ARITH_SARL);
		Validator val = validate(getValidationHelper(), getInjector(), mas);
		val
			.assertNoErrors(
				TypesPackage.eINSTANCE.getJvmParameterizedTypeReference(),
				org.eclipse.xtext.xbase.validation.IssueCodes.INVALID_CAST)
			.assertNoWarnings(
				TypesPackage.eINSTANCE.getJvmParameterizedTypeReference(),
				org.eclipse.xtext.xbase.validation.IssueCodes.OBSOLETE_CAST)
			.assertWarning(
				TypesPackage.eINSTANCE.getJvmParameterizedTypeReference(),
				IssueCodes.POTENTIAL_INEFFICIENT_VALUE_CONVERSION,
				"toA0");
	}

	@GlobalCompilationTestContribution
	public void compileLocalArith(ResourceSetGlobalCompilationContext ctx) throws Exception {
		ctx.compileTo(LOCAL_ARITH_SARL, LOCAL_ARITH_JAVA);
	}

	private static final String LOCAL_CAST_SARL = multilineString(
			"class A0 {",
			"}",
			"class A2 {",
			"  def fct(x : double) : A0 {",
			"    var y = fct(0)",
			"    return x as long as A0",
			"  }",
			"  def toA0(x : long) : A0 {",
			"    null",
			"  }",
			"}"
			);

	private static final String LOCAL_CAST_JAVA = multilineString(
			"import io.sarl.lang.core.annotation.SarlElementType;",
			"import io.sarl.lang.core.annotation.SarlSpecification;",
			"import io.sarl.lang.core.annotation.SyntheticMember;",
			"import org.eclipse.xtext.xbase.lib.Pure;",
			"import org.eclipse.xtext.xbase.lib.XbaseGenerated;",
			"",
			"@SarlSpecification(\"" + SARLVersion.SPECIFICATION_RELEASE_VERSION_STRING + "\")",
			"@SarlElementType(" + SarlPackage.SARL_CLASS + ")",
			"@XbaseGenerated",
			"@SuppressWarnings(\"all\")",
			"public class A2 {",
			"  @Pure",
			"  public A0 fct(final double x) {",
			"    A0 y = this.fct(0);",
			"    return this.toA0(((long) x));",
			"  }",
			"  ",
			"  @Pure",
			"  public A0 toA0(final long x) {",
			"    return null;",
			"  }",
			"  ",
			"  @SyntheticMember",
			"  public A2() {",
			"    super();",
			"  }",
			"}",
			"");

	@Test
	public void parseLocalCast() throws Exception {
		SarlScript mas = file(getParseHelper(), LOCAL_CAST_SARL);
		Validator val = validate(getValidationHelper(), getInjector(), mas);
		val
			.assertNoErrors(
				TypesPackage.eINSTANCE.getJvmParameterizedTypeReference(),
				org.eclipse.xtext.xbase.validation.IssueCodes.INVALID_CAST)
			.assertNoWarnings(
				TypesPackage.eINSTANCE.getJvmParameterizedTypeReference(),
				org.eclipse.xtext.xbase.validation.IssueCodes.OBSOLETE_CAST)
			.assertWarning(
				TypesPackage.eINSTANCE.getJvmParameterizedTypeReference(),
				IssueCodes.POTENTIAL_INEFFICIENT_VALUE_CONVERSION,
				"toA0");
	}

	@GlobalCompilationTestContribution
	public void compileLocalCast(ResourceSetGlobalCompilationContext ctx) throws Exception {
		ctx.compileTo(LOCAL_CAST_SARL, LOCAL_CAST_JAVA);
	}

	private static final String LOCAL_FUNCTION_CALL_SARL_00 = multilineString(
			"class A0 {",
			"}",
			"class A1 {",
			"  def getX : A1 { null }",
			"}",
			"class A2 {",
			"  def fct(x : A1) : A0 {",
			"    var y = fct(null)",
			"    return x.x as A0",
			"  }",
			"}"
			);

	@Test
	public void parseLocalFunctionCall00() throws Exception {
		SarlScript mas = file(getParseHelper(), LOCAL_FUNCTION_CALL_SARL_00);
		Validator val = validate(getValidationHelper(), getInjector(), mas);
		val
			.assertError(
				TypesPackage.eINSTANCE.getJvmParameterizedTypeReference(),
				org.eclipse.xtext.xbase.validation.IssueCodes.INVALID_CAST,
				"Cannot cast from A1 to A0")
			.assertNoWarnings(
				TypesPackage.eINSTANCE.getJvmParameterizedTypeReference(),
				org.eclipse.xtext.xbase.validation.IssueCodes.OBSOLETE_CAST)
			.assertNoWarnings(
				TypesPackage.eINSTANCE.getJvmParameterizedTypeReference(),
				IssueCodes.POTENTIAL_INEFFICIENT_VALUE_CONVERSION);
	}

	private static final String LOCAL_FUNCTION_CALL_SARL_01 = multilineString(
			"class A0 {",
			"}",
			"class A1 {",
			"  def getX : A1 { null }",
			"}",
			"class A2 {",
			"  def fct(x : A1) : A0 {",
			"    var y = fct(null)",
			"    return x.x as A0",
			"  }",
			"  def toA0(x : A1) : A0 { null }",
			"}"
			);

	private static final String LOCAL_FUNCTION_CALL_JAVA_01 = multilineString(
			"import io.sarl.lang.core.annotation.SarlElementType;",
			"import io.sarl.lang.core.annotation.SarlSpecification;",
			"import io.sarl.lang.core.annotation.SyntheticMember;",
			"import org.eclipse.xtext.xbase.lib.Pure;",
			"import org.eclipse.xtext.xbase.lib.XbaseGenerated;",
			"",
			"@SarlSpecification(\"" + SARLVersion.SPECIFICATION_RELEASE_VERSION_STRING + "\")",
			"@SarlElementType(" + SarlPackage.SARL_CLASS + ")",
			"@XbaseGenerated",
			"@SuppressWarnings(\"all\")",
			"public class A2 {",
			"  @Pure",
			"  public A0 fct(final A1 x) {",
			"    A0 y = this.fct(null);",
			"    A1 _x = x.getX();",
			"    return (_x == null ? null : this.toA0(_x));",
			"  }",
			"  ",
			"  @Pure",
			"  public A0 toA0(final A1 x) {",
			"    return null;",
			"  }",
			"  ",
			"  @SyntheticMember",
			"  public A2() {",
			"    super();",
			"  }",
			"}",
			"");

	@Test
	public void parseLocalFunctionCall01() throws Exception {
		SarlScript mas = file(getParseHelper(), LOCAL_FUNCTION_CALL_SARL_01);
		Validator val = validate(getValidationHelper(), getInjector(), mas);
		val
			.assertNoErrors(
				TypesPackage.eINSTANCE.getJvmParameterizedTypeReference(),
				org.eclipse.xtext.xbase.validation.IssueCodes.INVALID_CAST)
			.assertNoWarnings(
				TypesPackage.eINSTANCE.getJvmParameterizedTypeReference(),
				org.eclipse.xtext.xbase.validation.IssueCodes.OBSOLETE_CAST)
			.assertWarning(
				TypesPackage.eINSTANCE.getJvmParameterizedTypeReference(),
				IssueCodes.POTENTIAL_INEFFICIENT_VALUE_CONVERSION,
				"toA0");
	}

	@GlobalCompilationTestContribution
	public void compileLocalFunctionCall01(ResourceSetGlobalCompilationContext ctx) throws Exception {
		ctx.compileTo(LOCAL_FUNCTION_CALL_SARL_01, LOCAL_FUNCTION_CALL_JAVA_01);
	}

	private static final String OBJECT_SARL = multilineString(
			"class A0 {",
			"}",
			"class A1 {",
			"  def toA0 : A0 { null }",
			"}",
			"class A2 {",
			"  def fct(x : A1) : A0 {",
			"    var y = fct(null)",
			"    return x as A0",
			"  }",
			"}"
			);

	private static final String OBJECT_JAVA = multilineString(
			"import io.sarl.lang.core.annotation.SarlElementType;",
			"import io.sarl.lang.core.annotation.SarlSpecification;",
			"import io.sarl.lang.core.annotation.SyntheticMember;",
			"import org.eclipse.xtext.xbase.lib.Pure;",
			"import org.eclipse.xtext.xbase.lib.XbaseGenerated;",
			"",
			"@SarlSpecification(\"" + SARLVersion.SPECIFICATION_RELEASE_VERSION_STRING + "\")",
			"@SarlElementType(" + SarlPackage.SARL_CLASS + ")",
			"@XbaseGenerated",
			"@SuppressWarnings(\"all\")",
			"public class A2 {",
			"  @Pure",
			"  public A0 fct(final A1 x) {",
			"    A0 y = this.fct(null);",
			"    return (x == null ? null : x.toA0());",
			"  }",
			"  ",
			"  @SyntheticMember",
			"  public A2() {",
			"    super();",
			"  }",
			"}",
			"");

	@Test
	public void parseObject() throws Exception {
		SarlScript mas = file(getParseHelper(), OBJECT_SARL);
		Validator val = validate(getValidationHelper(), getInjector(), mas);
		val
			.assertNoErrors(
				TypesPackage.eINSTANCE.getJvmParameterizedTypeReference(),
				org.eclipse.xtext.xbase.validation.IssueCodes.INVALID_CAST)
			.assertNoWarnings(
				TypesPackage.eINSTANCE.getJvmParameterizedTypeReference(),
				org.eclipse.xtext.xbase.validation.IssueCodes.OBSOLETE_CAST)
			.assertWarning(
				TypesPackage.eINSTANCE.getJvmParameterizedTypeReference(),
				IssueCodes.POTENTIAL_INEFFICIENT_VALUE_CONVERSION,
				"toA0");
	}

	@GlobalCompilationTestContribution
	public void compileObject(ResourceSetGlobalCompilationContext ctx) throws Exception {
		ctx.compileTo(OBJECT_SARL, OBJECT_JAVA);
	}

	private static final String LOCAL_STATIC_SARL = multilineString(
			"class A0 {",
			"}",
			"class A1 {",
			"}",
			"class A2 {",
			"  def fct(x : A1) : A0 {",
			"    var y = fct(null)",
			"    return x as A0",
			"  }",
			"  static def toA0(x : A1) : A0 {",
			"    null",
			"  }",
			"  static def toString(x : A1, y : float) : String {",
			"    null",
			"  }",
			"  static def toA0(x : String) : A0 {",
			"    null",
			"  }",
			"}"
			);

	private static final String LOCAL_STATIC_JAVA = multilineString(
			"import io.sarl.lang.core.annotation.SarlElementType;",
			"import io.sarl.lang.core.annotation.SarlSpecification;",
			"import io.sarl.lang.core.annotation.SyntheticMember;",
			"import org.eclipse.xtext.xbase.lib.Pure;",
			"import org.eclipse.xtext.xbase.lib.XbaseGenerated;",
			"",
			"@SarlSpecification(\"" + SARLVersion.SPECIFICATION_RELEASE_VERSION_STRING + "\")",
			"@SarlElementType(" + SarlPackage.SARL_CLASS + ")",
			"@XbaseGenerated",
			"@SuppressWarnings(\"all\")",
			"public class A2 {",
			"  @Pure",
			"  public A0 fct(final A1 x) {",
			"    A0 y = this.fct(null);",
			"    return (x == null ? null : A2.toA0(x));",
			"  }",
			"  ",
			"  @Pure",
			"  public static A0 toA0(final A1 x) {",
			"    return null;",
			"  }",
			"  ",
			"  @Pure",
			"  public static String toString(final A1 x, final float y) {",
			"    return null;",
			"  }",
			"  ",
			"  @Pure",
			"  public static A0 toA0(final String x) {",
			"    return null;",
			"  }",
			"  ",
			"  @SyntheticMember",
			"  public A2() {",
			"    super();",
			"  }",
			"}",
			"");

	@Test
	public void parseLocalStatic() throws Exception {
		SarlScript mas = file(getParseHelper(), LOCAL_STATIC_SARL);
		Validator val = validate(getValidationHelper(), getInjector(), mas);
		val
			.assertNoErrors(
				TypesPackage.eINSTANCE.getJvmParameterizedTypeReference(),
				org.eclipse.xtext.xbase.validation.IssueCodes.INVALID_CAST)
			.assertNoWarnings(
				TypesPackage.eINSTANCE.getJvmParameterizedTypeReference(),
				org.eclipse.xtext.xbase.validation.IssueCodes.OBSOLETE_CAST)
			.assertWarning(
				TypesPackage.eINSTANCE.getJvmParameterizedTypeReference(),
				IssueCodes.POTENTIAL_INEFFICIENT_VALUE_CONVERSION,
				"toA0");
	}

	@GlobalCompilationTestContribution
	public void compileLocalStatic(ResourceSetGlobalCompilationContext ctx) throws Exception {
		ctx.compileTo(LOCAL_STATIC_SARL, LOCAL_STATIC_JAVA);
	}

	private static final String SUPER_STATIC_SARL = multilineString(
			"class A0 {",
			"}",
			"class A1 {",
			"}",
			"class A2 {",
			"  static def toA0(x : A1) : A0 {",
			"  }",
			"  static def toA0(x : A1, y : float) : String {",
			"  }",
			"  static def toA0(x : String) : A0 {",
			"  }",
			"}",
			"class A3 extends A2 {",
			"  def fct(x : A1) : A0 {",
			"    var y = fct(null)",
			"    return x as A0",
			"  }",
			"}"
			);

	private static final String SUPER_STATIC_JAVA = multilineString(
			"import io.sarl.lang.core.annotation.SarlElementType;",
			"import io.sarl.lang.core.annotation.SarlSpecification;",
			"import io.sarl.lang.core.annotation.SyntheticMember;",
			"import org.eclipse.xtext.xbase.lib.Pure;",
			"import org.eclipse.xtext.xbase.lib.XbaseGenerated;",
			"",
			"@SarlSpecification(\"" + SARLVersion.SPECIFICATION_RELEASE_VERSION_STRING + "\")",
			"@SarlElementType(" + SarlPackage.SARL_CLASS + ")",
			"@XbaseGenerated",
			"@SuppressWarnings(\"all\")",
			"public class A3 extends A2 {",
			"  @Pure",
			"  public A0 fct(final A1 x) {",
			"    A0 y = this.fct(null);",
			"    return (x == null ? null : A2.toA0(x));",
			"  }",
			"  ",
			"  @SyntheticMember",
			"  public A3() {",
			"    super();",
			"  }",
			"}",
			"");

	@Test
	public void parseSuperStatic() throws Exception {
		SarlScript mas = file(getParseHelper(), SUPER_STATIC_SARL);
		Validator val = validate(getValidationHelper(), getInjector(), mas);
		val
			.assertNoErrors(
				TypesPackage.eINSTANCE.getJvmParameterizedTypeReference(),
				org.eclipse.xtext.xbase.validation.IssueCodes.INVALID_CAST)
			.assertNoWarnings(
				TypesPackage.eINSTANCE.getJvmParameterizedTypeReference(),
				org.eclipse.xtext.xbase.validation.IssueCodes.OBSOLETE_CAST)
			.assertWarning(
				TypesPackage.eINSTANCE.getJvmParameterizedTypeReference(),
				IssueCodes.POTENTIAL_INEFFICIENT_VALUE_CONVERSION,
				"toA0");
	}

	@GlobalCompilationTestContribution
	public void compileSuperStatic(ResourceSetGlobalCompilationContext ctx) throws Exception {
		ctx.compileTo(SUPER_STATIC_SARL, SUPER_STATIC_JAVA);
	}

	private static final String SUPER_SARL = multilineString(
			"class A0 {",
			"}",
			"class A1 {",
			"}",
			"class A2 {",
			"  def toA0(x : A1) : A0 {",
			"  }",
			"  def toA0(x : A1, y : float) : String {",
			"  }",
			"  def toA0(x : String) : A0 {",
			"  }",
			"}",
			"class A3 extends A2 {",
			"  def fct(x : A1) : A0 {",
			"    var y = fct(null)",
			"    return x as A0",
			"  }",
			"}"
			);

	private static final String SUPER_JAVA = multilineString(
			"import io.sarl.lang.core.annotation.SarlElementType;",
			"import io.sarl.lang.core.annotation.SarlSpecification;",
			"import io.sarl.lang.core.annotation.SyntheticMember;",
			"import org.eclipse.xtext.xbase.lib.Pure;",
			"import org.eclipse.xtext.xbase.lib.XbaseGenerated;",
			"",
			"@SarlSpecification(\"" + SARLVersion.SPECIFICATION_RELEASE_VERSION_STRING + "\")",
			"@SarlElementType(" + SarlPackage.SARL_CLASS + ")",
			"@XbaseGenerated",
			"@SuppressWarnings(\"all\")",
			"public class A3 extends A2 {",
			"  @Pure",
			"  public A0 fct(final A1 x) {",
			"    A0 y = this.fct(null);",
			"    return (x == null ? null : this.toA0(x));",
			"  }",
			"  ",
			"  @SyntheticMember",
			"  public A3() {",
			"    super();",
			"  }",
			"}",
			"");

	@Test
	public void parseSuper() throws Exception {
		SarlScript mas = file(getParseHelper(), SUPER_SARL);
		Validator val = validate(getValidationHelper(), getInjector(), mas);
		val
			.assertNoErrors(
				TypesPackage.eINSTANCE.getJvmParameterizedTypeReference(),
				org.eclipse.xtext.xbase.validation.IssueCodes.INVALID_CAST)
			.assertNoWarnings(
				TypesPackage.eINSTANCE.getJvmParameterizedTypeReference(),
				org.eclipse.xtext.xbase.validation.IssueCodes.OBSOLETE_CAST)
			.assertWarning(
				TypesPackage.eINSTANCE.getJvmParameterizedTypeReference(),
				IssueCodes.POTENTIAL_INEFFICIENT_VALUE_CONVERSION,
				"toA0");
	}

	@GlobalCompilationTestContribution
	public void compileSuper(ResourceSetGlobalCompilationContext ctx) throws Exception {
		ctx.compileTo(SUPER_SARL, SUPER_JAVA);
	}

	private static final String STATIC_IMPORT_SARL = multilineString(
			"import static foo.FooUtils.*",
			"class A1 {",
			"}",
			"class A2 {",
			"  def fct(x : A1) : String {",
			"    var y = fct(null)",
			"    return x as String",
			"  }",
			"}"
			);

	private static final String STATIC_IMPORT_JAVA = multilineString(
			"import io.sarl.lang.core.annotation.SarlElementType;",
			"import io.sarl.lang.core.annotation.SarlSpecification;",
			"import io.sarl.lang.core.annotation.SyntheticMember;",
			"import org.eclipse.xtext.xbase.lib.Pure;",
			"import org.eclipse.xtext.xbase.lib.XbaseGenerated;",
			"",
			"@SarlSpecification(\"" + SARLVersion.SPECIFICATION_RELEASE_VERSION_STRING + "\")",
			"@SarlElementType(" + SarlPackage.SARL_CLASS + ")",
			"@XbaseGenerated",
			"@SuppressWarnings(\"all\")",
			"public class A2 {",
			"  @Pure",
			"  public String fct(final A1 x) {",
