Class EclipseHack


  • class EclipseHack
    extends java.lang.Object
    Hacks needed to work around various bugs and incompatibilities in Eclipse's implementation of annotation processing.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private javax.annotation.processing.ProcessingEnvironment processingEnv  
    • Constructor Summary

      Constructors 
      Constructor Description
      EclipseHack​(javax.annotation.processing.ProcessingEnvironment processingEnv)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      (package private) javax.lang.model.type.TypeMirror methodReturnType​(javax.lang.model.element.ExecutableElement method, javax.lang.model.type.DeclaredType in)  
      (package private) com.google.common.collect.ImmutableMap<javax.lang.model.element.ExecutableElement,​javax.lang.model.type.TypeMirror> methodReturnTypes​(java.util.Set<javax.lang.model.element.ExecutableElement> methods, javax.lang.model.type.DeclaredType in)
      Returns a map containing the real return types of the given methods, knowing that they appear in the given type.
      private java.util.Map<javax.lang.model.element.Name,​javax.lang.model.element.ExecutableElement> noArgMethodsIn​(javax.lang.model.type.DeclaredType in)
      Constructs a map from name to method of the no-argument methods in the given type.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • processingEnv

        private final javax.annotation.processing.ProcessingEnvironment processingEnv
    • Constructor Detail

      • EclipseHack

        EclipseHack​(javax.annotation.processing.ProcessingEnvironment processingEnv)
    • Method Detail

      • methodReturnType

        javax.lang.model.type.TypeMirror methodReturnType​(javax.lang.model.element.ExecutableElement method,
                                                          javax.lang.model.type.DeclaredType in)
      • methodReturnTypes

        com.google.common.collect.ImmutableMap<javax.lang.model.element.ExecutableElement,​javax.lang.model.type.TypeMirror> methodReturnTypes​(java.util.Set<javax.lang.model.element.ExecutableElement> methods,
                                                                                                                                                    javax.lang.model.type.DeclaredType in)
        Returns a map containing the real return types of the given methods, knowing that they appear in the given type. This means that if the given type is say StringIterator implements Iterator<String> then we want the next() method to map to String, rather than the T that it returns as inherited from Iterator<T>. This method is in EclipseHack because if it weren't for this Eclipse bug it would be trivial. Unfortunately, versions of Eclipse up to at least 4.5 have a bug where the Types.asMemberOf(javax.lang.model.type.DeclaredType, javax.lang.model.element.Element) method throws IllegalArgumentException if given a method that is inherited from an interface. Fortunately, Eclipse's implementation of Elements.getAllMembers(javax.lang.model.element.TypeElement) does the type substitution that asMemberOf would have done. But javac's implementation doesn't. So we try the way that would work if Eclipse weren't buggy, and only if we get IllegalArgumentException do we use getAllMembers.
      • noArgMethodsIn

        private java.util.Map<javax.lang.model.element.Name,​javax.lang.model.element.ExecutableElement> noArgMethodsIn​(javax.lang.model.type.DeclaredType in)
        Constructs a map from name to method of the no-argument methods in the given type. We need this because an ExecutableElement returned by Elements.getAllMembers(javax.lang.model.element.TypeElement) will not compare equal to the original ExecutableElement if getAllMembers substituted type parameters, as it does in Eclipse.