Ignore:
Timestamp:
2024-04-22T20:59:26+02:00 (4 weeks ago)
Author:
taylor.smock
Message:

Revert most var changes from r19048, fix most new compile warnings and checkstyle issues

Also, document why various ErrorProne checks were originally disabled and fix
generic SonarLint issues.

File:
1 edited

Legend:

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

    r19048 r19050  
    1111import java.nio.charset.StandardCharsets;
    1212import java.nio.file.Files;
     13import java.nio.file.Path;
    1314import java.nio.file.Paths;
    1415import java.util.ArrayList;
     
    3031import org.openstreetmap.josm.cli.CLIModule;
    3132import org.openstreetmap.josm.data.Preferences;
     33import org.openstreetmap.josm.data.osm.DataSet;
    3234import org.openstreetmap.josm.data.preferences.JosmBaseDirectories;
    3335import org.openstreetmap.josm.data.preferences.JosmUrls;
     
    174176            }
    175177            this.initialize();
    176             final var fileMonitor = progressMonitorFactory.get();
     178            final ProgressMonitor fileMonitor = progressMonitorFactory.get();
    177179            fileMonitor.beginTask(tr("Processing files..."), this.input.size());
    178180            for (String inputFile : this.input) {
     
    200202     */
    201203    private static void processMapcssFile(final String inputFile) throws ParseException {
    202         final var styleSource = new MapCSSStyleSource(new File(inputFile).toURI().getPath(), inputFile, inputFile);
     204        final MapCSSStyleSource styleSource = new MapCSSStyleSource(new File(inputFile).toURI().getPath(), inputFile, inputFile);
    203205        styleSource.loadStyleSource();
    204206        if (!styleSource.getErrors().isEmpty()) {
     
    219221        // Check asserts
    220222        Config.getPref().putBoolean("validator.check_assert_local_rules", true);
    221         final var mapCSSTagChecker = new MapCSSTagChecker();
    222         final var assertionErrors = new ArrayList<String>();
     223        final MapCSSTagChecker mapCSSTagChecker = new MapCSSTagChecker();
     224        final Collection<String> assertionErrors = new ArrayList<>();
    223225        final MapCSSTagChecker.ParseResult result = mapCSSTagChecker.addMapCSS(new File(inputFile).toURI().getPath(),
    224226                assertionErrors::add);
     
    245247     */
    246248    private void processFile(final String inputFile) throws IllegalDataException, IOException {
    247         final var inputFileFile = new File(inputFile);
     249        final File inputFileFile = new File(inputFile);
    248250        final List<FileImporter> inputFileImporters = ExtensionFileFilter.getImporters().stream()
    249251                .filter(importer -> importer.acceptFile(inputFileFile)).collect(Collectors.toList());
    250         final var stopwatch = Stopwatch.createStarted();
     252        final Stopwatch stopwatch = Stopwatch.createStarted();
    251253        if (inputFileImporters.stream().noneMatch(fileImporter ->
    252254                fileImporter.importDataHandleExceptions(inputFileFile, progressMonitorFactory.get()))) {
     
    261263                    .stream().filter(layer -> inputFileFile.equals(layer.getAssociatedFile()))
    262264                    .findFirst().orElseThrow(() -> new JosmRuntimeException(tr("Could not find a layer for {0}", inputFile)));
    263             final var dataSet = dataLayer.getDataSet();
     265            final DataSet dataSet = dataLayer.getDataSet();
    264266            if (this.changeFiles.containsKey(inputFile)) {
    265                 final var changeFilesMonitor = progressMonitorFactory.get();
     267                final ProgressMonitor changeFilesMonitor = progressMonitorFactory.get();
    266268                for (String changeFile : this.changeFiles.getOrDefault(inputFile, Collections.emptyList())) {
    267                     try (var changeStream = Compression.getUncompressedFileInputStream(Paths.get(changeFile))) {
     269                    try (InputStream changeStream = Compression.getUncompressedFileInputStream(Paths.get(changeFile))) {
    268270                        dataSet.mergeFrom(OsmChangeReader.parseDataSet(changeStream, changeFilesMonitor));
    269271                    }
    270272                }
    271273            }
    272             final var path = Paths.get(outputFile);
     274            final Path path = Paths.get(outputFile);
    273275            if (path.toFile().isFile() && !Files.deleteIfExists(path)) {
    274276                Logging.error("Could not delete {0}, attempting to append", outputFile);
    275277            }
    276             final var geoJSONMapRouletteWriter = new GeoJSONMapRouletteWriter(dataSet);
     278            final GeoJSONMapRouletteWriter geoJSONMapRouletteWriter = new GeoJSONMapRouletteWriter(dataSet);
    277279            OsmValidator.initializeTests();
    278280
    279             try (var fileOutputStream = Files.newOutputStream(path)) {
     281            try (OutputStream fileOutputStream = Files.newOutputStream(path)) {
    280282                // The first writeErrors catches anything that was written, for whatever reason. This is probably never
    281283                // going to be called.
     
    346348    /**
    347349     * Initialize everything that might be needed
    348      * <p>
     350     *
    349351     * Arguments may need to be parsed first.
    350352     */
     
    367369        Logging.setLogLevel(Level.INFO);
    368370
    369         final var parser = new OptionParser("JOSM validate");
    370         final var currentInput = new AtomicReference<String>(null);
     371        OptionParser parser = new OptionParser("JOSM validate");
     372        final AtomicReference<String> currentInput = new AtomicReference<>(null);
    371373        for (Option o : Option.values()) {
    372374            if (o.requiresArgument()) {
     
    423425            break;
    424426        case LOAD_PREFERENCES:
    425             final var tempPreferences = new Preferences();
     427            final Preferences tempPreferences = new Preferences();
    426428            tempPreferences.enableSaveOnPut(false);
    427             final var config = new CustomConfigurator.XMLCommandProcessor(tempPreferences);
     429            CustomConfigurator.XMLCommandProcessor config = new CustomConfigurator.XMLCommandProcessor(tempPreferences);
    428430            try (InputStream is = Utils.openStream(new File(argument).toURI().toURL())) {
    429431                config.openAndReadXML(is);
     
    433435            final IPreferences pref = Config.getPref();
    434436            if (pref instanceof MemoryPreferences) {
    435                 final var memoryPreferences = (MemoryPreferences) pref;
     437                final MemoryPreferences memoryPreferences = (MemoryPreferences) pref;
    436438                tempPreferences.getAllSettings().forEach(memoryPreferences::putSetting);
    437439            } else {
     
    452454
    453455    private static String getHelp() {
    454         final var helpPadding = "\t                          ";
     456        final String helpPadding = "\t                          ";
    455457        // CHECKSTYLE.OFF: SingleSpaceSeparator
    456458        return tr("JOSM Validation command line interface") + "\n\n" +
Note: See TracChangeset for help on using the changeset viewer.