Package javax.lang.model.element

Examples of javax.lang.model.element.ExecutableElement


    if (!isMethod())
    {
      return false;
    }

    ExecutableElement ex = (ExecutableElement)e;

    if (ex.getParameters().size() > 0)
    {
      return false;
    }

    if (ex.getReturnType().getKind().equals(TypeKind.VOID))
    {
      return false;
    }

    String name = getName();
View Full Code Here


    if (!isMethod())
    {
      return false;
    }

    ExecutableElement ex = (ExecutableElement)e;

    if (ex.getParameters().size() != 1)
    {
      return false;
    }

    if (!ex.getReturnType().getKind().equals(TypeKind.VOID))
    {
      return false;
    }

    String name = getName();
View Full Code Here

        for (TypeMirror iface: element.getInterfaces()) {
            newClass._implements((AbstractJClass)toJType(iface, environment));
        }
        for (Element enclosedElement: element.getEnclosedElements()) {
            if (enclosedElement.getKind().equals(ElementKind.METHOD)) {
                ExecutableElement executable = (ExecutableElement)enclosedElement;
                JMethod method = newClass.method(toJMod(executable.getModifiers()), codeModel.VOID, executable.getSimpleName().toString());
                TypeEnvironment methodEnvironment = environment.enclosed();
                Annotator methodAnnotator = new Annotator(method, environment);
                methodAnnotator.annotate(executable.getAnnotationMirrors());
                for (TypeParameterElement parameter: executable.getTypeParameters()) {
                    JTypeVar typeVariable = method.generify(parameter.getSimpleName().toString());
                    methodEnvironment.put(typeVariable.name(), typeVariable);
                    for (TypeMirror type: parameter.getBounds()) {
                        typeVariable.bound((AbstractJClass)toJType(type, methodEnvironment));
                    }
                }
                method.type(toJType(executable.getReturnType(), methodEnvironment));
                for (TypeMirror type: executable.getThrownTypes()) {
                    AbstractJClass throwable = (AbstractJClass)toJType(type, methodEnvironment);
                    method._throws(throwable);
                }

                List<? extends VariableElement> parameters = executable.getParameters();
                int n = 0;
                for (VariableElement variable: parameters) {
                    String parameterName = variable.getSimpleName().toString();
                    TypeMirror parameterTypeMirror = variable.asType();
                    AbstractJType parameterType = toJType(parameterTypeMirror, methodEnvironment);

                    JVar param;
                    if (executable.isVarArgs() && n == parameters.size() - 1) {
                        param = method.varParam(toJMod(variable.getModifiers()), parameterType.elementType(), parameterName);
                    } else {
                        param = method.param(toJMod(variable.getModifiers()), parameterType, parameterName);
                    }
                    Annotator parametorAnnotator = new Annotator(param, methodEnvironment);
View Full Code Here

   *
   * @return A possibly non-empty set of constraint check errors, never null.
   */
  private Set<ConstraintCheckError> checkMessageAttribute(TypeElement element) {

    ExecutableElement messageMethod = getMethod( element, "message" );

    if ( messageMethod == null ) {
      return CollectionHelper.asSet(
          new ConstraintCheckError( element, null, "CONSTRAINT_TYPE_MUST_DECLARE_MESSAGE_MEMBER" )
      );
    }

    if ( !typeUtils.isSameType(
        annotationApiHelper.getMirrorForType( String.class ), messageMethod.getReturnType()
    ) ) {
      return CollectionHelper.asSet(
          new ConstraintCheckError( messageMethod, null, "RETURN_TYPE_MUST_BE_STRING" )
      );
    }
View Full Code Here

   *
   * @return A possibly non-empty set of constraint check errors, never null.
   */
  private Set<ConstraintCheckError> checkGroupsAttribute(TypeElement element) {

    ExecutableElement groupsMethod = getMethod( element, "groups" );

    if ( groupsMethod == null ) {
      return CollectionHelper.asSet(
          new ConstraintCheckError( element, null, "CONSTRAINT_TYPE_MUST_DECLARE_GROUPS_MEMBER" )
      );
    }

    DeclaredType type = getComponentTypeOfArrayReturnType( groupsMethod );

    if ( type == null ) {
      return CollectionHelper.asSet(
          new ConstraintCheckError( groupsMethod, null, "RETURN_TYPE_MUST_BE_CLASS_ARRAY" )
      );
    }

    boolean typeHasNameClass = type.asElement().getSimpleName().contentEquals( "Class" );
    boolean typeHasExactlyOneTypeArgument = type.getTypeArguments().size() == 1;
    boolean typeArgumentIsUnboundWildcard = validateWildcardBounds( type.getTypeArguments().get( 0 ), null, null );

    if ( !( typeHasNameClass && typeHasExactlyOneTypeArgument && typeArgumentIsUnboundWildcard ) ) {
      return CollectionHelper.asSet(
          new ConstraintCheckError( groupsMethod, null, "RETURN_TYPE_MUST_BE_CLASS_ARRAY" )
      );
    }

    if ( !isEmptyArray( groupsMethod.getDefaultValue() ) ) {
      return CollectionHelper.asSet(
          new ConstraintCheckError( groupsMethod, null, "DEFAULT_VALUE_MUST_BE_EMPTY_ARRAY" )
      );
    }

View Full Code Here

   *
   * @return A possibly non-empty set of constraint check errors, never null.
   */
  private Set<ConstraintCheckError> checkPayloadAttribute(TypeElement element) {

    ExecutableElement payloadMethod = getMethod( element, "payload" );

    if ( payloadMethod == null ) {
      return CollectionHelper.asSet(
          new ConstraintCheckError( element, null, "CONSTRAINT_TYPE_MUST_DECLARE_PAYLOAD_MEMBER" )
      );
    }

    DeclaredType type = getComponentTypeOfArrayReturnType( payloadMethod );

    if ( type == null ) {
      return CollectionHelper.asSet(
          new ConstraintCheckError( payloadMethod, null, "PAYLOAD_RETURN_TYPE_MUST_BE_CLASS_ARRAY" )
      );
    }

    boolean typeHasNameClass = type.asElement().getSimpleName().contentEquals( "Class" );
    boolean typeHasExactlyOneTypeArgument = type.getTypeArguments().size() == 1;
    boolean typeArgumentIsWildcardWithPayloadExtendsBound = validateWildcardBounds(
        type.getTypeArguments().get( 0 ),
        annotationApiHelper.getDeclaredTypeByName( BeanValidationTypes.PAYLOAD ),
        null
    );

    if ( !( typeHasNameClass && typeHasExactlyOneTypeArgument && typeArgumentIsWildcardWithPayloadExtendsBound ) ) {
      return CollectionHelper.asSet(
          new ConstraintCheckError( payloadMethod, null, "PAYLOAD_RETURN_TYPE_MUST_BE_CLASS_ARRAY" )
      );
    }

    if ( !isEmptyArray( payloadMethod.getDefaultValue() ) ) {
      return CollectionHelper.asSet(
          new ConstraintCheckError( payloadMethod, null, "PAYLOAD_DEFAULT_VALUE_MUST_BE_EMPTY_ARRAY" )
      );
    }

View Full Code Here

  @Override
  public List<? extends Element> getEnclosedElements() {
    ReferenceBinding binding = (ReferenceBinding)_binding;
    List<Element> enclosed = new ArrayList<Element>(binding.fieldCount() + binding.methods().length);
    for (MethodBinding method : binding.methods()) {
      ExecutableElement executable = new ExecutableElementImpl(_env, method);
      enclosed.add(executable);
    }
    for (FieldBinding field : binding.fields()) {
      // TODO no field should be excluded according to the JLS
      if (!field.isSynthetic()) {
View Full Code Here

      MethodBinding method = pair.getMethodBinding();
      if (method == null) {
        // ideally we should be able to create a fake ExecutableElementImpl
        continue;
      }
      ExecutableElement e = new ExecutableElementImpl(_env, method);
      AnnotationValue v = new AnnotationMemberValue(_env, pair.getValue(), method);
      valueMap.put(e, v);
    }
    return Collections.unmodifiableMap(valueMap);
  }
View Full Code Here

      // if binding is in ElementValuePair list, then get value from there
      boolean foundExplicitValue = false;
      for (int i = 0; i < pairs.length; ++i) {
        MethodBinding explicitBinding = pairs[i].getMethodBinding();
        if (method == explicitBinding) {
          ExecutableElement e = new ExecutableElementImpl(_env, explicitBinding);
          AnnotationValue v = new AnnotationMemberValue(_env, pairs[i].getValue(), explicitBinding);
          valueMap.put(e, v);
          foundExplicitValue = true;
          break;
        }
      }
      // else get default value if one exists
      if (!foundExplicitValue) {
        Object defaultVal = method.getDefaultValue();
        if (null != defaultVal) {
          ExecutableElement e = new ExecutableElementImpl(_env, method);
          AnnotationValue v = new AnnotationMemberValue(_env, defaultVal, method);
          valueMap.put(e, v);
        }
      }
    }
View Full Code Here

    if (element.getKind() != ElementKind.METHOD) {
      error("@Test must prefix a method -- " + element
          + " is not a method");
      return;
    }
    ExecutableElement ee = (ExecutableElement) element;
    if (ee.getModifiers().contains(Modifier.STATIC)) {
      warn("Method "
          + elementAsString(ee)
          + "\n\tis prefixed with @Test and is static\n\tA test method can't be static");
    }
    if (!ee.getModifiers().contains(Modifier.PUBLIC)) {
      warn("Method "
          + elementAsString(ee)
          + "\n\tis prefixed with @Test and is not public \n\tA test method must be public");
    }
    if (!TypeKind.VOID.equals(ee.getReturnType().getKind())) {
      warn("Method "
          + elementAsString(ee)
          + "\n\tis prefixed with @Test and is not void\n\tA test method must be void");
    }
    if (ee.getParameters().size() != 0) {
      warn("Method"
          + elementAsString(ee)
          + "\n\tis prefixed with @Test and is not 0-args\n\tA test method must be 0-args");
    }
  }
View Full Code Here

TOP

Related Classes of javax.lang.model.element.ExecutableElement

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.