use of org.eclipse.xtend2.lib.StringConcatenationClient in project xtext-core by eclipse.
the class GrammarAccessFragment2 method generate.
@Override
public void generate() {
final GuiceModuleAccess.BindingFactory bindingFactory = new GuiceModuleAccess.BindingFactory();
String _name = this.getLanguage().getGrammar().getName();
boolean _notEquals = (!Objects.equal(_name, "org.eclipse.xtext.common.Terminals"));
if (_notEquals) {
TypeReference _typeRef = TypeReference.typeRef(ClassLoader.class);
StringConcatenationClient _client = new StringConcatenationClient() {
@Override
protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
_builder.append("getClass().getClassLoader()");
}
};
bindingFactory.addTypeToInstance(_typeRef, _client);
}
bindingFactory.addTypeToType(TypeReference.typeRef(IGrammarAccess.class), this._grammarAccessExtensions.getGrammarAccess(this.getLanguage().getGrammar())).contributeTo(this.getLanguage().getRuntimeGenModule());
ManifestAccess _manifest = this.getProjectConfig().getRuntime().getManifest();
boolean _tripleNotEquals = (_manifest != null);
if (_tripleNotEquals) {
String _runtimeBasePackage = this._xtextGeneratorNaming.getRuntimeBasePackage(this.getGrammar());
String _runtimeBasePackage_1 = this._xtextGeneratorNaming.getRuntimeBasePackage(this.getGrammar());
String _plus = (_runtimeBasePackage_1 + ".services");
this.getProjectConfig().getRuntime().getManifest().getExportedPackages().addAll(Collections.<String>unmodifiableList(CollectionLiterals.<String>newArrayList(_runtimeBasePackage, _plus)));
}
this.doGenerateGrammarAccess();
this.writeGrammar();
}
use of org.eclipse.xtend2.lib.StringConcatenationClient in project xtext-core by eclipse.
the class GrammarAccessFragment2 method _cache.
protected StringConcatenationClient _cache(final TerminalRule it) {
StringConcatenationClient _client = new StringConcatenationClient() {
@Override
protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
_builder.append("private final ");
_builder.append(TerminalRule.class);
_builder.append(" ");
String _gaRuleAccessorLocalVarName = GrammarAccessFragment2.this.gaRuleAccessorLocalVarName(it);
_builder.append(_gaRuleAccessorLocalVarName);
_builder.append(";");
_builder.newLineIfNotEmpty();
}
};
return _client;
}
use of org.eclipse.xtend2.lib.StringConcatenationClient in project xtext-core by eclipse.
the class GrammarAccessFragment2 method loadElementStatement.
protected StringConcatenationClient loadElementStatement(final AbstractElement ele) {
StringConcatenationClient _client = new StringConcatenationClient() {
@Override
protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
_builder.append("(");
TypeReference _typeRef = TypeReference.typeRef(ele.eClass(), GrammarAccessFragment2.this.getLanguage());
_builder.append(_typeRef);
_builder.append(")");
String _loadElementParentStatement = GrammarAccessFragment2.this.loadElementParentStatement(ele);
_builder.append(_loadElementParentStatement);
_builder.append(".eContents().get(");
int _indexOf = ele.eContainer().eContents().indexOf(ele);
_builder.append(_indexOf);
_builder.append(")");
}
};
return _client;
}
use of org.eclipse.xtend2.lib.StringConcatenationClient in project xtext-core by eclipse.
the class EmfAdaptableProcessor method doTransform.
@Override
public void doTransform(final MutableClassDeclaration annotatedClass, @Extension final TransformationContext context) {
final MutableClassDeclaration adapterClass = context.findClass(this.getAdapterClassName(annotatedClass));
final Procedure1<MutableMethodDeclaration> _function = (MutableMethodDeclaration it) -> {
it.addParameter("emfObject", context.newTypeReference(Notifier.class));
it.setReturnType(context.newTypeReference(annotatedClass));
it.setStatic(true);
StringConcatenationClient _client = new StringConcatenationClient() {
@Override
protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
_builder.append("for (");
_builder.append(Adapter.class);
_builder.append(" adapter : emfObject.eAdapters()) {");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("if (adapter instanceof ");
_builder.append(adapterClass, "\t");
_builder.append(") {");
_builder.newLineIfNotEmpty();
_builder.append("\t\t");
_builder.append("return ((");
_builder.append(adapterClass, "\t\t");
_builder.append(") adapter).get();");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("}");
_builder.newLine();
_builder.append("return null;");
_builder.newLine();
}
};
it.setBody(_client);
};
annotatedClass.addMethod("findInEmfObject", _function);
final Procedure1<MutableMethodDeclaration> _function_1 = (MutableMethodDeclaration it) -> {
it.addParameter("emfObject", context.newTypeReference(Notifier.class));
it.setReturnType(context.newTypeReference(annotatedClass));
it.setStatic(true);
StringConcatenationClient _client = new StringConcatenationClient() {
@Override
protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
_builder.append(List.class);
_builder.append("<");
_builder.append(Adapter.class);
_builder.append("> adapters = emfObject.eAdapters();");
_builder.newLineIfNotEmpty();
_builder.append("for(int i = 0, max = adapters.size(); i < max; i++) {");
_builder.newLine();
_builder.append("\t");
_builder.append(Adapter.class, "\t");
_builder.append(" adapter = adapters.get(i);");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("if (adapter instanceof ");
_builder.append(adapterClass, "\t");
_builder.append(") {");
_builder.newLineIfNotEmpty();
_builder.append("\t\t");
_builder.append("emfObject.eAdapters().remove(i);");
_builder.newLine();
_builder.append("\t\t");
_builder.append("return ((");
_builder.append(adapterClass, "\t\t");
_builder.append(") adapter).get();");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("}");
_builder.newLine();
_builder.append("return null;");
_builder.newLine();
}
};
it.setBody(_client);
};
annotatedClass.addMethod("removeFromEmfObject", _function_1);
final Procedure1<MutableMethodDeclaration> _function_2 = (MutableMethodDeclaration it) -> {
it.addParameter("emfObject", context.newTypeReference(Notifier.class));
it.setReturnType(context.getPrimitiveVoid());
StringConcatenationClient _client = new StringConcatenationClient() {
@Override
protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
String _simpleName = annotatedClass.getSimpleName();
_builder.append(_simpleName);
_builder.append(" result = findInEmfObject(emfObject);");
_builder.newLineIfNotEmpty();
_builder.append("if (result != null)");
_builder.newLine();
_builder.append("\t");
_builder.append("throw new IllegalStateException(\"The given EMF object already contains an adapter for ");
String _simpleName_1 = annotatedClass.getSimpleName();
_builder.append(_simpleName_1, "\t");
_builder.append("\");");
_builder.newLineIfNotEmpty();
_builder.append(adapterClass);
_builder.append(" adapter = new ");
_builder.append(adapterClass);
_builder.append("(this);");
_builder.newLineIfNotEmpty();
_builder.append("emfObject.eAdapters().add(adapter);");
_builder.newLine();
}
};
it.setBody(_client);
};
annotatedClass.addMethod("attachToEmfObject", _function_2);
adapterClass.setExtendedClass(context.newTypeReference(AdapterImpl.class));
final Procedure1<MutableFieldDeclaration> _function_3 = (MutableFieldDeclaration it) -> {
it.setType(context.newTypeReference(annotatedClass));
};
adapterClass.addField("element", _function_3);
final Procedure1<MutableConstructorDeclaration> _function_4 = (MutableConstructorDeclaration it) -> {
it.addParameter("element", context.newTypeReference(annotatedClass));
StringConcatenationClient _client = new StringConcatenationClient() {
@Override
protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
_builder.append("this.element = element;");
_builder.newLine();
}
};
it.setBody(_client);
};
adapterClass.addConstructor(_function_4);
final Procedure1<MutableMethodDeclaration> _function_5 = (MutableMethodDeclaration it) -> {
it.setReturnType(context.newTypeReference(annotatedClass));
StringConcatenationClient _client = new StringConcatenationClient() {
@Override
protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
_builder.append("return this.element;");
_builder.newLine();
}
};
it.setBody(_client);
};
adapterClass.addMethod("get", _function_5);
final Procedure1<MutableMethodDeclaration> _function_6 = (MutableMethodDeclaration it) -> {
it.addAnnotation(context.newAnnotationReference(Override.class));
it.addParameter("object", context.newTypeReference(Object.class));
it.setReturnType(context.getPrimitiveBoolean());
StringConcatenationClient _client = new StringConcatenationClient() {
@Override
protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
_builder.append("return object == ");
_builder.append(annotatedClass);
_builder.append(".class;");
_builder.newLineIfNotEmpty();
}
};
it.setBody(_client);
};
adapterClass.addMethod("isAdapterForType", _function_6);
}
use of org.eclipse.xtend2.lib.StringConcatenationClient in project xtext-core by eclipse.
the class LogProcessor method doTransform.
@Override
public void doTransform(final MutableClassDeclaration cls, @Extension final TransformationContext context) {
final Procedure1<MutableFieldDeclaration> _function = (MutableFieldDeclaration it) -> {
it.setStatic(true);
it.setFinal(true);
it.setType(context.newTypeReference(Logger.class));
StringConcatenationClient _client = new StringConcatenationClient() {
@Override
protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
_builder.append(Logger.class);
_builder.append(".getLogger(");
String _simpleName = cls.getSimpleName();
_builder.append(_simpleName);
_builder.append(".class)");
_builder.newLineIfNotEmpty();
}
};
it.setInitializer(_client);
context.setPrimarySourceElement(it, cls);
};
cls.addField("LOG", _function);
}
Aggregations