Ignore:
Timestamp:
2023-10-24T17:29:11+02:00 (13 months ago)
Author:
taylor.smock
Message:

See #23220: Use jakarta.annotation instead of javax.annotation (JSR305)

jsr305 should be removed in June 2024 to give plugins time to migrate.

Some lint issues were also fixed.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/osm/search/SearchCompiler.java

    r18852 r18877  
    2727import java.util.regex.PatternSyntaxException;
    2828import java.util.stream.Collectors;
    29 
    30 import javax.annotation.Nonnull;
    31 import javax.annotation.Nullable;
    3229
    3330import org.openstreetmap.josm.data.Bounds;
     
    5956import org.openstreetmap.josm.tools.date.DateUtils;
    6057
     58import jakarta.annotation.Nonnull;
     59import jakarta.annotation.Nullable;
     60
    6161/**
    6262 * Implements a google-like search.
     
    8585    private final boolean caseSensitive;
    8686    private final boolean regexSearch;
    87     private static final String rxErrorMsg = marktr("The regex \"{0}\" had a parse error at offset {1}, full error:\n\n{2}");
    88     private static final String rxErrorMsgNoPos = marktr("The regex \"{0}\" had a parse error, full error:\n\n{1}");
     87    private static final String REGEX_ERROR_MESSAGE = marktr("The regex \"{0}\" had a parse error at offset {1}, full error:\n\n{2}");
     88    private static final String REGEX_ERROR_MESSAGE_NO_POSITION = marktr("The regex \"{0}\" had a parse error, full error:\n\n{1}");
     89    private static final String RANGE_OF_NUMBERS_EXPECTED = marktr("Range of numbers expected");
    8990    private final PushbackTokenizer tokenizer;
    9091    private static final Map<String, SimpleMatchFactory> simpleMatchFactoryMap = new HashMap<>();
    9192    private static final Map<String, UnaryMatchFactory> unaryMatchFactoryMap = new HashMap<>();
    9293    private static final Map<String, BinaryMatchFactory> binaryMatchFactoryMap = new HashMap<>();
     94
     95    // Common literals
     96    private static final String AREA_SIZE = "areasize";
     97    private static final String CHANGESET = "changeset";
     98    private static final String CLOSED = "closed";
     99    private static final String DELETED = "deleted";
     100    private static final String INCOMPLETE = "incomplete";
     101    private static final String IN_DOWNLOADED_AREA = "indownloadedarea";
     102    private static final String ALL_IN_DOWNLOADED_AREA = "all" + IN_DOWNLOADED_AREA;
     103    private static final String MEMBERS = "members";
     104    private static final String MODIFIED = "modified";
     105    private static final String NODES = "nodes";
     106    private static final String SELECTED = "selected";
     107    private static final String TIMESTAMP = "timestamp";
     108    private static final String UNTAGGED = "untagged";
     109    private static final String VERSION = "version";
     110    private static final String WAYS = "ways";
     111    private static final String WAY_LENGTH = "waylength";
    93112
    94113    static {
     
    134153     */
    135154    public static class CoreSimpleMatchFactory implements SimpleMatchFactory {
    136         private final Collection<String> keywords = Arrays.asList("id", "version", "type", "user", "role",
    137                 "changeset", "nodes", "ways", "members", "tags", "areasize", "waylength", "modified", "deleted", "selected",
    138                 "incomplete", "untagged", "closed", "new", "indownloadedarea",
    139                 "allindownloadedarea", "timestamp", "nth", "nth%", "hasRole", "preset");
     155        private final Collection<String> keywords = Arrays.asList("id", VERSION, "type", "user", "role",
     156                CHANGESET, NODES, WAYS, MEMBERS, "tags", AREA_SIZE, WAY_LENGTH, MODIFIED, DELETED, SELECTED,
     157                INCOMPLETE, UNTAGGED, CLOSED, "new", IN_DOWNLOADED_AREA,
     158                ALL_IN_DOWNLOADED_AREA, TIMESTAMP, "nth", "nth%", "hasRole", "preset");
    140159
    141160        @Override
    142161        public Match get(String keyword, boolean caseSensitive, boolean regexSearch, PushbackTokenizer tokenizer) throws SearchParseError {
    143162            switch(keyword) {
    144             case "modified":
     163            case MODIFIED:
    145164                return new Modified();
    146             case "deleted":
     165            case DELETED:
    147166                return new Deleted();
    148             case "selected":
     167            case SELECTED:
    149168                return new Selected();
    150             case "incomplete":
     169            case INCOMPLETE:
    151170                return new Incomplete();
    152             case "untagged":
     171            case UNTAGGED:
    153172                return new Untagged();
    154             case "closed":
     173            case CLOSED:
    155174                return new Closed();
    156175            case "new":
    157176                return new New();
    158             case "indownloadedarea":
     177            case IN_DOWNLOADED_AREA:
    159178                return new InDataSourceArea(false);
    160             case "allindownloadedarea":
     179            case ALL_IN_DOWNLOADED_AREA:
    161180                return new InDataSourceArea(true);
    162181            default:
     
    174193                case "id":
    175194                    return new Id(tokenizer);
    176                 case "version":
     195                case VERSION:
    177196                    return new Version(tokenizer);
    178197                case "type":
     
    184203                case "role":
    185204                    return new RoleMatch(tokenizer.readTextOrNumber());
    186                 case "changeset":
     205                case CHANGESET:
    187206                    return new ChangesetId(tokenizer);
    188                 case "nodes":
     207                case NODES:
    189208                    return new NodeCountRange(tokenizer);
    190                 case "ways":
     209                case WAYS:
    191210                    return new WayCountRange(tokenizer);
    192                 case "members":
     211                case MEMBERS:
    193212                    return new MemberCountRange(tokenizer);
    194213                case "tags":
    195214                    return new TagCountRange(tokenizer);
    196                 case "areasize":
     215                case AREA_SIZE:
    197216                    return new AreaSize(tokenizer);
    198                 case "waylength":
     217                case WAY_LENGTH:
    199218                    return new WayLength(tokenizer);
    200219                case "nth":
     
    204223                case "hasRole":
    205224                    return new HasRole(tokenizer);
    206                 case "timestamp":
     225                case TIMESTAMP:
    207226                    // add leading/trailing space in order to get expected split (e.g. "a--" => {"a", ""})
    208227                    String rangeS = ' ' + tokenizer.readTextOrNumber() + ' ';
     
    370389                return Pattern.compile(regex, flags);
    371390            } catch (PatternSyntaxException e) {
    372                 throw new SearchParseError(tr(rxErrorMsg, e.getPattern(), e.getIndex(), e.getMessage()), e);
     391                throw new SearchParseError(tr(REGEX_ERROR_MESSAGE, e.getPattern(), e.getIndex(), e.getMessage()), e);
    373392            } catch (IllegalArgumentException | StringIndexOutOfBoundsException e) {
    374393                // StringIndexOutOfBoundsException caught because of https://bugs.openjdk.java.net/browse/JI-9044959
    375394                // See #13870: To remove after we switch to a version of Java which resolves this bug
    376                 throw new SearchParseError(tr(rxErrorMsgNoPos, regex, e.getMessage()), e);
     395                throw new SearchParseError(tr(REGEX_ERROR_MESSAGE_NO_POSITION, regex, e.getMessage()), e);
    377396            }
    378397        }
     
    707726        @Override
    708727        protected String getString() {
    709             return "changeset";
     728            return CHANGESET;
    710729        }
    711730    }
     
    730749        @Override
    731750        protected String getString() {
    732             return "version";
     751            return VERSION;
    733752        }
    734753    }
     
    783802        private String getMv(Tagged osm) {
    784803            String mv;
    785             if ("timestamp".equals(key) && osm instanceof OsmPrimitive) {
     804            if (TIMESTAMP.equals(key) && osm instanceof OsmPrimitive) {
    786805                mv = ((OsmPrimitive) osm).getInstant().toString();
    787806            } else {
     
    14291448
    14301449        NodeCountRange(PushbackTokenizer tokenizer) throws SearchParseError {
    1431             this(tokenizer.readRange(tr("Range of numbers expected")));
     1450            this(tokenizer.readRange(tr(RANGE_OF_NUMBERS_EXPECTED)));
    14321451        }
    14331452
     
    14451464        @Override
    14461465        protected String getString() {
    1447             return "nodes";
     1466            return NODES;
    14481467        }
    14491468    }
     
    14581477
    14591478        WayCountRange(PushbackTokenizer tokenizer) throws SearchParseError {
    1460             this(tokenizer.readRange(tr("Range of numbers expected")));
     1479            this(tokenizer.readRange(tr(RANGE_OF_NUMBERS_EXPECTED)));
    14611480        }
    14621481
     
    14871506
    14881507        MemberCountRange(PushbackTokenizer tokenizer) throws SearchParseError {
    1489             this(tokenizer.readRange(tr("Range of numbers expected")));
     1508            this(tokenizer.readRange(tr(RANGE_OF_NUMBERS_EXPECTED)));
    14901509        }
    14911510
     
    15021521        @Override
    15031522        protected String getString() {
    1504             return "members";
     1523            return MEMBERS;
    15051524        }
    15061525    }
     
    15151534
    15161535        TagCountRange(PushbackTokenizer tokenizer) throws SearchParseError {
    1517             this(tokenizer.readRange(tr("Range of numbers expected")));
     1536            this(tokenizer.readRange(tr(RANGE_OF_NUMBERS_EXPECTED)));
    15181537        }
    15191538
     
    15661585        @Override
    15671586        protected String getString() {
    1568             return "timestamp";
     1587            return TIMESTAMP;
    15691588        }
    15701589    }
     
    16271646        @Override
    16281647        public String toString() {
    1629             return "modified";
     1648            return MODIFIED;
    16301649        }
    16311650    }
     
    16421661        @Override
    16431662        public String toString() {
    1644             return "deleted";
     1663            return DELETED;
    16451664        }
    16461665    }
     
    16571676        @Override
    16581677        public String toString() {
    1659             return "selected";
     1678            return SELECTED;
    16601679        }
    16611680    }
     
    16741693        @Override
    16751694        public String toString() {
    1676             return "incomplete";
     1695            return INCOMPLETE;
    16771696        }
    16781697    }
     
    16911710        @Override
    16921711        public String toString() {
    1693             return "untagged";
     1712            return UNTAGGED;
    16941713        }
    16951714    }
     
    17061725        @Override
    17071726        public String toString() {
    1708             return "closed";
     1727            return CLOSED;
    17091728        }
    17101729    }
     
    17671786
    17681787        AreaSize(PushbackTokenizer tokenizer) throws SearchParseError {
    1769             this(tokenizer.readRange(tr("Range of numbers expected")));
     1788            this(tokenizer.readRange(tr(RANGE_OF_NUMBERS_EXPECTED)));
    17701789        }
    17711790
     
    17781797        @Override
    17791798        protected String getString() {
    1780             return "areasize";
     1799            return AREA_SIZE;
    17811800        }
    17821801    }
     
    17921811
    17931812        WayLength(PushbackTokenizer tokenizer) throws SearchParseError {
    1794             this(tokenizer.readRange(tr("Range of numbers expected")));
     1813            this(tokenizer.readRange(tr(RANGE_OF_NUMBERS_EXPECTED)));
    17951814        }
    17961815
     
    18051824        @Override
    18061825        protected String getString() {
    1807             return "waylength";
     1826            return WAY_LENGTH;
    18081827        }
    18091828    }
     
    18781897        @Override
    18791898        public String toString() {
    1880             return all ? "allindownloadedarea" : "indownloadedarea";
     1899            return all ? ALL_IN_DOWNLOADED_AREA : IN_DOWNLOADED_AREA;
    18811900        }
    18821901    }
Note: See TracChangeset for help on using the changeset viewer.