Returns the {@link TypeElement} corresponding to {@code type}, if there is one.
328118
public static Optional<TypeElement> maybeAsTypeElement(TypeMirror type) {
    Optional<DeclaredType> declaredType = maybeDeclared(type);
    if (declaredType.isPresent()) {
      return maybeType(declaredType.get().asElement());
    } else {
      return Optional.empty();
    }
  }
786393
public static String getClassName(TypeElement typeElement) {
        Name qualifiedName = typeElement.getQualifiedName();
        NestingKind nestingKind;
        try {
            nestingKind = typeElement.getNestingKind();
            if (nestingKind == NestingKind.MEMBER) {
                TypeElement enclosingElement = typeElement;
                StringBuilder builder = new StringBuilder();
                while (nestingKind == NestingKind.MEMBER) {
                    builder.insert(0, '$').insert(1, enclosingElement.getSimpleName());
                    Element enclosing = enclosingElement.getEnclosingElement();

                    if (enclosing instanceof TypeElement) {
                        enclosingElement = (TypeElement) enclosing;
                        nestingKind = enclosingElement.getNestingKind();
                    } else {
                        break;
                    }
                }
                Name enclosingName = enclosingElement.getQualifiedName();
                return enclosingName.toString() + builder;
            } else {
                return qualifiedName.toString();
            }
        } catch (RuntimeException e) {
            return qualifiedName.toString();
        }
    }
631219
@Nullable final TypeElement classElementFor(Element element) {
        while (element != null && !(JavaModelUtils.isClassOrInterface(element) || JavaModelUtils.isEnum(element))) {
            element = element.getEnclosingElement();
        }
        if (element instanceof  TypeElement) {
            return (TypeElement) element;
        }
        return null;
    }
815597
public static <T> TypeChecker<Queue<? extends T>> tQueue(Class<? extends T> elementType) {
        return tQueue(tSimple(elementType));
    }
882748
private static List<TypeElement> fetchAllNestedTypes(MessageElement type) {
        List<TypeElement> ret = new ArrayList<TypeElement>();

        List<TypeElement> nestedTypes = type.nestedElements();
        ret.addAll(nestedTypes);
        for (TypeElement t : nestedTypes) {
            if (t instanceof MessageElement) {
                List<TypeElement> subNestedTypes = fetchAllNestedTypes((MessageElement) t);
                ret.addAll(subNestedTypes);
            }
        }
        return ret;
    }
1295078
@Requires("element != null")
  @Ensures("result != null")
  TypeName getGenericTypeName(TypeParameterElement element) {
    String name = element.getSimpleName().toString();
    List<? extends TypeMirror> bounds = element.getBounds();
    if (bounds.isEmpty()
        || (bounds.size() == 1
            && bounds.get(0).toString().equals("java.lang.Object"))) {
      return new TypeName(name);
    }

    StringBuilder buffer = new StringBuilder();
    buffer.append(name);
    buffer.append(" extends ");

    Iterator<? extends TypeMirror> iter = bounds.iterator();
    for (;;) {
      buffer.append(iter.next().toString());
      if (!iter.hasNext()) {
        break;
      }
      buffer.append(" & ");
    }

    return new TypeName(buffer.toString());
  }
353999
@Nullable
    Object resolveTypeReference(Element element) {
        if (element instanceof TypeElement) {
            TypeElement typeElement = (TypeElement) element;
            return resolveTypeReferenceForTypeElement(typeElement);
        }
        return null;
    }
250558
private SortedSet<TypeElement> get(Map<TypeElement, SortedSet<TypeElement>> map, TypeElement typeElement) {
        return map.computeIfAbsent(typeElement, t ->  new TreeSet<>(comparator));
    }
802540
public static String getElementAsString(JDeclaration type) {
		StringBuilder builder = new StringBuilder();
		JFormatter jFormatter = new JFormatter(new StringBuilderWriter(builder));
		type.declare(jFormatter);
		return builder.toString();
	}
1067246
def getElementsByType(self, type):
        
        foundElements=[]
        for element in self.getAllElementsOfHirarchy():
            if isinstance(element, type):
                foundElements.append(element)                
                
        return foundElements
1088552
private static JSType getTypeBeforeCast(Node node) {
    JSType typeBeforeCast = node.getJSTypeBeforeCast();
    // might still return null if node.getJSType() is null (i.e. typechecking hasn't run)
    return typeBeforeCast != null ? typeBeforeCast : node.getJSType();
  }
1004457
public static Set<TypeElement>
            typesIn(Set<? extends Element> elements) {
        return setFilter(elements, TYPE_KINDS, TypeElement.class);
    }
1071591
public Type getType() {
        if (coordinates[0].length==1) return Type.POINT;
        else if (coordinates[0].length>2) return Type.POLYGON;
        else { //coordinates[0].length==2
            if (Float.isNaN(coordinates[0][1])) return Type.CIRCLE;
            else return Type.BOX;
        }
    }
680899
public static boolean isJavaConstantType(TypeMirror type)
    {
        switch (type.getKind())
        {
            case INT:
            case LONG:
            case FLOAT:
            case DOUBLE:
                return true;
            case DECLARED:
                DeclaredType dt = (DeclaredType) type;
                TypeElement te = (TypeElement) dt.asElement();
                return "java.lang.String".contentEquals(te.getQualifiedName());
            default:
                return false;
        }
    }
256
TypeElement superClassFor(TypeElement element) {
        TypeMirror superclass = element.getSuperclass();
        if (superclass.getKind() == TypeKind.NONE) {
            return null;
        }
        DeclaredType kind = (DeclaredType) superclass;
        return (TypeElement) kind.asElement();
    }
830784
private static TypeElement getEnclosingType(Element element) {
    return element.accept(new SimpleElementVisitor6<TypeElement, Void>() {
      @Override protected TypeElement defaultAction(Element e, Void p) {
        return e.getEnclosingElement().accept(this, p);
      }

      @Override public TypeElement visitType(TypeElement e, Void p) {
        return e;
      }

      @Override public TypeElement visitPackage(PackageElement e, Void p) {
        throw new IllegalArgumentException();
      }
    }, null);
  }
251165
public static <T extends TypeDefinition> ElementMatcher.Junction<T> is(Type type) {
        return is(TypeDefinition.Sort.describe(type));
    }