protected Class<?> lookupType(String name, int dim, Node node) {
            StringBuffer fb = new StringBuffer(name);
            // strip array descriptors from class names, we know its an array from the type node.
            if (name != null && !name.isEmpty() && name.charAt(0) == '[') {
                fb.deleteCharAt(name.lastIndexOf('[') + 1);
                int i = 0;
                while ((i = fb.indexOf("[")) != -1)
                    fb.deleteCharAt(i);
                if ((i = fb.indexOf(";")) != -1)
                    fb.deleteCharAt(i);
            }
            String checkName = fb.toString();
            String fixedName = checkName;
            String errorMsg = null;

            boolean resolved = false;
            Class<?> resolvedClass = null;
            String resolvedPackage = mImports[0];
            for (int i=-1; i<mImports.length; i++) {
                if (i >= 0) {
                    checkName = mImports[i] + '.' + fixedName;
                }

                try {
                    Class<?> clazz = null;
                    if (checkName.equals("boolean"))
                        clazz = Boolean.TYPE;
                    else if (checkName.equals("int"))
                        clazz = Integer.TYPE;
                    else if (checkName.equals("double"))
                        clazz = Double.TYPE;
                    else if (checkName.equals("long"))
                        clazz = Long.TYPE;
                    else if (checkName.equals("short"))
                        clazz = Short.TYPE;
                    else if (checkName.equals("float"))
                        clazz = Float.TYPE;
                    else if (checkName.equals("byte"))
                        clazz = Byte.TYPE;
                    else
                        clazz = loadClass(checkName);
                    checkAccess(clazz, node);

                    // Found class, check if should be array.
                    if (dim > 0) {
                        clazz =
                            Array.newInstance(clazz, new int[dim]).getClass();
                    }

                    errorMsg = null;
                    if (! resolved) {
                        if (! mHasImports) {
                            return clazz;
                        }

                        resolved = true;
                        resolvedClass = clazz;
                        if (i > 0) {
                            resolvedPackage = mImports[i];
                        }
                        continue;
                    }
                    else {
                        if (i >= 0) {
                            error("typename.package.conflict", name,
                                  resolvedPackage, mImports[i], node);
                        }
                        return clazz;
                    }
                }
                catch (ClassNotFoundException e) {
                    if (errorMsg == null) {
                        errorMsg = mFormatter.format("typename.unknown", name);
                    }
                }
                catch (RuntimeException e) {
                    error(e.toString(), node);
                    return null;
                }
                catch (LinkageError e) {
                    error(e.toString(), node);
                    return null;
                }
            }

            // Fall through to here only if class wasn't found.
            if (!resolved && errorMsg != null && node != null) {
                error(errorMsg, node);
            }

            // return resolved if found
            return resolvedClass;
        }