javax.lang.model.element.TypeElement.getQualifiedName()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(12.2k)|赞(0)|评价(0)|浏览(101)

本文整理了Java中javax.lang.model.element.TypeElement.getQualifiedName()方法的一些代码示例,展示了TypeElement.getQualifiedName()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。TypeElement.getQualifiedName()方法的具体详情如下:
包路径:javax.lang.model.element.TypeElement
类名称:TypeElement
方法名:getQualifiedName

TypeElement.getQualifiedName介绍

[英]Returns the fully qualified name of this type element. More precisely, it returns the canonical name. For local and anonymous classes, which do not have canonical names, an empty name is returned.

The name of a generic type does not include any reference to its formal type parameters. For example, the fully qualified name of the interface java.util.Set is " java.util.Set". Nested types use " ." as a separator, as in " java.util.Map.Entry".
[中]返回此类型元素的完全限定名。更准确地说,它返回规范名称。对于没有规范名称的本地类和匿名类,将返回空名称。
泛型类型的名称不包括对其形式类型参数的任何引用。例如,接口java的完全限定名。util。Set是“java.util.Set”。嵌套类型使用“”作为分隔符,如“java.util.Map.Entry”中所述。

代码示例

代码示例来源:origin: androidannotations/androidannotations

public AnnotationMirror getAnnotationMirror() {
  List<? extends AnnotationMirror> annotationMirrors = element.getAnnotationMirrors();
  for (AnnotationMirror annotationMirror : annotationMirrors) {
    TypeElement annotationElement = (TypeElement) annotationMirror.getAnnotationType().asElement();
    if (annotationElement.getQualifiedName().toString().equals(annotationName)) {
      return annotationMirror;
    }
  }
  return null;
}

代码示例来源:origin: neo4j/neo4j

@Override
  public Boolean visitType( TypeElement element, Void aVoid )
  {
    return element.getQualifiedName().contentEquals( annotationType.getName() );
  }
}

代码示例来源:origin: greenrobot/EventBus

private TypeElement getSuperclass(TypeElement type) {
  if (type.getSuperclass().getKind() == TypeKind.DECLARED) {
    TypeElement superclass = (TypeElement) processingEnv.getTypeUtils().asElement(type.getSuperclass());
    String name = superclass.getQualifiedName().toString();
    if (name.startsWith("java.") || name.startsWith("javax.") || name.startsWith("android.")) {
      // Skip system classes, this just degrades performance
      return null;
    } else {
      return superclass;
    }
  } else {
    return null;
  }
}

代码示例来源:origin: immutables/immutables

@Nullable
public static AnnotationMirror findAnnotation(
  List<? extends AnnotationMirror> annotationMirrors,
  String annotationTypeName) {
 for (AnnotationMirror annotation : annotationMirrors) {
  if (((TypeElement) annotation.getAnnotationType().asElement())
    .getQualifiedName()
    .contentEquals(annotationTypeName)) {
   return annotation;
  }
 }
 return null;
}

代码示例来源:origin: yanzhenjie/AndServer

private void findMapping(Set<? extends Element> set, Map<TypeElement, List<ExecutableElement>> controllerMap) {
  for (Element element : set) {
    if (element instanceof ExecutableElement) {
      ExecutableElement execute = (ExecutableElement)element;
      Element enclosing = element.getEnclosingElement();
      if (!(enclosing instanceof TypeElement)) continue;
      TypeElement type = (TypeElement)enclosing;
      Annotation restController = type.getAnnotation(RestController.class);
      Annotation controller = type.getAnnotation(Controller.class);
      if (restController == null && controller == null) {
        mLog.w(String.format("Controller/RestController annotations may be missing on %s.",
          type.getQualifiedName()));
        continue;
      }
      String host = type.getQualifiedName() + "#" + execute.getSimpleName() + "()";
      Set<Modifier> modifiers = execute.getModifiers();
      Validate.isTrue(!modifiers.contains(Modifier.PRIVATE), "The modifier private is redundant on %s.",
        host);
      if (modifiers.contains(Modifier.STATIC)) {
        mLog.w(String.format("The modifier static is redundant on %s.", host));
      }
      List<ExecutableElement> elementList = controllerMap.get(type);
      if (CollectionUtils.isEmpty(elementList)) {
        elementList = new ArrayList<>();
        controllerMap.put(type, elementList);
      }
      elementList.add(execute);
    }
  }
}

代码示例来源:origin: immutables/immutables

private String qualifiedNameOf(DeclaredType t) {
 return ((TypeElement) t.asElement()).getQualifiedName().toString();
}

代码示例来源:origin: remkop/picocli

private static boolean find(String interfaceName, TypeElement typeElement, Set<Element> visited) {
  if (visited.contains(typeElement)) { return false; }
  visited.add(typeElement);
  //logger.finest("trying to find " + interfaceName + " in " + typeElement);
  if (typeElement.getQualifiedName().contentEquals(interfaceName)) {
    return true;
  }
  for (TypeMirror implemented : typeElement.getInterfaces()) {
    if (find(interfaceName, (TypeElement) ((DeclaredType) implemented).asElement())) {
      return true;
    }
  }
  while (typeElement.getSuperclass().getKind() != TypeKind.NONE) {
    typeElement = (TypeElement) ((DeclaredType) typeElement.getSuperclass()).asElement();
    if (find(interfaceName, typeElement)) {
      return true;
    }
  }
  return false;
}

代码示例来源:origin: hibernate/hibernate-orm

private static String findMappedSuperClass(MetaEntity entity, Context context) {
  TypeMirror superClass = entity.getTypeElement().getSuperclass();
  //superclass of Object is of NoType which returns some other kind
  while ( superClass.getKind() == TypeKind.DECLARED ) {
    //F..king Ch...t Have those people used their horrible APIs even once?
    final Element superClassElement = ( (DeclaredType) superClass ).asElement();
    String superClassName = ( (TypeElement) superClassElement ).getQualifiedName().toString();
    if ( extendsSuperMetaModel( superClassElement, entity.isMetaComplete(), context ) ) {
      return superClassName;
    }
    superClass = ( (TypeElement) superClassElement ).getSuperclass();
  }
  return null;
}

代码示例来源:origin: google/error-prone

@Override
 public String apply(VariableTree variableTree) {
  for (Compound c : ASTHelpers.getSymbol(variableTree).getAnnotationMirrors()) {
   if (((TypeElement) c.getAnnotationType().asElement())
     .getQualifiedName()
     .contentEquals(ASSISTED_ANNOTATION)) {
    // Assisted only has 'value', and value can only contain 1 element.
    Collection<Attribute> valueEntries = c.getElementValues().values();
    if (!valueEntries.isEmpty()) {
     return Iterables.getOnlyElement(valueEntries).getValue().toString();
    }
   }
  }
  return "";
 }
};

代码示例来源:origin: javaee/glassfish

public Model(DeclaredType type) {
  this.type = type;
  for (ExecutableElement e : ElementFilter.methodsIn(type.asElement().getEnclosedElements())) {
    Metadata im = e.getAnnotation(Metadata.class);
    if(im==null)    continue;
    String name = im.value();
    if (name.length() == 0) name = ((TypeElement) type.asElement()).getQualifiedName().toString() + '.' + e.getSimpleName();
    metadataProperties.put(e,name);
  }
}

代码示例来源:origin: yanzhenjie/AndServer

.add("\n");
String host = type.getQualifiedName().toString() + "#" + execute.getSimpleName().toString() + "()";
StringBuilder paramBuild = new StringBuilder();
List<? extends VariableElement> parameters = execute.getParameters();
String executeName = execute.getSimpleName().toString();
TypeMirror returnMirror = execute.getReturnType();
handleCode.add("\n").addStatement("Object o = null", type, executeName).beginControlFlow("try");
if (!TypeKind.VOID.equals(returnMirror.getKind())) {
  handleCode.addStatement("o = (($T)mHost).$L($L)", type, executeName, paramBuild.toString());
} else {

代码示例来源:origin: immutables/immutables

static AttributeTypeKind from(TypeMirror type) {
  if (type.getKind() == TypeKind.DECLARED) {
   TypeElement typeElement = toElement(type);
   if (typeElement.getKind() == ElementKind.ENUM) {
    return ENUM;
   }
   if (typeElement.getKind() == ElementKind.ANNOTATION_TYPE) {
    return ANNOTATION;
   }
   Name qualifiedName = typeElement.getQualifiedName();
   if (qualifiedName.contentEquals(Class.class.getName())) {
    return TYPE;
   }
   if (qualifiedName.contentEquals(String.class.getName())) {
    return STRING;
   }
  } else if (type.getKind().isPrimitive()) {
   return PRIMITIVE;
  }
  throw new AssertionError();
 }
}

代码示例来源:origin: immutables/immutables

public static ImmutableList<TypeMirror> getTypesFromMirrors(
  String annotationQualifiedName,
  String annotationAttributeName,
  List<? extends AnnotationMirror> annotationMirrors) {
 ImmutableList.Builder<TypeMirror> builder = ImmutableList.builder();
 for (AnnotationMirror annotationMirror : annotationMirrors) {
  TypeElement element = (TypeElement) annotationMirror.getAnnotationType().asElement();
  if (element.getQualifiedName().contentEquals(annotationQualifiedName)) {
   collectTypesFromAnnotationAttribute(annotationAttributeName, builder, annotationMirror);
  }
 }
 return builder.build();
}

代码示例来源:origin: androidannotations/androidannotations

private void extractAnnotations(AnnotationElementsHolder extractedModel, Set<String> annotationTypesToCheck, TypeElement rootTypeElement, Element ancestorEnclosedElement) {
  List<? extends AnnotationMirror> ancestorEnclosedElementAnnotations = ancestorEnclosedElement.getAnnotationMirrors();
  for (AnnotationMirror annotationMirror : ancestorEnclosedElementAnnotations) {
    DeclaredType annotationType = annotationMirror.getAnnotationType();
    if (annotationTypesToCheck.contains(annotationType.toString())) {
      TypeElement annotation = (TypeElement) annotationType.asElement();
      /*
       * rootTypeElement is one of the types that are being compiled
       *
       * ancestorEnclosedElement is the annotated element in an ancestor of
       * rootTypeElement
       *
       * annotation is a type representing the annotation on ancestorEnclosedElement
       */
      extractedModel.putAncestorAnnotatedElement(annotation.getQualifiedName().toString(), ancestorEnclosedElement, rootTypeElement);
    }
  }
}

代码示例来源:origin: androidannotations/androidannotations

public RInnerClass(TypeElement rInnerTypeElement) {
  if (rInnerTypeElement != null) {
    rInnerQualifiedName = rInnerTypeElement.getQualifiedName().toString();
    List<? extends Element> idEnclosedElements = rInnerTypeElement.getEnclosedElements();
    List<VariableElement> idFields = ElementFilter.fieldsIn(idEnclosedElements);
    for (VariableElement idField : idFields) {
      TypeKind fieldType = idField.asType().getKind();
      if (fieldType.isPrimitive() && fieldType.equals(TypeKind.INT)) {
        String idQualifiedName = rInnerQualifiedName + "." + idField.getSimpleName();
        idQualifiedNames.add(idQualifiedName);
        Integer idFieldId = (Integer) idField.getConstantValue();
        if (idFieldId != null) {
          idQualifiedNamesByIdValues.put(idFieldId, idQualifiedName);
        }
      }
    }
  } else {
    rInnerQualifiedName = "";
  }
}

代码示例来源:origin: JakeWharton/butterknife

if (duplicateId != null) {
 error(element, "@%s annotation for method contains duplicate ID %d. (%s.%s)",
   annotationClass.getSimpleName(), duplicateId, enclosingElement.getQualifiedName(),
   element.getSimpleName());
 hasError = true;
   if (!required) {
    error(element, "ID-free binding must not be annotated with @Optional. (%s.%s)",
      enclosingElement.getQualifiedName(), element.getSimpleName());
    hasError = true;
     annotationClass.getSimpleName(), id, enclosingElement.getQualifiedName(),
     element.getSimpleName());
   hasError = true;
 error(element, "@%s methods can have at most %s parameter(s). (%s.%s)",
   annotationClass.getSimpleName(), method.parameters().length,
   enclosingElement.getQualifiedName(), element.getSimpleName());
 hasError = true;
 error(element, "@%s methods must have a '%s' return type. (%s.%s)",
   annotationClass.getSimpleName(), method.returnType(),
   enclosingElement.getQualifiedName(), element.getSimpleName());
 hasError = true;
     .append(annotationClass.getSimpleName())
     .append(" method arguments. (")
     .append(enclosingElement.getQualifiedName())
     .append('.')

代码示例来源:origin: f2prateek/dart

private TypeElement getIntentBuilder(TypeMirror dartModelMirror) {
  final TypeElement dartModel = (TypeElement) ((DeclaredType) dartModelMirror).asElement();
  final String modelFQN = dartModel.getQualifiedName().toString();
  final int indexOfSuffix = modelFQN.indexOf(DART_MODEL_SUFFIX);
  if (indexOfSuffix == -1) {
   return null;
  }
  final String targetComponentFQN = modelFQN.substring(0, indexOfSuffix);
  return elementUtils.getTypeElement(targetComponentFQN + BUNDLE_BUILDER_SUFFIX);
 }
}

代码示例来源:origin: yongjhih/RetroFacebook

private boolean isJavaLangObject(TypeMirror type) {
  if (type.getKind() != TypeKind.DECLARED) {
   return false;
  }
  DeclaredType declaredType = (DeclaredType) type;
  TypeElement typeElement = (TypeElement) declaredType.asElement();
  return typeElement.getQualifiedName().contentEquals("java.lang.Object");
 }
};

代码示例来源:origin: requery/requery

private static boolean namesEqual(TypeElement element, String qualifiedName) {
    return element != null && element.getQualifiedName().contentEquals(qualifiedName);
  }
}

代码示例来源:origin: facebook/litho

@Override
public TypeSpec visitDeclared(DeclaredType t, Void aVoid) {
 final TypeElement typeElement = (TypeElement) t.asElement();
 final String qualifiedName = typeElement.getQualifiedName().toString();
 final Supplier<TypeSpec> superclass =
   new SimpleMemoizingSupplier<>(
     () -> {
      final TypeMirror mirror = typeElement.getSuperclass();
      return mirror.getKind() != TypeKind.DECLARED
        ? null
        : generateTypeSpec(mirror);
     ? mirrors
       .stream()
       .filter(mirror -> mirror.getKind() == TypeKind.DECLARED)
       .map(SpecModelUtils::generateTypeSpec)
       .collect(Collectors.toList())

相关文章