use of org.eclipse.xtext.xtext.generator.model.GeneratedJavaFileAccess in project xtext-core by eclipse.
the class ContentAssistFragment2 method generateGenJavaProposalProvider.
protected GeneratedJavaFileAccess generateGenJavaProposalProvider() {
GeneratedJavaFileAccess _xblockexpression = null;
{
final Set<String> excludedFqnFeatureNames = this.getFQFeatureNamesToExclude(this.getGrammar());
final HashSet<String> processedNames = CollectionLiterals.<String>newHashSet();
final Function2<ArrayList<Assignment>, Assignment, ArrayList<Assignment>> _function = (ArrayList<Assignment> candidates, Assignment assignment) -> {
ArrayList<Assignment> _xblockexpression_1 = null;
{
final String fqFeatureName = this.getFQFeatureName(assignment);
if (((!processedNames.contains(fqFeatureName)) && (!excludedFqnFeatureNames.contains(fqFeatureName)))) {
processedNames.add(fqFeatureName);
candidates.add(assignment);
}
_xblockexpression_1 = candidates;
}
return _xblockexpression_1;
};
final ArrayList<Assignment> assignments = IterableExtensions.<Assignment, ArrayList<Assignment>>fold(GrammarUtil.containedAssignments(this.getGrammar()), CollectionLiterals.<Assignment>newArrayList(), _function);
final Function2<ArrayList<AbstractRule>, AbstractRule, ArrayList<AbstractRule>> _function_1 = (ArrayList<AbstractRule> candidates, AbstractRule rule) -> {
ArrayList<AbstractRule> _xblockexpression_1 = null;
{
final String fqnFeatureName = this.getFQFeatureName(rule);
if (((!processedNames.contains(fqnFeatureName)) && (!excludedFqnFeatureNames.contains(fqnFeatureName)))) {
processedNames.add(fqnFeatureName);
candidates.add(rule);
}
_xblockexpression_1 = candidates;
}
return _xblockexpression_1;
};
final ArrayList<AbstractRule> remainingRules = IterableExtensions.<AbstractRule, ArrayList<AbstractRule>>fold(this.getGrammar().getRules(), CollectionLiterals.<AbstractRule>newArrayList(), _function_1);
TypeReference _xifexpression = null;
boolean _isGenerateStub = this.isGenerateStub();
if (_isGenerateStub) {
_xifexpression = this.getGenProposalProviderClass(this.getGrammar());
} else {
_xifexpression = this.getProposalProviderClass(this.getGrammar());
}
final TypeReference genClass = _xifexpression;
GeneratedJavaFileAccess _createGeneratedJavaFile = this.fileAccessFactory.createGeneratedJavaFile(genClass);
final Procedure1<GeneratedJavaFileAccess> _function_2 = (GeneratedJavaFileAccess it) -> {
final TypeReference superClass = this.getGenProposalProviderSuperClass(this.getGrammar());
StringConcatenationClient _client = new StringConcatenationClient() {
@Override
protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
_builder.append("/**");
_builder.newLine();
_builder.append(" ");
_builder.append("* Represents a generated, default implementation of superclass {@link ");
_builder.append(superClass, " ");
_builder.append("}.");
_builder.newLineIfNotEmpty();
_builder.append(" ");
_builder.append("* Methods are dynamically dispatched on the first parameter, i.e., you can override them ");
_builder.newLine();
_builder.append(" ");
_builder.append("* with a more concrete subtype. ");
_builder.newLine();
_builder.append(" ");
_builder.append("*/");
_builder.newLine();
}
};
it.setTypeComment(_client);
StringConcatenationClient _client_1 = new StringConcatenationClient() {
@Override
protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
_builder.append("public ");
{
boolean _isGenerateStub = ContentAssistFragment2.this.isGenerateStub();
if (_isGenerateStub) {
_builder.append("abstract ");
}
}
_builder.append("class ");
String _simpleName = genClass.getSimpleName();
_builder.append(_simpleName);
_builder.append(" extends ");
_builder.append(superClass);
_builder.append(" {");
_builder.newLineIfNotEmpty();
_builder.newLine();
{
boolean _isEmpty = assignments.isEmpty();
boolean _not = (!_isEmpty);
if (_not) {
{
for (final Assignment assignment : assignments) {
_builder.append("\t");
StringConcatenationClient _handleAssignment = ContentAssistFragment2.this.handleAssignment(assignment);
_builder.append(_handleAssignment, "\t");
_builder.newLineIfNotEmpty();
}
}
_builder.newLine();
}
}
{
for (final AbstractRule rule : remainingRules) {
_builder.append("\t");
_builder.append("public void complete");
String _fQFeatureName = ContentAssistFragment2.this.getFQFeatureName(rule);
_builder.append(_fQFeatureName, "\t");
_builder.append("(");
_builder.append(EObject.class, "\t");
_builder.append(" model, ");
_builder.append(RuleCall.class, "\t");
_builder.append(" ruleCall, ");
TypeReference _contentAssistContextClass = ContentAssistFragment2.this.getContentAssistContextClass();
_builder.append(_contentAssistContextClass, "\t");
_builder.append(" context, ");
TypeReference _iCompletionProposalAcceptorClass = ContentAssistFragment2.this.getICompletionProposalAcceptorClass();
_builder.append(_iCompletionProposalAcceptorClass, "\t");
_builder.append(" acceptor) {");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("\t");
_builder.append("// subclasses may override");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
}
}
_builder.append("}");
_builder.newLine();
}
};
it.setContent(_client_1);
it.writeTo(this.getProjectConfig().getEclipsePlugin().getSrcGen());
};
_xblockexpression = ObjectExtensions.<GeneratedJavaFileAccess>operator_doubleArrow(_createGeneratedJavaFile, _function_2);
}
return _xblockexpression;
}
use of org.eclipse.xtext.xtext.generator.model.GeneratedJavaFileAccess in project xtext-core by eclipse.
the class SimpleProjectWizardFragment2 method generateNewProjectWizard.
public void generateNewProjectWizard() {
final TypeReference genClass = TypeReference.typeRef(this.getProjectWizardClassName());
final TypeReference projectInfoClass = TypeReference.typeRef(this.getProjectInfoClassName());
final TypeReference creationPageClassName = TypeReference.typeRef(this.getProjectWizardCreationPageClassName());
final GeneratedJavaFileAccess file = this.fileAccessFactory.createGeneratedJavaFile(genClass);
StringConcatenationClient _client = new StringConcatenationClient() {
@Override
protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
_builder.append("import org.eclipse.xtext.ui.wizard.IExtendedProjectInfo;");
_builder.newLine();
_builder.append("import org.eclipse.xtext.ui.wizard.IProjectCreator;");
_builder.newLine();
_builder.append("import com.google.inject.Inject;");
_builder.newLine();
_builder.newLine();
_builder.append("public class ");
String _simpleName = genClass.getSimpleName();
_builder.append(_simpleName);
_builder.append(" extends ");
TypeReference _typeRef = TypeReference.typeRef("org.eclipse.xtext.ui.wizard.XtextNewProjectWizard");
_builder.append(_typeRef);
_builder.append(" {");
_builder.newLineIfNotEmpty();
_builder.newLine();
_builder.append("\t");
_builder.append("private ");
_builder.append(creationPageClassName, "\t");
_builder.append(" mainPage;");
_builder.newLineIfNotEmpty();
_builder.newLine();
_builder.append("\t");
_builder.append("@Inject");
_builder.newLine();
_builder.append("\t");
_builder.append("public ");
String _simpleName_1 = genClass.getSimpleName();
_builder.append(_simpleName_1, "\t");
_builder.append("(IProjectCreator projectCreator) {");
_builder.newLineIfNotEmpty();
_builder.append("\t\t");
_builder.append("super(projectCreator);");
_builder.newLine();
_builder.append("\t\t");
_builder.append("setWindowTitle(\"New ");
String _simpleName_2 = GrammarUtil.getSimpleName(SimpleProjectWizardFragment2.this.getGrammar());
_builder.append(_simpleName_2, "\t\t");
_builder.append(" Project\");");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.newLine();
_builder.append("\t");
_builder.append("protected ");
_builder.append(creationPageClassName, "\t");
_builder.append(" getMainPage() {");
_builder.newLineIfNotEmpty();
_builder.append("\t\t");
_builder.append("return mainPage;");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.newLine();
_builder.append("\t");
_builder.append("/**");
_builder.newLine();
_builder.append("\t ");
_builder.append("* Use this method to add pages to the wizard.");
_builder.newLine();
_builder.append("\t ");
_builder.append("* The one-time generated version of this class will add a default new project page to the wizard.");
_builder.newLine();
_builder.append("\t ");
_builder.append("*/");
_builder.newLine();
_builder.append("\t");
_builder.append("@Override");
_builder.newLine();
_builder.append("\t");
_builder.append("public void addPages() {");
_builder.newLine();
_builder.append("\t\t");
_builder.append("mainPage = createMainPage(\"basicNewProjectPage\");");
_builder.newLine();
_builder.append("\t\t");
_builder.append("mainPage.setTitle(\"");
String _simpleName_3 = GrammarUtil.getSimpleName(SimpleProjectWizardFragment2.this.getGrammar());
_builder.append(_simpleName_3, "\t\t");
_builder.append(" Project\");");
_builder.newLineIfNotEmpty();
_builder.append("\t\t");
_builder.append("mainPage.setDescription(\"Create a new ");
String _simpleName_4 = GrammarUtil.getSimpleName(SimpleProjectWizardFragment2.this.getGrammar());
_builder.append(_simpleName_4, "\t\t");
_builder.append(" project.\");");
_builder.newLineIfNotEmpty();
_builder.append("\t\t");
_builder.append("addPage(mainPage);");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.newLine();
_builder.append("\t");
_builder.append("protected ");
_builder.append(creationPageClassName, "\t");
_builder.append(" createMainPage(String pageName) {");
_builder.newLineIfNotEmpty();
_builder.append("\t\t");
_builder.append("return new ");
_builder.append(creationPageClassName, "\t\t");
_builder.append("(pageName);");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.newLine();
_builder.append("\t");
_builder.append("/**");
_builder.newLine();
_builder.append("\t ");
_builder.append("* Use this method to read the project settings from the wizard pages and feed them into the project info class.");
_builder.newLine();
_builder.append("\t ");
_builder.append("*/");
_builder.newLine();
_builder.append("\t");
_builder.append("@Override");
_builder.newLine();
_builder.append("\t");
_builder.append("protected IExtendedProjectInfo getProjectInfo() {");
_builder.newLine();
_builder.append("\t\t");
String _simpleName_5 = projectInfoClass.getSimpleName();
_builder.append(_simpleName_5, "\t\t");
_builder.append(" projectInfo = new ");
String _simpleName_6 = projectInfoClass.getSimpleName();
_builder.append(_simpleName_6, "\t\t");
_builder.append("();");
_builder.newLineIfNotEmpty();
_builder.append("\t\t");
_builder.append("projectInfo.setProjectName(mainPage.getProjectName());");
_builder.newLine();
_builder.append("\t\t");
_builder.append("if (!mainPage.useDefaults()) {");
_builder.newLine();
_builder.append("\t\t\t");
_builder.append("projectInfo.setLocationPath(mainPage.getLocationPath());");
_builder.newLine();
_builder.append("\t\t");
_builder.append("}");
_builder.newLine();
_builder.append("\t\t");
_builder.append("return projectInfo;");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_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 QuickfixProviderFragment2 method generateGenQuickfixProvider.
public void generateGenQuickfixProvider() {
final TypeReference genClass = this.getQuickfixProviderClass(this.getGrammar());
final GeneratedJavaFileAccess file = this.fileAccessFactory.createGeneratedJavaFile(genClass);
StringConcatenationClient _client = new StringConcatenationClient() {
@Override
protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
_builder.append("public class ");
String _simpleName = genClass.getSimpleName();
_builder.append(_simpleName);
_builder.append(" extends ");
TypeReference _quickfixProviderSuperClass = QuickfixProviderFragment2.this.getQuickfixProviderSuperClass(QuickfixProviderFragment2.this.getGrammar());
_builder.append(_quickfixProviderSuperClass);
_builder.append(" {");
_builder.newLineIfNotEmpty();
_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 CodetemplatesGeneratorFragment2 method generate.
@Override
public void generate() {
IBundleProjectConfig _eclipsePlugin = this.getProjectConfig().getEclipsePlugin();
ManifestAccess _manifest = null;
if (_eclipsePlugin != null) {
_manifest = _eclipsePlugin.getManifest();
}
Set<String> _requiredBundles = null;
if (_manifest != null) {
_requiredBundles = _manifest.getRequiredBundles();
}
if (_requiredBundles != null) {
_requiredBundles.addAll(Collections.<String>unmodifiableList(CollectionLiterals.<String>newArrayList("org.eclipse.xtext.ui", "org.eclipse.xtext.ui.codetemplates.ui")));
}
GuiceModuleAccess.BindingFactory _bindingFactory = new GuiceModuleAccess.BindingFactory();
TypeReference _typeRef = TypeReference.typeRef("org.eclipse.xtext.ui.codetemplates.ui.preferences.TemplatesLanguageConfiguration");
StringConcatenationClient _client = new StringConcatenationClient() {
@Override
protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
TypeReference _typeRef = TypeReference.typeRef("org.eclipse.xtext.ui.codetemplates.ui.AccessibleCodetemplatesActivator");
_builder.append(_typeRef);
_builder.append(".getTemplatesLanguageConfigurationProvider()");
}
};
GuiceModuleAccess.BindingFactory _addTypeToProviderInstance = _bindingFactory.addTypeToProviderInstance(_typeRef, _client);
TypeReference _typeRef_1 = TypeReference.typeRef("org.eclipse.xtext.ui.codetemplates.ui.registry.LanguageRegistry");
StringConcatenationClient _client_1 = new StringConcatenationClient() {
@Override
protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
TypeReference _typeRef = TypeReference.typeRef("org.eclipse.xtext.ui.codetemplates.ui.AccessibleCodetemplatesActivator");
_builder.append(_typeRef);
_builder.append(".getLanguageRegistry()");
}
};
_addTypeToProviderInstance.addTypeToProviderInstance(_typeRef_1, _client_1).addTypeToTypeEagerSingleton(TypeReference.typeRef("org.eclipse.xtext.ui.codetemplates.ui.registry.LanguageRegistrar"), TypeReference.typeRef("org.eclipse.xtext.ui.codetemplates.ui.registry.LanguageRegistrar")).addTypeToType(TypeReference.typeRef("org.eclipse.xtext.ui.editor.templates.XtextTemplatePreferencePage"), TypeReference.typeRef("org.eclipse.xtext.ui.codetemplates.ui.preferences.AdvancedTemplatesPreferencePage")).addTypeToType(TypeReference.typeRef("org.eclipse.xtext.ide.editor.partialEditing.IPartialEditingContentAssistParser"), this.getPartialContentAssistParserClass(this.getGrammar())).addTypeToType(TypeReference.typeRef("org.eclipse.xtext.ui.codetemplates.ui.partialEditing.IPartialEditingContentAssistContextFactory"), TypeReference.typeRef("org.eclipse.xtext.ui.codetemplates.ui.partialEditing.PartialEditingContentAssistContextFactory")).contributeTo(this.getLanguage().getEclipsePluginGenModule());
IBundleProjectConfig _genericIde = this.getProjectConfig().getGenericIde();
IXtextGeneratorFileSystemAccess _srcGen = null;
if (_genericIde != null) {
_srcGen = _genericIde.getSrcGen();
}
boolean _tripleNotEquals = (_srcGen != null);
if (_tripleNotEquals) {
GeneratedJavaFileAccess _createGeneratedJavaFile = this.fileAccessFactory.createGeneratedJavaFile(this.getPartialContentAssistParserClass(this.getGrammar()));
final Procedure1<GeneratedJavaFileAccess> _function = (GeneratedJavaFileAccess it) -> {
it.setContent(this.getGenPartialContentAssistParser());
it.writeTo(this.getProjectConfig().getGenericIde().getSrcGen());
};
ObjectExtensions.<GeneratedJavaFileAccess>operator_doubleArrow(_createGeneratedJavaFile, _function);
}
}
use of org.eclipse.xtext.xtext.generator.model.GeneratedJavaFileAccess in project xtext-core by eclipse.
the class ValidatorFragment2 method generateGenValidator.
protected GeneratedJavaFileAccess generateGenValidator() {
GeneratedJavaFileAccess _xblockexpression = null;
{
TypeReference _xifexpression = null;
boolean _isGenerateStub = this.isGenerateStub();
if (_isGenerateStub) {
_xifexpression = this._validatorNaming.getAbstractValidatorClass(this.getGrammar());
} else {
_xifexpression = this._validatorNaming.getValidatorClass(this.getGrammar());
}
final TypeReference genClass = _xifexpression;
final GeneratedJavaFileAccess javaFile = this.fileAccessFactory.createGeneratedJavaFile(genClass);
StringConcatenationClient _client = new StringConcatenationClient() {
@Override
protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
{
boolean _isEmpty = ValidatorFragment2.this.composedChecks.isEmpty();
boolean _not = (!_isEmpty);
if (_not) {
_builder.append("@");
_builder.append(ComposedChecks.class);
_builder.append("(validators = {");
{
boolean _hasElements = false;
for (final String validator : ValidatorFragment2.this.composedChecks) {
if (!_hasElements) {
_hasElements = true;
} else {
_builder.appendImmediate(", ", "");
}
TypeReference _typeRef = TypeReference.typeRef(validator);
_builder.append(_typeRef);
_builder.append(".class");
}
}
_builder.append("})");
_builder.newLineIfNotEmpty();
}
}
_builder.append("public ");
{
boolean _isGenerateStub = ValidatorFragment2.this.isGenerateStub();
if (_isGenerateStub) {
_builder.append("abstract ");
}
}
_builder.append("class ");
String _simpleName = genClass.getSimpleName();
_builder.append(_simpleName);
_builder.append(" extends ");
TypeReference _genValidatorSuperClass = ValidatorFragment2.this.getGenValidatorSuperClass(ValidatorFragment2.this.getGrammar());
_builder.append(_genValidatorSuperClass);
_builder.append(" {");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.newLine();
_builder.append("\t");
_builder.append("@Override");
_builder.newLine();
_builder.append("\t");
_builder.append("protected ");
_builder.append(List.class, "\t");
_builder.append("<");
_builder.append(EPackage.class, "\t");
_builder.append("> getEPackages() {");
_builder.newLineIfNotEmpty();
_builder.append("\t\t");
_builder.append(List.class, "\t\t");
_builder.append("<");
_builder.append(EPackage.class, "\t\t");
_builder.append("> result = new ");
_builder.append(ArrayList.class, "\t\t");
_builder.append("<");
_builder.append(EPackage.class, "\t\t");
_builder.append(">(");
{
if ((ValidatorFragment2.this.isInheritImplementation() && (GrammarUtil2.getNonTerminalsSuperGrammar(ValidatorFragment2.this.getGrammar()) != null))) {
_builder.append("super.getEPackages()");
}
}
_builder.append(");");
_builder.newLineIfNotEmpty();
{
Iterable<EPackage> _generatedPackagesToValidate = ValidatorFragment2.this.getGeneratedPackagesToValidate();
for (final EPackage e : _generatedPackagesToValidate) {
_builder.append("\t\t");
_builder.append("result.add(");
String _generatedEPackageName = ValidatorFragment2.this.getGeneratedEPackageName(e);
_builder.append(_generatedEPackageName, "\t\t");
_builder.append(".eINSTANCE);");
_builder.newLineIfNotEmpty();
}
}
{
Collection<EPackage> _registryPackagesToValidate = ValidatorFragment2.this.getRegistryPackagesToValidate();
for (final EPackage e_1 : _registryPackagesToValidate) {
_builder.append("\t\t");
_builder.append("result.add(EPackage.Registry.INSTANCE.getEPackage(\"");
String _nsURI = e_1.getNsURI();
_builder.append(_nsURI, "\t\t");
_builder.append("\"));");
_builder.newLineIfNotEmpty();
}
}
_builder.append("\t\t");
_builder.append("return result;");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("\t");
StringConcatenationClient _generateValidationToDeprecateRules = ValidatorFragment2.this.generateValidationToDeprecateRules();
_builder.append(_generateValidationToDeprecateRules, "\t");
_builder.newLineIfNotEmpty();
_builder.append("}");
_builder.newLine();
}
};
javaFile.setContent(_client);
_xblockexpression = javaFile;
}
return _xblockexpression;
}
Aggregations