當前位置: 首頁>>代碼示例>>Java>>正文


Java TypeElement.getSimpleName方法代碼示例

本文整理匯總了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());
    }
}
 
開發者ID:simplezhli,項目名稱:RxPay,代碼行數:25,代碼來源:ClassEntity.java

示例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());
    }
 
開發者ID:ahmed-basyouni,項目名稱:AndroidKVO,代碼行數:21,代碼來源:KVOProcessor.java

示例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();
	}
}
 
開發者ID:tik5213,項目名稱:DUnit,代碼行數:19,代碼來源:DUnitModelUtil.java

示例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();
    }
}
 
開發者ID:daisuke-nomura,項目名稱:KiiAnnotation,代碼行數:15,代碼來源:KiiAnnotationProcessor.java

示例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 "";
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:37,代碼來源:ViewStateProviderClassGenerator.java

示例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;
      }
    }
  }
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:35,代碼來源:Processor.java

示例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;
  }
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:32,代碼來源:ValueAttribute.java

示例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();
}
 
開發者ID:jacklongway,項目名稱:FactoryAnnotation,代碼行數:38,代碼來源:FactoryGroupedClasses.java

示例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";
}
 
開發者ID:dleppik,項目名稱:EgTest,代碼行數:8,代碼來源:ClassWriter.java

示例10: getTargetClassName

import javax.lang.model.element.TypeElement; //導入方法依賴的package包/類
private String getTargetClassName(TypeElement originalClass) {
    return originalClass.getSimpleName() + "Wrapper";
}
 
開發者ID:srym,項目名稱:shoebill,代碼行數:4,代碼來源:ShoebillProcessor.java

示例11: NoPackageNameException

import javax.lang.model.element.TypeElement; //導入方法依賴的package包/類
public NoPackageNameException(TypeElement typeElement) {
    super("The package of " + typeElement.getSimpleName() + " has no name");
}
 
開發者ID:weizongwei5,項目名稱:GeneratorX,代碼行數:4,代碼來源:NoPackageNameException.java

示例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;
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:50,代碼來源:PresenterBinderClassGenerator.java

示例13: getSimpleName

import javax.lang.model.element.TypeElement; //導入方法依賴的package包/類
public static final String getSimpleName(TypeElement type) {
  return GENERATOR_PREFIX + type.getSimpleName();
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:4,代碼來源:GeneratedTypes.java

示例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());
    }
}
 
開發者ID:peckb1,項目名稱:autojackson,代碼行數:65,代碼來源:DeserializerCreator.java

示例15: UnnamedPackageException

import javax.lang.model.element.TypeElement; //導入方法依賴的package包/類
public UnnamedPackageException(TypeElement typeElement) {
  super("The package of " + typeElement.getSimpleName() + " is unnamed");
}
 
開發者ID:Comcast,項目名稱:resourceprovider,代碼行數:4,代碼來源:UnnamedPackageException.java


注:本文中的javax.lang.model.element.TypeElement.getSimpleName方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。