javac does not initialize receiver types of methods read from class files, which results in ExecutableElement.getReceiverType incorrectly reporting that methods don't have a receiver type.
Repro:
=== P.java
import java.util.Set;
import javax.annotation.processing.AbstractProcessor;
import javax.annotation.processing.RoundEnvironment;
import javax.annotation.processing.SupportedAnnotationTypes;
import javax.lang.model.SourceVersion;
import javax.lang.model.element.Element;
import javax.lang.model.element.ExecutableElement;
import javax.lang.model.element.TypeElement;
import javax.tools.Diagnostic;
@SupportedAnnotationTypes("*")
public class P extends AbstractProcessor {
@Override
public SourceVersion getSupportedSourceVersion() {
return SourceVersion.latestSupported();
}
boolean first = true;
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
if (first) {
for (Element e :
processingEnv.getElementUtils().getTypeElement("Test").getEnclosedElements()) {
if (e.getSimpleName().contentEquals("f")) {
ExecutableElement f = (ExecutableElement) e;
processingEnv
.getMessager()
.printMessage(Diagnostic.Kind.NOTE, f.getReceiverType().toString(), f);
}
}
first = false;
}
return false;
}
}
=== Test.java
class Test {
void f(Test this) {}
}
===
The receiver type is available if 'Test' is compiled from source:
$ javac -processor P -implicit:none Test.java
Test.java:2: Note: Test
void f(Test this) {}
^
The receiver type is incorrectly reported as 'none' if 'Test' is loaded from the classpath:
$ javac -processor P -implicit:none Test
Note: none