-
Notifications
You must be signed in to change notification settings - Fork 178
bug(#4529): locals-to-aliases optimization implemented in MjParse
#4588
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -9,6 +9,9 @@ | |||||||||||||||||||||||||||||||||||||||||||||||
| import com.jcabi.log.Logger; | ||||||||||||||||||||||||||||||||||||||||||||||||
| import com.jcabi.xml.XML; | ||||||||||||||||||||||||||||||||||||||||||||||||
| import com.jcabi.xml.XMLDocument; | ||||||||||||||||||||||||||||||||||||||||||||||||
| import com.yegor256.xsline.StClasspath; | ||||||||||||||||||||||||||||||||||||||||||||||||
| import com.yegor256.xsline.TrDefault; | ||||||||||||||||||||||||||||||||||||||||||||||||
| import com.yegor256.xsline.Xsline; | ||||||||||||||||||||||||||||||||||||||||||||||||
| import java.io.FileNotFoundException; | ||||||||||||||||||||||||||||||||||||||||||||||||
| import java.io.IOException; | ||||||||||||||||||||||||||||||||||||||||||||||||
| import java.nio.file.Path; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -21,6 +24,7 @@ | |||||||||||||||||||||||||||||||||||||||||||||||
| import org.apache.maven.plugins.annotations.ResolutionScope; | ||||||||||||||||||||||||||||||||||||||||||||||||
| import org.cactoos.io.InputOf; | ||||||||||||||||||||||||||||||||||||||||||||||||
| import org.cactoos.iterable.Filtered; | ||||||||||||||||||||||||||||||||||||||||||||||||
| import org.cactoos.list.ListOf; | ||||||||||||||||||||||||||||||||||||||||||||||||
| import org.cactoos.text.TextOf; | ||||||||||||||||||||||||||||||||||||||||||||||||
| import org.eolang.parser.EoSyntax; | ||||||||||||||||||||||||||||||||||||||||||||||||
| import org.eolang.parser.OnDefault; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -41,6 +45,32 @@ | |||||||||||||||||||||||||||||||||||||||||||||||
| requiresDependencyResolution = ResolutionScope.COMPILE | ||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||
| public final class MjParse extends MjSafe { | ||||||||||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||||||||||
| * Reserved object bases from QQ. | ||||||||||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||||||||||
| private static final String QQS = String.join( | ||||||||||||||||||||||||||||||||||||||||||||||||
| ",", | ||||||||||||||||||||||||||||||||||||||||||||||||
| new ListOf<>( | ||||||||||||||||||||||||||||||||||||||||||||||||
| "Φ.org.eolang.number", | ||||||||||||||||||||||||||||||||||||||||||||||||
| "Φ.org.eolang.bytes" | ||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||||||||||
| * Optimization line. | ||||||||||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||||||||||
| private static final Xsline OPTIMIZATION_LINE = new Xsline( | ||||||||||||||||||||||||||||||||||||||||||||||||
| new TrDefault<>( | ||||||||||||||||||||||||||||||||||||||||||||||||
| new StClasspath( | ||||||||||||||||||||||||||||||||||||||||||||||||
| "/org/eolang/maven/parse/locals-to-aliases.xsl", | ||||||||||||||||||||||||||||||||||||||||||||||||
| "name reserved", | ||||||||||||||||||||||||||||||||||||||||||||||||
| String.format( | ||||||||||||||||||||||||||||||||||||||||||||||||
| "reserved %s", | ||||||||||||||||||||||||||||||||||||||||||||||||
| MjParse.QQS | ||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+62
to
+73
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same Checkstyle issue for OPTIMIZATION_LINE; also drop unused XSL param “name”.
Apply this diff: - private static final Xsline OPTIMIZATION_LINE = new Xsline(
+ static final Xsline OPTIMIZATION_LINE = new Xsline(
new TrDefault<>(
new StClasspath(
"/org/eolang/maven/parse/locals-to-aliases.xsl",
- "name reserved",
String.format(
"reserved %s",
MjParse.QQS
)
)
)
);📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||||||||||
| * Zero version. | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -104,7 +134,7 @@ private int parsed(final TjForeign tojo) throws Exception { | |||||||||||||||||||||||||||||||||||||||||||||||
| src -> { | ||||||||||||||||||||||||||||||||||||||||||||||||
| final Node node = this.parsed(src, name); | ||||||||||||||||||||||||||||||||||||||||||||||||
| refs.add(node); | ||||||||||||||||||||||||||||||||||||||||||||||||
| return new XMLDocument(node).toString(); | ||||||||||||||||||||||||||||||||||||||||||||||||
| return MjParse.OPTIMIZATION_LINE.pass(new XMLDocument(node)).toString(); | ||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||
| this.cache.toPath().resolve(MjParse.CACHE), | ||||||||||||||||||||||||||||||||||||||||||||||||
| this.plugin.getVersion(), | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,39 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <?xml version="1.0" encoding="UTF-8"?> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <!-- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * SPDX-FileCopyrightText: Copyright (c) 2016-2025 Objectionary.com | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * SPDX-License-Identifier: MIT | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| --> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:eo="https://www.eolang.org" id="locals-to-aliases" version="2.0"> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <xsl:param name="name"/> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <xsl:param name="reserved"/> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <xsl:output encoding="UTF-8" method="xml"/> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <xsl:variable name="pkg" select="normalize-space(/object/metas/meta[head='package'][1]/tail)"/> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <xsl:variable name="qqs" select="tokenize(normalize-space($reserved), '[\s,]+')"/> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <xsl:template match="@*|node()"> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <xsl:copy> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <xsl:apply-templates select="@*|node()"/> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| </xsl:copy> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| </xsl:template> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <xsl:template match="@base[starts-with(., 'Φ.') and not(. = $qqs)]"> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <xsl:variable name="seg" select="tokenize(., '\.')[last()]"/> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <xsl:attribute name="base" select="concat($pkg, '.', $seg)"/> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| </xsl:template> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+17
to
+20
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Critical: Wrong rewrite target (affects Φ. instead of locals).* You currently rewrite bases starting with Φ., which are standard library objects, not locals. This will incorrectly turn many QQ references into package ones and won’t touch local names like “bar”. Rewrite only simple, local bases (no dot, not Φ/ξ). Apply this diff: - <xsl:template match="@base[starts-with(., 'Φ.') and not(. = $qqs)]">
- <xsl:variable name="seg" select="tokenize(., '\.')[last()]"/>
- <xsl:attribute name="base" select="concat($pkg, '.', $seg)"/>
- </xsl:template>
+ <!-- Rewrite only local (simple) bases to fully-qualified ones -->
+ <xsl:template match="@base[not(contains(., '.')) and not(starts-with(., 'Φ')) and not(starts-with(., 'ξ')) and string-length($pkg) > 0]">
+ <xsl:attribute name="base" select="concat($pkg, '.', .)"/>
+ </xsl:template>🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <xsl:template match="metas"> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <xsl:copy> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <xsl:apply-templates select="@*|node()"/> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <xsl:for-each-group select="//@base[starts-with(., 'Φ.') and not(. = $qqs)]" group-by="tokenize(., '\.')[last()]"> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <xsl:variable name="seg" select="current-grouping-key()"/> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <xsl:variable name="new" select="concat($pkg, '.', $seg)"/> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <xsl:variable name="tail" select="concat($seg, ' ', $new)"/> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <xsl:if test="not(/object/metas/meta[head='alias' and tail=$new])"> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <meta> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <head>alias</head> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <tail><xsl:value-of select="$tail"/></tail> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <part><xsl:value-of select="$seg"/></part> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <part><xsl:value-of select="$new"/></part> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| </meta> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| </xsl:if> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| </xsl:for-each-group> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| </xsl:copy> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+21
to
+37
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Critical: Alias generation targets the wrong set and has a bug in existence check.
Apply this diff: <xsl:template match="metas">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
- <xsl:for-each-group select="//@base[starts-with(., 'Φ.') and not(. = $qqs)]" group-by="tokenize(., '\.')[last()]">
- <xsl:variable name="seg" select="current-grouping-key()"/>
- <xsl:variable name="new" select="concat($pkg, '.', $seg)"/>
- <xsl:variable name="tail" select="concat($seg, ' ', $new)"/>
- <xsl:if test="not(/object/metas/meta[head='alias' and tail=$new])">
+ <!-- Create aliases for local names only -->
+ <xsl:for-each-group
+ select="//@base[not(contains(., '.')) and not(starts-with(., 'Φ')) and not(starts-with(., 'ξ'))]"
+ group-by=".">
+ <xsl:variable name="seg" select="current-grouping-key()"/>
+ <xsl:variable name="new" select="concat($pkg, '.', $seg)"/>
+ <xsl:variable name="tail" select="concat($seg, ' ', $new)"/>
+ <xsl:if test="string-length($pkg) > 0 and not(/object/metas/meta[head='alias' and tail=$tail])">
<meta>
<head>alias</head>
- <tail><xsl:value-of select="$tail"/></tail>
- <part><xsl:value-of select="$seg"/></part>
- <part><xsl:value-of select="$new"/></part>
+ <tail><xsl:value-of select="$tail"/></tail>
+ <part><xsl:value-of select="$seg"/></part>
+ <part><xsl:value-of select="$new"/></part>
</meta>
</xsl:if>
</xsl:for-each-group>
</xsl:copy>
</xsl:template>📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| </xsl:template> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| </xsl:stylesheet> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
This file was deleted.
This file was deleted.
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -5,6 +5,7 @@ | |||
| package org.eolang.maven; | ||||
|
|
||||
| import com.jcabi.matchers.XhtmlMatchers; | ||||
| import com.jcabi.xml.XML; | ||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove unused import to fix qulice failure.
Apply this diff: -import com.jcabi.xml.XML;📝 Committable suggestion
Suggested change
🧰 Tools🪛 GitHub Actions: qulice[error] 8-8: PMD: Unused import 'com.jcabi.xml.XML' (UnnecessaryImport) 🤖 Prompt for AI Agents |
||||
| import com.jcabi.xml.XMLDocument; | ||||
| import com.yegor256.Mktmp; | ||||
| import com.yegor256.MktmpResolver; | ||||
|
|
@@ -283,6 +284,33 @@ void parsesWithTargetCache(@Mktmp final Path temp) throws IOException { | |||
| ); | ||||
| } | ||||
|
|
||||
| @Test | ||||
| void convertsLocalObjectsToAliases(@Mktmp final Path temp) throws IOException { | ||||
| MatcherAssert.assertThat( | ||||
| "Local object is not converted to alias, but it should", | ||||
| new XMLDocument( | ||||
| new FakeMaven(temp) | ||||
| .withProgram( | ||||
| String.join( | ||||
| "\n", | ||||
| "+package foo", | ||||
| "", | ||||
| "[] > x", | ||||
| " bar 42 > @" | ||||
| ), | ||||
| "foo.x" | ||||
| ) | ||||
| .execute(new FakeMaven.Parse()) | ||||
| .result() | ||||
| .get("target/1-parse/foo/x.xmir") | ||||
| ), | ||||
| XhtmlMatchers.hasXPaths( | ||||
| "/object/metas/meta[head='alias' and part='bar' and part='foo.bar' and tail='bar foo.bar']", | ||||
| "//o[@base='foo.bar']/o[1][@base='Φ.org.eolang.number']/o[1][@base='Φ.org.eolang.bytes']" | ||||
| ) | ||||
| ); | ||||
| } | ||||
|
|
||||
| /** | ||||
| * The mojo that does nothing, but executes infinitely. | ||||
| * @since 0.29 | ||||
|
|
||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix Checkstyle DeclarationOrder by aligning access modifiers.
The new fields precede package-private constants (ZERO, DIR, CACHE), causing “Variable access definition in wrong order.” Make these new constants package‑private to match, or move them below. Quick unblocking change:
Apply this diff:
🤖 Prompt for AI Agents