本文整理了Java中com.squareup.javapoet.ClassName.packageName()
方法的一些代码示例,展示了ClassName.packageName()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ClassName.packageName()
方法的具体详情如下:
包路径:com.squareup.javapoet.ClassName
类名称:ClassName
方法名:packageName
[英]The package name of this class, or "" if this is in the default package.
[中]此类的包名称,如果在默认包中,则为“”。
代码示例来源:origin: JakeWharton/butterknife
JavaFile brewJava(int sdk, boolean debuggable) {
TypeSpec bindingConfiguration = createType(sdk, debuggable);
return JavaFile.builder(bindingClassName.packageName(), bindingConfiguration)
.addFileComment("Generated code from Butter Knife. Do not modify!")
.build();
}
代码示例来源:origin: square/dagger
/** Returns a class name to complement {@code type}. */
public static ClassName adapterName(ClassName type, String suffix) {
return ClassName.get(type.packageName(),
Joiner.on('$').join(type.simpleNames()) + suffix);
}
代码示例来源:origin: bluelinelabs/LoganSquare
public static String getInjectedFQCN(ClassName className) {
StringBuilder name = new StringBuilder();
for (String part : className.simpleNames()) {
if (name.length() > 0) {
name.append("$");
}
name.append(part);
}
return className.packageName() + "." + name.toString() + Constants.MAPPER_CLASS_SUFFIX;
}
代码示例来源:origin: square/javapoet
private void importableType(ClassName className) {
if (className.packageName().isEmpty()) {
return;
}
ClassName topLevelClassName = className.topLevelClassName();
String simpleName = topLevelClassName.simpleName();
ClassName replaced = importableTypes.put(simpleName, topLevelClassName);
if (replaced != null) {
importableTypes.put(simpleName, replaced); // On collision, prefer the first inserted.
}
}
代码示例来源:origin: square/wire
private String reflectionName(ClassName className) {
return className.packageName().isEmpty()
? Joiner.on('$').join(className.simpleNames())
: className.packageName() + '.' + Joiner.on('$').join(className.simpleNames());
}
代码示例来源:origin: VictorAlbertos/RxCache
JavaFile from(ProvidersClass providersClass) throws IOException {
List<MethodSpec> methodSpecs = new ArrayList<>();
for (ProvidersClass.Method method : providersClass.methods) {
methodSpecs.add(getActionProvider(providersClass.className, method));
}
TypeSpec typeSpec = classProviders(providersClass.className, methodSpecs);
return JavaFile.builder(providersClass.className.packageName(), typeSpec)
.build();
}
代码示例来源:origin: airbnb/epoxy
return rClasses.get(0).packageName();
String[] rModuleNames = rClass.packageName().split("\\.");
int numNameMatches = 0;
for (int i = 0; i < Math.min(packageNames.length, rModuleNames.length); i++) {
return bestMatch.packageName();
代码示例来源:origin: square/wire
private void writeJavaFile(ClassName javaTypeName, TypeSpec typeSpec, Location location)
throws IOException {
JavaFile.Builder builder = JavaFile.builder(javaTypeName.packageName(), typeSpec)
.addFileComment("$L", "Code generated by Wire protocol buffer compiler, do not edit.");
if (location != null) {
builder.addFileComment("\nSource file: $L", location);
}
JavaFile javaFile = builder.build();
try {
javaFile.writeTo(new File(generatedSourceDirectory));
} catch (IOException e) {
throw new IOException("Failed to write " + javaFile.packageName + "."
+ javaFile.typeSpec.name + " to " + generatedSourceDirectory, e);
}
}
}
代码示例来源:origin: square/wire
private void writeJavaFile(ClassName javaTypeName, TypeSpec typeSpec, Location location,
Stopwatch stopwatch) throws IOException {
JavaFile.Builder builder = JavaFile.builder(javaTypeName.packageName(), typeSpec)
.addFileComment("Code generated by $L, do not edit.", CodegenSample.class.getName());
if (location != null) {
builder.addFileComment("\nSource file: $L", location.path());
}
JavaFile javaFile = builder.build();
try {
javaFile.writeTo(new File(generatedSourceDirectory));
} catch (IOException e) {
throw new IOException("Failed to write " + javaFile.packageName + "."
+ javaFile.typeSpec.name + " to " + generatedSourceDirectory, e);
}
log.info("Generated %s in %s", javaTypeName, stopwatch);
}
代码示例来源:origin: janishar/PlaceHolderView
@Override
public boolean compile(RoundEnvironment roundEnv) {
try {
JavaFile.builder(getRClassBuilder().getClassName().packageName(),
getRClassBuilder().build())
.build()
.writeTo(getFiler());
} catch (IOException e) {
// Allowing to successive rewrite file
return true;
}
return true;
}
代码示例来源:origin: airbnb/epoxy
private void generateHelperClassForController(ControllerClassInfo controllerInfo)
throws IOException {
ParameterizedTypeName parameterizeSuperClass =
ParameterizedTypeName
.get(ClassNames.EPOXY_CONTROLLER_HELPER, controllerInfo.getControllerClassType());
TypeSpec.Builder builder = TypeSpec.classBuilder(controllerInfo.getGeneratedClassName())
.addJavadoc("Generated file. Do not modify!")
.addModifiers(Modifier.PUBLIC)
.superclass(parameterizeSuperClass)
.addField(controllerInfo.getControllerClassType(), "controller", Modifier.FINAL,
Modifier.PRIVATE)
.addMethod(buildConstructor(controllerInfo))
.addMethod(buildResetModelsMethod(controllerInfo));
if (configManager.shouldValidateModelUsage()) {
builder.addFields(buildFieldsToSaveModelsForValidation(controllerInfo))
.addMethod(buildValidateModelsHaveNotChangedMethod(controllerInfo))
.addMethod(buildValidateSameValueMethod())
.addMethod(buildSaveModelsForNextValidationMethod(controllerInfo));
}
JavaFile.builder(controllerInfo.getGeneratedClassName().packageName(), builder.build())
.build()
.writeTo(filer);
}
代码示例来源:origin: square/javapoet
if (Objects.equals(packageName, className.packageName())) {
referencedNames.add(topLevelSimpleName);
return join(".", className.simpleNames());
代码示例来源:origin: square/wire
public String generateCode(String typeName, String profile) throws IOException {
Schema schema = schema();
JavaGenerator javaGenerator = JavaGenerator.get(schema);
if (profile != null) {
javaGenerator = javaGenerator.withProfile(profile(profile));
}
Type type = schema.getType(typeName);
TypeSpec typeSpec = javaGenerator.generateType(type);
ClassName typeName1 = javaGenerator.generatedTypeName(type);
return JavaFile.builder(typeName1.packageName(), typeSpec).build().toString();
}
代码示例来源:origin: square/javapoet
private void emit(CodeWriter codeWriter) throws IOException {
codeWriter.pushPackage(packageName);
if (!fileComment.isEmpty()) {
codeWriter.emitComment(fileComment);
}
if (!packageName.isEmpty()) {
codeWriter.emit("package $L;\n", packageName);
codeWriter.emit("\n");
}
if (!staticImports.isEmpty()) {
for (String signature : staticImports) {
codeWriter.emit("import static $L;\n", signature);
}
codeWriter.emit("\n");
}
int importedTypesCount = 0;
for (ClassName className : new TreeSet<>(codeWriter.importedTypes().values())) {
if (skipJavaLangImports && className.packageName().equals("java.lang")) continue;
codeWriter.emit("import $L;\n", className.withoutAnnotations());
importedTypesCount++;
}
if (importedTypesCount > 0) {
codeWriter.emit("\n");
}
typeSpec.emit(codeWriter, null, Collections.emptySet());
codeWriter.popPackage();
}
代码示例来源:origin: square/dagger
return JavaFile.builder(adapterClassName.packageName(), adapterBuilder.build())
.addFileComment(AdapterJavadocs.GENERATED_BY_DAGGER)
.build();
代码示例来源:origin: facebook/litho
ParameterizedTypeName.get(
ClassName.get(
specModel.getComponentClass().packageName(),
specModel.getComponentClass().simpleName(),
BUILDER),
代码示例来源:origin: facebook/litho
@Before
public void ListUp() {
mDiffTypeSpecWrappingInt =
new TypeSpec.DeclaredTypeSpec(
ClassNames.DIFF,
ClassNames.DIFF.packageName() + "." + ClassNames.DIFF.simpleName(),
() -> new TypeSpec(TypeName.OBJECT),
ImmutableList.of(),
ImmutableList.of(new TypeSpec(TypeName.INT.box())));
}
代码示例来源:origin: airbnb/RxGroups
private void generateClass(ClassToGenerateInfo info) throws IOException {
TypeSpec generatedClass = TypeSpec.classBuilder(info.generatedClassName)
.superclass(BaseObservableResubscriber.class)
.addJavadoc("Generated file. Do not modify!")
.addModifiers(Modifier.PUBLIC)
.addMethod(generateConstructor(info))
.build();
JavaFile.builder(info.generatedClassName.packageName(), generatedClass)
.build()
.writeTo(filer);
}
代码示例来源:origin: stephanenicolas/toothpick
public String brewJava() {
// Interface to implement
ClassName className = ClassName.get(targetClass);
ParameterizedTypeName memberInjectorInterfaceParameterizedTypeName = ParameterizedTypeName.get(ClassName.get(MemberInjector.class), className);
// Build class
TypeSpec.Builder scopeMemberTypeSpec = TypeSpec.classBuilder(getGeneratedSimpleClassName(targetClass) + MEMBER_INJECTOR_SUFFIX)
.addModifiers(Modifier.PUBLIC, Modifier.FINAL)
.addSuperinterface(memberInjectorInterfaceParameterizedTypeName);
emitSuperMemberInjectorFieldIfNeeded(scopeMemberTypeSpec);
emitInjectMethod(scopeMemberTypeSpec, fieldInjectionTargetList, methodInjectionTargetList);
JavaFile javaFile = JavaFile.builder(className.packageName(), scopeMemberTypeSpec.build()).build();
return javaFile.toString();
}
代码示例来源:origin: stephanenicolas/toothpick
public String brewJava() {
// Interface to implement
ClassName className = ClassName.get(constructorInjectionTarget.builtClass);
ParameterizedTypeName parameterizedTypeName = ParameterizedTypeName.get(ClassName.get(Factory.class), className);
// Build class
TypeSpec.Builder factoryTypeSpec = TypeSpec.classBuilder(getGeneratedSimpleClassName(constructorInjectionTarget.builtClass) + FACTORY_SUFFIX)
.addModifiers(Modifier.PUBLIC, Modifier.FINAL)
.addSuperinterface(parameterizedTypeName);
emitSuperMemberInjectorFieldIfNeeded(factoryTypeSpec);
emitCreateInstance(factoryTypeSpec);
emitGetTargetScope(factoryTypeSpec);
emitHasScopeAnnotation(factoryTypeSpec);
emitHasScopeInstancesAnnotation(factoryTypeSpec);
JavaFile javaFile = JavaFile.builder(className.packageName(), factoryTypeSpec.build()).build();
return javaFile.toString();
}
内容来源于网络,如有侵权,请联系作者删除!