Search in sources :

Example 71 with XtendTypeDeclaration

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

the class AccessRestrictionInWorkspaceTest method testReexported.

@Test
public void testReexported() {
    try {
        final XtendFile xtendFile = this.parse(IResourcesSetupUtil.createFile("thirdProject/src/Dummy.xtend", "class D { allowed.C c }"));
        XtendTypeDeclaration _head = IterableExtensions.<XtendTypeDeclaration>head(xtendFile.getXtendTypes());
        final XtendClass c = ((XtendClass) _head);
        this._validationTestHelper.assertNoError(c, IssueCodes.DISCOURAGED_REFERENCE);
        this._validationTestHelper.assertNoError(c, IssueCodes.FORBIDDEN_REFERENCE);
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) XtendTypeDeclaration(org.eclipse.xtend.core.xtend.XtendTypeDeclaration) Test(org.junit.Test)

Example 72 with XtendTypeDeclaration

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

the class AccessRestrictionInWorkspaceTest method testDiscouragedReferenceInOtherProject.

@Test
public void testDiscouragedReferenceInOtherProject() {
    try {
        final XtendFile xtendFile = this.parse(IResourcesSetupUtil.createFile("secondProject/src/Dummy.xtend", "class D { discouraged.B b }"));
        XtendTypeDeclaration _head = IterableExtensions.<XtendTypeDeclaration>head(xtendFile.getXtendTypes());
        final XtendClass c = ((XtendClass) _head);
        this._validationTestHelper.assertWarning(c, TypesPackage.Literals.JVM_TYPE_REFERENCE, IssueCodes.DISCOURAGED_REFERENCE, "Discouraged access: The type B is not accessible", "on required project firstProject");
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) XtendTypeDeclaration(org.eclipse.xtend.core.xtend.XtendTypeDeclaration) Test(org.junit.Test)

Example 73 with XtendTypeDeclaration

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

the class XtendValidator method checkModifiers.

@Check
protected void checkModifiers(XtendConstructor constructor) {
    if (!(constructor.getDeclaringType() instanceof XtendClass)) {
        error("Contructors are only permitted within classes", null, CONSTRUCTOR_NOT_PERMITTED);
    } else {
        String typeName = ((XtendTypeDeclaration) constructor.eContainer()).getName();
        constructorModifierValidator.checkModifiers(constructor, "type " + typeName);
    }
}
Also used : XtendClass(org.eclipse.xtend.core.xtend.XtendClass) XtendTypeDeclaration(org.eclipse.xtend.core.xtend.XtendTypeDeclaration) RichString(org.eclipse.xtend.core.xtend.RichString) Check(org.eclipse.xtext.validation.Check)

Example 74 with XtendTypeDeclaration

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

the class XtendValidator method getOutermostType.

/**
 * Replies the outer-most type of the given member.
 * @return the container of {@code XtendTypeDeclaration} type if it exists, or the direct container.
 */
protected final EObject getOutermostType(XtendMember member) {
    XtendTypeDeclaration result = EcoreUtil2.getContainerOfType(member, XtendTypeDeclaration.class);
    if (result == null) {
        return member.eContainer();
    }
    while (!(result.eContainer() instanceof XtendFile)) {
        XtendTypeDeclaration next = EcoreUtil2.getContainerOfType(result.eContainer(), XtendTypeDeclaration.class);
        if (next == null) {
            return result;
        }
        result = next;
    }
    return result;
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) XtendTypeDeclaration(org.eclipse.xtend.core.xtend.XtendTypeDeclaration)

Example 75 with XtendTypeDeclaration

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

the class XtendFormatter method _format.

protected void _format(final XtendFile xtendFile, @Extension final IFormattableDocument format) {
    final Procedure1<IHiddenRegionFormatter> _function = (IHiddenRegionFormatter it) -> {
        it.noSpace();
    };
    format.<XtendFile>prepend(xtendFile, _function);
    final ISemanticRegion pkg = this.textRegionExtensions.regionFor(xtendFile).feature(XtendPackage.Literals.XTEND_FILE__PACKAGE);
    if ((pkg != null)) {
        final Procedure1<IHiddenRegionFormatter> _function_1 = (IHiddenRegionFormatter it) -> {
            it.oneSpace();
        };
        format.prepend(pkg, _function_1);
        final ISemanticRegion pkgSemicolon = pkg.immediatelyFollowing().keyword(";");
        if ((pkgSemicolon != null)) {
            final Procedure1<IHiddenRegionFormatter> _function_2 = (IHiddenRegionFormatter it) -> {
                it.noSpace();
            };
            format.append(pkg, _function_2);
            format.append(pkgSemicolon, XtendFormatterPreferenceKeys.blankLinesAfterPackageDecl);
        } else {
            format.append(pkg, XtendFormatterPreferenceKeys.blankLinesAfterPackageDecl);
        }
    }
    XImportSection _importSection = xtendFile.getImportSection();
    if (_importSection != null) {
        format.<XImportSection>format(_importSection);
    }
    EList<XtendTypeDeclaration> _xtendTypes = xtendFile.getXtendTypes();
    for (final XtendTypeDeclaration clazz : _xtendTypes) {
        {
            format.<XtendTypeDeclaration>format(clazz);
            XtendTypeDeclaration _last = IterableExtensions.<XtendTypeDeclaration>last(xtendFile.getXtendTypes());
            boolean _notEquals = (!Objects.equal(clazz, _last));
            if (_notEquals) {
                format.<XtendTypeDeclaration>append(clazz, XtendFormatterPreferenceKeys.blankLinesBetweenClasses);
            }
        }
    }
    final Procedure1<IHiddenRegionFormatter> _function_3 = (IHiddenRegionFormatter it) -> {
        it.newLine();
    };
    format.<XtendFile>append(xtendFile, _function_3);
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) IHiddenRegionFormatter(org.eclipse.xtext.formatting2.IHiddenRegionFormatter) XImportSection(org.eclipse.xtext.xtype.XImportSection) XtendTypeDeclaration(org.eclipse.xtend.core.xtend.XtendTypeDeclaration) ISemanticRegion(org.eclipse.xtext.formatting2.regionaccess.ISemanticRegion)

Aggregations

XtendTypeDeclaration (org.eclipse.xtend.core.xtend.XtendTypeDeclaration)134 XtendFile (org.eclipse.xtend.core.xtend.XtendFile)98 Test (org.junit.Test)91 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)77 XtendMember (org.eclipse.xtend.core.xtend.XtendMember)57 XtendFunction (org.eclipse.xtend.core.xtend.XtendFunction)39 XtendClass (org.eclipse.xtend.core.xtend.XtendClass)36 XExpression (org.eclipse.xtext.xbase.XExpression)36 EObject (org.eclipse.emf.ecore.EObject)34 XBlockExpression (org.eclipse.xtext.xbase.XBlockExpression)29 IResolvedTypes (org.eclipse.xtext.xbase.typesystem.IResolvedTypes)19 JvmOperation (org.eclipse.xtext.common.types.JvmOperation)15 XAnnotation (org.eclipse.xtext.xbase.annotations.xAnnotations.XAnnotation)13 Resource (org.eclipse.emf.ecore.resource.Resource)12 XtendField (org.eclipse.xtend.core.xtend.XtendField)12 JvmType (org.eclipse.xtext.common.types.JvmType)11 JvmGenericType (org.eclipse.xtext.common.types.JvmGenericType)10 AnonymousClass (org.eclipse.xtend.core.xtend.AnonymousClass)8 JvmTypeReference (org.eclipse.xtext.common.types.JvmTypeReference)8 XtextResource (org.eclipse.xtext.resource.XtextResource)8