Skip to content

Commit

Permalink
feat: add doc generation.
Browse files Browse the repository at this point in the history
  • Loading branch information
gdethier committed Mar 3, 2022
1 parent 9cb301a commit e88d741
Show file tree
Hide file tree
Showing 12 changed files with 304 additions and 72 deletions.
9 changes: 5 additions & 4 deletions META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,18 @@ Bundle-RequiredExecutionEnvironment: JavaSE-11
Require-Bundle: org.eclipse.ui,
org.eclipse.core.runtime,
org.eclipse.core.resources,
poussecafe.source.eclipse.plugin;bundle-version="0.28.1",
org.eclipse.jface.text,
org.eclipse.ui.editors,
pousse-cafe-antlr4-runtime-eclipse-plugin;bundle-version="4.8.0",
org.slf4j.api,
org.eclipse.jdt.ui;bundle-version="3.22.0",
org.eclipse.ui.ide;bundle-version="3.18.0",
org.eclipse.jdt.core,
poussecafe.base.eclipse.plugin;bundle-version="0.26.0",
org.apache.commons.lang3,
org.eclipse.ui.workbench.texteditor;bundle-version="3.15.100"
org.eclipse.ui.workbench.texteditor;bundle-version="3.15.100",
pousse-cafe-antlr4-runtime-eclipse-plugin;bundle-version="4.8.0",
poussecafe.doc.eclipse.plugin;bundle-version="0.29.0",
poussecafe.source.eclipse.plugin;bundle-version="0.29.0",
poussecafe.base.eclipse.plugin;bundle-version="0.29.0"
Import-Package: javax.inject
Bundle-Vendor: Pousse-Café Team
Bundle-Activator: poussecafe.eclipse.plugin.core.PousseCafePlugin
Binary file added icons/doc.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 17 additions & 1 deletion plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@
id="poussecafe.eclipse.plugin.commands.generateCode"
name="Generate code">
</command>
<command
categoryId="poussecafe.eclipse.plugin.commands.category"
id="poussecafe.eclipse.plugin.commands.generateDoc"
name="Generate doc">
</command>
</extension>
<extension
point="org.eclipse.ui.menus">
Expand Down Expand Up @@ -112,9 +117,16 @@
commandId="poussecafe.eclipse.plugin.commands.generateCode"
icon="icons/emil.png"
id="poussecafe.eclipse.plugin.toolbars.generateCode"
label="Pousse-Café toolbar"
label="Generate code"
tooltip="Generate code using active EMIL editor&apos;s content">
</command>
<command
commandId="poussecafe.eclipse.plugin.commands.generateDoc"
icon="icons/doc.png"
id="poussecafe.eclipse.plugin.toolbars.generateDoc"
label="Generate doc"
tooltip="Generate documentation for selected projects">
</command>
</toolbar>
</menuContribution>
</extension>
Expand Down Expand Up @@ -176,6 +188,10 @@
</with>
</enabledWhen>
</handler>
<handler
class="poussecafe.eclipse.plugin.handlers.GenerateDocHandler"
commandId="poussecafe.eclipse.plugin.commands.generateDoc">
</handler>
</extension>
<extension
point="org.eclipse.ui.propertyPages">
Expand Down
58 changes: 35 additions & 23 deletions src/poussecafe/eclipse/plugin/builder/PousseCafeBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,12 @@
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.OperationCanceledException;
import org.eclipse.core.runtime.Platform;
import org.eclipse.jdt.core.IClassFile;
import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.IPackageFragment;
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.core.JavaModelException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import poussecafe.eclipse.plugin.core.PousseCafeCore;
Expand Down Expand Up @@ -180,14 +184,39 @@ private void fullBuild(IProgressMonitor monitor) {
logger.info("Starting full build...");
long start = System.currentTimeMillis();
try {
getProject().accept(new ResourceVisitor(monitor));
var project = pousseCafeProject();
for(var fragmentRoot : javaProject().getPackageFragments()) {
String fragmentRootName = fragmentRoot.getElementName();
if(fragmentRootName.startsWith(project.getBasePackage())) {
include(monitor, fragmentRoot);
}
}
} catch (CoreException e) {
platformLogger.error("Unable to validate project", e);
platformLogger.error("Unable to build project", e);
}
long end = System.currentTimeMillis();
logger.info("Scanned project in {} ms", (end - start));
}

private void include(IProgressMonitor monitor, IPackageFragment fragmentRoot) throws JavaModelException {
if(monitor.isCanceled()) {
throw new OperationCanceledException();
}
for(var child : fragmentRoot.getChildren()) {
if(monitor.isCanceled()) {
throw new OperationCanceledException();
}
if(child instanceof ICompilationUnit) {
var file = (IFile) child.getResource();
monitor.subTask("Pousse-Café build: scanning " + file.getName());
includeFile(new ResourceSource(file));
} else if(child instanceof IClassFile) {
monitor.subTask("Pousse-Café build: scanning " + child.getElementName());
includeFile(new ResourceSource((IClassFile) child));
}
}
}

private List<IResourceDelta> relevantDeltas(IResourceDelta delta) {
var updatedResources = new ArrayList<IResourceDelta>();
addRelevantDeltas(updatedResources, delta);
Expand Down Expand Up @@ -224,29 +253,12 @@ private IJavaProject javaProject() {

private SourceScanner scanner;

private class ResourceVisitor extends JavaSourceFileVisitor {

ResourceVisitor(IProgressMonitor monitor) {
super(javaProject());
this.monitor = monitor;
}

private IProgressMonitor monitor;

@Override
protected void visit(ResourceSource source) {
if(monitor.isCanceled()) {
throw new OperationCanceledException();
}
monitor.subTask("Pousse-Café build: scanning " + source.id());
includeFile(source);
}
}

private void includeFile(ResourceSource source) {
try {
scanner.includeSource(source);
logger.debug("Included {}", source.id());
if(source.hasSource()) {
scanner.includeSource(source);
logger.debug("Included {}", source.id());
}
} catch (Exception e) {
platformLogger.error("Error while scanning " + source.id(), e);
}
Expand Down
45 changes: 35 additions & 10 deletions src/poussecafe/eclipse/plugin/builder/ResourceSource.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
import org.eclipse.jdt.core.IClassFile;
import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.IType;
Expand All @@ -29,24 +30,26 @@ private void connectedOrThrow() {
}

public boolean isConnected() {
return type != null;
return type != null || source != null;
}

public boolean hasFile() {
connectedOrThrow();
return file != null;
public boolean hasSource() {
return compilationUnit != null || source != null;
}

@Override
public void configure(ASTParser parser) {
parser.setSource(resourceCompilationUnit());
if(compilationUnit != null) {
parser.setSource(resourceCompilationUnit());
} else if(source != null) {
parser.setSource(source.toCharArray());
} else {
throw new IllegalStateException("No source available");
}
}

public ICompilationUnit resourceCompilationUnit() {
private ICompilationUnit resourceCompilationUnit() {
connectedOrThrow();
if(compilationUnit == null) {

}
return compilationUnit;
}

Expand Down Expand Up @@ -82,6 +85,15 @@ public ResourceSource(IType type) {

private String typeName;

public ResourceSource(IClassFile classFile) {
super(classFile.getElementName());

classFileHandleIdentifier = classFile.getHandleIdentifier();
connect(classFile.getJavaProject());
}

private String classFileHandleIdentifier;

@Override
public void connect(Object project) {
requireNonNull(project);
Expand All @@ -104,16 +116,29 @@ public void connect(Object project) {
}
}

if(type == null) {
if(type == null && typeName != null) {
relativePath = null;
try {
type = javaProject.findType(typeName);
} catch (Exception e) {
// Do nothing
}
}

if(type == null && classFileHandleIdentifier != null) {
relativePath = null;
try {
var classFile = (IClassFile) JavaCore.create(classFileHandleIdentifier);
type = classFile.findPrimaryType();
source = classFile.getSource();
} catch (Exception e) {
// Do nothing
}
}
}

private String source;

ResourceSource() {

}
Expand Down
28 changes: 27 additions & 1 deletion src/poussecafe/eclipse/plugin/core/PousseCafeProject.java
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,12 @@ public String getBasePackage() {
private String getProperty(QualifiedName name, String defaultValue) {
var resource = project.getProject();
try {
return resource.getPersistentProperty(name);
String value = resource.getPersistentProperty(name);
if(value == null) {
return defaultValue;
} else {
return value;
}
} catch (CoreException e) {
return defaultValue;
}
Expand Down Expand Up @@ -195,4 +200,25 @@ public boolean hasProblems() throws CoreException {
var problems = project.getProject().findMarkers(PousseCafeBuilder.MARKER_TYPE, true, IResource.DEPTH_INFINITE);
return problems != null && problems.length > 0;
}

public Path getDocumentationFolder() throws CoreException {
var tempFolder = createPousseCafeTempFolder();
var folder = tempFolder.getFolder("doc");
folder.refreshLocal(IResource.DEPTH_ZERO, null);
if(!folder.exists()) {
folder.create(false, true, null);
}
return Path.of(folder.getLocation().toOSString());
}

public String getDomain() {
return getProperty(PousseCafeProjectPropertyPage.DOMAIN_PROPERTY_NAME,
PousseCafeProjectPropertyPage.DEFAULT_DOMAIN);
}

public boolean openDocInExternalBrownser() {
var value = getProperty(PousseCafeProjectPropertyPage.OPEN_IN_EXTERNAL_BROWSER_PROPERTY_NAME,
PousseCafeProjectPropertyPage.DEFAULT_OPEN_IN_EXTERNAL_BROWSER);
return Boolean.parseBoolean(value);
}
}
14 changes: 6 additions & 8 deletions src/poussecafe/eclipse/plugin/editors/EmilHyperlinkDetector.java
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ private void tryAddLinksOfHeader(HeaderContext header) {
var process = modelOrElseThrow().processes().stream()
.filter(candidate -> candidate.simpleName().equals(processName.getText()))
.findFirst();
tryAddLink(processName.getSymbol(), process.map(ProcessModel::source), unit -> Optional.of(unit));
tryAddLink(processName.getSymbol(), process.map(ProcessModel::source), Optional::of);
}

private SourceModel modelOrElseThrow() {
Expand Down Expand Up @@ -153,7 +153,7 @@ private void tryAddLinksOfCommandConsumption(ConsumptionContext consumption) {
if(commandConsumption != null) {
var commandName = commandConsumption.command().NAME();
var command = modelOrElseThrow().command(commandName.getText());
tryAddLink(commandName.getSymbol(), command.map(Command::source), unit -> Optional.of(unit));
tryAddLink(commandName.getSymbol(), command.map(Command::source), Optional::of);
tryAddLinks(commandName.getText(), commandConsumption.messageConsumptions());
}
}
Expand Down Expand Up @@ -233,7 +233,7 @@ private void tryAddLinksOfAggregateContainer(QualifiedNameContext qualifiedName)
var aggregateNameNode = qualifiedName.NAME(0);
var source = aggregateContainer(qualifiedName);
if(source.isPresent()) {
tryAddLink(aggregateNameNode.getSymbol(), source.get(), unit -> Optional.of(unit));
tryAddLink(aggregateNameNode.getSymbol(), source.get(), Optional::of);

var typeNameNode = qualifiedName.NAME(1);
tryAddLink(typeNameNode.getSymbol(), source.get(), unit -> Optional.of(unit.getType(typeNameNode.getText())));
Expand All @@ -249,7 +249,7 @@ private void tryAddLinkStandaloneComponent(
var aggregate = modelOrElseThrow().aggregate(aggregateName);
if(aggregate.isPresent()) {
tryAddLink(simpleName, sourceProvider.apply(aggregate.get()),
unit -> Optional.of(unit));
Optional::of);
}
}

Expand All @@ -266,7 +266,6 @@ private void tryAddLinkListener(
containerType);
var listenerExtractor = listenerExtractor(
containerQualifiedName,
containerSimpleName,
listenerName.getText(),
messageTypeName);
tryAddLink(listenerName, listenerContainer, listenerExtractor);
Expand Down Expand Up @@ -314,7 +313,6 @@ private Optional<Aggregate> aggregate(QualifiedNameContext qualifiedName) {

private Function<IType, Optional<IMember>> listenerExtractor(
QualifiedNameContext qualifiedName,
Token simpleName,
String methodName,
String messageTypeName) {
return type -> {
Expand Down Expand Up @@ -374,7 +372,7 @@ private void tryAddLinks(EventProductionContext eventProduction) {
private void tryAddLinkEvent(EventContext event) {
var eventName = event.NAME();
var domainEvent = modelOrElseThrow().event(eventName.getText());
tryAddLink(eventName.getSymbol(), domainEvent.map(DomainEvent::source), unit -> Optional.of(unit));
tryAddLink(eventName.getSymbol(), domainEvent.map(DomainEvent::source), Optional::of);
}

private void tryAddLinks(String messageTypeName, AggregateRootConsumptionContext aggregateRootConsumption) {
Expand All @@ -390,7 +388,7 @@ private void tryAddLinks(String messageTypeName, AggregateRootConsumptionContext
var runner = modelOrElseThrow().runner(listener.get().runnerClass().orElseThrow());
tryAddLink(aggregateRootConsumption.runnerName,
runner.map(Runner::runnerSource),
unit -> Optional.of(unit));
Optional::of);
}
tryAddLinkListener(
aggregateRootConsumption.aggregateRoot().qualifiedRootName,
Expand Down
Loading

0 comments on commit e88d741

Please sign in to comment.