Search in sources :

Example 41 with XtendTypeDeclaration

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

the class InsertionOffsetTest method checkMethodInsertionOffset.

protected void checkMethodInsertionOffset(final CharSequence model) {
    try {
        final String modelAsString = model.toString();
        final int caretOffset = modelAsString.replace("$", "").indexOf("|");
        final int expectedOffset = modelAsString.replace("|", "").indexOf("$");
        XtendTypeDeclaration _head = IterableExtensions.<XtendTypeDeclaration>head(this.parseHelper.parse(modelAsString.replace("|", "").replace("$", "")).getXtendTypes());
        final XtendClass xtendClass = ((XtendClass) _head);
        Resource _eResource = xtendClass.eResource();
        final XtextResource xtextResource = ((XtextResource) _eResource);
        final EObject caretElement = this._eObjectAtOffsetHelper.resolveContainedElementAt(xtextResource, caretOffset);
        Assert.assertEquals(expectedOffset, this._insertionOffsets.getNewMethodInsertOffset(caretElement, xtendClass));
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : XtendClass(org.eclipse.xtend.core.xtend.XtendClass) EObject(org.eclipse.emf.ecore.EObject) XtendTypeDeclaration(org.eclipse.xtend.core.xtend.XtendTypeDeclaration) XtextResource(org.eclipse.xtext.resource.XtextResource) Resource(org.eclipse.emf.ecore.resource.Resource) XtextResource(org.eclipse.xtext.resource.XtextResource)

Example 42 with XtendTypeDeclaration

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

the class InsertionOffsetTest method checkFieldInsertionOffset.

protected void checkFieldInsertionOffset(final CharSequence model) {
    try {
        final String modelAsString = model.toString();
        final int caretOffset = modelAsString.replace("$", "").indexOf("|");
        final int expectedOffset = modelAsString.replace("|", "").indexOf("$");
        XtendTypeDeclaration _head = IterableExtensions.<XtendTypeDeclaration>head(this.parseHelper.parse(modelAsString.replace("|", "").replace("$", "")).getXtendTypes());
        final XtendClass xtendClass = ((XtendClass) _head);
        Resource _eResource = xtendClass.eResource();
        final XtextResource xtextResource = ((XtextResource) _eResource);
        final EObject caretElement = this._eObjectAtOffsetHelper.resolveContainedElementAt(xtextResource, caretOffset);
        Assert.assertEquals(expectedOffset, this._insertionOffsets.getNewFieldInsertOffset(caretElement, xtendClass));
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : XtendClass(org.eclipse.xtend.core.xtend.XtendClass) EObject(org.eclipse.emf.ecore.EObject) XtendTypeDeclaration(org.eclipse.xtend.core.xtend.XtendTypeDeclaration) XtextResource(org.eclipse.xtext.resource.XtextResource) Resource(org.eclipse.emf.ecore.resource.Resource) XtextResource(org.eclipse.xtext.resource.XtextResource)

Example 43 with XtendTypeDeclaration

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

the class DependentElementsCalculatorTests method testDependentElements.

@Test
public void testDependentElements() {
    try {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("class Foo {");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("def Foo foo() {");
        _builder.newLine();
        _builder.append("\t\t");
        _builder.append("new Foo()");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("}");
        _builder.newLine();
        _builder.append("}");
        _builder.newLine();
        final XtendFile file = this.testHelper.xtendFile("Foo", _builder.toString());
        XtendTypeDeclaration _get = file.getXtendTypes().get(0);
        final XtendClass fooClass = ((XtendClass) _get);
        NullProgressMonitor _nullProgressMonitor = new NullProgressMonitor();
        final Iterable<URI> dependentElementURIs = this.dependentElementsCalculator.getDependentElementURIs(fooClass, _nullProgressMonitor);
        Assert.assertEquals(3, IterableExtensions.size(dependentElementURIs));
        XtendMember _get_1 = fooClass.getMembers().get(0);
        final XtendFunction fooFunction = ((XtendFunction) _get_1);
        final Consumer<EObject> _function = (EObject it) -> {
            final Function1<URI, Boolean> _function_1 = (URI element) -> {
                URI _uRI = EcoreUtil.getURI(it);
                return Boolean.valueOf(Objects.equal(element, _uRI));
            };
            Assert.assertTrue(it.toString(), IterableExtensions.<URI>exists(dependentElementURIs, _function_1));
        };
        CollectionLiterals.<EObject>newArrayList(fooFunction, this.associations.getInferredType(fooClass), this.associations.getInferredConstructor(fooClass)).forEach(_function);
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) XtendMember(org.eclipse.xtend.core.xtend.XtendMember) Function1(org.eclipse.xtext.xbase.lib.Functions.Function1) URI(org.eclipse.emf.common.util.URI) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) EObject(org.eclipse.emf.ecore.EObject) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) XtendTypeDeclaration(org.eclipse.xtend.core.xtend.XtendTypeDeclaration) Test(org.junit.Test)

Example 44 with XtendTypeDeclaration

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

the class AbstractMultiModeOutlineTreeProvider method computeDecoratedText.

protected Object computeDecoratedText(final Object modelElement, final int inheritanceDepth) {
    Object supertext = super.getText(modelElement);
    if (!(supertext instanceof StyledString)) {
        return supertext;
    }
    StyledString styledText = (StyledString) supertext;
    if (inheritanceDepth > 0) {
        styledText = applyStylerToFirstSegment(styledText, ColoringLabelProvider.INHERITED_STYLER);
    }
    if (modelElement instanceof JvmIdentifiableElement) {
        JvmIdentifiableElement jvmElement = (JvmIdentifiableElement) modelElement;
        if (!getAssociations().getSourceElements(jvmElement).isEmpty() && !getAssociations().isPrimaryJvmElement(jvmElement)) {
            styledText = applyStylerToFirstSegment(styledText, StyledString.QUALIFIER_STYLER);
        }
    }
    if (isShowInherited()) {
        if (modelElement instanceof IResolvedFeature) {
            String qualifier = createQualifier((IResolvedFeature) modelElement);
            appendQualifier(styledText, qualifier);
        } else if (modelElement instanceof JvmMember) {
            String qualifier = createQualifier((JvmMember) modelElement);
            appendQualifier(styledText, qualifier);
        } else if (modelElement instanceof XtendMember) {
            XtendMember xtendMember = (XtendMember) modelElement;
            if (xtendMember.eContainer() instanceof XtendTypeDeclaration) {
                String qualifiedName = createQualifier((XtendTypeDeclaration) xtendMember.eContainer(), '.');
                appendQualifier(styledText, qualifiedName);
            } else if (xtendMember instanceof XtendTypeDeclaration) {
                XtendFile xtendFile = EcoreUtil2.getContainerOfType(xtendMember, XtendFile.class);
                String qualifiedName = xtendFile.getPackage() == null ? "(default package)" : xtendFile.getPackage();
                appendQualifier(styledText, qualifiedName);
            }
        }
    }
    return styledText;
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) JvmIdentifiableElement(org.eclipse.xtext.common.types.JvmIdentifiableElement) XtendMember(org.eclipse.xtend.core.xtend.XtendMember) XtendTypeDeclaration(org.eclipse.xtend.core.xtend.XtendTypeDeclaration) EObject(org.eclipse.emf.ecore.EObject) JvmMember(org.eclipse.xtext.common.types.JvmMember) StyledString(org.eclipse.jface.viewers.StyledString) StyledString(org.eclipse.jface.viewers.StyledString) IResolvedFeature(org.eclipse.xtext.xbase.typesystem.override.IResolvedFeature)

Example 45 with XtendTypeDeclaration

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

the class AbstractMultiModeOutlineTreeProvider method createQualifier.

private String createQualifier(XtendTypeDeclaration xtendType, char innerClassDelimiter) {
    if (xtendType.getName() == null)
        return null;
    XtendTypeDeclaration declaringType = null;
    if (xtendType.eContainer() instanceof XtendTypeDeclaration) {
        declaringType = (XtendTypeDeclaration) xtendType.eContainer();
    }
    if (declaringType == null) {
        return xtendType.getName();
    }
    String qualifier = xtendType.getName();
    while (xtendType.eContainer() instanceof XtendTypeDeclaration) {
        XtendTypeDeclaration parent = (XtendTypeDeclaration) xtendType.eContainer();
        qualifier = parent.getName() + innerClassDelimiter + qualifier;
        xtendType = parent;
    }
    return qualifier;
}
Also used : XtendTypeDeclaration(org.eclipse.xtend.core.xtend.XtendTypeDeclaration) StyledString(org.eclipse.jface.viewers.StyledString)

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