Search in sources :

Example 1 with DocumentationAdapter

use of org.eclipse.xtext.xbase.compiler.DocumentationAdapter in project xtext-eclipse by eclipse.

the class XbaseHoverDocumentationProvider method resolveDocumentation.

protected String resolveDocumentation(EObject object) {
    String documentation = documentationProvider.getDocumentation(object);
    if (documentation != null) {
        return documentation;
    }
    DocumentationAdapter adapter = getDocumentationAdapter(object);
    if (adapter != null) {
        documentation = adapter.getDocumentation();
    }
    if (documentation != null) {
        return documentation;
    }
    EObject primarySourceElement = associations.getPrimarySourceElement(object);
    if (primarySourceElement == null) {
        return null;
    }
    return documentationProvider.getDocumentation(primarySourceElement);
}
Also used : DocumentationAdapter(org.eclipse.xtext.xbase.compiler.DocumentationAdapter) EObject(org.eclipse.emf.ecore.EObject)

Example 2 with DocumentationAdapter

use of org.eclipse.xtext.xbase.compiler.DocumentationAdapter in project xtext-xtend by eclipse.

the class JvmMemberDeclarationImpl method setDocComment.

public void setDocComment(final String docComment) {
    this.checkMutable();
    Adapter _adapter = EcoreUtil.getAdapter(this.getDelegate().eAdapters(), DocumentationAdapter.class);
    DocumentationAdapter adapter = ((DocumentationAdapter) _adapter);
    if ((adapter == null)) {
        DocumentationAdapter _documentationAdapter = new DocumentationAdapter();
        adapter = _documentationAdapter;
        EList<Adapter> _eAdapters = this.getDelegate().eAdapters();
        _eAdapters.add(adapter);
    }
    adapter.setDocumentation(docComment);
}
Also used : DocumentationAdapter(org.eclipse.xtext.xbase.compiler.DocumentationAdapter) Adapter(org.eclipse.emf.common.notify.Adapter) DocumentationAdapter(org.eclipse.xtext.xbase.compiler.DocumentationAdapter)

Example 3 with DocumentationAdapter

use of org.eclipse.xtext.xbase.compiler.DocumentationAdapter in project xtext-xtend by eclipse.

the class ResourceStorageTest method testWriteAndLoad.

@Test
public void testWriteAndLoad() {
    try {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("package foo");
        _builder.newLine();
        _builder.newLine();
        _builder.append("class Bar {");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("def dispatch myMethod(String s) {}");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("/**");
        _builder.newLine();
        _builder.append("\t ");
        _builder.append("* Hello myMethod ");
        _builder.newLine();
        _builder.append("\t ");
        _builder.append("*/");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("def dispatch myMethod(CharSequence cs) {}");
        _builder.newLine();
        _builder.append("}");
        _builder.newLine();
        _builder.append("class Foo {");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("def dispatch other(String it) {");
        _builder.newLine();
        _builder.append("\t\t");
        _builder.append("var x = \"\"");
        _builder.newLine();
        _builder.append("\t\t");
        _builder.append("x = length.toString");
        _builder.newLine();
        _builder.append("\t\t");
        _builder.append("println(x)");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("}");
        _builder.newLine();
        _builder.append("}");
        _builder.newLine();
        final String contents = _builder.toString();
        final XtendFile file = this.file(contents);
        final ByteArrayOutputStream bout = new ByteArrayOutputStream();
        ((ResourceStorageFacade) this.resourceStorageFacade).setStoreNodeModel(true);
        Resource _eResource = file.eResource();
        this.resourceStorageFacade.createResourceStorageWritable(bout).writeResource(((StorageAwareResource) _eResource));
        byte[] _byteArray = bout.toByteArray();
        ByteArrayInputStream _byteArrayInputStream = new ByteArrayInputStream(_byteArray);
        final ResourceStorageLoadable in = this.resourceStorageFacade.createResourceStorageLoadable(_byteArrayInputStream);
        Resource _createResource = file.eResource().getResourceSet().createResource(URI.createURI("synthetic:/test/MyClass.xtend"));
        final StorageAwareResource resource = ((StorageAwareResource) _createResource);
        final InMemoryURIConverter converter = new InMemoryURIConverter();
        converter.addModel(resource.getURI().toString(), contents);
        ResourceSet _resourceSet = resource.getResourceSet();
        _resourceSet.setURIConverter(converter);
        EList<Resource> _resources = file.eResource().getResourceSet().getResources();
        _resources.add(resource);
        resource.loadFromStorage(in);
        EObject _get = resource.getContents().get(1);
        final JvmGenericType jvmClass = ((JvmGenericType) _get);
        Assert.assertEquals("java.lang.CharSequence", IterableExtensions.<JvmFormalParameter>head(((JvmOperation[]) Conversions.unwrapArray(jvmClass.getDeclaredOperations(), JvmOperation.class))[2].getParameters()).getParameterType().getQualifiedName());
        Assert.assertEquals("java.lang.Object", ((JvmOperation[]) Conversions.unwrapArray(jvmClass.getDeclaredOperations(), JvmOperation.class))[2].getReturnType().getQualifiedName());
        Assert.assertEquals("Hello myMethod", IterableExtensions.<DocumentationAdapter>head(Iterables.<DocumentationAdapter>filter(((JvmOperation[]) Conversions.unwrapArray(jvmClass.getDeclaredOperations(), JvmOperation.class))[1].eAdapters(), DocumentationAdapter.class)).getDocumentation());
        Assert.assertEquals(resource.getURI(), resource.getResourceDescription().getURI());
        Assert.assertEquals(2, IterableExtensions.size(resource.getResourceDescription().getExportedObjects()));
        Assert.assertEquals("foo.Bar", IterableExtensions.<IEObjectDescription>head(resource.getResourceDescription().getExportedObjects()).getQualifiedName().toString());
        final BidiTreeIterator<INode> restoredNodes = NodeModelUtils.findActualNodeFor(IterableExtensions.<EObject>head(resource.getContents())).getAsTreeIterable().iterator();
        final BidiTreeIterator<INode> originalNodes = NodeModelUtils.findActualNodeFor(file).getAsTreeIterable().iterator();
        while (restoredNodes.hasNext()) {
            {
                final INode rest = restoredNodes.next();
                final INode orig = originalNodes.next();
                Assert.assertEquals(orig.getStartLine(), rest.getStartLine());
                Assert.assertEquals(orig.getEndLine(), rest.getEndLine());
                Assert.assertEquals(orig.getOffset(), rest.getOffset());
                Assert.assertEquals(orig.getEndOffset(), rest.getEndOffset());
                Assert.assertEquals(orig.getLength(), rest.getLength());
                Assert.assertEquals(orig.getTotalStartLine(), rest.getTotalStartLine());
                Assert.assertEquals(orig.getTotalEndLine(), rest.getTotalEndLine());
                Assert.assertEquals(orig.getTotalOffset(), rest.getTotalOffset());
                Assert.assertEquals(orig.getTotalEndOffset(), rest.getTotalEndOffset());
                Assert.assertEquals(orig.getTotalLength(), rest.getTotalLength());
                Assert.assertSame(orig.getGrammarElement(), rest.getGrammarElement());
                Assert.assertEquals(file.eResource().getURIFragment(orig.getSemanticElement()), resource.getURIFragment(rest.getSemanticElement()));
                Assert.assertEquals(orig.getText(), rest.getText());
            }
        }
        Assert.assertFalse(originalNodes.hasNext());
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) InMemoryURIConverter(org.eclipse.xtend.core.tests.util.InMemoryURIConverter) INode(org.eclipse.xtext.nodemodel.INode) ResourceStorageFacade(org.eclipse.xtext.resource.persistence.ResourceStorageFacade) IResourceStorageFacade(org.eclipse.xtext.resource.persistence.IResourceStorageFacade) Resource(org.eclipse.emf.ecore.resource.Resource) BatchLinkableResource(org.eclipse.xtext.xbase.resource.BatchLinkableResource) StorageAwareResource(org.eclipse.xtext.resource.persistence.StorageAwareResource) JvmGenericType(org.eclipse.xtext.common.types.JvmGenericType) ByteArrayOutputStream(java.io.ByteArrayOutputStream) StorageAwareResource(org.eclipse.xtext.resource.persistence.StorageAwareResource) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) JvmOperation(org.eclipse.xtext.common.types.JvmOperation) DocumentationAdapter(org.eclipse.xtext.xbase.compiler.DocumentationAdapter) ResourceStorageLoadable(org.eclipse.xtext.resource.persistence.ResourceStorageLoadable) ByteArrayInputStream(java.io.ByteArrayInputStream) EObject(org.eclipse.emf.ecore.EObject) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) Test(org.junit.Test)

Example 4 with DocumentationAdapter

use of org.eclipse.xtext.xbase.compiler.DocumentationAdapter in project xtext-xtend by eclipse.

the class XtendHoverDocumentationProvider method resolveDocumentationForJvmElement.

protected String resolveDocumentationForJvmElement(EObject jvmElement) {
    String documentation = documentationProvider.getDocumentation(jvmElement);
    if (documentation != null) {
        return documentation;
    }
    DocumentationAdapter adapter = getDocumentationAdapter(jvmElement);
    return adapter == null ? null : adapter.getDocumentation();
}
Also used : DocumentationAdapter(org.eclipse.xtext.xbase.compiler.DocumentationAdapter)

Example 5 with DocumentationAdapter

use of org.eclipse.xtext.xbase.compiler.DocumentationAdapter in project xtext-xtend by eclipse.

the class JvmMemberDeclarationImpl method getDocComment.

@Override
public String getDocComment() {
    Adapter _adapter = EcoreUtil.getAdapter(this.getDelegate().eAdapters(), DocumentationAdapter.class);
    final DocumentationAdapter adapter = ((DocumentationAdapter) _adapter);
    String _documentation = null;
    if (adapter != null) {
        _documentation = adapter.getDocumentation();
    }
    return _documentation;
}
Also used : DocumentationAdapter(org.eclipse.xtext.xbase.compiler.DocumentationAdapter) Adapter(org.eclipse.emf.common.notify.Adapter) DocumentationAdapter(org.eclipse.xtext.xbase.compiler.DocumentationAdapter)

Aggregations

DocumentationAdapter (org.eclipse.xtext.xbase.compiler.DocumentationAdapter)5 Adapter (org.eclipse.emf.common.notify.Adapter)2 EObject (org.eclipse.emf.ecore.EObject)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 Resource (org.eclipse.emf.ecore.resource.Resource)1 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)1 InMemoryURIConverter (org.eclipse.xtend.core.tests.util.InMemoryURIConverter)1 XtendFile (org.eclipse.xtend.core.xtend.XtendFile)1 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)1 JvmGenericType (org.eclipse.xtext.common.types.JvmGenericType)1 JvmOperation (org.eclipse.xtext.common.types.JvmOperation)1 INode (org.eclipse.xtext.nodemodel.INode)1 IResourceStorageFacade (org.eclipse.xtext.resource.persistence.IResourceStorageFacade)1 ResourceStorageFacade (org.eclipse.xtext.resource.persistence.ResourceStorageFacade)1 ResourceStorageLoadable (org.eclipse.xtext.resource.persistence.ResourceStorageLoadable)1 StorageAwareResource (org.eclipse.xtext.resource.persistence.StorageAwareResource)1 BatchLinkableResource (org.eclipse.xtext.xbase.resource.BatchLinkableResource)1 Test (org.junit.Test)1