Skip to content

Commit

Permalink
Re-try to resolve types in java.lang
Browse files Browse the repository at this point in the history
Because `java.lang` types get automatically imported, they can be
"resolved" without being resolved to the same thing that they are in the
source file. This ultimately winds up preventing the generated code from
compiling.
  • Loading branch information
PtrTeixeira committed Aug 3, 2023
1 parent 9fdadf7 commit 3487dc5
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package org.immutables.fixture.module;

import org.immutables.value.Value;

@Value.Immutable
@Value.Style(typeAbstract = {"*IF"}, typeImmutable = "*")
public interface ModuleIF {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package org.immutables.fixture.module.subpackage;

import org.immutables.fixture.module.Module;
import org.immutables.value.Value;


@Value.Immutable
@Value.Style(headerComments = true)
public interface HasModuleField {
Module getModule();
}
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,14 @@ private void appendResolved(DeclaredType type) {
}

hasMaybeUnresolvedYetAfter |= importsResolver.unresolved;
} else if (typeName.equals("java.lang." + typeElement.getSimpleName())) {
// Because java.lang is automatically imported, you can have type names that are "resolved,"
// but aren't the names that are actually imported in the source file
String simpleName = type.asElement().getSimpleName().toString();
String guessedName = importsResolver.apply(simpleName);
if (!importsResolver.unresolved) {
typeName = guessedName;
}
}

buffer.append(typeName);
Expand Down

0 comments on commit 3487dc5

Please sign in to comment.