use of io.github.classgraph.TypeArgument in project conquery by bakdata.
the class GroupHandler method printType.
private String printType(Ctx ctx, TypeArgument type) {
if (type.getTypeSignature() == null) {
return "UNKNWON";
}
if (type.getTypeSignature() instanceof TypeVariableSignature) {
String v = type.getTypeSignature().toString();
TypeParameter typeParam = ctx.getField().getClassInfo().getTypeSignature().getTypeParameters().stream().filter(tp -> tp.getName().equals(v)).collect(MoreCollectors.onlyElement());
if (typeParam.getClassBound() != null) {
return printType(ctx, typeParam.getClassBound());
}
return printType(ctx, typeParam.getInterfaceBounds().get(0));
}
return printType(ctx, type.getTypeSignature());
}
use of io.github.classgraph.TypeArgument in project joinfaces by joinfaces.
the class RewriteAnnotationProviderHandler method handle.
@Override
public void handle(ScanResult scanResult, File classpathRoot) throws IOException {
ClassInfoList annotationHandlers = scanResult.getClassesImplementing(REWRITE_ANNOTATION_HANDLER);
if (annotationHandlers.isEmpty()) {
return;
}
List<String> annotationClassNames = annotationHandlers.stream().map(classInfo -> classInfo.getDeclaredMethodInfo("handles")).flatMap(Collection::stream).map(MethodInfo::getTypeSignature).map(MethodTypeSignature::getResultType).filter(ClassRefTypeSignature.class::isInstance).map(ClassRefTypeSignature.class::cast).map(classRefTypeSignature -> classRefTypeSignature.getTypeArguments().get(0)).map(TypeArgument::getTypeSignature).filter(ClassRefTypeSignature.class::isInstance).map(ClassRefTypeSignature.class::cast).map(ClassRefTypeSignature::getFullyQualifiedClassName).collect(Collectors.toList());
File resultFile = new File(classpathRoot, "META-INF/joinfaces/" + REWRITE_ANNOTATION_HANDLER + ".classes");
SortedSet<String> result = new TreeSet<>(String::compareTo);
for (String annotationClassName : annotationClassNames) {
result.addAll(scanResult.getClassesWithAnnotation(annotationClassName).getNames());
result.addAll(scanResult.getClassesWithFieldAnnotation(annotationClassName).getNames());
result.addAll(scanResult.getClassesWithMethodAnnotation(annotationClassName).getNames());
}
writeClassList(resultFile, result);
}
use of io.github.classgraph.TypeArgument in project conquery by bakdata.
the class GroupHandler method printType.
private String printType(Ctx ctx, TypeSignature type) {
if (type instanceof ArrayTypeSignature) {
return LIST_OF + printType(ctx, ((ArrayTypeSignature) type).getElementTypeSignature());
}
if (type instanceof BaseTypeSignature) {
return code(type.toString());
}
if (type instanceof ClassRefTypeSignature) {
ClassRefTypeSignature classRef = (ClassRefTypeSignature) type;
Class<?> cl = classRef.loadClass();
// ID
if (IId.class.isAssignableFrom(cl)) {
String name = cl.getSimpleName();
return ID_OF + code(name.substring(0, name.length() - 2));
}
// File
if (File.class.isAssignableFrom(cl)) {
// we could check if dir or file here
return code("File");
}
// List
if (List.class.isAssignableFrom(cl)) {
TypeArgument param = classRef.getTypeArguments().get(0);
return LIST_OF + printType(ctx.withGeneric(true), param);
}
// Map
if (BiMap.class.isAssignableFrom(cl)) {
return "bijective map from " + printType(ctx.withGeneric(true), classRef.getTypeArguments().get(0)) + " to " + printType(ctx.withGeneric(true), classRef.getTypeArguments().get(1));
}
if (ClassToInstanceMap.class.isAssignableFrom(cl)) {
return "ClassToInstanceMap maps from base class " + printType(ctx.withGeneric(true), classRef.getTypeArguments().get(0)) + " to instances of subtypes";
}
if (Map.class.isAssignableFrom(cl)) {
return "map from " + printType(ctx.withGeneric(true), classRef.getTypeArguments().get(0)) + " to " + printType(ctx.withGeneric(true), classRef.getTypeArguments().get(1));
}
// String
if (String.class.isAssignableFrom(cl)) {
return code("String");
}
// another BaseClass
if (content.keySet().stream().map(Base::getBaseClass).anyMatch(c -> c.equals(cl))) {
return "[" + type.toStringWithSimpleNames() + "](" + anchor(baseTitle(cl)) + ")";
}
// another contentClass
Optional<Pair<CPSType, ClassInfo>> match = content.values().stream().filter(p -> p.getRight().loadClass().equals(cl)).collect(MoreCollectors.toOptional());
if (match.isPresent()) {
return "[" + match.get().getLeft().id() + "](" + anchor(match.get().getLeft().id()) + ")";
}
if (content.keySet().stream().map(Base::getBaseClass).anyMatch(c -> c.equals(cl))) {
return "[" + type.toStringWithSimpleNames() + "](" + anchor(baseTitle(cl)) + ")";
}
// another class in the group
if (group.getOtherClasses().contains(cl)) {
return "[" + cl.getSimpleName() + "](" + anchor(typeTitle(cl)) + ")";
}
// a marker interface
if (group.getMarkerInterfaces().contains(cl)) {
return "[" + cl.getSimpleName() + "](" + anchor(markerTitle(cl)) + ")";
}
// ENUM
if (Enum.class.isAssignableFrom(cl)) {
return "one of " + Arrays.stream(cl.getEnumConstants()).map(Enum.class::cast).map(Enum::name).collect(Collectors.joining(", "));
}
if (Primitives.isWrapperType(cl)) {
return "`" + Primitives.unwrap(cl).getSimpleName() + "`" + (ctx.isIdOf() ? "" : " or `null`");
}
// default for hidden types
if (group.getHides().contains(cl)) {
return code(type.toStringWithSimpleNames());
}
}
if (!ctx.isIdOf()) {
log.warn("Unhandled type {}", type);
}
return code(type.toStringWithSimpleNames());
}
use of io.github.classgraph.TypeArgument in project helidon by oracle.
the class NativeUtil method getSimpleType.
Class<?> getSimpleType(Function<String, Class<?>> classResolver, Supplier<TypeSignature> typeSignatureSupplier, Supplier<TypeSignature> typeDescriptorSupplier) {
TypeSignature typeSignature = typeSignatureSupplier.get();
if (typeSignature == null) {
// not a generic type
TypeSignature typeDescriptor = typeDescriptorSupplier.get();
return getSimpleType(classResolver, typeDescriptor);
}
if (typeSignature instanceof ClassRefTypeSignature) {
ClassRefTypeSignature refType = (ClassRefTypeSignature) typeSignature;
List<TypeArgument> typeArguments = refType.getTypeArguments();
if (typeArguments.size() == 1) {
TypeArgument typeArgument = typeArguments.get(0);
ReferenceTypeSignature ref = typeArgument.getTypeSignature();
return getSimpleType(classResolver, ref);
}
}
return getSimpleType(classResolver, typeSignature);
}
Aggregations