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

manifold.preprocessor.definitions.JavacDefinitions Maven / Gradle / Ivy

The newest version!
/*
 * Copyright (c) 2019 - Manifold Systems LLC
 *
 * 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 manifold.preprocessor.definitions;

import com.sun.tools.javac.processing.JavacProcessingEnvironment;
import manifold.internal.javac.JavacPlugin;
import manifold.util.concurrent.LocklessLazyVar;

import java.util.HashMap;
import java.util.Map;

public class JavacDefinitions
{
  private static LocklessLazyVar INSTANCE =
    LocklessLazyVar.make( () -> new JavacDefinitions() );

  private final Map _env;

  static JavacDefinitions instance()
  {
    return INSTANCE.get();
  }

  public JavacDefinitions()
  {
    Map map = new HashMap<>();
    addJavacEnvironment( map );
    _env = map;
  }

  public Map getEnv()
  {
    return _env;
  }

  protected void addJavacEnvironment( Map map )
  {
    if( JavacPlugin.instance() == null )
    {
      return;
    }

    JavacProcessingEnvironment jpe = JavacProcessingEnvironment.instance( JavacPlugin.instance().getContext() );
    addAnnotationOptions( map, jpe );
  }

  /**
   * These are the {@code -Akey[=value]} options on the javac command line, much like {@code -D}, but for the javac
   * environment, not the JVM. Intended for use with annotations, but also great for a preprocessor.
   * See Standard Options.
   */
  protected void addAnnotationOptions( Map map, JavacProcessingEnvironment jpe )
  {
    Map options = jpe.getOptions();
    if( options != null )
    {
      map.putAll( options );
    }
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy