Changeset 9062 in josm for trunk/src/org


Ignore:
Timestamp:
2015-11-25T01:21:14+01:00 (9 years ago)
Author:
Don-vip
Message:

Sonar - squid:S1941 - Variables should not be declared before they are relevant

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

Legend:

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

    r8870 r9062  
    162162        }
    163163
    164         // now we can start doing things to OSM data
    165         Collection<Command> cmds = new LinkedList<>();
    166         EastNorth center = null;
     164        EastNorth center;
    167165
    168166        if (nodes.size() == 2) {
     
    201199        int[] count = distributeNodes(angles,
    202200                numberOfNodesInCircle >= nodes.size() ? numberOfNodesInCircle - nodes.size() : 0);
     201
     202        // now we can start doing things to OSM data
     203        Collection<Command> cmds = new LinkedList<>();
    203204
    204205        // build a way for the circle
  • trunk/src/org/openstreetmap/josm/actions/CreateMultipolygonAction.java

    r8870 r9062  
    141141
    142142        final Collection<Way> selectedWays = Main.main.getCurrentDataSet().getSelectedWays();
    143         final Collection<Relation> selectedRelations = Main.main.getCurrentDataSet().getSelectedRelations();
    144143
    145144        if (selectedWays.isEmpty()) {
     
    154153        }
    155154
     155        final Collection<Relation> selectedRelations = Main.main.getCurrentDataSet().getSelectedRelations();
    156156        final Relation multipolygonRelation = update
    157157                ? getSelectedMultipolygonRelation(selectedWays, selectedRelations)
  • trunk/src/org/openstreetmap/josm/actions/JoinAreasAction.java

    r8955 r9062  
    768768    private List<WayInPolygon> markWayInsideSide(List<Way> parts, boolean isInner) {
    769769
    770         List<WayInPolygon> result = new ArrayList<>();
    771 
    772770        //prepare next map
    773771        Map<Way, Way> nextWayMap = new HashMap<>();
     
    854852        Way curWay = topWay;
    855853        boolean curWayInsideToTheRight = wayClockwise ^ isInner;
     854        List<WayInPolygon> result = new ArrayList<>();
    856855
    857856        //iterate till full circle is reached
  • trunk/src/org/openstreetmap/josm/actions/JumpToAction.java

    r8670 r9062  
    9797
    9898        double dist = mv.getDist100Pixel();
    99         double zoomFactor = 1/dist;
    100 
    10199        zm.setText(Long.toString(Math.round(dist*100)/100));
    102100        updateUrl(true);
     
    161159        }
    162160
     161        double zoomFactor = 1/dist;
    163162        mv.zoomToFactor(mv.getProjection().latlon2eastNorth(ll), zoomFactor * zoomLvl);
    164163    }
  • trunk/src/org/openstreetmap/josm/actions/MergeNodesAction.java

    r8919 r9062  
    314314        try {
    315315            TagCollection nodeTags = TagCollection.unionOfAllPrimitives(nodes);
    316             List<Command> resultion = CombinePrimitiveResolverDialog.launchIfNecessary(nodeTags, nodes, Collections.singleton(targetNode));
    317             List<Command> cmds = new LinkedList<>();
    318316
    319317            // the nodes we will have to delete
     
    324322            // fix the ways referring to at least one of the merged nodes
    325323            //
    326             Collection<Way> waysToDelete = new HashSet<>();
    327             List<Command> wayFixCommands = fixParentWays(
    328                     nodesToDelete,
    329                     targetNode);
     324            List<Command> wayFixCommands = fixParentWays(nodesToDelete, targetNode);
    330325            if (wayFixCommands == null) {
    331326                return null;
    332327            }
    333             cmds.addAll(wayFixCommands);
     328            List<Command> cmds = new LinkedList<>(wayFixCommands);
    334329
    335330            // build the commands
     
    343338                }
    344339            }
    345             cmds.addAll(resultion);
     340            cmds.addAll(CombinePrimitiveResolverDialog.launchIfNecessary(nodeTags, nodes, Collections.singleton(targetNode)));
    346341            if (!nodesToDelete.isEmpty()) {
    347342                cmds.add(new DeleteCommand(nodesToDelete));
    348             }
    349             if (!waysToDelete.isEmpty()) {
    350                 cmds.add(new DeleteCommand(waysToDelete));
    351343            }
    352344            return new SequenceCommand(/* for correct i18n of plural forms - see #9110 */
  • trunk/src/org/openstreetmap/josm/actions/OpenLocationAction.java

    r8510 r9062  
    189189     */
    190190    public void openUrl(boolean newLayer, final String url) {
    191         PleaseWaitProgressMonitor monitor = new PleaseWaitProgressMonitor(tr("Download Data"));
    192191        Collection<DownloadTask> tasks = findDownloadTasks(url, false);
    193192
     
    198197            return;
    199198        }
     199
     200        PleaseWaitProgressMonitor monitor = new PleaseWaitProgressMonitor(tr("Download Data"));
    200201
    201202        for (final DownloadTask task : tasks) {
     
    207208            }
    208209        }
    209 
    210210    }
    211211
  • trunk/src/org/openstreetmap/josm/actions/SelectNonBranchingWaySequences.java

    r8780 r9062  
    136136     */
    137137    public void extend(DataSet data) {
    138         Collection<OsmPrimitive> currentSelection;
    139         Collection<OsmPrimitive> selection;
    140         boolean selectionChanged = false;
    141         Way way;
    142 
    143138        if (!canExtend())
    144139            return;
    145140
    146         currentSelection = data.getSelected();
     141        Collection<OsmPrimitive> currentSelection = data.getSelected();
    147142
    148         way = findWay(currentSelection);
     143        Way way = findWay(currentSelection);
    149144
    150145        if (way == null)
    151146            return;
    152147
    153         selection = new LinkedList<>();
     148        boolean selectionChanged = false;
     149        Collection<OsmPrimitive> selection = new LinkedList<>();
    154150        for (OsmPrimitive primitive : currentSelection) {
    155151            selection.add(primitive);
  • trunk/src/org/openstreetmap/josm/actions/SessionSaveAsAction.java

    r8919 r9062  
    230230
    231231        protected final Component build() {
    232             JPanel p = new JPanel(new GridBagLayout());
    233232            JPanel ip = new JPanel(new GridBagLayout());
    234233            for (Layer layer : layers) {
     
    249248            JScrollPane sp = new JScrollPane(ip);
    250249            sp.setBorder(BorderFactory.createEmptyBorder());
     250            JPanel p = new JPanel(new GridBagLayout());
    251251            p.add(sp, GBC.eol().fill());
    252252            final JTabbedPane tabs = new JTabbedPane();
  • trunk/src/org/openstreetmap/josm/actions/SplitWayAction.java

    r8990 r9062  
    137137        List<Node> selectedNodes = OsmPrimitive.getFilteredList(selection, Node.class);
    138138        List<Way> selectedWays = OsmPrimitive.getFilteredList(selection, Way.class);
    139         List<Relation> selectedRelations =
    140             OsmPrimitive.getFilteredList(selection, Relation.class);
    141139        List<Way> applicableWays = getApplicableWays(selectedWays, selectedNodes);
    142140
     
    191189        final List<List<Node>> wayChunks = buildSplitChunks(selectedWay, selectedNodes);
    192190        if (wayChunks != null) {
     191            List<Relation> selectedRelations =
     192                    OsmPrimitive.getFilteredList(selection, Relation.class);
    193193            final List<OsmPrimitive> sel = new ArrayList<>(selectedWays.size() + selectedRelations.size());
    194194            sel.addAll(selectedWays);
  • trunk/src/org/openstreetmap/josm/actions/UploadSelectionAction.java

    r8856 r9062  
    101101            }
    102102        }
    103         UploadHullBuilder builder = new UploadHullBuilder();
    104         UploadSelectionDialog dialog = new UploadSelectionDialog();
    105103        Collection<OsmPrimitive> modifiedCandidates = getModifiedPrimitives(getEditLayer().data.getAllSelected());
    106104        Collection<OsmPrimitive> deletedCandidates = getDeletedPrimitives(getEditLayer().data);
     
    114112            return;
    115113        }
     114        UploadSelectionDialog dialog = new UploadSelectionDialog();
    116115        dialog.populate(
    117116                modifiedCandidates,
     
    121120        if (dialog.isCanceled())
    122121            return;
    123         Collection<OsmPrimitive> toUpload = builder.build(dialog.getSelectedPrimitives());
     122        Collection<OsmPrimitive> toUpload = new UploadHullBuilder().build(dialog.getSelectedPrimitives());
    124123        if (toUpload.isEmpty()) {
    125124            JOptionPane.showMessageDialog(
  • trunk/src/org/openstreetmap/josm/actions/mapmode/AddNoteAction.java

    r8308 r9062  
    6868        }
    6969        Main.map.selectMapMode(Main.map.mapModeSelect);
    70         LatLon latlon = Main.map.mapView.getLatLon(e.getPoint().x, e.getPoint().y);
    7170
    7271        NoteInputDialog dialog = new NoteInputDialog(Main.parent, tr("Create new note"), tr("Create note"));
     
    7978        String input = dialog.getInputText();
    8079        if (input != null && !input.isEmpty()) {
     80            LatLon latlon = Main.map.mapView.getLatLon(e.getPoint().x, e.getPoint().y);
    8181            noteData.createNote(latlon, input);
    8282        } else {
  • trunk/src/org/openstreetmap/josm/actions/mapmode/DrawAction.java

    r9059 r9062  
    394394        DataSet ds = getCurrentDataSet();
    395395        Collection<OsmPrimitive> selection = new ArrayList<>(ds.getSelected());
    396         Collection<Command> cmds = new LinkedList<>();
    397         Collection<OsmPrimitive> newSelection = new LinkedList<>(ds.getSelected());
    398 
    399         List<Way> reuseWays = new ArrayList<>(),
    400                 replacedWays = new ArrayList<>();
     396
    401397        boolean newNode = false;
    402398        Node n = null;
     
    451447            snapHelper.unsetFixedMode();
    452448        }
     449
     450        Collection<Command> cmds = new LinkedList<>();
     451        Collection<OsmPrimitive> newSelection = new LinkedList<>(ds.getSelected());
     452        List<Way> reuseWays = new ArrayList<>();
     453        List<Way> replacedWays = new ArrayList<>();
    453454
    454455        if (newNode) {
     
    769770     */
    770771    private void computeHelperLine() {
    771         MapView mv = Main.map.mapView;
    772772        if (mousePos == null) {
    773773            // Don't draw the line.
     
    779779        Collection<OsmPrimitive> selection = getCurrentDataSet().getSelected();
    780780
     781        MapView mv = Main.map.mapView;
    781782        Node currentMouseNode = null;
    782783        mouseOnExistingNode = null;
     
    12711272        public void actionPerformed(ActionEvent e) {
    12721273            Main.main.undoRedo.undo();
    1273             Node n = null;
    12741274            Command lastCmd = Main.main.undoRedo.commands.peekLast();
    12751275            if (lastCmd == null) return;
     1276            Node n = null;
    12761277            for (OsmPrimitive p: lastCmd.getParticipatingPrimitives()) {
    12771278                if (p instanceof Node) {
  • trunk/src/org/openstreetmap/josm/actions/mapmode/ParallelWayAction.java

    r8870 r9062  
    393393        mouseHasBeenDragged = true;
    394394
    395         Point p = e.getPoint();
    396395        if (mode == Mode.normal) {
    397396            // Should we ensure that the copyTags modifiers are still valid?
     
    407406
    408407        // Calculate distance to the reference line
     408        Point p = e.getPoint();
    409409        EastNorth enp = mv.getEastNorth((int) p.getX(), (int) p.getY());
    410410        EastNorth nearestPointOnRefLine = Geometry.closestPointToLine(referenceSegment.getFirstNode().getEastNorth(),
  • trunk/src/org/openstreetmap/josm/actions/mapmode/SelectAction.java

    r8985 r9062  
    11021102         */
    11031103        private Collection<OsmPrimitive> cyclePrims() {
    1104             OsmPrimitive nxt = null;
    1105 
    11061104            if (cycleList.size() <= 1) {
    11071105                // no real cycling, just return one-element collection with nearest primitive in it
     
    11121110            DataSet ds = getCurrentDataSet();
    11131111            OsmPrimitive first = cycleList.iterator().next(), foundInDS = null;
    1114             nxt = first;
     1112            OsmPrimitive nxt = first;
    11151113
    11161114            if (cyclePrims && shift) {
  • trunk/src/org/openstreetmap/josm/command/DeleteCommand.java

    r8855 r9062  
    374374            return null;
    375375
    376         Collection<Way> waysToBeChanged = new HashSet<>();
    377 
    378376        if (alsoDeleteNodesInWay) {
    379377            // delete untagged nodes only referenced by primitives in primitivesToDelete, too
     
    386384            return null;
    387385
    388         waysToBeChanged.addAll(OsmPrimitive.getFilteredSet(OsmPrimitive.getReferrer(primitivesToDelete), Way.class));
     386        Collection<Way> waysToBeChanged = new HashSet<>(OsmPrimitive.getFilteredSet(OsmPrimitive.getReferrer(primitivesToDelete), Way.class));
    389387
    390388        Collection<Command> cmds = new LinkedList<>();
  • trunk/src/org/openstreetmap/josm/command/PurgeCommand.java

    r8931 r9062  
    200200        @SuppressWarnings({ "unchecked", "rawtypes" })
    201201        Set<Relation> inR = (Set) in;
    202         Set<Relation> childlessR = new HashSet<>();
    203         List<Relation> outR = new ArrayList<>(inR.size());
    204202
    205203        Map<Relation, Integer> numChilds = new HashMap<>();
     
    219217            }
    220218        }
     219        Set<Relation> childlessR = new HashSet<>();
    221220        for (Relation r : inR) {
    222221            if (numChilds.get(r).equals(0)) {
     
    225224        }
    226225
     226        List<Relation> outR = new ArrayList<>(inR.size());
    227227        while (!childlessR.isEmpty()) {
    228228            // Identify one childless Relation and
  • trunk/src/org/openstreetmap/josm/corrector/TagCorrector.java

    r8919 r9062  
    139139            if (answer == JOptionPane.YES_OPTION) {
    140140                for (Entry<OsmPrimitive, List<TagCorrection>> entry : tagCorrectionsMap.entrySet()) {
    141                     List<TagCorrection> tagCorrections = entry.getValue();
    142141                    OsmPrimitive primitive = entry.getKey();
    143142
     
    158157
    159158                    // apply all changes to this clone
     159                    List<TagCorrection> tagCorrections = entry.getValue();
    160160                    for (int i = 0; i < tagCorrections.size(); i++) {
    161161                        if (tagTableMap.get(primitive).getCorrectionTableModel().getApply(i)) {
  • trunk/src/org/openstreetmap/josm/plugins/PluginHandler.java

    r9059 r9062  
    380380        if (message == null) return false;
    381381
     382        UpdatePluginsMessagePanel pnlMessage = new UpdatePluginsMessagePanel();
     383        pnlMessage.setMessage(message);
     384        pnlMessage.initDontShowAgain(togglePreferenceKey);
     385
     386        // check whether automatic update at startup was disabled
     387        //
     388        String policy = Main.pref.get(togglePreferenceKey, "ask").trim().toLowerCase(Locale.ENGLISH);
     389        switch(policy) {
     390        case "never":
     391            if ("pluginmanager.version-based-update.policy".equals(togglePreferenceKey)) {
     392                Main.info(tr("Skipping plugin update after JOSM upgrade. Automatic update at startup is disabled."));
     393            } else if ("pluginmanager.time-based-update.policy".equals(togglePreferenceKey)) {
     394                Main.info(tr("Skipping plugin update after elapsed update interval. Automatic update at startup is disabled."));
     395            }
     396            return false;
     397
     398        case "always":
     399            if ("pluginmanager.version-based-update.policy".equals(togglePreferenceKey)) {
     400                Main.info(tr("Running plugin update after JOSM upgrade. Automatic update at startup is enabled."));
     401            } else if ("pluginmanager.time-based-update.policy".equals(togglePreferenceKey)) {
     402                Main.info(tr("Running plugin update after elapsed update interval. Automatic update at startup is disabled."));
     403            }
     404            return true;
     405
     406        case "ask":
     407            break;
     408
     409        default:
     410            Main.warn(tr("Unexpected value ''{0}'' for preference ''{1}''. Assuming value ''ask''.", policy, togglePreferenceKey));
     411        }
     412
    382413        ButtonSpec[] options = new ButtonSpec[] {
    383414                new ButtonSpec(
     
    394425                )
    395426        };
    396 
    397         UpdatePluginsMessagePanel pnlMessage = new UpdatePluginsMessagePanel();
    398         pnlMessage.setMessage(message);
    399         pnlMessage.initDontShowAgain(togglePreferenceKey);
    400 
    401         // check whether automatic update at startup was disabled
    402         //
    403         String policy = Main.pref.get(togglePreferenceKey, "ask").trim().toLowerCase(Locale.ENGLISH);
    404         switch(policy) {
    405         case "never":
    406             if ("pluginmanager.version-based-update.policy".equals(togglePreferenceKey)) {
    407                 Main.info(tr("Skipping plugin update after JOSM upgrade. Automatic update at startup is disabled."));
    408             } else if ("pluginmanager.time-based-update.policy".equals(togglePreferenceKey)) {
    409                 Main.info(tr("Skipping plugin update after elapsed update interval. Automatic update at startup is disabled."));
    410             }
    411             return false;
    412 
    413         case "always":
    414             if ("pluginmanager.version-based-update.policy".equals(togglePreferenceKey)) {
    415                 Main.info(tr("Running plugin update after JOSM upgrade. Automatic update at startup is enabled."));
    416             } else if ("pluginmanager.time-based-update.policy".equals(togglePreferenceKey)) {
    417                 Main.info(tr("Running plugin update after elapsed update interval. Automatic update at startup is disabled."));
    418             }
    419             return true;
    420 
    421         case "ask":
    422             break;
    423 
    424         default:
    425             Main.warn(tr("Unexpected value ''{0}'' for preference ''{1}''. Assuming value ''ask''.", policy, togglePreferenceKey));
    426         }
    427427
    428428        int ret = HelpAwareOptionPane.showOptionDialog(
  • trunk/src/org/openstreetmap/josm/plugins/ReadRemotePluginInformationTask.java

    r8540 r9062  
    315315        if (sites == null) return;
    316316        getProgressMonitor().setTicksCount(sites.size() * 3);
    317         File pluginDir = Main.pref.getPluginsDirectory();
    318317
    319318        // collect old cache files and remove if no longer in use
     
    334333        }
    335334
     335        File pluginDir = Main.pref.getPluginsDirectory();
    336336        for (String site: sites) {
    337337            String printsite = site.replaceAll("%<(.*)>", "");
  • trunk/src/org/openstreetmap/josm/tools/Geometry.java

    r9059 r9062  
    352352        double a2 = p4.getY() - p3.getY();
    353353        double b2 = p3.getX() - p4.getX();
    354         double c2 = (p4.getX() - p1.getX()) * (p3.getY() - p1.getY()) - (p3.getX() - p1.getX()) * (p4.getY() - p1.getY());
    355354
    356355        // Solve the equations
     
    358357        if (det == 0)
    359358            return null; // Lines are parallel
     359
     360        double c2 = (p4.getX() - p1.getX()) * (p3.getY() - p1.getY()) - (p3.getX() - p1.getX()) * (p4.getY() - p1.getY());
    360361
    361362        return new EastNorth(b1 * c2 / det + p1.getX(), -a1 * c2 / det + p1.getY());
     
    573574            return false;
    574575
     576        //iterate each side of the polygon, start with the last segment
     577        Node oldPoint = polygonNodes.get(polygonNodes.size() - 1);
     578
     579        if (!oldPoint.isLatLonKnown()) {
     580            return false;
     581        }
     582
    575583        boolean inside = false;
    576584        Node p1, p2;
    577 
    578         //iterate each side of the polygon, start with the last segment
    579         Node oldPoint = polygonNodes.get(polygonNodes.size() - 1);
    580 
    581         if (!oldPoint.isLatLonKnown()) {
    582             return false;
    583         }
    584585
    585586        for (Node newPoint : polygonNodes) {
     
    708709     */
    709710    public static boolean isClockwise(List<Node> nodes) {
    710         double area2 = 0.;
    711711        int nodesCount = nodes.size();
    712712        if (nodesCount < 3 || nodes.get(0) != nodes.get(nodesCount - 1)) {
    713713            throw new IllegalArgumentException("Way must be closed to check orientation.");
    714714        }
     715        double area2 = 0.;
    715716
    716717        for (int node = 1; node <= /*sic! consider last-first as well*/ nodesCount; node++) {
  • trunk/src/org/openstreetmap/josm/tools/I18n.java

    r8989 r9062  
    583583                    }
    584584                    String[] enstrings = new String[ennum];
    585                     String[] trstrings = new String[trnum];
    586585                    for (int i = 0; i < ennum; ++i) {
    587586                        int val = ens.read(enlen);
     
    597596                        enstrings[i] = new String(str, 0, val, StandardCharsets.UTF_8);
    598597                    }
     598                    String[] trstrings = new String[trnum];
    599599                    for (int i = 0; i < trnum; ++i) {
    600600                        int val = trs.read(trlen);
  • trunk/src/org/openstreetmap/josm/tools/ImageProvider.java

    r8992 r9062  
    836836        Matcher m = dataUrlPattern.matcher(url);
    837837        if (m.matches()) {
    838             String mediatype = m.group(1);
    839838            String base64 = m.group(2);
    840839            String data = m.group(3);
     
    850849                }
    851850            }
     851            String mediatype = m.group(1);
    852852            if ("image/svg+xml".equals(mediatype)) {
    853853                String s = new String(bytes, StandardCharsets.UTF_8);
  • trunk/src/org/openstreetmap/josm/tools/OsmUrlToBounds.java

    r8846 r9062  
    9393        }
    9494        int zoom;
    95         double lat, lon;
    9695        try {
    9796            zoom = Integer.parseInt(parts[0]);
     
    10099            return null;
    101100        }
     101        double lat, lon;
    102102        try {
    103103            lat = Double.parseDouble(parts[1]);
  • trunk/src/org/openstreetmap/josm/tools/WindowGeometry.java

    r8924 r9062  
    6767     */
    6868    public static WindowGeometry centerInWindow(Component reference, Dimension extent) {
    69         Window parentWindow = null;
    7069        while (reference != null && !(reference instanceof Window)) {
    7170            reference = reference.getParent();
     
    7372        if (reference == null)
    7473            return new WindowGeometry(new Point(0, 0), extent);
    75         parentWindow = (Window) reference;
     74        Window parentWindow = (Window) reference;
    7675        Point topLeft = new Point(
    7776                Math.max(0, (parentWindow.getSize().width - extent.width) /2),
  • trunk/src/org/openstreetmap/josm/tools/date/PrimaryDateParser.java

    r8870 r9062  
    4141
    4242    private static boolean isDateInShortStandardFormat(String date) {
    43         char[] dateChars;
    4443        // We can only parse the date if it is in a very specific format.
    4544        // eg. 2007-09-23T08:25:43Z
     
    4948        }
    5049
    51         dateChars = date.toCharArray();
     50        char[] dateChars = date.toCharArray();
    5251
    5352        // Make sure any fixed characters are in the correct place.
     
    108107
    109108    private static boolean isDateInLongStandardFormat(String date) {
    110         char[] dateChars;
    111109        // We can only parse the date if it is in a very specific format.
    112110        // eg. 2007-09-23T08:25:43.000Z
     
    116114        }
    117115
    118         dateChars = date.toCharArray();
     116        char[] dateChars = date.toCharArray();
    119117
    120118        // Make sure any fixed characters are in the correct place.
Note: See TracChangeset for help on using the changeset viewer.