Search in sources :

Example 46 with XtendFile

use of org.eclipse.xtend.core.xtend.XtendFile in project xtext-xtend by eclipse.

the class ErrorTest method testErrorModel_012.

@Test
public void testErrorModel_012() throws Exception {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("class Y {");
    _builder.newLine();
    _builder.append(" ");
    _builder.append("static def <T> IExpectationSetters<T> expect(T value) {");
    _builder.newLine();
    _builder.append(" ");
    _builder.append("}");
    _builder.newLine();
    _builder.append(" ");
    _builder.append("HeaderAccess<?> unboundedMockHeaderAccess");
    _builder.newLine();
    _builder.append(" ");
    _builder.append("def test() {");
    _builder.newLine();
    _builder.append("   ");
    _builder.append("val Object header = unboundedMockHeaderAccess.header");
    _builder.newLine();
    _builder.append("   ");
    _builder.append("val IExpectationSettersObject> exp1 = expect(header)");
    _builder.newLine();
    _builder.append("   ");
    _builder.append("val IExpectationSetters<Object> exp2 = expect(unboundedMockHeaderAccess.getHeader())");
    _builder.newLine();
    _builder.append(" ");
    _builder.append("}");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    _builder.append("interface HeaderAccess<T> {");
    _builder.newLine();
    _builder.append("   ");
    _builder.append("def T getHeader();");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    _builder.append("interface IExpectationSetters<T> {}");
    _builder.newLine();
    final XtendFile file = this.processWithoutException(_builder);
    final XtendTypeDeclaration y = IterableExtensions.<XtendTypeDeclaration>head(file.getXtendTypes());
    XtendMember _get = y.getMembers().get(3);
    final XtendField exp1 = ((XtendField) _get);
    final XExpression initializer = exp1.getInitialValue();
    final IResolvedTypes resolvedTypes = this.typeResolver.resolveTypes(initializer);
    Assert.assertNotNull(resolvedTypes.getActualType(initializer));
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) XtendMember(org.eclipse.xtend.core.xtend.XtendMember) IResolvedTypes(org.eclipse.xtext.xbase.typesystem.IResolvedTypes) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) XtendTypeDeclaration(org.eclipse.xtend.core.xtend.XtendTypeDeclaration) XExpression(org.eclipse.xtext.xbase.XExpression) XtendField(org.eclipse.xtend.core.xtend.XtendField) Test(org.junit.Test)

Example 47 with XtendFile

use of org.eclipse.xtend.core.xtend.XtendFile in project xtext-xtend by eclipse.

the class SuspiciousOverloadValidationTest method assertValid.

protected void assertValid(final CharSequence contents) {
    final XtendFile file = this.getParsedXtendFile(contents);
    final EList<Resource.Diagnostic> errors = file.eResource().getErrors();
    Assert.assertEquals(errors.toString(), 0, errors.size());
    this._validationTestHelper.assertNoErrors(file);
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) AbstractDiagnostic(org.eclipse.xtext.diagnostics.AbstractDiagnostic)

Example 48 with XtendFile

use of org.eclipse.xtend.core.xtend.XtendFile in project xtext-xtend by eclipse.

the class ValidationBug398302Test method test_03.

@Test
public void test_03() {
    try {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("import static java.lang.String.*");
        _builder.newLine();
        _builder.append("class C {");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("def m() {");
        _builder.newLine();
        _builder.append("\t\t");
        _builder.append("CASE_INSENSITIVE_ORDER = null");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("}");
        _builder.newLine();
        _builder.append("}");
        _builder.newLine();
        final String s = _builder.toString();
        final XtendFile file = this.parser.parse(s);
        final String fieldName = "CASE_INSENSITIVE_ORDER";
        this.helper.assertError(file, XbasePackage.Literals.XASSIGNMENT, IssueCodes.ASSIGNMENT_TO_FINAL, s.indexOf(fieldName), fieldName.length());
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) Test(org.junit.Test)

Example 49 with XtendFile

use of org.eclipse.xtend.core.xtend.XtendFile in project xtext-xtend by eclipse.

the class ValidationBug398302Test method test_01.

@Test
public void test_01() {
    try {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("class C {");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("def m() {");
        _builder.newLine();
        _builder.append("\t\t");
        _builder.append("String.CASE_INSENSITIVE_ORDER = null");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("}");
        _builder.newLine();
        _builder.append("}");
        _builder.newLine();
        final String s = _builder.toString();
        final XtendFile file = this.parser.parse(s);
        final String fieldName = "CASE_INSENSITIVE_ORDER";
        this.helper.assertError(file, XbasePackage.Literals.XASSIGNMENT, IssueCodes.ASSIGNMENT_TO_FINAL, s.indexOf(fieldName), fieldName.length());
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) Test(org.junit.Test)

Example 50 with XtendFile

use of org.eclipse.xtend.core.xtend.XtendFile in project xtext-xtend by eclipse.

the class ValidationBug398302Test method test_04.

@Test
public void test_04() {
    try {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("class C {");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("val string = \'\'");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("def m() {");
        _builder.newLine();
        _builder.append("\t\t");
        _builder.append("string = null");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("}");
        _builder.newLine();
        _builder.append("}");
        _builder.newLine();
        final String s = _builder.toString();
        final XtendFile file = this.parser.parse(s);
        final String assignment = "string = null";
        this.helper.assertError(file, XbasePackage.Literals.XASSIGNMENT, IssueCodes.ASSIGNMENT_TO_FINAL, s.indexOf(assignment), 6);
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) Test(org.junit.Test)

Aggregations

XtendFile (org.eclipse.xtend.core.xtend.XtendFile)855 Test (org.junit.Test)782 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)372 XtendClass (org.eclipse.xtend.core.xtend.XtendClass)229 XtendFunction (org.eclipse.xtend.core.xtend.XtendFunction)182 XBlockExpression (org.eclipse.xtext.xbase.XBlockExpression)126 XtendMember (org.eclipse.xtend.core.xtend.XtendMember)119 XtendTypeDeclaration (org.eclipse.xtend.core.xtend.XtendTypeDeclaration)98 XExpression (org.eclipse.xtext.xbase.XExpression)82 JvmGenericType (org.eclipse.xtext.common.types.JvmGenericType)64 JvmIdentifiableElement (org.eclipse.xtext.common.types.JvmIdentifiableElement)62 JvmOperation (org.eclipse.xtext.common.types.JvmOperation)62 EObject (org.eclipse.emf.ecore.EObject)50 Resource (org.eclipse.emf.ecore.resource.Resource)47 XMemberFeatureCall (org.eclipse.xtext.xbase.XMemberFeatureCall)46 XAbstractFeatureCall (org.eclipse.xtext.xbase.XAbstractFeatureCall)42 XtextResource (org.eclipse.xtext.resource.XtextResource)34 XFeatureCall (org.eclipse.xtext.xbase.XFeatureCall)29 XtendField (org.eclipse.xtend.core.xtend.XtendField)23 IResolvedTypes (org.eclipse.xtext.xbase.typesystem.IResolvedTypes)21