FromSupertype(String type, Iterable<ValueAttribute> attribute) { this.type = type; this.hasGenerics = type.indexOf('<') > 0; Entry<String, List<String>> withArgs = SourceTypes.extract(type); this.raw = withArgs.getKey(); this.wildcard = hasGenerics ? SourceTypes.stringify(Maps.immutableEntry(withArgs.getKey(), Collections.nCopies(withArgs.getValue().size(), "?"))) : type; this.attributes = ImmutableList.copyOf(attribute); }
private Entry<String, List<String>> resolveTypes(Entry<String, List<String>> sourceTypes) { String typeName = sourceTypes.getKey(); typeName = importsResolver.apply(typeName); hasMaybeUnresolvedYetAfter |= importsResolver.unresolved; List<String> typeArguments = Lists.newArrayListWithCapacity(sourceTypes.getValue().size()); for (String typeArgument : sourceTypes.getValue()) { String resolvedTypeArgument = SourceTypes.stringify(resolveTypes(SourceTypes.extract(typeArgument))); typeArguments.add(resolvedTypeArgument); } return Maps.immutableEntry(typeName, typeArguments); }
@Override public CharSequence extractReturnType(ExecutableElement executableElement) { if (executableElement instanceof ExecutableElementImpl) { Binding binding = ((ExecutableElementImpl) executableElement)._binding; if (binding instanceof MethodBinding) { MethodBinding methodBinding = (MethodBinding) binding; @Nullable AbstractMethodDeclaration sourceMethod = methodBinding.sourceMethod(); if (sourceMethod != null) { CharSequence rawType = getRawType(methodBinding); char[] content = sourceMethod.compilationResult.compilationUnit.getContents(); int sourceEnd = methodBinding.sourceStart();// intentionaly int sourceStart = scanForTheSourceStart(content, sourceEnd); char[] methodTest = Arrays.copyOfRange(content, sourceStart, sourceEnd); Entry<String, List<String>> extracted = SourceTypes.extract(String.valueOf(methodTest)); return SourceTypes.stringify( Maps.immutableEntry(rawType.toString(), extracted.getValue())); } } } return UNABLE_TO_EXTRACT; }
public void stringify() { Entry<String, List<String>> entry = Maps.<String, List<String>>immutableEntry("Map", ImmutableList.of("String<X>", "Map<Int, B>")); check(SourceTypes.stringify(entry)).is("Map<String<X>, Map<Int, B>>"); } }
this.workaroundTypeString = SourceTypes.stringify(resolvedTypes);