Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions CodenameOne/src/com/codename1/annotations/Email.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Copyright (c) 2026, Codename One and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Codename One designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Codename One through http://www.codenameone.com/ if you
* need additional information or have any questions.
*/
package com.codename1.annotations;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/// Requires the component value to be a syntactically valid e-mail address.
/// The processor emits `RegexConstraint.validEmail(message)` into the
/// `Validator` returned by `Binding#getValidator()`.
///
/// ```java
/// @Bind(name="emailField") @Required @Email
/// private String email;
/// ```
///
/// Stacks well with `@Required` -- the standard email regex accepts the
/// empty string as "not yet an address," so combine with `@Required` when
/// the field is mandatory.
@Retention(RetentionPolicy.CLASS)
@Target(ElementType.FIELD)
public @interface Email {
/// Override the default error message ("Invalid Email Address").
String message() default "";
}
55 changes: 55 additions & 0 deletions CodenameOne/src/com/codename1/annotations/ExistIn.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* Copyright (c) 2026, Codename One and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Codename One designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Codename One through http://www.codenameone.com/ if you
* need additional information or have any questions.
*/
package com.codename1.annotations;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/// Requires the component value to be one of an allowed list of strings. The
/// processor emits
/// `com.codename1.ui.validation.ExistInConstraint(value, caseSensitive, message)`
/// into the `Validator` returned by `Binding#getValidator()`.
///
/// ```java
/// @Bind(name="roleField") @ExistIn({"admin", "editor", "viewer"})
/// private String role;
/// ```
///
/// Use it to gate free-text fields that should accept only a known
/// vocabulary, or to gate `Picker` selections against an authoritative list
/// known at compile time.
@Retention(RetentionPolicy.CLASS)
@Target(ElementType.FIELD)
public @interface ExistIn {
/// The allowed values. The component must equal one of them.
String[] value();

/// `true` to compare values with case-sensitivity. Default: false.
boolean caseSensitive() default false;

/// Override the default error message
/// (`ExistInConstraint` derives one from the value list when blank).
String message() default "";
}
52 changes: 52 additions & 0 deletions CodenameOne/src/com/codename1/annotations/Length.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* Copyright (c) 2026, Codename One and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Codename One designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Codename One through http://www.codenameone.com/ if you
* need additional information or have any questions.
*/
package com.codename1.annotations;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/// Requires the component value to have at least `min` characters. The
/// processor wires this into the `Validator` returned by
/// `Binding#getValidator()` as a
/// `com.codename1.ui.validation.LengthConstraint(min, message)`.
///
/// ```java
/// @Bindable
/// public class SignupModel {
/// @Bind(name="passwordField") @Length(min = 8)
/// private String password;
/// }
/// ```
@Retention(RetentionPolicy.CLASS)
@Target(ElementType.FIELD)
public @interface Length {
/// Minimum number of characters. Use `1` for "non-empty" -- or just write
/// `@Required` which is shorter and reads better.
int min();

/// Override the default error message
/// (`"Input must be at least <min> characters"`).
String message() default "";
}
61 changes: 61 additions & 0 deletions CodenameOne/src/com/codename1/annotations/Numeric.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* Copyright (c) 2026, Codename One and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Codename One designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Codename One through http://www.codenameone.com/ if you
* need additional information or have any questions.
*/
package com.codename1.annotations;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/// Requires the component value to parse as a number, optionally within a
/// closed range. The processor emits
/// `com.codename1.ui.validation.NumericConstraint(decimal, min, max, message)`
/// into the `Validator` returned by `Binding#getValidator()`.
///
/// ```java
/// @Bind(name="ageField") @Numeric(min = 0, max = 150)
/// private int age;
///
/// @Bind(name="priceField") @Numeric(decimal = true, min = 0.01)
/// private double price;
/// ```
///
/// Bounds are inclusive. Omitting `min` / `max` removes that side of the
/// range (the defaults are negative / positive infinity).
@Retention(RetentionPolicy.CLASS)
@Target(ElementType.FIELD)
public @interface Numeric {
/// `true` allows a decimal value (parsed via `Double.parseDouble`);
/// `false` requires an integer (parsed via `Integer.parseInt`).
boolean decimal() default false;

/// Inclusive lower bound. Default: no lower bound.
double min() default Double.NEGATIVE_INFINITY;

/// Inclusive upper bound. Default: no upper bound.
double max() default Double.POSITIVE_INFINITY;

/// Override the default error message
/// (`NumericConstraint` derives one from the bounds when blank).
String message() default "";
}
54 changes: 54 additions & 0 deletions CodenameOne/src/com/codename1/annotations/Regex.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* Copyright (c) 2026, Codename One and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Codename One designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Codename One through http://www.codenameone.com/ if you
* need additional information or have any questions.
*/
package com.codename1.annotations;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/// Requires the component value to match a regular expression. The processor
/// emits a `com.codename1.ui.validation.RegexConstraint(pattern, message)`
/// into the `Validator` returned by `Binding#getValidator()`.
///
/// ```java
/// @Bind(name="phoneField")
/// @Regex(pattern="^[0-9+\\-]+$", message="Digits, plus and dash only")
/// private String phone;
/// ```
///
/// Use `@Email` or `@Url` for the two most common patterns -- they reuse the
/// expressions already vetted in `RegexConstraint.validEmail()` /
/// `validURL()`.
@Retention(RetentionPolicy.CLASS)
@Target(ElementType.FIELD)
public @interface Regex {
/// The regular expression. Same dialect as
/// `com.codename1.util.regex.RE` (a Codename One subset of standard
/// regex that works on every supported runtime).
String pattern();

/// Override the default error message. Required because
/// `RegexConstraint` has no canned message for arbitrary patterns.
String message() default "Invalid value";
}
51 changes: 51 additions & 0 deletions CodenameOne/src/com/codename1/annotations/Required.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* Copyright (c) 2026, Codename One and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Codename One designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Codename One through http://www.codenameone.com/ if you
* need additional information or have any questions.
*/
package com.codename1.annotations;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/// Marks a `@Bind` field whose component must hold a non-empty value. The
/// binder generated by the Codename One Maven plugin installs a
/// `com.codename1.ui.validation.LengthConstraint(1)` on the matching component
/// and wires it into the `Validator` returned by `Binding#getValidator()`.
///
/// ```java
/// @Bindable
/// public class SignupModel {
/// @Bind(name="userField") @Required
/// private String user;
/// }
/// ```
///
/// Stack with other validation annotations -- the constraints are combined
/// (AND) via `Validator.addConstraint(Component, Constraint...)`. The first
/// failing constraint's message is shown.
@Retention(RetentionPolicy.CLASS)
@Target(ElementType.FIELD)
public @interface Required {
/// Override the default error message ("A value is required").
String message() default "";
}
43 changes: 43 additions & 0 deletions CodenameOne/src/com/codename1/annotations/Url.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Copyright (c) 2026, Codename One and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Codename One designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Codename One through http://www.codenameone.com/ if you
* need additional information or have any questions.
*/
package com.codename1.annotations;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/// Requires the component value to be a syntactically valid URL (http, https,
/// ftp, or file scheme). The processor emits `RegexConstraint.validURL(message)`
/// into the `Validator` returned by `Binding#getValidator()`.
///
/// ```java
/// @Bind(name="homepageField") @Url
/// private String homepage;
/// ```
@Retention(RetentionPolicy.CLASS)
@Target(ElementType.FIELD)
public @interface Url {
/// Override the default error message ("Invalid URL").
String message() default "";
}
Loading
Loading