Changeset 15972 in josm for trunk/src/org/openstreetmap


Ignore:
Timestamp:
2020-03-01T10:34:23+01:00 (5 years ago)
Author:
GerdP
Message:

fix #18810: Validator dialog should show the test that produced the message

  • show test also for the grouped error. If multiple tests are involved show "Different tests"
  • for MapCss rules report also the URL/File as stated in the preference dialog, e.g. "resource://data/validator/geometry.mapcss"
  • for Java tests report "Java: " + this.getClass().getName(), e.g. "Java: org.openstreetmap.josm.data.validation.DuplicateWay"
Location:
trunk/src/org/openstreetmap/josm
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/validation/Test.java

    r15755 r15972  
    382382        showElementCount = b;
    383383    }
     384
     385    /**
     386     * @return the name of this class (for ToolTip)
     387     * since 15972
     388     */
     389    public Object getSource() {
     390        return "Java: " + this.getClass().getName();
     391    }
    384392}
  • trunk/src/org/openstreetmap/josm/data/validation/tests/MapCSSTagChecker.java

    r15959 r15972  
    107107        /** MapCSS declaration **/
    108108        public final Declaration declaration;
     109        /** MapCSS source **/
     110        public final String source;
     111
     112        /**
     113         * Constructs a new {@code GroupedMapCSSRule} with empty source
     114         * @param selectors MapCSS selectors
     115         * @param declaration MapCSS declaration
     116         */
     117        public GroupedMapCSSRule(List<Selector> selectors, Declaration declaration) {
     118            this(selectors, declaration, "");
     119        }
    109120
    110121        /**
     
    112123         * @param selectors MapCSS selectors
    113124         * @param declaration MapCSS declaration
    114          */
    115         public GroupedMapCSSRule(List<Selector> selectors, Declaration declaration) {
     125         * @param source the source of the rule
     126         */
     127        public GroupedMapCSSRule(List<Selector> selectors, Declaration declaration, String source) {
    116128            this.selectors = selectors;
    117129            this.declaration = declaration;
     130            this.source = source;
    118131        }
    119132
     
    391404
    392405        static ParseResult readMapCSS(Reader css) throws ParseException {
     406            return readMapCSS(css, "");
     407        }
     408
     409        static ParseResult readMapCSS(Reader css, String url) throws ParseException {
    393410            CheckParameterUtil.ensureParameterNotNull(css, "css");
    394411
     
    415432                try {
    416433                    parseChecks.add(TagCheck.ofMapCSSRule(
    417                             new GroupedMapCSSRule(map.getValue(), map.getKey())));
     434                            new GroupedMapCSSRule(map.getValue(), map.getKey(), url)));
    418435                } catch (IllegalDataException e) {
    419436                    Logging.error("Cannot add MapCss rule: "+e.getMessage());
     
    707724            return "MapCSSTagCheckerAndRule [rule=" + rule + ']';
    708725        }
     726
     727        @Override
     728        public String getSource() {
     729            return tr("URL / File: {0}", rule.source);
     730        }
    709731    }
    710732
     
    849871            if (zip != null)
    850872                I18n.addTexts(cache.getFile());
    851             result = TagCheck.readMapCSS(reader);
     873            result = TagCheck.readMapCSS(reader, url);
    852874            checks.remove(url);
    853875            checks.putAll(url, result.parseChecks);
  • trunk/src/org/openstreetmap/josm/gui/dialogs/validator/ValidatorTreePanel.java

    r15962 r15972  
    117117            if (nodeInfo instanceof TestError) {
    118118                TestError error = (TestError) nodeInfo;
    119                 res = "<html>" + error.getNameVisitor().getText() + "<br>" + error.getMessage();
     119                res = error.getNameVisitor().getText() + "<br>" + error.getMessage();
    120120                String d = error.getDescription();
    121121                if (d != null)
    122122                    res += "<br>" + d;
    123                 res += "<br>" + tr("Test: {0}", error.getTester().getName());
    124                 res += "</html>";
     123                res += "<br>" + tr("Test: {0}", getTesterDetails(error));
    125124            } else {
    126                 res = node.toString();
    127             }
    128         }
    129         return res;
     125                Set<String> tests = new HashSet<>();
     126                visitTestErrors(node, err -> tests.add(getTesterDetails(err)), null);
     127                String source = (tests.size() == 1) ? tr("Test: {0}", tests.iterator().next()) : tr("Different tests");
     128                res = node.toString() + "<br>" + source;
     129            }
     130        }
     131        return "<html>" + res + "</html>";
     132    }
     133
     134    private static String getTesterDetails(TestError e) {
     135        return e.getTester().getName() + "<br>" + e.getTester().getSource();
    130136    }
    131137
Note: See TracChangeset for help on using the changeset viewer.