Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6346983

jsr269 Types.getDeclaredType(TypElement, TypeMirror ...) create's invalid DecalaredType.

    Details

      Description

      This following example shows, how to create a invalid 'DeclaredType' instance.
      Case1<java.lang.String,java.lang.String> is invalid as Case1<T extends List, T1 extends List> was declared.

      I am not completely sure, what other complications can cause while using a invalid 'DeclaredType'.

      bash-3.00$ ksh compile.sh
       element received as Case1
       declared type Case1<java.lang.String,java.lang.String>
       element received as Case1
       declared type Case1<java.lang.String,java.lang.String>
      java version "1.6.0-auto"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.6.0-auto-292b)
      Java HotSpot(TM) Server VM (build 1.6.0-ea-b56, mixed mode)
      bash-3.00$ cat Case1.java
      import java.util.List;
      public class Case1 <T extends List, T1 extends List> {
      }
      bash-3.00$ cat CaseAP.java
      import java.util.*;
      import javax.annotation.processing.*;
      import javax.lang.model.element.*;
      import javax.lang.model.type.*;
      import javax.lang.model.util.*;
      import static javax.lang.model.SourceVersion.*;
      import static javax.lang.model.type.TypeKind.*;

      @SupportedAnnotationTypes("*")
      @SupportedSourceVersion(RELEASE_6)
      @SupportedOptions("-verbose")
      public class CaseAP extends AbstractProcessor {
          public void init(ProcessingEnvironment penv) {
              super.init(penv);
          }
          public boolean process(Set<? extends TypeElement> typeElementSet,
                  RoundEnvironment renv) {
              Elements elementUtils = processingEnv.getElementUtils();
              Types types = processingEnv.getTypeUtils();
              TypeElement case2 = elementUtils.getTypeElement("Case1");
              TypeElement type = elementUtils.getTypeElement("java.lang.String");
              if ( case2 != null ) {
                  System.out.println(" element received as "+case2.toString());
                  DeclaredType dt = types.getDeclaredType(case2, type.asType(), type.asType());
                  System.out.println(" declared type "+dt.toString());
              }
              return true ;
          }
      }
      bash-3.00$

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                darcy Joe Darcy
                Reporter:
                vvegurusunw Viswadeep Veguru (Inactive)
              • Votes:
                0 Vote for this issue
                Watchers:
                1 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Imported:
                  Indexed: