langtools/src/share/classes/com/sun/tools/javac/util/RichDiagnosticFormatter.java
changeset 3540 dceac8629a56
parent 3380 a6c2bcab0fec
child 3541 46fcb9a809a6
--- a/langtools/src/share/classes/com/sun/tools/javac/util/RichDiagnosticFormatter.java	Thu Jul 30 10:29:53 2009 +0100
+++ b/langtools/src/share/classes/com/sun/tools/javac/util/RichDiagnosticFormatter.java	Thu Jul 30 10:30:10 2009 +0100
@@ -208,6 +208,32 @@
         }
         return clauses.reverse();
     }
+
+    private int indexOf(Type type, WhereClauseKind kind) {
+        int index = 1;
+        for (Type t : whereClauses.get(kind).keySet()) {
+            if (t.tsym == type.tsym) {
+                return index;
+            }
+            if (kind != WhereClauseKind.TYPEVAR ||
+                    t.toString().equals(type.toString())) {
+                index++;
+            }
+        }
+        return -1;
+    }
+
+    private boolean unique(TypeVar typevar) {
+        int found = 0;
+        for (Type t : whereClauses.get(WhereClauseKind.TYPEVAR).keySet()) {
+            if (t.toString().equals(typevar.toString())) {
+                found++;
+            }
+        }
+        if (found < 1)
+            throw new AssertionError("Missing type variable in where clause " + typevar);
+        return found == 1;
+    }
     //where
     /**
      * This enum defines all posssible kinds of where clauses that can be
@@ -366,33 +392,6 @@
             }
         }
 
-        private int indexOf(Type type, WhereClauseKind kind) {
-            int index = 0;
-            boolean found = false;
-            for (Type t : whereClauses.get(kind).keySet()) {
-                if (t == type) {
-                    found = true;
-                    break;
-                }
-                index++;
-            }
-            if (!found)
-                throw new AssertionError("Missing symbol in where clause " + type);
-            return index + 1;
-        }
-
-        private boolean unique(TypeVar typevar) {
-            int found = 0;
-            for (Type t : whereClauses.get(WhereClauseKind.TYPEVAR).keySet()) {
-                if (t.toString().equals(typevar.toString())) {
-                    found++;
-                }
-            }
-            if (found < 1)
-                throw new AssertionError("Missing type variable in where clause " + typevar);
-            return found == 1;
-        }
-
         @Override
         protected String printMethodArgs(List<Type> args, boolean varArgs, Locale locale) {
             return super.printMethodArgs(args, varArgs, locale);
@@ -492,7 +491,7 @@
 
         @Override
         public Void visitCapturedType(CapturedType t, Void ignored) {
-            if (!whereClauses.get(WhereClauseKind.CAPTURED).containsKey(t)) {
+            if (indexOf(t, WhereClauseKind.CAPTURED) == -1) {
                 String suffix = t.lower == syms.botType ? ".1" : "";
                 JCDiagnostic d = diags.fragment("where.captured"+ suffix, t, t.bound, t.lower, t.wildcard);
                 whereClauses.get(WhereClauseKind.CAPTURED).put(t, d);
@@ -506,7 +505,7 @@
         @Override
         public Void visitClassType(ClassType t, Void ignored) {
             if (t.isCompound()) {
-                if (!whereClauses.get(WhereClauseKind.INTERSECTION).containsKey(t)) {
+                if (indexOf(t, WhereClauseKind.INTERSECTION) == -1) {
                     Type supertype = types.supertype(t);
                     List<Type> interfaces = types.interfaces(t);
                     JCDiagnostic d = diags.fragment("where.intersection", t, interfaces.prepend(supertype));
@@ -524,7 +523,7 @@
 
         @Override
         public Void visitTypeVar(TypeVar t, Void ignored) {
-            if (!whereClauses.get(WhereClauseKind.TYPEVAR).containsKey(t)) {
+            if (indexOf(t, WhereClauseKind.TYPEVAR) == -1) {
                 Type bound = t.bound;
                 while ((bound instanceof ErrorType))
                     bound = ((ErrorType)bound).getOriginalType();