Search in sources :

Example 1 with Generated

use of javax.annotation.Generated in project bazel by bazelbuild.

the class StrictJavaDepsPlugin method isAnnotationProcessorExempt.

/**
   * Returns true if the compilation unit contains a single top-level class generated by an exempt
   * annotation processor (according to its {@link @Generated} annotation).
   *
   * <p>Annotation processors are expected to never generate more than one top level class, as
   * required by the style guide.
   */
public ProcessorDependencyMode isAnnotationProcessorExempt(JCTree.JCCompilationUnit unit) {
    if (unit.getTypeDecls().size() != 1) {
        return ProcessorDependencyMode.DEFAULT;
    }
    Symbol sym = TreeInfo.symbolFor(getOnlyElement(unit.getTypeDecls()));
    if (sym == null) {
        return ProcessorDependencyMode.DEFAULT;
    }
    Generated generated = sym.getAnnotation(Generated.class);
    if (generated == null) {
        return ProcessorDependencyMode.DEFAULT;
    }
    for (String value : generated.value()) {
        // Relax strict deps for dagger-generated code (b/17979436).
        if (value.startsWith(DAGGER_PROCESSOR_PREFIX)) {
            return ProcessorDependencyMode.EXEMPT_NORECORD;
        }
        if (dependencyModule.getExemptGenerators().contains(value)) {
            return ProcessorDependencyMode.EXEMPT_RECORD;
        }
    }
    return ProcessorDependencyMode.DEFAULT;
}
Also used : Generated(javax.annotation.Generated) ClassSymbol(com.sun.tools.javac.code.Symbol.ClassSymbol) Symbol(com.sun.tools.javac.code.Symbol)

Example 2 with Generated

use of javax.annotation.Generated in project querydsl by querydsl.

the class BeanSerializer method serialize.

@Override
public void serialize(EntityType model, SerializerConfig serializerConfig, CodeWriter writer) throws IOException {
    String simpleName = model.getSimpleName();
    // package
    if (!model.getPackageName().isEmpty()) {
        writer.packageDecl(model.getPackageName());
    }
    // imports
    Set<String> importedClasses = getAnnotationTypes(model);
    for (Type iface : interfaces) {
        importedClasses.add(iface.getFullName());
    }
    importedClasses.add(Generated.class.getName());
    if (model.hasLists()) {
        importedClasses.add(List.class.getName());
    }
    if (model.hasCollections()) {
        importedClasses.add(Collection.class.getName());
    }
    if (model.hasSets()) {
        importedClasses.add(Set.class.getName());
    }
    if (model.hasMaps()) {
        importedClasses.add(Map.class.getName());
    }
    if (addToString && model.hasArrays()) {
        importedClasses.add(Arrays.class.getName());
    }
    writer.importClasses(importedClasses.toArray(new String[importedClasses.size()]));
    // javadoc
    writer.javadoc(simpleName + javadocSuffix);
    // header
    for (Annotation annotation : model.getAnnotations()) {
        writer.annotation(annotation);
    }
    writer.line("@Generated(\"", getClass().getName(), "\")");
    if (!interfaces.isEmpty()) {
        Type superType = null;
        if (printSupertype && model.getSuperType() != null) {
            superType = model.getSuperType().getType();
        }
        Type[] ifaces = interfaces.toArray(new Type[interfaces.size()]);
        writer.beginClass(model, superType, ifaces);
    } else if (printSupertype && model.getSuperType() != null) {
        writer.beginClass(model, model.getSuperType().getType());
    } else {
        writer.beginClass(model);
    }
    bodyStart(model, writer);
    if (addFullConstructor) {
        addFullConstructor(model, writer);
    }
    // fields
    for (Property property : model.getProperties()) {
        if (propertyAnnotations) {
            for (Annotation annotation : property.getAnnotations()) {
                writer.annotation(annotation);
            }
        }
        writer.privateField(property.getType(), property.getEscapedName());
    }
    // accessors
    for (Property property : model.getProperties()) {
        String propertyName = property.getEscapedName();
        // getter
        writer.beginPublicMethod(property.getType(), "get" + BeanUtils.capitalize(propertyName));
        writer.line("return ", propertyName, ";");
        writer.end();
        // setter
        Parameter parameter = new Parameter(propertyName, property.getType());
        writer.beginPublicMethod(Types.VOID, "set" + BeanUtils.capitalize(propertyName), parameter);
        writer.line("this.", propertyName, " = ", propertyName, ";");
        writer.end();
    }
    if (addToString) {
        addToString(model, writer);
    }
    bodyEnd(model, writer);
    writer.end();
}
Also used : Generated(javax.annotation.Generated) Annotation(java.lang.annotation.Annotation)

Aggregations

Generated (javax.annotation.Generated)2 Symbol (com.sun.tools.javac.code.Symbol)1 ClassSymbol (com.sun.tools.javac.code.Symbol.ClassSymbol)1 Annotation (java.lang.annotation.Annotation)1