Package javax.lang.model.type

Examples of javax.lang.model.type.ExecutableType


    DeclaredType type = null;
    if ( elem.asType() instanceof DeclaredType ) {
      type = ( (DeclaredType) elem.asType() );
    }
    else if ( elem.asType() instanceof ExecutableType ) {
      ExecutableType executableType = (ExecutableType) elem.asType();
      if ( executableType.getReturnType() instanceof DeclaredType ) {
        type = (DeclaredType) executableType.getReturnType();
      }
    }
    return type;
  }
View Full Code Here


    public ExecutableElement visitExecutable(ExecutableElement domainMethodElement, State state) {
      // Quick check for name, paramer count, and return type assignability
      if (domainMethodElement.getSimpleName().contentEquals(name)
          && domainMethodElement.getParameters().size() == params.size()) {
        // Pick up parameterizations in domain type
        ExecutableType domainMethod = viewIn(domainType, domainMethodElement, state);

        boolean returnTypeMatches;
        if (returnType == null) {
          /*
           * This condition is for methods that we don't really care about the
           * domain return types (for getId(), getVersion()).
           */
          returnTypeMatches = true;
        } else {
          TypeMirror domainReturn =
              TypeSimplifier.simplify(domainMethod.getReturnType(), boxReturnType, state);
          // The isSameType handles the NONE case.
          returnTypeMatches = state.types.isSubtype(domainReturn, returnType);
        }
        if (returnTypeMatches) {
          boolean paramsMatch = true;
          Iterator<TypeMirror> lookFor = params.iterator();
          Iterator<? extends TypeMirror> domainParam = domainMethod.getParameterTypes().iterator();
          while (lookFor.hasNext()) {
            assert domainParam.hasNext();
            TypeMirror requestedType = lookFor.next();
            TypeMirror paramType = TypeSimplifier.simplify(domainParam.next(), false, state);
            if (!state.types.isSubtype(requestedType, paramType)) {
View Full Code Here

        && constructorFound.ordinal() <= v.ordinal()) {
      return null;
    }

    subtype.clearSuperArguments();
    ExecutableType execType =
        (ExecutableType) utils.typeUtils.asMemberOf(typeMirror, e);
    List<? extends TypeMirror> paramTypes = execType.getParameterTypes();
    for (TypeMirror t : paramTypes) {
      subtype.addSuperArgument(utils.getTypeNameForType(t));
    }

    constructorFound = v;
View Full Code Here

     * For enum types, synthesized methods values() and
     * valueOf(String) are reflected by the API but must not be
     * reproduced in the mock.
     */
    if (p.getKind() == ElementKind.ENUM) {
      ExecutableType t = (ExecutableType) e.asType();
      if (name.equals("values")) {
        if (t.getParameterTypes().isEmpty()) {
          return null;
        }
      } else if (name.equals("valueOf")) {
        List<TypeMirror> valueOfParameterTypes =
            Collections.singletonList(
                utils.elementUtils
                .getTypeElement("java.lang.String").asType());
        if (t.getParameterTypes().equals(valueOfParameterTypes)) {
          return null;
        }
      }
    }

View Full Code Here

  public Void visitExecutable(ExecutableElement x, State state) {
    if (shouldIgnore(x, state)) {
      return null;
    }

    ExecutableType xType = viewIn(checkedElement, x, state);
    if (isGetter(x, state)) {
      TypeMirror returnType = xType.getReturnType();
      if (!state.isTransportableType(returnType)) {
        // XXX(t.broyer): should we really pass the "resolved" type? that could
        // result in several errors being reported on the same method, but on
        // the other hand tells exactly which type it is that isn't
        // transportable.
        // For instance, a List<T> might be transportable if T is
        // java.lang.String in a sub-interface, but not if T is some
        // untransportable type in another sub-interface
        state.poison(x, Messages.untransportableType(returnType));
      }
    } else if (!isSetter(x, state)) {
      state.poison(x, Messages.proxyOnlyGettersSetters());
    }

    // check parameters (we do not defer to visitVariable, as we need the
    // resolved generics)
    int i = 0;
    for (TypeMirror parameterType : xType.getParameterTypes()) {
      if (!state.isTransportableType(parameterType)) {
        // see comments above about the returnType
        state.poison(x.getParameters().get(i), Messages.untransportableType(parameterType));
      }
      i++;
View Full Code Here

    if (currentTypeIsProxy && name.contentEquals("stableId")
        && clientMethodElement.getParameters().isEmpty()) {
      return null;
    }

    ExecutableType clientMethod = viewIn(checkedElement, clientMethodElement, state);
    List<TypeMirror> lookFor = new ArrayList<TypeMirror>();
    // Convert client method signature to domain types
    TypeMirror returnType;
    try {
      returnType = convertToDomainTypes(clientMethod, lookFor, clientMethodElement, state);
    } catch (UnmappedTypeException e) {
      /*
       * Unusual: this would happen if a RequestContext for which we have a
       * resolved domain service method uses unresolved proxy types. For
       * example, the RequestContext uses a @Service annotation, while one or
       * more proxy types use @ProxyForName("") and specify a domain type not
       * available to the compiler.
       */
      return null;
    }

    ExecutableElement domainMethod;
    if (currentTypeIsProxy && isSetter(clientMethodElement, state)) {
      // Look for void setFoo(...)
      domainMethod =
          new MethodFinder(name, state.types.getNoType(TypeKind.VOID), lookFor, false, state).scan(
              domainElement, state);
      if (domainMethod == null) {
        // Try a builder style
        domainMethod =
            new MethodFinder(name, domainElement.asType(), lookFor, false, state).scan(
                domainElement, state);
      }
    } else {
      /*
       * The usual case for getters and all service methods. Only box return
       * types when matching context methods since there's a significant
       * semantic difference between a null Integer and 0.
       */
      domainMethod =
          new MethodFinder(name, returnType, lookFor, !currentTypeIsProxy, state).scan(
              domainElement, state);
    }

    if (domainMethod == null) {
      // Did not find a service method
      StringBuilder sb = new StringBuilder();
      sb.append(returnType).append(" ").append(name).append("(");
      boolean first = true;
      for (TypeMirror param : lookFor) {
        if (!first) {
          sb.append(", ");
        }
        sb.append(param);
        first = false;
      }
      sb.append(")");

      state.poison(clientMethodElement, Messages.domainMissingMethod(sb));
      return null;
    }

    // Check if the method is public
    if (!domainMethod.getModifiers().contains(Modifier.PUBLIC)) {
      state.poison(clientMethodElement, Messages.domainMethodNotPublic(
          domainMethod.getSimpleName()));
    }

    /*
     * Check the domain method for any requirements for it to be static.
     * InstanceRequests assume instance methods on the domain type.
     */
    boolean isInstanceRequest =
        state.types.isSubtype(clientMethod.getReturnType(), state.instanceRequestType);

    if ((isInstanceRequest || requireInstanceDomainMethods)
        && domainMethod.getModifiers().contains(Modifier.STATIC)) {
      state.poison(clientMethodElement, Messages.domainMethodWrongModifier(false, domainMethod
          .getSimpleName()));
View Full Code Here

    public ExecutableElement visitExecutable(ExecutableElement domainMethodElement, State state) {
      // Quick check for name, paramer count, and return type assignability
      if (domainMethodElement.getSimpleName().contentEquals(name)
          && domainMethodElement.getParameters().size() == params.size()) {
        // Pick up parameterizations in domain type
        ExecutableType domainMethod = viewIn(domainType, domainMethodElement, state);

        boolean returnTypeMatches;
        if (returnType == null) {
          /*
           * This condition is for methods that we don't really care about the
           * domain return types (for getId(), getVersion()).
           */
          returnTypeMatches = true;
        } else {
          TypeMirror domainReturn =
              TypeSimplifier.simplify(domainMethod.getReturnType(), boxReturnType, state);
          // The isSameType handles the NONE case.
          returnTypeMatches = state.types.isSubtype(domainReturn, returnType);
        }
        if (returnTypeMatches) {
          boolean paramsMatch = true;
          Iterator<TypeMirror> lookFor = params.iterator();
          Iterator<? extends TypeMirror> domainParam = domainMethod.getParameterTypes().iterator();
          while (lookFor.hasNext()) {
            assert domainParam.hasNext();
            TypeMirror requestedType = lookFor.next();
            TypeMirror paramType = TypeSimplifier.simplify(domainParam.next(), false, state);
            if (!state.types.isSubtype(requestedType, paramType)) {
View Full Code Here

  public Void visitExecutable(ExecutableElement x, State state) {
    if (shouldIgnore(x, state)) {
      return null;
    }
    // resolve type parameters, if any
    ExecutableType xType = viewIn(checkedElement, x, state);
    TypeMirror returnType = xType.getReturnType();
    if (state.types.isAssignable(returnType, state.requestType)) {
      // Extract Request<Foo> type
      DeclaredType asRequest = (DeclaredType) State.viewAs(state.requestType, returnType, state);
      if (asRequest.getTypeArguments().isEmpty()) {
        state.poison(x, Messages.rawType());
      } else {
        TypeMirror requestReturn = asRequest.getTypeArguments().get(0);
        if (!state.isTransportableType(requestReturn)) {
          state.poison(x, Messages.untransportableType(requestReturn));
        }
      }
    } else if (state.types.isAssignable(returnType, state.instanceRequestType)) {
      // Extract InstanceRequest<FooProxy, String>
      DeclaredType asInstanceRequest =
          (DeclaredType) State.viewAs(state.instanceRequestType, returnType, state);
      if (asInstanceRequest.getTypeArguments().isEmpty()) {
        state.poison(x, Messages.rawType());
      } else {
        TypeMirror instanceType = asInstanceRequest.getTypeArguments().get(0);
        state.maybeScanProxy((TypeElement) state.types.asElement(instanceType));
        TypeMirror requestReturn = asInstanceRequest.getTypeArguments().get(1);
        if (!state.isTransportableType(requestReturn)) {
          state.poison(x, Messages.untransportableType(requestReturn));
        }
      }
    } else if (!isSetter(x, state)) {
      state.poison(x, Messages.contextRequiredReturnTypes(state.requestType.asElement()
          .getSimpleName(), state.instanceRequestType.asElement().getSimpleName()));
    }

    // check parameters (we do not defer to visitVariable, as we need the
    // resolved generics)
    int i = 0;
    for (TypeMirror parameterType : xType.getParameterTypes()) {
      if (!state.isTransportableType(parameterType)) {
        // see comments in ProxyScanner#visitExecutable
        state.poison(x.getParameters().get(i), Messages.untransportableType(parameterType));
      }
      i++;
View Full Code Here

    }
    if (!x.getParameters().isEmpty()) {
      state.poison(x, Messages.factoryNoMethodParameters());
    }
    // resolve type parameters, if any
    ExecutableType xType = viewIn(checkedElement, x, state);
    TypeMirror returnType = xType.getReturnType();
    if (state.types.isAssignable(returnType, state.requestContextType)) {
      Element returnTypeElement = state.types.asElement(returnType);
      if (!returnTypeElement.getKind().equals(ElementKind.INTERFACE)) {
        state.poison(x, Messages.factoryMustReturnInterface(returnTypeElement.getSimpleName()));
      } else {
View Full Code Here

        TypeElement extendingType = declaration.get().extendingType();
        List<ExecutableElement> supertypeMethods =
            ElementFilter.methodsIn(elements.getAllMembers(extendingType));
        for (ExecutableElement supertypeMethod : supertypeMethods) {
          if (supertypeMethod.getModifiers().contains(Modifier.ABSTRACT)) {
            ExecutableType methodType = Elements2.getExecutableElementAsMemberOf(
                types, supertypeMethod, extendingType);
            implemetationMethodDescriptors.add(new ImplemetationMethodDescriptor.Builder()
                .name(supertypeMethod.getSimpleName().toString())
                .returnType(getAnnotatedType(element).getQualifiedName().toString())
                .publicMethod()
                .passedParameters(Parameter.forParameterList(
                    supertypeMethod.getParameters(), methodType.getParameterTypes()))
                .build());
          }
        }
        for (TypeElement implementingType : declaration.get().implementingTypes()) {
          List<ExecutableElement> interfaceMethods =
              ElementFilter.methodsIn(elements.getAllMembers(implementingType));
          for (ExecutableElement interfaceMethod : interfaceMethods) {
            if (interfaceMethod.getModifiers().contains(Modifier.ABSTRACT)) {
              ExecutableType methodType = Elements2.getExecutableElementAsMemberOf(
                  types, interfaceMethod, implementingType);
              implemetationMethodDescriptors.add(new ImplemetationMethodDescriptor.Builder()
                  .name(interfaceMethod.getSimpleName().toString())
                  .returnType(getAnnotatedType(element).getQualifiedName().toString())
                  .publicMethod()
                  .passedParameters(Parameter.forParameterList(
                      interfaceMethod.getParameters(), methodType.getParameterTypes()))
                  .build());
            }
          }
        }
      }
View Full Code Here

TOP

Related Classes of javax.lang.model.type.ExecutableType

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.