public static TypeName getTypeName(final Element element, final boolean wrap) { final TypeMirror typeMirror = getTypeMirror(element); final TypeKind kind = typeMirror.getKind(); if (kind == TypeKind.ERROR) { final ProcessorContext context = ProcessorContextHolder.getContext(); final Collection<ProcessorSourceContext> sourceContexts = context.getSourceContexts(); final String typeName = String.valueOf(typeMirror); final TypeElement originElement = ProcessorSourceContext.guessOriginElement(sourceContexts, typeName); if (originElement != null) { final String packageName = ProcessorUtils.packageName(originElement); return ClassName.get(packageName, typeName); } return ClassName.bestGuess(typeName); } return TypeName.get(wrap ? ProcessorUtils.getWrappedType(typeMirror).asType() : typeMirror); }