Package net.ssehub.easy.dslCore
Class ModelUtility<E extends org.eclipse.emf.ecore.EObject,R extends net.ssehub.easy.basics.modelManagement.IModel>
java.lang.Object
net.ssehub.easy.dslCore.ModelUtility<E,R>
- Type Parameters:
E- the top-level ECore classR- the top-level result model class
- All Implemented Interfaces:
net.ssehub.easy.basics.modelManagement.IModelLoader<R>
public abstract class ModelUtility<E extends org.eclipse.emf.ecore.EObject,R extends net.ssehub.easy.basics.modelManagement.IModel>
extends Object
implements net.ssehub.easy.basics.modelManagement.IModelLoader<R>
A basic set of model utilities.
Call
setResourceInitializer(IResourceInitializer) before using this
class.- Author:
- Holger Eichelberger
-
Nested Class Summary
Nested classes/interfaces inherited from interface net.ssehub.easy.basics.modelManagement.IModelLoader
net.ssehub.easy.basics.modelManagement.IModelLoader.IModelInfoHolder<M extends net.ssehub.easy.basics.modelManagement.IModel>, net.ssehub.easy.basics.modelManagement.IModelLoader.LoadResult<M extends net.ssehub.easy.basics.modelManagement.IModel> -
Field Summary
FieldsModifier and TypeFieldDescriptionStores information about files currently being loaded in order to prevent infinite recursions in case of errors in dependent projects.private static booleanprivate org.eclipse.xtext.GrammarStores the XText grammar.private com.google.inject.Injectorprivate static List<ModelUtility<?, ?>> private static IResourceInitializerprivate org.eclipse.xtext.resource.XtextResourceSetStores the XText resource set.private static final List<ModelUtility<?, ?>> -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedCreates an instance and causes the creation of the injector or schedules the creation. -
Method Summary
Modifier and TypeMethodDescriptionstatic StringBuilderappend(StringBuilder builder, String text, String separator) Appends atexttobuilderand insertsseparatorbefore iftextis not empty.static StringBuilderappendWithNewLine(StringBuilder builder, String text) Appends atexttobuilderand inserts a new line before iftextis not empty.static booleanforceUnloadOnParse(boolean force) abstract StringReturns the file extension / identifier to react on.protected org.eclipse.xtext.GrammarReturns the object representation of the actual grammar (and performs a lazy initialization ofgrammarorresourceSetif required).abstract net.ssehub.easy.basics.modelManagement.ModelInfo<R> Returns model information from the underlying model repository.net.ssehub.easy.basics.modelManagement.ModelInfo<R> getInfo(org.eclipse.emf.common.util.URI uri) Return model information from the underlying model repository.com.google.inject.InjectorReturns the injector for this language / environment.protected abstract ClassLoaderReturns the actual class loader of the language.protected abstract StringReturns the language name as specified in the xText configuration.static IResourceInitializerReturns the actual resource initializer.org.eclipse.xtext.resource.XtextResourceSetReturns the XText resource set (and performs a lazy initialization ofresourceSetif required).protected booleanReturns whether this model utility class handles this type of file.protected abstract voidInitializes instances which depend onresourceInitializer.static Iterable<ModelUtility<?, ?>> net.ssehub.easy.basics.modelManagement.IModelLoader.LoadResult<R> load(net.ssehub.easy.basics.modelManagement.ModelInfo<R> info, net.ssehub.easy.basics.modelManagement.ImportResolver<R> resolver) obtainInfo(File file) Obtains project info.obtainInfo(org.eclipse.emf.common.util.URI uri) Obtains model information.Parse an IVML model file for standalone application (without editor) with a new default import resolver.parse(org.eclipse.emf.common.util.URI uri) Parse an IVML model file for standalone application (without editor) with a new default import resolver.protected Eparse(org.eclipse.emf.common.util.URI uri, boolean unload, MessageReceiver receiver, Class<E> cls) Parses anurito obtain the top-level element.abstract TranslationResult<R> parse(org.eclipse.emf.common.util.URI uri, net.ssehub.easy.basics.modelManagement.ImportResolver<R> resolver) Parse an IVML model file for standalone application (without editor) with a given import resolver.protected org.eclipse.xtext.parser.IParseResultparseFragment(String ruleName, String input) Parses a grammar fragment.voidprotected voidsetInjector(com.google.inject.Injector injector) Defines the injector for this language / environment.static voidsetResourceInitializer(IResourceInitializer initializer) Defines the resource initializer.static final URItoNetUri(org.eclipse.emf.common.util.URI uri) Converts an Eclipse URI to a java.net.URI.voidvalidate(org.eclipse.emf.ecore.resource.Resource resource, Consumer<MessageReceiver> messageHandler) Validates the given resource.
-
Field Details
-
resourceInitializer
-
instances
-
SCHEDULED
-
forceUnloadOnParse
private static boolean forceUnloadOnParse -
beingLoaded
Stores information about files currently being loaded in order to prevent infinite recursions in case of errors in dependent projects. -
resourceSet
private org.eclipse.xtext.resource.XtextResourceSet resourceSetStores the XText resource set. This attribute is initialized in a lazy way ingetResourceSet(). Therefore, do not use this attribute directly but only throughgetResourceSet(). -
injector
private com.google.inject.Injector injector -
grammar
private org.eclipse.xtext.Grammar grammarStores the XText grammar. This attribute is initialized in a lazy fashion ingetGrammar(). Therefore, do not use this attribute directly but only throughgetGrammar().
-
-
Constructor Details
-
ModelUtility
protected ModelUtility()Creates an instance and causes the creation of the injector or schedules the creation.
-
-
Method Details
-
forceUnloadOnParse
public static boolean forceUnloadOnParse(boolean force) -
instances
-
setResourceInitializer
Defines the resource initializer.- Parameters:
initializer- the initializer
-
initializeAfterResourceInitializer
protected abstract void initializeAfterResourceInitializer()Initializes instances which depend onresourceInitializer. -
getResourceInitializer
Returns the actual resource initializer.- Returns:
- the actual resource initializer
-
toNetUri
Converts an Eclipse URI to a java.net.URI.- Parameters:
uri- the URI to convert- Returns:
- the converted URI
- Throws:
URISyntaxException- in case of URI syntax errors
-
getResourceSet
public org.eclipse.xtext.resource.XtextResourceSet getResourceSet()Returns the XText resource set (and performs a lazy initialization ofresourceSetif required).- Returns:
- the resource set
-
getInjector
public com.google.inject.Injector getInjector()Returns the injector for this language / environment.- Returns:
- the injector
-
setInjector
protected void setInjector(com.google.inject.Injector injector) Defines the injector for this language / environment.- Parameters:
injector- the injector instance
-
parse
Parse an IVML model file for standalone application (without editor) with a new default import resolver.- Parameters:
file- the location of the model- Returns:
- the created variability model including messages
- Throws:
IOException- in case of IO problems
-
parse
Parse an IVML model file for standalone application (without editor) with a new default import resolver.- Parameters:
uri- the location of the model, e.g. via URI.createURI("dummy:/example.ex1")- Returns:
- the created variability model including messages
- Throws:
IOException- in case of any I/O or URI problem
-
parse
public abstract TranslationResult<R> parse(org.eclipse.emf.common.util.URI uri, net.ssehub.easy.basics.modelManagement.ImportResolver<R> resolver) throws IOException Parse an IVML model file for standalone application (without editor) with a given import resolver.- Parameters:
uri- the location of the model, e.g. via URI.createURI("dummy:/example.ex1")resolver- the import resolver (may be null for a new default import resolver)- Returns:
- the created variability model including messages
- Throws:
IOException- in case of any I/O or URI problem
-
getGrammar
protected org.eclipse.xtext.Grammar getGrammar()Returns the object representation of the actual grammar (and performs a lazy initialization ofgrammarorresourceSetif required).- Returns:
- the grammar
-
getLanguageName
Returns the language name as specified in the xText configuration. This name can be found as URL in the grammar file or corresponds to the Java path of the grammar-XMI file in src-gen.- Returns:
- the language name in Java package notation
-
getLanguageClassLoader
Returns the actual class loader of the language. This loader may be different due to different bundles.- Returns:
- the class loader
-
parseFragment
Parses a grammar fragment.- Parameters:
ruleName- the name of the grammar ruleinput- the text to be parsed- Returns:
- the parse result if successful, null in case of instantiation problems
-
append
Appends atexttobuilderand insertsseparatorbefore iftextis not empty.- Parameters:
builder- the builder to append totext- the text to appendseparator- the separator to be considered- Returns:
builder
-
appendWithNewLine
Appends atexttobuilderand inserts a new line before iftextis not empty.- Parameters:
builder- the builder to append totext- the text to append- Returns:
builder
-
parse
protected E parse(org.eclipse.emf.common.util.URI uri, boolean unload, MessageReceiver receiver, Class<E> cls) throws IOException Parses anurito obtain the top-level element.- Parameters:
uri- the URI to readunload- unload the parsed XText resource, may change AST node adapters and keep source positions internalreceiver- the message receiver used for storing messages (may be null)cls- the class of the result- Returns:
- the top-level element (or null if not found)
- Throws:
IOException- in case of any I/O and parsing problems
-
handles
Returns whether this model utility class handles this type of file.- Parameters:
location- the location to be considered- Returns:
trueif it handles the specified location,falseelse- See Also:
-
scan
public void scan(File location, net.ssehub.easy.basics.modelManagement.IModelLoader.IModelInfoHolder<R> holder) - Specified by:
scanin interfacenet.ssehub.easy.basics.modelManagement.IModelLoader<E extends org.eclipse.emf.ecore.EObject>
-
obtainInfo
public List<net.ssehub.easy.basics.modelManagement.ModelInfo<R>> obtainInfo(File file) throws IOException Obtains project info.- Parameters:
file- the file to read the info from- Returns:
- the project info instances related to
file - Throws:
IOException- in case that an I/O error happens during parsing
-
obtainInfo
public abstract List<net.ssehub.easy.basics.modelManagement.ModelInfo<R>> obtainInfo(org.eclipse.emf.common.util.URI uri) throws IOException Obtains model information.- Parameters:
uri- the URI to read the info from- Returns:
- the project info instances related to
uri - Throws:
IOException- in case that an I/O error happens during parsing
-
getInfo
Returns model information from the underlying model repository.- Parameters:
uri- the URI to return the info for- Returns:
- the project info instance related to
uri, may be null for none
-
getInfo
public net.ssehub.easy.basics.modelManagement.ModelInfo<R> getInfo(org.eclipse.emf.common.util.URI uri) Return model information from the underlying model repository.- Parameters:
uri- the URI to return the info for- Returns:
- the project info instance related to
uri, may be null for none - See Also:
-
load
public net.ssehub.easy.basics.modelManagement.IModelLoader.LoadResult<R> load(net.ssehub.easy.basics.modelManagement.ModelInfo<R> info, net.ssehub.easy.basics.modelManagement.ImportResolver<R> resolver) - Specified by:
loadin interfacenet.ssehub.easy.basics.modelManagement.IModelLoader<E extends org.eclipse.emf.ecore.EObject>
-
getExtension
Returns the file extension / identifier to react on.- Returns:
- the extension
-
validate
public void validate(org.eclipse.emf.ecore.resource.Resource resource, Consumer<MessageReceiver> messageHandler) Validates the given resource.- Parameters:
resource- the resourcemessageHandler- message handler (may be on UI level)
-