Changeset 2973 in josm for trunk


Ignore:
Timestamp:
2010-02-13T17:05:37+01:00 (14 years ago)
Author:
jttt
Message:

Fix #4519 JOSM doesn't show nor find token (negative) IDs

Location:
trunk/src/org/openstreetmap/josm
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/search/PushbackTokenizer.java

    r2863 r2973  
    1515    private Token currentToken;
    1616    private String currentText;
     17    private long currentNumber;
    1718    private int c;
    1819
     
    2526        NOT(marktr("<not>")), OR(marktr("<or>")), LEFT_PARENT(marktr("<left parent>")),
    2627        RIGHT_PARENT(marktr("<right parent>")), COLON(marktr("<colon>")), EQUALS(marktr("<equals>")),
    27         KEY(marktr("<key>")), QUESTION_MARK(marktr("<question mark>")), EOF(marktr("<end-of-file>"));
     28        KEY(marktr("<key>")), QUESTION_MARK(marktr("<question mark>")), NUMBER(marktr("<number>")),
     29        EOF(marktr("<end-of-file>"));
    2830
    2931        private Token(String name) {
     
    4648            throw new RuntimeException(e.getMessage(), e);
    4749        }
     50    }
     51
     52    private long getNumber() {
     53        long result = 0;
     54        while (Character.isDigit(c)) {
     55            result = result * 10 + (c - '0');
     56            getChar();
     57        }
     58        return result;
    4859    }
    4960
     
    7889        case '-':
    7990            getChar();
    80             return Token.NOT;
     91            if (Character.isDigit(c)) {
     92                currentNumber = -1 * getNumber();
     93                return Token.NUMBER;
     94            } else
     95                return Token.NOT;
    8196        case '(':
    8297            getChar();
     
    111126        default:
    112127        {
     128            if (Character.isDigit(c)) {
     129                currentNumber = getNumber();
     130                return Token.NUMBER;
     131            }
     132
    113133            StringBuilder s = new StringBuilder();
    114134            while (!(c == -1 || Character.isWhitespace(c) || c == '"'|| c == ':' || c == '(' || c == ')' || c == '|' || c == '=' || c == '?')) {
     
    149169    }
    150170
     171    public long readNumber(String errorMessage) throws ParseError {
     172        if (nextToken() == Token.NUMBER)
     173            return currentNumber;
     174        else
     175            throw new ParseError(errorMessage);
     176    }
     177
    151178    public String getText() {
    152179        return currentText;
  • trunk/src/org/openstreetmap/josm/actions/search/SearchCompiler.java

    r2962 r2973  
    122122    private static class Id extends Match {
    123123        private long id;
    124         public Id(long id) {this.id = id;}
    125         @Override public boolean match(OsmPrimitive osm) {
    126             return osm.getId() == id;
     124        public Id(long id) {
     125            this.id = id;
     126        }
     127        @Override public boolean match(OsmPrimitive osm) {
     128            return osm.getUniqueId() == id;
    127129        }
    128130        @Override public String toString() {return "id="+id;}
     
    663665                return new ExactKeyValue(regexSearch, key, tokenizer.readText());
    664666            else if (tokenizer.readIfEqual(Token.COLON))
    665                 return parseKV(key, tokenizer.readText());
     667                if ("id".equals(key))
     668                    return new Id(tokenizer.readNumber(tr("Primitive id expected")));
     669                else
     670                    return parseKV(key, tokenizer.readText());
    666671            else if (tokenizer.readIfEqual(Token.QUESTION_MARK))
    667672                return new BooleanMatch(key, false);
     
    725730            }
    726731
    727         } else if (key.equals("id")) {
    728             try {
    729                 return new Id(Long.parseLong(value));
    730             } catch (NumberFormatException x) {
    731                 throw new ParseError(tr("Incorrect value of id operator: {0}. Number is expected.", value));
    732             }
    733732        } else if (key.equals("changeset")) {
    734733            try {
  • trunk/src/org/openstreetmap/josm/gui/DefaultNameFormatter.java

    r2893 r2973  
    7373    /**
    7474     * Decorates the name of primitive with its id, if the preference
    75      * <tt>osm-primitives.showid</tt> is set.
     75     * <tt>osm-primitives.showid</tt> is set. Shows unique id if osm-primitives.showid.new-primitives is set
    7676     *
    7777     * @param name  the name without the id
     
    8181    protected String decorateNameWithId(String name, OsmPrimitive primitive) {
    8282        if (Main.pref.getBoolean("osm-primitives.showid"))
    83             return name + tr(" [id: {0}]", primitive.getId());
     83            if (Main.pref.getBoolean("osm-primitives.showid.new-primitives"))
     84                return name + tr(" [id: {0}]", primitive.getUniqueId());
     85            else
     86                return name + tr(" [id: {0}]", primitive.getId());
    8487        else
    8588            return name;
Note: See TracChangeset for help on using the changeset viewer.