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

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

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

TypeElement.getNestingKind介绍

[英]Returns the nesting kind of this type element.
[中]返回此类型元素的嵌套类型。

代码示例

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

public boolean isTopLevel(TypeElement element) {
  return element.getNestingKind() == NestingKind.TOP_LEVEL;
}

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

@Override
public NestingKind getNestingKind() {
 return delegate.getNestingKind();
}

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

private boolean isInnerClass(Element element) {
    TypeElement typeElement = (TypeElement) element;
    return typeElement.getNestingKind().isNested();
  }
}

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

@Override
default NestingKind getNestingKind() {
  return getDelegate().getNestingKind();
}

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

public String generatedClassQualifiedNameFromQualifiedName(String qualifiedName) {
  TypeElement type = typeElementFromQualifiedName(qualifiedName);
  if (type.getNestingKind() == NestingKind.MEMBER) {
    String parentGeneratedClass = generatedClassQualifiedNameFromQualifiedName(type.getEnclosingElement().asType().toString());
    return parentGeneratedClass + "." + type.getSimpleName().toString() + classSuffix();
  } else {
    return qualifiedName + classSuffix();
  }
}

代码示例来源:origin: airbnb/epoxy

if (enclosingElement.getNestingKind().isNested()) {
 if (!enclosingElement.getModifiers().contains(STATIC)) {
  errorLogger.logError(

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

/**
 * @return true, if is top level
 */
@Value.Derived
@Value.Auxiliary
public boolean isTopLevel() {
 return element().getNestingKind() == NestingKind.TOP_LEVEL;
}

代码示例来源:origin: org.netbeans.api/org-openide-filesystems

throw new LayerGenerationException(clazz + " is not public", originatingElement, processingEnv, annotation, annotationMethod);
if (((TypeElement) originatingElement).getNestingKind().isNested() && !originatingElement.getModifiers().contains(Modifier.STATIC)) {
  throw new LayerGenerationException(clazz + " is nested but not static", originatingElement, processingEnv, annotation, annotationMethod);

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

Encoding(TypeElement type) {
 this.typeEncoding = type;
 if (type.getKind() != ElementKind.CLASS || type.getNestingKind() != NestingKind.TOP_LEVEL) {
  reporter.withElement(type).error("Encoding type '%s' should be top-level class", type.getSimpleName());

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

protected void setGeneratedClass() throws Exception {
  String annotatedComponentQualifiedName = annotatedElement.getQualifiedName().toString();
  annotatedClass = getCodeModel().directClass(annotatedElement.asType().toString());
  if (annotatedElement.getNestingKind().isNested()) {
    Element enclosingElement = annotatedElement.getEnclosingElement();
    GeneratedClassHolder enclosingHolder = environment.getGeneratedClassHolder(enclosingElement);
    String generatedBeanSimpleName = annotatedElement.getSimpleName().toString() + classSuffix();
    int modifier = PUBLIC | STATIC;
    if (environment.getOptionBooleanValue(OPTION_GENERATE_FINAL_CLASSES)) {
      modifier |= FINAL;
    }
    generatedClass = enclosingHolder.getGeneratedClass()._class(modifier, generatedBeanSimpleName, EClassType.CLASS);
  } else {
    String generatedClassQualifiedName = annotatedComponentQualifiedName + classSuffix();
    int modifier = PUBLIC;
    if (environment.getOptionBooleanValue(OPTION_GENERATE_FINAL_CLASSES)) {
      modifier |= FINAL;
    }
    generatedClass = getCodeModel()._class(modifier, generatedClassQualifiedName, EClassType.CLASS);
  }
  codeModelHelper.generify(generatedClass, annotatedElement);
  setExtends();
  codeModelHelper.copyNonAAAnnotations(generatedClass, annotatedElement.getAnnotationMirrors());
}

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

validator.error("Invalid class identifier " + entity.name(), Entity.class);
if (element().getNestingKind() == NestingKind.ANONYMOUS) {
  validator.error("Entity annotation cannot be applied to anonymous class");

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

Element enclosingElement = annotatedElement.getEnclosingElement();
if (typeElement.getNestingKind() == NestingKind.MEMBER && processHolder.getGeneratedClassHolder(enclosingElement) == null) {
  if (validatedElements.contains(enclosingElement)) {
    isElementRemaining = true;

代码示例来源:origin: inferred/FreeBuilder

/**
 * Returns a {@link QualifiedName} for {@code type}.
 */
public static QualifiedName of(TypeElement type) {
 switch (type.getNestingKind()) {
  case TOP_LEVEL:
   PackageElement pkg = (PackageElement) type.getEnclosingElement();
   return QualifiedName.of(pkg.getQualifiedName().toString(), type.getSimpleName().toString());
  case MEMBER:
   List<String> reversedNames = new ArrayList<String>();
   reversedNames.add(type.getSimpleName().toString());
   Element parent = type.getEnclosingElement();
   while (parent.getKind() != ElementKind.PACKAGE) {
    reversedNames.add(parent.getSimpleName().toString());
    parent = parent.getEnclosingElement();
   }
   return new QualifiedName(
     ((PackageElement) parent).getQualifiedName().toString(),
     ImmutableList.copyOf(Lists.reverse(reversedNames)));
  default:
   throw new IllegalArgumentException("Cannot determine qualified name of " + type);
 }
}

代码示例来源:origin: inferred/FreeBuilder

@Test
public void newType() {
 TypeElement type = model.newType(
   "package foo.bar;",
   "public class MyType {",
   "  public void doNothing() { }",
   "}");
 assertEquals(ElementKind.CLASS, type.getKind());
 assertEquals(NestingKind.TOP_LEVEL, type.getNestingKind());
 assertEquals("MyType", type.getSimpleName().toString());
 assertEquals("foo.bar.MyType", type.toString());
 assertEquals("doNothing",
   getOnlyElement(methodsIn(type.getEnclosedElements())).getSimpleName().toString());
}

代码示例来源:origin: inferred/FreeBuilder

@Test
public void newType_class() {
 TypeElement type = model.newType(
   "package foo.bar;",
   "public class MyType {",
   "  public void doNothing() { }",
   "}");
 assertEquals(ElementKind.CLASS, type.getKind());
 assertEquals(NestingKind.TOP_LEVEL, type.getNestingKind());
 assertEquals("MyType", type.getSimpleName().toString());
 assertEquals("foo.bar.MyType", type.toString());
 assertEquals("doNothing",
   getOnlyElement(methodsIn(type.getEnclosedElements())).getSimpleName().toString());
}

代码示例来源:origin: inferred/FreeBuilder

@Test
public void newType_interface() {
 TypeElement type = model.newType(
   "package foo.bar;",
   "public interface MyType {",
   "  public void doNothing();",
   "}");
 assertEquals(ElementKind.INTERFACE, type.getKind());
 assertEquals(NestingKind.TOP_LEVEL, type.getNestingKind());
 assertEquals("MyType", type.getSimpleName().toString());
 assertEquals("foo.bar.MyType", type.toString());
 assertEquals("doNothing",
   getOnlyElement(methodsIn(type.getEnclosedElements())).getSimpleName().toString());
}

代码示例来源:origin: inferred/FreeBuilder

@Test
public void newType_annotation() {
 TypeElement type = model.newType(
   "package foo.bar;",
   "public @interface MyType {",
   "  String param();",
   "}");
 assertEquals(ElementKind.ANNOTATION_TYPE, type.getKind());
 assertEquals(NestingKind.TOP_LEVEL, type.getNestingKind());
 assertEquals("MyType", type.getSimpleName().toString());
 assertEquals("foo.bar.MyType", type.toString());
 assertEquals("param",
   getOnlyElement(methodsIn(type.getEnclosedElements())).getSimpleName().toString());
}

代码示例来源:origin: inferred/FreeBuilder

@Test
public void newElementWithMarker() {
 TypeElement type = (TypeElement) model.newElementWithMarker(
   "package foo.bar;",
   "public class MyType {",
   "  ---> public class MyInnerType {",
   "    public void doNothing() { }",
   "  }",
   "}");
 assertEquals(ElementKind.CLASS, type.getKind());
 assertEquals(NestingKind.MEMBER, type.getNestingKind());
 assertEquals("MyInnerType", type.getSimpleName().toString());
 assertEquals("foo.bar.MyType.MyInnerType", type.toString());
 assertEquals("doNothing",
   getOnlyElement(methodsIn(type.getEnclosedElements())).getSimpleName().toString());
}

代码示例来源:origin: inferred/FreeBuilder

@Test
public void newElementAnnotatedWith() {
 TypeElement type = (TypeElement) model.newElementAnnotatedWith(
   Deprecated.class,
   "package foo.bar;",
   "public class MyType {",
   "  @Deprecated public class MyInnerType {",
   "    public void doNothing() { }",
   "  }",
   "}");
 assertEquals(ElementKind.CLASS, type.getKind());
 assertEquals(NestingKind.MEMBER, type.getNestingKind());
 assertEquals("MyInnerType", type.getSimpleName().toString());
 assertEquals("foo.bar.MyType.MyInnerType", type.toString());
 assertEquals("doNothing",
   getOnlyElement(methodsIn(type.getEnclosedElements())).getSimpleName().toString());
}

代码示例来源:origin: inferred/FreeBuilder

@Test
public void newType_enum() {
 TypeElement type = model.newType(
   "package foo.bar;",
   "public enum MyType { A, B; }");
 assertEquals(ElementKind.ENUM, type.getKind());
 assertEquals(NestingKind.TOP_LEVEL, type.getNestingKind());
 assertEquals("MyType", type.getSimpleName().toString());
 assertEquals("foo.bar.MyType", type.toString());
}

相关文章