Search in sources :

Example 11 with XtendTypeDeclaration

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

the class AbstractXtendOutlineTreeBuilder method buildMembers.

protected void buildMembers(final JvmDeclaredType inferredType, final JvmDeclaredType baseType, @Extension final IXtendOutlineContext context) {
    EList<JvmMember> _members = inferredType.getMembers();
    for (final JvmMember member : _members) {
        boolean _isProcessed = context.isProcessed(member);
        boolean _not = (!_isProcessed);
        if (_not) {
            if ((member instanceof JvmDeclaredType)) {
                boolean _isShowInherited = context.isShowInherited();
                if (_isShowInherited) {
                    final IXtendOutlineContext typeContext = context.newContext();
                    final EObject sourceElement = this._iXtendJvmAssociations.getPrimarySourceElement(member);
                    if ((sourceElement instanceof XtendTypeDeclaration)) {
                        this.buildType(sourceElement, typeContext);
                    } else {
                        this.buildJvmType(((JvmDeclaredType) member), typeContext);
                    }
                } else {
                    this.buildJvmType(((JvmDeclaredType) member), context);
                }
            } else {
                if ((member instanceof JvmFeature)) {
                    boolean _skipFeature = this.skipFeature(((JvmFeature) member));
                    boolean _not_1 = (!_skipFeature);
                    if (_not_1) {
                        final IXtendOutlineContext featureContext = this.buildFeature(baseType, ((JvmFeature) member), member, context);
                        final Consumer<JvmGenericType> _function = (JvmGenericType it) -> {
                            this.buildJvmType(it, featureContext.newContext());
                        };
                        ((JvmFeature) member).getLocalClasses().forEach(_function);
                    }
                }
            }
            context.markAsProcessed(member);
        }
    }
    boolean _isShowInherited_1 = context.isShowInherited();
    if (_isShowInherited_1) {
        this.buildInheritedMembers(inferredType, context);
    }
}
Also used : JvmFeature(org.eclipse.xtext.common.types.JvmFeature) IXtendOutlineContext(org.eclipse.xtend.ide.common.outline.IXtendOutlineContext) EObject(org.eclipse.emf.ecore.EObject) XtendTypeDeclaration(org.eclipse.xtend.core.xtend.XtendTypeDeclaration) JvmGenericType(org.eclipse.xtext.common.types.JvmGenericType) JvmDeclaredType(org.eclipse.xtext.common.types.JvmDeclaredType) JvmMember(org.eclipse.xtext.common.types.JvmMember)

Example 12 with XtendTypeDeclaration

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

the class ConstantExpressionsInterpreterTest method testConstants_WithStaticImport.

@Test
public void testConstants_WithStaticImport() {
    try {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("import static test.Constants1.* ");
        _builder.newLine();
        _builder.append("class C { ");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("val someString = STRING_CONSTANT");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("val someInt = INT_CONSTANT");
        _builder.newLine();
        _builder.append("}");
        _builder.newLine();
        final XtendFile file = this.file(_builder.toString());
        final XtendField stringField = IterableExtensions.<XtendField>head(Iterables.<XtendField>filter(IterableExtensions.<XtendTypeDeclaration>head(file.getXtendTypes()).getMembers(), XtendField.class));
        final XtendField intField = ((XtendField[]) Conversions.unwrapArray(Iterables.<XtendField>filter(IterableExtensions.<XtendTypeDeclaration>head(file.getXtendTypes()).getMembers(), XtendField.class), XtendField.class))[1];
        Assert.assertEquals(Constants1.STRING_CONSTANT, this.interpreter.evaluate(stringField.getInitialValue(), null));
        Assert.assertEquals(Integer.valueOf(Constants1.INT_CONSTANT), this.interpreter.evaluate(intField.getInitialValue(), null));
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) XtendTypeDeclaration(org.eclipse.xtend.core.xtend.XtendTypeDeclaration) XtendField(org.eclipse.xtend.core.xtend.XtendField) Test(org.junit.Test)

Example 13 with XtendTypeDeclaration

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

the class ProblemSupportTests method testErrorOnDerivedElement.

@Test
public void testErrorOnDerivedElement() {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("class MyClass {");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("String foo = \'foo\'");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    final Procedure1<CompilationUnitImpl> _function = (CompilationUnitImpl it) -> {
        final MutableClassDeclaration derived = it.getTypeLookup().findClass("MyClass");
        it.getProblemSupport().addError(derived, "error on derived element");
        Assert.assertEquals("error on derived element", IterableExtensions.<Resource.Diagnostic>head(it.getXtendFile().eResource().getErrors()).getMessage());
        Resource.Diagnostic _head = IterableExtensions.<Resource.Diagnostic>head(it.getXtendFile().eResource().getErrors());
        Assert.assertEquals(IterableExtensions.<XtendTypeDeclaration>head(it.getXtendFile().getXtendTypes()), ((EObjectDiagnosticImpl) _head).getProblematicObject());
    };
    this.asCompilationUnit(this.validFile(_builder), _function);
}
Also used : EObjectDiagnosticImpl(org.eclipse.xtext.validation.EObjectDiagnosticImpl) CompilationUnitImpl(org.eclipse.xtend.core.macro.declaration.CompilationUnitImpl) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) Resource(org.eclipse.emf.ecore.resource.Resource) XtendTypeDeclaration(org.eclipse.xtend.core.xtend.XtendTypeDeclaration) MutableClassDeclaration(org.eclipse.xtend.lib.macro.declaration.MutableClassDeclaration) Test(org.junit.Test)

Example 14 with XtendTypeDeclaration

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

the class UnloadingTest method testProperUnloading.

@Test
public void testProperUnloading() {
    try {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("class B {");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("def void foo() {");
        _builder.newLine();
        _builder.append("\t\t");
        _builder.append("new A(this)");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("}");
        _builder.newLine();
        _builder.append("}");
        _builder.newLine();
        final String fileB = _builder.toString();
        StringConcatenation _builder_1 = new StringConcatenation();
        _builder_1.append("class A {");
        _builder_1.newLine();
        _builder_1.append("\t");
        _builder_1.append("new (B b) {");
        _builder_1.newLine();
        _builder_1.append("\t");
        _builder_1.append("}");
        _builder_1.newLine();
        _builder_1.append("}");
        _builder_1.newLine();
        final List<XtendFile> parsedFiles = IterableExtensions.<XtendFile>toList(this.files(true, _builder_1.toString(), fileB));
        Resource _eResource = parsedFiles.get(1).eResource();
        final DerivedStateAwareResource resource = ((DerivedStateAwareResource) _eResource);
        final Resource resourceA = IterableExtensions.<XtendFile>head(parsedFiles).eResource();
        resource.reparse(fileB);
        EObject _head = IterableExtensions.<EObject>head(resourceA.getContents());
        final XtendFile file = ((XtendFile) _head);
        XtendTypeDeclaration _head_1 = IterableExtensions.<XtendTypeDeclaration>head(file.getXtendTypes());
        XtendMember _head_2 = IterableExtensions.<XtendMember>head(((XtendClass) _head_1).getMembers());
        Assert.assertNotNull(IterableExtensions.<XtendParameter>head(((XtendConstructor) _head_2).getParameters()).getParameterType().getType().eResource());
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) XtendParameter(org.eclipse.xtend.core.xtend.XtendParameter) DerivedStateAwareResource(org.eclipse.xtext.resource.DerivedStateAwareResource) XtendMember(org.eclipse.xtend.core.xtend.XtendMember) EObject(org.eclipse.emf.ecore.EObject) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) DerivedStateAwareResource(org.eclipse.xtext.resource.DerivedStateAwareResource) Resource(org.eclipse.emf.ecore.resource.Resource) XtendTypeDeclaration(org.eclipse.xtend.core.xtend.XtendTypeDeclaration) Test(org.junit.Test)

Example 15 with XtendTypeDeclaration

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

the class XtendCompiler method needSyntheticSelfVariable.

@Override
protected boolean needSyntheticSelfVariable(XClosure closure, LightweightTypeReference typeRef) {
    JvmType jvmType = typeRef.getType();
    TreeIterator<EObject> closureIterator = closure.eAllContents();
    while (closureIterator.hasNext()) {
        EObject obj1 = closureIterator.next();
        if (obj1 instanceof XClosure) {
            closureIterator.prune();
        } else if (obj1 instanceof XtendTypeDeclaration) {
            TreeIterator<EObject> typeIterator = obj1.eAllContents();
            while (typeIterator.hasNext()) {
                EObject obj2 = typeIterator.next();
                if (obj2 instanceof XClosure) {
                    typeIterator.prune();
                } else if (obj2 instanceof XFeatureCall && isReferenceToSelf((XFeatureCall) obj2, jvmType)) {
                    return true;
                }
            }
            closureIterator.prune();
        }
    }
    return false;
}
Also used : XClosure(org.eclipse.xtext.xbase.XClosure) XFeatureCall(org.eclipse.xtext.xbase.XFeatureCall) EObject(org.eclipse.emf.ecore.EObject) XtendTypeDeclaration(org.eclipse.xtend.core.xtend.XtendTypeDeclaration) JvmType(org.eclipse.xtext.common.types.JvmType) TreeIterator(org.eclipse.emf.common.util.TreeIterator)

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