/*
 * $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.core.tests.scoping.extensions.cast;

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.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.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;

/**
 * @author $Author: sgalland$
 * @version $FullVersion$
 * @mavengroupid $GroupId$
 * @mavenartifactid $ArtifactId$
 */
@GlobalCompilationSuite
@SuppressWarnings("all")
@DisplayName("Cast operators - compilation")
@Tag("core")
public class CompilerTest extends AbstractSarlTest {

	private static final String STRING_AS_BOOLEAN_SARL = multilineString(
			"class A {",
			"  def fct(left : String) : boolean {",
			"    left as boolean",
			"  }",
			"}");

	private static final String STRING_AS_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 A {",
			"  @Pure",
			"  public boolean fct(final String left) {",
			"    return (left == null ? false : Boolean.parseBoolean((left).toString()));",
			"  }",
			"  ",
			"  @SyntheticMember",
			"  public A() {",
			"    super();",
			"  }",
			"}",
			"");

	@Test
	@Tag("sarlValidation")
	@DisplayName("Parsing: String as boolean")
	public void string_as_boolean_issues() throws Exception {
		validate(getValidationHelper(), getInjector(), file(getParseHelper(), STRING_AS_BOOLEAN_SARL))
		.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,
				"'booleanValue'");
	}

	@GlobalCompilationTestContribution
	@Tag("compileToJava")
	@DisplayName("Compiling: String as boolean")
	public void string_as_boolean(ResourceSetGlobalCompilationContext ctx) throws Exception {
		ctx.compileTo(STRING_AS_BOOLEAN_SARL, STRING_AS_BOOLEAN_JAVA);
	}

	private static final String BOOLEAN_AS_STRING_SARL = multilineString(
			"class A {",
			"  def fct(left : boolean) : String {",
			"    left as String",
			"  }",
			"}");

	private static final String BOOLEAN_AS_STRING_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 A {",
			"  @Pure",
			"  public String fct(final boolean left) {",
			"    return Boolean.toString(left);",
			"  }",
			"  ",
			"  @SyntheticMember",
			"  public A() {",
			"    super();",
			"  }",
			"}",
			"");

	@Test
	@Tag("sarlValidation")
	@DisplayName("Parsing: boolean as String")
	public void boolean_as_string_issues() throws Exception {
		validate(getValidationHelper(), getInjector(), file(getParseHelper(), BOOLEAN_AS_STRING_SARL))
		.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,
				"'toString'");
	}

	@GlobalCompilationTestContribution
	@Tag("compileToJava")
	@DisplayName("Compiling: boolean as String")
	public void boolean_as_string(ResourceSetGlobalCompilationContext ctx) throws Exception {
		ctx.compileTo(BOOLEAN_AS_STRING_SARL, BOOLEAN_AS_STRING_JAVA);
	}

	private static final String CHAR_AS_STRING_SARL = multilineString(
			"class A {",
			"  def fct(left : char) : String {",
			"    left as String",
			"  }",
			"}");

	private static final String CHAR_AS_STRING_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 A {",
			"  @Pure",
			"  public String fct(final char left) {",
			"    return Character.toString(left);",
			"  }",
			"  ",
			"  @SyntheticMember",
			"  public A() {",
			"    super();",
			"  }",
			"}",
			"");

	@Test
	@Tag("sarlValidation")
	@DisplayName("Parsing: char as String")
	public void char_as_string_issues() throws Exception {
		validate(getValidationHelper(), getInjector(), file(getParseHelper(), CHAR_AS_STRING_SARL))
		.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,
				"'toString'");
	}

	@GlobalCompilationTestContribution
	@Tag("compileToJava")
	@DisplayName("Compiling: char as String")
	public void char_as_string(ResourceSetGlobalCompilationContext ctx) throws Exception {
		ctx.compileTo(CHAR_AS_STRING_SARL, CHAR_AS_STRING_JAVA);
	}

	private static final String STRING_AS_BYTE_SARL = multilineString(
			"class A {",
			"  def fct(left : String) : byte {",
			"    left as byte",
			"  }",
			"}");

	private static final String STRING_AS_BYTE_JAVA = multilineString(
			"import io.sarl.lang.core.annotation.SarlElementType;",
			"import io.sarl.lang.core.annotation.SarlSpecification;",
			"import io.sarl.lang.core.annotation.SyntheticMember;",
			"import io.sarl.lang.core.scoping.extensions.cast.PrimitiveCastExtensions;",
			"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 A {",
			"  @Pure",
			"  public byte fct(final String left) {",
			"    return (left == null ? 0 : PrimitiveCastExtensions.byteValue(left));",
			"  }",
			"  ",
			"  @SyntheticMember",
			"  public A() {",
			"    super();",
			"  }",
			"}",
			"");

	@Test
	@Tag("sarlValidation")
	@DisplayName("Parsing: String as byte")
	public void string_as_byte_issues() throws Exception {
		validate(getValidationHelper(), getInjector(), file(getParseHelper(), STRING_AS_BYTE_SARL))
		.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,
				"'byteValue'");
	}

	@GlobalCompilationTestContribution
	@Tag("compileToJava")
	@DisplayName("Compiling: String as byte")
	public void string_as_byte(ResourceSetGlobalCompilationContext ctx) throws Exception {
		ctx.compileTo(STRING_AS_BYTE_SARL, STRING_AS_BYTE_JAVA);
	}

	private static final String STRING_AS_BYTEOBJ_SARL = multilineString(
			"class A {",
			"  def fct(left : String) : Byte {",
			"    left as Byte",
			"  }",
			"}");

	private static final String STRING_AS_BYTEOBJ_JAVA = multilineString(
			"import io.sarl.lang.core.annotation.SarlElementType;",
			"import io.sarl.lang.core.annotation.SarlSpecification;",
			"import io.sarl.lang.core.annotation.SyntheticMember;",
			"import io.sarl.lang.core.scoping.extensions.cast.PrimitiveCastExtensions;",
			"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 A {",
			"  @Pure",
			"  public Byte fct(final String left) {",
			"    return (left == null ? null : PrimitiveCastExtensions.toByte(left));",
			"  }",
			"  ",
			"  @SyntheticMember",
			"  public A() {",
			"    super();",
			"  }",
			"}",
			"");

	@Test
	@Tag("sarlValidation")
	@DisplayName("Parsing: String as Byte")
	public void string_as_Byte_issues() throws Exception {
		validate(getValidationHelper(), getInjector(), file(getParseHelper(), STRING_AS_BYTEOBJ_SARL))
		.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,
				"'toByte'");
	}

	@GlobalCompilationTestContribution
	@Tag("compileToJava")
	@DisplayName("Compiling: String as Byte")
	public void string_as_Byte(ResourceSetGlobalCompilationContext ctx) throws Exception {
		ctx.compileTo(STRING_AS_BYTEOBJ_SARL, STRING_AS_BYTEOBJ_JAVA);
	}

	private static final String STRING_AS_SHORT_SARL = multilineString(
			"class A {",
			"  def fct(left : String) : short {",
			"    left as short",
			"  }",
			"}");

	private static final String STRING_AS_SHORT_JAVA = multilineString(
			"import io.sarl.lang.core.annotation.SarlElementType;",
			"import io.sarl.lang.core.annotation.SarlSpecification;",
			"import io.sarl.lang.core.annotation.SyntheticMember;",
			"import io.sarl.lang.core.scoping.extensions.cast.PrimitiveCastExtensions;",
			"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 A {",
			"  @Pure",
			"  public short fct(final String left) {",
			"    return (left == null ? 0 : PrimitiveCastExtensions.shortValue(left));",
			"  }",
			"  ",
			"  @SyntheticMember",
			"  public A() {",
			"    super();",
			"  }",
			"}",
			"");

	@Test
	@Tag("sarlValidation")
	@DisplayName("Parsing: String as short")
	public void string_as_short_issues() throws Exception {
		validate(getValidationHelper(), getInjector(), file(getParseHelper(), STRING_AS_SHORT_SARL))
		.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,
				"'shortValue'");
	}

	@GlobalCompilationTestContribution
	@Tag("compileToJava")
	@DisplayName("Compiling: String as short")
	public void string_as_short(ResourceSetGlobalCompilationContext ctx) throws Exception {
		ctx.compileTo(STRING_AS_SHORT_SARL, STRING_AS_SHORT_JAVA);
	}

	private static final String STRING_AS_SHORTOBJ_SARL = multilineString(
			"class A {",
			"  def fct(left : String) : Short {",
			"    left as Short",
			"  }",
			"}");

	private static final String STRING_AS_SHORTOBJ_JAVA = multilineString(
			"import io.sarl.lang.core.annotation.SarlElementType;",
			"import io.sarl.lang.core.annotation.SarlSpecification;",
			"import io.sarl.lang.core.annotation.SyntheticMember;",
			"import io.sarl.lang.core.scoping.extensions.cast.PrimitiveCastExtensions;",
			"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 A {",
			"  @Pure",
			"  public Short fct(final String left) {",
			"    return (left == null ? null : PrimitiveCastExtensions.toShort(left));",
			"  }",
			"  ",
			"  @SyntheticMember",
			"  public A() {",
			"    super();",
			"  }",
			"}",
			"");

	@Test
	@Tag("sarlValidation")
	@DisplayName("Parsing: String as Short")
	public void string_as_Short_issues() throws Exception {
		validate(getValidationHelper(), getInjector(), file(getParseHelper(), STRING_AS_SHORTOBJ_SARL))
		.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,
				"'toShort'");
	}

	@GlobalCompilationTestContribution
	@Tag("compileToJava")
	@DisplayName("Compiling: String as Short")
	public void string_as_Short(ResourceSetGlobalCompilationContext ctx) throws Exception {
		ctx.compileTo(STRING_AS_SHORTOBJ_SARL, STRING_AS_SHORTOBJ_JAVA);
	}

	private static final String STRING_AS_INT_SARL = multilineString(
			"class A {",
			"  def fct(left : String) : int {",
			"    left as int",
			"  }",
			"}");

	private static final String STRING_AS_INT_JAVA = multilineString(
			"import io.sarl.lang.core.annotation.SarlElementType;",
			"import io.sarl.lang.core.annotation.SarlSpecification;",
			"import io.sarl.lang.core.annotation.SyntheticMember;",
			"import io.sarl.lang.core.scoping.extensions.cast.PrimitiveCastExtensions;",
			"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 A {",
			"  @Pure",
			"  public int fct(final String left) {",
			"    return (left == null ? 0 : PrimitiveCastExtensions.intValue(left));",
			"  }",
			"  ",
			"  @SyntheticMember",
			"  public A() {",
			"    super();",
			"  }",
			"}",
			"");

	@Test
	@Tag("sarlValidation")
	@DisplayName("Parsing: String as int")
	public void string_as_int_issues() throws Exception {
		validate(getValidationHelper(), getInjector(), file(getParseHelper(), STRING_AS_INT_SARL))
		.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,
				"'intValue'");
	}

	@GlobalCompilationTestContribution
	@Tag("compileToJava")
	@DisplayName("Compiling: String as int")
	public void string_as_int(ResourceSetGlobalCompilationContext ctx) throws Exception {
		ctx.compileTo(STRING_AS_INT_SARL, STRING_AS_INT_JAVA);
	}

	private static final String STRING_AS_INTEGER_SARL = multilineString(
			"class A {",
			"  def fct(left : String) : Integer {",
			"    left as Integer",
			"  }",
			"}");

	private static final String STRING_AS_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 io.sarl.lang.core.scoping.extensions.cast.PrimitiveCastExtensions;",
			"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 A {",
			"  @Pure",
			"  public Integer fct(final String left) {",
			"    return (left == null ? null : PrimitiveCastExtensions.toInteger(left));",
			"  }",
			"  ",
			"  @SyntheticMember",
			"  public A() {",
			"    super();",
			"  }",
			"}",
			"");

	@Test
	@Tag("sarlValidation")
	@DisplayName("Parsing: String as Integer")
	public void string_as_integer_issues() throws Exception {
		validate(getValidationHelper(), getInjector(), file(getParseHelper(), STRING_AS_INTEGER_SARL))
		.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,
				"'toInteger'");
	}

	@GlobalCompilationTestContribution
	@Tag("compileToJava")
	@DisplayName("Compiling: String as Integer")
	public void string_as_integer(ResourceSetGlobalCompilationContext ctx) throws Exception {
		ctx.compileTo(STRING_AS_INTEGER_SARL, STRING_AS_INTEGER_JAVA);
	}

	private static final String STRING_AS_LONG_SARL = multilineString(
			"class A {",
			"  def fct(left : String) : long {",
			"    left as long",
			"  }",
			"}");

	private static final String STRING_AS_LONG_JAVA = multilineString(
			"import io.sarl.lang.core.annotation.SarlElementType;",
			"import io.sarl.lang.core.annotation.SarlSpecification;",
			"import io.sarl.lang.core.annotation.SyntheticMember;",
			"import io.sarl.lang.core.scoping.extensions.cast.PrimitiveCastExtensions;",
			"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 A {",
			"  @Pure",
			"  public long fct(final String left) {",
			"    return (left == null ? 0 : PrimitiveCastExtensions.longValue(left));",
			"  }",
			"  ",
			"  @SyntheticMember",
			"  public A() {",
			"    super();",
			"  }",
			"}",
			"");

	@Test
	@Tag("sarlValidation")
	@DisplayName("Parsing: String as long")
	public void string_as_long_issues() throws Exception {
		validate(getValidationHelper(), getInjector(), file(getParseHelper(), STRING_AS_LONG_SARL))
		.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,
				"'longValue'");
	}

	@GlobalCompilationTestContribution
	@Tag("compileToJava")
	@DisplayName("Compiling: String as long")
	public void string_as_long(ResourceSetGlobalCompilationContext ctx) throws Exception {
		ctx.compileTo(STRING_AS_LONG_SARL, STRING_AS_LONG_JAVA);
	}


	private static final String STRING_AS_LONGOBJ_SARL = multilineString(
			"class A {",
			"  def fct(left : String) : Long {",
			"    left as Long",
			"  }",
			"}");

	private static final String STRING_AS_LONGOBJ_JAVA = multilineString(
			"import io.sarl.lang.core.annotation.SarlElementType;",
			"import io.sarl.lang.core.annotation.SarlSpecification;",
			"import io.sarl.lang.core.annotation.SyntheticMember;",
			"import io.sarl.lang.core.scoping.extensions.cast.PrimitiveCastExtensions;",
			"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 A {",
			"  @Pure",
			"  public Long fct(final String left) {",
			"    return (left == null ? null : PrimitiveCastExtensions.toLong(left));",
			"  }",
			"  ",
			"  @SyntheticMember",
			"  public A() {",
			"    super();",
			"  }",
			"}",
			"");

	@Test
	@Tag("sarlValidation")
	@DisplayName("Parsing: String as Long")
	public void string_as_Long_issues() throws Exception {
		validate(getValidationHelper(), getInjector(), file(getParseHelper(), STRING_AS_LONGOBJ_SARL))
		.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,
				"'toLong'");
	}

	@GlobalCompilationTestContribution
	@Tag("compileToJava")
	@DisplayName("Compiling: String as Long")
	public void string_as_Long(ResourceSetGlobalCompilationContext ctx) throws Exception {
		ctx.compileTo(STRING_AS_LONGOBJ_SARL, STRING_AS_LONGOBJ_JAVA);
	}

	private static final String STRING_AS_FLOAT_SARL = multilineString(
			"class A {",
			"  def fct(left : String) : float {",
			"    left as float",
			"  }",
			"}");

	private static final String STRING_AS_FLOAT_JAVA = multilineString(
			"import io.sarl.lang.core.annotation.SarlElementType;",
			"import io.sarl.lang.core.annotation.SarlSpecification;",
			"import io.sarl.lang.core.annotation.SyntheticMember;",
			"import io.sarl.lang.core.scoping.extensions.cast.PrimitiveCastExtensions;",
			"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 A {",
			"  @Pure",
			"  public float fct(final String left) {",
			"    return (left == null ? 0 : PrimitiveCastExtensions.floatValue(left));",
			"  }",
			"  ",
			"  @SyntheticMember",
			"  public A() {",
			"    super();",
			"  }",
			"}",
			"");

	@Test
	@Tag("sarlValidation")
	@DisplayName("Parsing: String as float")
	public void string_as_float_issues() throws Exception {
		validate(getValidationHelper(), getInjector(), file(getParseHelper(), STRING_AS_FLOAT_SARL))
		.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,
				"'floatValue'");
	}

	@GlobalCompilationTestContribution
	@Tag("compileToJava")
	@DisplayName("Compiling: String as float")
	public void string_as_float(ResourceSetGlobalCompilationContext ctx) throws Exception {
		ctx.compileTo(STRING_AS_FLOAT_SARL, STRING_AS_FLOAT_JAVA);
	}

	private static final String STRING_AS_FLOATOBJ_SARL = multilineString(
			"class A {",
			"  def fct(left : String) : Float {",
			"    left as Float",
			"  }",
			"}");

	private static final String STRING_AS_FLOATOBJ_JAVA = multilineString(
			"import io.sarl.lang.core.annotation.SarlElementType;",
			"import io.sarl.lang.core.annotation.SarlSpecification;",
			"import io.sarl.lang.core.annotation.SyntheticMember;",
			"import io.sarl.lang.core.scoping.extensions.cast.PrimitiveCastExtensions;",
			"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 A {",
			"  @Pure",
			"  public Float fct(final String left) {",
			"    return (left == null ? null : PrimitiveCastExtensions.toFloat(left));",
			"  }",
			"  ",
			"  @SyntheticMember",
			"  public A() {",
			"    super();",
			"  }",
			"}",
			"");

	@Test
	@Tag("sarlValidation")
	@DisplayName("Parsing: String as Float")
	public void string_as_Float_issues() throws Exception {
		validate(getValidationHelper(), getInjector(), file(getParseHelper(), STRING_AS_FLOATOBJ_SARL))
		.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,
				"'toFloat'");
	}

	@GlobalCompilationTestContribution
	@Tag("compileToJava")
	@DisplayName("Compiling: String as Float")
	public void string_as_Float(ResourceSetGlobalCompilationContext ctx) throws Exception {
		ctx.compileTo(STRING_AS_FLOATOBJ_SARL, STRING_AS_FLOATOBJ_JAVA);
	}

	private static final String STRING_AS_DOUBLE_SARL = multilineString(
			"class A {",
			"  def fct(left : String) : double {",
			"    left as double",
			"  }",
			"}");

	private static final String STRING_AS_DOUBLE_JAVA = multilineString(
			"import io.sarl.lang.core.annotation.SarlElementType;",
			"import io.sarl.lang.core.annotation.SarlSpecification;",
			"import io.sarl.lang.core.annotation.SyntheticMember;",
			"import io.sarl.lang.core.scoping.extensions.cast.PrimitiveCastExtensions;",
			"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 A {",
			"  @Pure",
			"  public double fct(final String left) {",
			"    return (left == null ? 0 : PrimitiveCastExtensions.doubleValue(left));",
			"  }",
			"  ",
			"  @SyntheticMember",
			"  public A() {",
			"    super();",
			"  }",
			"}",
			"");

	@Test
	@Tag("sarlValidation")
	@DisplayName("Parsing: String as double")
	public void string_as_double_issues() throws Exception {
		validate(getValidationHelper(), getInjector(), file(getParseHelper(), STRING_AS_DOUBLE_SARL))
		.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,
				"'doubleValue'");
	}

	@GlobalCompilationTestContribution
	@Tag("compileToJava")
	@DisplayName("Compiling: String as double")
	public void string_as_double(ResourceSetGlobalCompilationContext ctx) throws Exception {
		ctx.compileTo(STRING_AS_DOUBLE_SARL, STRING_AS_DOUBLE_JAVA);
	}

	private static final String STRING_AS_DOUBLEOBJ_SARL = multilineString(
			"class A {",
			"  def fct(left : String) : Double {",
			"    left as Double",
			"  }",
			"}");

	private static final String STRING_AS_DOUBLEOBJ_JAVA = multilineString(
			"import io.sarl.lang.core.annotation.SarlElementType;",
			"import io.sarl.lang.core.annotation.SarlSpecification;",
			"import io.sarl.lang.core.annotation.SyntheticMember;",
			"import io.sarl.lang.core.scoping.extensions.cast.PrimitiveCastExtensions;",
			"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 A {",
			"  @Pure",
			"  public Double fct(final String left) {",
			"    return (left == null ? null : PrimitiveCastExtensions.toDouble(left));",
			"  }",
			"  ",
			"  @SyntheticMember",
			"  public A() {",
			"    super();",
			"  }",
			"}",
			"");

	@Test
	@Tag("sarlValidation")
	@DisplayName("Parsing: String as Double")
	public void string_as_Double_issues() throws Exception {
		validate(getValidationHelper(), getInjector(), file(getParseHelper(), STRING_AS_DOUBLEOBJ_SARL))
		.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,
				"'toDouble'");
	}

	@GlobalCompilationTestContribution
	@Tag("compileToJava")
	@DisplayName("Compiling: String as Double")
	public void string_as_Double(ResourceSetGlobalCompilationContext ctx) throws Exception {
		ctx.compileTo(STRING_AS_DOUBLEOBJ_SARL, STRING_AS_DOUBLEOBJ_JAVA);
	}

	private static final String STRING_AS_ATOMICINTEGER_SARL = multilineString(
			"import java.util.concurrent.atomic.AtomicInteger",
			"class A {",
			"  def fct(left : String) : AtomicInteger {",
			"    left as AtomicInteger",
			"  }",
			"}");

	private static final String STRING_AS_ATOMICINTEGER_JAVA = multilineString(
			"import io.sarl.lang.core.annotation.SarlElementType;",
			"import io.sarl.lang.core.annotation.SarlSpecification;",
			"import io.sarl.lang.core.annotation.SyntheticMember;",
			"import io.sarl.lang.core.scoping.extensions.cast.PrimitiveCastExtensions;",
			"import java.util.concurrent.atomic.AtomicInteger;",
			"import org.eclipse.xtext.xbase.lib.Pure;",
			"import org.eclipse.xtext.xbase.lib.XbaseGenerated;",
			"",
			"@SarlSpecification(\"" + SARLVersion.SPECIFICATION_RELEASE_VERSION_STRING + "\")",
			"@SarlElementType(" + SarlPackage.SARL_CLASS + ")",
