Package javax.lang.model.element

Examples of javax.lang.model.element.ExecutableElement


      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

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

        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.name().isEmpty()) {
            name = delegate;
        } else {
            name = new ClosureName(annotation.name());
        }

        final List<? extends VariableElement> parameters = method.getParameters();
        final boolean isStatic = method.getModifiers().contains(Modifier.STATIC);

        final Argument input;

        if (isStatic) {
            input = findInput(parameters);
        } else {
            input = new Argument(typeElement, "input");
        }
       
        final ClosureBuilder builder;

        if (method.getReturnType().getKind() == TypeKind.BOOLEAN) {
            builder = new ClosureBuilder(input, delegate);
        } else {
            final Name returnType = new Name(method.getReturnType().toString());
            builder = new ClosureBuilder(input, delegate, returnType);
        }

        builder.withName(name);
        builder.withStatic(isStatic);
View Full Code Here

    // Given:
    String pojoClassname = PojoF.class.getCanonicalName();
    String factoryClassname = PojoFFactory.class.getCanonicalName();
    TypeElement factoryType = elements.getTypeElement(factoryClassname);
    List<ExecutableElement> methods = ElementFilter.methodsIn(elements.getAllMembers(factoryType));
    ExecutableElement methodEl = getFirstMethodByName("createPojoF", methods);
    Input input = inputFactory.getInput(methodEl);

    // When:
    Output output = underTest.analyze(input);
View Full Code Here

          findAnnotatedElements(result, el, annotationType);
        }
        break;
      case CONSTRUCTOR:
      case METHOD:
        ExecutableElement exeEl = (ExecutableElement) element;
        for (AnnotationMirror anno : exeEl.getAnnotationMirrors()) {
          if (annotationType.getName().equals(getName(anno))) {
            result.add(exeEl);
          }
        }
        break;
View Full Code Here

        throw new InvalidElementException(String.format("Pojo %s must not be a non-static inner class!",
            annotatedElement), annotatedElement);
      }
      return getInputForAnnotatedPojo(typeEl);
    } else if (annotatedElement.getKind() == ElementKind.CONSTRUCTOR) {
      ExecutableElement constrEl = (ExecutableElement) annotatedElement;
      if (constrEl.getModifiers().contains(Modifier.PRIVATE)) {
        throw new InvalidElementException(String.format("Constructor  %s must not be private!", annotatedElement),
            annotatedElement);
      }
      TypeElement typeEl = (TypeElement) constrEl.getEnclosingElement();
      if (typeEl.getModifiers().contains(Modifier.PRIVATE)) {
        throw new InvalidElementException(String.format("Pojo %s must not be private!", typeEl), annotatedElement);
      }
      if (typeEl.getEnclosingElement().getKind() == ElementKind.CLASS
          && !typeEl.getModifiers().contains(Modifier.STATIC)) {
        throw new InvalidElementException(String.format("Pojo %s must not be a non-static inner class!", typeEl),
            annotatedElement);
      }
      return getInputForAnnotatedConstructor(constrEl);
    } else if (annotatedElement.getKind() == ElementKind.METHOD) {
      ExecutableElement methodEl = (ExecutableElement) annotatedElement;
      // TODO add support for non-static and non-public factory methods
      if (!methodEl.getModifiers().contains(Modifier.STATIC)) {
        throw new InvalidElementException(String.format("Factory method  %s must be static!", annotatedElement),
            annotatedElement);
      }
      if (!methodEl.getModifiers().contains(Modifier.PUBLIC)) {
        throw new InvalidElementException(String.format("Factory method  %s must be public!", annotatedElement),
            annotatedElement);
      }
      return getInputForAnnotatedFactoryMethod(methodEl);
    } else {
View Full Code Here

            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

    @Override
    public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
        if (!ran) {
            ran = true;
            ExecutableElement m = getFirstMethodIn("C");
            System.err.println("method: " + m);

            TypeMirror type = (DeclaredType)m.getParameters().get(0).asType();
            System.err.println("parameters[0]: " + type);
            if (!isParameterized(type))
                throw new AssertionError(type);

            type = ((ExecutableType)m.asType()).getParameterTypes().get(0);
            System.err.println("parameterTypes[0]: " + type);
            if (!isParameterized(type))
                throw new AssertionError(type);
            System.err.println();
        }
View Full Code Here

            }
            Element annoElement = (Element)annoElems.toArray()[0];
            if (!(annoElement instanceof ExecutableElement)) {
                error("annotated element must be a method");
            }
            ExecutableElement method = (ExecutableElement)annoElement;
            if (method.getParameters().size() != 2) {
                error("annotated method must have 2 arguments");
            }
            DeclaredType d1 = (DeclaredType)method.getParameters().get(0).asType();
            DeclaredType d2 = (DeclaredType)method.getParameters().get(1).asType();
            if (d1.getTypeArguments().size() != 1 ||
                    d1.getTypeArguments().size() != 1) {
                error("parameter type must be generic in one type-variable");
            }
            TypeMirror t1 = d1.getTypeArguments().get(0);
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.