use of org.eclipse.xtext.xtext.generator.model.GeneratedJavaFileAccess in project xtext-core by eclipse.
the class XtextGeneratorTemplates method createIdeaGenModule.
public JavaFileAccess createIdeaGenModule(final IXtextGeneratorLanguage langConfig) {
final Grammar it = langConfig.getGrammar();
TypeReference _elvis = null;
TypeReference _superClass = langConfig.getIdeaGenModule().getSuperClass();
if (_superClass != null) {
_elvis = _superClass;
} else {
TypeReference _ideaDefaultModule = this.naming.getIdeaDefaultModule(it);
_elvis = _ideaDefaultModule;
}
final TypeReference superClass = _elvis;
final GeneratedJavaFileAccess file = this.fileAccessFactory.createGeneratedJavaFile(this.naming.getIdeaGenModule(it));
file.setImportNestedTypeThreshold(JavaFileAccess.DONT_IMPORT_NESTED_TYPES);
StringConcatenationClient _client = new StringConcatenationClient() {
@Override
protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
_builder.append("/**");
_builder.newLine();
_builder.append(" ");
_builder.append("* Manual modifications go to {@link ");
String _simpleName = XtextGeneratorTemplates.this.naming.getIdeaModule(it).getSimpleName();
_builder.append(_simpleName, " ");
_builder.append("}.");
_builder.newLineIfNotEmpty();
_builder.append(" ");
_builder.append("*/");
_builder.newLine();
}
};
file.setTypeComment(_client);
List<IClassAnnotation> _annotations = file.getAnnotations();
SuppressWarningsAnnotation _suppressWarningsAnnotation = new SuppressWarningsAnnotation();
_annotations.add(_suppressWarningsAnnotation);
StringConcatenationClient _client_1 = new StringConcatenationClient() {
@Override
protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
_builder.append("public abstract class ");
String _simpleName = XtextGeneratorTemplates.this.naming.getIdeaGenModule(it).getSimpleName();
_builder.append(_simpleName);
_builder.append(" extends ");
_builder.append(superClass);
_builder.append(" {");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.newLine();
{
Set<GuiceModuleAccess.Binding> _bindings = langConfig.getIdeaGenModule().getBindings();
for (final GuiceModuleAccess.Binding binding : _bindings) {
_builder.append("\t");
StringConcatenationClient _createBindingMethod = XtextGeneratorTemplates.this.createBindingMethod(binding);
_builder.append(_createBindingMethod, "\t");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.newLine();
}
}
_builder.append("}");
_builder.newLine();
}
};
file.setContent(_client_1);
return file;
}
use of org.eclipse.xtext.xtext.generator.model.GeneratedJavaFileAccess in project xtext-core by eclipse.
the class XtextGeneratorTemplates method createEclipsePluginActivator.
public JavaFileAccess createEclipsePluginActivator(final IXtextProjectConfig projectConfig, final List<? extends IXtextGeneratorLanguage> langConfigs) {
final TypeReference activator = this.naming.getEclipsePluginActivator();
final GeneratedJavaFileAccess file = this.fileAccessFactory.createGeneratedJavaFile(activator);
StringConcatenationClient _client = new StringConcatenationClient() {
@Override
protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
_builder.append("/**");
_builder.newLine();
_builder.append(" ");
_builder.append("* This class was generated. Customizations should only happen in a newly");
_builder.newLine();
_builder.append(" ");
_builder.append("* introduced subclass. ");
_builder.newLine();
_builder.append(" ");
_builder.append("*/");
_builder.newLine();
}
};
file.setTypeComment(_client);
StringConcatenationClient _client_1 = new StringConcatenationClient() {
@Override
protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
_builder.append("public class ");
String _simpleName = activator.getSimpleName();
_builder.append(_simpleName);
_builder.append(" extends ");
TypeReference _typeRef = TypeReference.typeRef("org.eclipse.ui.plugin.AbstractUIPlugin");
_builder.append(_typeRef);
_builder.append(" {");
_builder.newLineIfNotEmpty();
_builder.newLine();
_builder.append("\t");
_builder.append("public static final String PLUGIN_ID = \"");
String _name = projectConfig.getEclipsePlugin().getName();
_builder.append(_name, "\t");
_builder.append("\";");
_builder.newLineIfNotEmpty();
{
for (final IXtextGeneratorLanguage lang : langConfigs) {
_builder.append("\t");
_builder.append("public static final String ");
String _replaceAll = lang.getGrammar().getName().toUpperCase().replaceAll("\\.", "_");
_builder.append(_replaceAll, "\t");
_builder.append(" = \"");
String _name_1 = lang.getGrammar().getName();
_builder.append(_name_1, "\t");
_builder.append("\";");
_builder.newLineIfNotEmpty();
}
}
_builder.append("\t");
_builder.newLine();
_builder.append("\t");
_builder.append("private static final ");
_builder.append(Logger.class, "\t");
_builder.append(" logger = ");
_builder.append(Logger.class, "\t");
_builder.append(".getLogger(");
String _simpleName_1 = activator.getSimpleName();
_builder.append(_simpleName_1, "\t");
_builder.append(".class);");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.newLine();
_builder.append("\t");
_builder.append("private static ");
String _simpleName_2 = activator.getSimpleName();
_builder.append(_simpleName_2, "\t");
_builder.append(" INSTANCE;");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.newLine();
_builder.append("\t");
_builder.append("private ");
_builder.append(Map.class, "\t");
_builder.append("<String, ");
_builder.append(Injector.class, "\t");
_builder.append("> injectors = ");
_builder.append(Collections.class, "\t");
_builder.append(".synchronizedMap(");
_builder.append(Maps.class, "\t");
_builder.append(".<String, ");
_builder.append(Injector.class, "\t");
_builder.append("> newHashMapWithExpectedSize(1));");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.newLine();
_builder.append("\t");
_builder.append("@Override");
_builder.newLine();
_builder.append("\t");
_builder.append("public void start(");
TypeReference _typeRef_1 = TypeReference.typeRef("org.osgi.framework.BundleContext");
_builder.append(_typeRef_1, "\t");
_builder.append(" context) throws Exception {");
_builder.newLineIfNotEmpty();
_builder.append("\t\t");
_builder.append("super.start(context);");
_builder.newLine();
_builder.append("\t\t");
_builder.append("INSTANCE = this;");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("\t");
_builder.newLine();
_builder.append("\t");
_builder.append("@Override");
_builder.newLine();
_builder.append("\t");
_builder.append("public void stop(");
TypeReference _typeRef_2 = TypeReference.typeRef("org.osgi.framework.BundleContext");
_builder.append(_typeRef_2, "\t");
_builder.append(" context) throws Exception {");
_builder.newLineIfNotEmpty();
_builder.append("\t\t");
_builder.append("injectors.clear();");
_builder.newLine();
_builder.append("\t\t");
_builder.append("INSTANCE = null;");
_builder.newLine();
_builder.append("\t\t");
_builder.append("super.stop(context);");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("\t");
_builder.newLine();
_builder.append("\t");
_builder.append("public static ");
String _simpleName_3 = activator.getSimpleName();
_builder.append(_simpleName_3, "\t");
_builder.append(" getInstance() {");
_builder.newLineIfNotEmpty();
_builder.append("\t\t");
_builder.append("return INSTANCE;");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("\t");
_builder.newLine();
_builder.append("\t");
_builder.append("public ");
_builder.append(Injector.class, "\t");
_builder.append(" getInjector(String language) {");
_builder.newLineIfNotEmpty();
_builder.append("\t\t");
_builder.append("synchronized (injectors) {");
_builder.newLine();
_builder.append("\t\t\t");
_builder.append(Injector.class, "\t\t\t");
_builder.append(" injector = injectors.get(language);");
_builder.newLineIfNotEmpty();
_builder.append("\t\t\t");
_builder.append("if (injector == null) {");
_builder.newLine();
_builder.append("\t\t\t\t");
_builder.append("injectors.put(language, injector = createInjector(language));");
_builder.newLine();
_builder.append("\t\t\t");
_builder.append("}");
_builder.newLine();
_builder.append("\t\t\t");
_builder.append("return injector;");
_builder.newLine();
_builder.append("\t\t");
_builder.append("}");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("\t");
_builder.newLine();
_builder.append("\t");
_builder.append("protected ");
_builder.append(Injector.class, "\t");
_builder.append(" createInjector(String language) {");
_builder.newLineIfNotEmpty();
_builder.append("\t\t");
_builder.append("try {");
_builder.newLine();
_builder.append("\t\t\t");
_builder.append(com.google.inject.Module.class, "\t\t\t");
_builder.append(" runtimeModule = getRuntimeModule(language);");
_builder.newLineIfNotEmpty();
_builder.append("\t\t\t");
_builder.append(com.google.inject.Module.class, "\t\t\t");
_builder.append(" sharedStateModule = getSharedStateModule();");
_builder.newLineIfNotEmpty();
_builder.append("\t\t\t");
_builder.append(com.google.inject.Module.class, "\t\t\t");
_builder.append(" uiModule = getUiModule(language);");
_builder.newLineIfNotEmpty();
_builder.append("\t\t\t");
_builder.append(com.google.inject.Module.class, "\t\t\t");
_builder.append(" mergedModule = ");
_builder.append(Modules2.class, "\t\t\t");
_builder.append(".mixin(runtimeModule, sharedStateModule, uiModule);");
_builder.newLineIfNotEmpty();
_builder.append("\t\t\t");
_builder.append("return ");
_builder.append(Guice.class, "\t\t\t");
_builder.append(".createInjector(mergedModule);");
_builder.newLineIfNotEmpty();
_builder.append("\t\t");
_builder.append("} catch (Exception e) {");
_builder.newLine();
_builder.append("\t\t\t");
_builder.append("logger.error(\"Failed to create injector for \" + language);");
_builder.newLine();
_builder.append("\t\t\t");
_builder.append("logger.error(e.getMessage(), e);");
_builder.newLine();
_builder.append("\t\t\t");
_builder.append("throw new RuntimeException(\"Failed to create injector for \" + language, e);");
_builder.newLine();
_builder.append("\t\t");
_builder.append("}");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("\t");
_builder.newLine();
_builder.append("\t");
_builder.append("protected ");
_builder.append(com.google.inject.Module.class, "\t");
_builder.append(" getRuntimeModule(String grammar) {");
_builder.newLineIfNotEmpty();
{
for (final IXtextGeneratorLanguage lang_1 : langConfigs) {
_builder.append("\t\t");
_builder.append("if (");
String _replaceAll_1 = lang_1.getGrammar().getName().toUpperCase().replaceAll("\\.", "_");
_builder.append(_replaceAll_1, "\t\t");
_builder.append(".equals(grammar)) {");
_builder.newLineIfNotEmpty();
_builder.append("\t\t");
_builder.append("\t");
_builder.append("return new ");
TypeReference _runtimeModule = XtextGeneratorTemplates.this.naming.getRuntimeModule(lang_1.getGrammar());
_builder.append(_runtimeModule, "\t\t\t");
_builder.append("();");
_builder.newLineIfNotEmpty();
_builder.append("\t\t");
_builder.append("}");
_builder.newLine();
}
}
_builder.append("\t\t");
_builder.append("throw new IllegalArgumentException(grammar);");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("\t");
_builder.newLine();
_builder.append("\t");
_builder.append("protected ");
_builder.append(com.google.inject.Module.class, "\t");
_builder.append(" getUiModule(String grammar) {");
_builder.newLineIfNotEmpty();
{
for (final IXtextGeneratorLanguage lang_2 : langConfigs) {
_builder.append("\t\t");
_builder.append("if (");
String _replaceAll_2 = lang_2.getGrammar().getName().toUpperCase().replaceAll("\\.", "_");
_builder.append(_replaceAll_2, "\t\t");
_builder.append(".equals(grammar)) {");
_builder.newLineIfNotEmpty();
_builder.append("\t\t");
_builder.append("\t");
_builder.append("return new ");
TypeReference _eclipsePluginModule = XtextGeneratorTemplates.this.naming.getEclipsePluginModule(lang_2.getGrammar());
_builder.append(_eclipsePluginModule, "\t\t\t");
_builder.append("(this);");
_builder.newLineIfNotEmpty();
_builder.append("\t\t");
_builder.append("}");
_builder.newLine();
}
}
_builder.append("\t\t");
_builder.append("throw new IllegalArgumentException(grammar);");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("\t");
_builder.newLine();
_builder.append("\t");
_builder.append("protected ");
_builder.append(com.google.inject.Module.class, "\t");
_builder.append(" getSharedStateModule() {");
_builder.newLineIfNotEmpty();
_builder.append("\t\t");
_builder.append("return new ");
TypeReference _typeRef_3 = TypeReference.typeRef("org.eclipse.xtext.ui.shared.SharedStateModule");
_builder.append(_typeRef_3, "\t\t");
_builder.append("();");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("\t");
_builder.newLine();
_builder.append("\t");
_builder.newLine();
_builder.append("}");
_builder.newLine();
}
};
file.setContent(_client_1);
return file;
}
use of org.eclipse.xtext.xtext.generator.model.GeneratedJavaFileAccess in project xtext-core by eclipse.
the class SimpleProjectWizardFragment2 method generateProjectCreator.
public void generateProjectCreator() {
final TypeReference genClass = TypeReference.typeRef(this.getProjectCreatorClassName());
final TypeReference projectInfoClass = TypeReference.typeRef(this.getProjectInfoClassName());
String _xifexpression = null;
if (this.pluginProject) {
_xifexpression = "org.eclipse.xtext.ui.wizard.AbstractPluginProjectCreator";
} else {
_xifexpression = "org.eclipse.xtext.ui.wizard.AbstractProjectCreator";
}
final TypeReference baseClass = TypeReference.typeRef(_xifexpression);
final GeneratedJavaFileAccess file = this.fileAccessFactory.createGeneratedJavaFile(genClass);
StringConcatenationClient _client = new StringConcatenationClient() {
@Override
protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
_builder.append("import java.util.HashMap;");
_builder.newLine();
_builder.append("import java.util.List;");
_builder.newLine();
_builder.append("import java.util.Set;");
_builder.newLine();
_builder.newLine();
_builder.append("import org.eclipse.core.resources.IProject;");
_builder.newLine();
_builder.append("import org.eclipse.core.resources.IResource;");
_builder.newLine();
_builder.append("import org.eclipse.core.runtime.CoreException;");
_builder.newLine();
_builder.append("import org.eclipse.core.runtime.IProgressMonitor;");
_builder.newLine();
_builder.append("import org.eclipse.xtext.builder.EclipseResourceFileSystemAccess2;");
_builder.newLine();
_builder.append("import org.eclipse.xtext.generator.IFileSystemAccess;");
_builder.newLine();
_builder.append("import org.eclipse.xtext.generator.IFileSystemAccess2;");
_builder.newLine();
_builder.append("import org.eclipse.xtext.generator.IOutputConfigurationProvider;");
_builder.newLine();
_builder.append("import org.eclipse.xtext.generator.OutputConfiguration;");
_builder.newLine();
{
if (SimpleProjectWizardFragment2.this.pluginProject) {
_builder.append("import org.eclipse.xtext.ui.util.PluginProjectFactory;");
_builder.newLine();
} else {
_builder.append("import org.eclipse.xtext.ui.util.ProjectFactory;");
_builder.newLine();
}
}
_builder.append("import com.google.common.collect.ImmutableList;");
_builder.newLine();
{
if (SimpleProjectWizardFragment2.this.pluginProject) {
_builder.append("import com.google.common.collect.Lists;");
_builder.newLine();
}
}
_builder.append("import com.google.inject.Inject;");
_builder.newLine();
_builder.append("import com.google.inject.Provider;");
_builder.newLine();
_builder.newLine();
_builder.append("public class ");
String _simpleName = genClass.getSimpleName();
_builder.append(_simpleName);
_builder.append(" extends ");
_builder.append(baseClass);
_builder.append(" {");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("protected static final String DSL_PROJECT_NAME = \"");
String _namespace = GrammarUtil.getNamespace(SimpleProjectWizardFragment2.this.getGrammar());
_builder.append(_namespace, "\t");
_builder.append("\";");
_builder.newLineIfNotEmpty();
_builder.newLine();
_builder.append("\t");
_builder.append("@Inject");
_builder.newLine();
_builder.append("\t");
_builder.append("private ");
String _simpleName_1 = TypeReference.typeRef(SimpleProjectWizardFragment2.this.getProjectWizardInitialContentsClassName()).getSimpleName();
_builder.append(_simpleName_1, "\t");
_builder.append(" initialContents;");
_builder.newLineIfNotEmpty();
_builder.newLine();
_builder.append("\t");
_builder.append("@Inject");
_builder.newLine();
_builder.append("\t");
_builder.append("private Provider<EclipseResourceFileSystemAccess2> fileSystemAccessProvider;");
_builder.newLine();
_builder.newLine();
_builder.append("\t");
_builder.append("@Inject");
_builder.newLine();
_builder.append("\t");
_builder.append("private IOutputConfigurationProvider outputConfigurationProvider;");
_builder.newLine();
{
if ((!SimpleProjectWizardFragment2.this.pluginProject)) {
_builder.newLine();
_builder.append("\t");
_builder.append("@Inject");
_builder.newLine();
_builder.append("\t");
_builder.append("private Provider<ProjectFactory> projectFactoryProvider;");
_builder.newLine();
_builder.append("\t");
_builder.newLine();
_builder.append("\t");
_builder.append("@Override");
_builder.newLine();
_builder.append("\t");
_builder.append("protected ProjectFactory createProjectFactory() {");
_builder.newLine();
_builder.append("\t");
_builder.append("\t");
_builder.append("return projectFactoryProvider.get();");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
} else {
_builder.newLine();
_builder.append("\t");
_builder.append("@Override");
_builder.newLine();
_builder.append("\t");
_builder.append("protected PluginProjectFactory createProjectFactory() {");
_builder.newLine();
_builder.append("\t");
_builder.append("\t");
_builder.append("PluginProjectFactory projectFactory = super.createProjectFactory();");
_builder.newLine();
_builder.append("\t");
_builder.append("\t");
_builder.append("projectFactory.setWithPluginXml(false);");
_builder.newLine();
_builder.append("\t");
_builder.append("\t");
_builder.append("return projectFactory;");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
}
}
_builder.newLine();
_builder.append("\t");
_builder.append("@Override");
_builder.newLine();
_builder.append("\t");
_builder.append("protected ");
String _simpleName_2 = projectInfoClass.getSimpleName();
_builder.append(_simpleName_2, "\t");
_builder.append(" getProjectInfo() {");
_builder.newLineIfNotEmpty();
_builder.append("\t\t");
_builder.append("return (");
String _simpleName_3 = projectInfoClass.getSimpleName();
_builder.append(_simpleName_3, "\t\t");
_builder.append(") super.getProjectInfo();");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.newLine();
_builder.append("\t");
_builder.append("@Override");
_builder.newLine();
_builder.append("\t");
_builder.append("protected String getModelFolderName() {");
_builder.newLine();
_builder.append("\t\t");
_builder.append("return \"src\";");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.newLine();
_builder.append("\t");
_builder.append("@Override");
_builder.newLine();
_builder.append("\t");
_builder.append("protected List<String> getAllFolders() {");
_builder.newLine();
_builder.append("\t\t");
_builder.append("Set<OutputConfiguration> outputConfigurations = outputConfigurationProvider.getOutputConfigurations();");
_builder.newLine();
_builder.append("\t\t");
_builder.append("String outputFolder = \"src-gen\";");
_builder.newLine();
_builder.append("\t\t");
_builder.append("for (OutputConfiguration outputConfiguration : outputConfigurations) {");
_builder.newLine();
_builder.append("\t\t\t");
_builder.append("if (IFileSystemAccess.DEFAULT_OUTPUT.equals(outputConfiguration.getName())) {");
_builder.newLine();
_builder.append("\t\t\t\t");
_builder.append("outputFolder = outputConfiguration.getOutputDirectory();");
_builder.newLine();
_builder.append("\t\t\t\t");
_builder.append("break;");
_builder.newLine();
_builder.append("\t\t\t");
_builder.append("}");
_builder.newLine();
_builder.append("\t\t");
_builder.append("}");
_builder.newLine();
_builder.append("\t\t");
_builder.append("return ImmutableList.of(getModelFolderName(), outputFolder);");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
{
if (SimpleProjectWizardFragment2.this.pluginProject) {
_builder.newLine();
_builder.append("\t");
_builder.append("@Override");
_builder.newLine();
_builder.append("\t");
_builder.append("protected List<String> getRequiredBundles() {");
_builder.newLine();
_builder.append("\t");
_builder.append("\t");
_builder.append("return Lists.newArrayList(DSL_PROJECT_NAME);");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
}
}
_builder.newLine();
_builder.append("\t");
_builder.append("@Override");
_builder.newLine();
_builder.append("\t");
_builder.append("protected void enhanceProject(final IProject project, final IProgressMonitor monitor) throws CoreException {");
_builder.newLine();
_builder.append("\t\t");
_builder.append("IFileSystemAccess2 access = getFileSystemAccess(project, monitor);");
_builder.newLine();
_builder.append("\t\t");
_builder.append("initialContents.generateInitialContents(access);");
_builder.newLine();
_builder.append("\t\t");
_builder.append("project.refreshLocal(IResource.DEPTH_INFINITE, monitor);");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.newLine();
_builder.append("\t");
_builder.append("protected IFileSystemAccess2 getFileSystemAccess(final IProject project, final IProgressMonitor monitor) {");
_builder.newLine();
_builder.append("\t\t");
_builder.append("EclipseResourceFileSystemAccess2 access = fileSystemAccessProvider.get();");
_builder.newLine();
_builder.append("\t\t");
_builder.append("access.setContext(project);");
_builder.newLine();
_builder.append("\t\t");
_builder.append("access.setMonitor(monitor);");
_builder.newLine();
_builder.append("\t\t");
_builder.append("OutputConfiguration defaultOutput = new OutputConfiguration(IFileSystemAccess.DEFAULT_OUTPUT);");
_builder.newLine();
_builder.append("\t\t");
_builder.append("defaultOutput.setDescription(\"Output Folder\");");
_builder.newLine();
_builder.append("\t\t");
_builder.append("defaultOutput.setOutputDirectory(\"./\");");
_builder.newLine();
_builder.append("\t\t");
_builder.append("defaultOutput.setOverrideExistingResources(true);");
_builder.newLine();
_builder.append("\t\t");
_builder.append("defaultOutput.setCreateOutputDirectory(true);");
_builder.newLine();
_builder.append("\t\t");
_builder.append("defaultOutput.setCleanUpDerivedResources(false);");
_builder.newLine();
_builder.append("\t\t");
_builder.append("defaultOutput.setSetDerivedProperty(false);");
_builder.newLine();
_builder.append("\t\t");
_builder.append("defaultOutput.setKeepLocalHistory(false);");
_builder.newLine();
_builder.append("\t\t");
_builder.append("HashMap<String, OutputConfiguration> outputConfigurations = new HashMap<String, OutputConfiguration>();");
_builder.newLine();
_builder.append("\t\t");
_builder.append("outputConfigurations.put(IFileSystemAccess.DEFAULT_OUTPUT, defaultOutput);");
_builder.newLine();
_builder.append("\t\t");
_builder.append("access.setOutputConfigurations(outputConfigurations);");
_builder.newLine();
_builder.append("\t\t");
_builder.append("return access;");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("}");
_builder.newLine();
}
};
file.setContent(_client);
file.writeTo(this.getProjectConfig().getEclipsePlugin().getSrcGen());
}
use of org.eclipse.xtext.xtext.generator.model.GeneratedJavaFileAccess in project xtext-core by eclipse.
the class XtextAntlrGeneratorFragment2 method generateProductionParser.
public JavaFileAccess generateProductionParser() {
GeneratedJavaFileAccess _xblockexpression = null;
{
@Extension final GrammarNaming naming = this.productionNaming;
final GeneratedJavaFileAccess file = this.fileFactory.createGeneratedJavaFile(naming.getParserClass(this.getGrammar()));
StringConcatenationClient _client = new StringConcatenationClient() {
@Override
protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
_builder.append("public class ");
String _simpleName = naming.getParserClass(XtextAntlrGeneratorFragment2.this.getGrammar()).getSimpleName();
_builder.append(_simpleName);
_builder.append(" extends ");
_builder.append(AbstractAntlrParser.class);
_builder.append(" {");
_builder.newLineIfNotEmpty();
_builder.newLine();
_builder.append("\t");
_builder.append("@");
_builder.append(Inject.class, "\t");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("private ");
TypeReference _grammarAccess = XtextAntlrGeneratorFragment2.this.grammarUtil.getGrammarAccess(XtextAntlrGeneratorFragment2.this.getGrammar());
_builder.append(_grammarAccess, "\t");
_builder.append(" grammarAccess;");
_builder.newLineIfNotEmpty();
_builder.newLine();
_builder.append("\t");
_builder.append("@Override");
_builder.newLine();
_builder.append("\t");
_builder.append("protected void setInitialHiddenTokens(");
_builder.append(XtextTokenStream.class, "\t");
_builder.append(" tokenStream) {");
_builder.newLineIfNotEmpty();
_builder.append("\t\t");
_builder.append("tokenStream.setInitialHiddenTokens(");
{
List<String> _initialHiddenTokens = XtextAntlrGeneratorFragment2.this.grammarUtil.initialHiddenTokens(XtextAntlrGeneratorFragment2.this.getGrammar());
boolean _hasElements = false;
for (final String hidden : _initialHiddenTokens) {
if (!_hasElements) {
_hasElements = true;
} else {
_builder.appendImmediate(", ", "\t\t");
}
_builder.append("\"");
_builder.append(hidden, "\t\t");
_builder.append("\"");
}
}
_builder.append(");");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("\t");
_builder.newLine();
{
boolean _hasSyntheticTerminalRule = XtextAntlrGeneratorFragment2.this.hasSyntheticTerminalRule();
if (_hasSyntheticTerminalRule) {
_builder.append("\t");
_builder.append("@Override");
_builder.newLine();
_builder.append("\t");
_builder.append("protected ");
_builder.append(TokenSource.class, "\t");
_builder.append(" createLexer(");
_builder.append(CharStream.class, "\t");
_builder.append(" stream) {");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("\t");
_builder.append("return new ");
TypeReference _tokenSourceClass = naming.getTokenSourceClass(XtextAntlrGeneratorFragment2.this.getGrammar());
_builder.append(_tokenSourceClass, "\t\t");
_builder.append("(super.createLexer(stream));");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("\t");
_builder.newLine();
_builder.append("\t");
_builder.append("/**");
_builder.newLine();
_builder.append("\t");
_builder.append(" ");
_builder.append("* Indentation aware languages do not support partial parsing since the lexer is inherently stateful.");
_builder.newLine();
_builder.append("\t");
_builder.append(" ");
_builder.append("* Override and return {@code true} if your terminal splitting is stateless.");
_builder.newLine();
_builder.append("\t");
_builder.append(" ");
_builder.append("*/");
_builder.newLine();
_builder.append("\t");
_builder.append("@Override");
_builder.newLine();
_builder.append("\t");
_builder.append("protected boolean isReparseSupported() {");
_builder.newLine();
_builder.append("\t");
_builder.append("\t");
_builder.append("return false;");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
}
}
_builder.newLine();
_builder.append("\t");
_builder.append("@Override");
_builder.newLine();
_builder.append("\t");
_builder.append("protected ");
TypeReference _internalParserClass = naming.getInternalParserClass(XtextAntlrGeneratorFragment2.this.getGrammar());
_builder.append(_internalParserClass, "\t");
_builder.append(" createParser(");
_builder.append(XtextTokenStream.class, "\t");
_builder.append(" stream) {");
_builder.newLineIfNotEmpty();
_builder.append("\t\t");
_builder.append("return new ");
TypeReference _internalParserClass_1 = naming.getInternalParserClass(XtextAntlrGeneratorFragment2.this.getGrammar());
_builder.append(_internalParserClass_1, "\t\t");
_builder.append("(stream, getGrammarAccess());");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.newLine();
_builder.append("\t");
_builder.append("@Override ");
_builder.newLine();
_builder.append("\t");
_builder.append("protected String getDefaultRuleName() {");
_builder.newLine();
_builder.append("\t\t");
_builder.append("return \"");
String _name = AntlrGrammarGenUtil.<ParserRule>getOriginalElement(IterableExtensions.<ParserRule>head(GrammarUtil.allParserRules(XtextAntlrGeneratorFragment2.this.getGrammar()))).getName();
_builder.append(_name, "\t\t");
_builder.append("\";");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.newLine();
_builder.append("\t");
_builder.append("public ");
TypeReference _grammarAccess_1 = XtextAntlrGeneratorFragment2.this.grammarUtil.getGrammarAccess(XtextAntlrGeneratorFragment2.this.getGrammar());
_builder.append(_grammarAccess_1, "\t");
_builder.append(" getGrammarAccess() {");
_builder.newLineIfNotEmpty();
_builder.append("\t\t");
_builder.append("return this.grammarAccess;");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.newLine();
_builder.append("\t");
_builder.append("public void setGrammarAccess(");
TypeReference _grammarAccess_2 = XtextAntlrGeneratorFragment2.this.grammarUtil.getGrammarAccess(XtextAntlrGeneratorFragment2.this.getGrammar());
_builder.append(_grammarAccess_2, "\t");
_builder.append(" grammarAccess) {");
_builder.newLineIfNotEmpty();
_builder.append("\t\t");
_builder.append("this.grammarAccess = grammarAccess;");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("}");
_builder.newLine();
}
};
file.setContent(_client);
_xblockexpression = file;
}
return _xblockexpression;
}
use of org.eclipse.xtext.xtext.generator.model.GeneratedJavaFileAccess in project xtext-core by eclipse.
the class SerializerFragment2 method generateAbstractSemanticSequencer.
protected void generateAbstractSemanticSequencer() {
final Collection<IGrammarConstraintProvider.IConstraint> localConstraints = this._semanticSequencerExtensions.getGrammarConstraints(this.getGrammar());
final Collection<IGrammarConstraintProvider.IConstraint> superConstraints = this._semanticSequencerExtensions.getGrammarConstraints(this._semanticSequencerExtensions.getSuperGrammar(this.getGrammar()));
final Function1<IGrammarConstraintProvider.IConstraint, Boolean> _function = (IGrammarConstraintProvider.IConstraint it) -> {
return Boolean.valueOf(((it.getType() != null) && (!superConstraints.contains(it))));
};
final Set<IGrammarConstraintProvider.IConstraint> newLocalConstraints = IterableExtensions.<IGrammarConstraintProvider.IConstraint>toSet(IterableExtensions.<IGrammarConstraintProvider.IConstraint>filter(localConstraints, _function));
TypeReference _xifexpression = null;
boolean _isGenerateStub = this.isGenerateStub();
if (_isGenerateStub) {
_xifexpression = this.getAbstractSemanticSequencerClass(this.getGrammar());
} else {
_xifexpression = this.getSemanticSequencerClass(this.getGrammar());
}
final TypeReference clazz = _xifexpression;
TypeReference _xifexpression_1 = null;
final Function1<IGrammarConstraintProvider.IConstraint, Boolean> _function_1 = (IGrammarConstraintProvider.IConstraint it) -> {
return Boolean.valueOf(superConstraints.contains(it));
};
boolean _exists = IterableExtensions.<IGrammarConstraintProvider.IConstraint>exists(localConstraints, _function_1);
if (_exists) {
_xifexpression_1 = this.getSemanticSequencerClass(IterableExtensions.<Grammar>head(this.getGrammar().getUsedGrammars()));
} else {
_xifexpression_1 = TypeReference.typeRef(AbstractDelegatingSemanticSequencer.class);
}
final TypeReference superClazz = _xifexpression_1;
final GeneratedJavaFileAccess javaFile = this.fileAccessFactory.createGeneratedJavaFile(clazz);
javaFile.setResourceSet(this.getLanguage().getResourceSet());
final HashSet<Pair<String, EClass>> methodSignatures = CollectionLiterals.<Pair<String, EClass>>newHashSet();
StringConcatenationClient _client = new StringConcatenationClient() {
@Override
protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
_builder.append("public ");
{
boolean _isGenerateStub = SerializerFragment2.this.isGenerateStub();
if (_isGenerateStub) {
_builder.append("abstract ");
}
}
_builder.append("class ");
String _simpleName = clazz.getSimpleName();
_builder.append(_simpleName);
_builder.append(" extends ");
_builder.append(superClazz);
_builder.append(" {");
_builder.newLineIfNotEmpty();
_builder.newLine();
_builder.append("\t");
_builder.append("@");
_builder.append(Inject.class, "\t");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("private ");
TypeReference _grammarAccess = SerializerFragment2.this._grammarAccessExtensions.getGrammarAccess(SerializerFragment2.this.getGrammar());
_builder.append(_grammarAccess, "\t");
_builder.append(" grammarAccess;");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.newLine();
_builder.append("\t");
StringConcatenationClient _genMethodCreateSequence = SerializerFragment2.this.genMethodCreateSequence();
_builder.append(_genMethodCreateSequence, "\t");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.newLine();
{
List<IGrammarConstraintProvider.IConstraint> _sort = IterableExtensions.<IGrammarConstraintProvider.IConstraint>sort(newLocalConstraints);
for (final IGrammarConstraintProvider.IConstraint c : _sort) {
{
String _simpleName_1 = c.getSimpleName();
EClass _type = c.getType();
Pair<String, EClass> _mappedTo = Pair.<String, EClass>of(_simpleName_1, _type);
boolean _add = methodSignatures.add(_mappedTo);
if (_add) {
_builder.append("\t");
StringConcatenationClient _genMethodSequence = SerializerFragment2.this.genMethodSequence(c);
_builder.append(_genMethodSequence, "\t");
_builder.newLineIfNotEmpty();
} else {
_builder.append("\t");
String _simpleName_2 = clazz.getSimpleName();
String _plus = ("Skipped generating duplicate method in " + _simpleName_2);
SerializerFragment2.LOG.warn(_plus);
_builder.newLineIfNotEmpty();
_builder.append("\t");
StringConcatenationClient _genMethodSequenceComment = SerializerFragment2.this.genMethodSequenceComment(c);
_builder.append(_genMethodSequenceComment, "\t");
_builder.newLineIfNotEmpty();
}
}
_builder.append("\t");
_builder.newLine();
}
}
_builder.append("}");
_builder.newLine();
}
};
javaFile.setContent(_client);
List<IClassAnnotation> _annotations = javaFile.getAnnotations();
SuppressWarningsAnnotation _suppressWarningsAnnotation = new SuppressWarningsAnnotation();
_annotations.add(_suppressWarningsAnnotation);
javaFile.writeTo(this.getProjectConfig().getRuntime().getSrcGen());
}
Aggregations