javax.lang.model.element.TypeElement.getKind()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(9.2k)|赞(0)|评价(0)|浏览(122)

本文整理了Java中javax.lang.model.element.TypeElement.getKind()方法的一些代码示例,展示了TypeElement.getKind()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。TypeElement.getKind()方法的具体详情如下:
包路径:javax.lang.model.element.TypeElement
类名称:TypeElement
方法名:getKind

TypeElement.getKind介绍

暂无

代码示例

代码示例来源:origin: immutables/immutables

private boolean hasEnumContainedElementType() {
 return containedTypeElement != null
   && containedTypeElement.getKind() == ElementKind.ENUM;
}

代码示例来源:origin: facebook/litho

private void validateElementIsInterface(TypeElement element) {
 if (element.getKind() != ElementKind.INTERFACE) {
  throw new ComponentsProcessingException(
    element,
    String.format(
      "Specs annotated with @TestSpecs must be interfaces and cannot be of kind %s.",
      element.getKind()));
 }
}

代码示例来源:origin: androidannotations/androidannotations

private boolean isAbstractClass(Element annotatedElement) {
  if (annotatedElement instanceof TypeElement) {
    TypeElement typeElement = (TypeElement) annotatedElement;
    return typeElement.getKind() == ElementKind.CLASS && typeElement.getModifiers().contains(Modifier.ABSTRACT);
  } else {
    return false;
  }
}

代码示例来源:origin: androidannotations/androidannotations

public boolean isInterface(TypeElement element) {
  return element.getKind().isInterface();
}

代码示例来源:origin: querydsl/querydsl

@Override
public Type visitDeclared(DeclaredType declaredType, Boolean p) {
  if (declaredType.asElement() instanceof TypeElement) {
    TypeElement typeElement = (TypeElement) declaredType.asElement();
    switch (typeElement.getKind()) {
      case ENUM:      return createEnumType(declaredType, typeElement, p);
      case ANNOTATION_TYPE:
      case CLASS:     return createClassType(declaredType, typeElement, p);
      case INTERFACE: return createInterfaceType(declaredType, typeElement, p);
      default: throw new IllegalArgumentException("Illegal type " + typeElement);
    }
  } else {
    throw new IllegalArgumentException("Unsupported element type " + declaredType.asElement());
  }
}

代码示例来源:origin: facebook/litho

static boolean isKotlinSingleton(TypeElement element) {
 return element.getKind() == ElementKind.CLASS
   && element
     .getEnclosedElements()
     .stream()
     .anyMatch(
       e -> {
        final CharSequence instanceFieldName = "INSTANCE";
        return e.getSimpleName().contentEquals(instanceFieldName)
          && e.asType().toString().equals(((Symbol.ClassSymbol) element).className())
          && e.getModifiers()
            .containsAll(
              ImmutableList.of(Modifier.PUBLIC, Modifier.STATIC, Modifier.FINAL));
       });
}

代码示例来源:origin: JakeWharton/butterknife

private boolean isInaccessibleViaGeneratedCode(Class<? extends Annotation> annotationClass,
  String targetThing, Element element) {
 boolean hasError = false;
 TypeElement enclosingElement = (TypeElement) element.getEnclosingElement();
 // Verify field or method modifiers.
 Set<Modifier> modifiers = element.getModifiers();
 if (modifiers.contains(PRIVATE) || modifiers.contains(STATIC)) {
  error(element, "@%s %s must not be private or static. (%s.%s)",
    annotationClass.getSimpleName(), targetThing, enclosingElement.getQualifiedName(),
    element.getSimpleName());
  hasError = true;
 }
 // Verify containing type.
 if (enclosingElement.getKind() != CLASS) {
  error(enclosingElement, "@%s %s may only be contained in classes. (%s.%s)",
    annotationClass.getSimpleName(), targetThing, enclosingElement.getQualifiedName(),
    element.getSimpleName());
  hasError = true;
 }
 // Verify containing class visibility is not private.
 if (enclosingElement.getModifiers().contains(PRIVATE)) {
  error(enclosingElement, "@%s %s may not be contained in private classes. (%s.%s)",
    annotationClass.getSimpleName(), targetThing, enclosingElement.getQualifiedName(),
    element.getSimpleName());
  hasError = true;
 }
 return hasError;
}

代码示例来源:origin: querydsl/querydsl

@Override
public TypeElement visitDeclared(DeclaredType t, Void p) {
  if (t.asElement() instanceof TypeElement) {
    TypeElement typeElement = (TypeElement) t.asElement();
    switch (typeElement.getKind()) {
      case ENUM:      return skipEnum ? null : typeElement;
      case CLASS:     return typeElement;
      case INTERFACE: return visitInterface(t);
      default: throw new IllegalArgumentException("Illegal type: " + typeElement);
    }
  } else {
    return null;
  }
}

代码示例来源:origin: square/dagger

@Override public Binding<?> getAtInjectBinding(
  String key, String className, ClassLoader classLoader, boolean mustHaveInjections) {
 TypeElement type = resolveType(processingEnv.getElementUtils(), className);
 if (type == null) {
  // We've encountered a type that the compiler can't introspect. If this
  // causes problems in practice (due to incremental compiles, etc.) we
  // should return a new unresolved binding and warn about the possibility
  // of runtime failures.
  return null;
 }
 if (type.getKind() == ElementKind.INTERFACE) {
  return null;
 }
 return GraphAnalysisInjectBinding.create(type, mustHaveInjections);
}

代码示例来源:origin: north2016/T-MVP

public static boolean isValidClass(Messager messager, TypeElement element) {
  if (element.getKind() != ElementKind.CLASS) {
    return false;
  }
  if (!isPublic(element)) {
    String message = String.format("Classes annotated with %s must be public.", ANNOTATION);
    messager.printMessage(Diagnostic.Kind.ERROR, message, element);
    return false;
  }
  if (isAbstract(element)) {
    String message = String.format("Classes annotated with %s must not be abstract.", ANNOTATION);
    messager.printMessage(Diagnostic.Kind.ERROR, message, element);
    return false;
  }
  return true;
}

代码示例来源:origin: yahoo/squidb

@Override
protected boolean hasPropertyGeneratorForField(VariableElement field, DeclaredTypeName fieldType) {
  if (TypeConstants.isConstant(field)) {
    // Looks like a constant, ignore
    return false;
  }
  TypeElement typeElement = (TypeElement) utils.getTypes().asElement(field.asType());
  return typeElement != null && typeElement.getKind() == ElementKind.ENUM;
}

代码示例来源:origin: UCodeUStory/S-MVP

public static boolean isValidClass(Messager messager, TypeElement element) {
  if (element.getKind() != ElementKind.CLASS) {
    return false;
  }
  if (!isPublic(element)) {
    String message = String.format("Classes annotated with %s must be public.", ANNOTATION);
    messager.printMessage(Diagnostic.Kind.ERROR, message, element);
    return false;
  }
  if (isAbstract(element)) {
    String message = String.format("Classes annotated with %s must not be abstract.", ANNOTATION);
    messager.printMessage(Diagnostic.Kind.ERROR, message, element);
    return false;
  }
  return true;
}

代码示例来源:origin: immutables/immutables

public boolean hasEnumFirstTypeParameter() {
 return typeKind().isEnumKeyed()
   && containedTypeElement.getKind() == ElementKind.ENUM;
}

代码示例来源:origin: immutables/immutables

public Collection<TypeElement> getEnumElements() {
 if (isEnumType()) {
  return Collections.singletonList(containedTypeElement);
 }
 if (!isContainerType()) {
  List<TypeElement> elements = Lists.newArrayListWithCapacity(2);
  if (hasEnumContainedElementType()) {
   elements.add(containedTypeElement);
  }
  if (isMapType() && containedSecondaryTypeElement.getKind() == ElementKind.ENUM) {
   elements.add(containedSecondaryTypeElement);
  }
  return elements;
 }
 return Collections.emptyList();
}

代码示例来源:origin: org.jboss.logging/jboss-logging-processor

@Override
public void processTypeElement(final TypeElement annotation, final TypeElement element, final MessageInterface messageInterface) {
  if (generatedFilesPath != null) {
    if (element.getKind().isInterface()) {
      String packageName = processingEnv.getElementUtils().getPackageOf(element).getQualifiedName().toString();
      String relativePath = packageName.replace('.', File.separatorChar);
      String fileName = getPrimaryClassNamePrefix(element) + GENERATED_FILE_EXTENSION;
      this.generateSkeletalTranslationFile(relativePath, fileName, messageInterface);
    }
  }
  // Always generate an Interface.i18n.properties file.
  generateDefaultTranslationFile(messageInterface);
}

代码示例来源:origin: requery/requery

@Override
public String tableName() {
  return annotationOf(Table.class).map(Table::name)
      .orElse( annotationOf(javax.persistence.Table.class)
           .map(javax.persistence.Table::name)
      .orElse( annotationOf(View.class).map(View::name)
      .orElse( element().getKind().isInterface() || isImmutable() ?
        element().getSimpleName().toString() :
        Names.removeClassPrefixes(element().getSimpleName()))));
}

代码示例来源:origin: requery/requery

@Override
public boolean isUnimplementable() {
  boolean extendable = annotationOf(Entity.class).map(Entity::extendable).orElse(true);
  return !extendable || (element().getKind().isClass() &&
    element().getModifiers().contains(Modifier.FINAL));
}

代码示例来源:origin: immutables/immutables

private boolean isExtending(TypeElement element) {
 if (element.getKind() == ElementKind.CLASS) {
  String superclassString = SourceExtraction.getSuperclassString(element);
  String rawSuperclass = SourceTypes.extract(superclassString).getKey();
  // If we are extending yet to be generated builder, we detect it by having the same name
  // as relative name of builder type
  return rawSuperclass.endsWith(typeImplementationBuilder().relativeRaw());
 }
 return false;
}

代码示例来源:origin: immutables/immutables

private void collectInterfacesMirrors(TypeMirror typeMirror, TypevarContext context) {
 if (typeMirror.getKind() != TypeKind.DECLARED) {
  return;
 }
 DeclaredType declaredType = toDeclaredType(typeMirror);
 TypeElement e = toTypeElement(declaredType);
 if (e.getKind().isInterface()) {
  implementedInterfaces.add(e);
  String stringified = stringify(declaredType, context);
  TypevarContext nestedContext = new TypevarContext(e, stringified);
  implementedInterfaceNames.add(stringified);
  for (TypeMirror m : e.getInterfaces()) {
   collectInterfacesMirrors(m, nestedContext);
  }
 }
}

代码示例来源:origin: requery/requery

@Override
public void generate(EntityDescriptor entity, TypeSpec.Builder builder) {
  if (isObservable() && entity.element().getKind().isInterface()) {
    builder.superclass(ClassName.get(BINDING_PACKAGE, "BaseObservable"));
  }
}

相关文章