本文整理汇总了Java中javax.lang.model.element.TypeElement.getKind方法的典型用法代码示例。如果您正苦于以下问题:Java TypeElement.getKind方法的具体用法?Java TypeElement.getKind怎么用?Java TypeElement.getKind使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.lang.model.element.TypeElement
的用法示例。
在下文中一共展示了TypeElement.getKind方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: printInterfaces
import javax.lang.model.element.TypeElement; //导入方法依赖的package包/类
private void printInterfaces(TypeElement e) {
ElementKind kind = e.getKind();
if(kind != ANNOTATION_TYPE) {
List<? extends TypeMirror> interfaces = e.getInterfaces();
if (interfaces.size() > 0) {
writer.print((kind.isClass() ? " implements" : " extends"));
boolean first = true;
for(TypeMirror interf: interfaces) {
if (!first)
writer.print(",");
writer.print(" ");
writer.print(interf.toString());
first = false;
}
}
}
}
示例2: isDeclaredAsJavaBean
import javax.lang.model.element.TypeElement; //导入方法依赖的package包/类
public static String isDeclaredAsJavaBean(TypeElement clazz) {
if (ElementKind.CLASS != clazz.getKind()) {
return PaletteUtils.getBundleString("MSG_notAClass"); // NOI18N
}
Set<javax.lang.model.element.Modifier> mods = clazz.getModifiers();
if (mods.contains(javax.lang.model.element.Modifier.ABSTRACT)) {
return PaletteUtils.getBundleString("MSG_abstractClass"); // NOI18N
}
if (!mods.contains(javax.lang.model.element.Modifier.PUBLIC)) {
return PaletteUtils.getBundleString("MSG_notPublic"); // NOI18N
}
for (Element member : clazz.getEnclosedElements()) {
mods = member.getModifiers();
if (ElementKind.CONSTRUCTOR == member.getKind() &&
mods.contains(javax.lang.model.element.Modifier.PUBLIC) &&
((ExecutableElement) member).getParameters().isEmpty()) {
return null;
}
}
return PaletteUtils.getBundleString("MSG_noPublicConstructor"); // NOI18N
}
示例3: createItem
import javax.lang.model.element.TypeElement; //导入方法依赖的package包/类
private CompletionItem createItem(ElementHandle<TypeElement> handle, int priority) {
TypeElement el = handle.resolve(ctx.getCompilationInfo());
if (el == null) {
// element does not exist etc
return null;
}
if (el.getKind() != ElementKind.CLASS && el.getKind() != ElementKind.ENUM) {
// do not honour interfaces
return null;
}
if (!el.getModifiers().contains(Modifier.PUBLIC)) {
return null;
}
CompletionItem item = null;
Collection<? extends ClassItemFactory> converters = MimeLookup.getLookup(JavaFXEditorUtils.FXML_MIME_TYPE).lookupAll(ClassItemFactory.class);
for (ClassItemFactory converter : converters) {
item = converter.convert(el, ctx, priority);
if (item != null) {
break;
}
}
return item;
}
示例4: createCompleter
import javax.lang.model.element.TypeElement; //导入方法依赖的package包/类
@Override
public Completer createCompleter(CompletionContext ctx) {
FxProperty p = ctx.getEnclosingProperty();
if (p == null || p.getType() == null) {
return null;
}
TypeMirror m = p.getType().resolve(ctx.getCompilationInfo());
if (m.getKind() == TypeKind.BOOLEAN) {
return new EnumValueCompleter(ctx);
}
if (m.getKind() != TypeKind.DECLARED) {
return null;
}
DeclaredType t = (DeclaredType)m;
TypeElement tel = (TypeElement)t.asElement();
if (tel.getQualifiedName().contentEquals("java.lang.Boolean")) {
return new EnumValueCompleter(ctx);
}
if (tel.getKind() == ElementKind.ENUM) {
return new EnumValueCompleter(ctx, tel);
} else {
return null;
}
}
示例5: resolveTypes
import javax.lang.model.element.TypeElement; //导入方法依赖的package包/类
private void resolveTypes(Parameters p) {
List<TypeElement> types = ElementFilter.typesIn(p.element.getEnclosedElements());
for (TypeElement typeElement : types) {
if ( typeElement.getKind() == ElementKind.CLASS ||
typeElement.getKind() == ElementKind.INTERFACE ) {
PatternAnalyser pa = new PatternAnalyser( p.ci.getFileObject(), ui );
pa.analyzeAll(p.ci, typeElement);
ClassPattern cp = new ClassPattern(pa, typeElement.asType(),
BeanUtils.nameAsString(typeElement));
currentClassesPatterns.add(cp);
}
}
}
示例6: isInaccessibleViaGeneratedCode
import javax.lang.model.element.TypeElement; //导入方法依赖的package包/类
private boolean isInaccessibleViaGeneratedCode(Class<? extends Annotation> annotationClass,
String targetThing, Element element) {
boolean hasError = false;
TypeElement enclosingElement = (TypeElement) element.getEnclosingElement();
// Verify method modifiers.
Set<Modifier> modifiers = element.getModifiers();
if (modifiers.contains(PRIVATE) || modifiers.contains(STATIC)) {
error(element, "@%s %s must not be private or static. (%s.%s)",
annotationClass.getSimpleName(), targetThing, enclosingElement.getQualifiedName(),
element.getSimpleName());
hasError = true;
}
// Verify containing type.
if (enclosingElement.getKind() != CLASS) {
error(enclosingElement, "@%s %s may only be contained in classes. (%s.%s)",
annotationClass.getSimpleName(), targetThing, enclosingElement.getQualifiedName(),
element.getSimpleName());
hasError = true;
}
// Verify containing class visibility is not private.
if (enclosingElement.getModifiers().contains(PRIVATE)) {
error(enclosingElement, "@%s %s may not be contained in private classes. (%s.%s)",
annotationClass.getSimpleName(), targetThing, enclosingElement.getQualifiedName(),
element.getSimpleName());
hasError = true;
}
return hasError;
}
示例7: handleJavaType
import javax.lang.model.element.TypeElement; //导入方法依赖的package包/类
private Optional<TSType> handleJavaType(TypeElement element) {
if (element == null) return Optional.empty();
if (checkExclusion(element)) {
LOG.info( () -> "Excluding " + element);
return Optional.empty();
}
List<TSType> supertypes = convertSuperTypes(element);
TSType result = null;
switch (element.getKind()) {
case CLASS:
{
result = TSInterfaceBuilder.of(element).withMembers(findMembers(element)).withSuperTypes(supertypes);
break;
}
case INTERFACE: {
result = TSInterfaceBuilder.of(element).withMembers(findMembers(element)).withSuperTypes(supertypes);
break;
}
case ENUM: {
result = TSEnumBuilder.of(element).withMembers(findEnumMembers(element));
break;
}
default: break;
}
return Optional.ofNullable(result);
}
示例8: processType
import javax.lang.model.element.TypeElement; //导入方法依赖的package包/类
private void processType(TypeElement type, Map<TypeElement, String> elementTargetNames) {
TypeElement mapFrom = getClassToMapFrom(type);
AutoMapper autoMapper = type.getAnnotation(AutoMapper.class);
if (autoMapper == null) {
mErrorReporter.abortWithError(
"annotation processor for @AutoParcel was invoked with a type annotated differently; compiler bug? O_o",
type
);
}
if (type.getKind() != ElementKind.CLASS) {
mErrorReporter.abortWithError("@" + AutoMapper.class.getName() + " only applies to classes", type);
}
if (ancestorIsAutoParcel(type)) {
mErrorReporter.abortWithError("One @AutoParcel class shall not extend another", type);
}
checkModifiersIfNested(type);
// get the fully-qualified class name
String fqClassName = generatedSubclassName(type, 0);
// class name
String className = TypeUtil.simpleNameOf(fqClassName);
String source = generateClass(type, className, type.getSimpleName().toString(), mapFrom, elementTargetNames);
source = Reformatter.fixup(source);
writeSourceFile(fqClassName, source, type);
}
示例9: process
import javax.lang.model.element.TypeElement; //导入方法依赖的package包/类
@Override
public void process( TypeElement typeElement, TypeProcessor typeProcessor, IssueReporter<JavaFileObject> issueReporter )
{
if( typeElement.getKind() == ElementKind.CLASS || typeElement.getKind() == ElementKind.INTERFACE )
{
TreeTranslator visitor = new ExtensionTransformer( this, typeProcessor );
typeProcessor.getTree().accept( visitor );
}
}
示例10: visitType
import javax.lang.model.element.TypeElement; //导入方法依赖的package包/类
@Override
public List<TypeElement> visitType(TypeElement typeElement, Void arg) {
if (typeElement.getKind() == ElementKind.CLASS && isAccessibleClass(typeElement)) {
DEFAULT_VALUE.add(typeElement);
}
return super.visitType(typeElement, arg);
}
示例11: createObjects
import javax.lang.model.element.TypeElement; //导入方法依赖的package包/类
@Override
public List<T> createObjects(TypeElement type) {
final List<T> result = new ArrayList<T>();
if (type.getKind() == ElementKind.CLASS || type.getKind() == ElementKind.INTERFACE) {
if (helper.hasAnyAnnotation(type.getAnnotationMirrors(), getAnnotationTypeNames())) {
result.add(createObject(helper, type));
}
}
return result;
}
示例12: getClass
import javax.lang.model.element.TypeElement; //导入方法依赖的package包/类
/**
* Finds a main top-level class or a nested class element
* for {@code sourceDataObject} which should be initialized.
*/
private TypeElement getClass(WorkingCopy workingCopy)
throws IOException {
workingCopy.toPhase(Phase.ELEMENTS_RESOLVED);
final String preferredName = sourceDataObject.getName();
TypeElement firstPublicNestedClass = null;
List<? extends TypeElement> topClasses = workingCopy.getTopLevelElements();
for (TypeElement topElement : topClasses) {
ElementKind elementKind = topElement.getKind();
if (!elementKind.isClass()) {
continue;
}
if (topElement.getSimpleName().contentEquals(preferredName)) {
return topElement;
}
if ((firstPublicNestedClass == null)
&& topElement.getModifiers().contains(Modifier.PUBLIC)) {
firstPublicNestedClass = topElement;
}
}
return firstPublicNestedClass;
}
示例13: isRootObjectType
import javax.lang.model.element.TypeElement; //导入方法依赖的package包/类
/**
* Checks whether the given type object represents type
* {@literal java.lang.Object}.
*
* @param type type to be checked
* @return {@literal true} if the passed type object represents type
* {@literal java.lang.Object}, {@literal false} otherwise
*/
private static boolean isRootObjectType(DeclaredType type) {
if (type.getKind() != TypeKind.DECLARED) {
return false;
}
TypeElement elem = (TypeElement) type.asElement();
return (elem.getKind() == ElementKind.CLASS)
&& (elem.getSuperclass().getKind() == TypeKind.NONE);
}
示例14: isValid
import javax.lang.model.element.TypeElement; //导入方法依赖的package包/类
/**
* 注解是否有效
* @author leibing
* @createTime 2017/3/2
* @lastModify 2017/3/2
* @param annotationClass
* @param targetThing
* @param element 元素
* @return
*/
private boolean isValid(Class<? extends Annotation> annotationClass, String targetThing, Element element) {
boolean isVaild = true;
// 获取变量的所在的父元素,肯能是类、接口、枚举
TypeElement enclosingElement = (TypeElement) element.getEnclosingElement();
// 父元素的全限定名
String qualifiedName = enclosingElement.getQualifiedName().toString();
// 所在的类不能是private或static修饰
Set<Modifier> modifiers = element.getModifiers();
if (modifiers.contains(PRIVATE) || modifiers.contains(STATIC)) {
error(element, "@%s %s must not be private or static. (%s.%s)",
annotationClass.getSimpleName(), targetThing, enclosingElement.getQualifiedName(),
element.getSimpleName());
isVaild = false;
}
// 父元素必须是类,而不能是接口或枚举
if (enclosingElement.getKind() != ElementKind.CLASS) {
error(enclosingElement, "@%s %s may only be contained in classes. (%s.%s)",
annotationClass.getSimpleName(), targetThing, enclosingElement.getQualifiedName(),
element.getSimpleName());
isVaild = false;
}
// 不能在Android框架层注解
if (qualifiedName.startsWith("android.")) {
error(element, "@%s-annotated class incorrectly in Android framework package. (%s)",
annotationClass.getSimpleName(), qualifiedName);
return false;
}
// 不能在java框架层注解
if (qualifiedName.startsWith("java.")) {
error(element, "@%s-annotated class incorrectly in Java framework package. (%s)",
annotationClass.getSimpleName(), qualifiedName);
return false;
}
return isVaild;
}
示例15: determineEventHandlers
import javax.lang.model.element.TypeElement; //导入方法依赖的package包/类
private void determineEventHandlers( @Nonnull final ComponentDescriptor descriptor )
{
final List<EventHandlerDescriptor> eventHandlers =
ProcessorUtil.getMethods( descriptor.getElement(), processingEnv.getTypeUtils() ).stream()
.filter( m -> null != ProcessorUtil.findAnnotationByType( m, Constants.EVENT_HANDLER_ANNOTATION_CLASSNAME ) )
.map( m -> createEventHandlerDescriptor( descriptor, m ) )
.collect( Collectors.toList() );
for ( final EventHandlerDescriptor eventHandler : eventHandlers )
{
final ExecutableElement method = eventHandler.getMethod();
final TypeElement handlerType = getEventHandlerType( method );
if ( ElementKind.INTERFACE != handlerType.getKind() )
{
throw new ReactProcessorException( "The @EventHandler specified an invalid type that is not an interface.",
eventHandler.getMethod() );
}
if ( null == ProcessorUtil.findAnnotationByType( handlerType, Constants.JS_FUNCTION_CLASSNAME ) )
{
throw new ReactProcessorException( "The @EventHandler specified an invalid type that is not annotated " +
"with the annotation jsinterop.annotations.JsFunction.",
eventHandler.getMethod() );
}
final EventHandlerDescriptor matched = eventHandlers.stream()
.filter( h -> h != eventHandler && h.getName().equals( eventHandler.getName() ) )
.findAny().orElse( null );
if ( null != matched )
{
throw new ReactProcessorException( "The @EventHandler has the same name as the event handler defined by " +
matched.getMethod() + ".", eventHandler.getMethod() );
}
final EventHandlerDescriptor matched2 = eventHandlers.stream()
.filter( h -> h != eventHandler &&
h.getMethod().getSimpleName().equals( eventHandler.getMethod().getSimpleName() ) )
.findAny().orElse( null );
if ( null != matched2 )
{
throw new ReactProcessorException( "The @EventHandler has the same method name as the event handler defined " +
"by " + matched2.getMethod() + ".", eventHandler.getMethod() );
}
final ExecutableType methodType = eventHandler.getMethodType();
final List<? extends TypeMirror> parameters = methodType.getParameterTypes();
if ( !parameters.isEmpty() )
{
// Our annotated handler method has parameters so they should exactly align
// in count and type with the parameters in the event handler method
final ExecutableElement target = eventHandler.getEventHandlerMethod();
final List<? extends VariableElement> targetParameters = target.getParameters();
if ( targetParameters.size() != parameters.size() )
{
throw new ReactProcessorException( "The @EventHandler target has " + parameters.size() + " parameters " +
"but the type parameter specified a handler with method type " +
eventHandler.getEventHandlerType().getQualifiedName() + " that has " +
"handler method with " + targetParameters.size() + " parameters. The " +
"@EventHandler target should have zero parameters or match the number " +
"of parameter in the target method " + target.getSimpleName() + ".",
eventHandler.getMethod() );
}
for ( int i = 0; i < parameters.size(); i++ )
{
final TypeMirror parameterType = parameters.get( i );
final VariableElement element = targetParameters.get( i );
final TypeMirror targetParameterType = element.asType();
final TypeMirror targetErased = processingEnv.getTypeUtils().erasure( targetParameterType );
final TypeMirror parameterErased = processingEnv.getTypeUtils().erasure( parameterType );
if ( !processingEnv.getTypeUtils().isAssignable( targetErased, parameterErased ) )
{
throw new ReactProcessorException( "The @EventHandler target parameter named " +
eventHandler.getMethod().getParameters().get( i ).getSimpleName() +
" of type " + parameterType + " is not assignable from target type " +
targetParameterType + " of parameter " + element.getSimpleName() +
" in method " + eventHandler.getEventHandlerType().getQualifiedName() +
"." + target.getSimpleName() + ".",
eventHandler.getMethod() );
}
}
}
}
descriptor.setEventHandlers( eventHandlers );
}