All Downloads are FREE. Search and download functionalities are using the official Maven repository.

br.com.objectos.flat.FlatFileExceptionArtifact Maven / Gradle / Ivy

The newest version!
/*
 * Copyright 2015 Objectos, Fábrica de Software LTDA.
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */
package br.com.objectos.flat;

import javax.lang.model.element.Modifier;

import br.com.objectos.code.Artifact;

import com.squareup.javapoet.AnnotationSpec;
import com.squareup.javapoet.TypeSpec;

/**
 * @author [email protected] (Marcio Endo)
 */
class FlatFileExceptionArtifact extends AbstractHasFlatFile {

  private final FlatFileExceptionConstructor constructor;
  private final FlatFileExceptionField field;
  private final FlatFileExceptionMethod method;
  private final FlatFileExceptionStaticFactory staticFactory;

  private FlatFileExceptionArtifact(FlatFilePojo pojo) {
    super(pojo);
    constructor = new FlatFileExceptionConstructor(pojo);
    field = new FlatFileExceptionField(pojo);
    method = new FlatFileExceptionMethod(pojo);
    staticFactory = new FlatFileExceptionStaticFactory(pojo);
  }

  public static FlatFileExceptionArtifact of(FlatFilePojo pojo) {
    return new FlatFileExceptionArtifact(pojo);
  }

  public Artifact execute() {
    return toArtifact(get());
  }

  private TypeSpec get() {
    TypeSpec.Builder type = TypeSpec.classBuilder(parseExceptionClassName().simpleName())
        .addAnnotation(annotationSpec(FlatFileExceptionArtifactAction.class))
        .addAnnotation(suppressWarningsSerial())
        .addModifiers(Modifier.PUBLIC, Modifier.FINAL)
        .superclass(ParseException.class);

    field.addTo(type);
    constructor.addTo(type);
    staticFactory.addTo(type);
    method.addTo(type);

    return type.build();
  }

  private AnnotationSpec suppressWarningsSerial() {
    return AnnotationSpec.builder(SuppressWarnings.class)
        .addMember("value", "$S", "serial")
        .build();
  }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy