use of org.eclipse.xtend2.lib.StringConcatenation in project xtext-eclipse by eclipse.
the class IdeaPluginGenerator method compileFacetConfiguration.
public CharSequence compileFacetConfiguration(final Grammar grammar) {
StringConcatenation _builder = new StringConcatenation();
_builder.append("package ");
String _packageName = this._ideaPluginClassNames.toPackageName(this._ideaPluginClassNames.getFacetConfiguration(grammar));
_builder.append(_packageName);
_builder.append(";");
_builder.newLineIfNotEmpty();
_builder.newLine();
_builder.append("import com.intellij.openapi.components.PersistentStateComponent;");
_builder.newLine();
_builder.append("import com.intellij.openapi.components.State;");
_builder.newLine();
_builder.append("import com.intellij.openapi.components.Storage;");
_builder.newLine();
_builder.append("import com.intellij.openapi.components.StoragePathMacros;");
_builder.newLine();
_builder.append("import com.intellij.openapi.components.StorageScheme;");
_builder.newLine();
{
boolean _doesUseXbase = XbaseGeneratorFragment.doesUseXbase(grammar);
if (_doesUseXbase) {
_builder.append("import org.eclipse.xtext.xbase.idea.facet.XbaseFacetConfiguration;");
_builder.newLine();
_builder.append("import org.eclipse.xtext.xbase.idea.facet.XbaseGeneratorConfigurationState;");
_builder.newLine();
} else {
_builder.append("import org.eclipse.xtext.idea.facet.AbstractFacetConfiguration;");
_builder.newLine();
_builder.append("import org.eclipse.xtext.idea.facet.GeneratorConfigurationState;");
_builder.newLine();
}
}
_builder.newLine();
_builder.append("@State(name = \"");
String _name = grammar.getName();
_builder.append(_name);
_builder.append("Generator\", storages = {");
_builder.newLineIfNotEmpty();
_builder.append("\t\t");
_builder.append("@Storage(id = \"default\", file = StoragePathMacros.PROJECT_FILE),");
_builder.newLine();
_builder.append("\t\t");
_builder.append("@Storage(id = \"dir\", file = StoragePathMacros.PROJECT_CONFIG_DIR");
_builder.newLine();
_builder.append("\t\t\t\t");
_builder.append("+ \"/");
String _simpleName = this._ideaPluginClassNames.toSimpleName(grammar.getName());
_builder.append(_simpleName, "\t\t\t\t");
_builder.append("GeneratorConfig.xml\", scheme = StorageScheme.DIRECTORY_BASED)})");
_builder.newLineIfNotEmpty();
_builder.append("public class ");
String _simpleName_1 = this._ideaPluginClassNames.toSimpleName(this._ideaPluginClassNames.getFacetConfiguration(grammar));
_builder.append(_simpleName_1);
_builder.append(" extends ");
{
boolean _doesUseXbase_1 = XbaseGeneratorFragment.doesUseXbase(grammar);
if (_doesUseXbase_1) {
_builder.append("XbaseFacetConfiguration implements PersistentStateComponent<XbaseGeneratorConfigurationState>");
} else {
_builder.append("AbstractFacetConfiguration implements PersistentStateComponent<GeneratorConfigurationState>");
}
}
_builder.append("{");
_builder.newLineIfNotEmpty();
_builder.newLine();
_builder.append("}");
_builder.newLine();
return _builder;
}
use of org.eclipse.xtend2.lib.StringConcatenation in project xtext-eclipse by eclipse.
the class IdeaPluginGenerator method compileAbstractCompletionContributor.
public CharSequence compileAbstractCompletionContributor(final Grammar grammar) {
StringConcatenation _builder = new StringConcatenation();
_builder.append("package ");
String _packageName = this._ideaPluginClassNames.toPackageName(this._ideaPluginClassNames.getCompletionContributor(grammar));
_builder.append(_packageName);
_builder.append(";");
_builder.newLineIfNotEmpty();
_builder.newLine();
_builder.append("import org.eclipse.xtext.idea.lang.AbstractXtextLanguage;");
_builder.newLine();
_builder.append("import ");
String _completionContributorSuperClass = this._ideaPluginClassNames.getCompletionContributorSuperClass(grammar);
_builder.append(_completionContributorSuperClass);
_builder.append(";");
_builder.newLineIfNotEmpty();
_builder.newLine();
_builder.append("public class ");
String _simpleName = this._ideaPluginClassNames.toSimpleName(this._ideaPluginClassNames.getAbstractCompletionContributor(grammar));
_builder.append(_simpleName);
_builder.append(" extends ");
String _simpleName_1 = this._ideaPluginClassNames.toSimpleName(this._ideaPluginClassNames.getCompletionContributorSuperClass(grammar));
_builder.append(_simpleName_1);
_builder.append(" {");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("public ");
String _simpleName_2 = this._ideaPluginClassNames.toSimpleName(this._ideaPluginClassNames.getAbstractCompletionContributor(grammar));
_builder.append(_simpleName_2, "\t");
_builder.append("(AbstractXtextLanguage lang) {");
_builder.newLineIfNotEmpty();
_builder.append("\t\t");
_builder.append("super(lang);");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("}");
_builder.newLine();
return _builder;
}
use of org.eclipse.xtend2.lib.StringConcatenation in project xtext-eclipse by eclipse.
the class IdeaPluginGenerator method compileFacetType.
public CharSequence compileFacetType(final Grammar grammar) {
StringConcatenation _builder = new StringConcatenation();
_builder.append("package ");
String _packageName = this._ideaPluginClassNames.toPackageName(this._ideaPluginClassNames.getFacetTypeName(grammar));
_builder.append(_packageName);
_builder.append(";");
_builder.newLineIfNotEmpty();
_builder.newLine();
_builder.append("import com.intellij.facet.Facet;");
_builder.newLine();
_builder.append("import com.intellij.facet.FacetTypeId;");
_builder.newLine();
_builder.append("import org.eclipse.xtext.idea.facet.AbstractFacetType;");
_builder.newLine();
_builder.newLine();
_builder.append("public class ");
String _simpleName = this._ideaPluginClassNames.toSimpleName(this._ideaPluginClassNames.getFacetTypeName(grammar));
_builder.append(_simpleName);
_builder.append(" extends AbstractFacetType<");
String _simpleName_1 = this._ideaPluginClassNames.toSimpleName(this._ideaPluginClassNames.getFacetConfiguration(grammar));
_builder.append(_simpleName_1);
_builder.append("> {");
_builder.newLineIfNotEmpty();
_builder.newLine();
_builder.append("\t");
_builder.append("public static final FacetTypeId<Facet<");
String _simpleName_2 = this._ideaPluginClassNames.toSimpleName(this._ideaPluginClassNames.getFacetConfiguration(grammar));
_builder.append(_simpleName_2, "\t");
_builder.append(">> TYPEID = new FacetTypeId<Facet<");
String _simpleName_3 = this._ideaPluginClassNames.toSimpleName(this._ideaPluginClassNames.getFacetConfiguration(grammar));
_builder.append(_simpleName_3, "\t");
_builder.append(">>(\"");
String _name = grammar.getName();
_builder.append(_name, "\t");
_builder.append("\");");
_builder.newLineIfNotEmpty();
_builder.newLine();
_builder.append("\t");
_builder.append("public ");
String _simpleName_4 = this._ideaPluginClassNames.toSimpleName(this._ideaPluginClassNames.getFacetTypeName(grammar));
_builder.append(_simpleName_4, "\t");
_builder.append("() {");
_builder.newLineIfNotEmpty();
_builder.append("\t\t");
_builder.append("super(TYPEID, \"");
String _name_1 = grammar.getName();
_builder.append(_name_1, "\t\t");
_builder.append("\", \"");
String _simpleName_5 = this._ideaPluginClassNames.toSimpleName(grammar.getName());
_builder.append(_simpleName_5, "\t\t");
_builder.append("\");");
_builder.newLineIfNotEmpty();
_builder.append("\t\t");
String _languageName = this._ideaPluginClassNames.getLanguageName(grammar);
_builder.append(_languageName, "\t\t");
_builder.append(".INSTANCE.injectMembers(this);");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.newLine();
_builder.append("}");
_builder.newLine();
return _builder;
}
use of org.eclipse.xtend2.lib.StringConcatenation in project xtext-eclipse by eclipse.
the class IdeaPluginGenerator method compileExtensionFactory.
public CharSequence compileExtensionFactory(final Grammar grammar) {
StringConcatenation _builder = new StringConcatenation();
_builder.append("package ");
String _packageName = this._ideaPluginClassNames.toPackageName(this._ideaPluginClassNames.getExtensionFactoryName(grammar));
_builder.append(_packageName);
_builder.append(";");
_builder.newLineIfNotEmpty();
_builder.newLine();
_builder.append("import ");
String _languageName = this._ideaPluginClassNames.getLanguageName(grammar);
_builder.append(_languageName);
_builder.append(";");
_builder.newLineIfNotEmpty();
_builder.newLine();
_builder.append("import com.intellij.openapi.extensions.ExtensionFactory;");
_builder.newLine();
_builder.newLine();
_builder.append("public class ");
String _simpleName = this._ideaPluginClassNames.toSimpleName(this._ideaPluginClassNames.getExtensionFactoryName(grammar));
_builder.append(_simpleName);
_builder.append(" implements ExtensionFactory {");
_builder.newLineIfNotEmpty();
_builder.newLine();
_builder.append("\t");
_builder.append("@Override");
_builder.newLine();
_builder.append("\t");
_builder.append("public Object createInstance(final String factoryArgument, final String implementationClass) {");
_builder.newLine();
_builder.append("\t\t");
_builder.append("Class<?> clazz;");
_builder.newLine();
_builder.append("\t\t");
_builder.append("try {");
_builder.newLine();
_builder.append("\t\t\t");
_builder.append("clazz = Class.forName(implementationClass);");
_builder.newLine();
_builder.append("\t\t");
_builder.append("} catch (ClassNotFoundException e) {");
_builder.newLine();
_builder.append("\t\t\t");
_builder.append("throw new IllegalArgumentException(\"Couldn\'t load \"+implementationClass, e);");
_builder.newLine();
_builder.append("\t\t");
_builder.append("}");
_builder.newLine();
_builder.append("\t\t");
_builder.append("return ");
String _simpleName_1 = this._ideaPluginClassNames.toSimpleName(this._ideaPluginClassNames.getLanguageName(grammar));
_builder.append(_simpleName_1, "\t\t");
_builder.append(".INSTANCE.<Object> getInstance(clazz);");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.newLine();
_builder.append("}");
_builder.newLine();
return _builder;
}
use of org.eclipse.xtend2.lib.StringConcatenation in project xtext-eclipse by eclipse.
the class IdeaPluginGenerator method compileElementTypeProvider.
public CharSequence compileElementTypeProvider(final Grammar grammar) {
StringConcatenation _builder = new StringConcatenation();
_builder.append("package ");
String _packageName = this._ideaPluginClassNames.toPackageName(this._ideaPluginClassNames.getElementTypeProviderName(grammar));
_builder.append(_packageName);
_builder.append(";");
_builder.newLineIfNotEmpty();
_builder.newLine();
_builder.append("import java.util.HashMap;");
_builder.newLine();
_builder.append("import java.util.Map;");
_builder.newLine();
_builder.newLine();
_builder.append("import org.eclipse.emf.ecore.EObject;");
_builder.newLine();
_builder.append("import org.eclipse.xtext.idea.lang.IElementTypeProvider;");
_builder.newLine();
_builder.append("import ");
String _fileImplName = this._ideaPluginClassNames.getFileImplName(grammar);
_builder.append(_fileImplName);
_builder.append(";");
_builder.newLineIfNotEmpty();
_builder.append("import ");
String _grammarAccessName = this._ideaPluginClassNames.getGrammarAccessName(grammar);
_builder.append(_grammarAccessName);
_builder.append(";");
_builder.newLineIfNotEmpty();
_builder.append("import org.eclipse.xtext.psi.stubs.XtextFileElementType;");
_builder.newLine();
_builder.append("import org.eclipse.xtext.psi.stubs.XtextFileStub;");
_builder.newLine();
_builder.append("import org.eclipse.xtext.psi.tree.IGrammarAwareElementType;");
_builder.newLine();
_builder.newLine();
_builder.append("import com.intellij.psi.tree.IFileElementType;");
_builder.newLine();
_builder.newLine();
_builder.append("public class ");
String _simpleName = this._ideaPluginClassNames.toSimpleName(this._ideaPluginClassNames.getElementTypeProviderName(grammar));
_builder.append(_simpleName);
_builder.append(" implements IElementTypeProvider {");
_builder.newLineIfNotEmpty();
_builder.newLine();
_builder.append("\t");
_builder.append("public static final IFileElementType FILE_TYPE = new XtextFileElementType<XtextFileStub<");
String _simpleName_1 = this._ideaPluginClassNames.toSimpleName(this._ideaPluginClassNames.getFileImplName(grammar));
_builder.append(_simpleName_1, "\t");
_builder.append(">>(");
String _simpleName_2 = this._ideaPluginClassNames.toSimpleName(this._ideaPluginClassNames.getLanguageName(grammar));
_builder.append(_simpleName_2, "\t");
_builder.append(".INSTANCE);");
_builder.newLineIfNotEmpty();
_builder.newLine();
_builder.append("\t");
_builder.append("private static final Map<EObject, IGrammarAwareElementType> GRAMMAR_ELEMENT_TYPE = new HashMap<EObject, IGrammarAwareElementType>();");
_builder.newLine();
_builder.newLine();
_builder.append("\t");
_builder.append("private static IGrammarAwareElementType associate(IGrammarAwareElementType grammarAwareElementType) {");
_builder.newLine();
_builder.append("\t\t");
_builder.append("GRAMMAR_ELEMENT_TYPE.put(grammarAwareElementType.getGrammarElement(), grammarAwareElementType);");
_builder.newLine();
_builder.append("\t\t");
_builder.append("return grammarAwareElementType;");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.newLine();
_builder.append("\t");
_builder.append("private static final ");
String _simpleName_3 = this._ideaPluginClassNames.toSimpleName(this._ideaPluginClassNames.getGrammarAccessName(grammar));
_builder.append(_simpleName_3, "\t");
_builder.append(" GRAMMAR_ACCESS = ");
String _simpleName_4 = this._ideaPluginClassNames.toSimpleName(this._ideaPluginClassNames.getLanguageName(grammar));
_builder.append(_simpleName_4, "\t");
_builder.append(".INSTANCE.getInstance(");
String _simpleName_5 = this._ideaPluginClassNames.toSimpleName(this._ideaPluginClassNames.getGrammarAccessName(grammar));
_builder.append(_simpleName_5, "\t");
_builder.append(".class);");
_builder.newLineIfNotEmpty();
{
Iterable<AbstractRule> _allNonTerminalRules = this._ideaPluginExtension.getAllNonTerminalRules(grammar);
for (final AbstractRule rule : _allNonTerminalRules) {
_builder.newLine();
_builder.append("\t");
_builder.append("private static class ");
String _grammarElementIdentifier = this._grammarAccessExtensions.grammarElementIdentifier(rule);
_builder.append(_grammarElementIdentifier, "\t");
_builder.append("Factory {");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("\t");
_builder.append("public static IGrammarAwareElementType create");
String _grammarElementIdentifier_1 = this._grammarAccessExtensions.grammarElementIdentifier(rule);
_builder.append(_grammarElementIdentifier_1, "\t\t");
_builder.append("ElementType() {");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("\t\t");
_builder.append("return new IGrammarAwareElementType(\"");
String _grammarElementIdentifier_2 = this._grammarAccessExtensions.grammarElementIdentifier(rule);
_builder.append(_grammarElementIdentifier_2, "\t\t\t");
_builder.append("_ELEMENT_TYPE\", ");
String _simpleName_6 = this._ideaPluginClassNames.toSimpleName(this._ideaPluginClassNames.getLanguageName(grammar));
_builder.append(_simpleName_6, "\t\t\t");
_builder.append(".INSTANCE, GRAMMAR_ACCESS.");
String _gaRuleAccessor = this._grammarAccess.gaRuleAccessor(rule);
_builder.append(_gaRuleAccessor, "\t\t\t");
_builder.append(");");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("\t");
_builder.append("}");
_builder.newLine();
{
Iterable<AbstractElement> _iterable = IteratorExtensions.<AbstractElement>toIterable(Iterators.<AbstractElement>filter(rule.eAllContents(), AbstractElement.class));
for (final AbstractElement element : _iterable) {
_builder.append("\t");
_builder.append("\t");
_builder.append("public static IGrammarAwareElementType create");
String _grammarElementIdentifier_3 = this._grammarAccessExtensions.grammarElementIdentifier(element);
_builder.append(_grammarElementIdentifier_3, "\t\t");
_builder.append("ElementType() {");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("\t");
_builder.append("\t");
_builder.append("return new IGrammarAwareElementType(\"");
String _grammarElementIdentifier_4 = this._grammarAccessExtensions.grammarElementIdentifier(element);
_builder.append(_grammarElementIdentifier_4, "\t\t\t");
_builder.append("_ELEMENT_TYPE\", ");
String _simpleName_7 = this._ideaPluginClassNames.toSimpleName(this._ideaPluginClassNames.getLanguageName(grammar));
_builder.append(_simpleName_7, "\t\t\t");
_builder.append(".INSTANCE, GRAMMAR_ACCESS.");
String _gaElementsAccessor = this._grammarAccess.gaElementsAccessor(rule);
_builder.append(_gaElementsAccessor, "\t\t\t");
_builder.append(".");
String _gaElementAccessor = this._grammarAccess.gaElementAccessor(element);
_builder.append(_gaElementAccessor, "\t\t\t");
_builder.append(");");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("\t");
_builder.append("}");
_builder.newLine();
}
}
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.newLine();
_builder.append("\t");
_builder.append("public static final IGrammarAwareElementType ");
String _grammarElementIdentifier_5 = this._grammarAccessExtensions.grammarElementIdentifier(rule);
_builder.append(_grammarElementIdentifier_5, "\t");
_builder.append("_ELEMENT_TYPE = associate(");
String _grammarElementIdentifier_6 = this._grammarAccessExtensions.grammarElementIdentifier(rule);
_builder.append(_grammarElementIdentifier_6, "\t");
_builder.append("Factory.create");
String _grammarElementIdentifier_7 = this._grammarAccessExtensions.grammarElementIdentifier(rule);
_builder.append(_grammarElementIdentifier_7, "\t");
_builder.append("ElementType());");
_builder.newLineIfNotEmpty();
{
Iterable<AbstractElement> _iterable_1 = IteratorExtensions.<AbstractElement>toIterable(Iterators.<AbstractElement>filter(rule.eAllContents(), AbstractElement.class));
for (final AbstractElement element_1 : _iterable_1) {
_builder.newLine();
_builder.append("\t");
_builder.append("public static final IGrammarAwareElementType ");
String _grammarElementIdentifier_8 = this._grammarAccessExtensions.grammarElementIdentifier(element_1);
_builder.append(_grammarElementIdentifier_8, "\t");
_builder.append("_ELEMENT_TYPE = associate(");
String _grammarElementIdentifier_9 = this._grammarAccessExtensions.grammarElementIdentifier(rule);
_builder.append(_grammarElementIdentifier_9, "\t");
_builder.append("Factory.create");
String _grammarElementIdentifier_10 = this._grammarAccessExtensions.grammarElementIdentifier(element_1);
_builder.append(_grammarElementIdentifier_10, "\t");
_builder.append("ElementType());");
_builder.newLineIfNotEmpty();
}
}
}
}
_builder.newLine();
_builder.append("\t");
_builder.append("@Override");
_builder.newLine();
_builder.append("\t");
_builder.append("public IFileElementType getFileType() {");
_builder.newLine();
_builder.append("\t\t");
_builder.append("return FILE_TYPE;");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.newLine();
_builder.append("\t");
_builder.append("@Override");
_builder.newLine();
_builder.append("\t");
_builder.append("public IGrammarAwareElementType findElementType(EObject grammarElement) {");
_builder.newLine();
_builder.append("\t\t");
_builder.append("return GRAMMAR_ELEMENT_TYPE.get(grammarElement);");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
{
Iterable<AbstractRule> _allNonTerminalRules_1 = this._ideaPluginExtension.getAllNonTerminalRules(grammar);
for (final AbstractRule rule_1 : _allNonTerminalRules_1) {
_builder.newLine();
_builder.append("\t");
_builder.append("public IGrammarAwareElementType get");
String _grammarElementIdentifier_11 = this._grammarAccessExtensions.grammarElementIdentifier(rule_1);
_builder.append(_grammarElementIdentifier_11, "\t");
_builder.append("ElementType() {");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("\t");
_builder.append("return ");
String _grammarElementIdentifier_12 = this._grammarAccessExtensions.grammarElementIdentifier(rule_1);
_builder.append(_grammarElementIdentifier_12, "\t\t");
_builder.append("_ELEMENT_TYPE;");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
{
Iterable<AbstractElement> _iterable_2 = IteratorExtensions.<AbstractElement>toIterable(Iterators.<AbstractElement>filter(rule_1.eAllContents(), AbstractElement.class));
for (final AbstractElement element_2 : _iterable_2) {
_builder.newLine();
_builder.append("\t");
_builder.append("public IGrammarAwareElementType get");
String _grammarElementIdentifier_13 = this._grammarAccessExtensions.grammarElementIdentifier(element_2);
_builder.append(_grammarElementIdentifier_13, "\t");
_builder.append("ElementType() {");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("\t");
_builder.append("return ");
String _grammarElementIdentifier_14 = this._grammarAccessExtensions.grammarElementIdentifier(element_2);
_builder.append(_grammarElementIdentifier_14, "\t\t");
_builder.append("_ELEMENT_TYPE;");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
}
}
}
}
_builder.newLine();
_builder.append("}");
_builder.newLine();
return _builder;
}
Aggregations