mirror of
https://github.com/sigmasternchen/xtext-core
synced 2025-03-15 08:18:55 +00:00
Remove IDEA since the support has been dropped.
Signed-off-by: Holger Schill <Holger.Schill@itemis.de>
This commit is contained in:
parent
d4e59eff93
commit
fe96a20cf9
24 changed files with 15 additions and 5666 deletions
|
@ -27,9 +27,6 @@ Workflow {
|
|||
enabled = true
|
||||
root = eclipsePath
|
||||
}
|
||||
ideaPlugin = {
|
||||
enabled = false
|
||||
}
|
||||
|
||||
createEclipseMetaData = true
|
||||
}
|
||||
|
|
|
@ -67,17 +67,7 @@ XtextGeneratorLanguage {
|
|||
// content assist API
|
||||
fragment = ui.contentAssist.ContentAssistFragment2 {}
|
||||
|
||||
fragment = idea.parser.antlr.XtextAntlrIDEAGeneratorFragment auto-inject {
|
||||
options = auto-inject {
|
||||
fieldsPerClass = "100"
|
||||
methodsPerClass = "100"
|
||||
}
|
||||
}
|
||||
// fragment = org.eclipse.xtext.generator.parser.antlr.XtextAntlrGeneratorComparisonFragment {
|
||||
// options = auto-inject {}
|
||||
// }
|
||||
|
||||
fragment = idea.IdeaPluginGenerator auto-inject {
|
||||
generateXtendStub = true
|
||||
}
|
||||
}
|
||||
|
|
|
@ -37,9 +37,6 @@ Workflow {
|
|||
component = DirectoryCleaner {
|
||||
directory="${runtimeProject}/src-gen/org/eclipse/xtext/grammarinheritance"
|
||||
}
|
||||
component = DirectoryCleaner {
|
||||
directory="${runtimeProject}/../../intellij/org.eclipse.xtext.core.idea.tests/src-gen/org/eclipse/xtext/grammarinheritance/idea"
|
||||
}
|
||||
|
||||
component = XtextGenerator {
|
||||
cleaner = {
|
||||
|
|
|
@ -26,10 +26,6 @@ Workflow {
|
|||
directory = "${runtimeProject}/src-gen/org/eclipse/xtext/parser/fragments"
|
||||
}
|
||||
|
||||
component = DirectoryCleaner {
|
||||
directory = "../../intellij/org.eclipse.xtext.core.idea.tests/src-gen/org/eclipse/xtext/parser/fragments/idea"
|
||||
}
|
||||
|
||||
component = XtextGenerator {
|
||||
cleaner = {
|
||||
enabled = false
|
||||
|
|
|
@ -25,10 +25,6 @@ Workflow {
|
|||
directory = "${runtimeProject}/src-gen/org/eclipse/xtext/parser/parameters"
|
||||
}
|
||||
|
||||
component = DirectoryCleaner {
|
||||
directory = "../../intellij/org.eclipse.xtext.core.idea.tests/src-gen/org/eclipse/xtext/parser/parameters/idea"
|
||||
}
|
||||
|
||||
component = XtextGenerator {
|
||||
cleaner = {
|
||||
enabled = false
|
||||
|
|
|
@ -26,10 +26,6 @@ Workflow {
|
|||
directory = "${runtimeProject}/src-gen/org/eclipse/xtext/parser/unorderedGroups"
|
||||
}
|
||||
|
||||
component = DirectoryCleaner {
|
||||
directory = "../../intellij/org.eclipse.xtext.core.idea.tests/src-gen/org/eclipse/xtext/parser/unorderedGroups/idea"
|
||||
}
|
||||
|
||||
component = XtextGenerator {
|
||||
cleaner = {
|
||||
enabled = false
|
||||
|
|
|
@ -70,7 +70,6 @@ public enum JavaVersion {
|
|||
// if you introduce a new JavaVersion don't forget to adapt
|
||||
// - JavaVersionTest
|
||||
// - JavaVersionExtendedTest
|
||||
// - org.eclipse.xtext.xbase.idea.facet.XbaseGeneratorConfigProvider.getTargetJavaVersion(XbaseGeneratorConfigurationState, Module)
|
||||
|
||||
private final String label;
|
||||
private final String[] qualifiers;
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
</listAttribute>
|
||||
<booleanAttribute key="org.eclipse.jdt.launching.ATTR_USE_START_ON_FIRST_THREAD" value="true"/>
|
||||
<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="org.eclipse.emf.mwe2.launch.runtime.Mwe2Launcher"/>
|
||||
<stringAttribute key="org.eclipse.jdt.launching.PROGRAM_ARGUMENTS" value="src/org/eclipse/xtext/xtext/bootstrap/GenerateXtext.mwe2 -p eclipseProjectPath=${project_loc:/org.eclipse.xtext.xtext.ui} -p ideaProjectPath=${project_loc:/org.eclipse.xtext.xtext.idea}"/>
|
||||
<stringAttribute key="org.eclipse.jdt.launching.PROGRAM_ARGUMENTS" value="src/org/eclipse/xtext/xtext/bootstrap/GenerateXtext.mwe2 -p eclipseProjectPath=${project_loc:/org.eclipse.xtext.xtext.ui}"/>
|
||||
<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="org.eclipse.xtext.xtext.bootstrap"/>
|
||||
<stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-Xmx512m"/>
|
||||
</launchConfiguration>
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
/*
|
||||
* Bootstrap project for the Xtext language. It contains an MWE2 generator workflow with
|
||||
* dedicated configuration code. The workflow generates into the core and generic ide projects
|
||||
* as well as the Eclipse and IDEA integration projects, which are defined in different
|
||||
* source repositories. The path to these other repositories is assumed to be ../xtext-eclipse
|
||||
* and ../xtext-idea, respectively.
|
||||
* dedicated configuration code. The workflow generates into the core and generic ide projects,
|
||||
* which are defined in different source repositories. The path to these other repositories is
|
||||
* assumed to be ../xtext-eclipse, respectively.
|
||||
*/
|
||||
|
||||
apply from: "${rootDir}/gradle/mwe2-workflows.gradle"
|
||||
|
|
|
@ -21,8 +21,6 @@ var runtimeProjectName = baseName
|
|||
var ideProjectName = "${baseName}.xtext.ide"
|
||||
var eclipseProjectName = "${baseName}.xtext.ui"
|
||||
var eclipseProjectPath = "${rootPath}/../xtext-eclipse/${eclipseProjectName}"
|
||||
var ideaProjectName = "${baseName}.xtext.idea"
|
||||
var ideaProjectPath = "${rootPath}/../xtext-idea/${ideaProjectName}"
|
||||
|
||||
var fileHeader = "/*\n * generated by Xtext 2.11\n */" //\${version}\n */"
|
||||
|
||||
|
@ -76,11 +74,6 @@ Workflow {
|
|||
name = eclipseProjectName
|
||||
root = eclipseProjectPath
|
||||
}
|
||||
ideaPlugin = {
|
||||
enabled = true
|
||||
name = ideaProjectName
|
||||
root = ideaProjectPath
|
||||
}
|
||||
// createEclipseMetaData = true
|
||||
}
|
||||
code = {
|
||||
|
@ -127,15 +120,6 @@ Workflow {
|
|||
fragment = ui.refactoring.RefactorElementNameFragment2 {}
|
||||
|
||||
fragment = ui.templates.CodetemplatesGeneratorFragment2 {}
|
||||
|
||||
fragment = org.eclipse.xtext.xtext.generator.idea.IdeaPluginGenerator {
|
||||
generateXtendStub = true
|
||||
}
|
||||
fragment = org.eclipse.xtext.xtext.generator.idea.parser.antlr.XtextAntlrIDEAGeneratorFragment {
|
||||
options = {
|
||||
classSplitting = true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,8 +34,6 @@ Export-Package: org.eclipse.xtext.xtext.generator,
|
|||
org.eclipse.xtext.tests,
|
||||
org.eclipse.xtext.xbase,
|
||||
org.eclipse.xtend.core",
|
||||
org.eclipse.xtext.xtext.generator.idea;x-internal:=true,
|
||||
org.eclipse.xtext.xtext.generator.idea.parser.antlr;x-friends:="org.eclipse.xtend.core",
|
||||
org.eclipse.xtext.xtext.generator.junit;x-internal:=true,
|
||||
org.eclipse.xtext.xtext.generator.model;x-friends:="org.eclipse.xtext.extras.tests,
|
||||
org.eclipse.xtext.generator,
|
||||
|
|
|
@ -1,153 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2015 itemis AG (http://www.itemis.eu) and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*******************************************************************************/
|
||||
package org.eclipse.xtext.xtext.generator.idea
|
||||
|
||||
import com.google.inject.Inject
|
||||
import org.eclipse.xtext.Grammar
|
||||
import org.eclipse.xtext.xtext.generator.XtextGeneratorNaming
|
||||
import org.eclipse.xtext.xtext.generator.model.TypeReference
|
||||
|
||||
import static extension org.eclipse.xtext.GrammarUtil.*
|
||||
import static extension org.eclipse.xtext.xtext.generator.model.TypeReference.*
|
||||
|
||||
class IdeaPluginClassNames {
|
||||
@Inject extension XtextGeneratorNaming
|
||||
|
||||
def String toPath(String fullName) {
|
||||
fullName.replace('.', '/')
|
||||
}
|
||||
|
||||
def TypeReference getIdeaSetup(Grammar it) {
|
||||
new TypeReference(ideaBasePackage, simpleName + 'IdeaSetup')
|
||||
}
|
||||
|
||||
def TypeReference getExtensionFactory(Grammar it) {
|
||||
new TypeReference(ideaBasePackage, simpleName + 'ExtensionFactory')
|
||||
}
|
||||
|
||||
def TypeReference getAbstractIdeaModule(Grammar it) {
|
||||
new TypeReference(ideaBasePackage, 'Abstract' + simpleName + 'IdeaModule')
|
||||
}
|
||||
|
||||
def TypeReference getFileType(Grammar it) {
|
||||
new TypeReference(ideaBasePackage + '.lang', simpleName + 'FileType')
|
||||
}
|
||||
|
||||
def TypeReference getAbstractFileType(Grammar it) {
|
||||
new TypeReference(ideaBasePackage + '.lang', 'Abstract' + simpleName + 'FileType')
|
||||
}
|
||||
|
||||
def TypeReference getFileTypeFactory(Grammar it) {
|
||||
new TypeReference(ideaBasePackage + '.lang', simpleName + 'FileTypeFactory')
|
||||
}
|
||||
|
||||
def TypeReference getIdeaLanguage(Grammar it) {
|
||||
new TypeReference(ideaBasePackage + '.lang', simpleName + 'Language')
|
||||
}
|
||||
|
||||
def TypeReference getCodeBlockModificationListener(Grammar it) {
|
||||
new TypeReference(ideaBasePackage + '.lang.psi', simpleName + 'CodeBlockModificationListener')
|
||||
}
|
||||
|
||||
def TypeReference getPsiParser(Grammar it) {
|
||||
new TypeReference(ideaBasePackage + '.lang.parser', simpleName + 'PsiParser')
|
||||
}
|
||||
|
||||
def TypeReference getAntlrTokenFileProvider(Grammar it) {
|
||||
new TypeReference(ideaBasePackage + '.lang.parser.antlr', simpleName + 'AntlrTokenFileProvider')
|
||||
}
|
||||
|
||||
def TypeReference getPomDeclarationSearcher(Grammar it) {
|
||||
new TypeReference(ideaBasePackage + '.lang.pom', simpleName + 'PomDeclarationSearcher')
|
||||
}
|
||||
|
||||
def TypeReference getSyntaxHighlighterFactory(Grammar it) {
|
||||
new TypeReference(ideaBasePackage + '.highlighting', simpleName + 'SyntaxHighlighterFactory')
|
||||
}
|
||||
|
||||
def TypeReference getSemanticHighlightVisitor(Grammar it) {
|
||||
new TypeReference(ideaBasePackage + '.highlighting', simpleName + 'SemanticHighlightVisitor')
|
||||
}
|
||||
|
||||
def TypeReference getSuperParserDefinition(Grammar it) {
|
||||
'org.eclipse.xtext.idea.parser.AbstractXtextParserDefinition'.typeRef
|
||||
}
|
||||
|
||||
def TypeReference getParserDefinition(Grammar it) {
|
||||
new TypeReference(ideaBasePackage + '.lang.parser', simpleName + 'ParserDefinition')
|
||||
}
|
||||
|
||||
def TypeReference getTokenTypeProvider(Grammar it) {
|
||||
new TypeReference(ideaBasePackage + '.lang.parser', simpleName + 'TokenTypeProvider')
|
||||
}
|
||||
|
||||
def TypeReference getElementTypeProvider(Grammar it) {
|
||||
new TypeReference(ideaBasePackage + '.lang', simpleName + 'ElementTypeProvider')
|
||||
}
|
||||
|
||||
def TypeReference getPsiInternalLexer(Grammar it) {
|
||||
new TypeReference(ideaBasePackage + '.parser.antlr.internal', 'PsiInternal' + simpleName + 'Lexer')
|
||||
}
|
||||
|
||||
def TypeReference getPsiInternalParser(Grammar it) {
|
||||
new TypeReference(ideaBasePackage + '.parser.antlr.internal', 'PsiInternal' + simpleName + 'Parser')
|
||||
}
|
||||
|
||||
def String getTokens(Grammar it) {
|
||||
(ideaBasePackage + '.parser.antlr.internal.PsiInternal' + simpleName).toPath + '.tokens'
|
||||
}
|
||||
|
||||
def TypeReference getFileImpl(Grammar it) {
|
||||
new TypeReference(psiImplPackageName, simpleName + 'FileImpl')
|
||||
}
|
||||
|
||||
def String getPsiPackageName(Grammar it) {
|
||||
ideaBasePackage + '.lang.psi'
|
||||
}
|
||||
|
||||
def String getPsiImplPackageName(Grammar it) {
|
||||
ideaBasePackage + '.lang.psi.impl'
|
||||
}
|
||||
|
||||
def TypeReference getInternalParser(Grammar it) {
|
||||
new TypeReference(namespace + '.parser.antlr.internal', 'Internal' + simpleName + 'Parser')
|
||||
}
|
||||
|
||||
def TypeReference getAntlrLexer(Grammar it) {
|
||||
new TypeReference(namespace + '.parser.antlr.internal', 'Internal' + simpleName + 'Lexer')
|
||||
}
|
||||
|
||||
def TypeReference getCompletionContributorSuperClass(Grammar it) {
|
||||
usedGrammars.head?.completionContributor ?:
|
||||
'org.eclipse.xtext.idea.completion.AbstractCompletionContributor'.typeRef
|
||||
}
|
||||
|
||||
def TypeReference getCompletionContributor(Grammar it) {
|
||||
new TypeReference(ideaBasePackage + '.completion', simpleName + 'CompletionContributor')
|
||||
}
|
||||
|
||||
def TypeReference getAbstractCompletionContributor(Grammar it) {
|
||||
new TypeReference(ideaBasePackage + '.completion', 'Abstract' + simpleName + 'CompletionContributor')
|
||||
}
|
||||
|
||||
def TypeReference getFacetConfiguration(Grammar it) {
|
||||
new TypeReference(ideaBasePackage + '.facet', simpleName + 'FacetConfiguration')
|
||||
}
|
||||
|
||||
def TypeReference getFacetType(Grammar it) {
|
||||
new TypeReference(ideaBasePackage + '.facet', simpleName + 'FacetType')
|
||||
}
|
||||
|
||||
def TypeReference baseColorSettingsPage(Grammar it) {
|
||||
new TypeReference(ideaBasePackage + '.highlighting', simpleName + 'BaseColorSettingsPage')
|
||||
}
|
||||
|
||||
def TypeReference colorSettingsPage(Grammar it) {
|
||||
new TypeReference(baseColorSettingsPage.packageName, simpleName + 'ColorSettingsPage')
|
||||
}
|
||||
}
|
|
@ -1,32 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2015 itemis AG (http://www.itemis.eu) and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*******************************************************************************/
|
||||
package org.eclipse.xtext.xtext.generator.idea
|
||||
|
||||
import org.eclipse.xtext.Grammar
|
||||
import org.eclipse.xtext.GrammarUtil
|
||||
import org.eclipse.xtext.TerminalRule
|
||||
|
||||
class IdeaPluginExtension {
|
||||
|
||||
def getAllNonTerminalRules(Grammar grammar) {
|
||||
GrammarUtil.allRules(grammar).filter[!(it instanceof TerminalRule)]
|
||||
}
|
||||
|
||||
def getSimpleName(Grammar grammar) {
|
||||
GrammarUtil::getSimpleName(grammar);
|
||||
}
|
||||
|
||||
def getPackageName(Grammar grammar) {
|
||||
GrammarUtil::getNamespace(grammar);
|
||||
}
|
||||
|
||||
def getLanguageID(Grammar grammar) {
|
||||
grammar.name
|
||||
}
|
||||
|
||||
}
|
|
@ -7,847 +7,16 @@
|
|||
*******************************************************************************/
|
||||
package org.eclipse.xtext.xtext.generator.idea
|
||||
|
||||
import com.google.inject.Guice
|
||||
import com.google.inject.Inject
|
||||
import com.google.inject.Singleton
|
||||
import com.google.inject.name.Names
|
||||
import java.io.InputStream
|
||||
import java.util.Arrays
|
||||
import java.util.Collections
|
||||
import java.util.HashMap
|
||||
import java.util.HashSet
|
||||
import java.util.Map
|
||||
import java.util.Set
|
||||
import org.antlr.runtime.Token
|
||||
import org.eclipse.emf.ecore.EAttribute
|
||||
import org.eclipse.emf.ecore.EClass
|
||||
import org.eclipse.emf.ecore.EObject
|
||||
import org.eclipse.xtend.lib.annotations.Accessors
|
||||
import org.eclipse.xtext.AbstractElement
|
||||
import org.eclipse.xtext.AbstractRule
|
||||
import org.eclipse.xtext.Action
|
||||
import org.eclipse.xtext.GeneratedMetamodel
|
||||
import org.eclipse.xtext.Grammar
|
||||
import org.eclipse.xtext.ISetup
|
||||
import org.eclipse.xtext.RuleCall
|
||||
import org.eclipse.xtext.parser.antlr.IAntlrTokenFileProvider
|
||||
import org.eclipse.xtext.parser.antlr.Lexer
|
||||
import org.eclipse.xtext.parser.antlr.LexerBindings
|
||||
import org.eclipse.xtext.service.LanguageSpecific
|
||||
import org.eclipse.xtext.util.Modules2
|
||||
import org.eclipse.xtext.xtext.generator.AbstractStubGeneratingFragment
|
||||
import org.eclipse.xtext.xtext.generator.XtextGeneratorNaming
|
||||
import org.eclipse.xtext.xtext.generator.grammarAccess.GrammarAccessExtensions
|
||||
import org.eclipse.xtext.xtext.generator.model.FileAccessFactory
|
||||
import org.eclipse.xtext.xtext.generator.model.GuiceModuleAccess.BindingFactory
|
||||
import org.eclipse.xtext.xtext.generator.model.JavaFileAccess
|
||||
import org.eclipse.xtext.xtext.generator.model.TextFileAccess
|
||||
import org.eclipse.xtext.xtext.generator.model.TypeReference
|
||||
import org.eclipse.xtext.xtext.generator.parser.antlr.ContentAssistGrammarNaming
|
||||
import org.eclipse.xtext.xtext.generator.xbase.XbaseUsageDetector
|
||||
|
||||
import static extension org.eclipse.xtext.EcoreUtil2.*
|
||||
import static extension org.eclipse.xtext.GrammarUtil.*
|
||||
import static extension org.eclipse.xtext.xtext.generator.model.TypeReference.*
|
||||
import com.google.inject.Injector
|
||||
import com.google.inject.Module
|
||||
|
||||
@Deprecated
|
||||
class IdeaPluginGenerator extends AbstractStubGeneratingFragment {
|
||||
@Inject extension XtextGeneratorNaming
|
||||
@Inject extension XbaseUsageDetector
|
||||
@Inject ContentAssistGrammarNaming caNaming
|
||||
|
||||
@Inject
|
||||
extension IdeaPluginExtension
|
||||
|
||||
@Inject
|
||||
extension IdeaPluginClassNames
|
||||
|
||||
@Inject
|
||||
extension GrammarAccessExtensions
|
||||
|
||||
@Inject
|
||||
FileAccessFactory fileAccessFactory
|
||||
|
||||
Set<String> libraries = newHashSet();
|
||||
|
||||
@Accessors
|
||||
boolean deployable = true
|
||||
|
||||
def addLibrary(String library) {
|
||||
libraries.add(library)
|
||||
}
|
||||
|
||||
override generate() {
|
||||
if (!projectConfig.ideaPlugin.enabled)
|
||||
return;
|
||||
val fileExtension = language.getFileExtensions().head
|
||||
val grammar = language.grammar
|
||||
|
||||
val bindFactory = new BindingFactory();
|
||||
bindFactory.addTypeToType('org.eclipse.xtext.parser.antlr.IAntlrTokenFileProvider'.typeRef, grammar.antlrTokenFileProvider)
|
||||
bindFactory.addTypeToType('org.eclipse.xtext.parser.antlr.Lexer'.typeRef, grammar.getPsiInternalLexer)
|
||||
bindFactory.addConfiguredBinding("RuntimeLexer", '''
|
||||
binder.bind(«Lexer».class)
|
||||
.annotatedWith(«Names».named(«LexerBindings».RUNTIME))
|
||||
.to(«grammar.psiInternalLexer».class);
|
||||
''')
|
||||
bindFactory.addTypeToType('com.intellij.lang.PsiParser'.typeRef, grammar.psiParser)
|
||||
bindFactory.addTypeToType('org.eclipse.xtext.idea.parser.TokenTypeProvider'.typeRef, grammar.tokenTypeProvider)
|
||||
bindFactory.addTypeToType('com.intellij.lang.ParserDefinition'.typeRef, grammar.parserDefinition)
|
||||
bindFactory.addTypeToTypeSingleton('org.eclipse.xtext.idea.lang.IElementTypeProvider'.typeRef, grammar.elementTypeProvider)
|
||||
bindFactory.addTypeToType('org.eclipse.xtext.idea.facet.AbstractFacetConfiguration'.typeRef, grammar.facetConfiguration)
|
||||
bindFactory.addTypeToInstance('com.intellij.facet.FacetTypeId'.typeRef, '''«grammar.facetType».TYPEID''')
|
||||
bindFactory.addTypeToType('org.eclipse.xtext.ide.editor.contentassist.antlr.IContentAssistParser'.typeRef, caNaming.getParserClass(grammar))
|
||||
bindFactory.addConfiguredBinding('ContentAssistLexer',
|
||||
'''binder.bind(«'org.eclipse.xtext.ide.editor.contentassist.antlr.internal.Lexer'.typeRef».class).annotatedWith(«Names».named(«'org.eclipse.xtext.ide.LexerIdeBindings'.typeRef».CONTENT_ASSIST)).to(«caNaming.getLexerClass(grammar)».class);''')
|
||||
if (grammar.inheritsXbase) {
|
||||
bindFactory.addTypeToType('org.eclipse.xtext.common.types.xtext.AbstractTypeScopeProvider'.typeRef, 'org.eclipse.xtext.idea.common.types.StubBasedTypeScopeProvider'.typeRef)
|
||||
bindFactory.addTypeToType(new TypeReference('org.eclipse.xtext.xbase.typesystem.internal', 'IFeatureScopeTracker.Provider'), 'org.eclipse.xtext.xbase.typesystem.internal.OptimizingFeatureScopeTrackerProvider'.typeRef)
|
||||
bindFactory.addConfiguredBinding('LanguageSpecificPsiModelAssociations', '''
|
||||
binder.bind(«"org.eclipse.xtext.psi.IPsiModelAssociations".typeRef».class)
|
||||
.annotatedWith(«LanguageSpecific».class)
|
||||
.to(«"org.eclipse.xtext.idea.common.types.DerivedMemberAwarePsiModelAssociations".typeRef».class);
|
||||
''')
|
||||
bindFactory.addTypeToType('org.eclipse.xtext.idea.highlighting.IHighlightingConfiguration'.typeRef, 'org.eclipse.xtext.xbase.idea.highlighting.XbaseHighlightingConfiguration'.typeRef)
|
||||
bindFactory.addTypeToType('org.eclipse.xtext.idea.formatting.BlockFactory'.typeRef, 'org.eclipse.xtext.xbase.idea.formatting.XbaseBlockFactory'.typeRef)
|
||||
bindFactory.addTypeToType('org.eclipse.xtext.idea.formatting.ChildAttributesProvider'.typeRef, 'org.eclipse.xtext.xbase.idea.formatting.XbaseChildAttributesProvider'.typeRef)
|
||||
bindFactory.addTypeToType('org.eclipse.xtext.ide.editor.bracketmatching.IBracePairProvider'.typeRef, 'org.eclipse.xtext.xbase.idea.bracketmatching.XbaseBracePairProvider'.typeRef)
|
||||
bindFactory.addTypeToType('org.eclipse.xtext.idea.findusages.IReferenceSearcher'.typeRef, 'org.eclipse.xtext.xbase.idea.findusages.JvmElementAwareReferenceSearcher'.typeRef)
|
||||
bindFactory.addTypeToType('org.eclipse.xtext.xbase.compiler.IGeneratorConfigProvider'.typeRef, 'org.eclipse.xtext.xbase.idea.facet.XbaseGeneratorConfigProvider'.typeRef)
|
||||
bindFactory.addTypeToType('org.eclipse.xtext.idea.findusages.WordsScannerProvider'.typeRef, new TypeReference('org.eclipse.xtext.xbase.idea.findusages', 'XbaseWordsScanner.XbaseWordsScannerProvider'))
|
||||
}
|
||||
|
||||
bindFactory.contributeTo(language.ideaGenModule)
|
||||
|
||||
#[
|
||||
grammar.compileStandaloneSetup,
|
||||
grammar.compileIdeaSetup,
|
||||
grammar.compileCompletionContributor,
|
||||
grammar.compileFileType,
|
||||
grammar.compileFacetConfiguration,
|
||||
grammar.compileColorSettingsPage
|
||||
].forEach[
|
||||
writeTo(projectConfig.ideaPlugin.src)
|
||||
]
|
||||
|
||||
#[
|
||||
grammar.compileServicesISetup,
|
||||
grammar.compileAbstractCompletionContributor,
|
||||
grammar.compileLanguage,
|
||||
grammar.compileAbstractFileType(fileExtension),
|
||||
grammar.compileFileTypeFactory,
|
||||
grammar.compileFileImpl,
|
||||
grammar.compileTokenTypeProvider,
|
||||
grammar.compileElementTypeProvider,
|
||||
grammar.compileParserDefinition,
|
||||
grammar.compileSyntaxHighlighterFactory,
|
||||
grammar.compileSemanticHighlightVisitor,
|
||||
grammar.compileExtensionFactory,
|
||||
grammar.compileCodeBlockModificationListener,
|
||||
grammar.compilePsiParser,
|
||||
grammar.compileAntlrTokenFileProvider,
|
||||
grammar.compilePomDeclarationSearcher,
|
||||
grammar.compileFacetType,
|
||||
grammar.compileBaseColorSettingsPage
|
||||
].forEach[
|
||||
writeTo(projectConfig.ideaPlugin.srcGen)
|
||||
]
|
||||
|
||||
if (deployable) {
|
||||
val pluginXml = grammar.compilePluginXml
|
||||
if (!projectConfig.ideaPlugin.metaInf.isFile(pluginXml.path)) {
|
||||
pluginXml.writeTo(projectConfig.ideaPlugin.metaInf)
|
||||
}
|
||||
grammar.compilePluginGenXml.writeTo(projectConfig.ideaPlugin.metaInf)
|
||||
}
|
||||
System.err.println("The support for Idea has been removed!")
|
||||
}
|
||||
|
||||
def iml() {
|
||||
".iml"
|
||||
}
|
||||
|
||||
def compileExtensionFactory(Grammar grammar) {
|
||||
fileAccessFactory.createJavaFile(grammar.extensionFactory, '''
|
||||
public class «grammar.extensionFactory.simpleName» implements «"com.intellij.openapi.extensions.ExtensionFactory".typeRef» {
|
||||
@Override
|
||||
public Object createInstance(«String» factoryArgument, «String» implementationClass) {
|
||||
«Class»<?> clazz;
|
||||
try {
|
||||
clazz = «Class».forName(implementationClass);
|
||||
} catch («ClassNotFoundException» e) {
|
||||
throw new «IllegalArgumentException»("Couldn't load "+implementationClass, e);
|
||||
}
|
||||
return «grammar.ideaLanguage».INSTANCE.<Object> getInstance(clazz);
|
||||
}
|
||||
}
|
||||
''')
|
||||
}
|
||||
def compileCodeBlockModificationListener(Grammar grammar) {
|
||||
fileAccessFactory.createJavaFile(grammar.codeBlockModificationListener, '''
|
||||
public class «grammar.codeBlockModificationListener.simpleName» extends «"org.eclipse.xtext.psi.BaseXtextCodeBlockModificationListener".typeRef» {
|
||||
|
||||
public «grammar.codeBlockModificationListener.simpleName»(«"com.intellij.psi.util.PsiModificationTracker".typeRef» psiModificationTracker) {
|
||||
super(«grammar.ideaLanguage».INSTANCE, psiModificationTracker);
|
||||
}
|
||||
«IF grammar.inheritsXbase»
|
||||
protected boolean hasJavaStructuralChanges(«"com.intellij.psi.impl.PsiTreeChangeEventImpl".typeRef» event) {
|
||||
return true;
|
||||
}
|
||||
«ENDIF»
|
||||
|
||||
}
|
||||
''')
|
||||
}
|
||||
|
||||
def compilePomDeclarationSearcher(Grammar it) {
|
||||
fileAccessFactory.createJavaFile(pomDeclarationSearcher, '''
|
||||
public class «pomDeclarationSearcher.simpleName» extends «"org.eclipse.xtext.idea.pom.AbstractXtextPomDeclarationSearcher".typeRef» {
|
||||
|
||||
public «pomDeclarationSearcher.simpleName»() {
|
||||
super(«grammar.ideaLanguage».INSTANCE);
|
||||
}
|
||||
}
|
||||
''')
|
||||
}
|
||||
|
||||
def compilePsiParser(Grammar grammar) {
|
||||
fileAccessFactory.createJavaFile(grammar.psiParser, '''
|
||||
public class «grammar.psiParser.simpleName» extends «"org.eclipse.xtext.idea.parser.AbstractXtextPsiParser".typeRef» {
|
||||
|
||||
«IF !grammar.initialHiddenTokens.empty»
|
||||
private static final «Set»<«String»> INITIAL_HIDDEN_TOKENS = new «HashSet»<«String»>(«Arrays».asList(«FOR hidden:grammar.initialHiddenTokens SEPARATOR ', '»"«hidden»"«ENDFOR»));
|
||||
«ELSE»
|
||||
private static final «Set»<«String»> INITIAL_HIDDEN_TOKENS = «Collections».emptySet();
|
||||
«ENDIF»
|
||||
|
||||
@«Inject»
|
||||
private «grammar.grammarAccess» grammarAccess;
|
||||
|
||||
@«Inject»
|
||||
private «grammar.elementTypeProvider» elementTypeProvider;
|
||||
|
||||
@«Override»
|
||||
protected «"org.eclipse.xtext.idea.parser.AbstractPsiAntlrParser".typeRef» createParser(«"com.intellij.lang.PsiBuilder".typeRef» builder, «"org.antlr.runtime.TokenStream".typeRef» tokenStream) {
|
||||
return new «grammar.psiInternalParser»(builder, tokenStream, elementTypeProvider, grammarAccess);
|
||||
}
|
||||
|
||||
@«Override»
|
||||
protected «Set»<«String»> getInitialHiddenTokens() {
|
||||
return INITIAL_HIDDEN_TOKENS;
|
||||
}
|
||||
}
|
||||
''')
|
||||
}
|
||||
|
||||
def compileAntlrTokenFileProvider(Grammar grammar) {
|
||||
fileAccessFactory.createJavaFile(grammar.antlrTokenFileProvider, '''
|
||||
public class «grammar.antlrTokenFileProvider.simpleName» implements «IAntlrTokenFileProvider» {
|
||||
@«Override»
|
||||
public «InputStream» getAntlrTokenFile() {
|
||||
«ClassLoader» classLoader = getClass().getClassLoader();
|
||||
return classLoader.getResourceAsStream("«grammar.tokens»");
|
||||
}
|
||||
}
|
||||
''')
|
||||
}
|
||||
def compilePluginXml(Grammar grammar) {
|
||||
fileAccessFactory.createTextFile("plugin.xml", '''
|
||||
<idea-plugin version="2" xmlns:xi="http://www.w3.org/2001/XInclude">
|
||||
<id>«grammar.ideaBasePackage»</id>
|
||||
<name>«grammar.simpleName» Support</name>
|
||||
<description>
|
||||
This plugin enables smart editing of «grammar.simpleName» files.
|
||||
</description>
|
||||
<version>1.0.0</version>
|
||||
<vendor>My Company</vendor>
|
||||
|
||||
<idea-version since-build="145"/>
|
||||
<depends>org.eclipse.xtext.idea</depends>
|
||||
|
||||
<xi:include href="plugin_gen.xml" xpointer="xpointer(/idea-plugin/*)"/>
|
||||
</idea-plugin>
|
||||
''')
|
||||
}
|
||||
|
||||
def compilePluginGenXml(Grammar grammar){
|
||||
fileAccessFactory.createTextFile("plugin_gen.xml", '''
|
||||
<idea-plugin version="2">
|
||||
<extensions defaultExtensionNs="org.eclipse.xtext.idea">
|
||||
«FOR generatedMetamodel:grammar.metamodelDeclarations.filter(GeneratedMetamodel)»
|
||||
<package
|
||||
uri="«generatedMetamodel.EPackage.nsURI»"
|
||||
class="«grammar.namespace».«generatedMetamodel.name».«generatedMetamodel.name.toFirstUpper»Package"
|
||||
/>
|
||||
«ENDFOR»
|
||||
<resourceFactory
|
||||
type="«language.fileExtensions.head»"
|
||||
class="org.eclipse.xtext.resource.IResourceFactory"
|
||||
factoryClass="«grammar.extensionFactory»"
|
||||
/>
|
||||
<resourceServiceProvider
|
||||
uriExtension="«language.fileExtensions.head»"
|
||||
class="org.eclipse.xtext.idea.resource.IResourceIdeaServiceProvider"
|
||||
factoryClass="«grammar.extensionFactory»"
|
||||
/>
|
||||
|
||||
<lang.setup
|
||||
language="«grammar.languageID»"
|
||||
implementationClass="«grammar.ideaSetup»"
|
||||
/>
|
||||
</extensions>
|
||||
|
||||
<extensions defaultExtensionNs="com.intellij">
|
||||
<psi.treeChangePreprocessor implementation="«grammar.codeBlockModificationListener»"/>
|
||||
|
||||
<fileTypeFactory implementation="«grammar.fileTypeFactory»"/>
|
||||
<stubElementTypeHolder class="«grammar.elementTypeProvider»"/>
|
||||
«grammar.compileExtension('lang.ast.factory', 'org.eclipse.xtext.idea.lang.BaseXtextASTFactory'.typeRef)»
|
||||
«grammar.compileExtension('lang.parserDefinition', grammar.parserDefinition)»
|
||||
«grammar.compileExtension('lang.findUsagesProvider', 'org.eclipse.xtext.idea.findusages.BaseXtextFindUsageProvider'.typeRef)»
|
||||
«grammar.compileExtension('lang.refactoringSupport', 'org.eclipse.xtext.idea.refactoring.BaseXtextRefactoringSupportProvider'.typeRef)»
|
||||
«grammar.compileExtension('lang.namesValidator', 'com.intellij.lang.refactoring.NamesValidator'.typeRef)»
|
||||
<lang.syntaxHighlighterFactory key="«grammar.languageID»" implementationClass="«grammar.syntaxHighlighterFactory»" />
|
||||
«grammar.compileExtension('lang.braceMatcher', 'com.intellij.lang.PairedBraceMatcher'.typeRef)»
|
||||
«grammar.compileExtension('annotator', 'org.eclipse.xtext.idea.annotation.IssueAnnotator'.typeRef)»
|
||||
<completion.contributor language="«grammar.languageID»" implementationClass="«grammar.completionContributor»"/>
|
||||
<pom.declarationSearcher implementation="«grammar.pomDeclarationSearcher»"/>
|
||||
|
||||
«grammar.compileExtension('lang.psiStructureViewFactory', 'com.intellij.lang.PsiStructureViewFactory'.typeRef)»
|
||||
<facetType implementation="«grammar.facetType»"/>
|
||||
«grammar.compileExtension('lang.documentationProvider', 'org.eclipse.xtext.idea.documentation.IdeaDocumentationProvider'.typeRef)»
|
||||
<colorSettingsPage implementation="«grammar.colorSettingsPage»"/>
|
||||
<highlightVisitor implementation="«grammar.semanticHighlightVisitor»"/>
|
||||
|
||||
«grammar.compileExtension('lang.formatter', 'com.intellij.formatting.FormattingModelBuilder'.typeRef)»
|
||||
«grammar.compileExtension('lang.commenter', 'com.intellij.lang.CodeDocumentationAwareCommenter'.typeRef)»
|
||||
</extensions>
|
||||
</idea-plugin>
|
||||
''')
|
||||
}
|
||||
|
||||
def compileExtension(Grammar grammar, String extensionPointId, TypeReference implementationClass) '''
|
||||
<«extensionPointId»
|
||||
language="«grammar.languageID»"
|
||||
factoryClass="«grammar.extensionFactory»"
|
||||
implementationClass="«implementationClass»"
|
||||
/>
|
||||
'''
|
||||
|
||||
def compileFileImpl(Grammar grammar) {
|
||||
fileAccessFactory.createJavaFile(grammar.fileImpl, '''
|
||||
public final class «grammar.fileImpl.simpleName» extends «"org.eclipse.xtext.psi.impl.BaseXtextFile".typeRef» {
|
||||
|
||||
public «grammar.fileImpl.simpleName»(«"com.intellij.psi.FileViewProvider".typeRef» viewProvider) {
|
||||
super(viewProvider, «grammar.ideaLanguage».INSTANCE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public «"com.intellij.openapi.fileTypes.FileType".typeRef» getFileType() {
|
||||
return «grammar.fileType».INSTANCE;
|
||||
}
|
||||
}
|
||||
''')
|
||||
}
|
||||
def compileFileTypeFactory(Grammar grammar) {
|
||||
fileAccessFactory.createJavaFile(grammar.fileTypeFactory, '''
|
||||
public class «grammar.fileTypeFactory.simpleName» extends «"com.intellij.openapi.fileTypes.FileTypeFactory".typeRef» {
|
||||
|
||||
@Override
|
||||
public void createFileTypes(@«"org.jetbrains.annotations.NotNull".typeRef» «"com.intellij.openapi.fileTypes.FileTypeConsumer".typeRef» consumer) {
|
||||
consumer.consume(«grammar.fileType».INSTANCE, «grammar.abstractFileType».DEFAULT_EXTENSION);
|
||||
}
|
||||
|
||||
}
|
||||
''')
|
||||
}
|
||||
|
||||
def compileAbstractFileType(Grammar grammar, String fileExtension) {
|
||||
fileAccessFactory.createJavaFile(grammar.abstractFileType, '''
|
||||
public class «grammar.abstractFileType.simpleName» extends «"com.intellij.openapi.fileTypes.LanguageFileType".typeRef» {
|
||||
|
||||
@«"org.jetbrains.annotations.NonNls".typeRef»
|
||||
public static final String DEFAULT_EXTENSION = "«fileExtension»";
|
||||
|
||||
protected «grammar.abstractFileType.simpleName»(final «"com.intellij.lang.Language".typeRef» language) {
|
||||
super(language);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDefaultExtension() {
|
||||
return DEFAULT_EXTENSION;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "«grammar.simpleName» files";
|
||||
}
|
||||
|
||||
@Override
|
||||
public «"javax.swing.Icon".typeRef» getIcon() {
|
||||
return «"org.eclipse.xtext.idea.Icons".typeRef».DSL_FILE_TYPE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "«grammar.simpleName»";
|
||||
}
|
||||
|
||||
}
|
||||
''')
|
||||
}
|
||||
|
||||
def compileFileType(Grammar grammar) {
|
||||
if (isGenerateXtendStub) {
|
||||
fileAccessFactory.createXtendFile(grammar.fileType, '''
|
||||
class «grammar.fileType.simpleName» extends «grammar.abstractFileType» {
|
||||
public static final «grammar.fileType.simpleName» INSTANCE = new «grammar.fileType.simpleName»()
|
||||
|
||||
new() {
|
||||
super(«grammar.ideaLanguage».INSTANCE)
|
||||
}
|
||||
}
|
||||
''')
|
||||
} else {
|
||||
fileAccessFactory.createJavaFile(grammar.fileType, '''
|
||||
public class «grammar.fileType.simpleName» extends «grammar.abstractFileType» {
|
||||
public static final «grammar.fileType.simpleName» INSTANCE = new «grammar.fileType.simpleName»();
|
||||
|
||||
public «grammar.fileType.simpleName»() {
|
||||
super(«grammar.ideaLanguage».INSTANCE);
|
||||
}
|
||||
}
|
||||
''')
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
def compileLanguage(Grammar grammar) {
|
||||
fileAccessFactory.createJavaFile(grammar.ideaLanguage, '''
|
||||
public final class «grammar.ideaLanguage.simpleName» extends «"org.eclipse.xtext.idea.lang.AbstractXtextLanguage".typeRef» {
|
||||
|
||||
public static final «grammar.ideaLanguage.simpleName» INSTANCE = new «grammar.ideaLanguage.simpleName»();
|
||||
|
||||
private «grammar.ideaLanguage.simpleName»() {
|
||||
super("«grammar.languageId»");
|
||||
}
|
||||
|
||||
}
|
||||
''')
|
||||
}
|
||||
|
||||
def compileStandaloneSetup(Grammar grammar) {
|
||||
if (isGenerateXtendStub) {
|
||||
fileAccessFactory.createXtendFile(grammar.ideaStandaloneSetup, '''
|
||||
class «grammar.ideaStandaloneSetup.simpleName» extends «grammar.runtimeGenSetup» {
|
||||
override createInjector() {
|
||||
val runtimeModule = new «grammar.runtimeModule»()
|
||||
val ideaModule = new «grammar.ideaModule»()
|
||||
val mergedModule = «Modules2».mixin(runtimeModule, ideaModule)
|
||||
return «Guice».createInjector(mergedModule)
|
||||
}
|
||||
}
|
||||
''')
|
||||
} else {
|
||||
fileAccessFactory.createJavaFile(grammar.ideaStandaloneSetup, '''
|
||||
public class «grammar.ideaStandaloneSetup.simpleName» extends «grammar.runtimeGenSetup» {
|
||||
@Override
|
||||
public «Injector» createInjector() {
|
||||
«grammar.runtimeModule» runtimeModule = new «grammar.runtimeModule»();
|
||||
«grammar.ideaModule» ideaModule = new «grammar.ideaModule»();
|
||||
«Module» mergedModule = «Modules2».mixin(runtimeModule, ideaModule);
|
||||
return «Guice».createInjector(mergedModule);
|
||||
}
|
||||
}
|
||||
''')
|
||||
}
|
||||
}
|
||||
|
||||
def compileIdeaSetup(Grammar grammar) {
|
||||
if (generateXtendStub) {
|
||||
fileAccessFactory.createXtendFile(grammar.ideaSetup, '''
|
||||
class «grammar.ideaSetup.simpleName» implements «ISetup» {
|
||||
|
||||
override createInjectorAndDoEMFRegistration() {
|
||||
«"org.eclipse.xtext.idea.extensions.EcoreGlobalRegistries".typeRef».ensureInitialized
|
||||
new «grammar.ideaStandaloneSetup»().createInjector
|
||||
}
|
||||
|
||||
}
|
||||
''')
|
||||
} else {
|
||||
fileAccessFactory.createJavaFile(grammar.ideaSetup, '''
|
||||
public class «grammar.ideaSetup.simpleName» implements «ISetup» {
|
||||
|
||||
@Override
|
||||
public «Injector» createInjectorAndDoEMFRegistration() {
|
||||
«"org.eclipse.xtext.idea.extensions.EcoreGlobalRegistries".typeRef».ensureInitialized();
|
||||
return new «grammar.ideaStandaloneSetup»().createInjector();
|
||||
}
|
||||
|
||||
}
|
||||
''')
|
||||
}
|
||||
}
|
||||
|
||||
def compileElementTypeProvider(Grammar grammar) {
|
||||
val file = fileAccessFactory.createJavaFile(grammar.elementTypeProvider)
|
||||
file.importType("org.eclipse.xtext.idea.lang.IElementTypeProvider".typeRef)
|
||||
file.importType("org.eclipse.xtext.psi.stubs.XtextFileElementType".typeRef)
|
||||
file.importType("org.eclipse.xtext.psi.stubs.XtextFileStub".typeRef)
|
||||
file.importType("org.eclipse.xtext.psi.tree.IGrammarAwareElementType".typeRef)
|
||||
file.importType("com.intellij.psi.tree.IFileElementType".typeRef)
|
||||
|
||||
file.content = '''
|
||||
public class «grammar.elementTypeProvider.simpleName» implements IElementTypeProvider {
|
||||
|
||||
public static final IFileElementType FILE_TYPE = new XtextFileElementType<XtextFileStub<«grammar.fileImpl»>>(«grammar.ideaLanguage».INSTANCE);
|
||||
|
||||
private static final «Map»<«EObject», IGrammarAwareElementType> GRAMMAR_ELEMENT_TYPE = new «HashMap»<«EObject», IGrammarAwareElementType>();
|
||||
|
||||
private static IGrammarAwareElementType associate(IGrammarAwareElementType grammarAwareElementType) {
|
||||
GRAMMAR_ELEMENT_TYPE.put(grammarAwareElementType.getGrammarElement(), grammarAwareElementType);
|
||||
return grammarAwareElementType;
|
||||
}
|
||||
|
||||
private static final «grammar.grammarAccess» GRAMMAR_ACCESS = «grammar.ideaLanguage».INSTANCE.getInstance(«grammar.grammarAccess».class);
|
||||
«FOR rule:grammar.allNonTerminalRules»
|
||||
|
||||
private static class «rule.grammarElementIdentifier»Factory {
|
||||
public static IGrammarAwareElementType create«rule.grammarElementIdentifier»ElementType() {
|
||||
return new IGrammarAwareElementType("«rule.grammarElementIdentifier»_ELEMENT_TYPE", «grammar.ideaLanguage».INSTANCE, GRAMMAR_ACCESS.«rule.gaRuleAccessor»);
|
||||
}
|
||||
«FOR element:rule.eAllContents.filter(AbstractElement).toIterable»
|
||||
public static IGrammarAwareElementType create«element.grammarElementIdentifier»ElementType() {
|
||||
return new IGrammarAwareElementType("«element.grammarElementIdentifier»_ELEMENT_TYPE", «grammar.ideaLanguage».INSTANCE, GRAMMAR_ACCESS.«rule.gaElementsAccessor».«element.gaElementAccessor»);
|
||||
}
|
||||
«ENDFOR»
|
||||
}
|
||||
|
||||
public static final IGrammarAwareElementType «rule.grammarElementIdentifier»_ELEMENT_TYPE = associate(«rule.grammarElementIdentifier»Factory.create«rule.grammarElementIdentifier»ElementType());
|
||||
«FOR element:rule.eAllContents.filter(AbstractElement).toIterable»
|
||||
|
||||
public static final IGrammarAwareElementType «element.grammarElementIdentifier»_ELEMENT_TYPE = associate(«rule.grammarElementIdentifier»Factory.create«element.grammarElementIdentifier»ElementType());
|
||||
«ENDFOR»
|
||||
«ENDFOR»
|
||||
|
||||
@Override
|
||||
public IFileElementType getFileType() {
|
||||
return FILE_TYPE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IGrammarAwareElementType findElementType(«EObject» grammarElement) {
|
||||
return GRAMMAR_ELEMENT_TYPE.get(grammarElement);
|
||||
}
|
||||
«FOR rule:grammar.allNonTerminalRules»
|
||||
|
||||
public IGrammarAwareElementType get«rule.grammarElementIdentifier»ElementType() {
|
||||
return «rule.grammarElementIdentifier»_ELEMENT_TYPE;
|
||||
}
|
||||
«FOR element:rule.eAllContents.filter(AbstractElement).toIterable»
|
||||
|
||||
public IGrammarAwareElementType get«element.grammarElementIdentifier»ElementType() {
|
||||
return «element.grammarElementIdentifier»_ELEMENT_TYPE;
|
||||
}
|
||||
«ENDFOR»
|
||||
«ENDFOR»
|
||||
|
||||
}
|
||||
'''
|
||||
return file
|
||||
}
|
||||
|
||||
def compileTokenTypeProvider(Grammar grammar) {
|
||||
val tokenSet = "com.intellij.psi.tree.TokenSet".typeRef
|
||||
val iElementType = "com.intellij.psi.tree.IElementType".typeRef
|
||||
val indexedElementType = "IndexedElementType" // no typeRef is used here as 'IndexedElementType' is inner class of 'TokenTypeProvider'
|
||||
return fileAccessFactory.createJavaFile(grammar.tokenTypeProvider, '''
|
||||
@«Singleton»
|
||||
public class «grammar.tokenTypeProvider.simpleName» implements «"org.eclipse.xtext.idea.parser.TokenTypeProvider".typeRef» {
|
||||
|
||||
private static final String[] TOKEN_NAMES = new «grammar.psiInternalParser»(null).getTokenNames();
|
||||
|
||||
private static final «iElementType»[] tokenTypes = new «iElementType»[TOKEN_NAMES.length];
|
||||
|
||||
static {
|
||||
for (int i = 0; i < TOKEN_NAMES.length; i++) {
|
||||
tokenTypes[i] = new «indexedElementType»(TOKEN_NAMES[i], i, «grammar.ideaLanguage».INSTANCE);
|
||||
}
|
||||
}
|
||||
|
||||
«IF grammar.allTerminalRules.exists[name == 'WS']»
|
||||
private static final «tokenSet» WHITESPACE_TOKENS = «tokenSet».create(tokenTypes[«grammar.psiInternalParser».RULE_WS]);
|
||||
«ELSE»
|
||||
private static final «tokenSet» WHITESPACE_TOKENS = «tokenSet».EMPTY;
|
||||
«ENDIF»
|
||||
«IF grammar.allTerminalRules.exists[name == 'SL_COMMENT'] && grammar.allTerminalRules.exists[name == 'ML_COMMENT']»
|
||||
private static final «tokenSet» COMMENT_TOKENS = «tokenSet».create(tokenTypes[«grammar.psiInternalParser».RULE_SL_COMMENT], tokenTypes[«grammar.psiInternalParser».RULE_ML_COMMENT]);
|
||||
«ELSEIF grammar.allTerminalRules.exists[name == 'SL_COMMENT']»
|
||||
private static final «tokenSet» COMMENT_TOKENS = «tokenSet».create(tokenTypes[«grammar.psiInternalParser».RULE_SL_COMMENT]);
|
||||
«ELSEIF grammar.allTerminalRules.exists[name == 'ML_COMMENT']»
|
||||
private static final «tokenSet» COMMENT_TOKENS = «tokenSet».create(tokenTypes[«grammar.psiInternalParser».RULE_ML_COMMENT]);
|
||||
«ELSE»
|
||||
private static final «tokenSet» COMMENT_TOKENS = «tokenSet».EMPTY;
|
||||
«ENDIF»
|
||||
«IF grammar.allTerminalRules.exists[name == 'STRING']»
|
||||
private static final «tokenSet» STRING_TOKENS = «tokenSet».create(tokenTypes[«grammar.psiInternalParser».RULE_STRING]);
|
||||
«ELSE»
|
||||
private static final «tokenSet» STRING_TOKENS = «tokenSet».EMPTY;
|
||||
«ENDIF»
|
||||
|
||||
@Override
|
||||
public int getAntlrType(«iElementType» iElementType) {
|
||||
return (iElementType instanceof «indexedElementType») ? ((«indexedElementType») iElementType).getLocalIndex() : «Token».INVALID_TOKEN_TYPE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public «iElementType» getIElementType(int antlrType) {
|
||||
return tokenTypes[antlrType];
|
||||
}
|
||||
|
||||
@Override
|
||||
public «tokenSet» getWhitespaceTokens() {
|
||||
return WHITESPACE_TOKENS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public «tokenSet» getCommentTokens() {
|
||||
return COMMENT_TOKENS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public «tokenSet» getStringLiteralTokens() {
|
||||
return STRING_TOKENS;
|
||||
}
|
||||
|
||||
}
|
||||
''')
|
||||
}
|
||||
|
||||
def compileSyntaxHighlighterFactory(Grammar grammar) {
|
||||
val syntaxHighlighter = "com.intellij.openapi.fileTypes.SyntaxHighlighter".typeRef
|
||||
val lazySyntaxHighlighter = "com.intellij.openapi.fileTypes.SingleLazyInstanceSyntaxHighlighterFactory".typeRef
|
||||
return fileAccessFactory.createJavaFile(grammar.syntaxHighlighterFactory, '''
|
||||
public class «grammar.syntaxHighlighterFactory.simpleName» extends «lazySyntaxHighlighter» {
|
||||
|
||||
@Override
|
||||
@«"org.jetbrains.annotations.NotNull".typeRef»
|
||||
protected «syntaxHighlighter» createHighlighter() {
|
||||
return «grammar.ideaLanguage».INSTANCE.getInstance(«syntaxHighlighter».class);
|
||||
}
|
||||
}
|
||||
''')
|
||||
}
|
||||
|
||||
def compileSemanticHighlightVisitor(Grammar grammar) {
|
||||
return fileAccessFactory.createJavaFile(grammar.semanticHighlightVisitor, '''
|
||||
public class «grammar.semanticHighlightVisitor.simpleName» extends «"org.eclipse.xtext.idea.highlighting.SemanticHighlightVisitor".typeRef» {
|
||||
public «grammar.semanticHighlightVisitor.simpleName»() {
|
||||
«grammar.ideaLanguage».INSTANCE.injectMembers(this);
|
||||
}
|
||||
}
|
||||
''')
|
||||
}
|
||||
|
||||
def compileParserDefinition(Grammar grammar) {
|
||||
val EObjectRules = grammar.allRules.filter[EObjectRule]
|
||||
return fileAccessFactory.createJavaFile(grammar.parserDefinition, '''
|
||||
public class «grammar.parserDefinition.simpleName» extends «grammar.superParserDefinition» {
|
||||
«IF !EObjectRules.empty»
|
||||
|
||||
@«Inject»
|
||||
private «grammar.elementTypeProvider» elementTypeProvider;
|
||||
«ENDIF»
|
||||
|
||||
@Override
|
||||
public «"com.intellij.psi.PsiFile".typeRef» createFile(«"com.intellij.psi.FileViewProvider".typeRef» viewProvider) {
|
||||
return new «grammar.fileImpl»(viewProvider);
|
||||
}
|
||||
«IF !EObjectRules.empty»
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("rawtypes")
|
||||
public «'com.intellij.psi.PsiElement'.typeRef» createElement(«'com.intellij.lang.ASTNode'.typeRef» node) {
|
||||
Boolean hasSemanticElement = node.getUserData(«'org.eclipse.xtext.idea.nodemodel.IASTNodeAwareNodeModelBuilder'.typeRef».HAS_SEMANTIC_ELEMENT_KEY);
|
||||
if (hasSemanticElement != null && hasSemanticElement) {
|
||||
«'com.intellij.psi.tree.IElementType'.typeRef» elementType = node.getElementType();
|
||||
«FOR rule : EObjectRules»
|
||||
if (elementType == elementTypeProvider.get«rule.grammarElementIdentifier»ElementType()) {
|
||||
«IF rule.named»
|
||||
return new «'org.eclipse.xtext.psi.impl.PsiNamedEObjectImpl'.typeRef»(node) {};
|
||||
«ELSE»
|
||||
return new «'org.eclipse.xtext.psi.impl.PsiEObjectImpl'.typeRef»(node) {};
|
||||
«ENDIF»
|
||||
}
|
||||
«FOR element : rule.EObjectElements»
|
||||
if (elementType == elementTypeProvider.get«element.grammarElementIdentifier»ElementType()) {
|
||||
«IF element.named»
|
||||
return new «'org.eclipse.xtext.psi.impl.PsiNamedEObjectImpl'.typeRef»(node) {};
|
||||
«ELSE»
|
||||
return new «'org.eclipse.xtext.psi.impl.PsiEObjectImpl'.typeRef»(node) {};
|
||||
«ENDIF»
|
||||
}
|
||||
«ENDFOR»
|
||||
«ENDFOR»
|
||||
throw new «'java.lang.IllegalStateException'.typeRef»("Unexpected element type: " + elementType);
|
||||
}
|
||||
return super.createElement(node);
|
||||
}
|
||||
«ENDIF»
|
||||
|
||||
}
|
||||
''')
|
||||
}
|
||||
|
||||
protected def getEObjectElements(AbstractRule rule) {
|
||||
rule.eAllOfType(AbstractElement).filter[ element |
|
||||
switch element {
|
||||
Action,
|
||||
RuleCall case element.EObjectRuleCall: true
|
||||
default: false
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
protected def isNamed(EObject element) {
|
||||
val type = switch element {
|
||||
AbstractRule: element.type
|
||||
RuleCall: element.rule?.type
|
||||
Action: element.type
|
||||
}
|
||||
val classifier = type?.classifier
|
||||
val feature = if(classifier instanceof EClass) classifier.getEStructuralFeature('name')
|
||||
feature instanceof EAttribute && !feature.many && feature.EType.instanceClass !== null && String.isAssignableFrom(feature.EType.instanceClass)
|
||||
}
|
||||
|
||||
def compileAbstractCompletionContributor(Grammar grammar) {
|
||||
fileAccessFactory.createJavaFile(grammar.abstractCompletionContributor, '''
|
||||
public class «grammar.abstractCompletionContributor.simpleName» extends «grammar.completionContributorSuperClass» {
|
||||
public «grammar.abstractCompletionContributor.simpleName»(«"org.eclipse.xtext.idea.lang.AbstractXtextLanguage".typeRef» lang) {
|
||||
super(lang);
|
||||
}
|
||||
}
|
||||
''')
|
||||
}
|
||||
|
||||
def JavaFileAccess compileCompletionContributor(Grammar grammar) {
|
||||
if (isGenerateXtendStub) {
|
||||
|
||||
fileAccessFactory.createXtendFile(grammar.completionContributor, '''
|
||||
class «grammar.completionContributor.simpleName» extends «grammar.abstractCompletionContributor» {
|
||||
new() {
|
||||
this(«grammar.ideaLanguage».INSTANCE)
|
||||
}
|
||||
|
||||
new(«"org.eclipse.xtext.idea.lang.AbstractXtextLanguage".typeRef» lang) {
|
||||
super(lang)
|
||||
//custom rules here
|
||||
}
|
||||
}
|
||||
''')
|
||||
} else {
|
||||
|
||||
fileAccessFactory.createJavaFile(grammar.completionContributor, '''
|
||||
public class «grammar.completionContributor.simpleName» extends «grammar.abstractCompletionContributor» {
|
||||
public «grammar.completionContributor.simpleName»() {
|
||||
this(«grammar.ideaLanguage».INSTANCE);
|
||||
}
|
||||
|
||||
public «grammar.completionContributor.simpleName»(«"org.eclipse.xtext.idea.lang.AbstractXtextLanguage".typeRef» lang) {
|
||||
super(lang);
|
||||
//custom rules here
|
||||
}
|
||||
}
|
||||
''')
|
||||
}
|
||||
}
|
||||
def TextFileAccess compileServicesISetup(Grammar grammar) {
|
||||
fileAccessFactory.createTextFile(
|
||||
'''META-INF/services/«ISetup.name»''', '''
|
||||
«grammar.runtimeSetup»
|
||||
''')
|
||||
}
|
||||
|
||||
def JavaFileAccess compileFacetConfiguration(Grammar grammar) {
|
||||
val file = if (isGenerateXtendStub) {
|
||||
fileAccessFactory.createXtendFile(grammar.facetConfiguration)
|
||||
} else {
|
||||
fileAccessFactory.createJavaFile(grammar.facetConfiguration)
|
||||
}
|
||||
file.importType("com.intellij.openapi.components.PersistentStateComponent".typeRef)
|
||||
file.importType("com.intellij.openapi.components.State".typeRef)
|
||||
file.importType("com.intellij.openapi.components.Storage".typeRef)
|
||||
file.importType("com.intellij.openapi.components.StoragePathMacros".typeRef)
|
||||
file.importType("com.intellij.openapi.components.StorageScheme".typeRef)
|
||||
if (grammar.inheritsXbase) {
|
||||
file.importType("org.eclipse.xtext.xbase.idea.facet.XbaseFacetConfiguration".typeRef)
|
||||
file.importType("org.eclipse.xtext.xbase.idea.facet.XbaseGeneratorConfigurationState".typeRef)
|
||||
} else {
|
||||
file.importType("org.eclipse.xtext.idea.facet.AbstractFacetConfiguration".typeRef)
|
||||
file.importType("org.eclipse.xtext.idea.facet.GeneratorConfigurationState".typeRef)
|
||||
}
|
||||
file.content = '''
|
||||
«IF isGenerateXtendStub»
|
||||
@State(name = "«grammar.name»Generator", storages = #[
|
||||
@Storage(id = "default", file = StoragePathMacros.PROJECT_FILE),
|
||||
@Storage(id = "dir", file = StoragePathMacros.PROJECT_CONFIG_DIR
|
||||
+ "/«grammar.simpleName»GeneratorConfig.xml", scheme = StorageScheme.DIRECTORY_BASED)])
|
||||
«ELSE»
|
||||
@State(name = "«grammar.name»Generator", storages = {
|
||||
@Storage(id = "default", file = StoragePathMacros.PROJECT_FILE),
|
||||
@Storage(id = "dir", file = StoragePathMacros.PROJECT_CONFIG_DIR
|
||||
+ "/«grammar.simpleName»GeneratorConfig.xml", scheme = StorageScheme.DIRECTORY_BASED)})
|
||||
«ENDIF»
|
||||
«IF !isGenerateXtendStub»public«ENDIF» class «grammar.facetConfiguration.simpleName» extends «IF grammar.inheritsXbase»XbaseFacetConfiguration implements PersistentStateComponent<XbaseGeneratorConfigurationState>«ELSE»AbstractFacetConfiguration implements PersistentStateComponent<GeneratorConfigurationState>«ENDIF»{
|
||||
|
||||
}
|
||||
'''
|
||||
return file
|
||||
}
|
||||
|
||||
def JavaFileAccess compileFacetType(Grammar grammar) {
|
||||
val faceTypeId = "com.intellij.facet.FacetTypeId".typeRef("com.intellij.facet.Facet".typeRef(grammar.facetConfiguration))
|
||||
return fileAccessFactory.createJavaFile(grammar.facetType, '''
|
||||
public class «grammar.facetType.simpleName» extends «"org.eclipse.xtext.idea.facet.AbstractFacetType".typeRef(grammar.facetConfiguration)» {
|
||||
|
||||
public static final «faceTypeId» TYPEID = new «faceTypeId»("«grammar.name»");
|
||||
|
||||
public «grammar.facetType.simpleName»() {
|
||||
super(TYPEID, "«grammar.name»", "«grammar.simpleName»");
|
||||
«grammar.ideaLanguage».INSTANCE.injectMembers(this);
|
||||
}
|
||||
}
|
||||
''')
|
||||
}
|
||||
|
||||
def JavaFileAccess compileBaseColorSettingsPage(Grammar grammar) {
|
||||
fileAccessFactory.createJavaFile(grammar.baseColorSettingsPage, '''
|
||||
public class «grammar.baseColorSettingsPage.simpleName» extends «"org.eclipse.xtext.idea.highlighting.AbstractColorSettingsPage".typeRef» {
|
||||
|
||||
public «grammar.baseColorSettingsPage.simpleName»() {
|
||||
«grammar.ideaLanguage».INSTANCE.injectMembers(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDisplayName() {
|
||||
return «grammar.ideaLanguage».INSTANCE.getDisplayName();
|
||||
}
|
||||
}
|
||||
''')
|
||||
}
|
||||
|
||||
def JavaFileAccess compileColorSettingsPage(Grammar grammar) {
|
||||
if (isGenerateXtendStub) {
|
||||
fileAccessFactory.createXtendFile(grammar.colorSettingsPage, '''
|
||||
class «grammar.colorSettingsPage.simpleName» extends «grammar.baseColorSettingsPage» {
|
||||
}
|
||||
''')
|
||||
} else {
|
||||
fileAccessFactory.createJavaFile(grammar.colorSettingsPage, '''
|
||||
public class «grammar.colorSettingsPage.simpleName» extends «grammar.baseColorSettingsPage» {
|
||||
}
|
||||
''')
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,397 +7,15 @@
|
|||
*******************************************************************************/
|
||||
package org.eclipse.xtext.xtext.generator.idea.parser.antlr
|
||||
|
||||
import com.google.inject.Inject
|
||||
import org.eclipse.emf.ecore.EObject
|
||||
import org.eclipse.xtext.AbstractRule
|
||||
import org.eclipse.xtext.Action
|
||||
import org.eclipse.xtext.Assignment
|
||||
import org.eclipse.xtext.CrossReference
|
||||
import org.eclipse.xtext.EnumLiteralDeclaration
|
||||
import org.eclipse.xtext.EnumRule
|
||||
import org.eclipse.xtext.Grammar
|
||||
import org.eclipse.xtext.Keyword
|
||||
import org.eclipse.xtext.ParserRule
|
||||
import org.eclipse.xtext.RuleCall
|
||||
import org.eclipse.xtext.TerminalRule
|
||||
import org.eclipse.xtext.UnorderedGroup
|
||||
import org.eclipse.xtext.xtext.generator.idea.IdeaPluginClassNames
|
||||
import org.eclipse.xtext.xtext.generator.parser.antlr.AbstractAntlrGrammarWithActionsGenerator
|
||||
import org.eclipse.xtext.xtext.generator.parser.antlr.AntlrOptions
|
||||
|
||||
import static extension org.eclipse.xtext.EcoreUtil2.*
|
||||
import static extension org.eclipse.xtext.GrammarUtil.*
|
||||
import static extension org.eclipse.xtext.xtext.generator.parser.antlr.AntlrGrammarGenUtil.*
|
||||
import org.eclipse.xtext.AbstractElement
|
||||
|
||||
@Deprecated
|
||||
class PsiAntlrGrammarGenerator extends AbstractAntlrGrammarWithActionsGenerator {
|
||||
|
||||
@Inject
|
||||
extension IdeaPluginClassNames
|
||||
@Inject
|
||||
extension PsiGrammarNaming naming
|
||||
|
||||
override protected getGrammarNaming() {
|
||||
naming
|
||||
|
||||
}
|
||||
|
||||
override protected compileParserImports(Grammar it, AntlrOptions options) '''
|
||||
|
||||
import «grammarNaming.getInternalParserSuperClass(it).name»;
|
||||
import «grammar.elementTypeProvider»;
|
||||
import org.eclipse.xtext.idea.parser.TokenTypeProvider;
|
||||
import org.eclipse.xtext.parser.antlr.XtextTokenStream;
|
||||
import org.eclipse.xtext.parser.antlr.XtextTokenStream.HiddenTokens;
|
||||
«IF !allParserRules.map[eAllContentsAsList].flatten.filter(UnorderedGroup).empty && options.backtrack»
|
||||
import org.eclipse.xtext.parser.antlr.IUnorderedGroupHelper.UnorderedGroupState;
|
||||
«ENDIF»
|
||||
import «grammarAccess.name»;
|
||||
|
||||
import com.intellij.lang.PsiBuilder;
|
||||
'''
|
||||
|
||||
override protected compileParserMembers(Grammar it, AntlrOptions options) '''
|
||||
|
||||
@parser::members {
|
||||
|
||||
«IF options.backtrack»
|
||||
/*
|
||||
This grammar contains a lot of empty actions to work around a bug in ANTLR.
|
||||
Otherwise the ANTLR tool will create synpreds that cannot be compiled in some rare cases.
|
||||
*/
|
||||
|
||||
«ENDIF»
|
||||
protected «grammarAccess.simpleName» grammarAccess;
|
||||
|
||||
protected «grammar.elementTypeProvider.simpleName» elementTypeProvider;
|
||||
|
||||
public «grammar.psiInternalParser.simpleName»(PsiBuilder builder, TokenStream input, «grammar.elementTypeProvider.simpleName» elementTypeProvider, «grammarAccess.simpleName» grammarAccess) {
|
||||
this(input);
|
||||
setPsiBuilder(builder);
|
||||
this.grammarAccess = grammarAccess;
|
||||
this.elementTypeProvider = elementTypeProvider;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getFirstRuleName() {
|
||||
return "«(allParserRules.head.originalElement as AbstractRule).name»";
|
||||
}
|
||||
|
||||
}
|
||||
'''
|
||||
|
||||
override protected shouldBeSkipped(TerminalRule it, Grammar grammar) {
|
||||
false
|
||||
}
|
||||
|
||||
override protected dispatch compileRule(ParserRule it, Grammar grammar, AntlrOptions options) '''
|
||||
«IF isValidEntryRule»
|
||||
//Entry rule «entryRuleName»
|
||||
«entryRuleName» returns [«currentType» current=false]«compileEntryInit(options)»:
|
||||
{ «markComposite» }
|
||||
iv_«originalElement.ruleName»=«originalElement.ruleName»«defaultArgumentList»
|
||||
{ $current=$iv_«originalElement.ruleName».current; }
|
||||
EOF;
|
||||
«compileEntryFinally(options)»
|
||||
«ENDIF»
|
||||
|
||||
«compileEBNF(options)»
|
||||
'''
|
||||
|
||||
override protected compileInit(AbstractRule it, AntlrOptions options) '''
|
||||
«IF it instanceof ParserRule»«getParameterList(!isPassCurrentIntoFragment, currentType)»«ENDIF» returns «compileReturns(options)»
|
||||
«super.compileInit(it, options)»'''
|
||||
|
||||
protected def compileReturns(AbstractRule it, AntlrOptions options) {
|
||||
switch it {
|
||||
ParserRule case !originalElement.datatypeRule && originalElement.isEObjectFragmentRule:
|
||||
'''[«currentType» current=in_current]'''
|
||||
default:
|
||||
'''[«currentType» current=false]'''
|
||||
}
|
||||
}
|
||||
|
||||
override protected _dataTypeEbnf2(Keyword it, boolean supportActions) {
|
||||
if (supportActions) '''
|
||||
{
|
||||
«markLeaf»
|
||||
}
|
||||
kw=«super._dataTypeEbnf2(it, supportActions)»
|
||||
{
|
||||
«doneLeaf('kw')»
|
||||
}
|
||||
'''
|
||||
else {
|
||||
super._dataTypeEbnf2(it, supportActions)
|
||||
}
|
||||
}
|
||||
|
||||
override protected _dataTypeEbnf2(RuleCall it, boolean supportActions) {
|
||||
if (supportActions) {
|
||||
switch it.getRule {
|
||||
EnumRule case assigned,
|
||||
ParserRule case assigned:
|
||||
super._dataTypeEbnf2(it, supportActions)
|
||||
EnumRule,
|
||||
ParserRule: '''
|
||||
{
|
||||
«markComposite»
|
||||
}
|
||||
«super._dataTypeEbnf2(it, supportActions)»
|
||||
{
|
||||
«doneComposite»
|
||||
}
|
||||
'''
|
||||
TerminalRule: '''
|
||||
{
|
||||
«markLeaf»
|
||||
}
|
||||
«localVar»=«super._dataTypeEbnf2(it, supportActions)»
|
||||
{
|
||||
«doneLeaf(localVar)»
|
||||
}
|
||||
'''
|
||||
default:
|
||||
super._dataTypeEbnf2(it, supportActions)
|
||||
}
|
||||
} else {
|
||||
super._dataTypeEbnf2(it, supportActions)
|
||||
}
|
||||
}
|
||||
|
||||
override protected _ebnf2(Action it, AntlrOptions options, boolean supportActions) {
|
||||
if (!supportActions)
|
||||
return super._ebnf2(it, options, supportActions)
|
||||
else '''
|
||||
«IF options.backtrack»
|
||||
{
|
||||
/* */
|
||||
}
|
||||
«ENDIF»
|
||||
{
|
||||
«precedeComposite»
|
||||
«doneComposite»
|
||||
«associateWithSemanticElement»
|
||||
}
|
||||
'''
|
||||
}
|
||||
|
||||
override protected _ebnf2(Keyword it, AntlrOptions options, boolean supportActions) {
|
||||
if (!supportActions)
|
||||
return super._ebnf2(it, options, supportActions)
|
||||
else if(assigned) '''
|
||||
{
|
||||
«markLeaf»
|
||||
}
|
||||
«containingAssignment.localVar(it)»=«super._ebnf2(it, options, supportActions)»
|
||||
{
|
||||
«doneLeaf(containingAssignment.localVar(it))»
|
||||
}
|
||||
'''
|
||||
else '''
|
||||
{
|
||||
«markLeaf»
|
||||
}
|
||||
«localVar»=«super._ebnf2(it, options, supportActions)»
|
||||
{
|
||||
«doneLeaf(localVar)»
|
||||
}
|
||||
'''
|
||||
}
|
||||
|
||||
override protected _ebnf2(EnumLiteralDeclaration it, AntlrOptions options, boolean supportActions) {
|
||||
if (!supportActions)
|
||||
return super._ebnf2(it, options, supportActions)
|
||||
else '''
|
||||
{
|
||||
«markLeaf»
|
||||
}
|
||||
«localVar»=«super._ebnf2(it, options, supportActions)»
|
||||
{
|
||||
«doneLeaf(localVar)»
|
||||
}
|
||||
'''
|
||||
}
|
||||
|
||||
override protected _ebnf2(RuleCall it, AntlrOptions options, boolean supportActions) {
|
||||
if (supportActions) {
|
||||
switch rule {
|
||||
EnumRule case assigned,
|
||||
ParserRule case assigned:
|
||||
super._ebnf2(it, options, supportActions)
|
||||
EnumRule,
|
||||
ParserRule case rule.originalElement.datatypeRule: '''
|
||||
«IF options.backtrack»
|
||||
{
|
||||
/* */
|
||||
}
|
||||
«ENDIF»
|
||||
{
|
||||
«markComposite»
|
||||
}
|
||||
«super._ebnf2(it, options, supportActions)»
|
||||
{
|
||||
«doneComposite»
|
||||
}
|
||||
'''
|
||||
ParserRule: '''
|
||||
«IF options.backtrack»
|
||||
{
|
||||
/* */
|
||||
}
|
||||
«ENDIF»
|
||||
{
|
||||
«IF isEObjectFragmentRuleCall»
|
||||
if (!$current) {
|
||||
«associateWithSemanticElement»
|
||||
$current = true;
|
||||
}
|
||||
«ENDIF»
|
||||
«markComposite»
|
||||
}
|
||||
«localVar»=«super._ebnf2(it, options, supportActions)»
|
||||
{
|
||||
$current = $«localVar».current;
|
||||
«doneComposite»
|
||||
}
|
||||
'''
|
||||
TerminalRule: '''
|
||||
{
|
||||
«markLeaf»
|
||||
}
|
||||
«localVar»=«super._ebnf2(it, options, supportActions)»
|
||||
{
|
||||
«doneLeaf(localVar)»
|
||||
}
|
||||
'''
|
||||
default:
|
||||
super._ebnf2(it, options, supportActions)
|
||||
}
|
||||
} else {
|
||||
super._ebnf2(it, options, supportActions)
|
||||
}
|
||||
}
|
||||
|
||||
override protected crossrefEbnf(AbstractRule it, RuleCall call, CrossReference ref, boolean supportActions) {
|
||||
if (supportActions) {
|
||||
switch it {
|
||||
EnumRule,
|
||||
ParserRule: '''
|
||||
{
|
||||
«ref.markComposite»
|
||||
}
|
||||
«super.crossrefEbnf(it, call, ref, supportActions)»
|
||||
{
|
||||
«ref.doneComposite»
|
||||
}
|
||||
'''
|
||||
TerminalRule: '''
|
||||
{
|
||||
«ref.markLeaf»
|
||||
}
|
||||
«ref.containingAssignment.localVar»=«super.crossrefEbnf(it, call, ref, supportActions)»
|
||||
{
|
||||
«ref.doneLeaf(ref.containingAssignment.localVar)»
|
||||
}
|
||||
'''
|
||||
default:
|
||||
throw new IllegalStateException("crossrefEbnf is not supported for " + it)
|
||||
}
|
||||
} else {
|
||||
super.crossrefEbnf(it, call, ref, supportActions)
|
||||
}
|
||||
}
|
||||
|
||||
override protected _assignmentEbnf(CrossReference it, Assignment assignment, AntlrOptions options, boolean supportActions) {
|
||||
if (supportActions) '''
|
||||
«IF options.backtrack»
|
||||
{
|
||||
/* */
|
||||
}
|
||||
«ENDIF»
|
||||
{
|
||||
if (!$current) {
|
||||
«associateWithSemanticElement»
|
||||
$current = true;
|
||||
}
|
||||
}
|
||||
«super._assignmentEbnf(it, assignment, options, supportActions)»'''
|
||||
else
|
||||
super._assignmentEbnf(it, assignment, options, supportActions)
|
||||
}
|
||||
|
||||
override protected _assignmentEbnf(AbstractElement it, Assignment assignment, AntlrOptions options, boolean supportActions) {
|
||||
if (supportActions) '''
|
||||
«super._assignmentEbnf(it, assignment, options, supportActions)»
|
||||
{
|
||||
if (!$current) {
|
||||
«associateWithSemanticElement»
|
||||
$current = true;
|
||||
}
|
||||
}
|
||||
'''
|
||||
else
|
||||
super._assignmentEbnf(it, assignment, options, supportActions)
|
||||
}
|
||||
|
||||
override protected _assignmentEbnf(RuleCall it, Assignment assignment, AntlrOptions options, boolean supportActions) {
|
||||
if (supportActions) {
|
||||
switch rule {
|
||||
EnumRule,
|
||||
ParserRule: '''
|
||||
{
|
||||
«markComposite»
|
||||
}
|
||||
«assignment.localVar(it)»=«super._assignmentEbnf(it, assignment, options, supportActions)»
|
||||
{
|
||||
«doneComposite»
|
||||
if(!$current) {
|
||||
«associateWithSemanticElement»
|
||||
$current = true;
|
||||
}
|
||||
}
|
||||
'''
|
||||
TerminalRule: '''
|
||||
{
|
||||
«markLeaf»
|
||||
}
|
||||
«assignment.localVar(it)»=«super._assignmentEbnf(it, assignment, options, supportActions)»
|
||||
{
|
||||
if(!$current) {
|
||||
«associateWithSemanticElement»
|
||||
$current = true;
|
||||
}
|
||||
}
|
||||
{
|
||||
«doneLeaf(assignment.localVar(it))»
|
||||
}
|
||||
'''
|
||||
default:
|
||||
throw new IllegalStateException("assignmentEbnf is not supported for " + it)
|
||||
}
|
||||
} else {
|
||||
super._assignmentEbnf(it, assignment, options, supportActions)
|
||||
}
|
||||
}
|
||||
|
||||
def protected markLeaf(EObject it) '''markLeaf(elementTypeProvider.get«originalElement.grammarElementIdentifier»ElementType());'''
|
||||
|
||||
def protected doneLeaf(EObject it, String token) '''doneLeaf(«token»);'''
|
||||
|
||||
def protected markComposite(EObject it) '''markComposite(elementTypeProvider.get«originalElement.grammarElementIdentifier»ElementType());'''
|
||||
|
||||
def protected doneComposite(EObject it) '''doneComposite();'''
|
||||
|
||||
def protected precedeComposite(EObject it) '''precedeComposite(elementTypeProvider.get«originalElement.grammarElementIdentifier»ElementType());'''
|
||||
|
||||
def protected associateWithSemanticElement() '''associateWithSemanticElement();'''
|
||||
|
||||
override protected isPassCurrentIntoFragment() {
|
||||
true
|
||||
}
|
||||
|
||||
override protected getCurrentType() {
|
||||
'Boolean'
|
||||
}
|
||||
|
||||
}
|
|
@ -1,37 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2015 itemis AG (http://www.itemis.eu) and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*******************************************************************************/
|
||||
package org.eclipse.xtext.xtext.generator.idea.parser.antlr
|
||||
|
||||
import com.google.inject.Inject
|
||||
import com.google.inject.Singleton
|
||||
import org.eclipse.xtext.Grammar
|
||||
import org.eclipse.xtext.xtext.generator.XtextGeneratorNaming
|
||||
import org.eclipse.xtext.xtext.generator.model.TypeReference
|
||||
import org.eclipse.xtext.xtext.generator.parser.antlr.GrammarNaming
|
||||
|
||||
@Singleton
|
||||
class PsiGrammarNaming extends GrammarNaming {
|
||||
@Inject
|
||||
extension XtextGeneratorNaming
|
||||
|
||||
override isCombinedGrammar(Grammar it) {
|
||||
// separated grammars are not supported for IDEA yet
|
||||
true
|
||||
}
|
||||
|
||||
override String getParserPackage(Grammar it) '''«ideaBasePackage».parser.antlr'''
|
||||
|
||||
override getInternalParserSuperClass(Grammar it) {
|
||||
new TypeReference("org.eclipse.xtext.idea.parser.AbstractPsiAntlrParser")
|
||||
}
|
||||
|
||||
override protected getGrammarNamePrefix(Grammar it) {
|
||||
"Psi"
|
||||
}
|
||||
|
||||
}
|
|
@ -7,33 +7,15 @@
|
|||
*******************************************************************************/
|
||||
package org.eclipse.xtext.xtext.generator.idea.parser.antlr
|
||||
|
||||
import com.google.inject.Inject
|
||||
import org.eclipse.xtext.xtext.generator.parser.antlr.AbstractAntlrGeneratorFragment2
|
||||
|
||||
@Deprecated
|
||||
class XtextAntlrIDEAGeneratorFragment extends AbstractAntlrGeneratorFragment2 {
|
||||
|
||||
@Inject
|
||||
PsiAntlrGrammarGenerator generator
|
||||
|
||||
@Inject extension PsiGrammarNaming
|
||||
|
||||
override protected doGenerate() {
|
||||
if (!projectConfig.ideaPlugin.enabled)
|
||||
return;
|
||||
val fsa = projectConfig.ideaPlugin.srcGen
|
||||
generator.generate(grammar, options, fsa)
|
||||
|
||||
val encoding = codeConfig.encoding
|
||||
val grammarFileName = grammar.parserGrammar.grammarFileName
|
||||
val absoluteGrammarFileName = '''«fsa.path»/«grammarFileName»'''
|
||||
addAntlrParam('-fo')
|
||||
addAntlrParam(absoluteGrammarFileName.substring(0, absoluteGrammarFileName.lastIndexOf('/')))
|
||||
antlrTool.runWithEncodingAndParams(absoluteGrammarFileName, encoding, antlrParams)
|
||||
|
||||
simplifyUnorderedGroupPredicatesIfRequired(grammar, fsa, grammar.internalParserClass)
|
||||
splitParserAndLexerIfEnabled(fsa, grammar.internalParserClass, grammar.lexerClass)
|
||||
normalizeTokens(fsa, grammar.lexerGrammar.tokensFileName)
|
||||
suppressWarnings(fsa, grammar.internalParserClass, grammar.lexerClass)
|
||||
normalizeLineDelimiters(fsa, grammar.internalParserClass, grammar.lexerClass)
|
||||
System.err.println("The support for Idea has been removed!")
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,283 +0,0 @@
|
|||
/**
|
||||
* Copyright (c) 2015 itemis AG (http://www.itemis.eu) and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*/
|
||||
package org.eclipse.xtext.xtext.generator.idea;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import org.eclipse.xtext.Grammar;
|
||||
import org.eclipse.xtext.GrammarUtil;
|
||||
import org.eclipse.xtext.xbase.lib.Extension;
|
||||
import org.eclipse.xtext.xbase.lib.IterableExtensions;
|
||||
import org.eclipse.xtext.xtext.generator.XtextGeneratorNaming;
|
||||
import org.eclipse.xtext.xtext.generator.model.TypeReference;
|
||||
|
||||
@SuppressWarnings("all")
|
||||
public class IdeaPluginClassNames {
|
||||
@Inject
|
||||
@Extension
|
||||
private XtextGeneratorNaming _xtextGeneratorNaming;
|
||||
|
||||
public String toPath(final String fullName) {
|
||||
return fullName.replace(".", "/");
|
||||
}
|
||||
|
||||
public TypeReference getIdeaSetup(final Grammar it) {
|
||||
String _ideaBasePackage = this._xtextGeneratorNaming.getIdeaBasePackage(it);
|
||||
String _simpleName = GrammarUtil.getSimpleName(it);
|
||||
String _plus = (_simpleName + "IdeaSetup");
|
||||
return new TypeReference(_ideaBasePackage, _plus);
|
||||
}
|
||||
|
||||
public TypeReference getExtensionFactory(final Grammar it) {
|
||||
String _ideaBasePackage = this._xtextGeneratorNaming.getIdeaBasePackage(it);
|
||||
String _simpleName = GrammarUtil.getSimpleName(it);
|
||||
String _plus = (_simpleName + "ExtensionFactory");
|
||||
return new TypeReference(_ideaBasePackage, _plus);
|
||||
}
|
||||
|
||||
public TypeReference getAbstractIdeaModule(final Grammar it) {
|
||||
String _ideaBasePackage = this._xtextGeneratorNaming.getIdeaBasePackage(it);
|
||||
String _simpleName = GrammarUtil.getSimpleName(it);
|
||||
String _plus = ("Abstract" + _simpleName);
|
||||
String _plus_1 = (_plus + "IdeaModule");
|
||||
return new TypeReference(_ideaBasePackage, _plus_1);
|
||||
}
|
||||
|
||||
public TypeReference getFileType(final Grammar it) {
|
||||
String _ideaBasePackage = this._xtextGeneratorNaming.getIdeaBasePackage(it);
|
||||
String _plus = (_ideaBasePackage + ".lang");
|
||||
String _simpleName = GrammarUtil.getSimpleName(it);
|
||||
String _plus_1 = (_simpleName + "FileType");
|
||||
return new TypeReference(_plus, _plus_1);
|
||||
}
|
||||
|
||||
public TypeReference getAbstractFileType(final Grammar it) {
|
||||
String _ideaBasePackage = this._xtextGeneratorNaming.getIdeaBasePackage(it);
|
||||
String _plus = (_ideaBasePackage + ".lang");
|
||||
String _simpleName = GrammarUtil.getSimpleName(it);
|
||||
String _plus_1 = ("Abstract" + _simpleName);
|
||||
String _plus_2 = (_plus_1 + "FileType");
|
||||
return new TypeReference(_plus, _plus_2);
|
||||
}
|
||||
|
||||
public TypeReference getFileTypeFactory(final Grammar it) {
|
||||
String _ideaBasePackage = this._xtextGeneratorNaming.getIdeaBasePackage(it);
|
||||
String _plus = (_ideaBasePackage + ".lang");
|
||||
String _simpleName = GrammarUtil.getSimpleName(it);
|
||||
String _plus_1 = (_simpleName + "FileTypeFactory");
|
||||
return new TypeReference(_plus, _plus_1);
|
||||
}
|
||||
|
||||
public TypeReference getIdeaLanguage(final Grammar it) {
|
||||
String _ideaBasePackage = this._xtextGeneratorNaming.getIdeaBasePackage(it);
|
||||
String _plus = (_ideaBasePackage + ".lang");
|
||||
String _simpleName = GrammarUtil.getSimpleName(it);
|
||||
String _plus_1 = (_simpleName + "Language");
|
||||
return new TypeReference(_plus, _plus_1);
|
||||
}
|
||||
|
||||
public TypeReference getCodeBlockModificationListener(final Grammar it) {
|
||||
String _ideaBasePackage = this._xtextGeneratorNaming.getIdeaBasePackage(it);
|
||||
String _plus = (_ideaBasePackage + ".lang.psi");
|
||||
String _simpleName = GrammarUtil.getSimpleName(it);
|
||||
String _plus_1 = (_simpleName + "CodeBlockModificationListener");
|
||||
return new TypeReference(_plus, _plus_1);
|
||||
}
|
||||
|
||||
public TypeReference getPsiParser(final Grammar it) {
|
||||
String _ideaBasePackage = this._xtextGeneratorNaming.getIdeaBasePackage(it);
|
||||
String _plus = (_ideaBasePackage + ".lang.parser");
|
||||
String _simpleName = GrammarUtil.getSimpleName(it);
|
||||
String _plus_1 = (_simpleName + "PsiParser");
|
||||
return new TypeReference(_plus, _plus_1);
|
||||
}
|
||||
|
||||
public TypeReference getAntlrTokenFileProvider(final Grammar it) {
|
||||
String _ideaBasePackage = this._xtextGeneratorNaming.getIdeaBasePackage(it);
|
||||
String _plus = (_ideaBasePackage + ".lang.parser.antlr");
|
||||
String _simpleName = GrammarUtil.getSimpleName(it);
|
||||
String _plus_1 = (_simpleName + "AntlrTokenFileProvider");
|
||||
return new TypeReference(_plus, _plus_1);
|
||||
}
|
||||
|
||||
public TypeReference getPomDeclarationSearcher(final Grammar it) {
|
||||
String _ideaBasePackage = this._xtextGeneratorNaming.getIdeaBasePackage(it);
|
||||
String _plus = (_ideaBasePackage + ".lang.pom");
|
||||
String _simpleName = GrammarUtil.getSimpleName(it);
|
||||
String _plus_1 = (_simpleName + "PomDeclarationSearcher");
|
||||
return new TypeReference(_plus, _plus_1);
|
||||
}
|
||||
|
||||
public TypeReference getSyntaxHighlighterFactory(final Grammar it) {
|
||||
String _ideaBasePackage = this._xtextGeneratorNaming.getIdeaBasePackage(it);
|
||||
String _plus = (_ideaBasePackage + ".highlighting");
|
||||
String _simpleName = GrammarUtil.getSimpleName(it);
|
||||
String _plus_1 = (_simpleName + "SyntaxHighlighterFactory");
|
||||
return new TypeReference(_plus, _plus_1);
|
||||
}
|
||||
|
||||
public TypeReference getSemanticHighlightVisitor(final Grammar it) {
|
||||
String _ideaBasePackage = this._xtextGeneratorNaming.getIdeaBasePackage(it);
|
||||
String _plus = (_ideaBasePackage + ".highlighting");
|
||||
String _simpleName = GrammarUtil.getSimpleName(it);
|
||||
String _plus_1 = (_simpleName + "SemanticHighlightVisitor");
|
||||
return new TypeReference(_plus, _plus_1);
|
||||
}
|
||||
|
||||
public TypeReference getSuperParserDefinition(final Grammar it) {
|
||||
return TypeReference.typeRef("org.eclipse.xtext.idea.parser.AbstractXtextParserDefinition");
|
||||
}
|
||||
|
||||
public TypeReference getParserDefinition(final Grammar it) {
|
||||
String _ideaBasePackage = this._xtextGeneratorNaming.getIdeaBasePackage(it);
|
||||
String _plus = (_ideaBasePackage + ".lang.parser");
|
||||
String _simpleName = GrammarUtil.getSimpleName(it);
|
||||
String _plus_1 = (_simpleName + "ParserDefinition");
|
||||
return new TypeReference(_plus, _plus_1);
|
||||
}
|
||||
|
||||
public TypeReference getTokenTypeProvider(final Grammar it) {
|
||||
String _ideaBasePackage = this._xtextGeneratorNaming.getIdeaBasePackage(it);
|
||||
String _plus = (_ideaBasePackage + ".lang.parser");
|
||||
String _simpleName = GrammarUtil.getSimpleName(it);
|
||||
String _plus_1 = (_simpleName + "TokenTypeProvider");
|
||||
return new TypeReference(_plus, _plus_1);
|
||||
}
|
||||
|
||||
public TypeReference getElementTypeProvider(final Grammar it) {
|
||||
String _ideaBasePackage = this._xtextGeneratorNaming.getIdeaBasePackage(it);
|
||||
String _plus = (_ideaBasePackage + ".lang");
|
||||
String _simpleName = GrammarUtil.getSimpleName(it);
|
||||
String _plus_1 = (_simpleName + "ElementTypeProvider");
|
||||
return new TypeReference(_plus, _plus_1);
|
||||
}
|
||||
|
||||
public TypeReference getPsiInternalLexer(final Grammar it) {
|
||||
String _ideaBasePackage = this._xtextGeneratorNaming.getIdeaBasePackage(it);
|
||||
String _plus = (_ideaBasePackage + ".parser.antlr.internal");
|
||||
String _simpleName = GrammarUtil.getSimpleName(it);
|
||||
String _plus_1 = ("PsiInternal" + _simpleName);
|
||||
String _plus_2 = (_plus_1 + "Lexer");
|
||||
return new TypeReference(_plus, _plus_2);
|
||||
}
|
||||
|
||||
public TypeReference getPsiInternalParser(final Grammar it) {
|
||||
String _ideaBasePackage = this._xtextGeneratorNaming.getIdeaBasePackage(it);
|
||||
String _plus = (_ideaBasePackage + ".parser.antlr.internal");
|
||||
String _simpleName = GrammarUtil.getSimpleName(it);
|
||||
String _plus_1 = ("PsiInternal" + _simpleName);
|
||||
String _plus_2 = (_plus_1 + "Parser");
|
||||
return new TypeReference(_plus, _plus_2);
|
||||
}
|
||||
|
||||
public String getTokens(final Grammar it) {
|
||||
String _ideaBasePackage = this._xtextGeneratorNaming.getIdeaBasePackage(it);
|
||||
String _plus = (_ideaBasePackage + ".parser.antlr.internal.PsiInternal");
|
||||
String _simpleName = GrammarUtil.getSimpleName(it);
|
||||
String _path = this.toPath((_plus + _simpleName));
|
||||
return (_path + ".tokens");
|
||||
}
|
||||
|
||||
public TypeReference getFileImpl(final Grammar it) {
|
||||
String _psiImplPackageName = this.getPsiImplPackageName(it);
|
||||
String _simpleName = GrammarUtil.getSimpleName(it);
|
||||
String _plus = (_simpleName + "FileImpl");
|
||||
return new TypeReference(_psiImplPackageName, _plus);
|
||||
}
|
||||
|
||||
public String getPsiPackageName(final Grammar it) {
|
||||
String _ideaBasePackage = this._xtextGeneratorNaming.getIdeaBasePackage(it);
|
||||
return (_ideaBasePackage + ".lang.psi");
|
||||
}
|
||||
|
||||
public String getPsiImplPackageName(final Grammar it) {
|
||||
String _ideaBasePackage = this._xtextGeneratorNaming.getIdeaBasePackage(it);
|
||||
return (_ideaBasePackage + ".lang.psi.impl");
|
||||
}
|
||||
|
||||
public TypeReference getInternalParser(final Grammar it) {
|
||||
String _namespace = GrammarUtil.getNamespace(it);
|
||||
String _plus = (_namespace + ".parser.antlr.internal");
|
||||
String _simpleName = GrammarUtil.getSimpleName(it);
|
||||
String _plus_1 = ("Internal" + _simpleName);
|
||||
String _plus_2 = (_plus_1 + "Parser");
|
||||
return new TypeReference(_plus, _plus_2);
|
||||
}
|
||||
|
||||
public TypeReference getAntlrLexer(final Grammar it) {
|
||||
String _namespace = GrammarUtil.getNamespace(it);
|
||||
String _plus = (_namespace + ".parser.antlr.internal");
|
||||
String _simpleName = GrammarUtil.getSimpleName(it);
|
||||
String _plus_1 = ("Internal" + _simpleName);
|
||||
String _plus_2 = (_plus_1 + "Lexer");
|
||||
return new TypeReference(_plus, _plus_2);
|
||||
}
|
||||
|
||||
public TypeReference getCompletionContributorSuperClass(final Grammar it) {
|
||||
TypeReference _elvis = null;
|
||||
Grammar _head = IterableExtensions.<Grammar>head(it.getUsedGrammars());
|
||||
TypeReference _completionContributor = null;
|
||||
if (_head!=null) {
|
||||
_completionContributor=this.getCompletionContributor(_head);
|
||||
}
|
||||
if (_completionContributor != null) {
|
||||
_elvis = _completionContributor;
|
||||
} else {
|
||||
TypeReference _typeRef = TypeReference.typeRef("org.eclipse.xtext.idea.completion.AbstractCompletionContributor");
|
||||
_elvis = _typeRef;
|
||||
}
|
||||
return _elvis;
|
||||
}
|
||||
|
||||
public TypeReference getCompletionContributor(final Grammar it) {
|
||||
String _ideaBasePackage = this._xtextGeneratorNaming.getIdeaBasePackage(it);
|
||||
String _plus = (_ideaBasePackage + ".completion");
|
||||
String _simpleName = GrammarUtil.getSimpleName(it);
|
||||
String _plus_1 = (_simpleName + "CompletionContributor");
|
||||
return new TypeReference(_plus, _plus_1);
|
||||
}
|
||||
|
||||
public TypeReference getAbstractCompletionContributor(final Grammar it) {
|
||||
String _ideaBasePackage = this._xtextGeneratorNaming.getIdeaBasePackage(it);
|
||||
String _plus = (_ideaBasePackage + ".completion");
|
||||
String _simpleName = GrammarUtil.getSimpleName(it);
|
||||
String _plus_1 = ("Abstract" + _simpleName);
|
||||
String _plus_2 = (_plus_1 + "CompletionContributor");
|
||||
return new TypeReference(_plus, _plus_2);
|
||||
}
|
||||
|
||||
public TypeReference getFacetConfiguration(final Grammar it) {
|
||||
String _ideaBasePackage = this._xtextGeneratorNaming.getIdeaBasePackage(it);
|
||||
String _plus = (_ideaBasePackage + ".facet");
|
||||
String _simpleName = GrammarUtil.getSimpleName(it);
|
||||
String _plus_1 = (_simpleName + "FacetConfiguration");
|
||||
return new TypeReference(_plus, _plus_1);
|
||||
}
|
||||
|
||||
public TypeReference getFacetType(final Grammar it) {
|
||||
String _ideaBasePackage = this._xtextGeneratorNaming.getIdeaBasePackage(it);
|
||||
String _plus = (_ideaBasePackage + ".facet");
|
||||
String _simpleName = GrammarUtil.getSimpleName(it);
|
||||
String _plus_1 = (_simpleName + "FacetType");
|
||||
return new TypeReference(_plus, _plus_1);
|
||||
}
|
||||
|
||||
public TypeReference baseColorSettingsPage(final Grammar it) {
|
||||
String _ideaBasePackage = this._xtextGeneratorNaming.getIdeaBasePackage(it);
|
||||
String _plus = (_ideaBasePackage + ".highlighting");
|
||||
String _simpleName = GrammarUtil.getSimpleName(it);
|
||||
String _plus_1 = (_simpleName + "BaseColorSettingsPage");
|
||||
return new TypeReference(_plus, _plus_1);
|
||||
}
|
||||
|
||||
public TypeReference colorSettingsPage(final Grammar it) {
|
||||
String _packageName = this.baseColorSettingsPage(it).getPackageName();
|
||||
String _simpleName = GrammarUtil.getSimpleName(it);
|
||||
String _plus = (_simpleName + "ColorSettingsPage");
|
||||
return new TypeReference(_packageName, _plus);
|
||||
}
|
||||
}
|
|
@ -1,37 +0,0 @@
|
|||
/**
|
||||
* Copyright (c) 2015 itemis AG (http://www.itemis.eu) and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*/
|
||||
package org.eclipse.xtext.xtext.generator.idea;
|
||||
|
||||
import org.eclipse.xtext.AbstractRule;
|
||||
import org.eclipse.xtext.Grammar;
|
||||
import org.eclipse.xtext.GrammarUtil;
|
||||
import org.eclipse.xtext.TerminalRule;
|
||||
import org.eclipse.xtext.xbase.lib.Functions.Function1;
|
||||
import org.eclipse.xtext.xbase.lib.IterableExtensions;
|
||||
|
||||
@SuppressWarnings("all")
|
||||
public class IdeaPluginExtension {
|
||||
public Iterable<AbstractRule> getAllNonTerminalRules(final Grammar grammar) {
|
||||
final Function1<AbstractRule, Boolean> _function = (AbstractRule it) -> {
|
||||
return Boolean.valueOf((!(it instanceof TerminalRule)));
|
||||
};
|
||||
return IterableExtensions.<AbstractRule>filter(GrammarUtil.allRules(grammar), _function);
|
||||
}
|
||||
|
||||
public String getSimpleName(final Grammar grammar) {
|
||||
return GrammarUtil.getSimpleName(grammar);
|
||||
}
|
||||
|
||||
public String getPackageName(final Grammar grammar) {
|
||||
return GrammarUtil.getNamespace(grammar);
|
||||
}
|
||||
|
||||
public String getLanguageID(final Grammar grammar) {
|
||||
return grammar.getName();
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
|
@ -1,49 +0,0 @@
|
|||
/**
|
||||
* Copyright (c) 2015 itemis AG (http://www.itemis.eu) and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*/
|
||||
package org.eclipse.xtext.xtext.generator.idea.parser.antlr;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Singleton;
|
||||
import org.eclipse.xtend2.lib.StringConcatenation;
|
||||
import org.eclipse.xtext.Grammar;
|
||||
import org.eclipse.xtext.xbase.lib.Extension;
|
||||
import org.eclipse.xtext.xtext.generator.XtextGeneratorNaming;
|
||||
import org.eclipse.xtext.xtext.generator.model.TypeReference;
|
||||
import org.eclipse.xtext.xtext.generator.parser.antlr.GrammarNaming;
|
||||
|
||||
@Singleton
|
||||
@SuppressWarnings("all")
|
||||
public class PsiGrammarNaming extends GrammarNaming {
|
||||
@Inject
|
||||
@Extension
|
||||
private XtextGeneratorNaming _xtextGeneratorNaming;
|
||||
|
||||
@Override
|
||||
public boolean isCombinedGrammar(final Grammar it) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getParserPackage(final Grammar it) {
|
||||
StringConcatenation _builder = new StringConcatenation();
|
||||
String _ideaBasePackage = this._xtextGeneratorNaming.getIdeaBasePackage(it);
|
||||
_builder.append(_ideaBasePackage);
|
||||
_builder.append(".parser.antlr");
|
||||
return _builder.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypeReference getInternalParserSuperClass(final Grammar it) {
|
||||
return new TypeReference("org.eclipse.xtext.idea.parser.AbstractPsiAntlrParser");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getGrammarNamePrefix(final Grammar it) {
|
||||
return "Psi";
|
||||
}
|
||||
}
|
|
@ -7,23 +7,11 @@
|
|||
*/
|
||||
package org.eclipse.xtext.xtext.generator.idea.parser.antlr;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import org.eclipse.xtend2.lib.StringConcatenation;
|
||||
import org.eclipse.xtext.xbase.lib.Extension;
|
||||
import org.eclipse.xtext.xtext.generator.idea.parser.antlr.PsiAntlrGrammarGenerator;
|
||||
import org.eclipse.xtext.xtext.generator.idea.parser.antlr.PsiGrammarNaming;
|
||||
import org.eclipse.xtext.xtext.generator.model.IXtextGeneratorFileSystemAccess;
|
||||
import org.eclipse.xtext.xtext.generator.parser.antlr.AbstractAntlrGeneratorFragment2;
|
||||
|
||||
@Deprecated
|
||||
@SuppressWarnings("all")
|
||||
public class XtextAntlrIDEAGeneratorFragment extends AbstractAntlrGeneratorFragment2 {
|
||||
@Inject
|
||||
private PsiAntlrGrammarGenerator generator;
|
||||
|
||||
@Inject
|
||||
@Extension
|
||||
private PsiGrammarNaming _psiGrammarNaming;
|
||||
|
||||
@Override
|
||||
protected void doGenerate() {
|
||||
boolean _isEnabled = this.getProjectConfig().getIdeaPlugin().isEnabled();
|
||||
|
@ -31,23 +19,6 @@ public class XtextAntlrIDEAGeneratorFragment extends AbstractAntlrGeneratorFragm
|
|||
if (_not) {
|
||||
return;
|
||||
}
|
||||
final IXtextGeneratorFileSystemAccess fsa = this.getProjectConfig().getIdeaPlugin().getSrcGen();
|
||||
this.generator.generate(this.getGrammar(), this.getOptions(), fsa);
|
||||
final String encoding = this.getCodeConfig().getEncoding();
|
||||
final String grammarFileName = this._psiGrammarNaming.getParserGrammar(this.getGrammar()).getGrammarFileName();
|
||||
StringConcatenation _builder = new StringConcatenation();
|
||||
String _path = fsa.getPath();
|
||||
_builder.append(_path);
|
||||
_builder.append("/");
|
||||
_builder.append(grammarFileName);
|
||||
final String absoluteGrammarFileName = _builder.toString();
|
||||
this.addAntlrParam("-fo");
|
||||
this.addAntlrParam(absoluteGrammarFileName.substring(0, absoluteGrammarFileName.lastIndexOf("/")));
|
||||
this.getAntlrTool().runWithEncodingAndParams(absoluteGrammarFileName, encoding, this.getAntlrParams());
|
||||
this.simplifyUnorderedGroupPredicatesIfRequired(this.getGrammar(), fsa, this._psiGrammarNaming.getInternalParserClass(this.getGrammar()));
|
||||
this.splitParserAndLexerIfEnabled(fsa, this._psiGrammarNaming.getInternalParserClass(this.getGrammar()), this._psiGrammarNaming.getLexerClass(this.getGrammar()));
|
||||
this.normalizeTokens(fsa, this._psiGrammarNaming.getLexerGrammar(this.getGrammar()).getTokensFileName());
|
||||
this.suppressWarnings(fsa, this._psiGrammarNaming.getInternalParserClass(this.getGrammar()), this._psiGrammarNaming.getLexerClass(this.getGrammar()));
|
||||
this.normalizeLineDelimiters(fsa, this._psiGrammarNaming.getInternalParserClass(this.getGrammar()), this._psiGrammarNaming.getLexerClass(this.getGrammar()));
|
||||
System.err.println("The support for Idea has been removed!");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,8 +13,6 @@ import org.eclipse.xtext.validation.ResourceValidatorImpl;
|
|||
|
||||
/**
|
||||
* This resource validator for xtext grammars only reports syntactic errors and broken references to rule calls and super grammars.
|
||||
* It's used in IDEA's Xtext editor until we fully support ecore linking and indexing.
|
||||
* see https://bugs.eclipse.org/bugs/show_bug.cgi?id=477683
|
||||
*
|
||||
* @noreference This class is not intended to be referenced by clients.
|
||||
* @noextend This class is not intended to be subclassed by clients.
|
||||
|
|
Loading…
Reference in a new issue