Examples of ExecutableElement


Examples of javax.lang.model.element.ExecutableElement

public class MethodParser implements Parser {

    @Override
    public void check(Element element) throws UnsupportedUsageException {
        final ExecutableElement method = (ExecutableElement) element;
        final Set<Modifier> modifiers = method.getModifiers();
        final List<? extends VariableElement> parameters = method.getParameters();

        final boolean returnsVoid = method.getReturnType().getKind() == TypeKind.VOID;

        if (returnsVoid) {
            throw new UnsupportedUsageException(method, "Void methods are not supported");
        }
View Full Code Here

Examples of javax.lang.model.element.ExecutableElement

        return true;
    }

    @Override
    public void parse(Element element, Function<TypeElement, Type> storage) {
        final ExecutableElement method = (ExecutableElement) element;
        final TypeElement typeElement = (TypeElement) method.getEnclosingElement();
        final FirstClass annotation = method.getAnnotation(FirstClass.class);
        final ClosureName delegate = new ClosureName(method.getSimpleName().toString());;

        final ClosureName name;
       
        if (annotation.value().isEmpty()) {
            name = delegate;
        } else {
            name = new ClosureName(annotation.value());
        }
       
        final boolean isStatic = method.getModifiers().contains(Modifier.STATIC);

        final Name parameterType;

        if (isStatic) {
            final VariableElement firstParameter = method.getParameters().get(0);
            parameterType = new Name(firstParameter.asType().toString());
        } else {
            parameterType = new Name(typeElement.getQualifiedName().toString());
        }

        final Closure closure;

        if (method.getReturnType().getKind() == TypeKind.BOOLEAN) {
            closure = new Closure(name, delegate, parameterType, isStatic, annotation.nullsafe());
        } else {
            final Name returnType = new Name(method.getReturnType().toString());
            closure = new Closure(name, delegate, parameterType, returnType, isStatic, annotation.nullsafe());
        }

        final Type type = storage.apply(typeElement);
        Preconditions.checkNotNull(type, "No type found for %s", typeElement);
View Full Code Here

Examples of javax.lang.model.element.ExecutableElement

        if (!isOverridingMethod) {
            switch (env.currElement.getKind()) {
                case METHOD:
                case CONSTRUCTOR: {
                    ExecutableElement ee = (ExecutableElement) env.currElement;
                    checkParamsDocumented(ee.getTypeParameters());
                    checkParamsDocumented(ee.getParameters());
                    switch (ee.getReturnType().getKind()) {
                        case VOID:
                        case NONE:
                            break;
                        default:
                            if (!foundReturn
                                    && !foundInheritDoc
                                    && !env.types.isSameType(ee.getReturnType(), env.java_lang_Void)) {
                                reportMissing("dc.missing.return");
                            }
                    }
                    checkThrowsDocumented(ee.getThrownTypes());
                }
            }
        }

        return null;
View Full Code Here

Examples of javax.lang.model.element.ExecutableElement

        } else if (isThrowable(ex.asType())) {
            switch (env.currElement.getKind()) {
                case CONSTRUCTOR:
                case METHOD:
                    if (isCheckedException(ex.asType())) {
                        ExecutableElement ee = (ExecutableElement) env.currElement;
                        checkThrowsDeclared(exName, ex.asType(), ee.getThrownTypes());
                    }
                    break;
                default:
                    env.messages.error(REFERENCE, tree, "dc.invalid.throws");
            }
View Full Code Here

Examples of javax.lang.model.element.ExecutableElement

       * 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()));
    }
    if (!isInstanceRequest && requireStaticDomainMethods
        && !domainMethod.getModifiers().contains(Modifier.STATIC)) {
      state.poison(clientMethodElement, Messages.domainMethodWrongModifier(true, domainMethod
          .getSimpleName()));
    }

    // Record the mapping
    state.addMapping(clientMethodElement, domainMethod);
View Full Code Here

Examples of javax.lang.model.element.ExecutableElement

   * non-static. Check that {@code findFoo()} exists, is static, returns an
   * appropriate type, and its parameter is assignable from the return value
   * from {@code getId()}.
   */
  private void checkDomainEntityMethods(State state) {
    ExecutableElement getId =
        new MethodFinder("getId", null, Collections.<TypeMirror> emptyList(), false, state).scan(
            domainElement, state);
    if (getId == null) {
      state.poison(checkedElement, Messages.domainNoGetId(domainElement.asType()));
    } else {
      if (getId.getModifiers().contains(Modifier.STATIC)) {
        state.poison(checkedElement, Messages.domainGetIdStatic());
      }

      // Can only check findFoo() if we have a getId
      ExecutableElement find =
          new MethodFinder("find" + domainElement.getSimpleName(), domainElement.asType(),
              Collections.singletonList(getId.getReturnType()), false, state).scan(domainElement,
              state);
      if (find == null) {
        state.warn(checkedElement, Messages.domainMissingFind(domainElement.asType(), domainElement
            .getSimpleName(), getId.getReturnType(), checkedElement.getSimpleName()));
      } else if (!find.getModifiers().contains(Modifier.STATIC)) {
        state.poison(checkedElement, Messages.domainFindNotStatic(domainElement.getSimpleName()));
      }
    }

    ExecutableElement getVersion =
        new MethodFinder("getVersion", null, Collections.<TypeMirror> emptyList(), false, state)
            .scan(domainElement, state);
    if (getVersion == null) {
      state.poison(checkedElement, Messages.domainNoGetVersion(domainElement.asType()));
    } else if (getVersion.getModifiers().contains(Modifier.STATIC)) {
      state.poison(checkedElement, Messages.domainGetVersionStatic());
    }
  }
View Full Code Here

Examples of javax.lang.model.element.ExecutableElement

            for (Element e : roundEnv.getElementsAnnotatedWith(SystemConfigFactoryConstructor.class))
            {
                if(e.getKind() == ElementKind.CONSTRUCTOR)
                {
                    ExecutableElement constructorElement = (ExecutableElement) e;
                    String factoryName = generateObjectFactory(filer, constructorElement);
                }
            }

        }
View Full Code Here

Examples of javax.lang.model.element.ExecutableElement

        for (Element e : roundEnv.getElementsAnnotatedWith(annotationElement))
        {
            checkAnnotationIsOnMethodInInterface(annotationElement, e);

            ExecutableElement methodElement = (ExecutableElement) e;

            checkInterfaceExtendsConfiguredObject(annotationElement, methodElement);
            checkMethodTakesNoArgs(annotationElement, methodElement);
            checkMethodName(annotationElement, methodElement);
            checkMethodReturnType(annotationElement, methodElement);
View Full Code Here

Examples of javax.lang.model.element.ExecutableElement

        for (Element e : roundEnv.getElementsAnnotatedWith(annotationElement))
        {
            checkAnnotationIsOnMethodInInterface(annotationElement, e);

            ExecutableElement methodElement = (ExecutableElement) e;

            checkInterfaceExtendsConfiguredObject(annotationElement, methodElement);
            checkMethodTakesNoArgs(annotationElement, methodElement);
            checkMethodName(annotationElement, methodElement);
            checkTypeAgreesWithName(annotationElement, methodElement);
View Full Code Here

Examples of javax.lang.model.element.ExecutableElement

            for (Element e : roundEnv.getElementsAnnotatedWith(ManagedObjectFactoryConstructor.class))
            {
                if(e.getKind() == ElementKind.CONSTRUCTOR)
                {
                    ExecutableElement constructorElement = (ExecutableElement) e;
                    String factoryName = generateObjectFactory(filer, constructorElement);
                }
            }

        }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.