Skip to content

Commit

Permalink
Merge pull request #3783 from maxonfjvipon/bug/#3481/rho-dot
Browse files Browse the repository at this point in the history
bug(#3481): removed `globals-to-abstracts.xsl` + fixed indents in `to-java.xsl`
  • Loading branch information
yegor256 authored Dec 31, 2024
2 parents e61b39b + 3764d30 commit eca8fc6
Show file tree
Hide file tree
Showing 19 changed files with 305 additions and 261 deletions.
11 changes: 11 additions & 0 deletions eo-maven-plugin/src/main/java/org/eolang/maven/SafeMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,17 @@ abstract class SafeMojo extends AbstractMojo {
@Parameter(property = "eo.transpiledFormat", required = true, defaultValue = "csv")
protected String transpiledFormat = "csv";

/**
* Track optimization steps into intermediate XMIR files?
*
* @since 0.24.0
* @checkstyle MemberNameCheck (7 lines)
* @checkstyle VisibilityModifierCheck (5 lines)
*/
@SuppressWarnings("PMD.LongVariable")
@Parameter(property = "eo.trackTransformationSteps", required = true, defaultValue = "false")
protected boolean trackTransformationSteps;

/**
* If set to TRUE, the exception on exit will be printed in details
* to the log.
Expand Down
52 changes: 23 additions & 29 deletions eo-maven-plugin/src/main/java/org/eolang/maven/ShakeMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@
import com.yegor256.xsline.Xsline;
import java.nio.file.Path;
import java.util.Collection;
import java.util.function.Function;
import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import org.cactoos.func.StickyFunc;
import org.cactoos.iterable.Filtered;
import org.eolang.maven.footprint.FpDefault;
Expand All @@ -56,7 +56,7 @@ public final class ShakeMojo extends SafeMojo {
/**
* The directory where to shake to.
*/
public static final String DIR = "2-shake";
static final String DIR = "2-shake";

/**
* Subdirectory for shaken cache.
Expand All @@ -66,50 +66,40 @@ public final class ShakeMojo extends SafeMojo {
/**
* The directory where to place intermediary files.
*/
static final String STEPS = "2-shake-steps";

/**
* Track optimization steps into intermediate XMIR files?
*
* @since 0.24.0
* @checkstyle MemberNameCheck (7 lines)
*/
@SuppressWarnings("PMD.LongVariable")
@Parameter(property = "eo.trackTransformationSteps", required = true, defaultValue = "false")
private boolean trackTransformationSteps;
private static final String STEPS = "2-shake-steps";

@Override
public void exec() {
final long start = System.currentTimeMillis();
final Collection<ForeignTojo> tojos = this.scopedTojos().withXmir();
final Xsline xsline = this.transformations();
final Function<XML, XML> transform = this.transformations();
final int total = new Threaded<>(
new Filtered<>(
ForeignTojo::notShaken,
tojos
),
tojo -> this.shaken(tojo, xsline)
tojo -> this.shaken(tojo, transform)
).total();
if (total > 0) {
Logger.info(
this,
"Optimized %d out of %d XMIR program(s) in %[ms]s",
"Shaked %d out of %d XMIR program(s) in %[ms]s",
total, tojos.size(),
System.currentTimeMillis() - start
);
} else {
Logger.debug(this, "No XMIR programs out of %d optimized", tojos.size());
Logger.debug(this, "No XMIR programs out of %d shaked", tojos.size());
}
}

/**
* XMIR shaken to another XMIR.
* @param tojo Foreign tojo
* @param xsline Transformations to apply to XMIR
* @param transform Transformations to apply to XMIR
* @return Amount of optimized XMIR files
* @throws Exception If fails
*/
private int shaken(final ForeignTojo tojo, final Xsline xsline)
private int shaken(final ForeignTojo tojo, final Function<XML, XML> transform)
throws Exception {
final Path source = tojo.xmir();
final XML xmir = new XMLDocument(source);
Expand All @@ -118,7 +108,7 @@ private int shaken(final ForeignTojo tojo, final Xsline xsline)
final Path target = new Place(name).make(base, AssembleMojo.XMIR);
tojo.withShaken(
new FpDefault(
src -> xsline.pass(xmir).toString(),
src -> transform.apply(xmir).toString(),
this.cache.toPath().resolve(ShakeMojo.CACHE),
this.plugin.getVersion(),
new TojoHash(tojo),
Expand All @@ -130,21 +120,25 @@ private int shaken(final ForeignTojo tojo, final Xsline xsline)

/**
* Shake XSL transformations.
* If {@link SafeMojo#trackTransformationSteps} is {@code true} - we create new {@link Xsline}
* for every XMIR in purpose of thread safety.
* @return Shake XSL transformations for all tojos.
*/
private Xsline transformations() {
private Function<XML, XML> transformations() {
final Train<Shift> measured = this.measured(new TrShaking());
final Train<Shift> train;
final Function<XML, XML> func;
if (this.trackTransformationSteps) {
train = new TrSpy(
measured,
new StickyFunc<>(
new ProgramPlace(this.targetDir.toPath().resolve(ShakeMojo.STEPS))
func = xml -> new Xsline(
new TrSpy(
measured,
new StickyFunc<>(
new ProgramPlace(this.targetDir.toPath().resolve(ShakeMojo.STEPS))
)
)
);
).pass(xml);
} else {
train = measured;
func = new Xsline(measured)::pass;
}
return new Xsline(train);
return func;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ final class TrShaking extends TrEnvelope {
"/org/eolang/parser/shake/explicit-data.xsl",
"/org/eolang/parser/shake/set-locators.xsl",
"/org/eolang/parser/shake/clean-up.xsl",
"/org/eolang/parser/shake/globals-to-abstracts.xsl",
"/org/eolang/parser/shake/remove-refs.xsl",
"/org/eolang/parser/shake/abstracts-float-up.xsl",
"/org/eolang/parser/shake/remove-levels.xsl",
Expand Down
60 changes: 36 additions & 24 deletions eo-maven-plugin/src/main/java/org/eolang/maven/TranspileMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import java.util.Collection;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Function;
import java.util.function.Supplier;
import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
Expand Down Expand Up @@ -78,26 +79,25 @@
)
@SuppressWarnings("PMD.LongVariable")
public final class TranspileMojo extends SafeMojo {

/**
* The directory where to put pre-transpile files.
*/
public static final String PRE = "7-pre";

/**
* The directory where to transpile to.
*/
public static final String DIR = "8-transpile";
static final String DIR = "8-transpile";

/**
* Cache directory for transpiled sources.
*/
public static final String CACHE = "transpiled";
private static final String CACHE = "transpiled";

/**
* Java extension.
*/
public static final String JAVA = "java";
private static final String JAVA = "java";

/**
* The directory where to put pre-transpile files.
*/
private static final String PRE = "7-pre";

/**
* Parsing train with XSLs.
Expand Down Expand Up @@ -165,10 +165,10 @@ public final class TranspileMojo extends SafeMojo {
@Override
public void exec() {
final Collection<ForeignTojo> sources = this.scopedTojos().withShaken();
final Xsline xsline = this.xsline();
final Function<XML, XML> transform = this.transpilation();
final int saved = new Threaded<>(
sources,
tojo -> this.transpiled(tojo, xsline)
tojo -> this.transpiled(tojo, transform)
).total();
Logger.info(
this, "Transpiled %d XMIRs, created %d Java files in %[file]s",
Expand All @@ -193,11 +193,14 @@ public void exec() {
/**
* Transpile.
* @param tojo Tojo that should be transpiled.
* @param xsline Optimization that transpiles
* @param transform Optimization that transpiles
* @return Number of transpiled files.
* @throws java.io.IOException If any issues with I/O
*/
private int transpiled(final ForeignTojo tojo, final Xsline xsline) throws IOException {
private int transpiled(
final ForeignTojo tojo,
final Function<XML, XML> transform
) throws IOException {
final Path source = tojo.shaken();
final XML xmir = new XMLDocument(source);
final Path base = this.targetDir.toPath().resolve(TranspileMojo.DIR);
Expand All @@ -209,7 +212,7 @@ private int transpiled(final ForeignTojo tojo, final Xsline xsline) throws IOExc
new FpDefault(
src -> {
rewrite.set(true);
return xsline.pass(xmir).toString();
return transform.apply(xmir).toString();
},
this.cache.toPath().resolve(TranspileMojo.CACHE),
this.plugin.getVersion(),
Expand All @@ -220,18 +223,27 @@ private int transpiled(final ForeignTojo tojo, final Xsline xsline) throws IOExc
}

/**
* Transpile optimization.
* @return Optimization that transpiles
* Transpile XSL transformations.
* If {@link SafeMojo#trackTransformationSteps} is {@code true} - we create new {@link Xsline}
* for every XMIR in purpose of thread safety.
* @return XSL transformations that transpiles XMIR to Java.
*/
private Xsline xsline() {
return new Xsline(
new TrSpy(
this.measured(TranspileMojo.TRAIN),
new StickyFunc<>(
new ProgramPlace(this.targetDir.toPath().resolve(TranspileMojo.PRE))
private Function<XML, XML> transpilation() {
final Train<Shift> measured = this.measured(TranspileMojo.TRAIN);
final Function<XML, XML> func;
if (this.trackTransformationSteps) {
func = xml -> new Xsline(
new TrSpy(
measured,
new StickyFunc<>(
new ProgramPlace(this.targetDir.toPath().resolve(TranspileMojo.PRE))
)
)
)
);
).pass(xml);
} else {
func = new Xsline(measured)::pass;
}
return func;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ SOFTWARE.
-->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" id="attrs" version="2.0">
<xsl:output encoding="UTF-8" method="xml"/>
<xsl:template match="class/o[@name and not(@level)]">
<xsl:template match="class[not(@base)]/o[@name and not(@level)]">
<xsl:element name="attr">
<xsl:apply-templates select="@name"/>
<xsl:variable name="t">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,25 @@ SOFTWARE.
</xsl:if>
</xsl:template>
<xsl:template match="o[eo:abstract(.)]">
<xsl:apply-templates select="." mode="class"/>
</xsl:template>
<xsl:template match="objects/o[@base and @name]">
<xsl:apply-templates select="." mode="class">
<xsl:with-param name="bound" select="true()"/>
</xsl:apply-templates>
</xsl:template>
<xsl:template match="o" mode="class">
<xsl:param name="bound"/>
<xsl:element name="class">
<xsl:apply-templates select="node()|@*"/>
<xsl:apply-templates select="@*"/>
<xsl:choose>
<xsl:when test="$bound">
<xsl:copy-of select="."/>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="node()"/>
</xsl:otherwise>
</xsl:choose>
<xsl:element name="xmir">
<xsl:call-template name="serialize">
<xsl:with-param name="node" select="."/>
Expand Down
Loading

0 comments on commit eca8fc6

Please sign in to comment.