public boolean isTopLevel(TypeElement element) { return element.getNestingKind() == NestingKind.TOP_LEVEL; }
@Override public NestingKind getNestingKind() { return delegate.getNestingKind(); }
private boolean isInnerClass(Element element) { TypeElement typeElement = (TypeElement) element; return typeElement.getNestingKind().isNested(); } }
@Override default NestingKind getNestingKind() { return getDelegate().getNestingKind(); }
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(); } }
if (enclosingElement.getNestingKind().isNested()) { if (!enclosingElement.getModifiers().contains(STATIC)) { errorLogger.logError(
/** * @return true, if is top level */ @Value.Derived @Value.Auxiliary public boolean isTopLevel() { return element().getNestingKind() == NestingKind.TOP_LEVEL; }
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);
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());
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()); }
validator.error("Invalid class identifier " + entity.name(), Entity.class); if (element().getNestingKind() == NestingKind.ANONYMOUS) { validator.error("Entity annotation cannot be applied to anonymous class");
Element enclosingElement = annotatedElement.getEnclosingElement(); if (typeElement.getNestingKind() == NestingKind.MEMBER && processHolder.getGeneratedClassHolder(enclosingElement) == null) { if (validatedElements.contains(enclosingElement)) { isElementRemaining = true;
/** * 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); } }
@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()); }
@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()); }
@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()); }
@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()); }
@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()); }
@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()); }
@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()); }