Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[API] Provide a better API #136

Merged
merged 2 commits into from
Jun 4, 2020
Merged

[API] Provide a better API #136

merged 2 commits into from
Jun 4, 2020

Conversation

echebbi
Copy link
Collaborator

@echebbi echebbi commented May 8, 2020

Contributes to #123

Changes

  • I've implemented most of the changes proposed by Decide of an API and use it #123 except the mechanism allowing to access runtime data
  • cleaned up some parts of the code (dead code, redundancies, etc.)
  • added JavaDoc where code was unclear
  • removed the org.eclipse.emf.ecoretools.ale plug-in
  • turned the org.eclipse.emf.ecoretools.ale.tests plug-in into a plug-in fragment to ease testing of internal classes
  • moved some classes to other packages

How to review

This PR impacts a lot of files but that's mainly because I renamed some classes and moved others. There's actually almost no change in features: I mainly introduced new interfaces (IAleInterpreter) and enforced the use of others (IAleEnvironment). Both automatic and manual testing have failed to find bugs so I'm pretty confident in not having introduce important regressions.

To review important changes I would advise to:

  • take a look at IAleEnvironment
  • take a look at AbstractAleEnvironment
  • take a look at AleInterpreter
  • take a look at BehaviorsParser (ex AstBuilder) and AntlrAstToBehaviorsAstAdapter (ex ModelBuilder)
  • check package hierarchy in org.eclipse.emf.ecoretools.ale.core

API

Lots of interfaces and classes are prefixed by Ale. It feels redundant and I can't decide whether it's worth it.

See also unit tests for examples.

Task 1: create a new ALE project

IWorkspace workspace = ResourcesPlugin.getWorkspace();
WorkspaceAleProject.Description desc = new WorkspaceAleProject.Description(
    isUsingAnExistingEcoreModel, ecoreModelFilePath, 
    ecorePackageName, 
    hasSiriusRepresentation, 
    hasJavaNature
);
Template project = new WorkspaceAleProject.Template(workspace, desc);
project.create(projectName, projectPath, new NullProgressMonitor());

Task 2: retrieve an existing ALE project

IProject    project    = ResourcesPlugin.getWorkspace().getRoot().getProject("fsm");
IAleProject aleProject = IAleProject.from(project);

Task 3: manipulate an ALE environment

/*
 * getEnvironment() returns the *applicable* environment, which may be
 * either stored as project preferences or declared in a .dsl file
 */
IAleEnvironment env = aleProject.getEnvironment();

// Or dynamically create a new environment
IAleEnvironment env = IAleEnvironment.fromPaths(
       asList("helloworld.ecore"), asList("helloworld.ale"));

// Persist given environment in the .dsl file
try (FileBasedAleEnvironment dsl = IAleEnvironment.fromFile(new File("helloworld.dsl"))) {
    dsl.save(env);
}

Task 4: manipulate ALE classes

IBehaviors    behaviors  = env.getBehaviors();
Set<EPackage> metamodels = env.getMetamodels();

The IBehaviors interface eases manipulation of dynamic ALE elements.

Task 5: execute an ALE program

IAleProject aleProject = IAleProject.from(project);
try (IAleEnvironment env = aleProject.getEnvironment()) {
    IAleInterpreter interpreter = env.getInterpreter();

    EObject      caller = environment.loadModel(createURI("HelloWorld.xmi")).get(0);
    Method       main   = environment.getBehaviors().getMainMethods().get(0);
    List<Object> args   = emptyList();

    IAleInterpreter   interpreter = environment.getInterpreter();
    IEvaluationResult result      = interpreter.eval(caller, main, args);
}

The environment itself is AutoCloseable and responsible for releasing resources (see AbstractAleEnvironement::close for the actual implementation).

@echebbi echebbi self-assigned this May 8, 2020
@echebbi echebbi requested a review from dvojtise May 9, 2020 16:19
@echebbi
Copy link
Collaborator Author

echebbi commented May 9, 2020

@dvojtise would you have the time to take a look at this PR before I squash & merge the commits? I'd appreciate a review.

echebbi added a commit that referenced this pull request May 14, 2020
Because:
 - some tasks are common and repeated across the codebase but no API is available, leading to code duplication
 - the purpose of some internal classes is unclear

Changes:
 - the new IAleEnvironment interface represents a coherent set of metamodels and ALE behaviors
 - the new IAleInterpreter interface represents an interpreter able to evaluate ALE expressions
 - rename AstBuilder and ModelBuilder as BehaviorsParser and AntlrAstToBehaviorsAstAdapter
 - document unclear classes
 - removed the org.eclipse.emf.ecoretools.ale bundle (and move content to core bundle)
 - turn the org.eclipse.emf.ecoretools.ale.tests plug-in into a plug-in fragment
Because:
 - some tasks are common and repeated across the codebase but no API is available, leading to code duplication
 - the purpose of some internal classes is unclear

Changes:
 - the new IAleEnvironment interface represents a coherent set of metamodels and ALE behaviors
 - the new IAleInterpreter interface represents an interpreter able to evaluate ALE expressions
 - rename AstBuilder and ModelBuilder as BehaviorsParser and AntlrAstToBehaviorsAstAdapter
 - document unclear classes
 - removed the org.eclipse.emf.ecoretools.ale bundle (and move content to core bundle)
 - turn the org.eclipse.emf.ecoretools.ale.tests plug-in into a plug-in fragment

Signed-off-by: Emmanuel Chebbi <emmanuel.chebbi@outlook.fr>
@echebbi echebbi marked this pull request as ready for review May 14, 2020 13:55
@dvojtise
Copy link
Contributor

Lots of interfaces and classes are prefixed by Ale. It feels redundant and I can't decide whether it's worth it.

I think that the prefix is short enough to keep it. Additionally, ALE is one of the meta-approach used in GEMOC, and we may have to mix approaches, in such situation, having clear class names will help (this is always a pain in java to have 2 classes from different packages that have the same name because java doesn't provide local rename mechanism such as other languages)

IMO, every class that might be used from outside (ie not internal) should keep the Ale prefix

@dvojtise
Copy link
Contributor

Globally the proposed changes make sense and improve the API (only some class names that could be improved)

once accepted, I would appreciate a PR in https://github.com/eclipse/gemoc-studio-execution-ale/ to report these changes to the GEMOC ALE engine that heavily use this API (I quickly tried renaming, but I think it could also be simplified thanks to the API addition you provided)

  * DslConfiguration       -> FileBasedAleEnvironment
  * InMemoryAleEnvironment -> PathsBasedAleEnvironment
  * MadeUpAleEnvironment   -> RawEnvironmentBasedAleEnvironment
  * Normalized             -> WithAbsoluteBehaviorPathsAleEnvironment
  * AleAware               -> AleProject

Signed-off-by: Emmanuel Chebbi <emmanuel.chebbi@outlook.fr>
@echebbi
Copy link
Collaborator Author

echebbi commented Jun 4, 2020

I think this PR can now be merged; @dvojtise are you OK with the changes?

@echebbi echebbi requested a review from dvojtise June 4, 2020 13:53
@dvojtise
Copy link
Contributor

dvojtise commented Jun 4, 2020

yes, looks good to merge :-)

@echebbi echebbi merged commit cf47b65 into master Jun 4, 2020
@echebbi echebbi deleted the 123-better-API branch June 4, 2020 14:32
@echebbi echebbi mentioned this pull request Jun 4, 2020
dvojtise added a commit that referenced this pull request Jul 20, 2020
this file was moved/renamed in
#136

Signed-off-by: Didier Vojtisek <didier.vojtisek@inria.fr>
echebbi pushed a commit that referenced this pull request Jul 23, 2020
this file was moved/renamed in
#136

Signed-off-by: Didier Vojtisek <didier.vojtisek@inria.fr>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants