本文整理汇总了Java中javax.lang.model.element.TypeElement.getSimpleName方法的典型用法代码示例。如果您正苦于以下问题:Java TypeElement.getSimpleName方法的具体用法?Java TypeElement.getSimpleName怎么用?Java TypeElement.getSimpleName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.lang.model.element.TypeElement
的用法示例。
在下文中一共展示了TypeElement.getSimpleName方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: ClassEntity
import javax.lang.model.element.TypeElement; //导入方法依赖的package包/类
/**
* @param elementUtils
* @param typeUtils
* @param element current anntated class
*/
public ClassEntity(Elements elementUtils, Types typeUtils, TypeElement element) {
elementWeakCache = new WeakReference<TypeElement>(element);
this.classPackageName = elementUtils.getPackageOf(element).getQualifiedName().toString();
this.modifierSet = element.getModifiers();
this.className = element.toString();
annotationMirrors = element.getAnnotationMirrors();
this.classSimpleName = element.getSimpleName();
this.classQualifiedName = element.getQualifiedName();
if ("java.lang.Object".equals(element.getSuperclass().toString())){
this.superclass = null;
}else{
this.superclass = element.getSuperclass().toString();
}
List<? extends TypeMirror> interfaces = element.getInterfaces();
for (TypeMirror anInterface : interfaces){
this.interfaces.add(typeUtils.asElement(anInterface).toString());
}
}
示例2: buildAnnotatedClass
import javax.lang.model.element.TypeElement; //导入方法依赖的package包/类
private AnnotatedClass buildAnnotatedClass(TypeElement annotatedClass) {
List<VariableElement> fields = new ArrayList<>();
for (Element element : annotatedClass.getEnclosedElements()) {
if (!(element instanceof VariableElement)) {
continue;
}
VariableElement variableElement = (VariableElement) element;
if (variableElement.getAnnotation(KVOField.class) != null) {
fields.add(variableElement);
}
}
return new AnnotatedClass(annotatedClass.getSimpleName() + "KVO", fields, annotatedClass
, processingEnv.getElementUtils().getPackageOf(annotatedClass).getQualifiedName().toString());
}
示例3: getRealClassName
import javax.lang.model.element.TypeElement; //导入方法依赖的package包/类
/**
* 获取TypeElement真实的类名
*/
public String getRealClassName(TypeElement typeElement) {
NestingKind nestingKind = typeElement.getNestingKind();
if (nestingKind.isNested()) {
Element enclosingElement = typeElement.getEnclosingElement();
if (enclosingElement.getKind() == ElementKind.CLASS || enclosingElement.getKind() == ElementKind.INTERFACE){
String enclosingClassName = getRealClassName((TypeElement) enclosingElement);
return enclosingClassName + "$" + typeElement.getSimpleName();
}else {
mErrorReporter.reportError("the type(" + enclosingElement.getKind()+ ") of enclosing element is not CLASS or INTERFACE.",typeElement);
return null;
}
}else {
return typeElement.getQualifiedName().toString();
}
}
示例4: getRegularClassString
import javax.lang.model.element.TypeElement; //导入方法依赖的package包/类
private static String getRegularClassString(Class<? extends Annotation> cls, TypeElement typeElement) {
if (cls.equals(ApplicationScope.class)) {
ApplicationScope appBucketObject = typeElement.getAnnotation(ApplicationScope.class);
return typeElement.getSimpleName() + appBucketObject.suffix();
} else if (cls.equals(GroupScope.class)) {
GroupScope groupBucketObject = typeElement.getAnnotation(GroupScope.class);
return typeElement.getSimpleName() + groupBucketObject.suffix();
} else if (cls.equals(UserScope.class)) {
UserScope userBucketObject = typeElement.getAnnotation(UserScope.class);
return typeElement.getSimpleName() + userBucketObject.suffix();
} else {
throw new IllegalAnnotationException();
}
}
示例5: getViewClassFromGeneric
import javax.lang.model.element.TypeElement; //导入方法依赖的package包/类
private String getViewClassFromGeneric(TypeElement typeElement) {
TypeMirror superclass = typeElement.asType();
Map<String, String> parentTypes = Collections.emptyMap();
if (!typeElement.getTypeParameters().isEmpty()) {
MvpCompiler.getMessager().printMessage(Diagnostic.Kind.WARNING, "Your " + typeElement.getSimpleName() + " is typed. @InjectViewState may generate wrong code. Your can set view/view state class manually.");
}
while (superclass.getKind() != TypeKind.NONE) {
TypeElement superclassElement = (TypeElement) ((DeclaredType) superclass).asElement();
final List<? extends TypeMirror> typeArguments = ((DeclaredType) superclass).getTypeArguments();
final List<? extends TypeParameterElement> typeParameters = superclassElement.getTypeParameters();
if (typeArguments.size() > typeParameters.size()) {
throw new IllegalArgumentException("Code generation for interface " + typeElement.getSimpleName() + " failed. Simplify your generics. (" + typeArguments + " vs " + typeParameters + ")");
}
Map<String, String> types = new HashMap<>();
for (int i = 0; i < typeArguments.size(); i++) {
types.put(typeParameters.get(i).toString(), fillGenerics(parentTypes, typeArguments.get(i)));
}
if (superclassElement.toString().equals(MVP_PRESENTER_CLASS)) {
// MvpPresenter is typed only on View class
return fillGenerics(parentTypes, typeArguments);
}
parentTypes = types;
superclass = superclassElement.getSuperclass();
}
return "";
}
示例6: getTemplateText
import javax.lang.model.element.TypeElement; //导入方法依赖的package包/类
private String getTemplateText(
Filer filer,
TypeElement templateType,
PackageElement packageElement) throws IOException {
CharSequence relativeName = templateType.getSimpleName() + ".generator";
CharSequence packageName = packageElement.getQualifiedName();
List<Exception> suppressed = Lists.newArrayList();
try {
return filer.getResource(StandardLocation.SOURCE_PATH, packageName, relativeName)
.getCharContent(true)
.toString();
} catch (Exception cannotGetFromSourcePath) {
suppressed.add(cannotGetFromSourcePath);
try {
return filer.getResource(StandardLocation.CLASS_OUTPUT, packageName, relativeName)
.getCharContent(true)
.toString();
} catch (Exception cannotGetFromOutputPath) {
suppressed.add(cannotGetFromOutputPath);
try {
return filer.getResource(StandardLocation.CLASS_PATH,
"",
packageName.toString().replace('.', '/') + '/' + relativeName)
.getCharContent(true)
.toString();
} catch (IOException cannotGetFromClasspath) {
for (Exception e : suppressed) {
cannotGetFromClasspath.addSuppressed(e);
}
throw cannotGetFromClasspath;
}
}
}
}
示例7: initSpecialAnnotations
import javax.lang.model.element.TypeElement; //导入方法依赖的package包/类
private void initSpecialAnnotations() {
for (AnnotationMirror annotation : element.getAnnotationMirrors()) {
TypeElement annotationElement = (TypeElement) annotation.getAnnotationType().asElement();
Name simpleName = annotationElement.getSimpleName();
Name qualifiedName = annotationElement.getQualifiedName();
if (qualifiedName.contentEquals(Annotations.JAVAX_CHECK_FOR_NULL)
|| qualifiedName.contentEquals(Annotations.JAVAX_NULLABLE)
|| simpleName.contentEquals(containingType.names().nullableAnnotation)) {
nullability = ImmutableNullabilityAnnotationInfo.of(annotationElement);
} else if (simpleName.contentEquals(TypeStringProvider.EPHEMERAL_ANNOTATION_ALLOW_NULLS)) {
nullElements = NullElements.ALLOW;
} else if (simpleName.contentEquals(TypeStringProvider.EPHEMERAL_ANNOTATION_SKIP_NULLS)) {
nullElements = NullElements.SKIP;
}
}
if (containingType.isGenerateJacksonProperties()
&& typeKind.isMap()
&& Proto.isAnnotatedWith(element, Annotations.JACKSON_ANY_GETTER)) {
jacksonAnyGetter = true;
}
if (containingType.isGenerateJacksonMapped()
&& (isGenerateAbstract || isGenerateDefault)
&& Proto.isAnnotatedWith(element, Annotations.JACKSON_VALUE)) {
jacksonValue = true;
}
if (isCollectionType()
&& nullElements == NullElements.BAN
&& protoclass().styles().style().validationMethod() == ValidationMethod.NONE) {
nullElements = NullElements.ALLOW;
}
}
示例8: generateCode
import javax.lang.model.element.TypeElement; //导入方法依赖的package包/类
public void generateCode(Elements elementUtils, Filer filer) throws IOException {
TypeElement superClassName = elementUtils.getTypeElement(qualifiedClassName);
String factoryClassName = superClassName.getSimpleName() + SUFFIX;
JavaFileObject jfo = filer.createSourceFile(qualifiedClassName + SUFFIX);
Writer writer = jfo.openWriter();
JavaWriter jw = new JavaWriter(writer);
// 写包名
PackageElement pkg = elementUtils.getPackageOf(superClassName);
if (!pkg.isUnnamed()) {
jw.emitPackage(pkg.getQualifiedName().toString());
jw.emitEmptyLine();
} else {
jw.emitPackage("");
}
jw.beginType(factoryClassName, "class", EnumSet.of(Modifier.PUBLIC));
jw.emitEmptyLine();
jw.beginMethod(qualifiedClassName, "create", EnumSet.of(Modifier.PUBLIC), "String", "id");
jw.beginControlFlow("if (id == null)");
jw.emitStatement("throw new IllegalArgumentException(\"id is null!\")");
jw.endControlFlow();
for (FactoryAnnotatedClass item : itemsMap.values()) {
jw.beginControlFlow(String.format("if (\"%s\".equals(id))", item.getId()));
jw.emitStatement("return new %s()", item.getTypeElement().getQualifiedName().toString());
jw.endControlFlow();
jw.emitEmptyLine();
}
jw.emitStatement("throw new IllegalArgumentException(\"Unknown id = \" + id)");
jw.endMethod();
jw.endType();
jw.close();
}
示例9: ClassWriter
import javax.lang.model.element.TypeElement; //导入方法依赖的package包/类
private ClassWriter(CodeInjector codeInjector, TypeElement classElement, MessageHandler messageHandler, List<EgItem<?>> items) {
this.codeInjector = codeInjector;
this.messageHandler = messageHandler;
this.items = items;
this.classElement = JavaModelUtil.topLevelClass(items.get(0).getElement());
this.className = classElement.getSimpleName() +"$EgTest";
}
示例10: getTargetClassName
import javax.lang.model.element.TypeElement; //导入方法依赖的package包/类
private String getTargetClassName(TypeElement originalClass) {
return originalClass.getSimpleName() + "Wrapper";
}
示例11: NoPackageNameException
import javax.lang.model.element.TypeElement; //导入方法依赖的package包/类
public NoPackageNameException(TypeElement typeElement) {
super("The package of " + typeElement.getSimpleName() + " has no name");
}
示例12: generatePresenterBinderClass
import javax.lang.model.element.TypeElement; //导入方法依赖的package包/类
private static String generatePresenterBinderClass(final String builder, String targetClass, final Field field) {
TypeElement clazz = (TypeElement) ((DeclaredType) field.getClazz()).asElement();
String s = "\tpublic class " + field.getGeneratedClassName() + " extends PresenterField {\n" +
"\t\tpublic " + field.getGeneratedClassName() + "() {\n" +
"\t\t\tsuper(" + field.getTag() + ", PresenterType." + field.getType().name() + ", " + field.getPresenterId() + ", " + clazz + ".class);\n" +
"\t\t}\n" +
"\n" +
"\t\[email protected]\n" +
"\t\tpublic void bind(Object target, MvpPresenter presenter) {\n" +
"\t\t\t((" + targetClass + ") target)." + field.getName() + " = (" + clazz.getQualifiedName() + ") presenter;\n" +
"\t\t}\n";
s += "\n" +
"\t\[email protected]\n" +
"\t\tpublic MvpPresenter<?> providePresenter(Object delegated) {\n";
if (field.getPresenterProviderMethodName() != null) {
s+= "\t\t\treturn ((" + targetClass + ") delegated)." + field.getPresenterProviderMethodName() + "();\n";
} else {
boolean hasEmptyConstructor = false;
List<? extends Element> enclosedElements = clazz.getEnclosedElements();
for (Element enclosedElement : enclosedElements) {
if (enclosedElement.getKind() == ElementKind.CONSTRUCTOR) {
List<? extends VariableElement> parameters = ((ExecutableElement) enclosedElement).getParameters();
if (parameters == null || parameters.isEmpty()) {
hasEmptyConstructor = true;
break;
}
}
}
if (hasEmptyConstructor) {
s += "\t\t\treturn new " + clazz.getQualifiedName() + "();\n";
} else {
s += "\t\t\tthrow new IllegalStateException(\"" + clazz.getSimpleName() + " has not default constructor. You can apply @ProvidePresenter to some method which will construct Presenter. Also you can make it default constructor\");\n";
}
}
s += "\t\t}\n";
if (field.getPresenterTagProviderMethodName() != null) {
s += "\n" +
"\t\[email protected]\n" +
"\t\tpublic String getTag(Object delegated) {\n" +
"\t\t\treturn String.valueOf(((" + targetClass + ") delegated)." + field.getPresenterTagProviderMethodName() + "());\n" +
"\t\t}\n";
}
s += "\t}\n" +
"\n";
return builder + s;
}
示例13: getSimpleName
import javax.lang.model.element.TypeElement; //导入方法依赖的package包/类
public static final String getSimpleName(TypeElement type) {
return GENERATOR_PREFIX + type.getSimpleName();
}
示例14: createDeserializer
import javax.lang.model.element.TypeElement; //导入方法依赖的package包/类
/**
* Creates a custom Jackson deserializer for the given
* {@link TypeElement}. Filling out the logic of the actual
* deserialize method using the {@link DeserializerCreator
* #implementDeserializeMethod(TypeElement, Builder)}
* method implemented by our subclasses.
*
* @param typeElement The interface to create a custom deserializer for
*/
public void createDeserializer(TypeElement typeElement) {
Name className = typeElement.getSimpleName();
DeclaredType declaredType = this.typeUtils.getDeclaredType(typeElement);
ClassName stdDeserializer = ClassName.get(StdDeserializer.class);
TypeName deserializerType = TypeName.get(declaredType);
ParameterizedTypeName parameterizedDeserializer = ParameterizedTypeName.get(stdDeserializer, deserializerType);
MethodSpec.Builder constructorBuilder = MethodSpec.constructorBuilder().addModifiers(Modifier.PUBLIC);
// since Generics don't work when calling .class, check if there are type parameters
if (typeElement.getTypeParameters().isEmpty()) {
// if not we can use $T
constructorBuilder.addStatement("super($T.class)", typeElement);
} else {
// if so, we need to use the fully qualified name and $L
constructorBuilder.addStatement("super($L.class)", typeElement.getQualifiedName());
}
MethodSpec constructor = constructorBuilder.build();
ParameterSpec jsonParserParameter = ParameterSpec.builder(JsonParser.class, JSON_PARSER_PARAMETER_NAME)
.build();
ParameterSpec deserializationContextParameter = ParameterSpec.builder(DeserializationContext.class, DESERIALIZATION_CONTEXT_PARAMETER_NAME)
.build();
MethodSpec.Builder deserializeMethodBuilder = MethodSpec.methodBuilder("deserialize")
.addAnnotation(Override.class)
.addParameter(jsonParserParameter)
.addParameter(deserializationContextParameter)
.addException(ClassName.get(IOException.class))
.addException(ClassName.get(JsonProcessingException.class))
.returns(TypeName.get(declaredType))
.addModifiers(Modifier.PUBLIC);
MethodSpec deserializeMethod = implementDeserializeMethod(typeElement, deserializeMethodBuilder);
TypeSpec deserializationClass = TypeSpec
.classBuilder(className + DESERIALIZER_CLASS_NAME_SUFFIX)
.superclass(parameterizedDeserializer)
.addModifiers(Modifier.PUBLIC, Modifier.FINAL)
.addMethod(constructor)
.addMethod(deserializeMethod)
.build();
PackageElement packageElement = this.elementUtils.getPackageOf(typeElement);
JavaFile javaFile = JavaFile
.builder(packageElement.getQualifiedName().toString(), deserializationClass)
.build();
// and write that file to disc
try {
javaFile.writeTo(this.filer);
} catch (IOException e) {
this.processorUtil.error(typeElement, e.getMessage());
}
}
示例15: UnnamedPackageException
import javax.lang.model.element.TypeElement; //导入方法依赖的package包/类
public UnnamedPackageException(TypeElement typeElement) {
super("The package of " + typeElement.getSimpleName() + " is unnamed");
}