changeset 982:307b065ff2af

7026414: Types.asElement() returns null for ErrorType Reviewed-by: darcy
author jjg
date Mon, 14 Mar 2011 11:33:33 -0700
parents b60754fe206d
children e2890b8369f7
files src/share/classes/com/sun/tools/javac/model/JavacTypes.java test/tools/javac/api/6557752/T6557752.java test/tools/javac/processing/model/element/TestMissingElement/TestMissingElement.java
diffstat 3 files changed, 20 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/com/sun/tools/javac/model/JavacTypes.java	Fri Mar 11 15:39:51 2011 -0800
+++ b/src/share/classes/com/sun/tools/javac/model/JavacTypes.java	Mon Mar 14 11:33:33 2011 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 2011, 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
@@ -73,9 +73,14 @@
 
     public Element asElement(TypeMirror t) {
         Type type = cast(Type.class, t);
-        if (type.tag != TypeTags.CLASS && type.tag != TypeTags.TYPEVAR)
-            return null;
-        return type.asElement();
+        switch (type.tag) {
+            case TypeTags.CLASS:
+            case TypeTags.ERROR:
+            case TypeTags.TYPEVAR:
+                return type.asElement();
+            default:
+                return null;
+        }
     }
 
     public boolean isSameType(TypeMirror t1, TypeMirror t2) {
--- a/test/tools/javac/api/6557752/T6557752.java	Fri Mar 11 15:39:51 2011 -0800
+++ b/test/tools/javac/api/6557752/T6557752.java	Mon Mar 14 11:33:33 2011 -0700
@@ -118,7 +118,8 @@
 
                 Types types = task.getTypes();
 
-                if (types.asElement(trees.getOriginalType((ErrorType)typeMirror)) != null) {
+                str1 = types.asElement(trees.getOriginalType((ErrorType)typeMirror)).toString();
+                if (!str1.equals("FooBar")) {
                     throw new AssertionError("Types.asElement() error!");
                 }
                 foundError = true;
--- a/test/tools/javac/processing/model/element/TestMissingElement/TestMissingElement.java	Fri Mar 11 15:39:51 2011 -0800
+++ b/test/tools/javac/processing/model/element/TestMissingElement/TestMissingElement.java	Mon Mar 14 11:33:33 2011 -0700
@@ -24,7 +24,7 @@
 
 /*
  * @test
- * @bug 6639645
+ * @bug 6639645 7026414
  * @summary Modeling type implementing missing interfaces
  * @library ../../../../lib
  * @build JavacTestingAbstractProcessor TestMissingElement
@@ -112,6 +112,7 @@
 
             @Override
             public String visitDeclared(DeclaredType t, Void ignore) {
+                checkEqual(t.asElement(), types.asElement(t));
                 String s = asString(t.asElement());
                 List<? extends TypeMirror> args = t.getTypeArguments();
                 if (!args.isEmpty())
@@ -179,6 +180,13 @@
         return (e != null && e.getKind() == ElementKind.PACKAGE
                 && ((PackageElement) e).isUnnamed());
     }
+
+    void checkEqual(Element e1, Element e2) {
+        if (e1 != e2) {
+            throw new AssertionError("elements not equal as expected: "
+                + e1 + ", " + e2);
+        }
+    }
 }