Skip to content

Commit 352238e

Browse files
committed
Add InternalMethod#getOriginalName() and improve documentation
1 parent e5e43af commit 352238e

File tree

4 files changed

+11
-6
lines changed

4 files changed

+11
-6
lines changed

src/main/java/org/truffleruby/core/MainNodes.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ protected Object mainUsing(Frame callerFrame, Object self, Object[] rubyArgs, Ro
7373

7474
@TruffleBoundary
7575
private boolean isCalledFromTopLevel(InternalMethod callerMethod) {
76-
final String name = callerMethod.getSharedMethodInfo().getOriginalName();
76+
final String name = callerMethod.getOriginalName();
7777
return name.equals("<main>") || name.startsWith("<top ");
7878
}
7979
}

src/main/java/org/truffleruby/core/method/UnboundMethodNodes.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,11 +153,9 @@ public abstract static class OriginalNameNode extends CoreMethodArrayArgumentsNo
153153
@Specialization
154154
protected RubySymbol originalName(RubyUnboundMethod unboundMethod,
155155
@Cached ToSymbolNode toSymbolNode) {
156-
String originalName = unboundMethod.method.getSharedMethodInfo().getOriginalName();
157-
156+
String originalName = unboundMethod.method.getOriginalName();
158157
return toSymbolNode.execute(originalName);
159158
}
160-
161159
}
162160

163161
@CoreMethod(names = "owner")

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,10 @@ public String getName() {
194194
return name;
195195
}
196196

197+
public String getOriginalName() {
198+
return sharedMethodInfo.getOriginalName();
199+
}
200+
197201
public Visibility getVisibility() {
198202
return visibility;
199203
}

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,10 @@
2424
import org.truffleruby.parser.OpenModule;
2525
import org.truffleruby.parser.ParserContext;
2626

27-
/** {@link InternalMethod} objects are copied as properties such as visibility are changed. {@link SharedMethodInfo}
28-
* stores the state that does not change, such as where the method was defined. */
27+
/** SharedMethodInfo represents static information from the parser for either a method definition or a block like its
28+
* name, SourceSection, etc. Such information is always "original" since it comes from the source as opposed to
29+
* "aliased" (e.g. the aliased name of a method). In contrast, {@link InternalMethod} are runtime objects containing
30+
* properties that change for a method. */
2931
public final class SharedMethodInfo {
3032

3133
private final SourceSection sourceSection;
@@ -150,6 +152,7 @@ public static boolean isModuleBody(String name) {
150152
}
151153
}
152154

155+
/** See {@link #originalName} */
153156
public String getOriginalName() {
154157
return originalName;
155158
}

0 commit comments

Comments
 (0)