List of usage examples for org.eclipse.jdt.internal.compiler.apt.dispatch BaseProcessingEnvImpl getFactory
public Factory getFactory()
From source file:org.mapstruct.ap.internal.util.workarounds.EclipseAsMemberOfWorkaround.java
License:Apache License
/** * Eclipse-specific implementation of {@link Types#asMemberOf(DeclaredType, Element)}. * <p>/*w w w. j av a 2 s . c om*/ * Returns {@code null} if the implementation could not determine the result. */ static TypeMirror asMemberOf(ProcessingEnvironment environment, DeclaredType containing, Element element) { ElementImpl elementImpl = tryCast(element, ElementImpl.class); BaseProcessingEnvImpl env = tryCast(environment, BaseProcessingEnvImpl.class); if (elementImpl == null || env == null) { return null; } ReferenceBinding referenceBinding = (ReferenceBinding) ((ElementImpl) environment.getTypeUtils() .asElement(containing))._binding; MethodBinding methodBinding = (MethodBinding) elementImpl._binding; // matches in super-classes have priority MethodBinding inSuperclassHiearchy = findInSuperclassHierarchy(methodBinding, referenceBinding); if (inSuperclassHiearchy != null) { return env.getFactory().newTypeMirror(inSuperclassHiearchy); } // if nothing was found, traverse the interfaces and collect all candidate methods that match List<MethodBinding> candidatesFromInterfaces = new ArrayList<MethodBinding>(); collectFromInterfaces(methodBinding, referenceBinding, new HashSet<ReferenceBinding>(), candidatesFromInterfaces); // there can be multiple matches for the same method name from adjacent interface hierarchies. Collections.sort(candidatesFromInterfaces, MostSpecificMethodBindingComparator.INSTANCE); if (!candidatesFromInterfaces.isEmpty()) { // return the most specific match return env.getFactory().newTypeMirror(candidatesFromInterfaces.get(0)); } return null; }