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

#3728 add @original-name attribute including parent objects #3920

Merged
merged 21 commits into from
Feb 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ final class TrShaking extends TrEnvelope {
new TrClasspath<>(
"/org/eolang/maven/shake/cti-adds-errors.xsl",
"/org/eolang/maven/shake/add-probes.xsl",
"/org/eolang/maven/shake/set-locators.xsl"
"/org/eolang/maven/shake/set-locators.xsl",
"/org/eolang/maven/shake/set-original-names.xsl"
).back()
)
);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
The MIT License (MIT)

Copyright (c) 2016-2025 Objectionary.com

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
-->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:eo="https://www.eolang.org" xmlns:xs="http://www.w3.org/2001/XMLSchema" id="set-original-names" version="2.0">
<!--
Here we go through all objects and add @original-name attributes
to all of them. The value of the attribute is a FQN
of the object.
-->
<xsl:output encoding="UTF-8" method="xml"/>
<xsl:function name="eo:original-name" as="xs:string">
<xsl:param name="program" as="node()"/>
<xsl:param name="o" as="node()"/>
<xsl:if test="name($o) != 'o'">
<xsl:message terminate="yes">
<xsl:text>Only 'o' XML elements are accepted here</xsl:text>
</xsl:message>
</xsl:if>
<xsl:variable name="parent" select="$o/parent::o"/>
<xsl:variable name="ret">
<xsl:if test="$parent">
<xsl:value-of select="eo:original-name($program, $parent)"/>
<xsl:text>.</xsl:text>
</xsl:if>
<xsl:choose>
<xsl:when test="$o/@name">
<xsl:choose>
<xsl:when test="$o/@name = '@'">
<xsl:text>φ</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$o/@name"/>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:otherwise>
<xsl:choose>
<xsl:when test="starts-with($parent/@base, '.') and not($o/preceding-sibling::o)">
<xsl:text>ρ</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:text>α</xsl:text>
<xsl:value-of select="count($o/preceding-sibling::o) - count($parent[starts-with(@base, '.')])"/>
</xsl:otherwise>
</xsl:choose>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:value-of select="$ret"/>
</xsl:function>
<xsl:template match="o[not(@original-name)]">
<xsl:copy>
<xsl:apply-templates select="@*"/>
<xsl:attribute name="original-name" select="eo:original-name(/program, .)"/>
<xsl:apply-templates select="node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
Original file line number Diff line number Diff line change
Expand Up @@ -607,7 +607,9 @@ SOFTWARE.
<xsl:text>"</xsl:text>
<xsl:value-of select="@loc"/>
<xsl:text>"</xsl:text>
<xsl:text>);</xsl:text>
<xsl:text>, "</xsl:text>
<xsl:value-of select="@original-name"/>
<xsl:text>");</xsl:text>
</xsl:if>
</xsl:template>
<!-- Application -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,20 @@ sheets:
- /org/eolang/maven/shake/add-probes.xsl
- /org/eolang/maven/shake/set-locators.xsl
- /org/eolang/maven/shake/blank-xsd-schema.xsl
- /org/eolang/maven/shake/set-original-names.xsl
asserts:
- /program[not(errors)]
- //o[@name='a' and @loc='Φ.org.abc.a']
- //o[@base='Q.x' and @loc='Φ.org.abc.a.φ.α0']
- //o[@base='Q.org.eolang.string' and @loc='Φ.org.abc.a.φ.α0.α0']
- //o[@base='Q.x' and @name='tt' and @loc='Φ.org.abc.tt']
- //o[@base='Q.org.eolang.number' and @loc='Φ.org.abc.tt.α0']
- //o[@base='Q.org.eolang.tuple.empty.with' and @loc='Φ.org.abc.tt.α1.ρ']
- //o[@base='Q.org.eolang.number' and @loc='Φ.org.abc.tt.α1.ρ.α0']
- //o[not(@base) and @loc='Φ.org.abc.tt.α2']
- //o[@base='∅' and @name='e' and @loc='Φ.org.abc.tt.α2.e']
- //o[@base='$.e.hello' and @loc='Φ.org.abc.tt.α2.φ']
- //o[@base='$.^.^.p' and @loc='Φ.org.abc.q']
- //o[@name='a' and @loc='Φ.org.abc.a' and @original-name='a']
- //o[@base='Q.x' and @loc='Φ.org.abc.a.φ.α0' and @original-name='a.φ.α0']
- //o[@base='Q.org.eolang.string' and @loc='Φ.org.abc.a.φ.α0.α0' and @original-name='a.φ.α0.α0']
- //o[@base='Q.x' and @name='tt' and @loc='Φ.org.abc.tt' and @original-name='tt']
- //o[@base='Q.org.eolang.number' and @loc='Φ.org.abc.tt.α0' and @original-name='tt.α0']
- //o[@base='Q.org.eolang.tuple.empty.with' and @loc='Φ.org.abc.tt.α1.ρ' and @original-name='tt.α1.ρ']
- //o[@base='Q.org.eolang.number' and @loc='Φ.org.abc.tt.α1.ρ.α0' and @original-name='tt.α1.ρ.α0']
- //o[not(@base) and @loc='Φ.org.abc.tt.α2' and @original-name='tt.α2']
- //o[@base='∅' and @name='e' and @loc='Φ.org.abc.tt.α2.e' and @original-name='tt.α2.e']
- //o[@base='$.e.hello' and @loc='Φ.org.abc.tt.α2.φ' and @original-name='tt.α2.φ']
- //o[@base='$.^.^.p' and @loc='Φ.org.abc.q' and @original-name='q']
input: |
+alias org.abc.foo.b
+alias x
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# The MIT License (MIT)
#
# Copyright (c) 2016-2025 Objectionary.com
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
---
sheets:
- /org/eolang/maven/shake/set-original-names.xsl
document:
<?xml version="1.0" encoding="UTF-8"?>
<program>
<objects>
<o base=".a" name="a">
<o base="b"/>
<o base="c"/>
<o base="d"/>
</o>
</objects>
</program>
asserts:
- /program/objects/o[@original-name='a' and @base='.a']
- /program/objects/o/o[1][@original-name='a.ρ' and @base='b']
- /program/objects/o/o[2][@original-name='a.α0' and @base='c']
- /program/objects/o/o[3][@original-name='a.α1' and @base='d']
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# The MIT License (MIT)
#
# Copyright (c) 2016-2025 Objectionary.com
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
---
sheets:
- /org/eolang/maven/shake/set-original-names.xsl
document:
<?xml version="1.0" encoding="UTF-8"?>
<program>
<objects>
<o name="a">
<o base="b"/>
</o>
</objects>
</program>
asserts:
- /program/objects/o[@original-name='a']/o[@original-name='a.α0']
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ sheets:
- /org/eolang/maven/transpile/to-java.xsl
asserts:
- /program[not(errors)]
- //java[contains(text(), 'new PhSafe(r, "scenario", 3, 2, "Φ.foo.φ")')]
- //java[contains(text(), 'new PhSafe(rrb, "scenario", 6, 4, "Φ.foo.other.φ.ρ")')]
- //java[contains(text(), 'new PhSafe(rr, "scenario", 6, 6, "Φ.foo.other.φ")')]
- //java[contains(text(), 'new PhSafe(rr1, "scenario", 6, 12, "Φ.foo.other.φ.α0")')]
- //java[contains(text(), 'new PhSafe(rb, "scenario", 10, 2, "Φ.bar.φ.ρ")')]
- //java[contains(text(), 'new PhSafe(r, "scenario", 10, 4, "Φ.bar.φ")')]
- //java[contains(text(), 'new PhSafe(r1, "scenario", 10, 10, "Φ.bar.φ.α0")')]
- //java[contains(text(), 'new PhSafe(r, "scenario", 11, 2, "Φ.bar.five")')]
- //java[contains(text(), 'new PhSafe(r, "scenario", 3, 2, "Φ.foo.φ", "foo.φ")')]
- //java[contains(text(), 'new PhSafe(rrb, "scenario", 6, 4, "Φ.foo.other.φ.ρ", "foo.other.φ.ρ")')]
- //java[contains(text(), 'new PhSafe(rr, "scenario", 6, 6, "Φ.foo.other.φ", "foo.other.φ")')]
- //java[contains(text(), 'new PhSafe(rr1, "scenario", 6, 12, "Φ.foo.other.φ.α0", "foo.other.φ.α0")')]
- //java[contains(text(), 'new PhSafe(rb, "scenario", 10, 2, "Φ.bar.φ.ρ", "bar.φ.ρ")')]
- //java[contains(text(), 'new PhSafe(r, "scenario", 10, 4, "Φ.bar.φ", "bar.φ")')]
- //java[contains(text(), 'new PhSafe(r1, "scenario", 10, 10, "Φ.bar.φ.α0", "bar.φ.α0")')]
- //java[contains(text(), 'new PhSafe(r, "scenario", 11, 2, "Φ.bar.five", "bar.five")')]
input: |
# No comments.
[] > foo
Expand Down
3 changes: 3 additions & 0 deletions eo-runtime/src/main/java/org/eolang/Dataized.java
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ public byte[] take() {
raw.addAll(ex.messages());
Collections.reverse(raw);
final Phi enc = ex.enclosure();
if ("org.eolang.go.to.token.jump".equals(enc.forma())) {
throw new EOerror.ExError(enc);
}
if (String.format("%s.org.eolang.string", PhPackage.GLOBAL).equals(enc.forma())) {
raw.add(
String.format(
Expand Down
19 changes: 15 additions & 4 deletions eo-runtime/src/main/java/org/eolang/PhSafe.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ public final class PhSafe implements Phi, Atom {
*/
private final String location;

/**
* The original name.
*/
private final String oname;

/**
* Ctor.
*
Expand All @@ -90,7 +95,7 @@ public PhSafe(final Phi phi) {
* @checkstyle ParameterNumberCheck (5 lines)
*/
public PhSafe(final Phi phi, final String prg, final int lne, final int pos) {
this(phi, prg, lne, pos, "?");
this(phi, prg, lne, pos, "?", "?");
}

/**
Expand All @@ -101,15 +106,17 @@ public PhSafe(final Phi phi, final String prg, final int lne, final int pos) {
* @param lne Line
* @param pos Position
* @param loc Location
* @param oname Original name
* @checkstyle ParameterNumberCheck (5 lines)
*/
public PhSafe(final Phi phi, final String prg, final int lne,
final int pos, final String loc) {
final int pos, final String loc, final String oname) {
this.origin = phi;
this.program = prg;
this.line = lne;
this.position = pos;
this.location = loc;
this.oname = oname;
}

@Override
Expand All @@ -126,7 +133,7 @@ public int hashCode() {
public Phi copy() {
return new PhSafe(
this.origin.copy(), this.program,
this.line, this.position, this.location
this.line, this.position, this.location, this.oname
);
}

Expand Down Expand Up @@ -157,7 +164,11 @@ public String locator() {

@Override
public String forma() {
return this.through(this.origin::forma);
return String.join(
".",
this.getClass().getPackageName(),
this.oname
);
}

@Override
Expand Down
37 changes: 37 additions & 0 deletions eo-runtime/src/test/java/org/eolang/DataizedTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,43 @@ void failsWhenError() {
);
}

@Test
void doesNotLogGoToTokenJump() {
final Logger log = Logger.getLogger("logsWithPhSafe");
final Level before = log.getLevel();
log.setLevel(Level.ALL);
final List<LogRecord> logs = new LinkedList<>();
final Handler hnd = new Hnd(logs);
log.addHandler(hnd);
Assertions.assertThrows(
EOerror.ExError.class,
() -> new Dataized(
new PhDefault() {
@Override
public byte[] delta() {
throw new EOerror.ExError(
Phi.Φ.take("org")
.take("eolang")
.take("go")
.take("to")
.take("token")
.take("jump")
);
}
},
log
).take(),
"it is expected to fail with and exception"
);
log.setLevel(before);
log.removeHandler(hnd);
MatcherAssert.assertThat(
"Messages should not be logged",
logs,
Matchers.empty()
);
}

/**
* Handler implementation for tests.
*
Expand Down
2 changes: 1 addition & 1 deletion eo-runtime/src/test/java/org/eolang/PhSafeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ final class PhSafeTest {

@Test
void savesLocationAfterCopying() {
final Phi located = new PhSafe(new Data.ToPhi(0L), "foo", 123, 124, "qwerty");
final Phi located = new PhSafe(new Data.ToPhi(0L), "foo", 123, 124, "qwerty", "fqn");
MatcherAssert.assertThat(
"saves location",
located.copy().locator(),
Expand Down
19 changes: 18 additions & 1 deletion eo-runtime/src/test/java/org/eolang/PhiTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,26 @@ void getsLocation() {
"foobar",
123,
56,
"Φ.org.eolang$obj"
"Φ.org.eolang$obj",
"obj"
).locator(),
Matchers.equalTo("Φ.org.eolang$obj:123:56")
);
}

@Test
void getsForma() {
MatcherAssert.assertThat(
AtCompositeTest.TO_ADD_MESSAGE,
new PhSafe(
Phi.Φ,
"foobar",
123,
56,
"Φ.org.eolang$obj",
"obj.x"
).forma(),
Matchers.equalTo("org.eolang.obj.x")
);
}
}
Loading