private boolean tryToUseSourceAsAWorkaround() {
    if (element.getKind() != ElementKind.METHOD) {
      // we don't bother with non-method attributes
      // (like factory builder, where attributes are parameters)
      return false;
    }

    CharSequence returnTypeString =
        SourceExtraction.getReturnTypeString((ExecutableElement) element);
    if (returnTypeString.length() == 0) {
      // no source could be extracted for some reason, workaround will not work
      return false;
    }

    Entry<String, List<String>> extractedTypes = SourceTypes.extract(returnTypeString);

    // forces source imports based resolution,
    // we should not rely that types would be fully qualified
    Entry<String, List<String>> resolvedTypes = resolveTypes(extractedTypes);

    this.rawTypeName = resolvedTypes.getKey();
    this.workaroundTypeParameters = resolvedTypes.getValue();
    this.workaroundTypeString = SourceTypes.stringify(resolvedTypes);

    // workaround may have successed, need to continue with whatever we have
    return true;
  }
 private boolean isExtending(TypeElement element) {
   if (element.getKind() == ElementKind.CLASS) {
     String superclassString = SourceExtraction.getSuperclassString(element);
     String rawSuperclass = SourceTypes.extract(superclassString).getKey();
     // If we are extending yet to be generated builder, we detect it by having the same name
     // as relative name of builder type
     return rawSuperclass.endsWith(typeImplementationBuilder().relativeRaw());
   }
   return false;
 }
Beispiel #3
0
 @Value.Lazy
 public SourceExtraction.Imports sourceImports() {
   return SourceExtraction.readImports(processing(), CachingElements.getDelegate(element()));
 }
Beispiel #4
0
 @Value.Lazy
 public CharSequence headerComments() {
   return SourceExtraction.extractSourceHeader(
       processing(), CachingElements.getDelegate(element()));
 }