Java Code Examples for javax.lang.model.element.ExecutableElement#toString()

The following examples show how to use javax.lang.model.element.ExecutableElement#toString() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
protected boolean processedMethod(ExecutableElement method) {
    String id = method.toString();
    if (processedMethods.contains(id))
        return true;
    processedMethods.add(id);
    return false;
}
 
Example 2
protected boolean processedMethod(ExecutableElement method) {
    String id = method.toString();
    if (processedMethods.contains(id))
        return true;
    processedMethods.add(id);
    return false;
}
 
Example 3
protected boolean processedMethod(ExecutableElement method) {
    String id = method.toString();
    if (processedMethods.contains(id))
        return true;
    processedMethods.add(id);
    return false;
}
 
Example 4
protected boolean processedMethod(ExecutableElement method) {
    String id = method.toString();
    if (processedMethods.contains(id))
        return true;
    processedMethods.add(id);
    return false;
}
 
Example 5
protected boolean processedMethod(ExecutableElement method) {
    String id = method.toString();
    if (processedMethods.contains(id))
        return true;
    processedMethods.add(id);
    return false;
}
 
Example 6
protected boolean processedMethod(ExecutableElement method) {
    String id = method.toString();
    if (processedMethods.contains(id))
        return true;
    processedMethods.add(id);
    return false;
}
 
Example 7
protected boolean processedMethod(ExecutableElement method) {
    String id = method.toString();
    if (processedMethods.contains(id))
        return true;
    processedMethods.add(id);
    return false;
}
 
Example 8
protected boolean processedMethod(ExecutableElement method) {
    String id = method.toString();
    if (processedMethods.contains(id))
        return true;
    processedMethods.add(id);
    return false;
}
 
Example 9
public ColumnAnnotatedMethod(ExecutableElement method, Column annotation)
    throws ProcessingException {

  if (!method.getModifiers().contains(Modifier.PUBLIC)) {
    throw new ProcessingException(method,
        "Setter method %s in %s annotated with @%s is not public. Only PUBLIC setter methods are supported",
        method.getSimpleName().toString(), method.getEnclosingElement().toString(),
        Column.class.getSimpleName());
  }

  if (method.getParameters().size() != 1) {
    throw new ProcessingException(method,
        "Setter method %s in %s annotated with @%s MUST have exactly one parameter!",
        method.toString(), method.getEnclosingElement().toString(), Column.class.getSimpleName());
  }

  columnName = annotation.value();
  if (columnName == null || columnName.length() == 0) {
    throw new ProcessingException(method, "The column name is unspecified for method %s in %s",
        method.getSimpleName().toString(), method.getEnclosingElement().toString());
  }

  throwOnColumnIndexNotFound = annotation.throwOnColumnIndexNotFound();
  this.method = method;

  codeGenerator = MethodCodeFactory.get(this);
}
 
Example 10
private Optional<Getter> create(DeclaredType ownerType, ExecutableElement element) {
  if (element.getKind() != ElementKind.METHOD
      || element.getModifiers().contains(Modifier.STATIC)
      || !element.getModifiers().contains(Modifier.PUBLIC)) {
    return Optional.empty();
  }

  ExecutableType method = (ExecutableType) element.asType();
  if (!method.getParameterTypes().isEmpty()) {
    return Optional.empty();
  }

  if (element.getAnnotation(Encodable.Ignore.class) != null) {
    return Optional.empty();
  }
  Optional<String> fieldName = inferName(element);
  if (!fieldName.isPresent()) {
    return Optional.empty();
  }
  TypeMirror returnType = resolveTypeArguments(ownerType, element.getReturnType());
  String getterExpression = element.toString();

  // Fail to compile if Maps with non-string keys are used, if/when we add support for such maps
  // we should delete this.
  TypeMirror map = types.erasure(elements.getTypeElement("java.util.Map").asType());
  if (types.isAssignable(returnType, map)) {
    TypeMirror keyType = ((DeclaredType) returnType).getTypeArguments().get(0);
    if (!types.isSameType(keyType, elements.getTypeElement("java.lang.String").asType())) {
      messager.printMessage(
          Diagnostic.Kind.ERROR,
          "Cannot encode Maps with non-String keys.",
          ((DeclaredType) returnType).asElement());
    }
  }
  if (types.isAssignable(
      returnType, types.erasure(elements.getTypeElement("java.util.Optional").asType()))) {
    returnType = ((DeclaredType) returnType).getTypeArguments().get(0);
    getterExpression = getterExpression + ".orElse(null)";
  }

  Encodable.Field field = element.getAnnotation(Encodable.Field.class);

  return Optional.of(
      Getter.create(
          fieldName.get(), getterExpression, returnType, field != null && field.inline()));
}
 
Example 11
Source Project: spring-init   File: InitializerSpec.java    License: Apache License 2.0 4 votes vote down vote up
private boolean createBeanMethod(MethodSpec.Builder builder, ExecutableElement beanMethod, TypeElement type,
		boolean conditionsAvailable) {
	// TODO will need to handle bean methods in private configs
	try {
		TypeMirror returnType = utils.getReturnType(beanMethod);

		Element returnTypeElement = utils.asElement(returnType);
		boolean conditional = utils.hasAnnotation(beanMethod, SpringClassNames.CONDITIONAL.toString());
		if (conditional) {
			if (!conditionsAvailable) {
				builder.addStatement("$T conditions = context.getBeanFactory().getBean($T.class)",
						SpringClassNames.CONDITION_SERVICE, SpringClassNames.CONDITION_SERVICE);
			}
		}

		if (returnTypeElement.getModifiers().contains(Modifier.PRIVATE)) {

			if (conditional) {
				builder.beginControlFlow(
						"if (conditions.matches($T.class, $T.resolveClassName(\"$L\", context.getClassLoader())))",
						type, SpringClassNames.CLASS_UTILS, utils.erasure(returnType));
			}
			utils.printMessage(Kind.WARNING, "Generating source for bean method, type involved is private: "
					+ beanMethod.getEnclosingElement() + "." + beanMethod);
			builder.addStatement("context.registerBean($T.resolveClassName(\"$L\", context.getClassLoader()))",
					SpringClassNames.CLASS_UTILS, ((TypeElement) returnTypeElement).getQualifiedName());

		}
		else {

			if (conditional) {
				builder.beginControlFlow("if (conditions.matches($T.class, $T.class))", type,
						utils.erasure(returnType));
			}
			Parameters params = autowireParamsForMethod(beanMethod);

			builder.addStatement("context.registerBean(" + "\"" + beanMethod.getSimpleName() + "\", $T.class, "
					+ supplier(type, beanMethod, params.format) + customizer(type, beanMethod, params) + ")",
					ArrayUtils.merge(utils.erasure(returnType), type, params.args));
		}

		if (conditional) {
			builder.endControlFlow();
		}

		return conditional;
	}
	catch (Throwable t) {
		throw new RuntimeException(
				"Problem performing createBeanMethod for method " + type.toString() + "." + beanMethod.toString(),
				t);
	}
}