Skip to content
Snippets Groups Projects
Commit ea00de2c authored by Johannes Mey's avatar Johannes Mey
Browse files

add code style settings

parent 2a7ef328
No related branches found
No related tags found
No related merge requests found
package org.jastadd.tooling;
import com.intellij.psi.codeStyle.CodeStyleSettings;
import com.intellij.psi.codeStyle.CustomCodeStyleSettings;
public class RelAstGrammarCodeStyleSettings extends CustomCodeStyleSettings {
public RelAstGrammarCodeStyleSettings(CodeStyleSettings settings) {
super("RelAstGrammarCodeStyleSettings", settings);
}
}
package org.jastadd.tooling;
import com.intellij.application.options.CodeStyleAbstractConfigurable;
import com.intellij.application.options.CodeStyleAbstractPanel;
import com.intellij.application.options.TabbedLanguageCodeStylePanel;
import com.intellij.psi.codeStyle.CodeStyleConfigurable;
import com.intellij.psi.codeStyle.CodeStyleSettings;
import com.intellij.psi.codeStyle.CodeStyleSettingsProvider;
import com.intellij.psi.codeStyle.CustomCodeStyleSettings;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class RelAstGrammarCodeStyleSettingsProvider extends CodeStyleSettingsProvider {
@Override
public CustomCodeStyleSettings createCustomSettings(CodeStyleSettings settings) {
return new RelAstGrammarCodeStyleSettings(settings);
}
@Nullable
@Override
public String getConfigurableDisplayName() {
return "RelAst Grammar";
}
@NotNull
public CodeStyleConfigurable createConfigurable(@NotNull CodeStyleSettings settings, @NotNull CodeStyleSettings modelSettings) {
return new CodeStyleAbstractConfigurable(settings, modelSettings, this.getConfigurableDisplayName()) {
@Override
protected CodeStyleAbstractPanel createPanel(CodeStyleSettings settings) {
return new SimpleCodeStyleMainPanel(getCurrentSettings(), settings);
}
};
}
private static class SimpleCodeStyleMainPanel extends TabbedLanguageCodeStylePanel {
public SimpleCodeStyleMainPanel(CodeStyleSettings currentSettings, CodeStyleSettings settings) {
super(RelAstGrammar.INSTANCE, currentSettings, settings);
}
}
}
......@@ -28,8 +28,7 @@ public class RelAstGrammarFormattingModelBuilder implements FormattingModelBuild
.between(RelAstGrammarTypes.COMPONENT, RelAstGrammarTypes.COMPONENT).spaces(1)
.around(RelAstGrammarTypes.DOT).none()
.before(roleMultiplicityTokens).spaceIf(commonSettings.SPACE_AROUND_UNARY_OPERATOR)
.beforeInside(RelAstGrammarTypes.COL, RelAstGrammarTypes.TYPE_DECL).spaceIf(commonSettings.SPACE_BEFORE_COLON)
.afterInside(RelAstGrammarTypes.COL, RelAstGrammarTypes.TYPE_DECL).spaceIf(commonSettings.SPACE_AFTER_COLON)
.aroundInside(RelAstGrammarTypes.COL, RelAstGrammarTypes.TYPE_DECL).spaceIf(commonSettings.SPACE_AROUND_ADDITIVE_OPERATORS)
.aroundInside(RelAstGrammarTypes.COL, RelAstGrammarTypes.COMPONENT).none()
.withinPair(RelAstGrammarTypes.LT, RelAstGrammarTypes.GT).spaceIf(commonSettings.SPACE_WITHIN_CAST_PARENTHESES)
.withinPair(RelAstGrammarTypes.LBRACKET, RelAstGrammarTypes.RBRACKET).spaceIf(commonSettings.SPACE_WITHIN_BRACKETS)
......
package org.jastadd.tooling;
import com.intellij.lang.Language;
import com.intellij.psi.codeStyle.CodeStyleSettingsCustomizable;
import com.intellij.psi.codeStyle.LanguageCodeStyleSettingsProvider;
import org.jetbrains.annotations.NotNull;
public class RelAstGrammarLanguageCodeStyleSettingsProvider extends LanguageCodeStyleSettingsProvider {
@NotNull
@Override
public Language getLanguage() {
return RelAstGrammar.INSTANCE;
}
@Override
public void customizeSettings(@NotNull CodeStyleSettingsCustomizable consumer, @NotNull SettingsType settingsType) {
if (settingsType == SettingsType.SPACING_SETTINGS) {
consumer.showStandardOptions("SPACE_AROUND_ASSIGNMENT_OPERATORS");
consumer.renameStandardOption("SPACE_AROUND_ASSIGNMENT_OPERATORS", "Production Symbol (::=)");
consumer.showStandardOptions("SPACE_BEFORE_SEMICOLON");
consumer.renameStandardOption("SPACE_BEFORE_SEMICOLON", "Before semicolon");
consumer.showStandardOptions("SPACE_AROUND_RELATIONAL_OPERATORS");
consumer.renameStandardOption("SPACE_AROUND_RELATIONAL_OPERATORS", "Relation Directions (->,<->,<-)");
consumer.showStandardOptions("SPACE_AROUND_UNARY_OPERATOR");
consumer.renameStandardOption("SPACE_AROUND_UNARY_OPERATOR", "Multiplicity Operators (*,?)");
consumer.showStandardOptions("SPACE_AROUND_ADDITIVE_OPERATORS");
consumer.renameStandardOption("SPACE_AROUND_ADDITIVE_OPERATORS", "Superclass separator (:)");
consumer.showStandardOptions("SPACE_WITHIN_CAST_PARENTHESES");
consumer.renameStandardOption("SPACE_WITHIN_CAST_PARENTHESES", "Tokens");
consumer.showStandardOptions("SPACE_WITHIN_BRACKETS");
consumer.renameStandardOption("SPACE_WITHIN_BRACKETS", "Optional components");
} else if (settingsType == SettingsType.BLANK_LINES_SETTINGS) {
consumer.showStandardOptions("KEEP_BLANK_LINES_IN_CODE");
}
}
@Override
public String getCodeSample(@NotNull SettingsType settingsType) {
return "Program ::= GrammarFile* <NameList:java.util.Map<String,String>>;\n" +
"abstract Grammar ::= Declaration*; /* good rule! */\n" +
"GrammarFile : Grammar ::= <FileName> ; // also good rule\n" +
"/** the best rule */\n" +
"abstract Declaration ::= Comment* /Comment/;\n" +
"TypeDecl:Declaration ::= <Name> <Abstract:boolean> Component* [Comment];\n\n\n" +
"rel TypeDecl.SuperType? <-> TypeDecl.SubType*;\n";
}
}
......@@ -48,6 +48,11 @@
<lang.formatter language="JastAddGrammar"
implementationClass="org.jastadd.tooling.RelAstGrammarFormattingModelBuilder"/>
<codeStyleSettingsProvider implementation="org.jastadd.tooling.RelAstGrammarCodeStyleSettingsProvider"/>
<langCodeStyleSettingsProvider
implementation="org.jastadd.tooling.RelAstGrammarLanguageCodeStyleSettingsProvider"/>
</extensions>
<actions>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment