Skip to content

Start javadocs on Identifier - #2

Open
cassiancc wants to merge 6 commits into
FabricMC:26.3from
cassiancc:test-project
Open

cassiancc wants to merge 6 commits into
FabricMC:26.3from
cassiancc:test-project

Conversation

@cassiancc

Copy link
Copy Markdown
Member

Not comprehensive - opening this PR as a test of the editing/submission process.

@Earthcomputer Earthcomputer left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm surprised the javadoc lint was okay with [a-z0-9/._-], I'd have thought that would be interpreted as a link

@modmuss50 modmuss50 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for being picky, but I think we need to be on these early PRs, Ill have a PR with some convensions soon so hopefully that will help.

Co-authored-by: Joseph Burton <burtonjae@hotmail.co.uk>
@cassiancc

Copy link
Copy Markdown
Member Author

Picky is good - didn't know about @throws existing.

@ErrorCraft

Copy link
Copy Markdown

I recommend looking at this article as it explains the available keywords, as well as this article for markdown formatting as some keywords (like @code and @literal) are no longer necessary as a result of markdown Javadocs. It might also be useful to link the articles in the conventions PR modmuss mentioned.

As for this earlier comment:

I'm surprised the javadoc lint was okay with [a-z0-9/._-], I'd have thought that would be interpreted as a link

It's 'accepted' but renders the text red as it can't find the reference, as [whatever] tries to reference whatever the same way {@link whatever} does, so [Object#hashCode()] refers to the hashCode method in the Object class.

@Earthcomputer

Copy link
Copy Markdown
Contributor

The javadoc lint is supposed to check that references are valid...

@ErrorCraft

Copy link
Copy Markdown

Ah. If you're talking about the changes from #4, this branch doesn't have those commits, so it's not checking anything.

@Earthcomputer

Copy link
Copy Markdown
Contributor

No, the javadoc lint was added in #1

@ErrorCraft

Copy link
Copy Markdown

The task only seems to fail for cases where the body has a correct reference format, but the reference itself is invalid. I think it passes because a-z0-9/._- isn't an actual reference to anything, so it (incorrectly?) falls back to the usual markdown link title, or even interprets it as a literal as that is also considered valid markdown. (Example: 'hello [square] world' vs hello [square] world))

A few tests with these references gave the following results:

  • [Object#hashCode()] - does not fail as expected
  • [text label][Object#hashCode()] - does not fail as expected
  • [invalid] - fails as expected (wants to reference invalid as either class, field or method)
  • [invalid.] - does not fail
  • [text label][invalid] - fails as expected
  • [text label][invalid.] - does not fail

@Earthcomputer

Copy link
Copy Markdown
Contributor

I have tested it, the javadoc tool only treats it as a link if the text inside the [] brackets is a valid Javadoc link, otherwise it treats it as plain text. The output has no red text and isn't treated as an error.

@cassiancc

Copy link
Copy Markdown
Member Author

Sorry - why would it be read as a link in the first place? It's wrapped in a code block.

@Earthcomputer

Copy link
Copy Markdown
Contributor

We're talking about before it was wrapped in a code block and worrying about why it wasn't caught by any lint. It might be something for @its-miroma's linter to catch

@its-miroma

Copy link
Copy Markdown
Member

markdownlint does not know what a valid Java reference is. I would add a custom linter rule that validates each reference link.

@ErrorCraft

Copy link
Copy Markdown

It seems to be pretty inconsistent in IntelliJ too...
image

@cassiancc
cassiancc requested review from a team as code owners November 6, 2026 16:54
modmuss50
modmuss50 previously approved these changes Nov 7, 2026
NotNightSky
NotNightSky previously approved these changes Nov 7, 2026

@its-miroma its-miroma left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This review of mine is intentionally way too nitpicky, because we need to properly establish the conventions to follow.
My comments aren't necessarily changes to be applied, some are food for thought and discussion.

@@ -0,0 +1,40 @@
CLASS net/minecraft/resources/Identifier
COMMENT `Identifier`s are used in Minecraft's code to identify a resource's location.

@its-miroma its-miroma Nov 7, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Docs' refreshed guidelines say: "Avoid specifying that the [modded] game is Minecraft"

Should we apply that rule to Annotater too?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO, we should not apply that to the annotator, since the code is not modified yet.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's even more of a reason why mentioning "Minecraft" is redundant.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Annotater's guidelines don't specify this, I think the clarification is fine.

COMMENT To avoid ambiguity, they consist of a namespace representing the creator of the resource and the path to the resource.
COMMENT When converted to a string, the namespace and path are combined becoming `namespace:path`.
METHOD assertValidPath (Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;
COMMENT @throws IdentifierException If the path contains a non `[a-z0-9/._-]` character.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not super familiar with javadocs conventions, is this supposed to be read as a sentence? Should "If" be lowercase?

This is an internal private method, should it be documented?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically all Minecraft methods are "internal". I don't think we should limit ourselves to only documenting what is public, assuming there is actually something worth documenting.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A private method is only intended to be used by that class, so in that sense it's internal. I think we might want to avoid documenting methods unless they are public or access-widened, to keep the scope of the project contained.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

access widened methods do not exist in the annotater realm.

@cassiancc cassiancc Nov 7, 2026 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see the harm in documenting private methods if it benefits the user. Neither Yarn or Annotater had restrictions about documenting private methods.

COMMENT @throws IdentifierException If the path contains a non `[a-z0-9/._-]` character.
METHOD fromNamespaceAndPath (Ljava/lang/String;Ljava/lang/String;)Lnet/minecraft/resources/Identifier;
COMMENT Creates an identifier from a namespace and a path.
COMMENT @param namespace The namespace, restricted to `[a-z0-9_.-]`.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The "Effective Dart: Documentation" page that our guidelines cite discourage the usage of @param, especially when the description is redundant. Instead, they suggest formatting it as prose, like:

Both [namespace] and [path] are restricted to `[a-z0-9/._-]`.

In fact, given that we have a @throws clause, in this case we might want to do something like:

@throws IdentifierException if either [namespace] or [path] contain an invalid character.

Question: can multiple @throws clauses reference the same error?

@throws IdentifierException if [namespace] contains an invalid non-`[a-z0-9._-]` character.
@throws IdentifierException if [path] contains an invalid non-`[a-z0-9/._-]` character.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Annotater's guidelines do not discourage the use of @param, I think it is a benefit to be able to see descriptions on the parameters themselves.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's interesting, I was not aware of that detail regarding @param.

METHOD toLanguageKey (Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;
COMMENT @return A translation key in the format `prefix.namespace.path.suffix`.
METHOD toShortLanguageKey ()Ljava/lang/String;
COMMENT @return A translation key in the format `namespace.path`. If the namespace is `minecraft`, the translation key is shortened to `path`.

@its-miroma its-miroma Nov 7, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we reference other methods? For example:

Similar to [toLanguageKey], but drops the default [namespace] `minecraft`.

Question: can multiple @return clauses be used in the same comment?

@return A translation key in the format `namespace.path`.
@return A translation key in the format `path`, if the [namespace] is {@value #DEFAULT_NAMESPACE}.

@NotNightSky NotNightSky Nov 7, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, multiple @return clauses can be used in the same comment and will be formatted like multiple @param clauses.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think referencing other methods makes sense. Multiple @return declarations doesn't though, this isn't allowed per the javadoc spec.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think referencing other methods makes sense. Multiple @return declarations doesn't though, this isn't allowed per the javadoc spec.

It isn't?

Comment on lines +23 to +24
COMMENT @param namespace The namespace, restricted to `[a-z0-9_.-]`.
COMMENT @param path The path, restricted to `[a-z0-9/._-]`

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this description of namespace and path, and their constraints, should be moved to the class comment? That way all methods would document what they do with invalid parameters (throw, return null, etc).

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Annotater's guidelines allow for repeated descriptions like these - being able to see them when looking at a method is better than having to check the class itself.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make sense to reference the ALLOWED_NAMESPACE_CHARACTERS constant here instead?

COMMENT @param path The path, restricted to `[a-z0-9/._-]`
COMMENT @return An `Identifier` created from the namespace and path, or `null` if either string contains an invalid character.
METHOD withDefaultNamespace (Ljava/lang/String;)Lnet/minecraft/resources/Identifier;
COMMENT Creates an `Identifier` in the vanilla `minecraft` namespace.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we reference DEFAULT_NAMESPACE?

The @param description is more verbose than the other comments.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure - DEFAULT_NAMESPACE is a variable that's inlined at the compilation stage. We'll need to decide what to do about variables like these that need unpicking.

COMMENT @return A new `Identifier` with the same namespace and a different path.
METHOD withPath (Ljava/util/function/UnaryOperator;)Lnet/minecraft/resources/Identifier;
COMMENT @param modifier A modifier to prepend to the existing path, with the result restricted to `[a-z0-9/._-]`
COMMENT @return Creates a new `Identifier` with the same namespace and a different path.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know if this. is allowed in javadocs like these:

@return a new [Identifier] with the same [this.namespace] and the new [path].

I also think that we should prefer references to code blocks, such as [Identifier] instead of `Identifier`, because the former can be validated.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is valid by prepending it with a #; [#namespace] refers to the namespace field. As for the method parameters, those aren't valid references within the class, so using inline code is fine.

@return a new [Identifier] with the same [#namespace] and the new `path`.

@cassiancc
cassiancc dismissed stale reviews from NotNightSky and modmuss50 via 9919f58 November 7, 2026 20:22
COMMENT @param path the path, restricted to `[a-z0-9/._-]`
COMMENT @return an `Identifier` created from the namespace and path, or `null` if either string contains an invalid character.
METHOD withDefaultNamespace (Ljava/lang/String;)Lnet/minecraft/resources/Identifier;
COMMENT Creates an `Identifier` with the namespace set to [DEFAULT_NAMESPACE].

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
COMMENT Creates an `Identifier` with the namespace set to [DEFAULT_NAMESPACE].
COMMENT Creates an [Identifier] with the [default namespace][#DEFAULT_NAMESPACE].

Renders like this, which reads more like a sentence:

Creates an Identifier with the default namespace.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants