use of org.eclipse.xtext.xtext.generator.model.TextFileAccess in project xtext-core by eclipse.
the class WebIntegrationFragment method generateStyleSheet.
protected void generateStyleSheet() {
boolean _isFile = this.getProjectConfig().getWeb().getAssets().isFile("style.css");
if (_isFile) {
return;
}
final TextFileAccess styleFile = this.fileAccessFactory.createTextFile();
styleFile.setPath("style.css");
StringConcatenationClient _client = new StringConcatenationClient() {
@Override
protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
_builder.append("body {");
_builder.newLine();
_builder.append("\t");
_builder.append("width: 100%;");
_builder.newLine();
_builder.append("\t");
_builder.append("height: 100%;");
_builder.newLine();
_builder.append("\t");
_builder.append("overflow: hidden;");
_builder.newLine();
_builder.append("\t");
_builder.append("font: 16px Helvetica,sans-serif;");
_builder.newLine();
_builder.append("}");
_builder.newLine();
_builder.newLine();
_builder.append("a {");
_builder.newLine();
_builder.append("\t");
_builder.append("color: #22a;");
_builder.newLine();
_builder.append("\t");
_builder.append("text-decoration: none;");
_builder.newLine();
_builder.append("}");
_builder.newLine();
_builder.newLine();
_builder.append("a:hover {");
_builder.newLine();
_builder.append("\t");
_builder.append("text-decoration: underline;");
_builder.newLine();
_builder.append("}");
_builder.newLine();
_builder.newLine();
_builder.append(".container {");
_builder.newLine();
_builder.append("\t");
_builder.append("display: block;");
_builder.newLine();
_builder.append("\t");
_builder.append("position: absolute;");
_builder.newLine();
_builder.append("\t");
_builder.append("top: 0;");
_builder.newLine();
_builder.append("\t");
_builder.append("bottom: 0;");
_builder.newLine();
_builder.append("\t");
_builder.append("left: 0;");
_builder.newLine();
_builder.append("\t");
_builder.append("right: 0;");
_builder.newLine();
_builder.append("\t");
_builder.append("margin: 20px;");
_builder.newLine();
_builder.append("}");
_builder.newLine();
_builder.newLine();
_builder.append(".header {");
_builder.newLine();
_builder.append("\t");
_builder.append("display: block;");
_builder.newLine();
_builder.append("\t");
_builder.append("position: absolute;");
_builder.newLine();
_builder.append("\t");
_builder.append("background-color: #e8e8e8;");
_builder.newLine();
_builder.append("\t");
_builder.append("top: 0;");
_builder.newLine();
_builder.append("\t");
_builder.append("left: 0;");
_builder.newLine();
_builder.append("\t");
_builder.append("right: 0;");
_builder.newLine();
_builder.append("\t");
_builder.append("height: 60px;");
_builder.newLine();
_builder.append("\t");
_builder.append("padding: 10px;");
_builder.newLine();
_builder.append("}");
_builder.newLine();
_builder.newLine();
_builder.append(".content {");
_builder.newLine();
_builder.append("\t");
_builder.append("display: block;");
_builder.newLine();
_builder.append("\t");
_builder.append("position: absolute;");
_builder.newLine();
_builder.append("\t");
_builder.append("top: 90px;");
_builder.newLine();
_builder.append("\t");
_builder.append("bottom: 0;");
_builder.newLine();
_builder.append("\t");
_builder.append("left: 0;");
_builder.newLine();
_builder.append("\t");
_builder.append("width: 640px;");
_builder.newLine();
_builder.append("}");
_builder.newLine();
_builder.newLine();
_builder.append("#xtext-editor {");
_builder.newLine();
_builder.append("\t");
_builder.append("display: block;");
_builder.newLine();
_builder.append("\t");
_builder.append("position: absolute;");
_builder.newLine();
_builder.append("\t");
_builder.append("top: 0;");
_builder.newLine();
_builder.append("\t");
_builder.append("bottom: 0;");
_builder.newLine();
_builder.append("\t");
_builder.append("left: 0;");
_builder.newLine();
_builder.append("\t");
_builder.append("right: 0;");
_builder.newLine();
_builder.append("\t");
_builder.append("padding: 4px;");
_builder.newLine();
_builder.append("\t");
_builder.append("border: 1px solid #aaa;");
_builder.newLine();
_builder.append("}");
_builder.newLine();
{
WebIntegrationFragment.Framework _get = WebIntegrationFragment.this.framework.get();
boolean _equals = Objects.equal(_get, WebIntegrationFragment.Framework.ORION);
if (_equals) {
_builder.newLine();
_builder.append("/************* Examples for custom icons *************/");
_builder.newLine();
_builder.newLine();
_builder.append("/* For all elements of type Greeting or its subtypes */ ");
_builder.newLine();
_builder.append("/*");
_builder.newLine();
_builder.append("\t");
_builder.append(".Greeting-icon {");
_builder.newLine();
_builder.append("\t\t");
_builder.append("background-image: url(\'images/Greeting.gif\');");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append(" ");
_builder.append("*/");
_builder.newLine();
_builder.newLine();
_builder.append("/* Only in hovers */ ");
_builder.newLine();
_builder.append("/*");
_builder.newLine();
_builder.append("\t");
_builder.append(".xtext-hover .Greeting-icon {");
_builder.newLine();
_builder.append("\t\t");
_builder.append("background-image: url(\'images/Greeting.gif\');");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append(" ");
_builder.append("*/");
_builder.newLine();
}
}
}
};
styleFile.setContent(_client);
styleFile.writeTo(this.getProjectConfig().getWeb().getAssets());
}
use of org.eclipse.xtext.xtext.generator.model.TextFileAccess in project xtext-core by eclipse.
the class WebIntegrationFragment method generateJsHighlighting.
protected void generateJsHighlighting(final String langId) {
final Set<String> allKeywords = GrammarUtil.getAllKeywords(this.getGrammar());
final ArrayList<String> wordKeywords = CollectionLiterals.<String>newArrayList();
final ArrayList<String> nonWordKeywords = CollectionLiterals.<String>newArrayList();
final Pattern keywordsFilterPattern = Pattern.compile(this.keywordsFilter);
final Pattern wordKeywordPattern = Pattern.compile("\\w(.*\\w)?");
final Function1<String, Boolean> _function = (String it) -> {
return Boolean.valueOf(keywordsFilterPattern.matcher(it).matches());
};
final Consumer<String> _function_1 = (String it) -> {
boolean _matches = wordKeywordPattern.matcher(it).matches();
if (_matches) {
wordKeywords.add(it);
} else {
nonWordKeywords.add(it);
}
};
IterableExtensions.<String>filter(allKeywords, _function).forEach(_function_1);
Collections.<String>sort(wordKeywords);
Collections.<String>sort(nonWordKeywords);
final TextFileAccess jsFile = this.fileAccessFactory.createTextFile();
jsFile.setPath(this.highlightingPath);
WebIntegrationFragment.Framework _get = this.framework.get();
if (_get != null) {
switch(_get) {
case ORION:
final Collection<String> patterns = this.createOrionPatterns(langId, allKeywords);
boolean _isEmpty = wordKeywords.isEmpty();
boolean _not = (!_isEmpty);
if (_not) {
StringConcatenation _builder = new StringConcatenation();
_builder.append("{name: \"keyword.");
_builder.append(langId);
_builder.append("\", match: ");
CharSequence _generateKeywordsRegExp = this.generateKeywordsRegExp();
_builder.append(_generateKeywordsRegExp);
_builder.append("}");
patterns.add(_builder.toString());
}
boolean _isEmpty_1 = nonWordKeywords.isEmpty();
boolean _not_1 = (!_isEmpty_1);
if (_not_1) {
StringConcatenation _builder_1 = new StringConcatenation();
_builder_1.append("{name: \"keyword.extra.");
_builder_1.append(langId);
_builder_1.append("\", match: ");
CharSequence _generateExtraKeywordsRegExp = this.generateExtraKeywordsRegExp();
_builder_1.append(_generateExtraKeywordsRegExp);
_builder_1.append("}");
patterns.add(_builder_1.toString());
}
StringConcatenationClient _client = new StringConcatenationClient() {
@Override
protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
_builder.append("define(");
{
boolean _isNullOrEmpty = StringExtensions.isNullOrEmpty(WebIntegrationFragment.this.highlightingModuleName);
boolean _not = (!_isNullOrEmpty);
if (_not) {
_builder.append("\"");
_builder.append(WebIntegrationFragment.this.highlightingModuleName);
_builder.append("\", ");
}
}
_builder.append("[], function() {");
_builder.newLineIfNotEmpty();
_builder.append("\t");
CharSequence _generateKeywords = WebIntegrationFragment.this.generateKeywords(wordKeywords, nonWordKeywords);
_builder.append(_generateKeywords, "\t");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("return {");
_builder.newLine();
_builder.append("\t\t");
_builder.append("id: \"xtext.");
_builder.append(langId, "\t\t");
_builder.append("\",");
_builder.newLineIfNotEmpty();
_builder.append("\t\t");
_builder.append("contentTypes: [\"xtext/");
_builder.append(langId, "\t\t");
_builder.append("\"],");
_builder.newLineIfNotEmpty();
_builder.append("\t\t");
_builder.append("patterns: [");
_builder.newLine();
_builder.append("\t\t\t");
{
boolean _hasElements = false;
for (final String pattern : patterns) {
if (!_hasElements) {
_hasElements = true;
} else {
_builder.appendImmediate(",\n", "\t\t\t");
}
_builder.append(pattern, "\t\t\t");
}
}
_builder.newLineIfNotEmpty();
_builder.append("\t\t");
_builder.append("]");
_builder.newLine();
_builder.append("\t");
_builder.append("};");
_builder.newLine();
_builder.append("});");
_builder.newLine();
}
};
jsFile.setContent(_client);
break;
case ACE:
final Multimap<String, String> patterns_1 = this.createCodeMirrorPatterns(langId, allKeywords);
boolean _isEmpty_2 = wordKeywords.isEmpty();
boolean _not_2 = (!_isEmpty_2);
if (_not_2) {
StringConcatenation _builder_2 = new StringConcatenation();
_builder_2.append("{token: \"keyword\", regex: ");
CharSequence _generateKeywordsRegExp_1 = this.generateKeywordsRegExp();
_builder_2.append(_generateKeywordsRegExp_1);
_builder_2.append("}");
patterns_1.put("start", _builder_2.toString());
}
boolean _isEmpty_3 = nonWordKeywords.isEmpty();
boolean _not_3 = (!_isEmpty_3);
if (_not_3) {
StringConcatenation _builder_3 = new StringConcatenation();
_builder_3.append("{token: \"keyword\", regex: ");
CharSequence _generateExtraKeywordsRegExp_1 = this.generateExtraKeywordsRegExp();
_builder_3.append(_generateExtraKeywordsRegExp_1);
_builder_3.append("}");
patterns_1.put("start", _builder_3.toString());
}
StringConcatenationClient _client_1 = new StringConcatenationClient() {
@Override
protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
_builder.append("define(");
{
boolean _isNullOrEmpty = StringExtensions.isNullOrEmpty(WebIntegrationFragment.this.highlightingModuleName);
boolean _not = (!_isNullOrEmpty);
if (_not) {
_builder.append("\"");
_builder.append(WebIntegrationFragment.this.highlightingModuleName);
_builder.append("\", ");
}
}
_builder.append("[\"ace/lib/oop\", \"ace/mode/text\", \"ace/mode/text_highlight_rules\"], function(oop, mText, mTextHighlightRules) {");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("var HighlightRules = function() {");
_builder.newLine();
_builder.append("\t\t");
CharSequence _generateKeywords = WebIntegrationFragment.this.generateKeywords(wordKeywords, nonWordKeywords);
_builder.append(_generateKeywords, "\t\t");
_builder.newLineIfNotEmpty();
_builder.append("\t\t");
_builder.append("this.$rules = {");
_builder.newLine();
{
Set<String> _keySet = patterns_1.keySet();
boolean _hasElements = false;
for (final String state : _keySet) {
if (!_hasElements) {
_hasElements = true;
} else {
_builder.appendImmediate(",", "\t\t\t");
}
_builder.append("\t\t\t");
_builder.append("\"");
_builder.append(state, "\t\t\t");
_builder.append("\": [");
_builder.newLineIfNotEmpty();
_builder.append("\t\t\t");
_builder.append("\t");
{
Collection<String> _get = patterns_1.get(state);
boolean _hasElements_1 = false;
for (final String rule : _get) {
if (!_hasElements_1) {
_hasElements_1 = true;
} else {
_builder.appendImmediate(",\n", "\t\t\t\t");
}
_builder.append(rule, "\t\t\t\t");
}
}
_builder.newLineIfNotEmpty();
_builder.append("\t\t\t");
_builder.append("]");
_builder.newLine();
}
}
_builder.append("\t\t");
_builder.append("};");
_builder.newLine();
_builder.append("\t");
_builder.append("};");
_builder.newLine();
_builder.append("\t");
_builder.append("oop.inherits(HighlightRules, mTextHighlightRules.TextHighlightRules);");
_builder.newLine();
_builder.append("\t");
_builder.newLine();
_builder.append("\t");
_builder.append("var Mode = function() {");
_builder.newLine();
_builder.append("\t\t");
_builder.append("this.HighlightRules = HighlightRules;");
_builder.newLine();
_builder.append("\t");
_builder.append("};");
_builder.newLine();
_builder.append("\t");
_builder.append("oop.inherits(Mode, mText.Mode);");
_builder.newLine();
_builder.append("\t");
_builder.append("Mode.prototype.$id = \"xtext/");
_builder.append(langId, "\t");
_builder.append("\";");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("Mode.prototype.getCompletions = function(state, session, pos, prefix) {");
_builder.newLine();
_builder.append("\t\t");
_builder.append("return [];");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("\t");
_builder.newLine();
_builder.append("\t");
_builder.append("return {");
_builder.newLine();
_builder.append("\t\t");
_builder.append("Mode: Mode");
_builder.newLine();
_builder.append("\t");
_builder.append("};");
_builder.newLine();
_builder.append("});");
_builder.newLine();
}
};
jsFile.setContent(_client_1);
break;
case CODEMIRROR:
final Multimap<String, String> patterns_2 = this.createCodeMirrorPatterns(langId, allKeywords);
boolean _isEmpty_4 = wordKeywords.isEmpty();
boolean _not_4 = (!_isEmpty_4);
if (_not_4) {
StringConcatenation _builder_4 = new StringConcatenation();
_builder_4.append("{token: \"keyword\", regex: ");
CharSequence _generateKeywordsRegExp_2 = this.generateKeywordsRegExp();
_builder_4.append(_generateKeywordsRegExp_2);
_builder_4.append("}");
patterns_2.put("start", _builder_4.toString());
}
boolean _isEmpty_5 = nonWordKeywords.isEmpty();
boolean _not_5 = (!_isEmpty_5);
if (_not_5) {
StringConcatenation _builder_5 = new StringConcatenation();
_builder_5.append("{token: \"keyword\", regex: ");
CharSequence _generateExtraKeywordsRegExp_2 = this.generateExtraKeywordsRegExp();
_builder_5.append(_generateExtraKeywordsRegExp_2);
_builder_5.append("}");
patterns_2.put("start", _builder_5.toString());
}
StringConcatenationClient _client_2 = new StringConcatenationClient() {
@Override
protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
_builder.append("define(");
{
boolean _isNullOrEmpty = StringExtensions.isNullOrEmpty(WebIntegrationFragment.this.highlightingModuleName);
boolean _not = (!_isNullOrEmpty);
if (_not) {
_builder.append("\"");
_builder.append(WebIntegrationFragment.this.highlightingModuleName);
_builder.append("\", ");
}
}
_builder.append("[\"codemirror\", \"codemirror/addon/mode/simple\"], function(CodeMirror, SimpleMode) {");
_builder.newLineIfNotEmpty();
_builder.append("\t");
CharSequence _generateKeywords = WebIntegrationFragment.this.generateKeywords(wordKeywords, nonWordKeywords);
_builder.append(_generateKeywords, "\t");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("CodeMirror.defineSimpleMode(\"xtext/");
_builder.append(langId, "\t");
_builder.append("\", {");
_builder.newLineIfNotEmpty();
{
Set<String> _keySet = patterns_2.keySet();
boolean _hasElements = false;
for (final String state : _keySet) {
if (!_hasElements) {
_hasElements = true;
} else {
_builder.appendImmediate(",", "\t\t");
}
_builder.append("\t\t");
_builder.append(state, "\t\t");
_builder.append(": ");
{
boolean _equals = Objects.equal(state, "meta");
if (_equals) {
_builder.append("{");
} else {
_builder.append("[");
}
}
_builder.newLineIfNotEmpty();
_builder.append("\t\t");
_builder.append("\t");
{
Collection<String> _get = patterns_2.get(state);
boolean _hasElements_1 = false;
for (final String rule : _get) {
if (!_hasElements_1) {
_hasElements_1 = true;
} else {
_builder.appendImmediate(",\n", "\t\t\t");
}
_builder.append(rule, "\t\t\t");
}
}
_builder.newLineIfNotEmpty();
_builder.append("\t\t");
{
boolean _equals_1 = Objects.equal(state, "meta");
if (_equals_1) {
_builder.append("}");
} else {
_builder.append("]");
}
}
_builder.newLineIfNotEmpty();
}
}
_builder.append("\t");
_builder.append("});");
_builder.newLine();
_builder.append("});");
_builder.newLine();
}
};
jsFile.setContent(_client_2);
break;
default:
break;
}
}
jsFile.writeTo(this.getProjectConfig().getWeb().getAssets());
}
use of org.eclipse.xtext.xtext.generator.model.TextFileAccess in project xtext-core by eclipse.
the class WebIntegrationFragment method generateWebXml.
protected void generateWebXml() {
boolean _isFile = this.getProjectConfig().getWeb().getAssets().isFile("WEB-INF/web.xml");
if (_isFile) {
return;
}
final TextFileAccess xmlFile = this.fileAccessFactory.createTextFile();
xmlFile.setPath("WEB-INF/web.xml");
StringConcatenationClient _client = new StringConcatenationClient() {
@Override
protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
_builder.append("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>");
_builder.newLine();
_builder.append("<web-app version=\"");
{
if (WebIntegrationFragment.this.useServlet3Api) {
_builder.append("3.0");
} else {
_builder.append("2.3");
}
}
_builder.append("\">");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("<display-name>Xtext Example Application</display-name>");
_builder.newLine();
_builder.append("\t");
_builder.append("<description>");
_builder.newLine();
_builder.append("\t\t");
_builder.append("This Example demonstrates the usage of Xtext with a servlet container.");
_builder.newLine();
_builder.append("\t");
_builder.append("</description>");
_builder.newLine();
{
boolean _get = WebIntegrationFragment.this.generateServlet.get();
if (_get) {
_builder.append("\t");
_builder.newLine();
_builder.append("\t");
_builder.append("<servlet>");
_builder.newLine();
_builder.append("\t");
_builder.append("\t");
_builder.append("<servlet-name>XtextServices</servlet-name>");
_builder.newLine();
_builder.append("\t");
_builder.append("\t");
_builder.append("<description>");
_builder.newLine();
_builder.append("\t");
_builder.append("\t\t");
_builder.append("Back-end for the DSL-specific services of Xtext.");
_builder.newLine();
_builder.append("\t");
_builder.append("\t");
_builder.append("</description>");
_builder.newLine();
_builder.append("\t");
_builder.append("\t");
_builder.append("<servlet-class>");
TypeReference _servletClass = WebIntegrationFragment.this.getServletClass(WebIntegrationFragment.this.getGrammar());
_builder.append(_servletClass, "\t\t");
_builder.append("</servlet-class>");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("</servlet>");
_builder.newLine();
_builder.append("\t");
_builder.newLine();
_builder.append("\t");
_builder.append("<servlet-mapping>");
_builder.newLine();
_builder.append("\t");
_builder.append("\t");
_builder.append("<servlet-name>XtextServices</servlet-name>");
_builder.newLine();
_builder.append("\t");
_builder.append("\t");
_builder.append("<url-pattern>/xtext-service/*</url-pattern>");
_builder.newLine();
_builder.append("\t");
_builder.append("</servlet-mapping>");
_builder.newLine();
}
}
{
if ((!WebIntegrationFragment.this.useServlet3Api)) {
_builder.append("\t");
_builder.newLine();
_builder.append("\t");
_builder.append("<servlet>");
_builder.newLine();
_builder.append("\t");
_builder.append("\t");
_builder.append("<servlet-name>XtextResourcesServlet</servlet-name>");
_builder.newLine();
_builder.append("\t");
_builder.append("\t");
_builder.append("<servlet-class>org.eclipse.xtext.web.servlet.XtextResourcesServlet</servlet-class>");
_builder.newLine();
_builder.append("\t");
_builder.append("</servlet>");
_builder.newLine();
_builder.append("\t");
_builder.newLine();
_builder.append("\t");
_builder.append("<servlet-mapping>");
_builder.newLine();
_builder.append("\t");
_builder.append("\t");
_builder.append("<servlet-name>XtextResourcesServlet</servlet-name>");
_builder.newLine();
_builder.append("\t");
_builder.append("\t");
_builder.append("<url-pattern>/xtext/*</url-pattern>");
_builder.newLine();
_builder.append("\t");
_builder.append("</servlet-mapping>");
_builder.newLine();
_builder.append("\t");
_builder.newLine();
_builder.append("\t");
_builder.append("<servlet>");
_builder.newLine();
_builder.append("\t");
_builder.append("\t");
_builder.append("<servlet-name>WebjarsServlet</servlet-name>");
_builder.newLine();
_builder.append("\t");
_builder.append("\t");
_builder.append("<servlet-class>org.webjars.servlet.WebjarsServlet</servlet-class>");
_builder.newLine();
_builder.append("\t");
_builder.append("</servlet>");
_builder.newLine();
_builder.append("\t");
_builder.newLine();
_builder.append("\t");
_builder.append("<servlet-mapping>");
_builder.newLine();
_builder.append("\t");
_builder.append("\t");
_builder.append("<servlet-name>WebjarsServlet</servlet-name>");
_builder.newLine();
_builder.append("\t");
_builder.append("\t");
_builder.append("<url-pattern>/webjars/*</url-pattern>");
_builder.newLine();
_builder.append("\t");
_builder.append("</servlet-mapping>");
_builder.newLine();
}
}
{
boolean _get_1 = WebIntegrationFragment.this.generateHtmlExample.get();
if (_get_1) {
_builder.append("\t");
_builder.newLine();
_builder.append("\t");
_builder.append("<welcome-file-list>");
_builder.newLine();
_builder.append("\t");
_builder.append("\t");
_builder.append("<welcome-file>index.html</welcome-file>");
_builder.newLine();
_builder.append("\t");
_builder.append("</welcome-file-list>");
_builder.newLine();
}
}
_builder.append("\t");
_builder.newLine();
_builder.append("\t");
_builder.append("<session-config>");
_builder.newLine();
_builder.append("\t\t");
_builder.append("<session-timeout>30</session-timeout>");
_builder.newLine();
_builder.append("\t");
_builder.append("</session-config>");
_builder.newLine();
_builder.append("</web-app>");
_builder.newLine();
}
};
xmlFile.setContent(_client);
xmlFile.writeTo(this.getProjectConfig().getWeb().getAssets());
}
Aggregations