Skip to content

Commit

Permalink
objectionary#3728 introduce oname to PhSafe
Browse files Browse the repository at this point in the history
  • Loading branch information
Suban05 committed Feb 13, 2025
1 parent c48ec8e commit 19d5760
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -607,6 +607,10 @@ 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:text>);</xsl:text>
</xsl:if>
</xsl:template>
Expand Down
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
20 changes: 16 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,12 @@ public String locator() {

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

@Override
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
3 changes: 2 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,7 +104,8 @@ void getsLocation() {
"foobar",
123,
56,
"Φ.org.eolang$obj"
"Φ.org.eolang$obj",
"org.eolang.obj"
).locator(),
Matchers.equalTo("Φ.org.eolang$obj:123:56")
);
Expand Down

0 comments on commit 19d5760

Please sign in to comment.