-
Enhancement
-
Resolution: Unresolved
-
P4
-
None
-
None
-
None
This is generally related to JDK-8055219, which discussed handling of ErrorType in javax.lang.model.util.Types.
I think it would be valuable for the specification of Types#directSupertypes and TypeElement#getInterfacese to discuss how ErrorType is handled.
Consider an example like:
import java.util.List;
class T implements List<String>, NoSuch {}
Calling Types#directSupertypes on T omits the ErrorType:
directSupertypes(T) = [java.lang.Object, java.util.List<java.lang.String>]
on the other hand, TypeElement#getInterfaces includes the ErrorType:
getInterfaces() = java.util.List<java.lang.String>,NoSuch
I found it surprising that they weren't consistent, but I also don't have concerns wtih the current behaviour, mostly it wasn't clear to me what to expect and I think it would be valuable for the specification to address that the behaviour is.
---
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.TypeElement;
import javax.tools.Diagnostic;
@SupportedAnnotationTypes("*")
public class P extends AbstractProcessor {
@Override
public SourceVersion getSupportedSourceVersion() {
return SourceVersion.latestSupported();
}
private boolean first = true;
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
if (!first) {
return false;
}
first = false;
TypeElement e = processingEnv.getElementUtils().getTypeElement("T");
processingEnv
.getMessager()
.printMessage(
Diagnostic.Kind.ERROR,
String.format("%s.getInterfaces() = %s", e, e.getInterfaces()),
e);
processingEnv
.getMessager()
.printMessage(
Diagnostic.Kind.ERROR,
String.format(
"directSupertypes(%s) = %s",
e.asType(), processingEnv.getTypeUtils().directSupertypes(e.asType())),
e);
return false;
}
}
I think it would be valuable for the specification of Types#directSupertypes and TypeElement#getInterfacese to discuss how ErrorType is handled.
Consider an example like:
import java.util.List;
class T implements List<String>, NoSuch {}
Calling Types#directSupertypes on T omits the ErrorType:
directSupertypes(T) = [java.lang.Object, java.util.List<java.lang.String>]
on the other hand, TypeElement#getInterfaces includes the ErrorType:
getInterfaces() = java.util.List<java.lang.String>,NoSuch
I found it surprising that they weren't consistent, but I also don't have concerns wtih the current behaviour, mostly it wasn't clear to me what to expect and I think it would be valuable for the specification to address that the behaviour is.
---
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.TypeElement;
import javax.tools.Diagnostic;
@SupportedAnnotationTypes("*")
public class P extends AbstractProcessor {
@Override
public SourceVersion getSupportedSourceVersion() {
return SourceVersion.latestSupported();
}
private boolean first = true;
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
if (!first) {
return false;
}
first = false;
TypeElement e = processingEnv.getElementUtils().getTypeElement("T");
processingEnv
.getMessager()
.printMessage(
Diagnostic.Kind.ERROR,
String.format("%s.getInterfaces() = %s", e, e.getInterfaces()),
e);
processingEnv
.getMessager()
.printMessage(
Diagnostic.Kind.ERROR,
String.format(
"directSupertypes(%s) = %s",
e.asType(), processingEnv.getTypeUtils().directSupertypes(e.asType())),
e);
return false;
}
}
- relates to
-
JDK-8055219 Handling of non-standard inputs in javax.lang.model.util.Types
-
- Open
-