1 /* 2 * Copyright (C) 2018 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License 15 */ 16 17 package com.android.dialer.rootcomponentgenerator; 18 19 import com.squareup.javapoet.JavaFile; 20 import com.squareup.javapoet.TypeSpec; 21 import java.io.IOException; 22 import javax.annotation.processing.ProcessingEnvironment; 23 24 /** 25 * Contains a basic method writing java file to a curtain package. ProcessingEnvironment is needed. 26 */ 27 public abstract class RootComponentUtils { 28 /** 29 * The place where the generator puts metadata files storing reference for {@link 30 * RootComponentGeneratingStep}. 31 */ 32 static final String METADATA_PACKAGE_NAME = "com.android.dialer.rootcomponentgenerator.metadata"; 33 34 static final String GENERATED_COMPONENT_PREFIX = "Gen"; 35 writeJavaFile( ProcessingEnvironment processingEnv, String packageName, TypeSpec typeSpec)36 static void writeJavaFile( 37 ProcessingEnvironment processingEnv, String packageName, TypeSpec typeSpec) { 38 try { 39 JavaFile.builder(packageName, typeSpec) 40 .skipJavaLangImports(true) 41 .build() 42 .writeTo(processingEnv.getFiler()); 43 } catch (IOException e) { 44 System.out.println(e); 45 throw new RuntimeException(e); 46 } 47 } 48 } 49