Search in sources :

Example 6 with DomainModel

use of org.eclipse.xtext.example.domainmodel.domainmodel.DomainModel in project xtext-eclipse by eclipse.

the class ValidationTests method testDuplicatedOperation.

@Test
public void testDuplicatedOperation() throws Exception {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("entity E {");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("op foo() {}");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("op foo() {}");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    final String model = _builder.toString();
    DomainModel _parse = this._parseHelper.parse(model);
    final Procedure1<DomainModel> _function = (DomainModel it) -> {
        this.assertNumberOfIssues(it, 2);
        this._validationTestHelper.assertError(it, DomainmodelPackage.Literals.OPERATION, org.eclipse.xtext.example.domainmodel.validation.IssueCodes.DUPLICATE_OPERATION, model.indexOf("foo"), 3, "Duplicate operation foo");
        this._validationTestHelper.assertError(it, DomainmodelPackage.Literals.OPERATION, org.eclipse.xtext.example.domainmodel.validation.IssueCodes.DUPLICATE_OPERATION, model.lastIndexOf("foo"), 3, "Duplicate operation foo");
    };
    ObjectExtensions.<DomainModel>operator_doubleArrow(_parse, _function);
}
Also used : DomainModel(org.eclipse.xtext.example.domainmodel.domainmodel.DomainModel) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) Test(org.junit.Test)

Example 7 with DomainModel

use of org.eclipse.xtext.example.domainmodel.domainmodel.DomainModel in project xtext-eclipse by eclipse.

the class ValidationTests method testDuplicatedOperationWithDifferentSignatureWithSameTypeErasure.

@Test
public void testDuplicatedOperationWithDifferentSignatureWithSameTypeErasure() throws Exception {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("entity E {");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("op m(java.util.List<String> l1) {}");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("op m(java.util.List<Integer> l2) {}");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    final String model = _builder.toString();
    DomainModel _parse = this._parseHelper.parse(model);
    final Procedure1<DomainModel> _function = (DomainModel it) -> {
        this.assertNumberOfIssues(it, 2);
        this._validationTestHelper.assertError(it, DomainmodelPackage.Literals.OPERATION, org.eclipse.xtext.example.domainmodel.validation.IssueCodes.DUPLICATE_OPERATION, model.indexOf("m"), 1, "Duplicate operation m");
        this._validationTestHelper.assertError(it, DomainmodelPackage.Literals.OPERATION, org.eclipse.xtext.example.domainmodel.validation.IssueCodes.DUPLICATE_OPERATION, model.lastIndexOf("m"), 1, "Duplicate operation m");
    };
    ObjectExtensions.<DomainModel>operator_doubleArrow(_parse, _function);
}
Also used : DomainModel(org.eclipse.xtext.example.domainmodel.domainmodel.DomainModel) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) Test(org.junit.Test)

Example 8 with DomainModel

use of org.eclipse.xtext.example.domainmodel.domainmodel.DomainModel in project xtext-eclipse by eclipse.

the class ValidationTests method testDuplicatedProperty.

@Test
public void testDuplicatedProperty() throws Exception {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("entity E {");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("p : String");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("p : String");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    final String model = _builder.toString();
    DomainModel _parse = this._parseHelper.parse(model);
    final Procedure1<DomainModel> _function = (DomainModel it) -> {
        this.assertNumberOfIssues(it, 2);
        this._validationTestHelper.assertError(it, DomainmodelPackage.Literals.PROPERTY, org.eclipse.xtext.example.domainmodel.validation.IssueCodes.DUPLICATE_PROPERTY, model.indexOf("p"), 1, "Duplicate property p");
        this._validationTestHelper.assertError(it, DomainmodelPackage.Literals.PROPERTY, org.eclipse.xtext.example.domainmodel.validation.IssueCodes.DUPLICATE_PROPERTY, model.lastIndexOf("p"), 1, "Duplicate property p");
    };
    ObjectExtensions.<DomainModel>operator_doubleArrow(_parse, _function);
}
Also used : DomainModel(org.eclipse.xtext.example.domainmodel.domainmodel.DomainModel) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) Test(org.junit.Test)

Example 9 with DomainModel

use of org.eclipse.xtext.example.domainmodel.domainmodel.DomainModel in project xtext-eclipse by eclipse.

the class OrganizeImportsTest method assertIsOrganizedTo.

protected void assertIsOrganizedTo(final CharSequence model, final CharSequence expected) throws Exception {
    final DomainModel domainModel = this._parseHelper.parse(model.toString());
    Resource _eResource = domainModel.eResource();
    final List<ReplaceRegion> changes = this.importOrganizer.getOrganizedImportChanges(((XtextResource) _eResource));
    final StringBuilder builder = new StringBuilder(model);
    final Function1<ReplaceRegion, Integer> _function = (ReplaceRegion it) -> {
        return Integer.valueOf(it.getOffset());
    };
    final List<ReplaceRegion> sortedChanges = IterableExtensions.<ReplaceRegion, Integer>sortBy(changes, _function);
    ReplaceRegion lastChange = null;
    for (final ReplaceRegion it : sortedChanges) {
        {
            if (((lastChange != null) && (lastChange.getEndOffset() > it.getOffset()))) {
                Assert.fail(((("Overlapping text edits: " + lastChange) + " and ") + it));
            }
            lastChange = it;
        }
    }
    List<ReplaceRegion> _reverse = ListExtensions.<ReplaceRegion>reverse(sortedChanges);
    for (final ReplaceRegion it_1 : _reverse) {
        int _offset = it_1.getOffset();
        int _offset_1 = it_1.getOffset();
        int _length = it_1.getLength();
        int _plus = (_offset_1 + _length);
        builder.replace(_offset, _plus, it_1.getText());
    }
    Assert.assertEquals(expected.toString(), builder.toString());
}
Also used : DomainModel(org.eclipse.xtext.example.domainmodel.domainmodel.DomainModel) ReplaceRegion(org.eclipse.xtext.util.ReplaceRegion) XtextResource(org.eclipse.xtext.resource.XtextResource) Resource(org.eclipse.emf.ecore.resource.Resource) XtextResource(org.eclipse.xtext.resource.XtextResource)

Aggregations

DomainModel (org.eclipse.xtext.example.domainmodel.domainmodel.DomainModel)9 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)5 Test (org.junit.Test)5 AbstractElement (org.eclipse.xtext.example.domainmodel.domainmodel.AbstractElement)3 Entity (org.eclipse.xtext.example.domainmodel.domainmodel.Entity)3 PackageDeclaration (org.eclipse.xtext.example.domainmodel.domainmodel.PackageDeclaration)3 Feature (org.eclipse.xtext.example.domainmodel.domainmodel.Feature)2 Operation (org.eclipse.xtext.example.domainmodel.domainmodel.Operation)2 Property (org.eclipse.xtext.example.domainmodel.domainmodel.Property)2 Method (java.lang.reflect.Method)1 EObject (org.eclipse.emf.ecore.EObject)1 EPackage (org.eclipse.emf.ecore.EPackage)1 Resource (org.eclipse.emf.ecore.resource.Resource)1 Action (org.eclipse.xtext.Action)1 Parameter (org.eclipse.xtext.Parameter)1 ParserRule (org.eclipse.xtext.ParserRule)1 JvmFormalParameter (org.eclipse.xtext.common.types.JvmFormalParameter)1 JvmLowerBound (org.eclipse.xtext.common.types.JvmLowerBound)1 JvmOperation (org.eclipse.xtext.common.types.JvmOperation)1 JvmParameterizedTypeReference (org.eclipse.xtext.common.types.JvmParameterizedTypeReference)1