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

br.com.objectos.css.WriteCssProcessor Maven / Gradle / Ivy

/*
 * Copyright 2016 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.css;

import java.util.Map;

import javax.annotation.processing.Processor;

import br.com.objectos.code.AbstractAnnotationProcessor;
import br.com.objectos.code.Artifact;
import br.com.objectos.code.Configuration;
import br.com.objectos.code.ProcessingEnvironmentWrapper;
import br.com.objectos.code.ProcessorListener;
import br.com.objectos.code.TypeInfo;
import br.com.objectos.code.tools.ClassPath;
import br.com.objectos.code.tools.Methods;
import br.com.objectos.core.lang.Strings;
import br.com.objectos.css.internal.WriteCss;
import br.com.objectos.css.io.CssWritable;
import br.com.objectos.metainf.Services;

/**
 * @author [email protected] (Marcio Endo)
 */
@Services(Processor.class)
public class WriteCssProcessor extends AbstractAnnotationProcessor implements ProcessorListener {

  private ClassPath classPath;

  @Override
  public void onInit(ProcessingEnvironmentWrapper processingEnv) {
    Map optionMap = this.processingEnv.getOptions();
    String sourcePath = optionMap.get("sourcePath");
    classPath = ClassPath.builder()
        .addJarOf(getClass())
        .addJarOf(RuleSet.class)
        .addJarOf(WriteCss.class)
        .addJarOf(CssWritable.class)
        .addPath(Strings.nullToEmpty(sourcePath))
        .build();
  }

  @Override
  protected Configuration configuration() {
    return Configuration.builder()
        .addAnnotationType(WriteCss.class)
        .addTypeInfoArtifactGenerator(this::generate)
        .listener(this)
        .build();
  }

  private Artifact generate(TypeInfo typeInfo) {
    return Artifact.peerResource(typeInfo, "css")
        .contents(classPath.processorCompiler(processingEnv)
            .compile(typeInfo)
            .methodInfo("get")
            .invoke()
            .invoke(Methods.toStringMethod())
            .returnValueAs(String.class))
        .build();
  }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy