use of org.eclipse.jdt.internal.compiler.apt.model.ElementImpl in project mapstruct by mapstruct.
the class EclipseAsMemberOfWorkaround method asMemberOf.
/**
* Eclipse-specific implementation of {@link Types#asMemberOf(DeclaredType, Element)}.
* <p>
* 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;
}
use of org.eclipse.jdt.internal.compiler.apt.model.ElementImpl in project bazel-jdt-java-toolchain by salesforce.
the class AnnotationDiscoveryVisitor method resolveAnnotations.
private void resolveAnnotations(BlockScope scope, Annotation[] annotations, Binding currentBinding) {
int length = annotations == null ? 0 : annotations.length;
if (length == 0)
return;
boolean old = scope.insideTypeAnnotation;
scope.insideTypeAnnotation = true;
currentBinding.getAnnotationTagBits();
scope.insideTypeAnnotation = old;
ElementImpl element = (ElementImpl) _factory.newElement(currentBinding);
// discovery is never in terms of repeating annotation.
AnnotationBinding[] annotationBindings = element.getPackedAnnotationBindings();
for (AnnotationBinding binding : annotationBindings) {
ReferenceBinding annotationType = binding.getAnnotationType();
if (binding != null && Annotation.isAnnotationTargetAllowed(scope, annotationType, currentBinding)) {
// binding should be resolved, but in case it's not, ignore it: it could have been wrapped into a container.
TypeElement anno = (TypeElement) _factory.newElement(annotationType);
_annoToElement.put(anno, element);
}
}
}
Aggregations