Changeset 14638 in josm


Ignore:
Timestamp:
2019-01-04T22:24:55+01:00 (4 months ago)
Author:
simon04
Message:

Run PMD on scripts/ and apply fixes

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/build.xml

    r14637 r14638  
    962962                <exclude name="org/openstreetmap/josm/gui/mappaint/mapcss/parsergen/*.java" />
    963963            </fileset>
     964            <fileset dir="${base.dir}/scripts" includes="**/*.java"/>
    964965        </pmd>
    965966    </target>
  • trunk/scripts/BuildProjectionDefinitions.java

    r14637 r14638  
    11// License: GPL. For details, see LICENSE file.
    22
    3 import java.io.BufferedWriter;
    4 import java.io.File;
    5 import java.io.FileOutputStream;
     3import java.io.BufferedReader;
    64import java.io.IOException;
    7 import java.io.OutputStreamWriter;
     5import java.io.Writer;
    86import java.nio.charset.StandardCharsets;
     7import java.nio.file.Files;
     8import java.nio.file.Path;
     9import java.nio.file.Paths;
    910import java.util.Arrays;
    10 import java.util.Collections;
    1111import java.util.LinkedHashMap;
    1212import java.util.List;
     
    1616import java.util.regex.Matcher;
    1717import java.util.regex.Pattern;
     18import java.util.stream.Collectors;
    1819
    1920import org.openstreetmap.josm.data.projection.CustomProjection;
     
    4344
    4445    // statistics:
    45     private static int noInJosm = 0;
    46     private static int noInProj4 = 0;
    47     private static int noDeprecated = 0;
    48     private static int noGeocent = 0;
    49     private static int noBaseProjection = 0;
    50     private static int noEllipsoid = 0;
    51     private static int noNadgrid = 0;
    52     private static int noDatumgrid = 0;
    53     private static int noJosm = 0;
    54     private static int noProj4 = 0;
    55     private static int noEsri = 0;
    56     private static int noOmercNoBounds = 0;
    57     private static int noEquatorStereo = 0;
     46    private static int noInJosm;
     47    private static int noInProj4;
     48    private static int noDeprecated;
     49    private static int noGeocent;
     50    private static int noBaseProjection;
     51    private static int noEllipsoid;
     52    private static int noNadgrid;
     53    private static int noDatumgrid;
     54    private static int noJosm;
     55    private static int noProj4;
     56    private static int noEsri;
     57    private static int noOmercNoBounds;
     58    private static int noEquatorStereo;
    5859
    5960    private static final Map<String, Integer> baseProjectionMap = new TreeMap<>();
     
    7778    }
    7879
    79     static List<String> initList(String baseDir, String ext) {
    80         String[] result = new File(baseDir + File.separator + PROJ_DIR)
    81                 .list((dir, name) -> !name.contains(".") || name.toLowerCase(Locale.ENGLISH).endsWith(ext));
    82         return result != null ? Arrays.asList(result) : Collections.emptyList();
     80    static List<String> initList(String baseDir, String ext) throws IOException {
     81        return Files.list(Paths.get(baseDir).resolve(PROJ_DIR))
     82                .map(path -> path.getFileName().toString())
     83                .filter(name -> !name.contains(".") || name.toLowerCase(Locale.ENGLISH).endsWith(ext))
     84                .collect(Collectors.toList());
    8385    }
    8486
    8587    static void initMap(String baseDir, String file, Map<String, ProjectionDefinition> map) throws IOException {
    86         List<ProjectionDefinition> list = Projections.loadProjectionDefinitions(
    87                 baseDir + File.separator + PROJ_DIR + File.separator + file);
     88        final Path path = Paths.get(baseDir).resolve(PROJ_DIR).resolve(file);
     89        final List<ProjectionDefinition> list;
     90        try (BufferedReader reader = Files.newBufferedReader(path, StandardCharsets.UTF_8)) {
     91            list = Projections.loadProjectionDefinitions(reader);
     92        }
    8893        if (list.isEmpty())
    8994            throw new AssertionError("EPSG file seems corrupted");
     
    109114        knownNadgrids = initList(baseDir, ".gsb");
    110115
    111         try (FileOutputStream output = new FileOutputStream(baseDir + File.separator + OUTPUT_EPSG_FILE);
    112              BufferedWriter out = new BufferedWriter(new OutputStreamWriter(output, StandardCharsets.UTF_8))) {
     116        try (Writer out = Files.newBufferedWriter(Paths.get(baseDir).resolve(OUTPUT_EPSG_FILE), StandardCharsets.UTF_8)) {
    113117            out.write("## This file is autogenerated, do not edit!\n");
    114118            out.write("## Run ant task \"epsg\" to rebuild.\n");
     
    180184    }
    181185
    182     static void write(BufferedWriter out, ProjectionDefinition pd) throws IOException {
     186    static void write(Writer out, ProjectionDefinition pd) throws IOException {
    183187        out.write("# " + pd.name + "\n");
    184188        out.write("<"+pd.code.substring("EPSG:".length())+"> "+pd.definition+" <>\n");
     
    246250            parameters = CustomProjection.parseParameterList(pd.definition, true);
    247251        } catch (ProjectionConfigurationException ex) {
    248             throw new RuntimeException(pd.code+":"+ex);
     252            throw new IllegalStateException(pd.code + ":" + ex, ex);
    249253        }
    250254        String proj = parameters.get(CustomProjection.Param.proj.key);
     
    306310        }
    307311
    308         final double EPS10 = 1.e-10;
     312        final double eps10 = 1.e-10;
    309313
    310314        String lat0 = parameters.get("lat_0");
     
    313317                final double latitudeOfOrigin = Math.toRadians(CustomProjection.parseAngle(lat0, Param.lat_0.key));
    314318                // TODO: implement equatorial stereographic, see https://josm.openstreetmap.de/ticket/15970
    315                 if (result && "stere".equals(proj) && Math.abs(latitudeOfOrigin) < EPS10) {
     319                if (result && "stere".equals(proj) && Math.abs(latitudeOfOrigin) < eps10) {
    316320                    result = false;
    317321                    noEquatorStereo++;
     
    320324                // exclude entries which need geodesic computation (equatorial/oblique azimuthal equidistant)
    321325                if (result && "aeqd".equals(proj)) {
    322                     final double HALF_PI = Math.PI / 2;
    323                     if (Math.abs(latitudeOfOrigin - HALF_PI) >= EPS10 &&
    324                         Math.abs(latitudeOfOrigin + HALF_PI) >= EPS10) {
     326                    final double halfPi = Math.PI / 2;
     327                    if (Math.abs(latitudeOfOrigin - halfPi) >= eps10 &&
     328                        Math.abs(latitudeOfOrigin + halfPi) >= eps10) {
    325329                        // See https://josm.openstreetmap.de/ticket/16129#comment:21
    326330                        result = false;
     
    338342        }
    339343
    340         String k_0 = parameters.get("k_0");
    341         if (result && k_0 != null && k_0.startsWith("-")) {
     344        String k0 = parameters.get("k_0");
     345        if (result && k0 != null && k0.startsWith("-")) {
    342346            // Proj fails with "k <= 0" for ESRI:102470
    343347            result = false;
  • trunk/scripts/TagInfoExtract.java

    r14635 r14638  
    407407             * @return the URL
    408408             */
    409             String createImage(StyleElement elem_style, final String type, NavigatableComponent nc) {
     409            String createImage(StyleElement element, final String type, NavigatableComponent nc) {
    410410                BufferedImage img = new BufferedImage(16, 16, BufferedImage.TYPE_INT_ARGB);
    411411                Graphics2D g = img.createGraphics();
     
    413413                StyledMapRenderer renderer = new StyledMapRenderer(g, nc, false);
    414414                renderer.getSettings(false);
    415                 elem_style.paintPrimitive(osm, MapPaintSettings.INSTANCE, renderer, false, false, false);
     415                element.paintPrimitive(osm, MapPaintSettings.INSTANCE, renderer, false, false, false);
    416416                final String imageName = type + "_" + tag + ".png";
    417417                try (OutputStream out = Files.newOutputStream(options.imageDir.resolve(imageName))) {
  • trunk/tools/pmd/josm-ruleset.xml

    r14604 r14638  
    6464    <exclude name="MethodArgumentCouldBeFinal"/>
    6565    <exclude name="MethodNamingConventions"/>
     66    <exclude name="NoPackage"/>
    6667    <exclude name="OnlyOneReturn"/>
    6768    <exclude name="PrematureDeclaration"/>
Note: See TracChangeset for help on using the changeset viewer.