1 /* 2 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 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 * A copy of the License is located at 7 * 8 * http://aws.amazon.com/apache2.0 9 * 10 * or in the "license" file accompanying this file. This file is distributed 11 * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 * express or implied. See the License for the specific language governing 13 * permissions and limitations under the License. 14 */ 15 16 package software.amazon.awssdk.codegen.poet; 17 18 import com.squareup.javapoet.ClassName; 19 import java.util.Arrays; 20 import java.util.Collections; 21 22 /** 23 * A Poet static import definition to enable inclusion of static imports at code generation time 24 */ 25 public interface StaticImport { 26 27 /** 28 * @return The Poet representation of the class to import (may or may not yet exist) 29 */ className()30 ClassName className(); 31 32 /** 33 * The members to import from the class for example if memberNames() returned List("trim", "isBlank") for 34 * StringUtils.class then the following static imports would be generated: 35 * 36 * import static software.amazon.awssdk.utils.StringUtils.trim; 37 * import static software.amazon.awssdk.utils.StringUtils.isBlank; 38 * 39 * @return The members to import from the class representation 40 */ memberNames()41 Iterable<String> memberNames(); 42 43 /** 44 * A helper implementation to create a {@link StaticImport} from a {@link Class} 45 * @param clz the class to import 46 * @param members the members from that class to import, if none then * is assumed 47 * @return an anonymous implementation of {@link StaticImport} 48 */ staticMethodImport(Class<?> clz, String... members)49 static StaticImport staticMethodImport(Class<?> clz, String... members) { 50 return new StaticImport() { 51 @Override 52 public ClassName className() { 53 return ClassName.get(clz); 54 } 55 56 @Override 57 public Iterable<String> memberNames() { 58 if (members.length > 0) { 59 return Arrays.asList(members); 60 } 61 return Collections.singletonList("*"); 62 } 63 }; 64 } 65 } 66