static TypeMirror asInheritedMemberReturnType( ProcessingEnvironment processing, TypeElement typeElement, ExecutableElement method) { ExecutableType asMethodOfType = (ExecutableType) processing.getTypeUtils() .asMemberOf((DeclaredType) typeElement.asType(), method); return asMethodOfType.getReturnType(); }
final BoundAccessor bind(TypeMirror target) { // asMemberOf wrongly implemented in ECJ, // we use it for fields only in Javac // but we expect it is already resolved TypeMirror type = !inEclipseCompiler ? types.asMemberOf((DeclaredType) target, element) : element.asType(); if (type instanceof ExecutableType) { type = ((ExecutableType) type).getReturnType(); } return new BoundAccessor(this, target, type); }
ExecutableType executableType = (ExecutableType) types.asMemberOf(enclosing, method); List<? extends TypeMirror> resolvedParameterTypes = executableType.getParameterTypes(); List<? extends TypeMirror> resolvedThrownTypes = executableType.getThrownTypes();
@Override public boolean test(ExecutableElement element) { if (element.getParameters().size() != 1) { return false; } if (!element.getSimpleName().contentEquals("mergeFrom")) { return false; } ExecutableType method = (ExecutableType) types.asMemberOf(builder, element); if (!types.isSubtype(parameter, method.getParameterTypes().get(0))) { return false; } return true; } }
protected static ExecutableType viewIn(TypeElement lookIn, ExecutableElement methodElement, State state) { // Do not use state.types.getDeclaredType, as we really want a // "prototypical" type, and not a raw type. // This is important when a proxy maps to a generic domain type: // state.types.getDeclaredType without typeArgs would return the raw type, // and asMemberOf would then return an ExecutableType using raw types too. // For instance, if a class Foo<T> contains a method whose return type is // List<String> (note it doesn't even make use of the T type parameter), // then if we were to use raw types, the returned type of the ExecutableType // would be the raw type java.util.List, and not List<String>. Using // asType(), we'd get the expected List<String> though; and for a List<T>, // we'd get a List<Object> (or whichever upper bound for the T type // parameter). try { return (ExecutableType) state.types.asMemberOf((DeclaredType) lookIn.asType(), methodElement); } catch (IllegalArgumentException e) { return (ExecutableType) methodElement.asType(); } }
@Override public boolean test(ExecutableElement element) { if (element.getParameters().size() != 0) { return false; } if (!element.getSimpleName().contentEquals("toBuilder")) { return false; } ExecutableType method = (ExecutableType) types.asMemberOf(datatype, element); if (!types.isSubtype(method.getReturnType(), builder)) { return false; } return true; } }
/** * Determines the return type of {@code method}, if called on an instance of type {@code type}. * * <p>For instance, in this example, myY.getProperty() returns List<T>, not T:<pre><code> * interface X<T> { * T getProperty(); * } * @FreeBuilder interface Y<T> extends X<List<T>> { }</code></pre> * * <p>(Unfortunately, a bug in Eclipse prevents us handling these cases correctly at the moment. * javac works fine.) */ public static TypeMirror getReturnType(TypeElement type, ExecutableElement method, Types types) { try { ExecutableType executableType = (ExecutableType) types.asMemberOf((DeclaredType) type.asType(), method); return executableType.getReturnType(); } catch (IllegalArgumentException e) { // Eclipse incorrectly throws an IllegalArgumentException here: // "element is not valid for the containing declared type" // As a workaround for the common case, fall back to the declared return type. return method.getReturnType(); } }
/** Returns the functional types accepted by {@code methodName} on {@code type}. */ public static List<FunctionalType> functionalTypesAcceptedByMethod( DeclaredType type, String methodName, Elements elements, Types types) { TypeElement typeElement = asElement(type); return methodsOn(typeElement, elements, errorType -> { }) .stream() .filter(method -> method.getSimpleName().contentEquals(methodName) && method.getParameters().size() == 1) .flatMap(method -> { ExecutableType methodType = (ExecutableType) types.asMemberOf(type, method); TypeMirror parameter = getOnlyElement(methodType.getParameterTypes()); return maybeFunctionalType(parameter, elements, types) .map(Stream::of).orElse(Stream.of()); }) .collect(toList()); }
public static Optional<FunctionalType> maybeFunctionalType( DeclaredType type, Elements elements, Types types) { TypeElement typeElement = asElement(type); if (!typeElement.getKind().isInterface()) { return Optional.empty(); } Set<ExecutableElement> abstractMethods = only(ABSTRACT, methodsOn(typeElement, elements, errorType -> { })); if (abstractMethods.size() != 1) { return Optional.empty(); } ExecutableElement method = getOnlyElement(abstractMethods); ExecutableType methodType = (ExecutableType) types.asMemberOf(type, method); return Optional.of(new FunctionalType( Type.from(type), method.getSimpleName().toString(), methodType.getParameterTypes(), methodType.getReturnType())); }
@Override public TypeMirror asMemberOf(DeclaredType arg0, Element arg1) { return realImpl.asMemberOf(arg0, arg1); }
/** * Get the Type for given method as part of usedMapper. Possibly parameterized types in method declaration will be * evaluated to concrete types then. * * @param includingType the type on which's scope the method type shall be evaluated * @param method the method * * @return the ExecutableType representing the method as part of usedMapper */ public TypeMirror getMethodType(DeclaredType includingType, Element method) { return typeUtils.asMemberOf( includingType, method ); }
@Override public TypeMirror asMemberOf(DeclaredType containing, Element element) { return types.asMemberOf(containing, element); } }
@Override public TypeMirror asMemberOf(DeclaredType arg0, Element arg1) { return realImpl.asMemberOf(arg0, arg1); }
private TypeMirror getParameterType( VariableElement var, ExecutableElement element, TypeElement parent , CompilationController controller ) { ExecutableType method = (ExecutableType)controller.getTypes().asMemberOf( (DeclaredType)parent.asType(), element); List<? extends TypeMirror> parameterTypes = method.getParameterTypes(); List<? extends VariableElement> parameters = element.getParameters(); int paramIndex = parameters.indexOf(var); return parameterTypes.get(paramIndex); }
protected ExecutableInformation(@Nonnull Element element, @Nonnull DeclaredType containingType, @Nonnull TypeInformation typeInformation) { super(element, StaticProcessingEnvironment.getTypeUtils().asMemberOf(containingType, element), containingType); final @Nonnull List<MethodParameterInformation> parameters = new ArrayList<>(getElement().getParameters().size()); for (@Nonnull VariableElement variableElement : getElement().getParameters()) { parameters.add(new MethodParameterInformation(variableElement, getContainingType(), typeInformation)); } this.parameters = FiniteIterable.of(parameters); }
public MethodWrapper(ExecutableElement method, DeclaredType declaredType, MapperGeneratorContext context) { this.method = method; this.parentType = declaredType; this.context = context; // Try to resolve any inherited or declared generic type using asMemberOf processed class this.executableType = (ExecutableType) context.type.asMemberOf(parentType, method); AnnotationWrapper annotationWrapper = AnnotationWrapper.buildFor(context, method, Mapper.class); if (annotationWrapper != null) { ignoreMissingProperties = annotationWrapper.getAsBoolean("ignoreMissingProperties"); } }
public TypeMirror asMemberOf(DeclaredType containing, Element element) { while (containing instanceof DecoratedDeclaredType) { containing = ((DecoratedDeclaredType) containing).getDelegate(); } while (element instanceof DecoratedElement) { element = ((DecoratedElement) element).getDelegate(); } return TypeMirrorDecorator.decorate(delegate.asMemberOf(containing, element), this.env); }
public TypeMirror asMemberOf(DeclaredType containing, Element element) { while (containing instanceof DecoratedDeclaredType) { containing = ((DecoratedDeclaredType) containing).getDelegate(); } while (element instanceof DecoratedElement) { element = ((DecoratedElement) element).getDelegate(); } return TypeMirrorDecorator.decorate(delegate.asMemberOf(containing, element), this.env); }
@Override public TypeMirror getType( WebBeansModelImplementation model, DeclaredType parent, VariableElement element ) { return model.getHelper().getCompilationController().getTypes(). asMemberOf(parent, element ); }
public @Nullable TypeMirror getReturnType() { if (!hasReturnType()) { return null; } final @Nonnull TypeMirror typeMirror = StaticProcessingEnvironment.getTypeUtils().asMemberOf(getContainingType(), getElement()); Require.that(typeMirror instanceof ExecutableType).orThrow("Expected ExecutableType, but got $", getContainingType()); final @Nonnull ExecutableType executableType = (ExecutableType) typeMirror; return executableType.getReturnType(); }