diff options
Diffstat (limited to 'plugins/org.eclipse.etrice.core.etmap/src/org/eclipse/etrice/core/etmap/formatting/ETMapFormatter.java')
-rw-r--r-- | plugins/org.eclipse.etrice.core.etmap/src/org/eclipse/etrice/core/etmap/formatting/ETMapFormatter.java | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/plugins/org.eclipse.etrice.core.etmap/src/org/eclipse/etrice/core/etmap/formatting/ETMapFormatter.java b/plugins/org.eclipse.etrice.core.etmap/src/org/eclipse/etrice/core/etmap/formatting/ETMapFormatter.java new file mode 100644 index 000000000..3956304a0 --- /dev/null +++ b/plugins/org.eclipse.etrice.core.etmap/src/org/eclipse/etrice/core/etmap/formatting/ETMapFormatter.java @@ -0,0 +1,59 @@ +/******************************************************************************* + * Copyright (c) 2012 protos software gmbh (http://www.protos.de). + * 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 + * + * CONTRIBUTORS: + * Henrik Rentz-Reichert (initial contribution) + * + *******************************************************************************/ + +package org.eclipse.etrice.core.etmap.formatting; + +import org.eclipse.etrice.core.etmap.services.ETMapGrammarAccess; +import org.eclipse.xtext.Keyword; +import org.eclipse.xtext.formatting.impl.AbstractDeclarativeFormatter; +import org.eclipse.xtext.formatting.impl.FormattingConfig; +import org.eclipse.xtext.util.Pair; + +/** + * This class contains custom formatting description. + * + * see : http://www.eclipse.org/Xtext/documentation/latest/xtext.html#formatting + * on how and when to use it + * + * Also see {@link org.eclipse.xtext.xtext.XtextFormattingTokenSerializer} as an example + */ +public class ETMapFormatter extends AbstractDeclarativeFormatter { + + @Override + protected void configureFormatting(FormattingConfig c) { + ETMapGrammarAccess f = (ETMapGrammarAccess) getGrammarAccess(); + + // general + + c.setAutoLinewrap(120); + c.setLinewrap(1).before(f.getSL_COMMENTRule()); + c.setLinewrap(2).before(f.getML_COMMENTRule()); + + for (Pair<Keyword, Keyword> pair : f.findKeywordPairs("{", "}")) { + c.setLinewrap().after(pair.getFirst()); + c.setIndentationIncrement().after(pair.getFirst()); + c.setLinewrap().before(pair.getSecond()); + c.setIndentationDecrement().before(pair.getSecond()); + c.setSpace(" ").between(pair.getFirst(), pair.getSecond()); + } + + for (Keyword k: f.findKeywords("/")) { + c.setNoSpace().around(k); + } + + c.setLinewrap(1).after(f.getImportRule()); + + c.setLinewrap(1).after(f.getMappingRule()); + c.setLinewrap(1).after(f.getSubSystemMappingRule()); + c.setLinewrap(1).after(f.getThreadMappingRule()); + } +} |