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

Share Name.Literal strings #11886

Merged
merged 2 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -477,16 +477,34 @@ object Name {
* @param originalName the name which this literal has replaced, if any
* @param passData the pass metadata associated with this node
*/
sealed case class Literal(
sealed case class Literal private (
override val name: String,
override val isMethod: Boolean,
override val identifiedLocation: IdentifiedLocation,
originalName: Option[Name] = None,
override val passData: MetadataStorage = new MetadataStorage()
private val origName: Name,
override val passData: MetadataStorage
) extends Name
with LazyDiagnosticStorage
with LazyId {

def this(
name: String,
isMethod: Boolean,
identifiedLocation: IdentifiedLocation,
originalName: Option[Name] = None,
passData: MetadataStorage = new MetadataStorage()
) = {
this(
name.intern(),
isMethod,
identifiedLocation,
originalName.orNull,
passData
)
}

def originalName: Option[Name] = Option(this.origName)

/** Creates a copy of `this`.
*
* @param name the literal text of the name
Expand Down Expand Up @@ -517,7 +535,7 @@ object Name {
|| id != this.id
) {
val res =
Literal(name, isMethod, location.orNull, originalName, passData)
new Literal(name, isMethod, location.orNull, originalName, passData)
res.diagnostics = diagnostics
res.id = id
res
Expand Down Expand Up @@ -568,6 +586,16 @@ object Name {
override def showCode(indent: Int): String = name
}

object Literal {
def apply(
name: String,
isMethod: Boolean,
identifiedLocation: IdentifiedLocation,
originalName: Option[Name] = None,
passData: MetadataStorage = new MetadataStorage()
) = new Literal(name, isMethod, identifiedLocation, originalName, passData)
}

/** Base trait for annotations. */
sealed trait Annotation extends Name with module.scope.Definition {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,12 +139,14 @@ && isVisibleFrom(e, orig))
if (constructors.size() > 1) {
var snd = (ExecutableElement) constructors.get(1);
if (richerConstructor.compare(cons, snd) == 0) {
processingEnv
.getMessager()
.printMessage(
Kind.ERROR,
"There should be exactly one 'richest' constructor in " + typeElem,
orig);
var sb = new StringBuilder();
sb.append("There should be exactly one 'richest' constructor in ")
.append(typeElem)
.append(". Found:");
for (var c : constructors) {
sb.append("\n ").append(c);
}
processingEnv.getMessager().printMessage(Kind.ERROR, sb.toString(), orig);
return false;
}
}
Expand Down Expand Up @@ -288,8 +290,12 @@ private int countInlineRef(List<? extends VariableElement> parameters) {
var cnt = 0;
for (var p : parameters) {
var type = tu.asElement(tu.erasure(p.asType()));
if (type != null && type.getSimpleName().toString().equals("Reference")) {
cnt++;
if (type != null) {
switch (type.getSimpleName().toString()) {
case "Reference" -> cnt++;
case "Option" -> cnt++;
default -> {}
}
}
}
return cnt;
Expand Down
Loading