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


Ignore:
Timestamp:
2022-06-09T19:22:55+02:00 (3 years ago)
Author:
taylor.smock
Message:

SonarLint: Fix most recent code smells

This also fixes some tests so that the JOSMTestRules is more
accurate for them.

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

Legend:

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

    r18481 r18485  
    8181    private static final String TOOLTIP_DEFAULT = tr("Save the current session.");
    8282
    83     protected FileFilter joz = new ExtensionFileFilter("joz", "joz", tr("Session file (archive) (*.joz)"));
    84     protected FileFilter jos = new ExtensionFileFilter("jos", "jos", tr("Session file (*.jos)"));
     83    protected transient FileFilter joz = new ExtensionFileFilter("joz", "joz", tr("Session file (archive) (*.joz)"));
     84    protected transient FileFilter jos = new ExtensionFileFilter("jos", "jos", tr("Session file (*.jos)"));
    8585
    8686    private File removeFileOnSuccess;
    8787
    8888    private static String tooltip = TOOLTIP_DEFAULT;
    89     protected static File sessionFile;
    90     protected static boolean isZipSessionFile;
    91     protected static List<WeakReference<Layer>> layersInSessionFile;
     89    static File sessionFile;
     90    static boolean isZipSessionFile;
     91    static List<WeakReference<Layer>> layersInSessionFile;
    9292
    9393    private static final SessionSaveAction instance = new SessionSaveAction();
     
    9797     * @return the instance
    9898     */
    99     public static final SessionSaveAction getInstance() {
     99    public static SessionSaveAction getInstance() {
    100100        return instance;
    101101    }
     
    132132        try {
    133133            saveSession(false, false);
    134         } catch (UserCancelException ignore) {
    135             Logging.trace(ignore);
     134        } catch (UserCancelException exception) {
     135            Logging.trace(exception);
    136136        }
    137137    }
     
    203203        setCurrentLayers(layersOut);
    204204
    205 
    206         if (fn.indexOf('.') == -1) {
    207             sessionFile = new File(sessionFile.getPath() + (isZipSessionFile ? ".joz" : ".jos"));
    208             if (!SaveActionBase.confirmOverwrite(sessionFile)) {
    209                 throw new UserCancelException();
    210             }
    211         }
     205        updateSessionFile(fn);
    212206
    213207        Stream<Layer> layersToSaveStream = layersOut.stream()
     
    219213
    220214        boolean success = true;
    221         if (forceSaveAll || SAVE_LOCAL_FILES_PROPERTY.get()) {
     215        if (forceSaveAll || Boolean.TRUE.equals(SAVE_LOCAL_FILES_PROPERTY.get())) {
    222216            // individual files must be saved before the session file as the location may change
    223217            if (layersToSaveStream
     
    394388
    395389            int numNoExporter = 0;
    396             WHILE: while (numNoExporter != noExporter.size()) {
     390            while (numNoExporter != noExporter.size()) {
    397391                numNoExporter = noExporter.size();
    398                 for (Layer layer : layers) {
    399                     if (noExporter.contains(layer)) continue;
    400                     for (Layer depLayer : dependencies.get(layer)) {
    401                         if (noExporter.contains(depLayer)) {
    402                             noExporter.add(layer);
    403                             exporters.put(layer, null);
    404                             break WHILE;
    405                         }
     392                updateExporters(noExporter);
     393            }
     394        }
     395
     396        private void updateExporters(Collection<Layer> noExporter) {
     397            for (Layer layer : layers) {
     398                if (noExporter.contains(layer)) continue;
     399                for (Layer depLayer : dependencies.get(layer)) {
     400                    if (noExporter.contains(depLayer)) {
     401                        noExporter.add(layer);
     402                        exporters.put(layer, null);
     403                        return;
    406404                    }
    407405                }
     
    436434            op.add(tabs, GBC.eol().fill());
    437435            JCheckBox chkSaveLocal = new JCheckBox(tr("Save all local files to disk"), SAVE_LOCAL_FILES_PROPERTY.get());
    438             chkSaveLocal.addChangeListener(l -> {
    439                 SAVE_LOCAL_FILES_PROPERTY.put(chkSaveLocal.isSelected());
    440             });
     436            chkSaveLocal.addChangeListener(l -> SAVE_LOCAL_FILES_PROPERTY.put(chkSaveLocal.isSelected()));
    441437            op.add(chkSaveLocal);
    442438            return op;
     
    496492
    497493    /**
     494     * Update the session file
     495     * @param fileName The filename to use. If there are no periods in the file, we update the extension.
     496     * @throws UserCancelException If the user does not want to overwrite a previously existing file.
     497     */
     498    private static void updateSessionFile(String fileName) throws UserCancelException {
     499        if (fileName.indexOf('.') == -1) {
     500            sessionFile = new File(sessionFile.getPath() + (isZipSessionFile ? ".joz" : ".jos"));
     501            if (!SaveActionBase.confirmOverwrite(sessionFile)) {
     502                throw new UserCancelException();
     503            }
     504        }
     505    }
     506
     507    /**
    498508     * Sets the current session file and the layers included in that file
    499509     * @param file file
     
    528538    public static void setCurrentLayers(List<Layer> layers) {
    529539        layersInSessionFile = layers.stream()
    530                 .filter(l -> l instanceof AbstractModifiableLayer)
     540                .filter(AbstractModifiableLayer.class::isInstance)
    531541                .map(WeakReference::new)
    532542                .collect(Collectors.toList());
  • trunk/src/org/openstreetmap/josm/actions/mapmode/SelectAction.java

    r18468 r18485  
    402402        mouseDownButton = e.getButton();
    403403        // return early
    404         if (!mv.isActiveLayerVisible() || !(Boolean) this.getValue("active") || mouseDownButton != MouseEvent.BUTTON1)
     404        if (!mv.isActiveLayerVisible() || Boolean.FALSE.equals(this.getValue("active")) || mouseDownButton != MouseEvent.BUTTON1)
    405405            return;
    406406
     
    744744                                dh += Math.PI/2;
    745745                                break;
     746                            default:
     747                                // Just in case we cannot clamp
    746748                            }
    747749                            clampedEastNorth = currentEN.rotate(startEN, -dh);
     
    11491151                        // special case:  for cycle groups of 2, we can toggle to the
    11501152                        // true nearest primitive on mousePressed right away
    1151                         if (cycleList.size() == 2 && !waitForMouseUpParameter) {
    1152                             if (!(osm.equals(old) || osm.isNew() || platformMenuShortcutKeyMask)) {
     1153                        if (cycleList.size() == 2 && !waitForMouseUpParameter
     1154                                // This was a nested if statement (see commented code below)
     1155                                && (!(osm.equals(old) || osm.isNew() || platformMenuShortcutKeyMask))) {
    11531156                                cyclePrims = false;
    11541157                                osm = old;
    1155                             } // else defer toggling to mouseRelease time in those cases:
     1158                            // else defer toggling to mouseRelease time in those cases:
    11561159                            /*
    11571160                             * osm == old -- the true nearest node is the
  • trunk/src/org/openstreetmap/josm/data/imagery/vectortile/mapbox/Feature.java

    r18473 r18485  
    5757     *
    5858     * @param layer  The layer the feature is part of (required for tags)
    59      * @param record The record to create the feature from
     59     * @param protobufRecord The record to create the feature from
    6060     * @throws IOException - if an IO error occurs
    6161     */
    62     public Feature(Layer layer, ProtobufRecord record) throws IOException {
     62    public Feature(Layer layer, ProtobufRecord protobufRecord) throws IOException {
    6363        long tId = 0;
    6464        GeometryTypes geometryTypeTemp = GeometryTypes.UNKNOWN;
     
    6969        // By avoiding array copies in TagMap, Feature#init goes from 339 MB to 188 MB.
    7070        ArrayList<String> tagList = null;
    71         try (ProtobufParser parser = new ProtobufParser(record.getBytes())) {
     71        try (ProtobufParser parser = new ProtobufParser(protobufRecord.getBytes())) {
    7272            ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(4);
    7373            while (parser.hasNext()) {
     
    111111        this.id = tId;
    112112        this.geometryType = geometryTypeTemp;
    113         record.close();
     113        protobufRecord.close();
    114114        if (tagList != null && !tagList.isEmpty()) {
    115115            this.tags = new TagMap(tagList.toArray(EMPTY_STRING_ARRAY));
     
    128128     * @return The new key (if {@code null}, then a value was parsed and added to tags)
    129129     */
    130     private String parseTagValue(String key, Layer layer, Number number, List<String> tagList) {
     130    private static String parseTagValue(String key, Layer layer, Number number, List<String> tagList) {
    131131        if (key == null) {
    132132            key = layer.getKey(number.intValue());
Note: See TracChangeset for help on using the changeset viewer.