JDK-6460529 : Provide mixin interfaces for getQualifiedName and getTypeParameters
  • Type: Enhancement
  • Component: core-libs
  • Sub-Component: javax.lang.model
  • Affected Version: 6
  • Priority: P4
  • Status: Closed
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2006-08-16
  • Updated: 2017-05-16
  • Resolved: 2011-07-15
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 7
7 b50Fixed
Related Reports
Relates :  
Description
The JSR 269 language model for elements is very flat, a root Element interface and five direct subinterfaces.  However, certain children interfaces have a method in common and it could be useful to be able to group objects based on the presence of those methods.  For example, TypeElements and PackageElements have a getQualifiedName method and TypeElements and ExecutableElements have a getTypeParameters method.  To allow such grouping,  "QualifiedNamable extends Element" and a "Parameterizable extends Element" interfaces could be added and implemented by the modeling interfaces in question.

Comments
SUGGESTED FIX --- old/src/share/classes/com/sun/tools/javac/processing/PrintingProcessor.java Fri Feb 20 11:56:28 2009 +++ new/src/share/classes/com/sun/tools/javac/processing/PrintingProcessor.java Fri Feb 20 11:56:27 2009 @@ -125,7 +125,7 @@ return this; defaultAction(e, true); - printFormalTypeParameters(e); + printFormalTypeParameters(e, true); switch(kind) { case CONSTRUCTOR: @@ -207,7 +207,7 @@ writer.print(" "); writer.print(e.getSimpleName()); - printFormalTypeParameters(e); + printFormalTypeParameters(e, false); // Print superclass information if informative if (kind == CLASS) { @@ -364,16 +364,9 @@ } } - private void printFormalTypeParameters(ExecutableElement executable) { - printFormalTypeParameters(executable.getTypeParameters(), true); - } - - private void printFormalTypeParameters(TypeElement type) { - printFormalTypeParameters(type.getTypeParameters(), false); - } - - private void printFormalTypeParameters(List<? extends TypeParameterElement> typeParams, + private void printFormalTypeParameters(Parameterizable e, boolean pad) { + List<? extends TypeParameterElement> typeParams = e.getTypeParameters(); if (typeParams.size() > 0) { writer.print("<"); --- old/src/share/classes/javax/lang/model/element/ExecutableElement.java Fri Feb 20 11:56:30 2009 +++ new/src/share/classes/javax/lang/model/element/ExecutableElement.java Fri Feb 20 11:56:29 2009 @@ -1,5 +1,5 @@ /* - * Copyright 2005-2006 Sun Microsystems, Inc. All Rights Reserved. + * Copyright 2005-2009 Sun Microsystems, Inc. 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 @@ -40,7 +40,7 @@ * @see ExecutableType * @since 1.6 */ -public interface ExecutableElement extends Element { +public interface ExecutableElement extends Element, Parameterizable { /** * Returns the formal type parameters of this executable * in declaration order. --- old/src/share/classes/javax/lang/model/element/PackageElement.java Fri Feb 20 11:56:32 2009 +++ new/src/share/classes/javax/lang/model/element/PackageElement.java Fri Feb 20 11:56:31 2009 @@ -1,5 +1,5 @@ /* - * Copyright 2005-2006 Sun Microsystems, Inc. All Rights Reserved. + * Copyright 2005-2009 Sun Microsystems, Inc. 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 @@ -25,7 +25,6 @@ package javax.lang.model.element; - /** * Represents a package program element. Provides access to information * about the package and its members. @@ -36,9 +35,8 @@ * @see javax.lang.model.util.Elements#getPackageOf * @since 1.6 */ +public interface PackageElement extends Element, QualifiedNameable { -public interface PackageElement extends Element { - /** * Returns the fully qualified name of this package. * This is also known as the package's <i>canonical</i> name. --- old/src/share/classes/javax/lang/model/element/TypeElement.java Fri Feb 20 11:56:33 2009 +++ new/src/share/classes/javax/lang/model/element/TypeElement.java Fri Feb 20 11:56:33 2009 @@ -1,5 +1,5 @@ /* - * Copyright 2005-2006 Sun Microsystems, Inc. All Rights Reserved. + * Copyright 2005-2009 Sun Microsystems, Inc. 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 @@ -59,7 +59,7 @@ * @see DeclaredType * @since 1.6 */ -public interface TypeElement extends Element { +public interface TypeElement extends Element, Parameterizable, QualifiedNameable { /** * Returns the <i>nesting kind</i> of this type element. --- /dev/null Fri Feb 20 11:56:35 2009 +++ new/src/share/classes/javax/lang/model/element/Parameterizable.java Fri Feb 20 11:56:35 2009 @@ -0,0 +1,45 @@ +/* + * Copyright 2009 Sun Microsystems, Inc. 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 + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Sun designates this + * particular file as subject to the "Classpath" exception as provided + * by Sun in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + */ + +package javax.lang.model.element; + +import java.util.List; + +/** + * A mixin interface for an element that has type parameters. + * + * @author Joseph D. Darcy + * @since 1.7 + */ +public interface Parameterizable extends Element { + /** + * Returns the formal type parameters of the type element in + * declaration order. + * + * @return the formal type parameters, or an empty list + * if there are none + */ + List<? extends TypeParameterElement> getTypeParameters(); +} --- /dev/null Fri Feb 20 11:56:37 2009 +++ new/src/share/classes/javax/lang/model/element/QualifiedNameable.java Fri Feb 20 11:56:37 2009 @@ -0,0 +1,41 @@ +/* + * Copyright 2009 Sun Microsystems, Inc. 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 + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Sun designates this + * particular file as subject to the "Classpath" exception as provided + * by Sun in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + */ + +package javax.lang.model.element; + +/** + * A mixin interface for an element that has a qualified name. + * + * @author Joseph D. Darcy + * @since 1.7 + */ +public interface QualifiedNameable extends Element { + /** + * Returns the fully qualified name of an element. + * + * @return the fully qualified name of an element + */ + Name getQualifiedName(); +}
2009-02-20

EVALUATION The utility of providing such mixin interfaces should be evaluated as more experience is gained programming against the API; such a retrofit can be done compatibly in a post-JDK 6 release.
2006-08-16