Skip to content

Commit 8ada900

Browse files
committed
Add custom conversion to String for some classes
1 parent 68c0f1c commit 8ada900

File tree

9 files changed

+95
-2
lines changed

9 files changed

+95
-2
lines changed

src/main/java/org/truffleruby/core/proc/ProcCallTargets.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import com.oracle.truffle.api.CompilerDirectives.CompilationFinal;
1414
import com.oracle.truffle.api.RootCallTarget;
1515
import com.oracle.truffle.api.nodes.RootNode;
16+
import org.truffleruby.core.string.StringUtils;
1617
import org.truffleruby.language.RubyLambdaRootNode;
1718
import org.truffleruby.language.RubyProcRootNode;
1819
import org.truffleruby.language.RubyRootNode;
@@ -92,4 +93,13 @@ private boolean validLambdaRootNode(RootCallTarget callTarget) {
9293
assert rootNode instanceof RubyLambdaRootNode : rootNode + " " + rootNode.getClass();
9394
return true;
9495
}
96+
97+
@Override
98+
public String toString() {
99+
return StringUtils.format(
100+
"ProcCallTargets(callTargetForProc = %s, callTargetForLambda = %s, altCallTargetCompiler = %s)",
101+
callTargetForProc,
102+
callTargetForLambda,
103+
altCallTargetCompiler);
104+
}
95105
}

src/main/java/org/truffleruby/core/range/RubyIntRange.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
*/
1010
package org.truffleruby.core.range;
1111

12+
import org.truffleruby.core.string.StringUtils;
1213

1314
public final class RubyIntRange extends RubyIntOrLongRange {
1415

@@ -21,4 +22,10 @@ public RubyIntRange(boolean excludedEnd, int begin, int end) {
2122
this.end = end;
2223
}
2324

25+
@Override
26+
public String toString() {
27+
String suffix = StringUtils.format("(begin = %s, end = %s, excludedEnd = %s)", begin, end, excludedEnd);
28+
return super.toString() + suffix;
29+
}
30+
2431
}

src/main/java/org/truffleruby/core/range/RubyLongRange.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
*/
1010
package org.truffleruby.core.range;
1111

12+
import org.truffleruby.core.string.StringUtils;
1213

1314
public final class RubyLongRange extends RubyIntOrLongRange {
1415

@@ -21,4 +22,10 @@ public RubyLongRange(boolean excludedEnd, long begin, long end) {
2122
this.end = end;
2223
}
2324

25+
@Override
26+
public String toString() {
27+
String suffix = StringUtils.format("(begin = %s, end = %s, excludedEnd = %s)", begin, end, excludedEnd);
28+
return super.toString() + suffix;
29+
}
30+
2431
}

src/main/java/org/truffleruby/core/regexp/RubyRegexp.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,15 @@
2626
import org.truffleruby.core.encoding.RubyEncoding;
2727
import org.truffleruby.core.kernel.KernelNodes;
2828
import org.truffleruby.core.klass.RubyClass;
29+
import org.truffleruby.core.string.StringUtils;
2930
import org.truffleruby.language.ImmutableRubyObjectNotCopyable;
3031
import org.truffleruby.core.string.TStringWithEncoding;
3132
import org.truffleruby.language.control.DeferredRaiseException;
3233
import org.truffleruby.language.dispatch.DispatchNode;
3334

3435
@ExportLibrary(InteropLibrary.class)
35-
public final class RubyRegexp extends ImmutableRubyObjectNotCopyable implements TruffleObject, Comparable<RubyRegexp> {
36+
public final class RubyRegexp extends ImmutableRubyObjectNotCopyable
37+
implements TruffleObject, Comparable<RubyRegexp> {
3638

3739
@TruffleBoundary
3840
public static RubyRegexp create(RubyLanguage language,
@@ -121,4 +123,11 @@ public int compareTo(RubyRegexp o) {
121123
return options.compareTo(o.options);
122124
}
123125
}
126+
127+
@Override
128+
public String toString() {
129+
return StringUtils.format(
130+
"RubyRegexp(source = %s, options = %s, encoding = %s)",
131+
source, options, encoding);
132+
}
124133
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/*
2+
* Copyright (c) 2021, 2023 Oracle and/or its affiliates. All rights reserved. This
3+
* code is released under a tri EPL/GPL/LGPL license. You can use it,
4+
* redistribute it and/or modify it under the terms of the:
5+
*
6+
* Eclipse Public License version 2.0, or
7+
* GNU General Public License version 2, or
8+
* GNU Lesser General Public License version 2.1.
9+
*/
10+
package org.truffleruby.core.support;
11+
12+
public interface DetailedInspectingSupport {
13+
public String toStringWithDetails();
14+
}

src/main/java/org/truffleruby/language/arguments/KeywordArgumentsDescriptor.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010
package org.truffleruby.language.arguments;
1111

1212
import com.oracle.truffle.api.CompilerDirectives.CompilationFinal;
13+
import org.truffleruby.core.string.StringUtils;
14+
15+
import java.util.stream.Collectors;
16+
import java.util.stream.Stream;
1317

1418
/** An arguments descriptor that says that keyword arguments were passed (either foo(a: 1) or foo(**kw)). Note that
1519
* currently, if kw is empty, then this descriptor is used even though it is semantically the same as if no keyword
@@ -26,4 +30,10 @@ public final class KeywordArgumentsDescriptor extends ArgumentsDescriptor {
2630
public String[] getKeywords() {
2731
return keywords;
2832
}
33+
34+
@Override
35+
public String toString() {
36+
final String keywordsAsString = Stream.of(keywords).collect(Collectors.joining(", ", "[", "]"));
37+
return StringUtils.format("KeywordArgumentsDescriptor(keywords = %s)", keywordsAsString);
38+
}
2939
}

src/main/java/org/truffleruby/language/methods/ModuleBodyDefinition.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
import org.truffleruby.collections.ConcurrentOperations;
1616
import org.truffleruby.core.module.RubyModule;
17+
import org.truffleruby.core.string.StringUtils;
1718
import org.truffleruby.language.LexicalScope;
1819
import org.truffleruby.language.RubyBaseNode;
1920
import org.truffleruby.annotations.Visibility;
@@ -85,4 +86,19 @@ private LexicalScope prepareLexicalScope(LexicalScope staticLexicalScope, Lexica
8586
}
8687
}
8788

89+
public RootCallTarget getCallTarget() {
90+
return callTarget;
91+
}
92+
93+
@Override
94+
public String toString() {
95+
return StringUtils.format(
96+
"ModuleBodyDefinition(name = %s, sharedMethodInfo = %s, callTarget = %s, staticLexicalScope = %s, dynamicLexicalScopes = %s)",
97+
this.name,
98+
this.sharedMethodInfo.toStringWithDetails(),
99+
this.callTarget,
100+
this.staticLexicalScope,
101+
this.dynamicLexicalScopes);
102+
}
103+
88104
}

src/main/java/org/truffleruby/language/methods/SharedMethodInfo.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
import org.truffleruby.core.klass.RubyClass;
1515
import org.truffleruby.core.module.RubyModule;
1616
import org.truffleruby.core.proc.RubyProc;
17+
import org.truffleruby.core.string.StringUtils;
18+
import org.truffleruby.core.support.DetailedInspectingSupport;
1719
import org.truffleruby.language.LexicalScope;
1820
import org.truffleruby.language.RubyDynamicObject;
1921
import org.truffleruby.language.RubyGuards;
@@ -24,11 +26,13 @@
2426
import org.truffleruby.parser.OpenModule;
2527
import org.truffleruby.parser.ParserContext;
2628

29+
import java.util.Arrays;
30+
2731
/** SharedMethodInfo represents static information from the parser for either a method definition or a block like its
2832
* name, SourceSection, etc. Such information is always "original" since it comes from the source as opposed to
2933
* "aliased" (e.g. the aliased name of a method). In contrast, {@link InternalMethod} are runtime objects containing
3034
* properties that change for a method. */
31-
public final class SharedMethodInfo {
35+
public final class SharedMethodInfo implements DetailedInspectingSupport {
3236

3337
private final SourceSection sourceSection;
3438
/** LexicalScope if it can be determined statically at parse time, otherwise null */
@@ -241,4 +245,13 @@ public String toString() {
241245
return getDescriptiveNameAndSource();
242246
}
243247

248+
@Override
249+
public String toStringWithDetails() {
250+
final String string = Arrays.deepToString(argumentDescriptors);
251+
252+
return StringUtils.format(
253+
"SharedMethodInfo(sourceSection = %s, staticLexicalScope = %s, arity = %s, originName = %s, blockDepth = %s, parseName = %s, notes = %s, argumentDescriptors = %s)",
254+
sourceSection, staticLexicalScope, arity, originalName, blockDepth, parseName, notes, string);
255+
}
256+
244257
}

src/main/java/org/truffleruby/parser/ArgumentDescriptor.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
***** END LICENSE BLOCK *****/
2727
package org.truffleruby.parser;
2828

29+
import org.truffleruby.core.string.StringUtils;
30+
2931
/** A description of a single argument in a Ruby argument list. */
3032
public final class ArgumentDescriptor {
3133
/** The type of the argument */
@@ -53,4 +55,9 @@ public ArgumentDescriptor(ArgumentType type) {
5355
this(type, null);
5456
}
5557

58+
@Override
59+
public String toString() {
60+
return StringUtils.format("ArgumentDescriptor(name = %s, type = %s)", name, type);
61+
}
62+
5663
}

0 commit comments

Comments
 (0)