Skip to content

Commit

Permalink
Hopefully fixes #2915 by harmonizing the access to actions documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexisDrogoul committed Sep 6, 2021
1 parent c7d5126 commit 581987a
Show file tree
Hide file tree
Showing 10 changed files with 1,343 additions and 512 deletions.
@@ -1,14 +1,13 @@
/*********************************************************************************************
/*******************************************************************************************************
*
* 'DocumentationTask.java, in plugin msi.gama.lang.gaml, is part of the source code of the GAMA modeling and simulation
* platform. (v. 1.8.1)
* DocumentationTask.java, in msi.gama.lang.gaml, is part of the source code of the GAMA modeling and simulation
* platform (v.1.8.2).
*
* (c) 2007-2020 UMI 209 UMMISCO IRD/UPMC & Partners
* (c) 2007-2021 UMI 209 UMMISCO IRD/SU & Partners (IRIT, MIAT, TLU, CTU)
*
* Visit https://github.com/gama-platform/gama for license information and developers contact.
* Visit https://github.com/gama-platform/gama for license information and contacts.
*
*
**********************************************************************************************/
********************************************************************************************************/
package msi.gama.lang.gaml.documentation;

import org.eclipse.emf.ecore.EObject;
Expand All @@ -18,25 +17,45 @@
import msi.gama.util.IMap;
import ummisco.gama.dev.utils.DEBUG;

/**
* The Class DocumentationTask.
*/
class DocumentationTask {

/** The object. */
final EObject object;

/** The description. */
final IGamlDescription description;

/** The documenter. */
final GamlResourceDocumenter documenter;

/**
* Instantiates a new documentation task.
*
* @param object
* the object
* @param description
* the description
* @param documenter
* the documenter
*/
public DocumentationTask(final EObject object, final IGamlDescription description,
final GamlResourceDocumenter documenter) {
super();
this.object = object;
this.description = description;
this.documenter = documenter;
}

/**
* Process.
*/
public void process() {
// DEBUG.LOG("Documenting " + description.getName());
if (description == null) { return; }
if (object == null) { return; }
if (description == null || object == null) return;
final Resource key = object.eResource();
if (key == null) { return; }
if (key == null) return;

DocumentationNode node = null;
try {
Expand All @@ -47,9 +66,7 @@ public void process() {
if (node != null) {
try {
final IMap<EObject, IGamlDescription> map = documenter.getDocumentationCache(key);
if (map != null) {
map.put(object, node);
}
if (map != null) { map.put(object, node); }
} catch (final RuntimeException e) {}
}

Expand Down
@@ -1,14 +1,13 @@
/*********************************************************************************************
/*******************************************************************************************************
*
* 'GamlResourceDocumenter.java, in plugin msi.gama.lang.gaml, is part of the source code of the GAMA modeling and
* simulation platform. (v. 1.8.1)
* GamlResourceDocumenter.java, in msi.gama.lang.gaml, is part of the source code of the GAMA modeling and simulation
* platform (v.1.8.2).
*
* (c) 2007-2020 UMI 209 UMMISCO IRD/UPMC & Partners
* (c) 2007-2021 UMI 209 UMMISCO IRD/SU & Partners (IRIT, MIAT, TLU, CTU)
*
* Visit https://github.com/gama-platform/gama for license information and developers contact.
* Visit https://github.com/gama-platform/gama for license information and contacts.
*
*
**********************************************************************************************/
********************************************************************************************************/
package msi.gama.lang.gaml.documentation;

import java.io.IOException;
Expand Down Expand Up @@ -40,8 +39,13 @@
@SuppressWarnings ({ "unchecked", "rawtypes" })
public class GamlResourceDocumenter implements IDocManager {

/** The cleanup tasks. */
final ConcurrentLinkedQueue<ModelDescription> cleanupTasks = new ConcurrentLinkedQueue();

/** The documentation queue. */
final ConcurrentLinkedQueue<DocumentationTask> documentationQueue = new ConcurrentLinkedQueue();

/** The documentation job. */
final Job documentationJob = new Job("Documentation") {
{
setUser(false);
Expand All @@ -64,10 +68,10 @@ protected IStatus run(final IProgressMonitor monitor) {
}
};

/** The documenting visitor. */
final DescriptionVisitor<IDescription> documentingVisitor = desc -> {
document(desc);
return true;

};

@Override
Expand All @@ -78,30 +82,38 @@ public void addCleanupTask(final ModelDescription model) {
@Override
public void setGamlDocumentation(final EObject object, final IGamlDescription description, final boolean replace,
final boolean force) {
if (!force && !shouldDocument(object)) { return; }
if (!force && !shouldDocument(object)) return;

documentationQueue.add(new DocumentationTask(object, description, this));
documentationJob.schedule(50);
}

/**
* Gets the documentation cache.
*
* @param resource
* the resource
* @return the documentation cache
*/
IMap<EObject, IGamlDescription> getDocumentationCache(final Resource resource) {
if (resource == null) { return null; }
if (resource == null) return null;
return GamlResourceServices.getDocumentationCache(resource);
}

// To be called once the validation has been done
@Override
public void document(final IDescription desc) {
if (desc == null) { return; }
if (desc == null) return;
final EObject e = desc.getUnderlyingElement();
if (e == null) { return; }
if (e == null) return;
setGamlDocumentation(e, desc, true);
desc.visitOwnChildren(documentingVisitor);

}

@Override
public IGamlDescription getGamlDocumentation(final IGamlDescription o) {
if (o == null) { return null; }
if (o == null) return null;
try {
return new DocumentationNode(o);
} catch (final IOException e) {
Expand All @@ -112,17 +124,23 @@ public IGamlDescription getGamlDocumentation(final IGamlDescription o) {

@Override
public IGamlDescription getGamlDocumentation(final EObject object) {
if (object == null) { return null; }
if (object == null) return null;
final IMap<EObject, IGamlDescription> map = getDocumentationCache(object.eResource());
if (map == null) { return null; }
if (map == null) return null;
return map.get(object);
}

/**
* Should document.
*
* @param object
* the object
* @return true, if successful
*/
private static boolean shouldDocument(final EObject object) {
if (object == null) { return false; }
if (object == null) return false;
final Resource r = object.eResource();
if (r == null) { return false; }
if (!GamlResourceServices.isEdited(r)) { return false; }
if (r == null || !GamlResourceServices.isEdited(r)) return false;
return true;
}

Expand Down

0 comments on commit 581987a

Please sign in to comment.