Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
17 changes: 17 additions & 0 deletions bundles/nl.esi.xplus.xtext.generator/.classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-21">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins">
<accessrules>
<accessrule kind="accessible" pattern="org/eclipse/xtext/**"/>
</accessrules>
</classpathentry>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="xtend-gen"/>
<classpathentry kind="output" path="target/classes"/>
</classpath>

34 changes: 34 additions & 0 deletions bundles/nl.esi.xplus.xtext.generator/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>nl.esi.xplus.xtext.generator</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.xtext.ui.shared.xtextBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.ManifestBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.SchemaBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.pde.PluginNature</nature>
<nature>org.eclipse.xtext.ui.shared.xtextNature</nature>
</natures>
</projectDescription>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
eclipse.preferences.version=1
encoding/<project>=UTF-8
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.targetPlatform=21
org.eclipse.jdt.core.compiler.compliance=21
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
org.eclipse.jdt.core.compiler.release=enabled
org.eclipse.jdt.core.compiler.source=21
20 changes: 20 additions & 0 deletions bundles/nl.esi.xplus.xtext.generator/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: XPlus Xtext Generator
Bundle-SymbolicName: nl.esi.xplus.xtext.generator
Bundle-Vendor: TNO-ESI
Bundle-Version: 0.5.0.qualifier
Export-Package: nl.esi.xplus.xtext.generator.ide.contentassist,
nl.esi.xplus.xtext.generator.lezer,
nl.esi.xplus.xtext.generator.model.project,
nl.esi.xplus.xtext.generator.serializer
Require-Bundle: org.eclipse.xtext;bundle-version="[2.22.0,2.38.0)",
org.eclipse.xtext.util;bundle-version="[2.22.0,2.38.0)",
org.eclipse.xtext.xtext.generator;bundle-version="[2.22.0,2.38.0)",
com.google.guava,
org.eclipse.xtext.xbase.lib,
org.eclipse.xtend.lib,
org.eclipse.xtend.lib.macro
Import-Package: org.slf4j;version="1.7.36"
Automatic-Module-Name: nl.esi.xplus.xtext.generator
Bundle-RequiredExecutionEnvironment: JavaSE-21
15 changes: 15 additions & 0 deletions bundles/nl.esi.xplus.xtext.generator/build.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#
# Copyright (c) 2024, 2026 TNO-ESI
#
# This program and the accompanying materials are made
# available under the terms of the Eclipse Public License 2.0
# which is available at https://www.eclipse.org/legal/epl-2.0/
#
# SPDX-License-Identifier: EPL-2.0
#

source.. = src/,\
xtend-gen/
output.. = target/classes/
bin.includes = META-INF/,\
.
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
/**
* Copyright (c) 2024, 2026 TNO-ESI
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*/
package nl.esi.xplus.xtext.generator.ide.contentassist

import com.google.inject.Inject
import java.util.List
import org.eclipse.xtext.AbstractRule
import org.eclipse.xtext.Assignment
import org.eclipse.xtext.Grammar
import org.eclipse.xtext.xtext.generator.XtextGeneratorNaming
import org.eclipse.xtext.xtext.generator.model.FileAccessFactory
import org.eclipse.xtext.xtext.generator.model.GuiceModuleAccess
import org.eclipse.xtext.xtext.generator.model.TypeReference
import org.eclipse.xtext.xtext.generator.ui.contentAssist.ContentAssistFragment2

import static extension org.eclipse.xtext.GrammarUtil.*

class IdeContentAssistFragment2 extends ContentAssistFragment2 {
@Inject
extension XtextGeneratorNaming

@Inject
FileAccessFactory fileAccessFactory

override protected getProposalProviderClass(Grammar g) {
return new TypeReference(
g.genericIdeBasePackage + ".contentassist." + g.simpleName + "IdeProposalProvider"
)
}

override protected getGenProposalProviderClass(Grammar g) {
return new TypeReference(
g.genericIdeBasePackage + ".contentassist.Abstract" + g.simpleName + "IdeProposalProvider"
)
}

override protected getGenProposalProviderSuperClass(Grammar g) {
val superGrammar = g.usedGrammars.head
if(inheritImplementation && superGrammar !== null && superGrammar.name != 'org.eclipse.xtext.common.Terminals') {
superGrammar.proposalProviderClass
} else {
getDefaultGenProposalProviderSuperClass
}
}

override protected getDefaultGenProposalProviderSuperClass() {
new TypeReference("org.eclipse.xtext.ide.editor.contentassist.IdeContentProposalProvider")
}

override generate() {
if (projectConfig.genericIde.manifest !== null) {
projectConfig.genericIde.manifest.requiredBundles += "org.eclipse.xtext.ide"
projectConfig.genericIde.manifest.requiredBundles += projectConfig.runtime.name + ';visibility:=reexport'
}

new GuiceModuleAccess.BindingFactory()
.addTypeToType(
new TypeReference("org.eclipse.xtext.ide.editor.contentassist.IdeContentProposalProvider"),
grammar.getProposalProviderClass
).contributeTo(language.ideGenModule);

if (projectConfig.genericIde.srcGen !== null) {
// generate the 'Abstract...IdeProposalProvider'
generateGenJavaProposalProvider
}

if (isGenerateStub && projectConfig.genericIde.src !== null) {
if (generateXtendStub) {
generateXtendProposalProviderStub

if (projectConfig.eclipsePlugin.manifest !== null) {
projectConfig.eclipsePlugin.manifest.requiredBundles += 'org.eclipse.xtext.xbase.lib;bundle-version="'+projectConfig.runtime.xbaseLibVersionLowerBound+'"'
projectConfig.eclipsePlugin.manifest.requiredBundles += 'org.eclipse.xtend.lib;resolution:=optional'
}
} else {
generateJavaProposalProviderStub
}
}

if (projectConfig.genericIde.manifest !== null) {
projectConfig.genericIde.manifest.exportedPackages += grammar.proposalProviderClass.packageName
}

// Creating UI delegation bindings to IDE
if (projectConfig.eclipsePlugin.manifest !== null) {
projectConfig.eclipsePlugin.manifest.requiredBundles += "org.eclipse.xtext.ui"
projectConfig.eclipsePlugin.manifest.requiredBundles += projectConfig.runtime.name + ';visibility:=reexport'
projectConfig.eclipsePlugin.manifest.requiredBundles += projectConfig.genericIde.name
}

new GuiceModuleAccess.BindingFactory()
.addTypeToType(
new TypeReference("org.eclipse.xtext.ui.editor.contentassist.IContentProposalProvider"),
new TypeReference("org.eclipse.xtext.ui.editor.contentassist.UiToIdeContentProposalProvider")
).contributeTo(language.eclipsePluginGenModule);

// The UI module does not include the bindings of the IDE module, so add these as well
new GuiceModuleAccess.BindingFactory()
.addTypeToType(
new TypeReference("org.eclipse.xtext.ide.editor.contentassist.IdeContentProposalProvider"),
grammar.getProposalProviderClass
).contributeTo(language.eclipsePluginGenModule);

}

override generateXtendProposalProviderStub() {
fileAccessFactory.createXtendFile(grammar.proposalProviderClass, '''
/**
* See https://www.eclipse.org/Xtext/documentation/310_eclipse_support.html#content-assist
* on how to customize the content assistant.
*/
class «grammar.proposalProviderClass.simpleName» extends «grammar.genProposalProviderClass» {
}
''').writeTo(projectConfig.genericIde.src)
}

override protected generateJavaProposalProviderStub() {
fileAccessFactory.createJavaFile(grammar.proposalProviderClass, '''
/**
* See https://www.eclipse.org/Xtext/documentation/310_eclipse_support.html#content-assist
* on how to customize the content assistant.
*/
public class «grammar.proposalProviderClass.simpleName» extends «grammar.genProposalProviderClass» {
}
''').writeTo(projectConfig.genericIde.src)
}

override protected generateGenJavaProposalProvider(List<Assignment> assignments, List<AbstractRule> rules, TypeReference genClass, TypeReference superClass) {
fileAccessFactory.createGeneratedJavaFile(genClass) => [

typeComment = '''
/**
* Represents a generated, default implementation of superclass {@link «superClass»}.
*/
'''

content = '''
public «IF isGenerateStub»abstract «ENDIF»class «genClass.simpleName» extends «superClass» {
// Placeholder for abstract implementation
}
'''
writeTo(projectConfig.genericIde.srcGen)
]
}
}
Loading
Loading