8224630: ElementScannerN, N > 9 should scan type parameters
Reviewed-by: mcimadamore, erikj
This commit is contained in:
parent
565770872a
commit
df308ac680
make/autoconf
src
java.compiler/share/classes/javax/lang/model/util
jdk.compiler/share/classes/com/sun/tools/javac/processing
@ -1,5 +1,5 @@
|
|||||||
#
|
#
|
||||||
# Copyright (c) 2011, 2018, Oracle and/or its affiliates. All rights reserved.
|
# Copyright (c) 2011, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||||
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
#
|
#
|
||||||
# This code is free software; you can redistribute it and/or modify it
|
# This code is free software; you can redistribute it and/or modify it
|
||||||
@ -345,7 +345,7 @@ AC_DEFUN_ONCE([BOOTJDK_SETUP_BOOT_JDK],
|
|||||||
|
|
||||||
# When compiling code to be executed by the Boot JDK, force compatibility with the
|
# When compiling code to be executed by the Boot JDK, force compatibility with the
|
||||||
# oldest supported bootjdk.
|
# oldest supported bootjdk.
|
||||||
BOOT_JDK_SOURCETARGET="-source 9 -target 9"
|
BOOT_JDK_SOURCETARGET="-source 13 -target 13"
|
||||||
AC_SUBST(BOOT_JDK_SOURCETARGET)
|
AC_SUBST(BOOT_JDK_SOURCETARGET)
|
||||||
|
|
||||||
AC_SUBST(JAVAC_FLAGS)
|
AC_SUBST(JAVAC_FLAGS)
|
||||||
|
@ -25,6 +25,8 @@
|
|||||||
|
|
||||||
package javax.lang.model.util;
|
package javax.lang.model.util;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.ArrayList;
|
||||||
import javax.lang.model.element.*;
|
import javax.lang.model.element.*;
|
||||||
import javax.annotation.processing.SupportedSourceVersion;
|
import javax.annotation.processing.SupportedSourceVersion;
|
||||||
import javax.lang.model.SourceVersion;
|
import javax.lang.model.SourceVersion;
|
||||||
@ -120,6 +122,48 @@ public class ElementScanner14<R, P> extends ElementScanner9<R, P> {
|
|||||||
super(defaultValue);
|
super(defaultValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*
|
||||||
|
* @implSpec This implementation scans the type parameters, if
|
||||||
|
* any, and then the enclosed elements.
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @param e {@inheritDoc}
|
||||||
|
* @param p {@inheritDoc}
|
||||||
|
* @return the result of scanning
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public R visitType(TypeElement e, P p) {
|
||||||
|
return scan(createScanningList(e, e.getEnclosedElements()), p);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*
|
||||||
|
* @implSpec This implementation first scans the type parameters, if any, and then
|
||||||
|
* the parameters.
|
||||||
|
*
|
||||||
|
* @param e {@inheritDoc}
|
||||||
|
* @param p {@inheritDoc}
|
||||||
|
* @return the result of scanning
|
||||||
|
*/
|
||||||
|
public R visitExecutable(ExecutableElement e, P p) {
|
||||||
|
return scan(createScanningList(e, e.getParameters()), p);
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<? extends Element> createScanningList(Parameterizable element,
|
||||||
|
List<? extends Element> toBeScanned) {
|
||||||
|
var typeParameters = element.getTypeParameters();
|
||||||
|
if (typeParameters.isEmpty()) {
|
||||||
|
return toBeScanned;
|
||||||
|
} else {
|
||||||
|
List<Element> scanningList = new ArrayList<>(typeParameters);
|
||||||
|
scanningList.addAll(toBeScanned);
|
||||||
|
return scanningList;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*
|
*
|
||||||
|
@ -124,8 +124,7 @@ public class JavacRoundEnvironment implements RoundEnvironment {
|
|||||||
|
|
||||||
Set<Element> result = Collections.emptySet();
|
Set<Element> result = Collections.emptySet();
|
||||||
@SuppressWarnings("preview")
|
@SuppressWarnings("preview")
|
||||||
ElementScanner14<Set<Element>, TypeElement> scanner =
|
var scanner = new AnnotationSetScanner(result);
|
||||||
new AnnotationSetScanner(result);
|
|
||||||
|
|
||||||
for (Element element : rootElements)
|
for (Element element : rootElements)
|
||||||
result = scanner.scan(element, a);
|
result = scanner.scan(element, a);
|
||||||
@ -146,8 +145,7 @@ public class JavacRoundEnvironment implements RoundEnvironment {
|
|||||||
|
|
||||||
Set<Element> result = Collections.emptySet();
|
Set<Element> result = Collections.emptySet();
|
||||||
@SuppressWarnings("preview")
|
@SuppressWarnings("preview")
|
||||||
ElementScanner14<Set<Element>, Set<TypeElement>> scanner =
|
var scanner = new AnnotationSetMultiScanner(result);
|
||||||
new AnnotationSetMultiScanner(result);
|
|
||||||
|
|
||||||
for (Element element : rootElements)
|
for (Element element : rootElements)
|
||||||
result = scanner.scan(element, annotationSet);
|
result = scanner.scan(element, annotationSet);
|
||||||
@ -156,8 +154,9 @@ public class JavacRoundEnvironment implements RoundEnvironment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Could be written as a local class inside getElementsAnnotatedWith
|
// Could be written as a local class inside getElementsAnnotatedWith
|
||||||
|
@SuppressWarnings("preview")
|
||||||
private class AnnotationSetScanner extends
|
private class AnnotationSetScanner extends
|
||||||
ElementScanningIncludingTypeParameters<Set<Element>, TypeElement> {
|
ElementScanner14<Set<Element>, TypeElement> {
|
||||||
// Insertion-order preserving set
|
// Insertion-order preserving set
|
||||||
private Set<Element> annotatedElements = new LinkedHashSet<>();
|
private Set<Element> annotatedElements = new LinkedHashSet<>();
|
||||||
|
|
||||||
@ -191,8 +190,9 @@ public class JavacRoundEnvironment implements RoundEnvironment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Could be written as a local class inside getElementsAnnotatedWithAny
|
// Could be written as a local class inside getElementsAnnotatedWithAny
|
||||||
|
@SuppressWarnings("preview")
|
||||||
private class AnnotationSetMultiScanner extends
|
private class AnnotationSetMultiScanner extends
|
||||||
ElementScanningIncludingTypeParameters<Set<Element>, Set<TypeElement>> {
|
ElementScanner14<Set<Element>, Set<TypeElement>> {
|
||||||
// Insertion-order preserving set
|
// Insertion-order preserving set
|
||||||
private Set<Element> annotatedElements = new LinkedHashSet<>();
|
private Set<Element> annotatedElements = new LinkedHashSet<>();
|
||||||
|
|
||||||
@ -225,29 +225,6 @@ public class JavacRoundEnvironment implements RoundEnvironment {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("preview")
|
|
||||||
private static abstract class ElementScanningIncludingTypeParameters<R, P>
|
|
||||||
extends ElementScanner14<R, P> {
|
|
||||||
|
|
||||||
protected ElementScanningIncludingTypeParameters(R defaultValue) {
|
|
||||||
super(defaultValue);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override @DefinedBy(Api.LANGUAGE_MODEL)
|
|
||||||
public R visitType(TypeElement e, P p) {
|
|
||||||
// Type parameters are not considered to be enclosed by a type
|
|
||||||
scan(e.getTypeParameters(), p);
|
|
||||||
return super.visitType(e, p);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override @DefinedBy(Api.LANGUAGE_MODEL)
|
|
||||||
public R visitExecutable(ExecutableElement e, P p) {
|
|
||||||
// Type parameters are not considered to be enclosed by an executable
|
|
||||||
scan(e.getTypeParameters(), p);
|
|
||||||
return super.visitExecutable(e, p);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*/
|
*/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user