static boolean suitableForBuilderConstructor(ExecutableElement element) { return element.getKind() == ElementKind.CONSTRUCTOR && !element.getModifiers().contains(Modifier.PRIVATE); }
static boolean suitableForBuilderFactory(ExecutableElement element) { return element.getKind() == ElementKind.METHOD && element.getReturnType().getKind() != TypeKind.VOID && !element.getModifiers().contains(Modifier.PRIVATE) && element.getModifiers().contains(Modifier.STATIC); }
private TypeElement getBuilderTypeFromCopyMethod() { return copyMethod().getKind() == ElementKind.CONSTRUCTOR ? (TypeElement) copyMethod().getEnclosingElement() : (TypeElement) ((DeclaredType) copyMethod().getReturnType()).asElement(); }
private TypeElement getBuilderTypeFromBuilderMethod() { return builderMethod().getKind() == ElementKind.CONSTRUCTOR ? (TypeElement) builderMethod().getEnclosingElement() : (TypeElement) ((DeclaredType) builderMethod().getReturnType()).asElement(); }
private void checkExecutableElement(ExecutableElement e, List<ExecutableElement> modelMethods, List<ExecutableElement> staticModelMethods, DeclaredTypeName modelClass) { Set<Modifier> modifiers = e.getModifiers(); if (e.getKind() == ElementKind.CONSTRUCTOR) {
void collect() { ExecutableElement factoryMethodElement = (ExecutableElement) protoclass.sourceElement(); Parameterizable element = (Parameterizable) (factoryMethodElement.getKind() == ElementKind.CONSTRUCTOR ? factoryMethodElement.getEnclosingElement() : type.element); for (VariableElement parameter : factoryMethodElement.getParameters()) { TypeMirror returnType = parameter.asType(); ValueAttribute attribute = new ValueAttribute(); attribute.isGenerateAbstract = true; attribute.reporter = reporter; attribute.returnType = returnType; attribute.element = parameter; String parameterName = parameter.getSimpleName().toString(); attribute.names = styles.forAccessorWithRaw(parameterName, parameterName); attribute.containingType = type; attributes.add(attribute); } Instantiator encodingInstantiator = protoclass.encodingInstantiator(); @Nullable InstantiationCreator instantiationCreator = encodingInstantiator.creatorFor(element); for (ValueAttribute attribute : attributes) { attribute.initAndValidate(instantiationCreator); } if (instantiationCreator != null) { type.additionalImports(instantiationCreator.imports); } type.attributes.addAll(attributes); type.throwing = extractThrowsClause(factoryMethodElement); }
TypeElement attributeBuilderType = builderModel().builderType(); if (copyMethod.getKind() == ElementKind.CONSTRUCTOR) { target = ValueToBuilderTarget.BUILDER_CONSTRUCTOR; } else if (copyMethod.getModifiers().contains(Modifier.STATIC)) { builderMethod.getSimpleName()); } else { if (builderMethod.getKind() == ElementKind.CONSTRUCTOR) { qualifiedBuilderConstructorMethod = String.format("new %s", attributeBuilderType.getQualifiedName());
/** * Checks that {@code element} is a method (not a constructor) that isn't abstract or static. */ private void checkMethod(ExecutableElement element) throws RemixerAnnotationException { if (element.getKind() != ElementKind.METHOD || element.getModifiers().contains(Modifier.ABSTRACT) || element.getModifiers().contains(Modifier.STATIC)) { throw new RemixerAnnotationException( element, "Variable annotations can only be used on non-abstract, non-static, regular methods"); } }
private static boolean isCallableMethod(ExecutableElement element) { boolean isMethod = (element.getKind() == ElementKind.METHOD); boolean isPublic = element.getModifiers().contains(Modifier.PUBLIC); boolean isNotStatic = !element.getModifiers().contains(Modifier.STATIC); boolean declaresNoExceptions = element.getThrownTypes().isEmpty(); return isMethod && isPublic && isNotStatic && declaresNoExceptions; }
/** * Ignore all static initializers and methods defined in the base * RequestFactory interfaces */ protected boolean shouldIgnore(ExecutableElement x, State state) { TypeMirror enclosingType = x.getEnclosingElement().asType(); return x.getKind().equals(ElementKind.STATIC_INIT) || state.types.isSameType(state.objectType, enclosingType) || state.types.isSameType(state.requestFactoryType, enclosingType) || state.types.isSameType(state.requestContextType, enclosingType) || state.types.isSameType(state.entityProxyType, enclosingType) || state.types.isSameType(state.valueProxyType, enclosingType); } }
ExecutableElement candidate = null; for (ExecutableElement element : ElementFilter.constructorsIn(e.getEnclosedElements())) { if (element.getKind() == ElementKind.CONSTRUCTOR) { candidate = element; if (!element.getModifiers().contains(Modifier.PUBLIC)) {
private static String getMethodName(ExecutableElement method) { if (method.getKind() == ElementKind.CONSTRUCTOR) { return CONSTRUCTOR_KEYWORD; } else { return method.getSimpleName().toString(); } }
@Override public TypeMirror getResolvedType() { if (resolvedMethod == null) { return null; } if (resolvedMethod.getKind() == ElementKind.CONSTRUCTOR) { return resolvedMethod.getEnclosingElement().asType(); } else { return resolvedMethod.getReturnType(); } }
public JExpr methodRef(final ExecutableElement method) { final ElementKind kind = method.getKind(); if (kind == ElementKind.METHOD && ! method.getModifiers().contains(Modifier.STATIC)) { final String name = method.getSimpleName().toString(); return methodRef(name); } throw new IllegalArgumentException("Unsupported element for method ref: " + method); }
public JCall call(final JExpr obj, final ExecutableElement element) { final ElementKind kind = element.getKind(); if (kind == ElementKind.METHOD) { final String name = element.getSimpleName().toString(); return call(obj, name); } throw new IllegalArgumentException("Unsupported element for call: " + element); }
public JCall call(final ExecutableElement method) { final ElementKind kind = method.getKind(); if (kind == ElementKind.METHOD && ! method.getModifiers().contains(Modifier.STATIC)) { final String name = method.getSimpleName().toString(); return call(name); } throw new IllegalArgumentException("Unsupported element for call: " + method); }
/** * Affirms if the given method matches the following signature * <code> public T getXXX() </code> * where T is any non-void type. */ public static boolean isNormalGetter(ExecutableElement method) { String methodName = method.getSimpleName().toString(); return method.getKind() == ElementKind.METHOD && startsWith(methodName, "get") && method.getParameters().isEmpty() && !isVoid(method.getReturnType()); }
/** * Affirms if the given method matches the following signature * <code> public boolean isXyz() </code> * <code> public Boolean isXyz() </code> */ public static boolean isBooleanGetter(ExecutableElement method) { String methodName = method.getSimpleName().toString(); return method.getKind() == ElementKind.METHOD && startsWith(methodName, "is") && method.getParameters().isEmpty() && isBoolean(method.getReturnType()); }
/** * Affirms if the given method matches the following signature * <code> public void setXXX(T t) </code> */ public static boolean isSetter(ExecutableElement method) { String methodName = method.getSimpleName().toString(); return method.getKind() == ElementKind.METHOD && startsWith(methodName, "set") && method.getParameters().size() == 1 && isVoid(method.getReturnType()); }
public AnnotationValueInfo processAnnotation(AnnotationMirror annotation) { String fqn = ((TypeElement) annotation.getAnnotationType().asElement()).getQualifiedName().toString(); AnnotationValueInfo owner = new AnnotationValueInfo(fqn); Map<? extends ExecutableElement, ? extends AnnotationValue> valueMap = elementUtils.getElementValuesWithDefaults(annotation); for (ExecutableElement valueElt : valueMap.keySet().stream().filter(e -> e.getKind().equals(ElementKind.METHOD)).collect(Collectors.toSet())) { owner.putMember(valueElt.getSimpleName().toString(), processAnnotationMemberValue(valueMap.get(valueElt))); } return owner; }