Java Code Examples for org.eclipse.xtext.xbase.compiler.DocumentationAdapter

The following examples show how to use org.eclipse.xtext.xbase.compiler.DocumentationAdapter. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: xtext-extras   Source File: JvmTypesBuilder.java    License: Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Attaches the given documentation of the source element to the given jvmElement.
 * 
 * The documentation is computed lazily.
 */
public void copyDocumentationTo(/* @Nullable */ final EObject source, /* @Nullable */ JvmIdentifiableElement jvmElement) {
	if(source == null || jvmElement == null)
		return;
	
	DocumentationAdapter documentationAdapter = new DocumentationAdapter() {
		private boolean computed = false;
		@Override
		public String getDocumentation() {
			if (computed) {
				return super.getDocumentation();
			}
			String result = JvmTypesBuilder.this.getDocumentation(source);
			setDocumentation(result);
			return result;
		}
		@Override
		public void setDocumentation(String documentation) {
			computed = true;
			super.setDocumentation(documentation);
		}
	};
	jvmElement.eAdapters().add(documentationAdapter);
}
 
Example 2
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);
}
 
Example 3
Source Project: sarl   Source File: SarlDocumentationProvider.java    License: Apache License 2.0 6 votes vote down vote up
public String getDocumentation(EObject o) {
	// Get the documentation from the Xtext grammar hidden nodes.
	String text = super.getDocumentation(o);
	if (text == null) {
		// Get the grammar from the Ecore model element.
		if (o instanceof EModelElement) {
			text = EcoreUtil.getDocumentation((EModelElement) o);
		}
		if (text == null) {
			// Get the grammar from the code builder extension.
			DocumentationAdapter adapter = (DocumentationAdapter) EcoreUtil.getAdapter(
					o.eAdapters(), DocumentationAdapter.class);
			if (adapter != null) {
				return adapter.getDocumentation();
			}
		}
	}
	return text;
}
 
Example 4
Source Project: xtext-extras   Source File: JvmTypesBuilder.java    License: Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Retrieves the attached documentation for the given source element.
 * By default this implementation provides the text of a multi line comment preceding the definition of the given source element.
 * 
 * @return the documentation of the given source, <code>null</code> if source is <code>null</code> or doesn't have any documentation.
 */
/* @Nullable */
public String getDocumentation(/* @Nullable */ EObject source) {
	if (source == null)
		return null;
	if (source instanceof JvmIdentifiableElement) {
		DocumentationAdapter adapter = (DocumentationAdapter) EcoreUtil.getAdapter(source.eAdapters(), DocumentationAdapter.class);
		if (adapter != null)
			return adapter.getDocumentation();
	}
	String documentation = documentationProvider.getDocumentation(source);
	return documentation;
}
 
Example 5
Source Project: xtext-extras   Source File: JvmTypesBuilder.java    License: Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Attaches the given documentation to the given jvmElement.
 */
public void setDocumentation(/* @Nullable */ JvmIdentifiableElement jvmElement, /* @Nullable */ String documentation) {
	if(jvmElement == null || documentation == null)
		return;
	DocumentationAdapter documentationAdapter = new DocumentationAdapter();
	documentationAdapter.setDocumentation(documentation);
	jvmElement.eAdapters().add(documentationAdapter);
}
 
Example 6
@Override
protected void handleSaveEObject(final InternalEObject object, final BinaryResourceImpl.EObjectOutputStream out) throws IOException {
  super.handleSaveEObject(object, out);
  DocumentationAdapter documentationAdapter = null;
  JvmIdentifiableMetaData metaDataAdapter = null;
  EList<Adapter> _eAdapters = object.eAdapters();
  for (final Adapter adapter : _eAdapters) {
    {
      if ((adapter instanceof DocumentationAdapter)) {
        documentationAdapter = ((DocumentationAdapter)adapter);
      }
      if ((adapter instanceof JvmIdentifiableMetaData)) {
        metaDataAdapter = ((JvmIdentifiableMetaData)adapter);
      }
    }
  }
  if ((documentationAdapter != null)) {
    out.writeBoolean(true);
    out.writeString(documentationAdapter.getDocumentation());
  } else {
    out.writeBoolean(false);
  }
  if ((metaDataAdapter != null)) {
    out.writeBoolean(true);
    out.writeBoolean(metaDataAdapter.isSynthetic());
  } else {
    out.writeBoolean(false);
  }
}
 
Example 7
Source Project: xtext-extras   Source File: JvmModelGenerator.java    License: Eclipse Public License 2.0 5 votes vote down vote up
public void generateJavaDoc(final EObject it, final ITreeAppendable appendable, final GeneratorConfig config) {
  final DocumentationAdapter adapter = IterableExtensions.<DocumentationAdapter>head(Iterables.<DocumentationAdapter>filter(it.eAdapters(), DocumentationAdapter.class));
  if (((adapter != null) && (!StringExtensions.isNullOrEmpty(adapter.getDocumentation())))) {
    final Set<EObject> sourceElements = this.getSourceElements(it);
    if (((sourceElements.size() == 1) && (this.documentationProvider instanceof IEObjectDocumentationProviderExtension))) {
      final List<INode> documentationNodes = ((IEObjectDocumentationProviderExtension) this.documentationProvider).getDocumentationNodes(IterableExtensions.<EObject>head(sourceElements));
      this.addJavaDocImports(it, appendable, documentationNodes);
      this.generateDocumentation(adapter.getDocumentation(), documentationNodes, appendable, config);
    } else {
      this.generateDocumentation(adapter.getDocumentation(), CollectionLiterals.<INode>emptyList(), appendable, config);
    }
  }
}
 
Example 8
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();
}
 
Example 9
@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;
}
 
Example 10
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);
}
 
Example 11
protected void emitDocumentation(EObject semanticObject) {
	if (this.documentedSemanticObjects.add(semanticObject)) {
		DocumentationAdapter documentationAdapter = (DocumentationAdapter) EcoreUtil.getAdapter(semanticObject.eAdapters(), DocumentationAdapter.class);
		if (documentationAdapter != null) {
			emitDocumentation(semanticObject.getClass(), documentationAdapter.getDocumentation());
		}
	}
}
 
Example 12
protected DocumentationAdapter getDocumentationAdapter(EObject object) {
	return (DocumentationAdapter) EcoreUtil.getAdapter(object.eAdapters(), DocumentationAdapter.class);
}
 
Example 13
Source Project: xtext-xtend   Source File: ResourceStorageTest.java    License: Eclipse Public License 2.0 4 votes vote down vote up
@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);
  }
}
 
Example 14
Source Project: sarl   Source File: AbstractSubCodeBuilderFragment.java    License: Apache License 2.0 4 votes vote down vote up
/** Replies the adapter for pre documentation.
 *
 * @return the adapter.
 */
@SuppressWarnings("static-method")
@Pure
protected TypeReference getPreDocumentationAdapter() {
	return new TypeReference(DocumentationAdapter.class);
}