--- old/src/java.compiler/share/classes/javax/lang/model/element/package-info.java 2016-08-19 20:01:43.490038592 -0700 +++ new/src/java.compiler/share/classes/javax/lang/model/element/package-info.java 2016-08-19 20:01:43.406038589 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 2016, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -53,7 +53,9 @@ * Names of parameters may not be recoverable from class files. * * The {@linkplain javax.lang.model.element.Modifier modifiers} on an - * element may differ in some cases including: + * element created from a class file may differ in some cases from an + * element for the same declaration created from a source file + * including: * * * - * Additionally, synthetic constructs in a class file, such as - * accessor methods used in implementing nested classes and bridge - * methods used in implementing covariant returns, are translation - * artifacts outside of this model. + * Some elements which are {@linkplain Elements.Naturalness#MANDATED + * mandated} may not be marked as such when created from class files. + * + * Additionally, {@linkplain Elements.Naturalness#SYNTHETIC synthetic} + * constructs in a class file, such as accessor methods used in + * implementing nested classes and {@linkplain + * Elements#isBridge(Element) bridge methods} used in implementing + * covariant returns, are translation artifacts strictly outside of + * this model. However, when operation on class files, it is helpful + * be able to operate on such elements, screening them out when + * appropriate. * *

During annotation processing, operating on incomplete or * erroneous programs is necessary; however, there are fewer --- old/src/java.compiler/share/classes/javax/lang/model/util/Elements.java 2016-08-19 20:01:43.810038604 -0700 +++ new/src/java.compiler/share/classes/javax/lang/model/util/Elements.java 2016-08-19 20:01:43.698038600 -0700 @@ -29,6 +29,7 @@ import java.util.List; import java.util.Map; +import javax.lang.model.AnnotatedConstruct; import javax.lang.model.element.*; @@ -136,6 +137,140 @@ boolean isDeprecated(Element e); /** + * Returns the naturalness of the given element. + * + *

Note that if an element logically has a naturalness other + * than {@link Naturalness#NATURAL NATURAL}, an implementation may + * not be able to reliably determine this status if the element is + * created from a class file due to limitations of the fidelity of + * the class file format in preserving information from source + * code. + * + * @implSpec The default implementation of this method returns + * {@link Naturalness#NATURAL NATURAL}. + * + * @param e the element being examined + * @return the naturalness of the given element + * @since 9 + */ + default Naturalness getNaturalness(Element e) { + return Naturalness.NATURAL; + } + + /** + * Returns the naturalness of the given annotation mirror. + * + * One example of a mandated construct is the + * implicitly declared container annotation used to hold + * repeated base annotations of a repeatable annotation type. + * + *

Note that if an annotation mirror logically has a + * naturalness other than {@link Naturalness#NATURAL NATURAL}, an + * implementation may not be able to reliably determine this + * status if the element is created from a class file due to + * limitations of the fidelity of the class file format in + * preserving information from source code. + * + * @implSpec The default implementation of this method returns + * {@link Naturalness#NATURAL NATURAL}. + * + * @param c the construct the annotation mirror modifies + * @param a the annotation mirror being examined + * @return the naturalness of the given annotation mirror + * @jls 9.6.3 Repeatable Annotation Types + * @jls 9.7.5 Multiple Annotations of the Same Type + * @since 9 + */ + default Naturalness getNaturalness(AnnotatedConstruct c, + AnnotationMirror a) { + return Naturalness.NATURAL; + } + + /** + * Returns the naturalness of the given module directive. + * + *

Note that if a directive mirror logically has a naturalness + * other than {@link Naturalness#NATURAL NATURAL}, an + * implementation may not be able to reliably determine this + * status if the element is created from a class file due to + * limitations of the fidelity of the class file format in + * preserving information from source code. + * + * @implSpec The default implementation of this method returns + * {@link Naturalness#NATURAL NATURAL}. + * + * @param m the module of the directive + * @param directive the module directive being examined + * @return the naturalness of the given directive + * @since 9 + */ + default Naturalness getNaturalness(ModuleElement m, + ModuleElement.Directive directive) { + return Naturalness.NATURAL; + } + + /** + * The naturalness of a construct. The naturalness of a + * construct concerns the consistency between how a construct is + * declared in source code (explicitly, implicitly, or not at all) + * compared to how the construct is represented in this model. + * + *

Note that it is possible additional kinds of naturalness + * will be added in future versions of the platform. + * + * @jls 13.1 The Form of a Binary + * @since 9 + */ + enum Naturalness { + /** + * A natural construct is explicitly declared in source code. + */ + NATURAL, + + /** + * A mandated construct is one not explicitly declared in the + * source code, but whose presence is mandated by the + * specification; such a construct is said to be implicitly declared. + * + * One example of a mandated element is a default + * constructor in a class that contains no explicit + * constructor declarations. + * + * Another example of a mandated construct is the implicitly + * declared container annotation used to hold + * multiple annotations of a repeatable annotation type. + * + * @jls 8.8.9 Default Constructor + * @jls 9.6.3 Repeatable Annotation Types + * @jls 9.7.5 Multiple Annotations of the Same Type + */ + MANDATED, + + /** + * A synthetic construct is one that is neither implicitly nor + * explicitly declared in the source code. Synthetic + * constructs are commonly translation artifacts created by + * compiler. + */ + SYNTHETIC; + } + + /** + * Returns {@code true} if the executable element is a bridge + * method, {@code false} otherwise. + * + * @implSpec The default implementation of this method returns {@code false}. + * + * @param e the executable being examined + * @return {@code true} if the executable element is a bridge + * method, {@code false} otherwise + * @since 9 + */ + default boolean isBridge(ExecutableElement e) { + return false; + } + + /** * Returns the binary name of a type element. * * @param type the type element being examined