Skip to content

Instantly share code, notes, and snippets.

View spoenemann's full-sized avatar

Miro Spönemann spoenemann

View GitHub Profile
@spoenemann
spoenemann / DomainModelDiagramSynthesis.xtend
Last active August 29, 2015 14:17
DomainModelDiagramSynthesis
/*******************************************************************************
* Copyright (c) 2015 itemis AG (http://www.itemis.eu) and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*******************************************************************************/
package org.eclipse.xtext.example.domainmodel.view
import com.google.common.collect.ImmutableList
@spoenemann
spoenemann / DomainmodelProposalProvider.xtend
Last active August 29, 2015 14:17
DomainmodelProposalProvider
/*******************************************************************************
* Copyright (c) 2015 itemis AG (http://www.itemis.eu) and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*******************************************************************************/
package org.eclipse.xtext.example.domainmodel.ui.contentassist
import com.google.inject.Inject
@spoenemann
spoenemann / gist:6c7259458e52ff998acf
Last active August 29, 2015 14:21
Configuration code for embedding an Xtext editor in a web page (beta2 version)
<link rel="stylesheet" type="text/css" href="xtext/2.9.0.beta2/xtext.css"/>
<script src="webjars/requirejs/2.1.17/require.min.js"></script>
<script type="text/javascript">
require.config({
paths: {
"text": "webjars/requirejs-text/2.0.10-3/text",
"jquery": "webjars/jquery/2.1.4/jquery.min",
"xtext/xtext": "xtext/2.9.0.beta2/xtext"
}
});
@spoenemann
spoenemann / example_classes.mydsl
Created May 24, 2017 08:34
Simple class DSL example
class Person {
name: string
bag: Bag
getCash(): number {
bag.wallet.cash
}
}
class Bag {
wallet: Wallet
}
@spoenemann
spoenemann / tracing_codegen_1.xtend
Created May 24, 2017 08:36
Entry method of the example code generator with tracing
override void doGenerate(Resource resource, IFileSystemAccess2 fsa, IGeneratorContext context) {
val model = resource.contents.head as Model
val baseName = resource.baseName
fsa.generateTracedFile(baseName + '.h', model, '''
/********************************
* Header file for «resource.URI.lastSegment»
*/
#ifndef «baseName.toUpperCase»_H
#define «baseName.toUpperCase»_H
@spoenemann
spoenemann / tracing_codegen_2.xtend
Created May 24, 2017 08:37
Traced method for translating a class declaration into a C struct
@Traced protected def generateHeader(ClassDeclaration it) '''
/*
* Declaration of «name» class
*/
struct _«_name»
{
«FOR p : members.filter(Property)»
/* Property «name».«p.name» */
«generateDeclaration(p)»
«ENDFOR»
@spoenemann
spoenemann / tracing_codegen_3.xtend
Created May 24, 2017 08:38
Example usage of the TracedAccessors active annotation
@TracedAccessors(MyDslFactory)
class MyDslTraceExtensions {
}
@spoenemann
spoenemann / tracing_codegen_4.xtend
Created May 24, 2017 08:39
Example code that constructs a traced generator subtree
val n = trace(expression)
val receiverVar = expression.receiver?.generateExpression(n, scope)
val resultVar = scope.nextVarName
n.append(generateType(expression.feature?.type))
n.append(' ')
n.append(resultVar)
...
n.append(' = ')
n.append(receiverVar ?: 'this')
n.append('->')
@spoenemann
spoenemann / example_c.txt
Created May 24, 2017 08:40
Example of generated C code
Bag* __local_0 = this->bag;
Wallet* __local_1 = __local_0->wallet;
double __local_2 = __local_1->cash;
@spoenemann
spoenemann / class-service.ts
Last active May 14, 2021 07:24
Comparison of class-based vs. function-based DI service
export const ScopeComputationKey: BindingKey<ScopeComputation> = { id: 'ScopeComputation' };
export class ScopeComputation implements DIService {
private nameProvider: NameProvider;
initialize(services: ServiceHolder): void {
this.nameProvider = services.get(NameProvider);
}